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

Legend:
Removed from v.168  
changed lines
  Added in v.231

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