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

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

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