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. |
… | |
… | |
42 | |
42 | |
43 | if (!value) { |
43 | if (!value) { |
44 | psiconv_error(config,0,0,"Can't parse to an empty buffer!"); |
44 | psiconv_error(config,0,0,"Can't parse to an empty buffer!"); |
45 | return -PSICONV_E_OTHER; |
45 | return -PSICONV_E_OTHER; |
46 | } |
46 | } |
47 | if (!(*buf = psiconv_buffer_new())) |
47 | if (!(*buf = psiconv_buffer_new())) { |
|
|
48 | psiconv_error(config,lev+1,0,"Out of memory error"); |
48 | return -PSICONV_E_NOMEM; |
49 | return -PSICONV_E_NOMEM; |
|
|
50 | } |
49 | |
51 | |
50 | if (value->type == psiconv_word_file) { |
52 | if (value->type == psiconv_word_file) { |
51 | if ((res = psiconv_write_header_section(config,*buf,lev+1,PSICONV_ID_PSION5, |
53 | if ((res = psiconv_write_header_section(config,*buf,lev+1,PSICONV_ID_PSION5, |
52 | PSICONV_ID_DATA_FILE, |
54 | PSICONV_ID_DATA_FILE, |
53 | PSICONV_ID_WORD))) |
55 | PSICONV_ID_WORD))) |
… | |
… | |
86 | } else { |
88 | } else { |
87 | psiconv_error(config,0,0,"Unknown or unsupported file type"); |
89 | psiconv_error(config,0,0,"Unknown or unsupported file type"); |
88 | res = -PSICONV_E_GENERATE; |
90 | res = -PSICONV_E_GENERATE; |
89 | goto ERROR; |
91 | goto ERROR; |
90 | } |
92 | } |
91 | if ((res = psiconv_buffer_resolve(*buf))) |
93 | if ((res = psiconv_buffer_resolve(*buf))) { |
|
|
94 | psiconv_error(config,lev+1,0,"Internal error resolving buffer references"); |
92 | goto ERROR; |
95 | goto ERROR; |
|
|
96 | } |
93 | return -PSICONV_E_OK; |
97 | return -PSICONV_E_OK; |
94 | |
98 | |
95 | ERROR: |
99 | ERROR: |
96 | psiconv_buffer_free(*buf); |
100 | psiconv_buffer_free(*buf); |
97 | return res; |
101 | return res; |
… | |
… | |
108 | psiconv_u32 section_table_id; |
112 | psiconv_u32 section_table_id; |
109 | psiconv_buffer buf_texted; |
113 | psiconv_buffer buf_texted; |
110 | |
114 | |
111 | psiconv_progress(config,lev,0,"Writing texted file"); |
115 | psiconv_progress(config,lev,0,"Writing texted file"); |
112 | if (!value) { |
116 | if (!value) { |
113 | psiconv_error(config,0,0,"Null TextEd file"); |
117 | psiconv_error(config,lev,0,"Null TextEd file"); |
114 | return -PSICONV_E_GENERATE; |
118 | res = -PSICONV_E_GENERATE; |
|
|
119 | goto ERROR1; |
115 | } |
120 | } |
116 | |
121 | |
117 | if (!(section_table = psiconv_list_new(sizeof(*entry)))) { |
122 | if (!(section_table = psiconv_list_new(sizeof(*entry)))) { |
|
|
123 | psiconv_error(config,lev+1,0,"Out of memory error"); |
118 | res = -PSICONV_E_NOMEM; |
124 | res = -PSICONV_E_NOMEM; |
119 | goto ERROR1; |
125 | goto ERROR1; |
120 | } |
126 | } |
121 | |
127 | |
122 | if (!(entry = malloc(sizeof(*entry)))) { |
128 | if (!(entry = malloc(sizeof(*entry)))) { |
|
|
129 | psiconv_error(config,lev+1,0,"Out of memory error"); |
123 | res = -PSICONV_E_NOMEM; |
130 | res = -PSICONV_E_NOMEM; |
124 | goto ERROR2; |
131 | goto ERROR2; |
125 | } |
132 | } |
126 | |
133 | |
127 | if (!(base_char = psiconv_basic_character_layout())) { |
134 | if (!(base_char = psiconv_basic_character_layout())) { |
|
|
135 | psiconv_error(config,lev+1,0,"Out of memory error"); |
128 | res = -PSICONV_E_NOMEM; |
136 | res = -PSICONV_E_NOMEM; |
129 | goto ERROR3; |
137 | goto ERROR3; |
130 | } |
138 | } |
131 | if (!(base_para = psiconv_basic_paragraph_layout())) { |
139 | if (!(base_para = psiconv_basic_paragraph_layout())) { |
|
|
140 | psiconv_error(config,lev+1,0,"Out of memory error"); |
132 | res = -PSICONV_E_NOMEM; |
141 | res = -PSICONV_E_NOMEM; |
133 | goto ERROR4; |
142 | goto ERROR4; |
134 | } |
143 | } |
135 | |
144 | |
136 | section_table_id = psiconv_buffer_unique_id(); |
145 | section_table_id = psiconv_buffer_unique_id(); |
137 | if ((res = psiconv_write_offset(config,buf,lev+1,section_table_id))) |
146 | if ((res = psiconv_write_offset(config,buf,lev+1,section_table_id))) { |
|
|
147 | psiconv_error(config,lev+1,0,"Out of memory error"); |
138 | goto ERROR5; |
148 | goto ERROR5; |
|
|
149 | } |
139 | |
150 | |
140 | entry->id = PSICONV_ID_APPL_ID_SECTION; |
151 | entry->id = PSICONV_ID_APPL_ID_SECTION; |
141 | entry->offset = psiconv_buffer_unique_id(); |
152 | entry->offset = psiconv_buffer_unique_id(); |
142 | if ((res = psiconv_list_add(section_table,entry))) |
153 | if ((res = psiconv_list_add(section_table,entry))) { |
|
|
154 | psiconv_error(config,lev+1,0,"Out of memory error"); |
143 | goto ERROR5; |
155 | goto ERROR5; |
|
|
156 | } |
144 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) |
157 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) { |
|
|
158 | psiconv_error(config,lev+1,0,"Out of memory error"); |
145 | goto ERROR5; |
159 | goto ERROR5; |
|
|
160 | } |
146 | if ((res=psiconv_write_application_id_section(config,buf,lev+1, |
161 | if ((res=psiconv_write_application_id_section(config,buf,lev+1, |
147 | PSICONV_ID_TEXTED,unicode_texted))) |
162 | PSICONV_ID_TEXTED,unicode_texted))) |
148 | goto ERROR5; |
163 | goto ERROR5; |
149 | |
164 | |
150 | entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION; |
165 | entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION; |
151 | entry->offset = psiconv_buffer_unique_id(); |
166 | entry->offset = psiconv_buffer_unique_id(); |
152 | if ((res = psiconv_list_add(section_table,entry))) |
167 | if ((res = psiconv_list_add(section_table,entry))) { |
|
|
168 | psiconv_error(config,lev+1,0,"Out of memory error"); |
153 | goto ERROR5; |
169 | goto ERROR5; |
|
|
170 | } |
154 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) |
171 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) { |
|
|
172 | psiconv_error(config,lev+1,0,"Out of memory error"); |
155 | goto ERROR5; |
173 | goto ERROR5; |
|
|
174 | } |
156 | if ((res = psiconv_write_page_layout_section(config,buf,lev+1,value->page_sec))) |
175 | if ((res = psiconv_write_page_layout_section(config,buf,lev+1,value->page_sec))) |
157 | goto ERROR5; |
176 | goto ERROR5; |
158 | |
177 | |
159 | entry->id = PSICONV_ID_TEXTED; |
178 | entry->id = PSICONV_ID_TEXTED; |
160 | entry->offset = psiconv_buffer_unique_id(); |
179 | entry->offset = psiconv_buffer_unique_id(); |
161 | if ((res = psiconv_list_add(section_table,entry))) |
180 | if ((res = psiconv_list_add(section_table,entry))) { |
|
|
181 | psiconv_error(config,lev+1,0,"Out of memory error"); |
162 | goto ERROR5; |
182 | goto ERROR5; |
|
|
183 | } |
163 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) |
184 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) { |
|
|
185 | psiconv_error(config,lev+1,0,"Out of memory error"); |
164 | goto ERROR5; |
186 | goto ERROR5; |
|
|
187 | } |
165 | if ((res = psiconv_write_texted_section(config,buf,lev+1,value->texted_sec, |
188 | if ((res = psiconv_write_texted_section(config,buf,lev+1,value->texted_sec, |
166 | base_char,base_para,&buf_texted))) |
189 | base_char,base_para,&buf_texted))) |
167 | goto ERROR5; |
190 | goto ERROR5; |
168 | |
191 | |
169 | if ((res = psiconv_buffer_concat(buf,buf_texted))) |
192 | if ((res = psiconv_buffer_concat(buf,buf_texted))) { |
|
|
193 | psiconv_error(config,lev+1,0,"Out of memory error"); |
170 | goto ERROR6; |
194 | goto ERROR6; |
|
|
195 | } |
171 | |
196 | |
172 | |
|
|
173 | if ((res = psiconv_buffer_add_target(buf,section_table_id))) |
197 | if ((res = psiconv_buffer_add_target(buf,section_table_id))) { |
|
|
198 | psiconv_error(config,lev+1,0,"Out of memory error"); |
174 | goto ERROR6; |
199 | goto ERROR6; |
|
|
200 | } |
175 | |
201 | |
176 | res = psiconv_write_section_table_section(config,buf,lev+1,section_table); |
202 | res = psiconv_write_section_table_section(config,buf,lev+1,section_table); |
177 | |
203 | |
178 | ERROR6: |
204 | ERROR6: |
179 | psiconv_buffer_free(buf_texted); |
205 | psiconv_buffer_free(buf_texted); |
… | |
… | |
184 | ERROR3: |
210 | ERROR3: |
185 | free(entry); |
211 | free(entry); |
186 | ERROR2: |
212 | ERROR2: |
187 | psiconv_list_free(section_table); |
213 | psiconv_list_free(section_table); |
188 | ERROR1: |
214 | ERROR1: |
|
|
215 | if (res) |
|
|
216 | psiconv_error(config,lev,0,"Writing of texted file failed"); |
|
|
217 | else |
|
|
218 | psiconv_progress(config,lev,0,"End of texted file"); |
189 | return res; |
219 | return res; |
190 | } |
220 | } |
191 | |
221 | |
192 | int psiconv_write_word_file(const psiconv_config config, |
222 | int psiconv_write_word_file(const psiconv_config config, |
193 | psiconv_buffer buf,int lev,psiconv_word_f value) |
223 | psiconv_buffer buf,int lev,psiconv_word_f value) |
… | |
… | |
197 | psiconv_section_table_entry entry; |
227 | psiconv_section_table_entry entry; |
198 | psiconv_u32 section_table_id; |
228 | psiconv_u32 section_table_id; |
199 | |
229 | |
200 | psiconv_progress(config,lev,0,"Writing word file"); |
230 | psiconv_progress(config,lev,0,"Writing word file"); |
201 | if (!value) { |
231 | if (!value) { |
202 | psiconv_error(config,0,0,"Null Word file"); |
232 | psiconv_error(config,lev,0,"Null Word file"); |
203 | return -PSICONV_E_GENERATE; |
233 | res = -PSICONV_E_GENERATE; |
|
|
234 | goto ERROR1; |
204 | } |
235 | } |
205 | |
236 | |
206 | if (!(section_table = psiconv_list_new(sizeof(*entry)))) { |
237 | if (!(section_table = psiconv_list_new(sizeof(*entry)))) { |
|
|
238 | psiconv_error(config,lev+1,0,"Out of memory error"); |
207 | res = -PSICONV_E_NOMEM; |
239 | res = -PSICONV_E_NOMEM; |
208 | goto ERROR1; |
240 | goto ERROR1; |
209 | } |
241 | } |
210 | |
242 | |
211 | if (!(entry = malloc(sizeof(*entry)))) { |
243 | if (!(entry = malloc(sizeof(*entry)))) { |
|
|
244 | psiconv_error(config,lev+1,0,"Out of memory error"); |
212 | res = -PSICONV_E_NOMEM; |
245 | res = -PSICONV_E_NOMEM; |
213 | goto ERROR2; |
246 | goto ERROR2; |
214 | } |
247 | } |
215 | |
248 | |
216 | section_table_id = psiconv_buffer_unique_id(); |
249 | section_table_id = psiconv_buffer_unique_id(); |
217 | if ((res = psiconv_write_offset(config,buf,lev+1,section_table_id))) |
250 | if ((res = psiconv_write_offset(config,buf,lev+1,section_table_id))) |
218 | goto ERROR3; |
251 | goto ERROR3; |
219 | |
252 | |
220 | entry->id = PSICONV_ID_APPL_ID_SECTION; |
253 | entry->id = PSICONV_ID_APPL_ID_SECTION; |
221 | entry->offset = psiconv_buffer_unique_id(); |
254 | entry->offset = psiconv_buffer_unique_id(); |
222 | if ((res = psiconv_list_add(section_table,entry))) |
255 | if ((res = psiconv_list_add(section_table,entry))) { |
|
|
256 | psiconv_error(config,lev+1,0,"Out of memory error"); |
223 | goto ERROR3; |
257 | goto ERROR3; |
|
|
258 | } |
224 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) |
259 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) { |
|
|
260 | psiconv_error(config,lev+1,0,"Out of memory error"); |
225 | goto ERROR3; |
261 | goto ERROR3; |
|
|
262 | } |
226 | if ((res=psiconv_write_application_id_section(config,buf,lev+1, |
263 | if ((res=psiconv_write_application_id_section(config,buf,lev+1, |
227 | PSICONV_ID_WORD,unicode_word))) |
264 | PSICONV_ID_WORD,unicode_word))) |
228 | goto ERROR3; |
265 | goto ERROR3; |
229 | |
266 | |
230 | entry->id = PSICONV_ID_WORD_STATUS_SECTION; |
267 | entry->id = PSICONV_ID_WORD_STATUS_SECTION; |
231 | entry->offset = psiconv_buffer_unique_id(); |
268 | entry->offset = psiconv_buffer_unique_id(); |
232 | if ((res = psiconv_list_add(section_table,entry))) |
269 | if ((res = psiconv_list_add(section_table,entry))) { |
|
|
270 | psiconv_error(config,lev+1,0,"Out of memory error"); |
233 | goto ERROR3; |
271 | goto ERROR3; |
|
|
272 | } |
234 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) |
273 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) { |
|
|
274 | psiconv_error(config,lev+1,0,"Out of memory error"); |
235 | goto ERROR3; |
275 | goto ERROR3; |
|
|
276 | } |
236 | if ((res = psiconv_write_word_status_section(config,buf,lev+1,value->status_sec))) |
277 | if ((res = psiconv_write_word_status_section(config,buf,lev+1,value->status_sec))) |
237 | goto ERROR3; |
278 | goto ERROR3; |
238 | |
279 | |
239 | entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION; |
280 | entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION; |
240 | entry->offset = psiconv_buffer_unique_id(); |
281 | entry->offset = psiconv_buffer_unique_id(); |
241 | if ((res = psiconv_list_add(section_table,entry))) |
282 | if ((res = psiconv_list_add(section_table,entry))) { |
|
|
283 | psiconv_error(config,lev+1,0,"Out of memory error"); |
242 | goto ERROR3; |
284 | goto ERROR3; |
|
|
285 | } |
243 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) |
286 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) { |
|
|
287 | psiconv_error(config,lev+1,0,"Out of memory error"); |
244 | goto ERROR3; |
288 | goto ERROR3; |
|
|
289 | } |
245 | if ((res = psiconv_write_page_layout_section(config,buf,lev+1,value->page_sec))) |
290 | if ((res = psiconv_write_page_layout_section(config,buf,lev+1,value->page_sec))) |
246 | goto ERROR3; |
291 | goto ERROR3; |
247 | |
292 | |
248 | entry->id = PSICONV_ID_WORD_STYLES_SECTION; |
293 | entry->id = PSICONV_ID_WORD_STYLES_SECTION; |
249 | entry->offset = psiconv_buffer_unique_id(); |
294 | entry->offset = psiconv_buffer_unique_id(); |
250 | if ((res = psiconv_list_add(section_table,entry))) |
295 | if ((res = psiconv_list_add(section_table,entry))) { |
|
|
296 | psiconv_error(config,lev+1,0,"Out of memory error"); |
251 | goto ERROR3; |
297 | goto ERROR3; |
|
|
298 | } |
252 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) |
299 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) { |
|
|
300 | psiconv_error(config,lev+1,0,"Out of memory error"); |
253 | goto ERROR3; |
301 | goto ERROR3; |
|
|
302 | } |
254 | if ((res = psiconv_write_word_styles_section(config,buf,lev+1,value->styles_sec))) |
303 | if ((res = psiconv_write_word_styles_section(config,buf,lev+1,value->styles_sec))) |
255 | goto ERROR3; |
304 | goto ERROR3; |
256 | |
305 | |
257 | entry->id = PSICONV_ID_TEXT_SECTION; |
306 | entry->id = PSICONV_ID_TEXT_SECTION; |
258 | entry->offset = psiconv_buffer_unique_id(); |
307 | entry->offset = psiconv_buffer_unique_id(); |
259 | if ((res = psiconv_list_add(section_table,entry))) |
308 | if ((res = psiconv_list_add(section_table,entry))) { |
|
|
309 | psiconv_error(config,lev+1,0,"Out of memory error"); |
260 | goto ERROR3; |
310 | goto ERROR3; |
|
|
311 | } |
261 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) |
312 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) { |
|
|
313 | psiconv_error(config,lev+1,0,"Out of memory error"); |
262 | goto ERROR3; |
314 | goto ERROR3; |
|
|
315 | } |
263 | if ((res = psiconv_write_text_section(config,buf,lev+1,value->paragraphs))) |
316 | if ((res = psiconv_write_text_section(config,buf,lev+1,value->paragraphs))) |
264 | goto ERROR3; |
317 | goto ERROR3; |
265 | |
318 | |
266 | entry->id = PSICONV_ID_LAYOUT_SECTION; |
319 | entry->id = PSICONV_ID_LAYOUT_SECTION; |
267 | entry->offset = psiconv_buffer_unique_id(); |
320 | entry->offset = psiconv_buffer_unique_id(); |
268 | if ((res = psiconv_list_add(section_table,entry))) |
321 | if ((res = psiconv_list_add(section_table,entry))) { |
|
|
322 | psiconv_error(config,lev+1,0,"Out of memory error"); |
269 | goto ERROR3; |
323 | goto ERROR3; |
|
|
324 | } |
270 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) |
325 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) { |
|
|
326 | psiconv_error(config,lev+1,0,"Out of memory error"); |
271 | goto ERROR3; |
327 | goto ERROR3; |
|
|
328 | } |
272 | if ((res = psiconv_write_styled_layout_section(config,buf,lev+1,value->paragraphs, |
329 | if ((res = psiconv_write_styled_layout_section(config,buf,lev+1,value->paragraphs, |
273 | value->styles_sec))) |
330 | value->styles_sec))) |
274 | goto ERROR3; |
331 | goto ERROR3; |
275 | |
332 | |
276 | if ((res = psiconv_buffer_add_target(buf,section_table_id))) |
333 | if ((res = psiconv_buffer_add_target(buf,section_table_id))) { |
|
|
334 | psiconv_error(config,lev+1,0,"Out of memory error"); |
277 | goto ERROR3; |
335 | goto ERROR3; |
|
|
336 | } |
278 | |
337 | |
279 | res = psiconv_write_section_table_section(config,buf,lev+1,section_table); |
338 | res = psiconv_write_section_table_section(config,buf,lev+1,section_table); |
280 | |
339 | |
281 | ERROR3: |
340 | ERROR3: |
282 | free(entry); |
341 | free(entry); |
283 | ERROR2: |
342 | ERROR2: |
284 | psiconv_list_free(section_table); |
343 | psiconv_list_free(section_table); |
285 | ERROR1: |
344 | ERROR1: |
|
|
345 | if (res) |
|
|
346 | psiconv_error(config,lev,0,"Writing of word file failed"); |
|
|
347 | else |
|
|
348 | psiconv_progress(config,lev,0,"End of word file"); |
286 | return res; |
349 | return res; |
287 | } |
350 | } |
288 | |
351 | |
289 | int psiconv_write_sketch_file(const psiconv_config config, |
352 | int psiconv_write_sketch_file(const psiconv_config config, |
290 | psiconv_buffer buf,int lev,psiconv_sketch_f value) |
353 | psiconv_buffer buf,int lev,psiconv_sketch_f value) |
… | |
… | |
294 | psiconv_section_table_entry entry; |
357 | psiconv_section_table_entry entry; |
295 | psiconv_u32 section_table_id; |
358 | psiconv_u32 section_table_id; |
296 | |
359 | |
297 | psiconv_progress(config,lev,0,"Writing sketch file"); |
360 | psiconv_progress(config,lev,0,"Writing sketch file"); |
298 | if (!value) { |
361 | if (!value) { |
299 | psiconv_error(config,0,0,"Null Sketch file"); |
362 | psiconv_error(config,lev,0,"Null Sketch file"); |
300 | return -PSICONV_E_GENERATE; |
363 | res = -PSICONV_E_GENERATE; |
|
|
364 | goto ERROR1; |
301 | } |
365 | } |
302 | |
366 | |
303 | if (!(section_table = psiconv_list_new(sizeof(*entry)))) { |
367 | if (!(section_table = psiconv_list_new(sizeof(*entry)))) { |
|
|
368 | psiconv_error(config,lev+1,0,"Out of memory error"); |
304 | res = -PSICONV_E_NOMEM; |
369 | res = -PSICONV_E_NOMEM; |
305 | goto ERROR1; |
370 | goto ERROR1; |
306 | } |
371 | } |
307 | |
372 | |
308 | if (!(entry = malloc(sizeof(*entry)))) { |
373 | if (!(entry = malloc(sizeof(*entry)))) { |
|
|
374 | psiconv_error(config,lev+1,0,"Out of memory error"); |
309 | res = -PSICONV_E_NOMEM; |
375 | res = -PSICONV_E_NOMEM; |
310 | goto ERROR2; |
376 | goto ERROR2; |
311 | } |
377 | } |
312 | |
378 | |
313 | section_table_id = psiconv_buffer_unique_id(); |
379 | section_table_id = psiconv_buffer_unique_id(); |
314 | if ((res = psiconv_write_offset(config,buf,lev+1,section_table_id))) |
380 | if ((res = psiconv_write_offset(config,buf,lev+1,section_table_id))) |
315 | goto ERROR3; |
381 | goto ERROR3; |
316 | |
382 | |
317 | entry->id = PSICONV_ID_APPL_ID_SECTION; |
383 | entry->id = PSICONV_ID_APPL_ID_SECTION; |
318 | entry->offset = psiconv_buffer_unique_id(); |
384 | entry->offset = psiconv_buffer_unique_id(); |
319 | if ((res = psiconv_list_add(section_table,entry))) |
385 | if ((res = psiconv_list_add(section_table,entry))) { |
|
|
386 | psiconv_error(config,lev+1,0,"Out of memory error"); |
320 | goto ERROR3; |
387 | goto ERROR3; |
|
|
388 | } |
321 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) |
389 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) { |
|
|
390 | psiconv_error(config,lev+1,0,"Out of memory error"); |
322 | goto ERROR3; |
391 | goto ERROR3; |
|
|
392 | } |
323 | if ((res=psiconv_write_application_id_section(config,buf,lev+1, |
393 | if ((res=psiconv_write_application_id_section(config,buf,lev+1, |
324 | PSICONV_ID_SKETCH,unicode_paint))) |
394 | PSICONV_ID_SKETCH,unicode_paint))) |
325 | goto ERROR3; |
395 | goto ERROR3; |
326 | |
396 | |
327 | entry->id = PSICONV_ID_SKETCH_SECTION; |
397 | entry->id = PSICONV_ID_SKETCH_SECTION; |
328 | entry->offset = psiconv_buffer_unique_id(); |
398 | entry->offset = psiconv_buffer_unique_id(); |
329 | if ((res = psiconv_list_add(section_table,entry))) |
399 | if ((res = psiconv_list_add(section_table,entry))) { |
|
|
400 | psiconv_error(config,lev+1,0,"Out of memory error"); |
330 | goto ERROR3; |
401 | goto ERROR3; |
|
|
402 | } |
331 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) |
403 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) { |
|
|
404 | psiconv_error(config,lev+1,0,"Out of memory error"); |
332 | goto ERROR3; |
405 | goto ERROR3; |
|
|
406 | } |
333 | if ((res = psiconv_write_sketch_section(config,buf,lev+1,value->sketch_sec))) |
407 | if ((res = psiconv_write_sketch_section(config,buf,lev+1,value->sketch_sec))) |
334 | goto ERROR3; |
408 | goto ERROR3; |
335 | |
409 | |
336 | if ((res = psiconv_buffer_add_target(buf,section_table_id))) |
410 | if ((res = psiconv_buffer_add_target(buf,section_table_id))) { |
|
|
411 | psiconv_error(config,lev+1,0,"Out of memory error"); |
337 | goto ERROR3; |
412 | goto ERROR3; |
|
|
413 | } |
338 | res = psiconv_write_section_table_section(config,buf,lev+1,section_table); |
414 | res = psiconv_write_section_table_section(config,buf,lev+1,section_table); |
339 | |
415 | |
340 | ERROR3: |
416 | ERROR3: |
341 | free(entry); |
417 | free(entry); |
342 | ERROR2: |
418 | ERROR2: |
343 | psiconv_list_free(section_table); |
419 | psiconv_list_free(section_table); |
344 | ERROR1: |
420 | ERROR1: |
|
|
421 | if (res) |
|
|
422 | psiconv_error(config,lev,0,"Writing of sketch file failed"); |
|
|
423 | else |
|
|
424 | psiconv_progress(config,lev,0,"End of sketch file"); |
345 | return res; |
425 | return res; |
346 | } |
426 | } |
347 | |
427 | |
348 | int psiconv_write_mbm_file(const psiconv_config config, |
428 | int psiconv_write_mbm_file(const psiconv_config config, |
349 | psiconv_buffer buf,int lev,psiconv_mbm_f value) |
429 | psiconv_buffer buf,int lev,psiconv_mbm_f value) |
… | |
… | |
353 | psiconv_u32 *entry,id,table_id; |
433 | psiconv_u32 *entry,id,table_id; |
354 | psiconv_paint_data_section section; |
434 | psiconv_paint_data_section section; |
355 | |
435 | |
356 | psiconv_progress(config,lev,0,"Writing mbm file"); |
436 | psiconv_progress(config,lev,0,"Writing mbm file"); |
357 | if (!value) { |
437 | if (!value) { |
358 | psiconv_error(config,0,0,"Null MBM file"); |
438 | psiconv_error(config,lev,0,"Null MBM file"); |
359 | return -PSICONV_E_GENERATE; |
439 | res = -PSICONV_E_GENERATE; |
|
|
440 | goto ERROR1; |
360 | } |
441 | } |
361 | |
442 | |
362 | if (!(jumptable = psiconv_list_new(sizeof(*entry)))) { |
443 | if (!(jumptable = psiconv_list_new(sizeof(*entry)))) { |
|
|
444 | psiconv_error(config,lev+1,0,"Out of memory error"); |
363 | res = -PSICONV_E_NOMEM; |
445 | res = -PSICONV_E_NOMEM; |
364 | goto ERROR1; |
446 | goto ERROR1; |
365 | } |
447 | } |
366 | |
448 | |
367 | table_id = psiconv_buffer_unique_id(); |
449 | table_id = psiconv_buffer_unique_id(); |
368 | if ((res = psiconv_buffer_add_reference(buf,table_id))) |
450 | if ((res = psiconv_buffer_add_reference(buf,table_id))) { |
|
|
451 | psiconv_error(config,lev+1,0,"Out of memory error"); |
369 | goto ERROR2; |
452 | goto ERROR2; |
|
|
453 | } |
370 | |
454 | |
371 | for (i = 0; i < psiconv_list_length(value->sections); i++) { |
455 | for (i = 0; i < psiconv_list_length(value->sections); i++) { |
372 | if (!(section = psiconv_list_get(value->sections,i))) { |
456 | if (!(section = psiconv_list_get(value->sections,i))) { |
373 | psiconv_error(config,0,0,"Massive memory corruption"); |
457 | psiconv_error(config,lev,0,"Data structure corruption"); |
374 | res = -PSICONV_E_NOMEM; |
458 | res = -PSICONV_E_NOMEM; |
375 | goto ERROR2; |
459 | goto ERROR2; |
376 | } |
460 | } |
377 | id = psiconv_buffer_unique_id(); |
461 | id = psiconv_buffer_unique_id(); |
378 | psiconv_list_add(jumptable,&id); |
462 | if ((res = psiconv_list_add(jumptable,&id))) { |
379 | if ((res = psiconv_buffer_add_target(buf,id))) |
463 | psiconv_error(config,lev+1,0,"Out of memory error"); |
380 | goto ERROR2; |
464 | goto ERROR2; |
|
|
465 | } |
|
|
466 | if ((res = psiconv_buffer_add_target(buf,id))) { |
|
|
467 | psiconv_error(config,lev+1,0,"Out of memory error"); |
|
|
468 | goto ERROR2; |
|
|
469 | } |
381 | if ((res = psiconv_write_paint_data_section(config,buf,lev+1,section,0))) |
470 | if ((res = psiconv_write_paint_data_section(config,buf,lev+1,section,0))) |
382 | goto ERROR2; |
471 | goto ERROR2; |
383 | } |
472 | } |
384 | |
473 | |
385 | if ((res = psiconv_buffer_add_target(buf,table_id))) |
474 | if ((res = psiconv_buffer_add_target(buf,table_id))) { |
|
|
475 | psiconv_error(config,lev+1,0,"Out of memory error"); |
386 | goto ERROR2; |
476 | goto ERROR2; |
|
|
477 | } |
387 | if ((res = psiconv_write_jumptable_section(config,buf,lev+1,jumptable))) |
478 | if ((res = psiconv_write_jumptable_section(config,buf,lev+1,jumptable))) |
388 | goto ERROR2; |
479 | goto ERROR2; |
389 | |
480 | |
390 | |
481 | |
391 | ERROR2: |
482 | ERROR2: |
392 | psiconv_list_free(jumptable); |
483 | psiconv_list_free(jumptable); |
393 | ERROR1: |
484 | ERROR1: |
|
|
485 | if (res) |
|
|
486 | psiconv_error(config,lev,0,"Writing of mbm file failed"); |
|
|
487 | else |
|
|
488 | psiconv_progress(config,lev,0,"End of mbm file"); |
394 | return res; |
489 | return res; |
395 | } |
490 | } |
396 | |
491 | |
397 | /* Note: this file is special, because it does not have a complete header! */ |
492 | /* Note: this file is special, because it does not have a complete header! */ |
398 | int psiconv_write_clipart_file(const psiconv_config config, |
493 | int psiconv_write_clipart_file(const psiconv_config config, |
… | |
… | |
404 | psiconv_clipart_section section; |
499 | psiconv_clipart_section section; |
405 | psiconv_buffer sec_buf; |
500 | psiconv_buffer sec_buf; |
406 | |
501 | |
407 | psiconv_progress(config,lev,0,"Writing clipart file"); |
502 | psiconv_progress(config,lev,0,"Writing clipart file"); |
408 | if (!value) { |
503 | if (!value) { |
409 | psiconv_error(config,0,0,"Null Clipart file"); |
504 | psiconv_error(config,lev,0,"Null Clipart file"); |
410 | return -PSICONV_E_GENERATE; |
505 | res = -PSICONV_E_GENERATE; |
|
|
506 | goto ERROR1; |
411 | } |
507 | } |
412 | |
508 | |
413 | if (!(jumptable = psiconv_list_new(sizeof(*entry)))) { |
509 | if (!(jumptable = psiconv_list_new(sizeof(*entry)))) { |
|
|
510 | psiconv_error(config,lev+1,0,"Out of memory error"); |
414 | res = -PSICONV_E_NOMEM; |
511 | res = -PSICONV_E_NOMEM; |
415 | goto ERROR1; |
512 | goto ERROR1; |
416 | } |
513 | } |
417 | |
514 | |
418 | if (!(sec_buf = psiconv_buffer_new())) { |
515 | if (!(sec_buf = psiconv_buffer_new())) { |
|
|
516 | psiconv_error(config,lev+1,0,"Out of memory error"); |
419 | res = -PSICONV_E_NOMEM; |
517 | res = -PSICONV_E_NOMEM; |
420 | goto ERROR2; |
518 | goto ERROR2; |
421 | } |
519 | } |
422 | |
520 | |
423 | if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_CLIPART))) |
521 | if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_CLIPART))) |
424 | goto ERROR3; |
522 | goto ERROR3; |
425 | |
523 | |
426 | for (i = 0; i < psiconv_list_length(value->sections); i++) { |
524 | for (i = 0; i < psiconv_list_length(value->sections); i++) { |
427 | if (!(section = psiconv_list_get(value->sections,i))) { |
525 | if (!(section = psiconv_list_get(value->sections,i))) { |
428 | psiconv_error(config,0,0,"Massive memory corruption"); |
526 | psiconv_error(config,lev,0,"Data structure corruption"); |
429 | res = -PSICONV_E_NOMEM; |
527 | res = -PSICONV_E_NOMEM; |
430 | goto ERROR3; |
528 | goto ERROR3; |
431 | } |
529 | } |
432 | id = psiconv_buffer_unique_id(); |
530 | id = psiconv_buffer_unique_id(); |
433 | psiconv_list_add(jumptable,&id); |
531 | if ((res = psiconv_list_add(jumptable,&id))) { |
434 | if ((res = psiconv_buffer_add_target(sec_buf,id))) |
532 | psiconv_error(config,lev+1,0,"Out of memory error"); |
435 | goto ERROR3; |
533 | goto ERROR3; |
|
|
534 | } |
|
|
535 | if ((res = psiconv_buffer_add_target(sec_buf,id))) { |
|
|
536 | psiconv_error(config,lev+1,0,"Out of memory error"); |
|
|
537 | goto ERROR3; |
|
|
538 | } |
436 | if ((res = psiconv_write_clipart_section(config,sec_buf, lev+1,section))) |
539 | if ((res = psiconv_write_clipart_section(config,sec_buf, lev+1,section))) |
437 | goto ERROR3; |
540 | goto ERROR3; |
438 | } |
541 | } |
439 | |
542 | |
440 | if ((res = psiconv_write_jumptable_section(config,buf,lev+1,jumptable))) |
543 | if ((res = psiconv_write_jumptable_section(config,buf,lev+1,jumptable))) |
441 | goto ERROR3; |
544 | goto ERROR3; |
442 | |
545 | |
443 | if ((res = psiconv_buffer_concat(buf,sec_buf))) |
546 | if ((res = psiconv_buffer_concat(buf,sec_buf))) { |
|
|
547 | psiconv_error(config,lev+1,0,"Out of memory error"); |
444 | goto ERROR3; |
548 | goto ERROR3; |
|
|
549 | } |
445 | |
550 | |
446 | |
551 | |
447 | ERROR3: |
552 | ERROR3: |
448 | psiconv_buffer_free(sec_buf); |
553 | psiconv_buffer_free(sec_buf); |
449 | ERROR2: |
554 | ERROR2: |
450 | psiconv_list_free(jumptable); |
555 | psiconv_list_free(jumptable); |
451 | ERROR1: |
556 | ERROR1: |
|
|
557 | if (res) |
|
|
558 | psiconv_error(config,lev,0,"Writing of clipart file failed"); |
|
|
559 | else |
|
|
560 | psiconv_progress(config,lev,0,"End of clipart file"); |
452 | return res; |
561 | return res; |
453 | } |
562 | } |