/[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 231 Revision 233
75 75
76 if ((res = psiconv_write_u8(config,buf,lev+1,2 * psiconv_list_length(value)))) 76 if ((res = psiconv_write_u8(config,buf,lev+1,2 * psiconv_list_length(value))))
77 goto ERROR; 77 goto ERROR;
78 for (i = 0; i < psiconv_list_length(value); i++) { 78 for (i = 0; i < psiconv_list_length(value); i++) {
79 if (!(entry = psiconv_list_get(value,i))) { 79 if (!(entry = psiconv_list_get(value,i))) {
80 psiconv_error(config,lev+1,0,"Massive memory corruption"); 80 psiconv_error(config,lev+1,0,"Data structure corruption");
81 res = -PSICONV_E_NOMEM; 81 res = -PSICONV_E_NOMEM;
82 goto ERROR; 82 goto ERROR;
83 } 83 }
84 if ((res = psiconv_write_u32(config,buf,lev+1,entry->id))) 84 if ((res = psiconv_write_u32(config,buf,lev+1,entry->id)))
85 goto ERROR; 85 goto ERROR;
127 goto ERROR; 127 goto ERROR;
128 } 128 }
129 129
130 if (psiconv_list_length(value)) { 130 if (psiconv_list_length(value)) {
131 if (!(extra_buf = psiconv_buffer_new())) { 131 if (!(extra_buf = psiconv_buffer_new())) {
132 psiconv_error(config,lev+1,0,"Out of memory error");
132 res = -PSICONV_E_NOMEM; 133 res = -PSICONV_E_NOMEM;
133 goto ERROR; 134 goto ERROR;
134 } 135 }
135 for (i = 0; i < psiconv_list_length(value); i++) { 136 for (i = 0; i < psiconv_list_length(value); i++) {
136 if (!(paragraph = psiconv_list_get(value,i))) { 137 if (!(paragraph = psiconv_list_get(value,i))) {
137 psiconv_error(config,lev+1,0,"Massive memory corruption"); 138 psiconv_error(config,lev+1,0,"Data structure corruption");
138 res = -PSICONV_E_NOMEM; 139 res = -PSICONV_E_NOMEM;
139 goto ERROR; 140 goto ERROR;
140 } 141 }
141 for (j = 0; j < psiconv_unicode_strlen(paragraph->text); j++) 142 for (j = 0; j < psiconv_unicode_strlen(paragraph->text); j++)
142 if ((res = psiconv_unicode_write_char(config,extra_buf,lev+1, 143 if ((res = psiconv_unicode_write_char(config,extra_buf,lev+1,
192 res = -PSICONV_E_GENERATE; 193 res = -PSICONV_E_GENERATE;
193 goto ERROR1; 194 goto ERROR1;
194 } 195 }
195 196
196 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");
197 res = -PSICONV_E_NOMEM; 199 res = -PSICONV_E_NOMEM;
198 goto ERROR1; 200 goto ERROR1;
199 } 201 }
200 202
201 if (!(buf_types = psiconv_buffer_new())) { 203 if (!(buf_types = psiconv_buffer_new())) {
204 psiconv_error(config,lev+1,0,"Out of memory error");
202 res = -PSICONV_E_NOMEM; 205 res = -PSICONV_E_NOMEM;
203 goto ERROR2; 206 goto ERROR2;
204 } 207 }
205 208
206 if (!(buf_elements = psiconv_buffer_new())) { 209 if (!(buf_elements = psiconv_buffer_new())) {
210 psiconv_error(config,lev+1,0,"Out of memory error");
207 res = -PSICONV_E_NOMEM; 211 res = -PSICONV_E_NOMEM;
208 goto ERROR3; 212 goto ERROR3;
209 } 213 }
210 214
211 if (!(buf_inlines = psiconv_buffer_new())) { 215 if (!(buf_inlines = psiconv_buffer_new())) {
216 psiconv_error(config,lev+1,0,"Out of memory error");
212 res = -PSICONV_E_NOMEM; 217 res = -PSICONV_E_NOMEM;
213 goto ERROR4; 218 goto ERROR4;
214 } 219 }
215 220
216 if (!(buf_objects = psiconv_buffer_new())) { 221 if (!(buf_objects = psiconv_buffer_new())) {
222 psiconv_error(config,lev+1,0,"Out of memory error");
217 res = -PSICONV_E_NOMEM; 223 res = -PSICONV_E_NOMEM;
218 goto ERROR5; 224 goto ERROR5;
219 } 225 }
220 226
221 for (i = 0; i < psiconv_list_length(value); i++) { 227 for (i = 0; i < psiconv_list_length(value); i++) {
222 if (!(paragraph = psiconv_list_get(value,i))) { 228 if (!(paragraph = psiconv_list_get(value,i))) {
223 psiconv_error(config,lev+1,0,"Massive memory corruption"); 229 psiconv_error(config,lev+1,0,"Data structure corruption");
224 res = -PSICONV_E_NOMEM; 230 res = -PSICONV_E_NOMEM;
225 goto ERROR6; 231 goto ERROR6;
226 } 232 }
227 if ((res = psiconv_write_u32(config,buf_elements,lev+1, 233 if ((res = psiconv_write_u32(config,buf_elements,lev+1,
228 psiconv_unicode_strlen(paragraph->text)+1))) 234 psiconv_unicode_strlen(paragraph->text)+1)))
229 goto ERROR6; 235 goto ERROR6;
230 236
231 /* We need it for the next if-statement */ 237 /* We need it for the next if-statement */
232 if (psiconv_list_length(paragraph->in_lines) == 1) 238 if (psiconv_list_length(paragraph->in_lines) == 1)
233 if (!(in_line = psiconv_list_get(paragraph->in_lines,1))) 239 if (!(in_line = psiconv_list_get(paragraph->in_lines,1))) {
240 psiconv_error(config,lev+1,0,"Data structure corruption");
241 res = -PSICONV_E_NOMEM;
234 goto ERROR6; 242 goto ERROR6;
243 }
235 244
236 if ((psiconv_list_length(paragraph->in_lines) > 1) || 245 if ((psiconv_list_length(paragraph->in_lines) > 1) ||
237 ((psiconv_list_length(paragraph->in_lines) == 1) && 246 ((psiconv_list_length(paragraph->in_lines) == 1) &&
238 (in_line->object != NULL))) { 247 (in_line->object != NULL))) {
239 /* Inline layouts, or an object, so we generate a paragraph element 248 /* Inline layouts, or an object, so we generate a paragraph element
259 /* Generate the inlines. NB: Against what are all settings relative?!? */ 268 /* Generate the inlines. NB: Against what are all settings relative?!? */
260 paralen = 0; 269 paralen = 0;
261 for (j = 0; j < psiconv_list_length(paragraph->in_lines); j++) { 270 for (j = 0; j < psiconv_list_length(paragraph->in_lines); j++) {
262 nr_of_inlines ++; 271 nr_of_inlines ++;
263 if (!(in_line = psiconv_list_get(paragraph->in_lines,j))) { 272 if (!(in_line = psiconv_list_get(paragraph->in_lines,j))) {
264 psiconv_error(config,lev,0,"Massive memory corruption"); 273 psiconv_error(config,lev,0,"Data structure corruption");
265 res = -PSICONV_E_NOMEM; 274 res = -PSICONV_E_NOMEM;
266 goto ERROR6; 275 goto ERROR6;
267 } 276 }
268 if ((res = psiconv_write_u8(config,buf_inlines,lev+1,in_line->object?0x01:0x00))) 277 if ((res = psiconv_write_u8(config,buf_inlines,lev+1,in_line->object?0x01:0x00)))
269 goto ERROR6; 278 goto ERROR6;
271 paralen += thislen; 280 paralen += thislen;
272 /* 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
273 complete length of all inlines equals the text length */ 282 complete length of all inlines equals the text length */
274 if (j == psiconv_list_length(paragraph->in_lines)-1) { 283 if (j == psiconv_list_length(paragraph->in_lines)-1) {
275 if (paralen > psiconv_unicode_strlen(paragraph->text)+1) { 284 if (paralen > psiconv_unicode_strlen(paragraph->text)+1) {
285 psiconv_error(config,lev+1,0,"Inline formatting data length and line length are inconsistent");
276 res = -PSICONV_E_GENERATE; 286 res = -PSICONV_E_GENERATE;
277 goto ERROR6; 287 goto ERROR6;
278 } 288 }
279 thislen += psiconv_unicode_strlen(paragraph->text)+1-paralen; 289 thislen += psiconv_unicode_strlen(paragraph->text)+1-paralen;
280 } 290 }
286 goto ERROR6; 296 goto ERROR6;
287 if (in_line->object) { 297 if (in_line->object) {
288 if ((res = psiconv_write_u32(config,buf_inlines,lev+1,PSICONV_ID_OBJECT))) 298 if ((res = psiconv_write_u32(config,buf_inlines,lev+1,PSICONV_ID_OBJECT)))
289 goto ERROR6; 299 goto ERROR6;
290 obj_id = psiconv_buffer_unique_id(); 300 obj_id = psiconv_buffer_unique_id();
291 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");
292 goto ERROR6; 303 goto ERROR6;
304 }
293 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");
294 goto ERROR6; 307 goto ERROR6;
308 }
295 if ((res = psiconv_write_embedded_object_section(config,buf_objects,lev+1, 309 if ((res = psiconv_write_embedded_object_section(config,buf_objects,lev+1,
296 in_line->object))) 310 in_line->object)))
297 goto ERROR6; 311 goto ERROR6;
298 if ((res = psiconv_write_length(config,buf_inlines,lev+1,in_line->object_width))) 312 if ((res = psiconv_write_length(config,buf_inlines,lev+1,in_line->object_width)))
299 goto ERROR6; 313 goto ERROR6;
307 /* Set para_charlayout to the correct character-level layout */ 321 /* Set para_charlayout to the correct character-level layout */
308 if (psiconv_list_length(paragraph->in_lines) == 0) 322 if (psiconv_list_length(paragraph->in_lines) == 0)
309 para_charlayout = paragraph->base_character; 323 para_charlayout = paragraph->base_character;
310 else { 324 else {
311 if (!(in_line = psiconv_list_get(paragraph->in_lines,0))) { 325 if (!(in_line = psiconv_list_get(paragraph->in_lines,0))) {
312 psiconv_error(config,lev,0,"Massive memory corruption"); 326 psiconv_error(config,lev,0,"Data structure corruption");
313 res = -PSICONV_E_NOMEM; 327 res = -PSICONV_E_NOMEM;
314 goto ERROR6; 328 goto ERROR6;
315 } 329 }
316 para_charlayout = in_line->layout; 330 para_charlayout = in_line->layout;
317 } 331 }
318 for (j = 0; j < psiconv_list_length(paragraph_type_list); j++) { 332 for (j = 0; j < psiconv_list_length(paragraph_type_list); j++) {
319 if (!(paragraph_type = psiconv_list_get(paragraph_type_list,j))) { 333 if (!(paragraph_type = psiconv_list_get(paragraph_type_list,j))) {
320 psiconv_error(config,lev,0,"Massive memory corruption"); 334 psiconv_error(config,lev,0,"Data structure corruption");
321 res = -PSICONV_E_NOMEM; 335 res = -PSICONV_E_NOMEM;
322 goto ERROR6; 336 goto ERROR6;
323 } 337 }
324 if ((paragraph->base_style == paragraph_type->style) && 338 if ((paragraph->base_style == paragraph_type->style) &&
325 !psiconv_compare_character_layout(para_charlayout, 339 !psiconv_compare_character_layout(para_charlayout,
336 /* No need to copy them, we won't change them anyway */ 350 /* No need to copy them, we won't change them anyway */
337 new_type.paragraph = paragraph->base_paragraph; 351 new_type.paragraph = paragraph->base_paragraph;
338 new_type.character = para_charlayout; 352 new_type.character = para_charlayout;
339 new_type.style = paragraph->base_style; 353 new_type.style = paragraph->base_style;
340 paragraph_type = &new_type; 354 paragraph_type = &new_type;
341 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");
342 goto ERROR6; 357 goto ERROR6;
358 }
343 if ((res = psiconv_write_u32(config,buf_types,lev+1,paragraph_type->nr))) 359 if ((res = psiconv_write_u32(config,buf_types,lev+1,paragraph_type->nr)))
344 goto ERROR6; 360 goto ERROR6;
345 if (!(style = psiconv_get_style(styles,paragraph_type->style))) { 361 if (!(style = psiconv_get_style(styles,paragraph_type->style))) {
346 psiconv_error(config,lev,0,"Unknown style"); 362 psiconv_error(config,lev,0,"Unknown style");
347 res = -PSICONV_E_GENERATE; 363 res = -PSICONV_E_GENERATE;
388 /* Now append everything */ 404 /* Now append everything */
389 if ((res = psiconv_write_u16(config,buf,lev+1,with_styles?0x0001:0x0000))) 405 if ((res = psiconv_write_u16(config,buf,lev+1,with_styles?0x0001:0x0000)))
390 goto ERROR6; 406 goto ERROR6;
391 if ((res = psiconv_write_u8(config,buf,lev+1, ptl_length))) 407 if ((res = psiconv_write_u8(config,buf,lev+1, ptl_length)))
392 goto ERROR6; 408 goto ERROR6;
393 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");
394 goto ERROR6; 411 goto ERROR6;
412 }
395 if ((res = psiconv_write_u32(config,buf,lev+1,pel_length))) 413 if ((res = psiconv_write_u32(config,buf,lev+1,pel_length)))
396 goto ERROR6; 414 goto ERROR6;
397 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");
398 goto ERROR6; 417 goto ERROR6;
418 }
399 if ((res = psiconv_write_u32(config,buf,lev+1,nr_of_inlines))) 419 if ((res = psiconv_write_u32(config,buf,lev+1,nr_of_inlines)))
400 goto ERROR6; 420 goto ERROR6;
401 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");
402 goto ERROR6; 423 goto ERROR6;
424 }
403 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");
404 goto ERROR6; 427 goto ERROR6;
428 }
405 429
406ERROR6: 430ERROR6:
407 psiconv_buffer_free(buf_objects); 431 psiconv_buffer_free(buf_objects);
408ERROR5: 432ERROR5:
409 psiconv_buffer_free(buf_inlines); 433 psiconv_buffer_free(buf_inlines);
445{ 469{
446 int res = 0; 470 int res = 0;
447 psiconv_word_styles_section styles_section; 471 psiconv_word_styles_section styles_section;
448 472
449 psiconv_progress(config,lev,0,"Writing styleless layout section"); 473 psiconv_progress(config,lev,0,"Writing styleless layout section");
450 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");
451 goto ERROR1; 476 goto ERROR1;
477 }
452 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");
453 goto ERROR2; 480 goto ERROR2;
481 }
454 if (!(styles_section->normal->character = 482 if (!(styles_section->normal->character =
455 psiconv_clone_character_layout(base_char))) 483 psiconv_clone_character_layout(base_char))) {
484 psiconv_error(config,lev+1,0,"Out of memory error");
456 goto ERROR3; 485 goto ERROR3;
486 }
457 if (!(styles_section->normal->paragraph = 487 if (!(styles_section->normal->paragraph =
458 psiconv_clone_paragraph_layout(base_para))) 488 psiconv_clone_paragraph_layout(base_para))) {
489 psiconv_error(config,lev+1,0,"Out of memory error");
459 goto ERROR4; 490 goto ERROR4;
491 }
460 styles_section->normal->hotkey = 0; 492 styles_section->normal->hotkey = 0;
461 if (!(styles_section->normal->name = psiconv_unicode_empty_string())) 493 if (!(styles_section->normal->name = psiconv_unicode_empty_string())) {
494 psiconv_error(config,lev+1,0,"Out of memory error");
462 goto ERROR5; 495 goto ERROR5;
496 }
463 if (!(styles_section->styles = psiconv_list_new(sizeof( 497 if (!(styles_section->styles = psiconv_list_new(sizeof(
464 struct psiconv_word_style_s)))) 498 struct psiconv_word_style_s)))) {
499 psiconv_error(config,lev+1,0,"Out of memory error");
465 goto ERROR6; 500 goto ERROR6;
501 }
466 502
467 res = psiconv_write_layout_section(config,buf,lev+1,value,styles_section,0); 503 res = psiconv_write_layout_section(config,buf,lev+1,value,styles_section,0);
468 psiconv_free_word_styles_section(styles_section); 504 psiconv_free_word_styles_section(styles_section);
469 psiconv_progress(config,lev,0,"End of styleless layout section"); 505 psiconv_progress(config,lev,0,"End of styleless layout section");
470 return res; 506 return res;
502 res = -PSICONV_E_GENERATE; 538 res = -PSICONV_E_GENERATE;
503 goto ERROR1; 539 goto ERROR1;
504 } 540 }
505 541
506 if (!(extra_buf = psiconv_buffer_new())) { 542 if (!(extra_buf = psiconv_buffer_new())) {
543 psiconv_error(config,lev+1,0,"Out of memory error");
507 res = -PSICONV_E_NOMEM; 544 res = -PSICONV_E_NOMEM;
508 goto ERROR1; 545 goto ERROR1;
509 } 546 }
510 547
511 display_id = psiconv_buffer_unique_id(); 548 display_id = psiconv_buffer_unique_id();
513 table_id = psiconv_buffer_unique_id(); 550 table_id = psiconv_buffer_unique_id();
514 if ((res = psiconv_write_u8(config,buf,lev+1,0x06))) 551 if ((res = psiconv_write_u8(config,buf,lev+1,0x06)))
515 goto ERROR2; 552 goto ERROR2;
516 if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_OBJECT_DISPLAY_SECTION))) 553 if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_OBJECT_DISPLAY_SECTION)))
517 goto ERROR2; 554 goto ERROR2;
518 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");
519 goto ERROR2; 557 goto ERROR2;
558 }
520 if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_OBJECT_ICON_SECTION))) 559 if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_OBJECT_ICON_SECTION)))
521 goto ERROR2; 560 goto ERROR2;
522 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");
523 goto ERROR2; 563 goto ERROR2;
564 }
524 if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_OBJECT_SECTION_TABLE_SECTION))) 565 if ((res = psiconv_write_u32(config,buf,lev+1,PSICONV_ID_OBJECT_SECTION_TABLE_SECTION)))
525 goto ERROR2; 566 goto ERROR2;
526 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");
527 goto ERROR2; 569 goto ERROR2;
570 }
528 571
529 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");
530 goto ERROR2; 574 goto ERROR2;
575 }
531 if ((res = psiconv_write_object_display_section(config,buf,lev+1,value->display))) 576 if ((res = psiconv_write_object_display_section(config,buf,lev+1,value->display)))
532 goto ERROR2; 577 goto ERROR2;
533 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");
534 goto ERROR2; 580 goto ERROR2;
581 }
535 if ((res = psiconv_write_object_icon_section(config,buf,lev+1,value->icon))) 582 if ((res = psiconv_write_object_icon_section(config,buf,lev+1,value->icon)))
536 goto ERROR2; 583 goto ERROR2;
537 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");
538 goto ERROR2; 586 goto ERROR2;
587 }
539 switch(value->object->type) { 588 switch(value->object->type) {
540 case psiconv_word_file: 589 case psiconv_word_file:
541 if ((res = psiconv_write_word_file(config,extra_buf,lev+1, 590 if ((res = psiconv_write_word_file(config,extra_buf,lev+1,
542 (psiconv_word_f) value->object->file))) 591 (psiconv_word_f) value->object->file)))
543 goto ERROR2; 592 goto ERROR2;
558 psiconv_error(config,lev,0,"Unknown or unsupported object type"); 607 psiconv_error(config,lev,0,"Unknown or unsupported object type");
559 res = -PSICONV_E_GENERATE; 608 res = -PSICONV_E_GENERATE;
560 goto ERROR2; 609 goto ERROR2;
561 } 610 }
562 611
563 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");
564 goto ERROR2; 614 goto ERROR2;
615 }
565 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");
566 goto ERROR2; 618 goto ERROR2;
619 }
567 psiconv_buffer_free(extra_buf); 620 psiconv_buffer_free(extra_buf);
568 621
569 psiconv_progress(config,lev,0,"End of embedded object section"); 622 psiconv_progress(config,lev,0,"End of embedded object section");
570 return 0; 623 return 0;
571 624

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

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