/[public]/psiconv/trunk/lib/psiconv/generate_common.c
ViewVC logotype

Diff of /psiconv/trunk/lib/psiconv/generate_common.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.184  
changed lines
  Added in v.270

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