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