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

Legend:
Removed from v.89  
changed lines
  Added in v.232

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