/[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 174 Revision 231
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 } 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,lev,0,"Null TextEd file");
108 return -PSICONV_E_GENERATE; 114 res = -PSICONV_E_GENERATE;
115 goto ERROR1;
109 } 116 }
110 117
111 if (!(section_table = psiconv_list_new(sizeof(*entry)))) { 118 if (!(section_table = psiconv_list_new(sizeof(*entry)))) {
112 res = -PSICONV_E_NOMEM; 119 res = -PSICONV_E_NOMEM;
113 goto ERROR1; 120 goto ERROR1;
126 res = -PSICONV_E_NOMEM; 133 res = -PSICONV_E_NOMEM;
127 goto ERROR4; 134 goto ERROR4;
128 } 135 }
129 136
130 section_table_id = psiconv_buffer_unique_id(); 137 section_table_id = psiconv_buffer_unique_id();
131 if ((res = psiconv_write_offset(config,buf,section_table_id))) 138 if ((res = psiconv_write_offset(config,buf,lev+1,section_table_id)))
132 goto ERROR5; 139 goto ERROR5;
133 140
134 entry->id = PSICONV_ID_APPL_ID_SECTION; 141 entry->id = PSICONV_ID_APPL_ID_SECTION;
135 entry->offset = psiconv_buffer_unique_id(); 142 entry->offset = psiconv_buffer_unique_id();
136 if ((res = psiconv_list_add(section_table,entry))) 143 if ((res = psiconv_list_add(section_table,entry)))
137 goto ERROR5; 144 goto ERROR5;
138 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 145 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
139 goto ERROR5; 146 goto ERROR5;
140 if ((res=psiconv_write_application_id_section(config,buf, 147 if ((res=psiconv_write_application_id_section(config,buf,lev+1,
141 PSICONV_ID_TEXTED,"TextEd.app"))) 148 PSICONV_ID_TEXTED,unicode_texted)))
142 goto ERROR5; 149 goto ERROR5;
143 150
144 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION; 151 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION;
145 entry->offset = psiconv_buffer_unique_id(); 152 entry->offset = psiconv_buffer_unique_id();
146 if ((res = psiconv_list_add(section_table,entry))) 153 if ((res = psiconv_list_add(section_table,entry)))
147 goto ERROR5; 154 goto ERROR5;
148 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 155 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
149 goto ERROR5; 156 goto ERROR5;
150 if ((res = psiconv_write_page_layout_section(config,buf,value->page_sec))) 157 if ((res = psiconv_write_page_layout_section(config,buf,lev+1,value->page_sec)))
151 goto ERROR5; 158 goto ERROR5;
152 159
153 entry->id = PSICONV_ID_TEXTED; 160 entry->id = PSICONV_ID_TEXTED;
154 entry->offset = psiconv_buffer_unique_id(); 161 entry->offset = psiconv_buffer_unique_id();
155 if ((res = psiconv_list_add(section_table,entry))) 162 if ((res = psiconv_list_add(section_table,entry)))
156 goto ERROR5; 163 goto ERROR5;
157 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 164 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
158 goto ERROR5; 165 goto ERROR5;
159 if ((res = psiconv_write_texted_section(config,buf,value->texted_sec, 166 if ((res = psiconv_write_texted_section(config,buf,lev+1,value->texted_sec,
160 base_char,base_para,&buf_texted))) 167 base_char,base_para,&buf_texted)))
161 goto ERROR5; 168 goto ERROR5;
162 169
163 if ((res = psiconv_buffer_concat(buf,buf_texted))) 170 if ((res = psiconv_buffer_concat(buf,buf_texted)))
164 goto ERROR6; 171 goto ERROR6;
165 172
166 173
167 if ((res = psiconv_buffer_add_target(buf,section_table_id))) 174 if ((res = psiconv_buffer_add_target(buf,section_table_id)))
168 goto ERROR6; 175 goto ERROR6;
169 176
170 res = psiconv_write_section_table_section(config,buf,section_table); 177 res = psiconv_write_section_table_section(config,buf,lev+1,section_table);
171 178
172ERROR6: 179ERROR6:
173 psiconv_buffer_free(buf_texted); 180 psiconv_buffer_free(buf_texted);
174ERROR5: 181ERROR5:
175 psiconv_free_paragraph_layout(base_para); 182 psiconv_free_paragraph_layout(base_para);
178ERROR3: 185ERROR3:
179 free(entry); 186 free(entry);
180ERROR2: 187ERROR2:
181 psiconv_list_free(section_table); 188 psiconv_list_free(section_table);
182ERROR1: 189ERROR1:
190 if (res)
191 psiconv_error(config,lev,0,"Writing of texted file failed");
192 else
193 psiconv_progress(config,lev,0,"End of texted file");
183 return res; 194 return res;
184} 195}
185 196
186int psiconv_write_word_file(const psiconv_config config, 197int psiconv_write_word_file(const psiconv_config config,
187 psiconv_buffer buf,psiconv_word_f value) 198 psiconv_buffer buf,int lev,psiconv_word_f value)
188{ 199{
189 int res; 200 int res;
190 psiconv_section_table_section section_table; 201 psiconv_section_table_section section_table;
191 psiconv_section_table_entry entry; 202 psiconv_section_table_entry entry;
192 psiconv_u32 section_table_id; 203 psiconv_u32 section_table_id;
193 204
205 psiconv_progress(config,lev,0,"Writing word file");
194 if (!value) { 206 if (!value) {
195 psiconv_warn(config,0,0,"Null Word file"); 207 psiconv_error(config,lev,0,"Null Word file");
196 return -PSICONV_E_GENERATE; 208 res = -PSICONV_E_GENERATE;
209 goto ERROR1;
197 } 210 }
198 211
199 if (!(section_table = psiconv_list_new(sizeof(*entry)))) { 212 if (!(section_table = psiconv_list_new(sizeof(*entry)))) {
200 res = -PSICONV_E_NOMEM; 213 res = -PSICONV_E_NOMEM;
201 goto ERROR1; 214 goto ERROR1;
205 res = -PSICONV_E_NOMEM; 218 res = -PSICONV_E_NOMEM;
206 goto ERROR2; 219 goto ERROR2;
207 } 220 }
208 221
209 section_table_id = psiconv_buffer_unique_id(); 222 section_table_id = psiconv_buffer_unique_id();
210 if ((res = psiconv_write_offset(config,buf,section_table_id))) 223 if ((res = psiconv_write_offset(config,buf,lev+1,section_table_id)))
211 goto ERROR3; 224 goto ERROR3;
212 225
213 entry->id = PSICONV_ID_APPL_ID_SECTION; 226 entry->id = PSICONV_ID_APPL_ID_SECTION;
214 entry->offset = psiconv_buffer_unique_id(); 227 entry->offset = psiconv_buffer_unique_id();
215 if ((res = psiconv_list_add(section_table,entry))) 228 if ((res = psiconv_list_add(section_table,entry)))
216 goto ERROR3; 229 goto ERROR3;
217 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 230 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
218 goto ERROR3; 231 goto ERROR3;
219 if ((res=psiconv_write_application_id_section(config,buf, 232 if ((res=psiconv_write_application_id_section(config,buf,lev+1,
220 PSICONV_ID_WORD,"Word.app"))) 233 PSICONV_ID_WORD,unicode_word)))
221 goto ERROR3; 234 goto ERROR3;
222 235
223 entry->id = PSICONV_ID_WORD_STATUS_SECTION; 236 entry->id = PSICONV_ID_WORD_STATUS_SECTION;
224 entry->offset = psiconv_buffer_unique_id(); 237 entry->offset = psiconv_buffer_unique_id();
225 if ((res = psiconv_list_add(section_table,entry))) 238 if ((res = psiconv_list_add(section_table,entry)))
226 goto ERROR3; 239 goto ERROR3;
227 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 240 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
228 goto ERROR3; 241 goto ERROR3;
229 if ((res = psiconv_write_word_status_section(config,buf,value->status_sec))) 242 if ((res = psiconv_write_word_status_section(config,buf,lev+1,value->status_sec)))
230 goto ERROR3; 243 goto ERROR3;
231 244
232 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION; 245 entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION;
233 entry->offset = psiconv_buffer_unique_id(); 246 entry->offset = psiconv_buffer_unique_id();
234 if ((res = psiconv_list_add(section_table,entry))) 247 if ((res = psiconv_list_add(section_table,entry)))
235 goto ERROR3; 248 goto ERROR3;
236 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 249 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
237 goto ERROR3; 250 goto ERROR3;
238 if ((res = psiconv_write_page_layout_section(config,buf,value->page_sec))) 251 if ((res = psiconv_write_page_layout_section(config,buf,lev+1,value->page_sec)))
239 goto ERROR3; 252 goto ERROR3;
240 253
241 entry->id = PSICONV_ID_WORD_STYLES_SECTION; 254 entry->id = PSICONV_ID_WORD_STYLES_SECTION;
242 entry->offset = psiconv_buffer_unique_id(); 255 entry->offset = psiconv_buffer_unique_id();
243 if ((res = psiconv_list_add(section_table,entry))) 256 if ((res = psiconv_list_add(section_table,entry)))
244 goto ERROR3; 257 goto ERROR3;
245 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 258 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
246 goto ERROR3; 259 goto ERROR3;
247 if ((res = psiconv_write_word_styles_section(config,buf,value->styles_sec))) 260 if ((res = psiconv_write_word_styles_section(config,buf,lev+1,value->styles_sec)))
248 goto ERROR3; 261 goto ERROR3;
249 262
250 entry->id = PSICONV_ID_TEXT_SECTION; 263 entry->id = PSICONV_ID_TEXT_SECTION;
251 entry->offset = psiconv_buffer_unique_id(); 264 entry->offset = psiconv_buffer_unique_id();
252 if ((res = psiconv_list_add(section_table,entry))) 265 if ((res = psiconv_list_add(section_table,entry)))
253 goto ERROR3; 266 goto ERROR3;
254 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 267 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
255 goto ERROR3; 268 goto ERROR3;
256 if ((res = psiconv_write_text_section(config,buf,value->paragraphs))) 269 if ((res = psiconv_write_text_section(config,buf,lev+1,value->paragraphs)))
257 goto ERROR3; 270 goto ERROR3;
258 271
259 entry->id = PSICONV_ID_LAYOUT_SECTION; 272 entry->id = PSICONV_ID_LAYOUT_SECTION;
260 entry->offset = psiconv_buffer_unique_id(); 273 entry->offset = psiconv_buffer_unique_id();
261 if ((res = psiconv_list_add(section_table,entry))) 274 if ((res = psiconv_list_add(section_table,entry)))
262 goto ERROR3; 275 goto ERROR3;
263 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 276 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
264 goto ERROR3; 277 goto ERROR3;
265 if ((res = psiconv_write_styled_layout_section(config,buf,value->paragraphs, 278 if ((res = psiconv_write_styled_layout_section(config,buf,lev+1,value->paragraphs,
266 value->styles_sec))) 279 value->styles_sec)))
267 goto ERROR3; 280 goto ERROR3;
268 281
269 if ((res = psiconv_buffer_add_target(buf,section_table_id))) 282 if ((res = psiconv_buffer_add_target(buf,section_table_id)))
270 goto ERROR3; 283 goto ERROR3;
271 284
272 res = psiconv_write_section_table_section(config,buf,section_table); 285 res = psiconv_write_section_table_section(config,buf,lev+1,section_table);
273 286
274ERROR3: 287ERROR3:
275 free(entry); 288 free(entry);
276ERROR2: 289ERROR2:
277 psiconv_list_free(section_table); 290 psiconv_list_free(section_table);
278ERROR1: 291ERROR1:
292 if (res)
293 psiconv_error(config,lev,0,"Writing of word file failed");
294 else
295 psiconv_progress(config,lev,0,"End of word file");
279 return res; 296 return res;
280} 297}
281 298
282int psiconv_write_sketch_file(const psiconv_config config, 299int psiconv_write_sketch_file(const psiconv_config config,
283 psiconv_buffer buf,psiconv_sketch_f value) 300 psiconv_buffer buf,int lev,psiconv_sketch_f value)
284{ 301{
285 int res; 302 int res;
286 psiconv_section_table_section section_table; 303 psiconv_section_table_section section_table;
287 psiconv_section_table_entry entry; 304 psiconv_section_table_entry entry;
288 psiconv_u32 section_table_id; 305 psiconv_u32 section_table_id;
289 306
307 psiconv_progress(config,lev,0,"Writing sketch file");
290 if (!value) { 308 if (!value) {
291 psiconv_warn(config,0,0,"Null Sketch file"); 309 psiconv_error(config,lev,0,"Null Sketch file");
292 return -PSICONV_E_GENERATE; 310 res = -PSICONV_E_GENERATE;
311 goto ERROR1;
293 } 312 }
294 313
295 if (!(section_table = psiconv_list_new(sizeof(*entry)))) { 314 if (!(section_table = psiconv_list_new(sizeof(*entry)))) {
296 res = -PSICONV_E_NOMEM; 315 res = -PSICONV_E_NOMEM;
297 goto ERROR1; 316 goto ERROR1;
301 res = -PSICONV_E_NOMEM; 320 res = -PSICONV_E_NOMEM;
302 goto ERROR2; 321 goto ERROR2;
303 } 322 }
304 323
305 section_table_id = psiconv_buffer_unique_id(); 324 section_table_id = psiconv_buffer_unique_id();
306 if ((res = psiconv_write_offset(config,buf,section_table_id))) 325 if ((res = psiconv_write_offset(config,buf,lev+1,section_table_id)))
307 goto ERROR3; 326 goto ERROR3;
308 327
309 entry->id = PSICONV_ID_APPL_ID_SECTION; 328 entry->id = PSICONV_ID_APPL_ID_SECTION;
310 entry->offset = psiconv_buffer_unique_id(); 329 entry->offset = psiconv_buffer_unique_id();
311 if ((res = psiconv_list_add(section_table,entry))) 330 if ((res = psiconv_list_add(section_table,entry)))
312 goto ERROR3; 331 goto ERROR3;
313 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 332 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
314 goto ERROR3; 333 goto ERROR3;
315 if ((res=psiconv_write_application_id_section(config,buf, 334 if ((res=psiconv_write_application_id_section(config,buf,lev+1,
316 PSICONV_ID_SKETCH,"Paint.app"))) 335 PSICONV_ID_SKETCH,unicode_paint)))
317 goto ERROR3; 336 goto ERROR3;
318 337
319 entry->id = PSICONV_ID_SKETCH_SECTION; 338 entry->id = PSICONV_ID_SKETCH_SECTION;
320 entry->offset = psiconv_buffer_unique_id(); 339 entry->offset = psiconv_buffer_unique_id();
321 if ((res = psiconv_list_add(section_table,entry))) 340 if ((res = psiconv_list_add(section_table,entry)))
322 goto ERROR3; 341 goto ERROR3;
323 if ((res = psiconv_buffer_add_target(buf,entry->offset))) 342 if ((res = psiconv_buffer_add_target(buf,entry->offset)))
324 goto ERROR3; 343 goto ERROR3;
325 if ((res = psiconv_write_sketch_section(config,buf,value->sketch_sec))) 344 if ((res = psiconv_write_sketch_section(config,buf,lev+1,value->sketch_sec)))
326 goto ERROR3; 345 goto ERROR3;
327 346
328 if ((res = psiconv_buffer_add_target(buf,section_table_id))) 347 if ((res = psiconv_buffer_add_target(buf,section_table_id)))
329 goto ERROR3; 348 goto ERROR3;
330 res = psiconv_write_section_table_section(config,buf,section_table); 349 res = psiconv_write_section_table_section(config,buf,lev+1,section_table);
331 350
332ERROR3: 351ERROR3:
333 free(entry); 352 free(entry);
334ERROR2: 353ERROR2:
335 psiconv_list_free(section_table); 354 psiconv_list_free(section_table);
336ERROR1: 355ERROR1:
356 if (res)
357 psiconv_error(config,lev,0,"Writing of sketch file failed");
358 else
359 psiconv_progress(config,lev,0,"End of sketch file");
337 return res; 360 return res;
338} 361}
339 362
340int psiconv_write_mbm_file(const psiconv_config config, 363int psiconv_write_mbm_file(const psiconv_config config,
341 psiconv_buffer buf,psiconv_mbm_f value) 364 psiconv_buffer buf,int lev,psiconv_mbm_f value)
342{ 365{
343 int res,i; 366 int res,i;
344 psiconv_jumptable_section jumptable; 367 psiconv_jumptable_section jumptable;
345 psiconv_u32 *entry,id,table_id; 368 psiconv_u32 *entry,id,table_id;
346 psiconv_paint_data_section section; 369 psiconv_paint_data_section section;
347 370
371 psiconv_progress(config,lev,0,"Writing mbm file");
348 if (!value) { 372 if (!value) {
349 psiconv_warn(config,0,0,"Null MBM file"); 373 psiconv_error(config,lev,0,"Null MBM file");
350 return -PSICONV_E_GENERATE; 374 res = -PSICONV_E_GENERATE;
375 goto ERROR1;
351 } 376 }
352 377
353 if (!(jumptable = psiconv_list_new(sizeof(*entry)))) { 378 if (!(jumptable = psiconv_list_new(sizeof(*entry)))) {
354 res = -PSICONV_E_NOMEM; 379 res = -PSICONV_E_NOMEM;
355 goto ERROR1; 380 goto ERROR1;
359 if ((res = psiconv_buffer_add_reference(buf,table_id))) 384 if ((res = psiconv_buffer_add_reference(buf,table_id)))
360 goto ERROR2; 385 goto ERROR2;
361 386
362 for (i = 0; i < psiconv_list_length(value->sections); i++) { 387 for (i = 0; i < psiconv_list_length(value->sections); i++) {
363 if (!(section = psiconv_list_get(value->sections,i))) { 388 if (!(section = psiconv_list_get(value->sections,i))) {
364 psiconv_warn(config,0,0,"Massive memory corruption"); 389 psiconv_error(config,lev,0,"Massive memory corruption");
365 res = -PSICONV_E_NOMEM; 390 res = -PSICONV_E_NOMEM;
366 goto ERROR2; 391 goto ERROR2;
367 } 392 }
368 id = psiconv_buffer_unique_id(); 393 id = psiconv_buffer_unique_id();
369 psiconv_list_add(jumptable,&id); 394 psiconv_list_add(jumptable,&id);
370 if ((res = psiconv_buffer_add_target(buf,id))) 395 if ((res = psiconv_buffer_add_target(buf,id)))
371 goto ERROR2; 396 goto ERROR2;
372 if ((res = psiconv_write_paint_data_section(config,buf,section,0))) 397 if ((res = psiconv_write_paint_data_section(config,buf,lev+1,section,0)))
373 goto ERROR2; 398 goto ERROR2;
374 } 399 }
375 400
376 if ((res = psiconv_buffer_add_target(buf,table_id))) 401 if ((res = psiconv_buffer_add_target(buf,table_id)))
377 goto ERROR2; 402 goto ERROR2;
378 if ((res = psiconv_write_jumptable_section(config,buf,jumptable))) 403 if ((res = psiconv_write_jumptable_section(config,buf,lev+1,jumptable)))
379 goto ERROR2; 404 goto ERROR2;
380 405
381 406
382ERROR2: 407ERROR2:
383 psiconv_list_free(jumptable); 408 psiconv_list_free(jumptable);
384ERROR1: 409ERROR1:
410 if (res)
411 psiconv_error(config,lev,0,"Writing of mbm file failed");
412 else
413 psiconv_progress(config,lev,0,"End of mbm file");
385 return res; 414 return res;
386} 415}
387 416
388/* Note: this file is special, because it does not have a complete header! */ 417/* Note: this file is special, because it does not have a complete header! */
389int psiconv_write_clipart_file(const psiconv_config config, 418int psiconv_write_clipart_file(const psiconv_config config,
390 psiconv_buffer buf,psiconv_clipart_f value) 419 psiconv_buffer buf,int lev,psiconv_clipart_f value)
391{ 420{
392 int res,i; 421 int res,i;
393 psiconv_jumptable_section jumptable; 422 psiconv_jumptable_section jumptable;
394 psiconv_u32 *entry,id; 423 psiconv_u32 *entry,id;
395 psiconv_clipart_section section; 424 psiconv_clipart_section section;
396 psiconv_buffer sec_buf; 425 psiconv_buffer sec_buf;
397 426
427 psiconv_progress(config,lev,0,"Writing clipart file");
398 if (!value) { 428 if (!value) {
399 psiconv_warn(config,0,0,"Null Clipart file"); 429 psiconv_error(config,lev,0,"Null Clipart file");
400 return -PSICONV_E_GENERATE; 430 res = -PSICONV_E_GENERATE;
431 goto ERROR1;
401 } 432 }
402 433
403 if (!(jumptable = psiconv_list_new(sizeof(*entry)))) { 434 if (!(jumptable = psiconv_list_new(sizeof(*entry)))) {
404 res = -PSICONV_E_NOMEM; 435 res = -PSICONV_E_NOMEM;
405 goto ERROR1; 436 goto ERROR1;
408 if (!(sec_buf = psiconv_buffer_new())) { 439 if (!(sec_buf = psiconv_buffer_new())) {
409 res = -PSICONV_E_NOMEM; 440 res = -PSICONV_E_NOMEM;
410 goto ERROR2; 441 goto ERROR2;
411 } 442 }
412 443
413 if ((res = psiconv_write_u32(config,buf,PSICONV_ID_CLIPART))) 444 if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_CLIPART)))
414 goto ERROR3; 445 goto ERROR3;
415 446
416 for (i = 0; i < psiconv_list_length(value->sections); i++) { 447 for (i = 0; i < psiconv_list_length(value->sections); i++) {
417 if (!(section = psiconv_list_get(value->sections,i))) { 448 if (!(section = psiconv_list_get(value->sections,i))) {
418 psiconv_warn(config,0,0,"Massive memory corruption"); 449 psiconv_error(config,lev,0,"Massive memory corruption");
419 res = -PSICONV_E_NOMEM; 450 res = -PSICONV_E_NOMEM;
420 goto ERROR3; 451 goto ERROR3;
421 } 452 }
422 id = psiconv_buffer_unique_id(); 453 id = psiconv_buffer_unique_id();
423 psiconv_list_add(jumptable,&id); 454 psiconv_list_add(jumptable,&id);
424 if ((res = psiconv_buffer_add_target(sec_buf,id))) 455 if ((res = psiconv_buffer_add_target(sec_buf,id)))
425 goto ERROR3; 456 goto ERROR3;
426 if ((res = psiconv_write_clipart_section(config,sec_buf, section))) 457 if ((res = psiconv_write_clipart_section(config,sec_buf, lev+1,section)))
427 goto ERROR3; 458 goto ERROR3;
428 } 459 }
429 460
430 if ((res = psiconv_write_jumptable_section(config,buf,jumptable))) 461 if ((res = psiconv_write_jumptable_section(config,buf,lev+1,jumptable)))
431 goto ERROR3; 462 goto ERROR3;
432 463
433 if ((res = psiconv_buffer_concat(buf,sec_buf))) 464 if ((res = psiconv_buffer_concat(buf,sec_buf)))
434 goto ERROR3; 465 goto ERROR3;
435 466
437ERROR3: 468ERROR3:
438 psiconv_buffer_free(sec_buf); 469 psiconv_buffer_free(sec_buf);
439ERROR2: 470ERROR2:
440 psiconv_list_free(jumptable); 471 psiconv_list_free(jumptable);
441ERROR1: 472ERROR1:
473 if (res)
474 psiconv_error(config,lev,0,"Writing of clipart file failed");
475 else
476 psiconv_progress(config,lev,0,"End of clipart file");
442 return res; 477 return res;
443} 478}

Legend:
Removed from v.174  
changed lines
  Added in v.231

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