/[public]/psiconv/trunk/lib/psiconv/generate_driver.c
ViewVC logotype

Annotation of /psiconv/trunk/lib/psiconv/generate_driver.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 170 - (hide annotations)
Tue Nov 25 22:08:48 2003 UTC (20 years, 4 months ago) by frodo
File MIME type: text/plain
File size: 10533 byte(s)
(Frodo) Generating of Sketch files, both stand-alone and as objects, works!

No RLE encoding yet, we have to test higher colordepths.

1 frodo 73 /*
2     generate_driver.c - Part of psiconv, a PSION 5 file formats converter
3     Copyright (c) 2000 Frodo Looijaard <frodol@dds.nl>
4    
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9    
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13     GNU General Public License for more details.
14    
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18     */
19    
20     #include "config.h"
21     #include "compat.h"
22    
23     #include <stdlib.h>
24    
25     #include "error.h"
26     #include "generate_routines.h"
27    
28 frodo 142 #ifdef DMALLOC
29     #include <dmalloc.h>
30     #endif
31 frodo 73
32 frodo 142
33 frodo 168 int psiconv_write(const psiconv_config config, psiconv_buffer *buf,
34     const psiconv_file value)
35 frodo 73 {
36     int res;
37    
38     if (!value) {
39 frodo 168 psiconv_warn(config,0,0,"Can't parse to an empty buffer!");
40 frodo 73 return -PSICONV_E_OTHER;
41     }
42 frodo 80 if (!(*buf = psiconv_buffer_new()))
43 frodo 75 return -PSICONV_E_NOMEM;
44 frodo 73
45     if (value->type == psiconv_word_file) {
46 frodo 168 if ((res = psiconv_write_header_section(config,*buf,PSICONV_ID_PSION5,
47 frodo 166 PSICONV_ID_DATA_FILE,
48     PSICONV_ID_WORD)))
49     goto ERROR;
50 frodo 168 if ((res =psiconv_write_word_file(config,*buf,(psiconv_word_f) (value->file))))
51 frodo 73 goto ERROR;
52 frodo 82 } else if (value->type == psiconv_texted_file) {
53 frodo 168 if ((res = psiconv_write_header_section(config,*buf,PSICONV_ID_PSION5,
54 frodo 166 PSICONV_ID_DATA_FILE,
55     PSICONV_ID_TEXTED)))
56     goto ERROR;
57 frodo 168 if ((res =psiconv_write_texted_file(config,*buf,
58 frodo 73 (psiconv_texted_f) (value->file))))
59     goto ERROR;
60     } else if (value->type == psiconv_sketch_file) {
61 frodo 170 if ((res = psiconv_write_header_section(config,*buf,PSICONV_ID_PSION5,
62     PSICONV_ID_DATA_FILE,
63     PSICONV_ID_SKETCH)))
64     goto ERROR;
65 frodo 168 if ((res =psiconv_write_sketch_file(config,*buf,
66 frodo 73 (psiconv_sketch_f) (value->file))))
67     goto ERROR;
68 frodo 170 #if 0
69 frodo 73 } else if (value->type == psiconv_mbm_file) {
70 frodo 168 if ((res =psiconv_write_mbm_file(config,*buf,
71 frodo 73 (psiconv_mbm_f) (value->file))))
72     goto ERROR;
73     } else if (value->type == psiconv_clipart_file) {
74 frodo 168 if ((res =psiconv_write_clipart_file(config,*buf,
75 frodo 73 (psiconv_clipart_f) (value->file))))
76     goto ERROR;
77     #endif
78     } else {
79 frodo 168 psiconv_warn(config,0,0,"Unknown or unsupported file type");
80 frodo 73 res = -PSICONV_E_GENERATE;
81     goto ERROR;
82     }
83 frodo 80 if ((res = psiconv_buffer_resolve(*buf)))
84     goto ERROR;
85 frodo 73 return -PSICONV_E_OK;
86    
87     ERROR:
88 frodo 79 psiconv_buffer_free(*buf);
89 frodo 73 return res;
90     }
91    
92 frodo 168 int psiconv_write_texted_file(const psiconv_config config,
93     psiconv_buffer buf,psiconv_texted_f value)
94 frodo 73 {
95     psiconv_character_layout base_char;
96     psiconv_paragraph_layout base_para;
97     int res;
98     psiconv_section_table_section section_table;
99     psiconv_section_table_entry entry;
100 frodo 80 psiconv_u32 section_table_id;
101     psiconv_buffer buf_texted;
102 frodo 73
103     if (!value) {
104 frodo 168 psiconv_warn(config,0,0,"Null TextEd file");
105 frodo 73 return -PSICONV_E_GENERATE;
106     }
107    
108     if (!(section_table = psiconv_list_new(sizeof(*entry)))) {
109     res = -PSICONV_E_NOMEM;
110     goto ERROR1;
111     }
112    
113     if (!(entry = malloc(sizeof(*entry)))) {
114     res = -PSICONV_E_NOMEM;
115     goto ERROR2;
116     }
117    
118 frodo 80 if (!(base_char = psiconv_basic_character_layout())) {
119 frodo 73 res = -PSICONV_E_NOMEM;
120     goto ERROR3;
121     }
122 frodo 80 if (!(base_para = psiconv_basic_paragraph_layout())) {
123 frodo 73 res = -PSICONV_E_NOMEM;
124     goto ERROR4;
125     }
126    
127 frodo 80 section_table_id = psiconv_buffer_unique_id();
128 frodo 168 if ((res = psiconv_write_offset(config,buf,section_table_id)))
129 frodo 80 goto ERROR5;
130 frodo 73
131     entry->id = PSICONV_ID_APPL_ID_SECTION;
132 frodo 80 entry->offset = psiconv_buffer_unique_id();
133 frodo 76 if ((res = psiconv_list_add(section_table,entry)))
134 frodo 80 goto ERROR5;
135     if ((res = psiconv_buffer_add_target(buf,entry->offset)))
136     goto ERROR5;
137 frodo 168 if ((res=psiconv_write_application_id_section(config,buf,
138 frodo 73 PSICONV_ID_TEXTED,"TextEd.app")))
139 frodo 80 goto ERROR5;
140 frodo 73
141     entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION;
142 frodo 80 entry->offset = psiconv_buffer_unique_id();
143 frodo 76 if ((res = psiconv_list_add(section_table,entry)))
144 frodo 80 goto ERROR5;
145     if ((res = psiconv_buffer_add_target(buf,entry->offset)))
146     goto ERROR5;
147 frodo 168 if ((res = psiconv_write_page_layout_section(config,buf,value->page_sec)))
148 frodo 80 goto ERROR5;
149 frodo 73
150     entry->id = PSICONV_ID_TEXTED;
151 frodo 80 entry->offset = psiconv_buffer_unique_id();
152 frodo 76 if ((res = psiconv_list_add(section_table,entry)))
153 frodo 80 goto ERROR5;
154     if ((res = psiconv_buffer_add_target(buf,entry->offset)))
155     goto ERROR5;
156 frodo 168 if ((res = psiconv_write_texted_section(config,buf,value->texted_sec,
157 frodo 80 base_char,base_para,&buf_texted)))
158     goto ERROR5;
159 frodo 73
160 frodo 80 if ((res = psiconv_buffer_concat(buf,buf_texted)))
161 frodo 73 goto ERROR6;
162    
163 frodo 80
164     if ((res = psiconv_buffer_add_target(buf,section_table_id)))
165 frodo 73 goto ERROR6;
166    
167 frodo 168 res = psiconv_write_section_table_section(config,buf,section_table);
168 frodo 73
169     ERROR6:
170 frodo 80 psiconv_buffer_free(buf_texted);
171     ERROR5:
172 frodo 73 psiconv_free_paragraph_layout(base_para);
173 frodo 80 ERROR4:
174 frodo 73 psiconv_free_character_layout(base_char);
175     ERROR3:
176     free(entry);
177     ERROR2:
178     psiconv_list_free(section_table);
179     ERROR1:
180     return res;
181     }
182 frodo 82
183 frodo 168 int psiconv_write_word_file(const psiconv_config config,
184     psiconv_buffer buf,psiconv_word_f value)
185 frodo 82 {
186     int res;
187     psiconv_section_table_section section_table;
188     psiconv_section_table_entry entry;
189     psiconv_u32 section_table_id;
190    
191     if (!value) {
192 frodo 168 psiconv_warn(config,0,0,"Null Word file");
193 frodo 82 return -PSICONV_E_GENERATE;
194     }
195    
196     if (!(section_table = psiconv_list_new(sizeof(*entry)))) {
197     res = -PSICONV_E_NOMEM;
198     goto ERROR1;
199     }
200    
201     if (!(entry = malloc(sizeof(*entry)))) {
202     res = -PSICONV_E_NOMEM;
203     goto ERROR2;
204     }
205    
206     section_table_id = psiconv_buffer_unique_id();
207 frodo 168 if ((res = psiconv_write_offset(config,buf,section_table_id)))
208 frodo 82 goto ERROR3;
209    
210     entry->id = PSICONV_ID_APPL_ID_SECTION;
211     entry->offset = psiconv_buffer_unique_id();
212     if ((res = psiconv_list_add(section_table,entry)))
213     goto ERROR3;
214     if ((res = psiconv_buffer_add_target(buf,entry->offset)))
215     goto ERROR3;
216 frodo 168 if ((res=psiconv_write_application_id_section(config,buf,
217 frodo 82 PSICONV_ID_WORD,"Word.app")))
218     goto ERROR3;
219    
220     entry->id = PSICONV_ID_WORD_STATUS_SECTION;
221     entry->offset = psiconv_buffer_unique_id();
222     if ((res = psiconv_list_add(section_table,entry)))
223     goto ERROR3;
224     if ((res = psiconv_buffer_add_target(buf,entry->offset)))
225     goto ERROR3;
226 frodo 168 if ((res = psiconv_write_word_status_section(config,buf,value->status_sec)))
227 frodo 82 goto ERROR3;
228    
229     entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION;
230     entry->offset = psiconv_buffer_unique_id();
231     if ((res = psiconv_list_add(section_table,entry)))
232     goto ERROR3;
233     if ((res = psiconv_buffer_add_target(buf,entry->offset)))
234     goto ERROR3;
235 frodo 168 if ((res = psiconv_write_page_layout_section(config,buf,value->page_sec)))
236 frodo 82 goto ERROR3;
237    
238     entry->id = PSICONV_ID_WORD_STYLES_SECTION;
239     entry->offset = psiconv_buffer_unique_id();
240     if ((res = psiconv_list_add(section_table,entry)))
241     goto ERROR3;
242     if ((res = psiconv_buffer_add_target(buf,entry->offset)))
243     goto ERROR3;
244 frodo 168 if ((res = psiconv_write_word_styles_section(config,buf,value->styles_sec)))
245 frodo 82 goto ERROR3;
246    
247     entry->id = PSICONV_ID_TEXT_SECTION;
248     entry->offset = psiconv_buffer_unique_id();
249     if ((res = psiconv_list_add(section_table,entry)))
250     goto ERROR3;
251     if ((res = psiconv_buffer_add_target(buf,entry->offset)))
252     goto ERROR3;
253 frodo 168 if ((res = psiconv_write_text_section(config,buf,value->paragraphs)))
254 frodo 82 goto ERROR3;
255    
256     entry->id = PSICONV_ID_LAYOUT_SECTION;
257     entry->offset = psiconv_buffer_unique_id();
258     if ((res = psiconv_list_add(section_table,entry)))
259     goto ERROR3;
260     if ((res = psiconv_buffer_add_target(buf,entry->offset)))
261     goto ERROR3;
262 frodo 168 if ((res = psiconv_write_styled_layout_section(config,buf,value->paragraphs,
263 frodo 82 value->styles_sec)))
264     goto ERROR3;
265    
266     if ((res = psiconv_buffer_add_target(buf,section_table_id)))
267     goto ERROR3;
268    
269 frodo 168 res = psiconv_write_section_table_section(config,buf,section_table);
270 frodo 82
271     ERROR3:
272     free(entry);
273     ERROR2:
274     psiconv_list_free(section_table);
275     ERROR1:
276     return res;
277     }
278 frodo 170
279     int psiconv_write_sketch_file(const psiconv_config config,
280     psiconv_buffer buf,psiconv_sketch_f value)
281     {
282     int res;
283     psiconv_section_table_section section_table;
284     psiconv_section_table_entry entry;
285     psiconv_u32 section_table_id;
286    
287     if (!value) {
288     psiconv_warn(config,0,0,"Null Sketch file");
289     return -PSICONV_E_GENERATE;
290     }
291    
292     if (!(section_table = psiconv_list_new(sizeof(*entry)))) {
293     res = -PSICONV_E_NOMEM;
294     goto ERROR1;
295     }
296    
297     if (!(entry = malloc(sizeof(*entry)))) {
298     res = -PSICONV_E_NOMEM;
299     goto ERROR2;
300     }
301    
302     section_table_id = psiconv_buffer_unique_id();
303     if ((res = psiconv_write_offset(config,buf,section_table_id)))
304     goto ERROR3;
305    
306     entry->id = PSICONV_ID_APPL_ID_SECTION;
307     entry->offset = psiconv_buffer_unique_id();
308     if ((res = psiconv_list_add(section_table,entry)))
309     goto ERROR3;
310     if ((res = psiconv_buffer_add_target(buf,entry->offset)))
311     goto ERROR3;
312     if ((res=psiconv_write_application_id_section(config,buf,
313     PSICONV_ID_SKETCH,"Paint.app")))
314     goto ERROR3;
315    
316     entry->id = PSICONV_ID_SKETCH_SECTION;
317     entry->offset = psiconv_buffer_unique_id();
318     if ((res = psiconv_list_add(section_table,entry)))
319     goto ERROR3;
320     if ((res = psiconv_buffer_add_target(buf,entry->offset)))
321     goto ERROR3;
322     if ((res = psiconv_write_sketch_section(config,buf,value->sketch_sec)))
323     goto ERROR3;
324    
325     if ((res = psiconv_buffer_add_target(buf,section_table_id)))
326     goto ERROR3;
327     res = psiconv_write_section_table_section(config,buf,section_table);
328    
329     ERROR3:
330     free(entry);
331     ERROR2:
332     psiconv_list_free(section_table);
333     ERROR1:
334     return res;
335     }

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26