1 | /* |
1 | /* |
2 | generate_common.c - Part of psiconv, a PSION 5 file formats converter |
2 | generate_common.c - Part of psiconv, a PSION 5 file formats converter |
3 | Copyright (c) 2000 Frodo Looijaard <frodol@dds.nl> |
3 | Copyright (c) 2000-2005 Frodo Looijaard <frodo@frodo.looijaard.name> |
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. |
… | |
… | |
28 | #ifdef DMALLOC |
28 | #ifdef DMALLOC |
29 | #include <dmalloc.h> |
29 | #include <dmalloc.h> |
30 | #endif |
30 | #endif |
31 | |
31 | |
32 | static int psiconv_write_layout_section(const psiconv_config config, |
32 | static int psiconv_write_layout_section(const psiconv_config config, |
33 | psiconv_buffer buf, |
33 | psiconv_buffer buf, int lev, |
34 | const psiconv_text_and_layout value, |
34 | const psiconv_text_and_layout value, |
35 | const psiconv_word_styles_section styles, |
35 | const psiconv_word_styles_section styles, |
36 | int with_styles); |
36 | int with_styles); |
37 | |
37 | |
38 | /* Maybe use a psiconv_header_section variable instead? */ |
38 | /* Maybe use a psiconv_header_section variable instead? */ |
39 | int psiconv_write_header_section(const psiconv_config config, |
39 | int psiconv_write_header_section(const psiconv_config config, |
40 | psiconv_buffer buf,psiconv_u32 uid1, |
40 | psiconv_buffer buf,int lev,psiconv_u32 uid1, |
41 | psiconv_u32 uid2, psiconv_u32 uid3) |
41 | psiconv_u32 uid2, psiconv_u32 uid3) |
42 | { |
42 | { |
43 | int res; |
43 | int res; |
|
|
44 | psiconv_progress(config,lev,0,"Writing header section"); |
44 | if ((res = psiconv_write_u32(config,buf,uid1))) |
45 | if ((res = psiconv_write_u32(config,buf,lev+1,uid1))) |
45 | return res; |
46 | goto ERROR; |
46 | if ((res = psiconv_write_u32(config,buf,uid2))) |
47 | if ((res = psiconv_write_u32(config,buf,lev+1,uid2))) |
47 | return res; |
48 | goto ERROR; |
48 | if ((res = psiconv_write_u32(config,buf,uid3))) |
49 | if ((res = psiconv_write_u32(config,buf,lev+1,uid3))) |
|
|
50 | goto ERROR; |
|
|
51 | if ((res = psiconv_write_u32(config,buf,lev+1, |
|
|
52 | psiconv_checkuid(uid1,uid2,uid3)))) |
|
|
53 | goto ERROR; |
|
|
54 | psiconv_progress(config,lev,0,"End of header section"); |
|
|
55 | return 0; |
|
|
56 | |
|
|
57 | ERROR: |
|
|
58 | psiconv_error(config,lev,0,"Writing of header section failed"); |
49 | return res; |
59 | return res; |
50 | return psiconv_write_u32(config,buf,psiconv_checkuid(uid1,uid2,uid3)); |
|
|
51 | } |
60 | } |
52 | |
61 | |
53 | int psiconv_write_section_table_section(const psiconv_config config, |
62 | int psiconv_write_section_table_section(const psiconv_config config, |
54 | psiconv_buffer buf, |
63 | psiconv_buffer buf,int lev, |
55 | const psiconv_section_table_section value) |
64 | const psiconv_section_table_section value) |
56 | { |
65 | { |
57 | int res,i; |
66 | int res,i; |
58 | psiconv_section_table_entry entry; |
67 | psiconv_section_table_entry entry; |
59 | |
68 | |
|
|
69 | psiconv_progress(config,lev,0,"Writing section table section"); |
60 | if (!value) { |
70 | if (!value) { |
61 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null section table section"); |
71 | psiconv_error(config,lev,0,"Null section table section"); |
62 | return -PSICONV_E_GENERATE; |
72 | res = -PSICONV_E_GENERATE; |
|
|
73 | goto ERROR; |
63 | } |
74 | } |
64 | |
75 | |
65 | if ((res = psiconv_write_u8(config,buf,2 * psiconv_list_length(value)))) |
76 | if ((res = psiconv_write_u8(config,buf,lev+1,2 * psiconv_list_length(value)))) |
66 | return res; |
77 | goto ERROR; |
67 | for (i = 0; i < psiconv_list_length(value); i++) { |
78 | for (i = 0; i < psiconv_list_length(value); i++) { |
68 | if (!(entry = psiconv_list_get(value,i))) { |
79 | if (!(entry = psiconv_list_get(value,i))) { |
69 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Massive memory corruption"); |
80 | psiconv_error(config,lev+1,0,"Data structure corruption"); |
70 | return -PSICONV_E_NOMEM; |
81 | res = -PSICONV_E_NOMEM; |
|
|
82 | goto ERROR; |
71 | } |
83 | } |
72 | if ((res = psiconv_write_u32(config,buf,entry->id))) |
84 | if ((res = psiconv_write_u32(config,buf,lev+1,entry->id))) |
73 | return res; |
85 | goto ERROR; |
74 | if ((res = psiconv_write_offset(config,buf,entry->offset))) |
86 | if ((res = psiconv_write_offset(config,buf,lev+1,entry->offset))) |
75 | return res; |
87 | goto ERROR; |
76 | } |
88 | } |
|
|
89 | psiconv_progress(config,lev,0,"End of section table section"); |
77 | return -PSICONV_E_OK; |
90 | return -PSICONV_E_OK; |
|
|
91 | |
|
|
92 | ERROR: |
|
|
93 | psiconv_error(config,lev,0,"Writing of section table section failed"); |
|
|
94 | return res; |
78 | } |
95 | } |
79 | |
96 | |
80 | int psiconv_write_application_id_section(const psiconv_config config, |
97 | int psiconv_write_application_id_section(const psiconv_config config, |
81 | psiconv_buffer buf,psiconv_u32 id, |
98 | psiconv_buffer buf,int lev,psiconv_u32 id, |
82 | const psiconv_string_t text) |
99 | const psiconv_string_t text) |
83 | { |
100 | { |
84 | int res; |
101 | int res; |
|
|
102 | psiconv_progress(config,lev,0,"Writing application id section"); |
85 | if ((res = psiconv_write_u32(config,buf,id))) |
103 | if ((res = psiconv_write_u32(config,buf,lev+1,id))) |
|
|
104 | goto ERROR; |
|
|
105 | if ((res = psiconv_write_string(config,buf,lev+1,text))) |
|
|
106 | goto ERROR; |
|
|
107 | psiconv_progress(config,lev,0,"End of application id section"); |
|
|
108 | return 0; |
|
|
109 | ERROR: |
|
|
110 | psiconv_error(config,lev,0,"Writing of application id section failed"); |
86 | return res; |
111 | return res; |
87 | return psiconv_write_string(config,buf,text); |
|
|
88 | } |
112 | } |
89 | |
113 | |
90 | int psiconv_write_text_section(const psiconv_config config, |
114 | int psiconv_write_text_section(const psiconv_config config, |
91 | psiconv_buffer buf, |
115 | psiconv_buffer buf,int lev, |
92 | const psiconv_text_and_layout value) |
116 | const psiconv_text_and_layout value) |
93 | { |
117 | { |
94 | int res; |
118 | int res; |
95 | psiconv_buffer extra_buf; |
119 | psiconv_buffer extra_buf = NULL; |
96 | int i,j; |
120 | int i,j; |
97 | psiconv_paragraph paragraph; |
121 | psiconv_paragraph paragraph; |
98 | |
122 | |
|
|
123 | psiconv_progress(config,lev,0,"Writing text section"); |
99 | if (!value) { |
124 | if (!value) { |
100 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null text section"); |
125 | psiconv_error(config,lev+1,0,"Null text section"); |
101 | return -PSICONV_E_GENERATE; |
126 | res = -PSICONV_E_GENERATE; |
|
|
127 | goto ERROR; |
102 | } |
128 | } |
103 | |
129 | |
104 | if (psiconv_list_length(value)) { |
130 | if (psiconv_list_length(value)) { |
105 | if (!(extra_buf = psiconv_buffer_new())) |
131 | if (!(extra_buf = psiconv_buffer_new())) { |
|
|
132 | psiconv_error(config,lev+1,0,"Out of memory error"); |
106 | return -PSICONV_E_NOMEM; |
133 | res = -PSICONV_E_NOMEM; |
|
|
134 | goto ERROR; |
|
|
135 | } |
107 | for (i = 0; i < psiconv_list_length(value); i++) { |
136 | for (i = 0; i < psiconv_list_length(value); i++) { |
108 | if (!(paragraph = psiconv_list_get(value,i))) { |
137 | if (!(paragraph = psiconv_list_get(value,i))) { |
109 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Massive memory corruption"); |
138 | psiconv_error(config,lev+1,0,"Data structure corruption"); |
110 | res = -PSICONV_E_OTHER; |
139 | res = -PSICONV_E_NOMEM; |
111 | goto ERROR; |
140 | goto ERROR; |
112 | } |
141 | } |
113 | for (j = 0; j < strlen(paragraph->text); j++) |
142 | for (j = 0; j < psiconv_unicode_strlen(paragraph->text); j++) |
114 | if ((res = psiconv_write_u8(config,extra_buf,paragraph->text[j]))) |
143 | if ((res = psiconv_unicode_write_char(config,extra_buf,lev+1, |
|
|
144 | paragraph->text[j]))) |
115 | goto ERROR; |
145 | goto ERROR; |
116 | psiconv_write_u8(config,extra_buf,0x06); |
146 | psiconv_unicode_write_char(config,extra_buf,lev+1,0x06); |
117 | } |
147 | } |
118 | if ((res = psiconv_write_X(config,buf,psiconv_buffer_length(extra_buf)))) |
148 | if ((res = psiconv_write_X(config,buf,lev+1,psiconv_buffer_length(extra_buf)))) |
119 | goto ERROR; |
149 | goto ERROR; |
120 | res = psiconv_buffer_concat(buf,extra_buf); |
150 | res = psiconv_buffer_concat(buf,extra_buf); |
121 | } else |
151 | } else |
122 | /* Hack: empty text sections are just not allowed */ |
152 | /* Hack: empty text sections are just not allowed */ |
123 | return psiconv_write_u16(config,buf,0x0602); |
153 | if ((res = psiconv_write_u16(config,buf,lev+1,0x0602))) |
|
|
154 | goto ERROR; |
|
|
155 | |
|
|
156 | psiconv_progress(config,lev,0,"End of text section"); |
|
|
157 | return 0; |
124 | |
158 | |
125 | ERROR: |
159 | ERROR: |
|
|
160 | if (extra_buf) |
126 | psiconv_buffer_free(extra_buf); |
161 | psiconv_buffer_free(extra_buf); |
|
|
162 | psiconv_error(config,lev,0,"Writing of text section failed"); |
127 | return res; |
163 | return res; |
128 | } |
164 | } |
129 | |
165 | |
130 | int psiconv_write_layout_section(const psiconv_config config, |
166 | int psiconv_write_layout_section(const psiconv_config config, |
131 | psiconv_buffer buf, |
167 | psiconv_buffer buf,int lev, |
132 | const psiconv_text_and_layout value, |
168 | const psiconv_text_and_layout value, |
133 | const psiconv_word_styles_section styles, |
169 | const psiconv_word_styles_section styles, |
134 | int with_styles) |
170 | int with_styles) |
135 | { |
171 | { |
136 | typedef struct psiconv_paragraph_type_list_s |
172 | typedef struct psiconv_paragraph_type_list_s |
… | |
… | |
149 | psiconv_in_line_layout in_line = NULL; |
185 | psiconv_in_line_layout in_line = NULL; |
150 | psiconv_word_style style; |
186 | psiconv_word_style style; |
151 | psiconv_character_layout para_charlayout; |
187 | psiconv_character_layout para_charlayout; |
152 | int i,j,para_type,nr_of_inlines=0,res,ptl_length,pel_length,thislen,paralen; |
188 | int i,j,para_type,nr_of_inlines=0,res,ptl_length,pel_length,thislen,paralen; |
153 | |
189 | |
|
|
190 | psiconv_progress(config,lev,0,"Writing layout section"); |
154 | if (!value) { |
191 | if (!value) { |
155 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null text section"); |
192 | psiconv_error(config,lev,0,"Null text section"); |
156 | return -PSICONV_E_GENERATE; |
193 | res = -PSICONV_E_GENERATE; |
|
|
194 | goto ERROR1; |
157 | } |
195 | } |
158 | |
196 | |
159 | if (!(paragraph_type_list = psiconv_list_new(sizeof(new_type)))) { |
197 | if (!(paragraph_type_list = psiconv_list_new(sizeof(new_type)))) { |
|
|
198 | psiconv_error(config,lev+1,0,"Out of memory error"); |
160 | res = -PSICONV_E_NOMEM; |
199 | res = -PSICONV_E_NOMEM; |
161 | goto ERROR1; |
200 | goto ERROR1; |
162 | } |
201 | } |
163 | |
202 | |
164 | if (!(buf_types = psiconv_buffer_new())) { |
203 | if (!(buf_types = psiconv_buffer_new())) { |
|
|
204 | psiconv_error(config,lev+1,0,"Out of memory error"); |
165 | res = -PSICONV_E_NOMEM; |
205 | res = -PSICONV_E_NOMEM; |
166 | goto ERROR2; |
206 | goto ERROR2; |
167 | } |
207 | } |
168 | |
208 | |
169 | if (!(buf_elements = psiconv_buffer_new())) { |
209 | if (!(buf_elements = psiconv_buffer_new())) { |
|
|
210 | psiconv_error(config,lev+1,0,"Out of memory error"); |
170 | res = -PSICONV_E_NOMEM; |
211 | res = -PSICONV_E_NOMEM; |
171 | goto ERROR3; |
212 | goto ERROR3; |
172 | } |
213 | } |
173 | |
214 | |
174 | if (!(buf_inlines = psiconv_buffer_new())) { |
215 | if (!(buf_inlines = psiconv_buffer_new())) { |
|
|
216 | psiconv_error(config,lev+1,0,"Out of memory error"); |
175 | res = -PSICONV_E_NOMEM; |
217 | res = -PSICONV_E_NOMEM; |
176 | goto ERROR4; |
218 | goto ERROR4; |
177 | } |
219 | } |
178 | |
220 | |
179 | if (!(buf_objects = psiconv_buffer_new())) { |
221 | if (!(buf_objects = psiconv_buffer_new())) { |
|
|
222 | psiconv_error(config,lev+1,0,"Out of memory error"); |
180 | res = -PSICONV_E_NOMEM; |
223 | res = -PSICONV_E_NOMEM; |
181 | goto ERROR5; |
224 | goto ERROR5; |
182 | } |
225 | } |
183 | |
226 | |
184 | for (i = 0; i < psiconv_list_length(value); i++) { |
227 | for (i = 0; i < psiconv_list_length(value); i++) { |
185 | if (!(paragraph = psiconv_list_get(value,i))) { |
228 | if (!(paragraph = psiconv_list_get(value,i))) { |
186 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Massive memory corruption"); |
229 | psiconv_error(config,lev+1,0,"Data structure corruption"); |
187 | res = -PSICONV_E_OTHER; |
230 | res = -PSICONV_E_NOMEM; |
188 | goto ERROR6; |
231 | goto ERROR6; |
189 | } |
232 | } |
190 | if ((res = psiconv_write_u32(config,buf_elements,strlen(paragraph->text)+1))) |
233 | if ((res = psiconv_write_u32(config,buf_elements,lev+1, |
|
|
234 | psiconv_unicode_strlen(paragraph->text)+1))) |
191 | goto ERROR6; |
235 | goto ERROR6; |
192 | |
236 | |
193 | /* We need it for the next if-statement */ |
237 | /* We need it for the next if-statement */ |
194 | if (psiconv_list_length(paragraph->in_lines) == 1) |
238 | if (psiconv_list_length(paragraph->in_lines) == 1) |
195 | if (!(in_line = psiconv_list_get(paragraph->in_lines,1))) |
239 | if (!(in_line = psiconv_list_get(paragraph->in_lines,0))) { |
|
|
240 | psiconv_error(config,lev+1,0,"Data structure corruption"); |
|
|
241 | res = -PSICONV_E_NOMEM; |
196 | goto ERROR6; |
242 | goto ERROR6; |
|
|
243 | } |
197 | |
244 | |
198 | if ((psiconv_list_length(paragraph->in_lines) > 1) || |
245 | if ((psiconv_list_length(paragraph->in_lines) > 1) || |
199 | ((psiconv_list_length(paragraph->in_lines) == 1) && |
246 | ((psiconv_list_length(paragraph->in_lines) == 1) && |
200 | (in_line->object != NULL))) { |
247 | (in_line->object != NULL))) { |
201 | /* Inline layouts, or an object, so we generate a paragraph element |
248 | /* Inline layouts, or an object, so we generate a paragraph element |
202 | and inline elements */ |
249 | and inline elements */ |
203 | if ((res = psiconv_write_u8(config,buf_elements,0x00))) |
250 | if ((res = psiconv_write_u8(config,buf_elements,lev+1,0x00))) |
204 | goto ERROR6; |
251 | goto ERROR6; |
205 | if (!(style = psiconv_get_style(styles,paragraph->base_style))) { |
252 | if (!(style = psiconv_get_style(styles,paragraph->base_style))) { |
206 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Unknown style"); |
253 | psiconv_error(config,lev+1,0,"Unknown style"); |
207 | res = -PSICONV_E_GENERATE; |
254 | res = -PSICONV_E_GENERATE; |
208 | goto ERROR6; |
255 | goto ERROR6; |
209 | } |
256 | } |
210 | if ((res = psiconv_write_paragraph_layout_list(config,buf_elements, |
257 | if ((res = psiconv_write_paragraph_layout_list(config,buf_elements,lev+1, |
211 | paragraph->base_paragraph, |
258 | paragraph->base_paragraph, |
212 | style->paragraph))) |
259 | style->paragraph))) |
213 | goto ERROR6; |
260 | goto ERROR6; |
214 | if (with_styles) |
261 | if (with_styles) |
215 | if ((res = psiconv_write_u8(config,buf_elements,paragraph->base_style))) |
262 | if ((res = psiconv_write_u8(config,buf_elements,lev+1,paragraph->base_style))) |
216 | goto ERROR6; |
263 | goto ERROR6; |
217 | if ((res = psiconv_write_u32(config,buf_elements, |
264 | if ((res = psiconv_write_u32(config,buf_elements,lev+1, |
218 | psiconv_list_length(paragraph->in_lines)))) |
265 | psiconv_list_length(paragraph->in_lines)))) |
219 | goto ERROR6; |
266 | goto ERROR6; |
220 | |
267 | |
221 | /* Generate the inlines. NB: Against what are all settings relative?!? */ |
268 | /* Generate the inlines. NB: Against what are all settings relative?!? */ |
222 | paralen = 0; |
269 | paralen = 0; |
223 | for (j = 0; j < psiconv_list_length(paragraph->in_lines); j++) { |
270 | for (j = 0; j < psiconv_list_length(paragraph->in_lines); j++) { |
224 | nr_of_inlines ++; |
271 | nr_of_inlines ++; |
225 | if (!(in_line = psiconv_list_get(paragraph->in_lines,j))) { |
272 | if (!(in_line = psiconv_list_get(paragraph->in_lines,j))) { |
226 | psiconv_warn(config,0,psiconv_buffer_length(buf), |
273 | psiconv_error(config,lev,0,"Data structure corruption"); |
227 | "Massive memory corruption"); |
|
|
228 | res = -PSICONV_E_OTHER; |
274 | res = -PSICONV_E_NOMEM; |
229 | goto ERROR6; |
275 | goto ERROR6; |
230 | } |
276 | } |
231 | if ((res = psiconv_write_u8(config,buf_inlines,in_line->object?0x01:0x00))) |
277 | if ((res = psiconv_write_u8(config,buf_inlines,lev+1,in_line->object?0x01:0x00))) |
232 | goto ERROR6; |
278 | goto ERROR6; |
233 | thislen = in_line->length; |
279 | thislen = in_line->length; |
234 | paralen += thislen; |
280 | paralen += thislen; |
235 | /* If this is the last in_line, we need to make sure that the |
281 | /* If this is the last in_line, we need to make sure that the |
236 | complete length of all inlines equals the text length */ |
282 | complete length of all inlines equals the text length */ |
237 | if (j == psiconv_list_length(paragraph->in_lines)-1) { |
283 | if (j == psiconv_list_length(paragraph->in_lines)-1) { |
238 | if (paralen > strlen(paragraph->text)+1) { |
284 | if (paralen > psiconv_unicode_strlen(paragraph->text)+1) { |
|
|
285 | psiconv_error(config,lev+1,0,"Inline formatting data length and line length are inconsistent"); |
239 | res = -PSICONV_E_GENERATE; |
286 | res = -PSICONV_E_GENERATE; |
240 | goto ERROR6; |
287 | goto ERROR6; |
241 | } |
288 | } |
242 | thislen += strlen(paragraph->text)+1-paralen; |
289 | thislen += psiconv_unicode_strlen(paragraph->text)+1-paralen; |
243 | } |
290 | } |
244 | if ((res = psiconv_write_u32(config,buf_inlines,thislen))) |
291 | if ((res = psiconv_write_u32(config,buf_inlines,lev+1,thislen))) |
245 | goto ERROR6; |
292 | goto ERROR6; |
246 | if ((res = psiconv_write_character_layout_list(config,buf_inlines, |
293 | if ((res = psiconv_write_character_layout_list(config,buf_inlines,lev+1, |
247 | in_line->layout, |
294 | in_line->layout, |
248 | style->character))) |
295 | style->character))) |
249 | goto ERROR6; |
296 | goto ERROR6; |
250 | if (in_line->object) { |
297 | if (in_line->object) { |
251 | if ((res = psiconv_write_u32(config,buf_inlines,PSICONV_ID_OBJECT))) |
298 | if ((res = psiconv_write_u32(config,buf_inlines,lev+1,PSICONV_ID_OBJECT))) |
252 | goto ERROR6; |
299 | goto ERROR6; |
253 | obj_id = psiconv_buffer_unique_id(); |
300 | obj_id = psiconv_buffer_unique_id(); |
254 | if ((res = psiconv_buffer_add_reference(buf_inlines,obj_id))) |
301 | if ((res = psiconv_buffer_add_reference(buf_inlines,obj_id))) { |
|
|
302 | psiconv_error(config,lev+1,0,"Out of memory error"); |
255 | goto ERROR6; |
303 | goto ERROR6; |
|
|
304 | } |
256 | if ((res = psiconv_buffer_add_target(buf_objects,obj_id))) |
305 | if ((res = psiconv_buffer_add_target(buf_objects,obj_id))) { |
|
|
306 | psiconv_error(config,lev+1,0,"Out of memory error"); |
257 | goto ERROR6; |
307 | goto ERROR6; |
|
|
308 | } |
258 | if ((res = psiconv_write_embedded_object_section(config,buf_objects, |
309 | if ((res = psiconv_write_embedded_object_section(config,buf_objects,lev+1, |
259 | in_line->object))) |
310 | in_line->object))) |
260 | goto ERROR6; |
311 | goto ERROR6; |
261 | if ((res = psiconv_write_length(config,buf_inlines,in_line->object_width))) |
312 | if ((res = psiconv_write_length(config,buf_inlines,lev+1,in_line->object_width))) |
262 | goto ERROR6; |
313 | goto ERROR6; |
263 | if ((res = psiconv_write_length(config,buf_inlines,in_line->object_height))) |
314 | if ((res = psiconv_write_length(config,buf_inlines,lev+1,in_line->object_height))) |
264 | goto ERROR6; |
315 | goto ERROR6; |
265 | } |
316 | } |
266 | } |
317 | } |
267 | } else { |
318 | } else { |
268 | /* No inline layouts (or only 1), so we generate a paragraph type list */ |
319 | /* No inline layouts (or only 1), so we generate a paragraph type list */ |
… | |
… | |
270 | /* Set para_charlayout to the correct character-level layout */ |
321 | /* Set para_charlayout to the correct character-level layout */ |
271 | if (psiconv_list_length(paragraph->in_lines) == 0) |
322 | if (psiconv_list_length(paragraph->in_lines) == 0) |
272 | para_charlayout = paragraph->base_character; |
323 | para_charlayout = paragraph->base_character; |
273 | else { |
324 | else { |
274 | if (!(in_line = psiconv_list_get(paragraph->in_lines,0))) { |
325 | if (!(in_line = psiconv_list_get(paragraph->in_lines,0))) { |
275 | psiconv_warn(config,0,psiconv_buffer_length(buf), |
326 | psiconv_error(config,lev,0,"Data structure corruption"); |
276 | "Massive memory corruption"); |
|
|
277 | res = -PSICONV_E_OTHER; |
327 | res = -PSICONV_E_NOMEM; |
278 | goto ERROR6; |
328 | goto ERROR6; |
279 | } |
329 | } |
280 | para_charlayout = in_line->layout; |
330 | para_charlayout = in_line->layout; |
281 | } |
331 | } |
282 | for (j = 0; j < psiconv_list_length(paragraph_type_list); j++) { |
332 | for (j = 0; j < psiconv_list_length(paragraph_type_list); j++) { |
283 | if (!(paragraph_type = psiconv_list_get(paragraph_type_list,j))) { |
333 | if (!(paragraph_type = psiconv_list_get(paragraph_type_list,j))) { |
284 | psiconv_warn(config,0,psiconv_buffer_length(buf), |
334 | psiconv_error(config,lev,0,"Data structure corruption"); |
285 | "Massive memory corruption"); |
|
|
286 | res = -PSICONV_E_OTHER; |
335 | res = -PSICONV_E_NOMEM; |
287 | goto ERROR6; |
336 | goto ERROR6; |
288 | } |
337 | } |
289 | if ((paragraph->base_style == paragraph_type->style) && |
338 | if ((paragraph->base_style == paragraph_type->style) && |
290 | !psiconv_compare_character_layout(para_charlayout, |
339 | !psiconv_compare_character_layout(para_charlayout, |
291 | paragraph_type->character) && |
340 | paragraph_type->character) && |
… | |
… | |
301 | /* No need to copy them, we won't change them anyway */ |
350 | /* No need to copy them, we won't change them anyway */ |
302 | new_type.paragraph = paragraph->base_paragraph; |
351 | new_type.paragraph = paragraph->base_paragraph; |
303 | new_type.character = para_charlayout; |
352 | new_type.character = para_charlayout; |
304 | new_type.style = paragraph->base_style; |
353 | new_type.style = paragraph->base_style; |
305 | paragraph_type = &new_type; |
354 | paragraph_type = &new_type; |
306 | if ((res = psiconv_list_add(paragraph_type_list,paragraph_type))) |
355 | if ((res = psiconv_list_add(paragraph_type_list,paragraph_type))) { |
|
|
356 | psiconv_error(config,lev+1,0,"Out of memory error"); |
307 | goto ERROR6; |
357 | goto ERROR6; |
|
|
358 | } |
308 | if ((res = psiconv_write_u32(config,buf_types,paragraph_type->nr))) |
359 | if ((res = psiconv_write_u32(config,buf_types,lev+1,paragraph_type->nr))) |
309 | goto ERROR6; |
360 | goto ERROR6; |
310 | if (!(style = psiconv_get_style(styles,paragraph_type->style))) { |
361 | if (!(style = psiconv_get_style(styles,paragraph_type->style))) { |
311 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Unknown style"); |
362 | psiconv_error(config,lev,0,"Unknown style"); |
312 | res = -PSICONV_E_GENERATE; |
363 | res = -PSICONV_E_GENERATE; |
313 | goto ERROR6; |
364 | goto ERROR6; |
314 | } |
365 | } |
315 | if ((res = psiconv_write_paragraph_layout_list(config,buf_types, |
366 | if ((res = psiconv_write_paragraph_layout_list(config,buf_types,lev+1, |
316 | paragraph_type->paragraph,style->paragraph))) |
367 | paragraph_type->paragraph,style->paragraph))) |
317 | goto ERROR6; |
368 | goto ERROR6; |
318 | if (with_styles) |
369 | if (with_styles) |
319 | if ((res = psiconv_write_u8(config,buf_types,paragraph_type->style))) |
370 | if ((res = psiconv_write_u8(config,buf_types,lev+1,paragraph_type->style))) |
320 | goto ERROR6; |
371 | goto ERROR6; |
321 | if ((res = psiconv_write_character_layout_list(config,buf_types, |
372 | if ((res = psiconv_write_character_layout_list(config,buf_types,lev+1, |
322 | paragraph_type->character,style->character))) |
373 | paragraph_type->character,style->character))) |
323 | goto ERROR6; |
374 | goto ERROR6; |
324 | } |
375 | } |
325 | if ((res = psiconv_write_u8(config,buf_elements,para_type))) |
376 | if ((res = psiconv_write_u8(config,buf_elements,lev+1,para_type))) |
326 | goto ERROR6; |
377 | goto ERROR6; |
327 | } |
378 | } |
328 | } |
379 | } |
329 | |
380 | |
330 | /* HACK: special case: no paragraphs at all. We need to improvize. */ |
381 | /* HACK: special case: no paragraphs at all. We need to improvize. */ |
331 | if (!psiconv_list_length(value)) { |
382 | if (!psiconv_list_length(value)) { |
332 | if ((res = psiconv_write_u32(config,buf_types,1))) |
383 | if ((res = psiconv_write_u32(config,buf_types,lev+1,1))) |
333 | goto ERROR6; |
384 | goto ERROR6; |
334 | if ((res = psiconv_write_u32(config,buf_types,0))) |
385 | if ((res = psiconv_write_u32(config,buf_types,lev+1,0))) |
335 | goto ERROR6; |
386 | goto ERROR6; |
336 | if (with_styles) |
387 | if (with_styles) |
337 | if ((res = psiconv_write_u8(config,buf_types,0))) |
388 | if ((res = psiconv_write_u8(config,buf_types,lev+1,0))) |
338 | goto ERROR6; |
389 | goto ERROR6; |
339 | if ((res = psiconv_write_u32(config,buf_types,0))) |
390 | if ((res = psiconv_write_u32(config,buf_types,lev+1,0))) |
340 | goto ERROR6; |
391 | goto ERROR6; |
341 | |
392 | |
342 | if ((res = psiconv_write_u32(config,buf_elements,1))) |
393 | if ((res = psiconv_write_u32(config,buf_elements,lev+1,1))) |
343 | goto ERROR6; |
394 | goto ERROR6; |
344 | if ((res = psiconv_write_u8(config,buf_elements,1))) |
395 | if ((res = psiconv_write_u8(config,buf_elements,lev+1,1))) |
345 | goto ERROR6; |
396 | goto ERROR6; |
346 | pel_length = 1; |
397 | pel_length = 1; |
347 | ptl_length = 1; |
398 | ptl_length = 1; |
348 | } else { |
399 | } else { |
349 | pel_length = psiconv_list_length(value); |
400 | pel_length = psiconv_list_length(value); |
350 | ptl_length = psiconv_list_length(paragraph_type_list); |
401 | ptl_length = psiconv_list_length(paragraph_type_list); |
351 | } |
402 | } |
352 | |
403 | |
353 | /* Now append everything */ |
404 | /* Now append everything */ |
354 | if ((res = psiconv_write_u16(config,buf,with_styles?0x0001:0x0000))) |
405 | if ((res = psiconv_write_u16(config,buf,lev+1,with_styles?0x0001:0x0000))) |
355 | goto ERROR6; |
406 | goto ERROR6; |
356 | if ((res = psiconv_write_u8(config,buf, ptl_length))) |
407 | if ((res = psiconv_write_u8(config,buf,lev+1, ptl_length))) |
357 | goto ERROR6; |
408 | goto ERROR6; |
358 | if ((res = psiconv_buffer_concat(buf,buf_types))) |
409 | if ((res = psiconv_buffer_concat(buf,buf_types))) { |
|
|
410 | psiconv_error(config,lev+1,0,"Out of memory error"); |
359 | goto ERROR6; |
411 | goto ERROR6; |
|
|
412 | } |
360 | if ((res = psiconv_write_u32(config,buf,pel_length))) |
413 | if ((res = psiconv_write_u32(config,buf,lev+1,pel_length))) |
361 | goto ERROR6; |
414 | goto ERROR6; |
362 | if ((res = psiconv_buffer_concat(buf,buf_elements))) |
415 | if ((res = psiconv_buffer_concat(buf,buf_elements))) { |
|
|
416 | psiconv_error(config,lev+1,0,"Out of memory error"); |
363 | goto ERROR6; |
417 | goto ERROR6; |
|
|
418 | } |
364 | if ((res = psiconv_write_u32(config,buf,nr_of_inlines))) |
419 | if ((res = psiconv_write_u32(config,buf,lev+1,nr_of_inlines))) |
365 | goto ERROR6; |
420 | goto ERROR6; |
366 | if ((res = psiconv_buffer_concat(buf,buf_inlines))) |
421 | if ((res = psiconv_buffer_concat(buf,buf_inlines))) { |
|
|
422 | psiconv_error(config,lev+1,0,"Out of memory error"); |
367 | goto ERROR6; |
423 | goto ERROR6; |
|
|
424 | } |
368 | if ((res = psiconv_buffer_concat(buf,buf_objects))) |
425 | if ((res = psiconv_buffer_concat(buf,buf_objects))) { |
|
|
426 | psiconv_error(config,lev+1,0,"Out of memory error"); |
369 | goto ERROR6; |
427 | goto ERROR6; |
|
|
428 | } |
370 | |
429 | |
371 | ERROR6: |
430 | ERROR6: |
372 | psiconv_buffer_free(buf_objects); |
431 | psiconv_buffer_free(buf_objects); |
373 | ERROR5: |
432 | ERROR5: |
374 | psiconv_buffer_free(buf_inlines); |
433 | psiconv_buffer_free(buf_inlines); |
… | |
… | |
377 | ERROR3: |
436 | ERROR3: |
378 | psiconv_buffer_free(buf_types); |
437 | psiconv_buffer_free(buf_types); |
379 | ERROR2: |
438 | ERROR2: |
380 | psiconv_list_free(paragraph_type_list); |
439 | psiconv_list_free(paragraph_type_list); |
381 | ERROR1: |
440 | ERROR1: |
|
|
441 | if (res) |
|
|
442 | psiconv_error(config,lev,0,"Writing of layout section failed"); |
|
|
443 | else |
|
|
444 | psiconv_progress(config,lev,0,"End of layout section"); |
382 | return res; |
445 | return res; |
383 | } |
446 | } |
384 | |
447 | |
385 | int psiconv_write_styled_layout_section(const psiconv_config config, |
448 | int psiconv_write_styled_layout_section(const psiconv_config config, |
386 | psiconv_buffer buf, |
449 | psiconv_buffer buf,int lev, |
387 | psiconv_text_and_layout result, |
450 | psiconv_text_and_layout result, |
388 | psiconv_word_styles_section styles) |
451 | psiconv_word_styles_section styles) |
389 | { |
452 | { |
|
|
453 | int res; |
|
|
454 | |
|
|
455 | psiconv_progress(config,lev,0,"Writing styled layout section"); |
390 | return psiconv_write_layout_section(config,buf,result,styles,1); |
456 | res = psiconv_write_layout_section(config,buf,lev+1,result,styles,1); |
|
|
457 | if (res) |
|
|
458 | psiconv_error(config,lev,0,"Writing of styles layout section failed"); |
|
|
459 | else |
|
|
460 | psiconv_progress(config,lev,0,"End of styled layout section"); |
|
|
461 | return res; |
391 | } |
462 | } |
392 | |
463 | |
393 | int psiconv_write_styleless_layout_section(const psiconv_config config, |
464 | int psiconv_write_styleless_layout_section(const psiconv_config config, |
394 | psiconv_buffer buf, |
465 | psiconv_buffer buf,int lev, |
395 | const psiconv_text_and_layout value, |
466 | const psiconv_text_and_layout value, |
396 | const psiconv_character_layout base_char, |
467 | const psiconv_character_layout base_char, |
397 | const psiconv_paragraph_layout base_para) |
468 | const psiconv_paragraph_layout base_para) |
398 | { |
469 | { |
399 | int res = 0; |
470 | int res = 0; |
400 | psiconv_word_styles_section styles_section; |
471 | psiconv_word_styles_section styles_section; |
401 | |
472 | |
|
|
473 | psiconv_progress(config,lev,0,"Writing styleless layout section"); |
402 | if (!(styles_section = malloc(sizeof(*styles_section)))) |
474 | if (!(styles_section = malloc(sizeof(*styles_section)))) { |
|
|
475 | psiconv_error(config,lev+1,0,"Out of memory error"); |
403 | goto ERROR1; |
476 | goto ERROR1; |
|
|
477 | } |
404 | if (!(styles_section->normal = malloc(sizeof(*styles_section->normal)))) |
478 | if (!(styles_section->normal = malloc(sizeof(*styles_section->normal)))) { |
|
|
479 | psiconv_error(config,lev+1,0,"Out of memory error"); |
405 | goto ERROR2; |
480 | goto ERROR2; |
|
|
481 | } |
406 | if (!(styles_section->normal->character = |
482 | if (!(styles_section->normal->character = |
407 | psiconv_clone_character_layout(base_char))) |
483 | psiconv_clone_character_layout(base_char))) { |
|
|
484 | psiconv_error(config,lev+1,0,"Out of memory error"); |
408 | goto ERROR3; |
485 | goto ERROR3; |
|
|
486 | } |
409 | if (!(styles_section->normal->paragraph = |
487 | if (!(styles_section->normal->paragraph = |
410 | psiconv_clone_paragraph_layout(base_para))) |
488 | psiconv_clone_paragraph_layout(base_para))) { |
|
|
489 | psiconv_error(config,lev+1,0,"Out of memory error"); |
411 | goto ERROR4; |
490 | goto ERROR4; |
|
|
491 | } |
412 | styles_section->normal->hotkey = 0; |
492 | styles_section->normal->hotkey = 0; |
413 | if (!(styles_section->normal->name = strdup(""))) |
493 | if (!(styles_section->normal->name = psiconv_unicode_empty_string())) { |
|
|
494 | psiconv_error(config,lev+1,0,"Out of memory error"); |
414 | goto ERROR5; |
495 | goto ERROR5; |
|
|
496 | } |
415 | if (!(styles_section->styles = psiconv_list_new(sizeof( |
497 | if (!(styles_section->styles = psiconv_list_new(sizeof( |
416 | struct psiconv_word_style_s)))) |
498 | struct psiconv_word_style_s)))) { |
|
|
499 | psiconv_error(config,lev+1,0,"Out of memory error"); |
417 | goto ERROR6; |
500 | goto ERROR6; |
|
|
501 | } |
418 | |
502 | |
419 | res = psiconv_write_layout_section(config,buf,value,styles_section,0); |
503 | res = psiconv_write_layout_section(config,buf,lev+1,value,styles_section,0); |
420 | psiconv_free_word_styles_section(styles_section); |
504 | psiconv_free_word_styles_section(styles_section); |
|
|
505 | psiconv_progress(config,lev,0,"End of styleless layout section"); |
421 | return res; |
506 | return res; |
422 | |
507 | |
423 | ERROR6: |
508 | ERROR6: |
424 | free(styles_section->normal->name); |
509 | free(styles_section->normal->name); |
425 | ERROR5: |
510 | ERROR5: |
… | |
… | |
429 | ERROR3: |
514 | ERROR3: |
430 | free(styles_section->normal); |
515 | free(styles_section->normal); |
431 | ERROR2: |
516 | ERROR2: |
432 | free(styles_section); |
517 | free(styles_section); |
433 | ERROR1: |
518 | ERROR1: |
|
|
519 | psiconv_error(config,lev,0,"Writing of styleless layout section failed"); |
434 | if (!res) |
520 | if (!res) |
435 | return -PSICONV_E_NOMEM; |
521 | return -PSICONV_E_NOMEM; |
436 | else |
522 | else |
437 | return res; |
523 | return res; |
438 | } |
524 | } |
439 | |
525 | |
440 | |
526 | |
441 | int psiconv_write_embedded_object_section(const psiconv_config config, |
527 | int psiconv_write_embedded_object_section(const psiconv_config config, |
442 | psiconv_buffer buf, |
528 | psiconv_buffer buf,int lev, |
443 | const psiconv_embedded_object_section value) |
529 | const psiconv_embedded_object_section value) |
444 | { |
530 | { |
445 | int res; |
531 | int res; |
446 | psiconv_u32 display_id,icon_id,table_id; |
532 | psiconv_u32 display_id,icon_id,table_id; |
447 | psiconv_buffer extra_buf; |
533 | psiconv_buffer extra_buf; |
448 | |
534 | |
|
|
535 | psiconv_progress(config,lev,0,"Writing embedded object section"); |
449 | if (!value) { |
536 | if (!value) { |
450 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null Object"); |
537 | psiconv_error(config,lev,0,"Null Object"); |
451 | res = -PSICONV_E_GENERATE; |
538 | res = -PSICONV_E_GENERATE; |
452 | goto ERROR1; |
539 | goto ERROR1; |
453 | } |
540 | } |
454 | |
541 | |
455 | if (!(extra_buf = psiconv_buffer_new())) { |
542 | if (!(extra_buf = psiconv_buffer_new())) { |
|
|
543 | psiconv_error(config,lev+1,0,"Out of memory error"); |
456 | res = -PSICONV_E_NOMEM; |
544 | res = -PSICONV_E_NOMEM; |
457 | goto ERROR1; |
545 | goto ERROR1; |
458 | } |
546 | } |
459 | |
547 | |
460 | display_id = psiconv_buffer_unique_id(); |
548 | display_id = psiconv_buffer_unique_id(); |
461 | icon_id = psiconv_buffer_unique_id(); |
549 | icon_id = psiconv_buffer_unique_id(); |
462 | table_id = psiconv_buffer_unique_id(); |
550 | table_id = psiconv_buffer_unique_id(); |
463 | if ((res = psiconv_write_u8(config,buf,0x06))) |
551 | if ((res = psiconv_write_u8(config,buf,lev+1,0x06))) |
464 | goto ERROR2; |
552 | goto ERROR2; |
465 | if ((res = psiconv_write_u32(config,buf,PSICONV_ID_OBJECT_DISPLAY_SECTION))) |
553 | if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_OBJECT_DISPLAY_SECTION))) |
466 | goto ERROR2; |
554 | goto ERROR2; |
467 | if ((res = psiconv_buffer_add_reference(buf,display_id))) |
555 | if ((res = psiconv_buffer_add_reference(buf,display_id))) { |
|
|
556 | psiconv_error(config,lev+1,0,"Out of memory error"); |
468 | goto ERROR2; |
557 | goto ERROR2; |
|
|
558 | } |
469 | if ((res = psiconv_write_u32(config,buf,PSICONV_ID_OBJECT_ICON_SECTION))) |
559 | if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_OBJECT_ICON_SECTION))) |
470 | goto ERROR2; |
560 | goto ERROR2; |
471 | if ((res = psiconv_buffer_add_reference(buf,icon_id))) |
561 | if ((res = psiconv_buffer_add_reference(buf,icon_id))) { |
|
|
562 | psiconv_error(config,lev+1,0,"Out of memory error"); |
472 | goto ERROR2; |
563 | goto ERROR2; |
|
|
564 | } |
473 | if ((res = psiconv_write_u32(config,buf,PSICONV_ID_OBJECT_SECTION_TABLE_SECTION))) |
565 | if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_OBJECT_SECTION_TABLE_SECTION))) |
474 | goto ERROR2; |
566 | goto ERROR2; |
475 | if ((res = psiconv_buffer_add_reference(buf,table_id))) |
567 | if ((res = psiconv_buffer_add_reference(buf,table_id))) { |
|
|
568 | psiconv_error(config,lev+1,0,"Out of memory error"); |
476 | goto ERROR2; |
569 | goto ERROR2; |
|
|
570 | } |
477 | |
571 | |
478 | if ((res = psiconv_buffer_add_target(buf,display_id))) |
572 | if ((res = psiconv_buffer_add_target(buf,display_id))) { |
|
|
573 | psiconv_error(config,lev+1,0,"Out of memory error"); |
479 | goto ERROR2; |
574 | goto ERROR2; |
|
|
575 | } |
480 | if ((res = psiconv_write_object_display_section(config,buf,value->display))) |
576 | if ((res = psiconv_write_object_display_section(config,buf,lev+1,value->display))) |
481 | goto ERROR2; |
577 | goto ERROR2; |
482 | if ((res = psiconv_buffer_add_target(buf,icon_id))) |
578 | if ((res = psiconv_buffer_add_target(buf,icon_id))) { |
|
|
579 | psiconv_error(config,lev+1,0,"Out of memory error"); |
483 | goto ERROR2; |
580 | goto ERROR2; |
|
|
581 | } |
484 | if ((res = psiconv_write_object_icon_section(config,buf,value->icon))) |
582 | if ((res = psiconv_write_object_icon_section(config,buf,lev+1,value->icon))) |
485 | goto ERROR2; |
583 | goto ERROR2; |
486 | if ((res = psiconv_buffer_add_target(buf,table_id))) |
584 | if ((res = psiconv_buffer_add_target(buf,table_id))) { |
|
|
585 | psiconv_error(config,lev+1,0,"Out of memory error"); |
487 | goto ERROR2; |
586 | goto ERROR2; |
|
|
587 | } |
488 | switch(value->object->type) { |
588 | switch(value->object->type) { |
489 | case psiconv_word_file: |
589 | case psiconv_word_file: |
490 | if ((res = psiconv_write_word_file(config,extra_buf, |
590 | if ((res = psiconv_write_word_file(config,extra_buf,lev+1, |
491 | (psiconv_word_f) value->object->file))) |
591 | (psiconv_word_f) value->object->file))) |
492 | goto ERROR2; |
592 | goto ERROR2; |
493 | break; |
593 | break; |
494 | /* |
|
|
495 | case psiconv_sketch_file: |
594 | case psiconv_sketch_file: |
496 | if ((res = psiconv_write_sketch_file(extra_buf, |
595 | if ((res = psiconv_write_sketch_file(config,extra_buf,lev+1, |
497 | (psiconv_sketch_f) value->object->file))) |
596 | (psiconv_sketch_f) value->object->file))) |
498 | goto ERROR2; |
597 | goto ERROR2; |
499 | break; |
598 | break; |
|
|
599 | /* |
500 | case psiconv_sheet_file: |
600 | case psiconv_sheet_file: |
501 | if ((res = psiconv_write_sheet_file(extra_buf, |
601 | if ((res = psiconv_write_sheet_file(config,extra_buf,lev+1, |
502 | (psiconv_sheet_f) value->object->file))) |
602 | (psiconv_sheet_f) value->object->file))) |
503 | goto ERROR2; |
603 | goto ERROR2; |
504 | break; |
604 | break; |
505 | */ |
605 | */ |
506 | default: |
606 | default: |
507 | psiconv_warn(config,0,psiconv_buffer_length(buf), |
607 | psiconv_error(config,lev,0,"Unknown or unsupported object type"); |
508 | "Unknown or unsupported object type"); |
|
|
509 | res = -PSICONV_E_GENERATE; |
608 | res = -PSICONV_E_GENERATE; |
510 | goto ERROR2; |
609 | goto ERROR2; |
511 | } |
610 | } |
512 | |
611 | |
513 | if ((res = psiconv_buffer_resolve(extra_buf))) |
612 | if ((res = psiconv_buffer_resolve(extra_buf))) { |
|
|
613 | psiconv_error(config,lev+1,0,"Internal error resolving buffer references"); |
514 | goto ERROR2; |
614 | goto ERROR2; |
|
|
615 | } |
515 | if ((res = psiconv_buffer_concat(buf,extra_buf))) |
616 | if ((res = psiconv_buffer_concat(buf,extra_buf))) { |
|
|
617 | psiconv_error(config,lev+1,0,"Out of memory error"); |
516 | goto ERROR2; |
618 | goto ERROR2; |
|
|
619 | } |
|
|
620 | psiconv_buffer_free(extra_buf); |
517 | |
621 | |
|
|
622 | psiconv_progress(config,lev,0,"End of embedded object section"); |
518 | return 0; |
623 | return 0; |
519 | |
624 | |
520 | ERROR2: |
625 | ERROR2: |
521 | psiconv_buffer_free(extra_buf); |
626 | psiconv_buffer_free(extra_buf); |
522 | ERROR1: |
627 | ERROR1: |
|
|
628 | psiconv_error(config,lev,0,"Writing of embedded object section failed"); |
523 | return res; |
629 | return res; |
524 | } |
630 | } |
525 | |
631 | |
526 | |
632 | |
527 | int psiconv_write_object_display_section(const psiconv_config config, |
633 | int psiconv_write_object_display_section(const psiconv_config config, |
528 | psiconv_buffer buf, |
634 | psiconv_buffer buf,int lev, |
529 | const psiconv_object_display_section value) |
635 | const psiconv_object_display_section value) |
530 | { |
636 | { |
531 | int res; |
637 | int res; |
532 | |
638 | |
|
|
639 | psiconv_progress(config,lev,0,"Writing object display section"); |
|
|
640 | |
533 | if (!value) { |
641 | if (!value) { |
534 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null Object Display Section"); |
642 | psiconv_error(config,lev,0,"Null Object Display Section"); |
535 | res = -PSICONV_E_GENERATE; |
643 | res = -PSICONV_E_GENERATE; |
536 | goto ERROR1; |
644 | goto ERROR1; |
537 | } |
645 | } |
538 | |
646 | |
539 | if ((res = psiconv_write_u8(config,buf,value->show_icon?0x00:0x01))) |
647 | if ((res = psiconv_write_u8(config,buf,lev+1,value->show_icon?0x00:0x01))) |
540 | goto ERROR1; |
648 | goto ERROR1; |
541 | if ((res = psiconv_write_length(config,buf,value->width))) |
649 | if ((res = psiconv_write_length(config,buf,lev+1,value->width))) |
542 | goto ERROR1; |
650 | goto ERROR1; |
543 | if ((res = psiconv_write_length(config,buf,value->height))) |
651 | if ((res = psiconv_write_length(config,buf,lev+1,value->height))) |
544 | goto ERROR1; |
652 | goto ERROR1; |
545 | if ((res = psiconv_write_u32(config,buf,0x00000000))) |
653 | if ((res = psiconv_write_u32(config,buf,lev+1,0x00000000))) |
546 | goto ERROR1; |
654 | goto ERROR1; |
|
|
655 | |
|
|
656 | psiconv_progress(config,lev,0,"End of object display section"); |
547 | |
657 | |
548 | return 0; |
658 | return 0; |
549 | |
659 | |
550 | ERROR1: |
660 | ERROR1: |
|
|
661 | psiconv_error(config,lev,0,"Writing of object display section failed"); |
551 | return res; |
662 | return res; |
552 | } |
663 | } |
553 | |
664 | |
554 | int psiconv_write_object_icon_section(const psiconv_config config, |
665 | int psiconv_write_object_icon_section(const psiconv_config config, |
555 | psiconv_buffer buf, |
666 | psiconv_buffer buf,int lev, |
556 | const psiconv_object_icon_section value) |
667 | const psiconv_object_icon_section value) |
557 | { |
668 | { |
558 | int res; |
669 | int res; |
559 | |
670 | |
|
|
671 | psiconv_progress(config,lev,0,"Writing object icon section"); |
|
|
672 | |
560 | if (!value) { |
673 | if (!value) { |
561 | psiconv_warn(config,0,psiconv_buffer_length(buf),"Null Object Icon Section"); |
674 | psiconv_error(config,lev,0,"Null Object Icon Section"); |
562 | res = -PSICONV_E_GENERATE; |
675 | res = -PSICONV_E_GENERATE; |
563 | goto ERROR1; |
676 | goto ERROR1; |
564 | } |
677 | } |
565 | |
678 | |
566 | if ((res = psiconv_write_string(config,buf,value->icon_name))) |
679 | if ((res = psiconv_write_string(config,buf,lev+1,value->icon_name))) |
567 | goto ERROR1; |
680 | goto ERROR1; |
568 | if ((res = psiconv_write_length(config,buf,value->icon_width))) |
681 | if ((res = psiconv_write_length(config,buf,lev+1,value->icon_width))) |
569 | goto ERROR1; |
682 | goto ERROR1; |
570 | if ((res = psiconv_write_length(config,buf,value->icon_height))) |
683 | if ((res = psiconv_write_length(config,buf,lev+1,value->icon_height))) |
571 | goto ERROR1; |
684 | goto ERROR1; |
572 | |
685 | |
|
|
686 | psiconv_progress(config,lev,0,"End of object icon section"); |
573 | return 0; |
687 | return 0; |
574 | |
688 | |
575 | ERROR1: |
689 | ERROR1: |
|
|
690 | psiconv_error(config,lev,0,"Writing of object icon section failed"); |
576 | return res; |
691 | return res; |
577 | } |
692 | } |