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