/[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 183 Revision 184
27 27
28#ifdef DMALLOC 28#ifdef DMALLOC
29#include <dmalloc.h> 29#include <dmalloc.h>
30#endif 30#endif
31 31
32static psiconv_ucs2 unicode_paint[10] = { 'P','a','i','n','t','.','a','p','p',0 };
33static psiconv_ucs2 unicode_texted[11] ={ 'T','e','x','t','E','d','.','a','p','p',0 };
34static psiconv_ucs2 unicode_word[9] = { 'W','o','r','d','.','a','p','p',0 };
35
32 36
33int psiconv_write(const psiconv_config config, psiconv_buffer *buf, 37int psiconv_write(const psiconv_config config, psiconv_buffer *buf,
34 const psiconv_file value) 38 const psiconv_file value)
35{ 39{
36 int res; 40 int res;
41 int lev = 0;
37 42
38 if (!value) { 43 if (!value) {
39 psiconv_warn(config,0,0,"Can't parse to an empty buffer!"); 44 psiconv_error(config,0,0,"Can't parse to an empty buffer!");
40 return -PSICONV_E_OTHER; 45 return -PSICONV_E_OTHER;
41 } 46 }
42 if (!(*buf = psiconv_buffer_new())) 47 if (!(*buf = psiconv_buffer_new()))
43 return -PSICONV_E_NOMEM; 48 return -PSICONV_E_NOMEM;
44 49
45 if (value->type == psiconv_word_file) { 50 if (value->type == psiconv_word_file) {
46 if ((res = psiconv_write_header_section(config,*buf,PSICONV_ID_PSION5, 51 if ((res = psiconv_write_header_section(config,*buf,lev+1,PSICONV_ID_PSION5,
47 PSICONV_ID_DATA_FILE, 52 PSICONV_ID_DATA_FILE,
48 PSICONV_ID_WORD))) 53 PSICONV_ID_WORD)))
49 goto ERROR; 54 goto ERROR;
50 if ((res =psiconv_write_word_file(config,*buf,(psiconv_word_f) (value->file)))) 55 if ((res =psiconv_write_word_file(config,*buf,lev+1,(psiconv_word_f) (value->file))))
51 goto ERROR; 56 goto ERROR;
52 } else if (value->type == psiconv_texted_file) { 57 } else if (value->type == psiconv_texted_file) {
53 if ((res = psiconv_write_header_section(config,*buf,PSICONV_ID_PSION5, 58 if ((res = psiconv_write_header_section(config,*buf,lev+1,PSICONV_ID_PSION5,
54 PSICONV_ID_DATA_FILE, 59 PSICONV_ID_DATA_FILE,
55 PSICONV_ID_TEXTED))) 60 PSICONV_ID_TEXTED)))
56 goto ERROR; 61 goto ERROR;
57 if ((res =psiconv_write_texted_file(config,*buf, 62 if ((res =psiconv_write_texted_file(config,*buf,lev+1,
58 (psiconv_texted_f) (value->file)))) 63 (psiconv_texted_f) (value->file))))
59 goto ERROR; 64 goto ERROR;
60 } else if (value->type == psiconv_sketch_file) { 65 } else if (value->type == psiconv_sketch_file) {
61 if ((res = psiconv_write_header_section(config,*buf,PSICONV_ID_PSION5, 66 if ((res = psiconv_write_header_section(config,*buf,lev+1,PSICONV_ID_PSION5,
62 PSICONV_ID_DATA_FILE, 67 PSICONV_ID_DATA_FILE,
63 PSICONV_ID_SKETCH))) 68 PSICONV_ID_SKETCH)))
64 goto ERROR; 69 goto ERROR;
65 if ((res =psiconv_write_sketch_file(config,*buf, 70 if ((res =psiconv_write_sketch_file(config,*buf,lev+1,
66 (psiconv_sketch_f) (value->file)))) 71 (psiconv_sketch_f) (value->file))))
67 goto ERROR; 72 goto ERROR;
68 } else if (value->type == psiconv_mbm_file) { 73 } else if (value->type == psiconv_mbm_file) {
69 if ((res = psiconv_write_header_section(config,*buf,PSICONV_ID_PSION5, 74 if ((res = psiconv_write_header_section(config,*buf,lev+1,PSICONV_ID_PSION5,
70 PSICONV_ID_MBM_FILE, 75 PSICONV_ID_MBM_FILE,
71 0x00000000))) 76 0x00000000)))
72 goto ERROR; 77 goto ERROR;
73 if ((res =psiconv_write_mbm_file(config,*buf, 78 if ((res =psiconv_write_mbm_file(config,*buf,lev+1,
74 (psiconv_mbm_f) (value->file)))) 79 (psiconv_mbm_f) (value->file))))
75 goto ERROR; 80 goto ERROR;
76 } else if (value->type == psiconv_clipart_file) { 81 } else if (value->type == psiconv_clipart_file) {
77 /* No complete header section, so we do it all in the below function */ 82 /* No complete header section, so we do it all in the below function */
78 if ((res =psiconv_write_clipart_file(config,*buf, 83 if ((res =psiconv_write_clipart_file(config,*buf,lev+1,
79 (psiconv_clipart_f) (value->file)))) 84 (psiconv_clipart_f) (value->file))))
80 goto ERROR; 85 goto ERROR;
81 } else { 86 } else {
82 psiconv_warn(config,0,0,"Unknown or unsupported file type"); 87 psiconv_error(config,0,0,"Unknown or unsupported file type");
83 res = -PSICONV_E_GENERATE; 88 res = -PSICONV_E_GENERATE;
84 goto ERROR; 89 goto ERROR;
85 } 90 }
86 if ((res = psiconv_buffer_resolve(*buf))) 91 if ((res = psiconv_buffer_resolve(*buf)))
87 goto ERROR; 92 goto ERROR;
91 psiconv_buffer_free(*buf); 96 psiconv_buffer_free(*buf);
92 return res; 97 return res;
93} 98}
94 99
95int psiconv_write_texted_file(const psiconv_config config, 100int psiconv_write_texted_file(const psiconv_config config,
96 psiconv_buffer buf,psiconv_texted_f value) 101 psiconv_buffer buf,int lev,psiconv_texted_f value)
97{ 102{
98 psiconv_character_layout base_char; 103 psiconv_character_layout base_char;
99 psiconv_paragraph_layout base_para; 104 psiconv_paragraph_layout base_para;
100 int res; 105 int res;
101 psiconv_section_table_section section_table; 106 psiconv_section_table_section section_table;
102 psiconv_section_table_entry entry; 107 psiconv_section_table_entry entry;
103 psiconv_u32 section_table_id; 108 psiconv_u32 section_table_id;
104 psiconv_buffer buf_texted; 109 psiconv_buffer buf_texted;
105 110
111 psiconv_progress(config,lev,0,"Writing texted file");
106 if (!value) { 112 if (!value) {
107 psiconv_warn(config,0,0,"Null TextEd file"); 113 psiconv_error(config,0,0,"Null TextEd file");
108 return -PSICONV_E_GENERATE; 114 return -PSICONV_E_GENERATE;
109 } 115 }
110 116
111 if (!(section_table = psiconv_list_new(sizeof(*entry)))) { 117 if (!(section_table = psiconv_list_new(sizeof(*entry)))) {
112 res = -PSICONV_E_NOMEM; 118 res = -PSICONV_E_NOMEM;
126 res = -PSICONV_E_NOMEM; 132 res = -PSICONV_E_NOMEM;
127 goto ERROR4; 133 goto ERROR4;
128 } 134 }
129 135
130 section_table_id = psiconv_buffer_unique_id(); 136 section_table_id = psiconv_buffer_unique_id();
131 if ((res = psiconv_write_offset(config,buf,section_table_id))) 137 if ((res = psiconv_write_offset(config,buf,lev+1,section_table_id)))
132 goto ERROR5; 138 goto ERROR5;
133 139
134 entry->id = PSICONV_ID_APPL_ID_SECTION; 140 entry->id = PSICONV_ID_APPL_ID_SECTION;
135 entry->offset = psiconv_buffer_unique_id(); 141 entry->offset = psiconv_buffer_unique_id();
136 if ((res = psiconv_list_add(section_table,entry))) 142 if ((res = psiconv_list_add(section_table,entry)))
137 goto ERROR5; 143 goto ERROR5;
138 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 144 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
139 goto ERROR5; 145 goto ERROR5;
140 if ((res=psiconv_write_application_id_section(config,buf, 146 if ((res=psiconv_write_application_id_section(config,buf,lev+1,
141 PSICONV_ID_TEXTED,"TextEd.app"))) 147 PSICONV_ID_TEXTED,unicode_texted)))
142 goto ERROR5; 148 goto ERROR5;
143 149
144 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION; 150 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION;
145 entry->offset = psiconv_buffer_unique_id(); 151 entry->offset = psiconv_buffer_unique_id();
146 if ((res = psiconv_list_add(section_table,entry))) 152 if ((res = psiconv_list_add(section_table,entry)))
147 goto ERROR5; 153 goto ERROR5;
148 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 154 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
149 goto ERROR5; 155 goto ERROR5;
150 if ((res = psiconv_write_page_layout_section(config,buf,value->page_sec))) 156 if ((res = psiconv_write_page_layout_section(config,buf,lev+1,value->page_sec)))
151 goto ERROR5; 157 goto ERROR5;
152 158
153 entry->id = PSICONV_ID_TEXTED; 159 entry->id = PSICONV_ID_TEXTED;
154 entry->offset = psiconv_buffer_unique_id(); 160 entry->offset = psiconv_buffer_unique_id();
155 if ((res = psiconv_list_add(section_table,entry))) 161 if ((res = psiconv_list_add(section_table,entry)))
156 goto ERROR5; 162 goto ERROR5;
157 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 163 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
158 goto ERROR5; 164 goto ERROR5;
159 if ((res = psiconv_write_texted_section(config,buf,value->texted_sec, 165 if ((res = psiconv_write_texted_section(config,buf,lev+1,value->texted_sec,
160 base_char,base_para,&buf_texted))) 166 base_char,base_para,&buf_texted)))
161 goto ERROR5; 167 goto ERROR5;
162 168
163 if ((res = psiconv_buffer_concat(buf,buf_texted))) 169 if ((res = psiconv_buffer_concat(buf,buf_texted)))
164 goto ERROR6; 170 goto ERROR6;
165 171
166 172
167 if ((res = psiconv_buffer_add_target(buf,section_table_id))) 173 if ((res = psiconv_buffer_add_target(buf,section_table_id)))
168 goto ERROR6; 174 goto ERROR6;
169 175
170 res = psiconv_write_section_table_section(config,buf,section_table); 176 res = psiconv_write_section_table_section(config,buf,lev+1,section_table);
171 177
172ERROR6: 178ERROR6:
173 psiconv_buffer_free(buf_texted); 179 psiconv_buffer_free(buf_texted);
174ERROR5: 180ERROR5:
175 psiconv_free_paragraph_layout(base_para); 181 psiconv_free_paragraph_layout(base_para);
182ERROR1: 188ERROR1:
183 return res; 189 return res;
184} 190}
185 191
186int psiconv_write_word_file(const psiconv_config config, 192int psiconv_write_word_file(const psiconv_config config,
187 psiconv_buffer buf,psiconv_word_f value) 193 psiconv_buffer buf,int lev,psiconv_word_f value)
188{ 194{
189 int res; 195 int res;
190 psiconv_section_table_section section_table; 196 psiconv_section_table_section section_table;
191 psiconv_section_table_entry entry; 197 psiconv_section_table_entry entry;
192 psiconv_u32 section_table_id; 198 psiconv_u32 section_table_id;
193 199
200 psiconv_progress(config,lev,0,"Writing word file");
194 if (!value) { 201 if (!value) {
195 psiconv_warn(config,0,0,"Null Word file"); 202 psiconv_error(config,0,0,"Null Word file");
196 return -PSICONV_E_GENERATE; 203 return -PSICONV_E_GENERATE;
197 } 204 }
198 205
199 if (!(section_table = psiconv_list_new(sizeof(*entry)))) { 206 if (!(section_table = psiconv_list_new(sizeof(*entry)))) {
200 res = -PSICONV_E_NOMEM; 207 res = -PSICONV_E_NOMEM;
205 res = -PSICONV_E_NOMEM; 212 res = -PSICONV_E_NOMEM;
206 goto ERROR2; 213 goto ERROR2;
207 } 214 }
208 215
209 section_table_id = psiconv_buffer_unique_id(); 216 section_table_id = psiconv_buffer_unique_id();
210 if ((res = psiconv_write_offset(config,buf,section_table_id))) 217 if ((res = psiconv_write_offset(config,buf,lev+1,section_table_id)))
211 goto ERROR3; 218 goto ERROR3;
212 219
213 entry->id = PSICONV_ID_APPL_ID_SECTION; 220 entry->id = PSICONV_ID_APPL_ID_SECTION;
214 entry->offset = psiconv_buffer_unique_id(); 221 entry->offset = psiconv_buffer_unique_id();
215 if ((res = psiconv_list_add(section_table,entry))) 222 if ((res = psiconv_list_add(section_table,entry)))
216 goto ERROR3; 223 goto ERROR3;
217 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 224 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
218 goto ERROR3; 225 goto ERROR3;
219 if ((res=psiconv_write_application_id_section(config,buf, 226 if ((res=psiconv_write_application_id_section(config,buf,lev+1,
220 PSICONV_ID_WORD,"Word.app"))) 227 PSICONV_ID_WORD,unicode_word)))
221 goto ERROR3; 228 goto ERROR3;
222 229
223 entry->id = PSICONV_ID_WORD_STATUS_SECTION; 230 entry->id = PSICONV_ID_WORD_STATUS_SECTION;
224 entry->offset = psiconv_buffer_unique_id(); 231 entry->offset = psiconv_buffer_unique_id();
225 if ((res = psiconv_list_add(section_table,entry))) 232 if ((res = psiconv_list_add(section_table,entry)))
226 goto ERROR3; 233 goto ERROR3;
227 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 234 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
228 goto ERROR3; 235 goto ERROR3;
229 if ((res = psiconv_write_word_status_section(config,buf,value->status_sec))) 236 if ((res = psiconv_write_word_status_section(config,buf,lev+1,value->status_sec)))
230 goto ERROR3; 237 goto ERROR3;
231 238
232 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION; 239 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION;
233 entry->offset = psiconv_buffer_unique_id(); 240 entry->offset = psiconv_buffer_unique_id();
234 if ((res = psiconv_list_add(section_table,entry))) 241 if ((res = psiconv_list_add(section_table,entry)))
235 goto ERROR3; 242 goto ERROR3;
236 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 243 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
237 goto ERROR3; 244 goto ERROR3;
238 if ((res = psiconv_write_page_layout_section(config,buf,value->page_sec))) 245 if ((res = psiconv_write_page_layout_section(config,buf,lev+1,value->page_sec)))
239 goto ERROR3; 246 goto ERROR3;
240 247
241 entry->id = PSICONV_ID_WORD_STYLES_SECTION; 248 entry->id = PSICONV_ID_WORD_STYLES_SECTION;
242 entry->offset = psiconv_buffer_unique_id(); 249 entry->offset = psiconv_buffer_unique_id();
243 if ((res = psiconv_list_add(section_table,entry))) 250 if ((res = psiconv_list_add(section_table,entry)))
244 goto ERROR3; 251 goto ERROR3;
245 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 252 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
246 goto ERROR3; 253 goto ERROR3;
247 if ((res = psiconv_write_word_styles_section(config,buf,value->styles_sec))) 254 if ((res = psiconv_write_word_styles_section(config,buf,lev+1,value->styles_sec)))
248 goto ERROR3; 255 goto ERROR3;
249 256
250 entry->id = PSICONV_ID_TEXT_SECTION; 257 entry->id = PSICONV_ID_TEXT_SECTION;
251 entry->offset = psiconv_buffer_unique_id(); 258 entry->offset = psiconv_buffer_unique_id();
252 if ((res = psiconv_list_add(section_table,entry))) 259 if ((res = psiconv_list_add(section_table,entry)))
253 goto ERROR3; 260 goto ERROR3;
254 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 261 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
255 goto ERROR3; 262 goto ERROR3;
256 if ((res = psiconv_write_text_section(config,buf,value->paragraphs))) 263 if ((res = psiconv_write_text_section(config,buf,lev+1,value->paragraphs)))
257 goto ERROR3; 264 goto ERROR3;
258 265
259 entry->id = PSICONV_ID_LAYOUT_SECTION; 266 entry->id = PSICONV_ID_LAYOUT_SECTION;
260 entry->offset = psiconv_buffer_unique_id(); 267 entry->offset = psiconv_buffer_unique_id();
261 if ((res = psiconv_list_add(section_table,entry))) 268 if ((res = psiconv_list_add(section_table,entry)))
262 goto ERROR3; 269 goto ERROR3;
263 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 270 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
264 goto ERROR3; 271 goto ERROR3;
265 if ((res = psiconv_write_styled_layout_section(config,buf,value->paragraphs, 272 if ((res = psiconv_write_styled_layout_section(config,buf,lev+1,value->paragraphs,
266 value->styles_sec))) 273 value->styles_sec)))
267 goto ERROR3; 274 goto ERROR3;
268 275
269 if ((res = psiconv_buffer_add_target(buf,section_table_id))) 276 if ((res = psiconv_buffer_add_target(buf,section_table_id)))
270 goto ERROR3; 277 goto ERROR3;
271 278
272 res = psiconv_write_section_table_section(config,buf,section_table); 279 res = psiconv_write_section_table_section(config,buf,lev+1,section_table);
273 280
274ERROR3: 281ERROR3:
275 free(entry); 282 free(entry);
276ERROR2: 283ERROR2:
277 psiconv_list_free(section_table); 284 psiconv_list_free(section_table);
278ERROR1: 285ERROR1:
279 return res; 286 return res;
280} 287}
281 288
282int psiconv_write_sketch_file(const psiconv_config config, 289int psiconv_write_sketch_file(const psiconv_config config,
283 psiconv_buffer buf,psiconv_sketch_f value) 290 psiconv_buffer buf,int lev,psiconv_sketch_f value)
284{ 291{
285 int res; 292 int res;
286 psiconv_section_table_section section_table; 293 psiconv_section_table_section section_table;
287 psiconv_section_table_entry entry; 294 psiconv_section_table_entry entry;
288 psiconv_u32 section_table_id; 295 psiconv_u32 section_table_id;
289 296
297 psiconv_progress(config,lev,0,"Writing sketch file");
290 if (!value) { 298 if (!value) {
291 psiconv_warn(config,0,0,"Null Sketch file"); 299 psiconv_error(config,0,0,"Null Sketch file");
292 return -PSICONV_E_GENERATE; 300 return -PSICONV_E_GENERATE;
293 } 301 }
294 302
295 if (!(section_table = psiconv_list_new(sizeof(*entry)))) { 303 if (!(section_table = psiconv_list_new(sizeof(*entry)))) {
296 res = -PSICONV_E_NOMEM; 304 res = -PSICONV_E_NOMEM;
301 res = -PSICONV_E_NOMEM; 309 res = -PSICONV_E_NOMEM;
302 goto ERROR2; 310 goto ERROR2;
303 } 311 }
304 312
305 section_table_id = psiconv_buffer_unique_id(); 313 section_table_id = psiconv_buffer_unique_id();
306 if ((res = psiconv_write_offset(config,buf,section_table_id))) 314 if ((res = psiconv_write_offset(config,buf,lev+1,section_table_id)))
307 goto ERROR3; 315 goto ERROR3;
308 316
309 entry->id = PSICONV_ID_APPL_ID_SECTION; 317 entry->id = PSICONV_ID_APPL_ID_SECTION;
310 entry->offset = psiconv_buffer_unique_id(); 318 entry->offset = psiconv_buffer_unique_id();
311 if ((res = psiconv_list_add(section_table,entry))) 319 if ((res = psiconv_list_add(section_table,entry)))
312 goto ERROR3; 320 goto ERROR3;
313 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 321 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
314 goto ERROR3; 322 goto ERROR3;
315 if ((res=psiconv_write_application_id_section(config,buf, 323 if ((res=psiconv_write_application_id_section(config,buf,lev+1,
316 PSICONV_ID_SKETCH,"Paint.app"))) 324 PSICONV_ID_SKETCH,unicode_paint)))
317 goto ERROR3; 325 goto ERROR3;
318 326
319 entry->id = PSICONV_ID_SKETCH_SECTION; 327 entry->id = PSICONV_ID_SKETCH_SECTION;
320 entry->offset = psiconv_buffer_unique_id(); 328 entry->offset = psiconv_buffer_unique_id();
321 if ((res = psiconv_list_add(section_table,entry))) 329 if ((res = psiconv_list_add(section_table,entry)))
322 goto ERROR3; 330 goto ERROR3;
323 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 331 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
324 goto ERROR3; 332 goto ERROR3;
325 if ((res = psiconv_write_sketch_section(config,buf,value->sketch_sec))) 333 if ((res = psiconv_write_sketch_section(config,buf,lev+1,value->sketch_sec)))
326 goto ERROR3; 334 goto ERROR3;
327 335
328 if ((res = psiconv_buffer_add_target(buf,section_table_id))) 336 if ((res = psiconv_buffer_add_target(buf,section_table_id)))
329 goto ERROR3; 337 goto ERROR3;
330 res = psiconv_write_section_table_section(config,buf,section_table); 338 res = psiconv_write_section_table_section(config,buf,lev+1,section_table);
331 339
332ERROR3: 340ERROR3:
333 free(entry); 341 free(entry);
334ERROR2: 342ERROR2:
335 psiconv_list_free(section_table); 343 psiconv_list_free(section_table);
336ERROR1: 344ERROR1:
337 return res; 345 return res;
338} 346}
339 347
340int psiconv_write_mbm_file(const psiconv_config config, 348int psiconv_write_mbm_file(const psiconv_config config,
341 psiconv_buffer buf,psiconv_mbm_f value) 349 psiconv_buffer buf,int lev,psiconv_mbm_f value)
342{ 350{
343 int res,i; 351 int res,i;
344 psiconv_jumptable_section jumptable; 352 psiconv_jumptable_section jumptable;
345 psiconv_u32 *entry,id,table_id; 353 psiconv_u32 *entry,id,table_id;
346 psiconv_paint_data_section section; 354 psiconv_paint_data_section section;
347 355
356 psiconv_progress(config,lev,0,"Writing mbm file");
348 if (!value) { 357 if (!value) {
349 psiconv_warn(config,0,0,"Null MBM file"); 358 psiconv_error(config,0,0,"Null MBM file");
350 return -PSICONV_E_GENERATE; 359 return -PSICONV_E_GENERATE;
351 } 360 }
352 361
353 if (!(jumptable = psiconv_list_new(sizeof(*entry)))) { 362 if (!(jumptable = psiconv_list_new(sizeof(*entry)))) {
354 res = -PSICONV_E_NOMEM; 363 res = -PSICONV_E_NOMEM;
359 if ((res = psiconv_buffer_add_reference(buf,table_id))) 368 if ((res = psiconv_buffer_add_reference(buf,table_id)))
360 goto ERROR2; 369 goto ERROR2;
361 370
362 for (i = 0; i < psiconv_list_length(value->sections); i++) { 371 for (i = 0; i < psiconv_list_length(value->sections); i++) {
363 if (!(section = psiconv_list_get(value->sections,i))) { 372 if (!(section = psiconv_list_get(value->sections,i))) {
364 psiconv_warn(config,0,0,"Massive memory corruption"); 373 psiconv_error(config,0,0,"Massive memory corruption");
365 res = -PSICONV_E_NOMEM; 374 res = -PSICONV_E_NOMEM;
366 goto ERROR2; 375 goto ERROR2;
367 } 376 }
368 id = psiconv_buffer_unique_id(); 377 id = psiconv_buffer_unique_id();
369 psiconv_list_add(jumptable,&id); 378 psiconv_list_add(jumptable,&id);
370 if ((res = psiconv_buffer_add_target(buf,id))) 379 if ((res = psiconv_buffer_add_target(buf,id)))
371 goto ERROR2; 380 goto ERROR2;
372 if ((res = psiconv_write_paint_data_section(config,buf,section,0))) 381 if ((res = psiconv_write_paint_data_section(config,buf,lev+1,section,0)))
373 goto ERROR2; 382 goto ERROR2;
374 } 383 }
375 384
376 if ((res = psiconv_buffer_add_target(buf,table_id))) 385 if ((res = psiconv_buffer_add_target(buf,table_id)))
377 goto ERROR2; 386 goto ERROR2;
378 if ((res = psiconv_write_jumptable_section(config,buf,jumptable))) 387 if ((res = psiconv_write_jumptable_section(config,buf,lev+1,jumptable)))
379 goto ERROR2; 388 goto ERROR2;
380 389
381 390
382ERROR2: 391ERROR2:
383 psiconv_list_free(jumptable); 392 psiconv_list_free(jumptable);
385 return res; 394 return res;
386} 395}
387 396
388/* Note: this file is special, because it does not have a complete header! */ 397/* Note: this file is special, because it does not have a complete header! */
389int psiconv_write_clipart_file(const psiconv_config config, 398int psiconv_write_clipart_file(const psiconv_config config,
390 psiconv_buffer buf,psiconv_clipart_f value) 399 psiconv_buffer buf,int lev,psiconv_clipart_f value)
391{ 400{
392 int res,i; 401 int res,i;
393 psiconv_jumptable_section jumptable; 402 psiconv_jumptable_section jumptable;
394 psiconv_u32 *entry,id; 403 psiconv_u32 *entry,id;
395 psiconv_clipart_section section; 404 psiconv_clipart_section section;
396 psiconv_buffer sec_buf; 405 psiconv_buffer sec_buf;
397 406
407 psiconv_progress(config,lev,0,"Writing clipart file");
398 if (!value) { 408 if (!value) {
399 psiconv_warn(config,0,0,"Null Clipart file"); 409 psiconv_error(config,0,0,"Null Clipart file");
400 return -PSICONV_E_GENERATE; 410 return -PSICONV_E_GENERATE;
401 } 411 }
402 412
403 if (!(jumptable = psiconv_list_new(sizeof(*entry)))) { 413 if (!(jumptable = psiconv_list_new(sizeof(*entry)))) {
404 res = -PSICONV_E_NOMEM; 414 res = -PSICONV_E_NOMEM;
408 if (!(sec_buf = psiconv_buffer_new())) { 418 if (!(sec_buf = psiconv_buffer_new())) {
409 res = -PSICONV_E_NOMEM; 419 res = -PSICONV_E_NOMEM;
410 goto ERROR2; 420 goto ERROR2;
411 } 421 }
412 422
413 if ((res = psiconv_write_u32(config,buf,PSICONV_ID_CLIPART))) 423 if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_CLIPART)))
414 goto ERROR3; 424 goto ERROR3;
415 425
416 for (i = 0; i < psiconv_list_length(value->sections); i++) { 426 for (i = 0; i < psiconv_list_length(value->sections); i++) {
417 if (!(section = psiconv_list_get(value->sections,i))) { 427 if (!(section = psiconv_list_get(value->sections,i))) {
418 psiconv_warn(config,0,0,"Massive memory corruption"); 428 psiconv_error(config,0,0,"Massive memory corruption");
419 res = -PSICONV_E_NOMEM; 429 res = -PSICONV_E_NOMEM;
420 goto ERROR3; 430 goto ERROR3;
421 } 431 }
422 id = psiconv_buffer_unique_id(); 432 id = psiconv_buffer_unique_id();
423 psiconv_list_add(jumptable,&id); 433 psiconv_list_add(jumptable,&id);
424 if ((res = psiconv_buffer_add_target(sec_buf,id))) 434 if ((res = psiconv_buffer_add_target(sec_buf,id)))
425 goto ERROR3; 435 goto ERROR3;
426 if ((res = psiconv_write_clipart_section(config,sec_buf, section))) 436 if ((res = psiconv_write_clipart_section(config,sec_buf, lev+1,section)))
427 goto ERROR3; 437 goto ERROR3;
428 } 438 }
429 439
430 if ((res = psiconv_write_jumptable_section(config,buf,jumptable))) 440 if ((res = psiconv_write_jumptable_section(config,buf,lev+1,jumptable)))
431 goto ERROR3; 441 goto ERROR3;
432 442
433 if ((res = psiconv_buffer_concat(buf,sec_buf))) 443 if ((res = psiconv_buffer_concat(buf,sec_buf)))
434 goto ERROR3; 444 goto ERROR3;
435 445

Legend:
Removed from v.183  
changed lines
  Added in v.184

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