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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 82 Revision 171
23#include <stdlib.h> 23#include <stdlib.h>
24 24
25#include "error.h" 25#include "error.h"
26#include "generate_routines.h" 26#include "generate_routines.h"
27 27
28#ifdef DMALLOC
29#include <dmalloc.h>
30#endif
28 31
29int psiconv_write(psiconv_buffer *buf,const psiconv_file value) 32
33int psiconv_write(const psiconv_config config, psiconv_buffer *buf,
34 const psiconv_file value)
30{ 35{
31 int res; 36 int res;
32 37
33 if (!value) { 38 if (!value) {
34 psiconv_warn(0,0,"Can't parse to an empty buffer!"); 39 psiconv_warn(config,0,0,"Can't parse to an empty buffer!");
35 return -PSICONV_E_OTHER; 40 return -PSICONV_E_OTHER;
36 } 41 }
37 if (!(*buf = psiconv_buffer_new())) 42 if (!(*buf = psiconv_buffer_new()))
38 return -PSICONV_E_NOMEM; 43 return -PSICONV_E_NOMEM;
39 44
40 if (value->type == psiconv_word_file) { 45 if (value->type == psiconv_word_file) {
46 if ((res = psiconv_write_header_section(config,*buf,PSICONV_ID_PSION5,
47 PSICONV_ID_DATA_FILE,
48 PSICONV_ID_WORD)))
49 goto ERROR;
41 if ((res =psiconv_write_word_file(*buf,(psiconv_word_f) (value->file)))) 50 if ((res =psiconv_write_word_file(config,*buf,(psiconv_word_f) (value->file))))
42 goto ERROR; 51 goto ERROR;
43 } else if (value->type == psiconv_texted_file) { 52 } else if (value->type == psiconv_texted_file) {
53 if ((res = psiconv_write_header_section(config,*buf,PSICONV_ID_PSION5,
54 PSICONV_ID_DATA_FILE,
55 PSICONV_ID_TEXTED)))
56 goto ERROR;
44 if ((res =psiconv_write_texted_file(*buf, 57 if ((res =psiconv_write_texted_file(config,*buf,
45 (psiconv_texted_f) (value->file)))) 58 (psiconv_texted_f) (value->file))))
46 goto ERROR; 59 goto ERROR;
60 } else if (value->type == psiconv_sketch_file) {
61 if ((res = psiconv_write_header_section(config,*buf,PSICONV_ID_PSION5,
62 PSICONV_ID_DATA_FILE,
63 PSICONV_ID_SKETCH)))
64 goto ERROR;
65 if ((res =psiconv_write_sketch_file(config,*buf,
66 (psiconv_sketch_f) (value->file))))
67 goto ERROR;
68 } else if (value->type == psiconv_mbm_file) {
69 if ((res = psiconv_write_header_section(config,*buf,PSICONV_ID_PSION5,
70 PSICONV_ID_MBM_FILE,
71 0x00000000)))
72 goto ERROR;
73 if ((res =psiconv_write_mbm_file(config,*buf,
74 (psiconv_mbm_f) (value->file))))
75 goto ERROR;
47#if 0 76#if 0
48 } else if (value->type == psiconv_sketch_file) {
49 if ((res =psiconv_write_sketch_file(*buf,
50 (psiconv_sketch_f) (value->file))))
51 goto ERROR;
52 } else if (value->type == psiconv_mbm_file) {
53 if ((res =psiconv_write_mbm_file(*buf,
54 (psiconv_mbm_f) (value->file))))
55 goto ERROR;
56 } else if (value->type == psiconv_clipart_file) { 77 } else if (value->type == psiconv_clipart_file) {
57 if ((res =psiconv_write_clipart_file(*buf, 78 if ((res =psiconv_write_clipart_file(config,*buf,
58 (psiconv_clipart_f) (value->file)))) 79 (psiconv_clipart_f) (value->file))))
59 goto ERROR; 80 goto ERROR;
60#endif 81#endif
61 } else { 82 } else {
62 psiconv_warn(0,0,"Unknown or unsupported file type"); 83 psiconv_warn(config,0,0,"Unknown or unsupported file type");
63 res = -PSICONV_E_GENERATE; 84 res = -PSICONV_E_GENERATE;
64 goto ERROR; 85 goto ERROR;
65 } 86 }
66 if ((res = psiconv_buffer_resolve(*buf))) 87 if ((res = psiconv_buffer_resolve(*buf)))
67 goto ERROR; 88 goto ERROR;
70ERROR: 91ERROR:
71 psiconv_buffer_free(*buf); 92 psiconv_buffer_free(*buf);
72 return res; 93 return res;
73} 94}
74 95
75int psiconv_write_texted_file(psiconv_buffer buf,psiconv_texted_f value) 96int psiconv_write_texted_file(const psiconv_config config,
97 psiconv_buffer buf,psiconv_texted_f value)
76{ 98{
77 psiconv_character_layout base_char; 99 psiconv_character_layout base_char;
78 psiconv_paragraph_layout base_para; 100 psiconv_paragraph_layout base_para;
79 int res; 101 int res;
80 psiconv_section_table_section section_table; 102 psiconv_section_table_section section_table;
81 psiconv_section_table_entry entry; 103 psiconv_section_table_entry entry;
82 psiconv_u32 section_table_id; 104 psiconv_u32 section_table_id;
83 psiconv_buffer buf_texted; 105 psiconv_buffer buf_texted;
84 106
85 if (!value) { 107 if (!value) {
86 psiconv_warn(0,0,"Null TextEd file"); 108 psiconv_warn(config,0,0,"Null TextEd file");
87 return -PSICONV_E_GENERATE; 109 return -PSICONV_E_GENERATE;
88 } 110 }
89 111
90 if (!(section_table = psiconv_list_new(sizeof(*entry)))) { 112 if (!(section_table = psiconv_list_new(sizeof(*entry)))) {
91 res = -PSICONV_E_NOMEM; 113 res = -PSICONV_E_NOMEM;
104 if (!(base_para = psiconv_basic_paragraph_layout())) { 126 if (!(base_para = psiconv_basic_paragraph_layout())) {
105 res = -PSICONV_E_NOMEM; 127 res = -PSICONV_E_NOMEM;
106 goto ERROR4; 128 goto ERROR4;
107 } 129 }
108 130
109 if ((res = psiconv_write_header_section(buf,PSICONV_ID_PSION5,
110 PSICONV_ID_DATA_FILE,
111 PSICONV_ID_TEXTED)))
112 goto ERROR5;
113
114 section_table_id = psiconv_buffer_unique_id(); 131 section_table_id = psiconv_buffer_unique_id();
115 if ((res = psiconv_write_offset(buf,section_table_id))) 132 if ((res = psiconv_write_offset(config,buf,section_table_id)))
116 goto ERROR5; 133 goto ERROR5;
117 134
118 entry->id = PSICONV_ID_APPL_ID_SECTION; 135 entry->id = PSICONV_ID_APPL_ID_SECTION;
119 entry->offset = psiconv_buffer_unique_id(); 136 entry->offset = psiconv_buffer_unique_id();
120 if ((res = psiconv_list_add(section_table,entry))) 137 if ((res = psiconv_list_add(section_table,entry)))
121 goto ERROR5; 138 goto ERROR5;
122 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 139 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
123 goto ERROR5; 140 goto ERROR5;
124 if ((res=psiconv_write_application_id_section(buf, 141 if ((res=psiconv_write_application_id_section(config,buf,
125 PSICONV_ID_TEXTED,"TextEd.app"))) 142 PSICONV_ID_TEXTED,"TextEd.app")))
126 goto ERROR5; 143 goto ERROR5;
127 144
128 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION; 145 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION;
129 entry->offset = psiconv_buffer_unique_id(); 146 entry->offset = psiconv_buffer_unique_id();
130 if ((res = psiconv_list_add(section_table,entry))) 147 if ((res = psiconv_list_add(section_table,entry)))
131 goto ERROR5; 148 goto ERROR5;
132 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 149 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
133 goto ERROR5; 150 goto ERROR5;
134 if ((res = psiconv_write_page_layout_section(buf,value->page_sec))) 151 if ((res = psiconv_write_page_layout_section(config,buf,value->page_sec)))
135 goto ERROR5; 152 goto ERROR5;
136 153
137 entry->id = PSICONV_ID_TEXTED; 154 entry->id = PSICONV_ID_TEXTED;
138 entry->offset = psiconv_buffer_unique_id(); 155 entry->offset = psiconv_buffer_unique_id();
139 if ((res = psiconv_list_add(section_table,entry))) 156 if ((res = psiconv_list_add(section_table,entry)))
140 goto ERROR5; 157 goto ERROR5;
141 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 158 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
142 goto ERROR5; 159 goto ERROR5;
143 if ((res = psiconv_write_texted_section(buf,value->texted_sec, 160 if ((res = psiconv_write_texted_section(config,buf,value->texted_sec,
144 base_char,base_para,&buf_texted))) 161 base_char,base_para,&buf_texted)))
145 goto ERROR5; 162 goto ERROR5;
146 163
147 if ((res = psiconv_buffer_concat(buf,buf_texted))) 164 if ((res = psiconv_buffer_concat(buf,buf_texted)))
148 goto ERROR6; 165 goto ERROR6;
149 166
150 167
151 if ((res = psiconv_buffer_add_target(buf,section_table_id))) 168 if ((res = psiconv_buffer_add_target(buf,section_table_id)))
152 goto ERROR6; 169 goto ERROR6;
153 170
154 res = psiconv_write_section_table_section(buf,section_table); 171 res = psiconv_write_section_table_section(config,buf,section_table);
155 172
156ERROR6: 173ERROR6:
157 psiconv_buffer_free(buf_texted); 174 psiconv_buffer_free(buf_texted);
158ERROR5: 175ERROR5:
159 psiconv_free_paragraph_layout(base_para); 176 psiconv_free_paragraph_layout(base_para);
165 psiconv_list_free(section_table); 182 psiconv_list_free(section_table);
166ERROR1: 183ERROR1:
167 return res; 184 return res;
168} 185}
169 186
170int psiconv_write_word_file(psiconv_buffer buf,psiconv_word_f value) 187int psiconv_write_word_file(const psiconv_config config,
188 psiconv_buffer buf,psiconv_word_f value)
171{ 189{
172 int res; 190 int res;
173 psiconv_section_table_section section_table; 191 psiconv_section_table_section section_table;
174 psiconv_section_table_entry entry; 192 psiconv_section_table_entry entry;
175 psiconv_u32 section_table_id; 193 psiconv_u32 section_table_id;
176 194
177 if (!value) { 195 if (!value) {
178 psiconv_warn(0,0,"Null Word file"); 196 psiconv_warn(config,0,0,"Null Word file");
179 return -PSICONV_E_GENERATE; 197 return -PSICONV_E_GENERATE;
180 } 198 }
181 199
182 if (!(section_table = psiconv_list_new(sizeof(*entry)))) { 200 if (!(section_table = psiconv_list_new(sizeof(*entry)))) {
183 res = -PSICONV_E_NOMEM; 201 res = -PSICONV_E_NOMEM;
187 if (!(entry = malloc(sizeof(*entry)))) { 205 if (!(entry = malloc(sizeof(*entry)))) {
188 res = -PSICONV_E_NOMEM; 206 res = -PSICONV_E_NOMEM;
189 goto ERROR2; 207 goto ERROR2;
190 } 208 }
191 209
192 if ((res = psiconv_write_header_section(buf,PSICONV_ID_PSION5,
193 PSICONV_ID_DATA_FILE,
194 PSICONV_ID_WORD)))
195 goto ERROR3;
196
197 section_table_id = psiconv_buffer_unique_id(); 210 section_table_id = psiconv_buffer_unique_id();
198 if ((res = psiconv_write_offset(buf,section_table_id))) 211 if ((res = psiconv_write_offset(config,buf,section_table_id)))
199 goto ERROR3; 212 goto ERROR3;
200 213
201 entry->id = PSICONV_ID_APPL_ID_SECTION; 214 entry->id = PSICONV_ID_APPL_ID_SECTION;
202 entry->offset = psiconv_buffer_unique_id(); 215 entry->offset = psiconv_buffer_unique_id();
203 if ((res = psiconv_list_add(section_table,entry))) 216 if ((res = psiconv_list_add(section_table,entry)))
204 goto ERROR3; 217 goto ERROR3;
205 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 218 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
206 goto ERROR3; 219 goto ERROR3;
207 if ((res=psiconv_write_application_id_section(buf, 220 if ((res=psiconv_write_application_id_section(config,buf,
208 PSICONV_ID_WORD,"Word.app"))) 221 PSICONV_ID_WORD,"Word.app")))
209 goto ERROR3; 222 goto ERROR3;
210 223
211 entry->id = PSICONV_ID_WORD_STATUS_SECTION; 224 entry->id = PSICONV_ID_WORD_STATUS_SECTION;
212 entry->offset = psiconv_buffer_unique_id(); 225 entry->offset = psiconv_buffer_unique_id();
213 if ((res = psiconv_list_add(section_table,entry))) 226 if ((res = psiconv_list_add(section_table,entry)))
214 goto ERROR3; 227 goto ERROR3;
215 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 228 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
216 goto ERROR3; 229 goto ERROR3;
217 if ((res = psiconv_write_word_status_section(buf,value->status_sec))) 230 if ((res = psiconv_write_word_status_section(config,buf,value->status_sec)))
218 goto ERROR3; 231 goto ERROR3;
219 232
220 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION; 233 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION;
221 entry->offset = psiconv_buffer_unique_id(); 234 entry->offset = psiconv_buffer_unique_id();
222 if ((res = psiconv_list_add(section_table,entry))) 235 if ((res = psiconv_list_add(section_table,entry)))
223 goto ERROR3; 236 goto ERROR3;
224 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 237 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
225 goto ERROR3; 238 goto ERROR3;
226 if ((res = psiconv_write_page_layout_section(buf,value->page_sec))) 239 if ((res = psiconv_write_page_layout_section(config,buf,value->page_sec)))
227 goto ERROR3; 240 goto ERROR3;
228 241
229 entry->id = PSICONV_ID_WORD_STYLES_SECTION; 242 entry->id = PSICONV_ID_WORD_STYLES_SECTION;
230 entry->offset = psiconv_buffer_unique_id(); 243 entry->offset = psiconv_buffer_unique_id();
231 if ((res = psiconv_list_add(section_table,entry))) 244 if ((res = psiconv_list_add(section_table,entry)))
232 goto ERROR3; 245 goto ERROR3;
233 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 246 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
234 goto ERROR3; 247 goto ERROR3;
235 if ((res = psiconv_write_word_styles_section(buf,value->styles_sec))) 248 if ((res = psiconv_write_word_styles_section(config,buf,value->styles_sec)))
236 goto ERROR3; 249 goto ERROR3;
237 250
238 entry->id = PSICONV_ID_TEXT_SECTION; 251 entry->id = PSICONV_ID_TEXT_SECTION;
239 entry->offset = psiconv_buffer_unique_id(); 252 entry->offset = psiconv_buffer_unique_id();
240 if ((res = psiconv_list_add(section_table,entry))) 253 if ((res = psiconv_list_add(section_table,entry)))
241 goto ERROR3; 254 goto ERROR3;
242 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 255 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
243 goto ERROR3; 256 goto ERROR3;
244 if ((res = psiconv_write_text_section(buf,value->paragraphs))) 257 if ((res = psiconv_write_text_section(config,buf,value->paragraphs)))
245 goto ERROR3; 258 goto ERROR3;
246 259
247 entry->id = PSICONV_ID_LAYOUT_SECTION; 260 entry->id = PSICONV_ID_LAYOUT_SECTION;
248 entry->offset = psiconv_buffer_unique_id(); 261 entry->offset = psiconv_buffer_unique_id();
249 if ((res = psiconv_list_add(section_table,entry))) 262 if ((res = psiconv_list_add(section_table,entry)))
250 goto ERROR3; 263 goto ERROR3;
251 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 264 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
252 goto ERROR3; 265 goto ERROR3;
253 if ((res = psiconv_write_styled_layout_section(buf,value->paragraphs, 266 if ((res = psiconv_write_styled_layout_section(config,buf,value->paragraphs,
254 value->styles_sec))) 267 value->styles_sec)))
255 goto ERROR3; 268 goto ERROR3;
256 269
257 if ((res = psiconv_buffer_add_target(buf,section_table_id))) 270 if ((res = psiconv_buffer_add_target(buf,section_table_id)))
258 goto ERROR3; 271 goto ERROR3;
259 272
260 res = psiconv_write_section_table_section(buf,section_table); 273 res = psiconv_write_section_table_section(config,buf,section_table);
261 274
262ERROR3: 275ERROR3:
263 free(entry); 276 free(entry);
264ERROR2: 277ERROR2:
265 psiconv_list_free(section_table); 278 psiconv_list_free(section_table);
266ERROR1: 279ERROR1:
267 return res; 280 return res;
268} 281}
282
283int psiconv_write_sketch_file(const psiconv_config config,
284 psiconv_buffer buf,psiconv_sketch_f value)
285{
286 int res;
287 psiconv_section_table_section section_table;
288 psiconv_section_table_entry entry;
289 psiconv_u32 section_table_id;
290
291 if (!value) {
292 psiconv_warn(config,0,0,"Null Sketch file");
293 return -PSICONV_E_GENERATE;
294 }
295
296 if (!(section_table = psiconv_list_new(sizeof(*entry)))) {
297 res = -PSICONV_E_NOMEM;
298 goto ERROR1;
299 }
300
301 if (!(entry = malloc(sizeof(*entry)))) {
302 res = -PSICONV_E_NOMEM;
303 goto ERROR2;
304 }
305
306 section_table_id = psiconv_buffer_unique_id();
307 if ((res = psiconv_write_offset(config,buf,section_table_id)))
308 goto ERROR3;
309
310 entry->id = PSICONV_ID_APPL_ID_SECTION;
311 entry->offset = psiconv_buffer_unique_id();
312 if ((res = psiconv_list_add(section_table,entry)))
313 goto ERROR3;
314 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
315 goto ERROR3;
316 if ((res=psiconv_write_application_id_section(config,buf,
317 PSICONV_ID_SKETCH,"Paint.app")))
318 goto ERROR3;
319
320 entry->id = PSICONV_ID_SKETCH_SECTION;
321 entry->offset = psiconv_buffer_unique_id();
322 if ((res = psiconv_list_add(section_table,entry)))
323 goto ERROR3;
324 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
325 goto ERROR3;
326 if ((res = psiconv_write_sketch_section(config,buf,value->sketch_sec)))
327 goto ERROR3;
328
329 if ((res = psiconv_buffer_add_target(buf,section_table_id)))
330 goto ERROR3;
331 res = psiconv_write_section_table_section(config,buf,section_table);
332
333ERROR3:
334 free(entry);
335ERROR2:
336 psiconv_list_free(section_table);
337ERROR1:
338 return res;
339}
340
341int psiconv_write_mbm_file(const psiconv_config config,
342 psiconv_buffer buf,psiconv_mbm_f value)
343{
344 int res,i;
345 psiconv_jumptable_section jumptable;
346 psiconv_u32 *entry,id,table_id;
347 psiconv_paint_data_section section;
348
349 if (!value) {
350 psiconv_warn(config,0,0,"Null MBM file");
351 return -PSICONV_E_GENERATE;
352 }
353
354 if (!(jumptable = psiconv_list_new(sizeof(*entry)))) {
355 res = -PSICONV_E_NOMEM;
356 goto ERROR1;
357 }
358
359 table_id = psiconv_buffer_unique_id();
360 if ((res = psiconv_buffer_add_reference(buf,table_id)))
361 goto ERROR2;
362
363 for (i = 0; i < psiconv_list_length(value->sections); i++) {
364 if (!(section = psiconv_list_get(value->sections,i))) {
365 psiconv_warn(config,0,0,"Massive memory corruption");
366 res = -PSICONV_E_NOMEM;
367 goto ERROR2;
368 }
369 id = psiconv_buffer_unique_id();
370 psiconv_list_add(jumptable,&id);
371 if ((res = psiconv_buffer_add_target(buf,id)))
372 goto ERROR2;
373 if ((res = psiconv_write_paint_data_section(config,buf,section)))
374 goto ERROR2;
375 }
376
377 if ((res = psiconv_buffer_add_target(buf,table_id)))
378 goto ERROR2;
379 if ((res = psiconv_write_jumptable_section(config,buf,jumptable)))
380 goto ERROR2;
381
382
383ERROR2:
384 psiconv_list_free(jumptable);
385ERROR1:
386 return res;
387}

Legend:
Removed from v.82  
changed lines
  Added in v.171

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