/[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 171 Revision 196
1/* 1/*
2 generate_driver.c - Part of psiconv, a PSION 5 file formats converter 2 generate_driver.c - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 2000 Frodo Looijaard <frodol@dds.nl> 3 Copyright (c) 2000-2004 Frodo Looijaard <frodol@dds.nl>
4 4
5 This program is free software; you can redistribute it and/or modify 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 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 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
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#if 0
77 } else if (value->type == psiconv_clipart_file) { 81 } else if (value->type == psiconv_clipart_file) {
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#endif
82 } else { 86 } else {
83 psiconv_warn(config,0,0,"Unknown or unsupported file type"); 87 psiconv_error(config,0,0,"Unknown or unsupported file type");
84 res = -PSICONV_E_GENERATE; 88 res = -PSICONV_E_GENERATE;
85 goto ERROR; 89 goto ERROR;
86 } 90 }
87 if ((res = psiconv_buffer_resolve(*buf))) 91 if ((res = psiconv_buffer_resolve(*buf)))
88 goto ERROR; 92 goto ERROR;
92 psiconv_buffer_free(*buf); 96 psiconv_buffer_free(*buf);
93 return res; 97 return res;
94} 98}
95 99
96int psiconv_write_texted_file(const psiconv_config config, 100int psiconv_write_texted_file(const psiconv_config config,
97 psiconv_buffer buf,psiconv_texted_f value) 101 psiconv_buffer buf,int lev,psiconv_texted_f value)
98{ 102{
99 psiconv_character_layout base_char; 103 psiconv_character_layout base_char;
100 psiconv_paragraph_layout base_para; 104 psiconv_paragraph_layout base_para;
101 int res; 105 int res;
102 psiconv_section_table_section section_table; 106 psiconv_section_table_section section_table;
103 psiconv_section_table_entry entry; 107 psiconv_section_table_entry entry;
104 psiconv_u32 section_table_id; 108 psiconv_u32 section_table_id;
105 psiconv_buffer buf_texted; 109 psiconv_buffer buf_texted;
106 110
111 psiconv_progress(config,lev,0,"Writing texted file");
107 if (!value) { 112 if (!value) {
108 psiconv_warn(config,0,0,"Null TextEd file"); 113 psiconv_error(config,0,0,"Null TextEd file");
109 return -PSICONV_E_GENERATE; 114 return -PSICONV_E_GENERATE;
110 } 115 }
111 116
112 if (!(section_table = psiconv_list_new(sizeof(*entry)))) { 117 if (!(section_table = psiconv_list_new(sizeof(*entry)))) {
113 res = -PSICONV_E_NOMEM; 118 res = -PSICONV_E_NOMEM;
127 res = -PSICONV_E_NOMEM; 132 res = -PSICONV_E_NOMEM;
128 goto ERROR4; 133 goto ERROR4;
129 } 134 }
130 135
131 section_table_id = psiconv_buffer_unique_id(); 136 section_table_id = psiconv_buffer_unique_id();
132 if ((res = psiconv_write_offset(config,buf,section_table_id))) 137 if ((res = psiconv_write_offset(config,buf,lev+1,section_table_id)))
133 goto ERROR5; 138 goto ERROR5;
134 139
135 entry->id = PSICONV_ID_APPL_ID_SECTION; 140 entry->id = PSICONV_ID_APPL_ID_SECTION;
136 entry->offset = psiconv_buffer_unique_id(); 141 entry->offset = psiconv_buffer_unique_id();
137 if ((res = psiconv_list_add(section_table,entry))) 142 if ((res = psiconv_list_add(section_table,entry)))
138 goto ERROR5; 143 goto ERROR5;
139 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 144 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
140 goto ERROR5; 145 goto ERROR5;
141 if ((res=psiconv_write_application_id_section(config,buf, 146 if ((res=psiconv_write_application_id_section(config,buf,lev+1,
142 PSICONV_ID_TEXTED,"TextEd.app"))) 147 PSICONV_ID_TEXTED,unicode_texted)))
143 goto ERROR5; 148 goto ERROR5;
144 149
145 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION; 150 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION;
146 entry->offset = psiconv_buffer_unique_id(); 151 entry->offset = psiconv_buffer_unique_id();
147 if ((res = psiconv_list_add(section_table,entry))) 152 if ((res = psiconv_list_add(section_table,entry)))
148 goto ERROR5; 153 goto ERROR5;
149 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 154 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
150 goto ERROR5; 155 goto ERROR5;
151 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)))
152 goto ERROR5; 157 goto ERROR5;
153 158
154 entry->id = PSICONV_ID_TEXTED; 159 entry->id = PSICONV_ID_TEXTED;
155 entry->offset = psiconv_buffer_unique_id(); 160 entry->offset = psiconv_buffer_unique_id();
156 if ((res = psiconv_list_add(section_table,entry))) 161 if ((res = psiconv_list_add(section_table,entry)))
157 goto ERROR5; 162 goto ERROR5;
158 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 163 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
159 goto ERROR5; 164 goto ERROR5;
160 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,
161 base_char,base_para,&buf_texted))) 166 base_char,base_para,&buf_texted)))
162 goto ERROR5; 167 goto ERROR5;
163 168
164 if ((res = psiconv_buffer_concat(buf,buf_texted))) 169 if ((res = psiconv_buffer_concat(buf,buf_texted)))
165 goto ERROR6; 170 goto ERROR6;
166 171
167 172
168 if ((res = psiconv_buffer_add_target(buf,section_table_id))) 173 if ((res = psiconv_buffer_add_target(buf,section_table_id)))
169 goto ERROR6; 174 goto ERROR6;
170 175
171 res = psiconv_write_section_table_section(config,buf,section_table); 176 res = psiconv_write_section_table_section(config,buf,lev+1,section_table);
172 177
173ERROR6: 178ERROR6:
174 psiconv_buffer_free(buf_texted); 179 psiconv_buffer_free(buf_texted);
175ERROR5: 180ERROR5:
176 psiconv_free_paragraph_layout(base_para); 181 psiconv_free_paragraph_layout(base_para);
183ERROR1: 188ERROR1:
184 return res; 189 return res;
185} 190}
186 191
187int psiconv_write_word_file(const psiconv_config config, 192int psiconv_write_word_file(const psiconv_config config,
188 psiconv_buffer buf,psiconv_word_f value) 193 psiconv_buffer buf,int lev,psiconv_word_f value)
189{ 194{
190 int res; 195 int res;
191 psiconv_section_table_section section_table; 196 psiconv_section_table_section section_table;
192 psiconv_section_table_entry entry; 197 psiconv_section_table_entry entry;
193 psiconv_u32 section_table_id; 198 psiconv_u32 section_table_id;
194 199
200 psiconv_progress(config,lev,0,"Writing word file");
195 if (!value) { 201 if (!value) {
196 psiconv_warn(config,0,0,"Null Word file"); 202 psiconv_error(config,0,0,"Null Word file");
197 return -PSICONV_E_GENERATE; 203 return -PSICONV_E_GENERATE;
198 } 204 }
199 205
200 if (!(section_table = psiconv_list_new(sizeof(*entry)))) { 206 if (!(section_table = psiconv_list_new(sizeof(*entry)))) {
201 res = -PSICONV_E_NOMEM; 207 res = -PSICONV_E_NOMEM;
206 res = -PSICONV_E_NOMEM; 212 res = -PSICONV_E_NOMEM;
207 goto ERROR2; 213 goto ERROR2;
208 } 214 }
209 215
210 section_table_id = psiconv_buffer_unique_id(); 216 section_table_id = psiconv_buffer_unique_id();
211 if ((res = psiconv_write_offset(config,buf,section_table_id))) 217 if ((res = psiconv_write_offset(config,buf,lev+1,section_table_id)))
212 goto ERROR3; 218 goto ERROR3;
213 219
214 entry->id = PSICONV_ID_APPL_ID_SECTION; 220 entry->id = PSICONV_ID_APPL_ID_SECTION;
215 entry->offset = psiconv_buffer_unique_id(); 221 entry->offset = psiconv_buffer_unique_id();
216 if ((res = psiconv_list_add(section_table,entry))) 222 if ((res = psiconv_list_add(section_table,entry)))
217 goto ERROR3; 223 goto ERROR3;
218 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 224 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
219 goto ERROR3; 225 goto ERROR3;
220 if ((res=psiconv_write_application_id_section(config,buf, 226 if ((res=psiconv_write_application_id_section(config,buf,lev+1,
221 PSICONV_ID_WORD,"Word.app"))) 227 PSICONV_ID_WORD,unicode_word)))
222 goto ERROR3; 228 goto ERROR3;
223 229
224 entry->id = PSICONV_ID_WORD_STATUS_SECTION; 230 entry->id = PSICONV_ID_WORD_STATUS_SECTION;
225 entry->offset = psiconv_buffer_unique_id(); 231 entry->offset = psiconv_buffer_unique_id();
226 if ((res = psiconv_list_add(section_table,entry))) 232 if ((res = psiconv_list_add(section_table,entry)))
227 goto ERROR3; 233 goto ERROR3;
228 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 234 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
229 goto ERROR3; 235 goto ERROR3;
230 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)))
231 goto ERROR3; 237 goto ERROR3;
232 238
233 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION; 239 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION;
234 entry->offset = psiconv_buffer_unique_id(); 240 entry->offset = psiconv_buffer_unique_id();
235 if ((res = psiconv_list_add(section_table,entry))) 241 if ((res = psiconv_list_add(section_table,entry)))
236 goto ERROR3; 242 goto ERROR3;
237 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 243 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
238 goto ERROR3; 244 goto ERROR3;
239 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)))
240 goto ERROR3; 246 goto ERROR3;
241 247
242 entry->id = PSICONV_ID_WORD_STYLES_SECTION; 248 entry->id = PSICONV_ID_WORD_STYLES_SECTION;
243 entry->offset = psiconv_buffer_unique_id(); 249 entry->offset = psiconv_buffer_unique_id();
244 if ((res = psiconv_list_add(section_table,entry))) 250 if ((res = psiconv_list_add(section_table,entry)))
245 goto ERROR3; 251 goto ERROR3;
246 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 252 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
247 goto ERROR3; 253 goto ERROR3;
248 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)))
249 goto ERROR3; 255 goto ERROR3;
250 256
251 entry->id = PSICONV_ID_TEXT_SECTION; 257 entry->id = PSICONV_ID_TEXT_SECTION;
252 entry->offset = psiconv_buffer_unique_id(); 258 entry->offset = psiconv_buffer_unique_id();
253 if ((res = psiconv_list_add(section_table,entry))) 259 if ((res = psiconv_list_add(section_table,entry)))
254 goto ERROR3; 260 goto ERROR3;
255 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 261 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
256 goto ERROR3; 262 goto ERROR3;
257 if ((res = psiconv_write_text_section(config,buf,value->paragraphs))) 263 if ((res = psiconv_write_text_section(config,buf,lev+1,value->paragraphs)))
258 goto ERROR3; 264 goto ERROR3;
259 265
260 entry->id = PSICONV_ID_LAYOUT_SECTION; 266 entry->id = PSICONV_ID_LAYOUT_SECTION;
261 entry->offset = psiconv_buffer_unique_id(); 267 entry->offset = psiconv_buffer_unique_id();
262 if ((res = psiconv_list_add(section_table,entry))) 268 if ((res = psiconv_list_add(section_table,entry)))
263 goto ERROR3; 269 goto ERROR3;
264 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 270 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
265 goto ERROR3; 271 goto ERROR3;
266 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,
267 value->styles_sec))) 273 value->styles_sec)))
268 goto ERROR3; 274 goto ERROR3;
269 275
270 if ((res = psiconv_buffer_add_target(buf,section_table_id))) 276 if ((res = psiconv_buffer_add_target(buf,section_table_id)))
271 goto ERROR3; 277 goto ERROR3;
272 278
273 res = psiconv_write_section_table_section(config,buf,section_table); 279 res = psiconv_write_section_table_section(config,buf,lev+1,section_table);
274 280
275ERROR3: 281ERROR3:
276 free(entry); 282 free(entry);
277ERROR2: 283ERROR2:
278 psiconv_list_free(section_table); 284 psiconv_list_free(section_table);
279ERROR1: 285ERROR1:
280 return res; 286 return res;
281} 287}
282 288
283int psiconv_write_sketch_file(const psiconv_config config, 289int psiconv_write_sketch_file(const psiconv_config config,
284 psiconv_buffer buf,psiconv_sketch_f value) 290 psiconv_buffer buf,int lev,psiconv_sketch_f value)
285{ 291{
286 int res; 292 int res;
287 psiconv_section_table_section section_table; 293 psiconv_section_table_section section_table;
288 psiconv_section_table_entry entry; 294 psiconv_section_table_entry entry;
289 psiconv_u32 section_table_id; 295 psiconv_u32 section_table_id;
290 296
297 psiconv_progress(config,lev,0,"Writing sketch file");
291 if (!value) { 298 if (!value) {
292 psiconv_warn(config,0,0,"Null Sketch file"); 299 psiconv_error(config,0,0,"Null Sketch file");
293 return -PSICONV_E_GENERATE; 300 return -PSICONV_E_GENERATE;
294 } 301 }
295 302
296 if (!(section_table = psiconv_list_new(sizeof(*entry)))) { 303 if (!(section_table = psiconv_list_new(sizeof(*entry)))) {
297 res = -PSICONV_E_NOMEM; 304 res = -PSICONV_E_NOMEM;
302 res = -PSICONV_E_NOMEM; 309 res = -PSICONV_E_NOMEM;
303 goto ERROR2; 310 goto ERROR2;
304 } 311 }
305 312
306 section_table_id = psiconv_buffer_unique_id(); 313 section_table_id = psiconv_buffer_unique_id();
307 if ((res = psiconv_write_offset(config,buf,section_table_id))) 314 if ((res = psiconv_write_offset(config,buf,lev+1,section_table_id)))
308 goto ERROR3; 315 goto ERROR3;
309 316
310 entry->id = PSICONV_ID_APPL_ID_SECTION; 317 entry->id = PSICONV_ID_APPL_ID_SECTION;
311 entry->offset = psiconv_buffer_unique_id(); 318 entry->offset = psiconv_buffer_unique_id();
312 if ((res = psiconv_list_add(section_table,entry))) 319 if ((res = psiconv_list_add(section_table,entry)))
313 goto ERROR3; 320 goto ERROR3;
314 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 321 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
315 goto ERROR3; 322 goto ERROR3;
316 if ((res=psiconv_write_application_id_section(config,buf, 323 if ((res=psiconv_write_application_id_section(config,buf,lev+1,
317 PSICONV_ID_SKETCH,"Paint.app"))) 324 PSICONV_ID_SKETCH,unicode_paint)))
318 goto ERROR3; 325 goto ERROR3;
319 326
320 entry->id = PSICONV_ID_SKETCH_SECTION; 327 entry->id = PSICONV_ID_SKETCH_SECTION;
321 entry->offset = psiconv_buffer_unique_id(); 328 entry->offset = psiconv_buffer_unique_id();
322 if ((res = psiconv_list_add(section_table,entry))) 329 if ((res = psiconv_list_add(section_table,entry)))
323 goto ERROR3; 330 goto ERROR3;
324 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 331 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
325 goto ERROR3; 332 goto ERROR3;
326 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)))
327 goto ERROR3; 334 goto ERROR3;
328 335
329 if ((res = psiconv_buffer_add_target(buf,section_table_id))) 336 if ((res = psiconv_buffer_add_target(buf,section_table_id)))
330 goto ERROR3; 337 goto ERROR3;
331 res = psiconv_write_section_table_section(config,buf,section_table); 338 res = psiconv_write_section_table_section(config,buf,lev+1,section_table);
332 339
333ERROR3: 340ERROR3:
334 free(entry); 341 free(entry);
335ERROR2: 342ERROR2:
336 psiconv_list_free(section_table); 343 psiconv_list_free(section_table);
337ERROR1: 344ERROR1:
338 return res; 345 return res;
339} 346}
340 347
341int psiconv_write_mbm_file(const psiconv_config config, 348int psiconv_write_mbm_file(const psiconv_config config,
342 psiconv_buffer buf,psiconv_mbm_f value) 349 psiconv_buffer buf,int lev,psiconv_mbm_f value)
343{ 350{
344 int res,i; 351 int res,i;
345 psiconv_jumptable_section jumptable; 352 psiconv_jumptable_section jumptable;
346 psiconv_u32 *entry,id,table_id; 353 psiconv_u32 *entry,id,table_id;
347 psiconv_paint_data_section section; 354 psiconv_paint_data_section section;
348 355
356 psiconv_progress(config,lev,0,"Writing mbm file");
349 if (!value) { 357 if (!value) {
350 psiconv_warn(config,0,0,"Null MBM file"); 358 psiconv_error(config,0,0,"Null MBM file");
351 return -PSICONV_E_GENERATE; 359 return -PSICONV_E_GENERATE;
352 } 360 }
353 361
354 if (!(jumptable = psiconv_list_new(sizeof(*entry)))) { 362 if (!(jumptable = psiconv_list_new(sizeof(*entry)))) {
355 res = -PSICONV_E_NOMEM; 363 res = -PSICONV_E_NOMEM;
360 if ((res = psiconv_buffer_add_reference(buf,table_id))) 368 if ((res = psiconv_buffer_add_reference(buf,table_id)))
361 goto ERROR2; 369 goto ERROR2;
362 370
363 for (i = 0; i < psiconv_list_length(value->sections); i++) { 371 for (i = 0; i < psiconv_list_length(value->sections); i++) {
364 if (!(section = psiconv_list_get(value->sections,i))) { 372 if (!(section = psiconv_list_get(value->sections,i))) {
365 psiconv_warn(config,0,0,"Massive memory corruption"); 373 psiconv_error(config,0,0,"Massive memory corruption");
366 res = -PSICONV_E_NOMEM; 374 res = -PSICONV_E_NOMEM;
367 goto ERROR2; 375 goto ERROR2;
368 } 376 }
369 id = psiconv_buffer_unique_id(); 377 id = psiconv_buffer_unique_id();
370 psiconv_list_add(jumptable,&id); 378 psiconv_list_add(jumptable,&id);
371 if ((res = psiconv_buffer_add_target(buf,id))) 379 if ((res = psiconv_buffer_add_target(buf,id)))
372 goto ERROR2; 380 goto ERROR2;
373 if ((res = psiconv_write_paint_data_section(config,buf,section))) 381 if ((res = psiconv_write_paint_data_section(config,buf,lev+1,section,0)))
374 goto ERROR2; 382 goto ERROR2;
375 } 383 }
376 384
377 if ((res = psiconv_buffer_add_target(buf,table_id))) 385 if ((res = psiconv_buffer_add_target(buf,table_id)))
378 goto ERROR2; 386 goto ERROR2;
379 if ((res = psiconv_write_jumptable_section(config,buf,jumptable))) 387 if ((res = psiconv_write_jumptable_section(config,buf,lev+1,jumptable)))
380 goto ERROR2; 388 goto ERROR2;
381 389
382 390
383ERROR2: 391ERROR2:
384 psiconv_list_free(jumptable); 392 psiconv_list_free(jumptable);
385ERROR1: 393ERROR1:
386 return res; 394 return res;
387} 395}
396
397/* Note: this file is special, because it does not have a complete header! */
398int psiconv_write_clipart_file(const psiconv_config config,
399 psiconv_buffer buf,int lev,psiconv_clipart_f value)
400{
401 int res,i;
402 psiconv_jumptable_section jumptable;
403 psiconv_u32 *entry,id;
404 psiconv_clipart_section section;
405 psiconv_buffer sec_buf;
406
407 psiconv_progress(config,lev,0,"Writing clipart file");
408 if (!value) {
409 psiconv_error(config,0,0,"Null Clipart file");
410 return -PSICONV_E_GENERATE;
411 }
412
413 if (!(jumptable = psiconv_list_new(sizeof(*entry)))) {
414 res = -PSICONV_E_NOMEM;
415 goto ERROR1;
416 }
417
418 if (!(sec_buf = psiconv_buffer_new())) {
419 res = -PSICONV_E_NOMEM;
420 goto ERROR2;
421 }
422
423 if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_CLIPART)))
424 goto ERROR3;
425
426 for (i = 0; i < psiconv_list_length(value->sections); i++) {
427 if (!(section = psiconv_list_get(value->sections,i))) {
428 psiconv_error(config,0,0,"Massive memory corruption");
429 res = -PSICONV_E_NOMEM;
430 goto ERROR3;
431 }
432 id = psiconv_buffer_unique_id();
433 psiconv_list_add(jumptable,&id);
434 if ((res = psiconv_buffer_add_target(sec_buf,id)))
435 goto ERROR3;
436 if ((res = psiconv_write_clipart_section(config,sec_buf, lev+1,section)))
437 goto ERROR3;
438 }
439
440 if ((res = psiconv_write_jumptable_section(config,buf,lev+1,jumptable)))
441 goto ERROR3;
442
443 if ((res = psiconv_buffer_concat(buf,sec_buf)))
444 goto ERROR3;
445
446
447ERROR3:
448 psiconv_buffer_free(sec_buf);
449ERROR2:
450 psiconv_list_free(jumptable);
451ERROR1:
452 return res;
453}

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

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