/[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 232 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");
234 res = -PSICONV_E_NOMEM; 241 res = -PSICONV_E_NOMEM;
235 goto ERROR6; 242 goto ERROR6;
236 } 243 }
237 244
238 if ((psiconv_list_length(paragraph->in_lines) > 1) || 245 if ((psiconv_list_length(paragraph->in_lines) > 1) ||
261 /* Generate the inlines. NB: Against what are all settings relative?!? */ 268 /* Generate the inlines. NB: Against what are all settings relative?!? */
262 paralen = 0; 269 paralen = 0;
263 for (j = 0; j < psiconv_list_length(paragraph->in_lines); j++) { 270 for (j = 0; j < psiconv_list_length(paragraph->in_lines); j++) {
264 nr_of_inlines ++; 271 nr_of_inlines ++;
265 if (!(in_line = psiconv_list_get(paragraph->in_lines,j))) { 272 if (!(in_line = psiconv_list_get(paragraph->in_lines,j))) {
266 psiconv_error(config,lev,0,"Massive memory corruption"); 273 psiconv_error(config,lev,0,"Data structure corruption");
267 res = -PSICONV_E_NOMEM; 274 res = -PSICONV_E_NOMEM;
268 goto ERROR6; 275 goto ERROR6;
269 } 276 }
270 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)))
271 goto ERROR6; 278 goto ERROR6;
273 paralen += thislen; 280 paralen += thislen;
274 /* 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
275 complete length of all inlines equals the text length */ 282 complete length of all inlines equals the text length */
276 if (j == psiconv_list_length(paragraph->in_lines)-1) { 283 if (j == psiconv_list_length(paragraph->in_lines)-1) {
277 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");
278 res = -PSICONV_E_GENERATE; 286 res = -PSICONV_E_GENERATE;
279 goto ERROR6; 287 goto ERROR6;
280 } 288 }
281 thislen += psiconv_unicode_strlen(paragraph->text)+1-paralen; 289 thislen += psiconv_unicode_strlen(paragraph->text)+1-paralen;
282 } 290 }
288 goto ERROR6; 296 goto ERROR6;
289 if (in_line->object) { 297 if (in_line->object) {
290 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)))
291 goto ERROR6; 299 goto ERROR6;
292 obj_id = psiconv_buffer_unique_id(); 300 obj_id = psiconv_buffer_unique_id();
293 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");
294 goto ERROR6; 303 goto ERROR6;
304 }
295 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");
296 goto ERROR6; 307 goto ERROR6;
308 }
297 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,
298 in_line->object))) 310 in_line->object)))
299 goto ERROR6; 311 goto ERROR6;
300 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)))
301 goto ERROR6; 313 goto ERROR6;
309 /* Set para_charlayout to the correct character-level layout */ 321 /* Set para_charlayout to the correct character-level layout */
310 if (psiconv_list_length(paragraph->in_lines) == 0) 322 if (psiconv_list_length(paragraph->in_lines) == 0)
311 para_charlayout = paragraph->base_character; 323 para_charlayout = paragraph->base_character;
312 else { 324 else {
313 if (!(in_line = psiconv_list_get(paragraph->in_lines,0))) { 325 if (!(in_line = psiconv_list_get(paragraph->in_lines,0))) {
314 psiconv_error(config,lev,0,"Massive memory corruption"); 326 psiconv_error(config,lev,0,"Data structure corruption");
315 res = -PSICONV_E_NOMEM; 327 res = -PSICONV_E_NOMEM;
316 goto ERROR6; 328 goto ERROR6;
317 } 329 }
318 para_charlayout = in_line->layout; 330 para_charlayout = in_line->layout;
319 } 331 }
320 for (j = 0; j < psiconv_list_length(paragraph_type_list); j++) { 332 for (j = 0; j < psiconv_list_length(paragraph_type_list); j++) {
321 if (!(paragraph_type = psiconv_list_get(paragraph_type_list,j))) { 333 if (!(paragraph_type = psiconv_list_get(paragraph_type_list,j))) {
322 psiconv_error(config,lev,0,"Massive memory corruption"); 334 psiconv_error(config,lev,0,"Data structure corruption");
323 res = -PSICONV_E_NOMEM; 335 res = -PSICONV_E_NOMEM;
324 goto ERROR6; 336 goto ERROR6;
325 } 337 }
326 if ((paragraph->base_style == paragraph_type->style) && 338 if ((paragraph->base_style == paragraph_type->style) &&
327 !psiconv_compare_character_layout(para_charlayout, 339 !psiconv_compare_character_layout(para_charlayout,
338 /* No need to copy them, we won't change them anyway */ 350 /* No need to copy them, we won't change them anyway */
339 new_type.paragraph = paragraph->base_paragraph; 351 new_type.paragraph = paragraph->base_paragraph;
340 new_type.character = para_charlayout; 352 new_type.character = para_charlayout;
341 new_type.style = paragraph->base_style; 353 new_type.style = paragraph->base_style;
342 paragraph_type = &new_type; 354 paragraph_type = &new_type;
343 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");
344 goto ERROR6; 357 goto ERROR6;
358 }
345 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)))
346 goto ERROR6; 360 goto ERROR6;
347 if (!(style = psiconv_get_style(styles,paragraph_type->style))) { 361 if (!(style = psiconv_get_style(styles,paragraph_type->style))) {
348 psiconv_error(config,lev,0,"Unknown style"); 362 psiconv_error(config,lev,0,"Unknown style");
349 res = -PSICONV_E_GENERATE; 363 res = -PSICONV_E_GENERATE;
390 /* Now append everything */ 404 /* Now append everything */
391 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)))
392 goto ERROR6; 406 goto ERROR6;
393 if ((res = psiconv_write_u8(config,buf,lev+1, ptl_length))) 407 if ((res = psiconv_write_u8(config,buf,lev+1, ptl_length)))
394 goto ERROR6; 408 goto ERROR6;
395 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");
396 goto ERROR6; 411 goto ERROR6;
412 }
397 if ((res = psiconv_write_u32(config,buf,lev+1,pel_length))) 413 if ((res = psiconv_write_u32(config,buf,lev+1,pel_length)))
398 goto ERROR6; 414 goto ERROR6;
399 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");
400 goto ERROR6; 417 goto ERROR6;
418 }
401 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)))
402 goto ERROR6; 420 goto ERROR6;
403 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");
404 goto ERROR6; 423 goto ERROR6;
424 }
405 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");
406 goto ERROR6; 427 goto ERROR6;
428 }
407 429
408ERROR6: 430ERROR6:
409 psiconv_buffer_free(buf_objects); 431 psiconv_buffer_free(buf_objects);
410ERROR5: 432ERROR5:
411 psiconv_buffer_free(buf_inlines); 433 psiconv_buffer_free(buf_inlines);
447{ 469{
448 int res = 0; 470 int res = 0;
449 psiconv_word_styles_section styles_section; 471 psiconv_word_styles_section styles_section;
450 472
451 psiconv_progress(config,lev,0,"Writing styleless layout section"); 473 psiconv_progress(config,lev,0,"Writing styleless layout section");
452 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");
453 goto ERROR1; 476 goto ERROR1;
477 }
454 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");
455 goto ERROR2; 480 goto ERROR2;
481 }
456 if (!(styles_section->normal->character = 482 if (!(styles_section->normal->character =
457 psiconv_clone_character_layout(base_char))) 483 psiconv_clone_character_layout(base_char))) {
484 psiconv_error(config,lev+1,0,"Out of memory error");
458 goto ERROR3; 485 goto ERROR3;
486 }
459 if (!(styles_section->normal->paragraph = 487 if (!(styles_section->normal->paragraph =
460 psiconv_clone_paragraph_layout(base_para))) 488 psiconv_clone_paragraph_layout(base_para))) {
489 psiconv_error(config,lev+1,0,"Out of memory error");
461 goto ERROR4; 490 goto ERROR4;
491 }
462 styles_section->normal->hotkey = 0; 492 styles_section->normal->hotkey = 0;
463 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");
464 goto ERROR5; 495 goto ERROR5;
496 }
465 if (!(styles_section->styles = psiconv_list_new(sizeof( 497 if (!(styles_section->styles = psiconv_list_new(sizeof(
466 struct psiconv_word_style_s)))) 498 struct psiconv_word_style_s)))) {
499 psiconv_error(config,lev+1,0,"Out of memory error");
467 goto ERROR6; 500 goto ERROR6;
501 }
468 502
469 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);
470 psiconv_free_word_styles_section(styles_section); 504 psiconv_free_word_styles_section(styles_section);
471 psiconv_progress(config,lev,0,"End of styleless layout section"); 505 psiconv_progress(config,lev,0,"End of styleless layout section");
472 return res; 506 return res;
504 res = -PSICONV_E_GENERATE; 538 res = -PSICONV_E_GENERATE;
505 goto ERROR1; 539 goto ERROR1;
506 } 540 }
507 541
508 if (!(extra_buf = psiconv_buffer_new())) { 542 if (!(extra_buf = psiconv_buffer_new())) {
543 psiconv_error(config,lev+1,0,"Out of memory error");
509 res = -PSICONV_E_NOMEM; 544 res = -PSICONV_E_NOMEM;
510 goto ERROR1; 545 goto ERROR1;
511 } 546 }
512 547
513 display_id = psiconv_buffer_unique_id(); 548 display_id = psiconv_buffer_unique_id();
515 table_id = psiconv_buffer_unique_id(); 550 table_id = psiconv_buffer_unique_id();
516 if ((res = psiconv_write_u8(config,buf,lev+1,0x06))) 551 if ((res = psiconv_write_u8(config,buf,lev+1,0x06)))
517 goto ERROR2; 552 goto ERROR2;
518 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)))
519 goto ERROR2; 554 goto ERROR2;
520 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");
521 goto ERROR2; 557 goto ERROR2;
558 }
522 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)))
523 goto ERROR2; 560 goto ERROR2;
524 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");
525 goto ERROR2; 563 goto ERROR2;
564 }
526 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)))
527 goto ERROR2; 566 goto ERROR2;
528 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");
529 goto ERROR2; 569 goto ERROR2;
570 }
530 571
531 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");
532 goto ERROR2; 574 goto ERROR2;
575 }
533 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)))
534 goto ERROR2; 577 goto ERROR2;
535 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");
536 goto ERROR2; 580 goto ERROR2;
581 }
537 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)))
538 goto ERROR2; 583 goto ERROR2;
539 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");
540 goto ERROR2; 586 goto ERROR2;
587 }
541 switch(value->object->type) { 588 switch(value->object->type) {
542 case psiconv_word_file: 589 case psiconv_word_file:
543 if ((res = psiconv_write_word_file(config,extra_buf,lev+1, 590 if ((res = psiconv_write_word_file(config,extra_buf,lev+1,
544 (psiconv_word_f) value->object->file))) 591 (psiconv_word_f) value->object->file)))
545 goto ERROR2; 592 goto ERROR2;
560 psiconv_error(config,lev,0,"Unknown or unsupported object type"); 607 psiconv_error(config,lev,0,"Unknown or unsupported object type");
561 res = -PSICONV_E_GENERATE; 608 res = -PSICONV_E_GENERATE;
562 goto ERROR2; 609 goto ERROR2;
563 } 610 }
564 611
565 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");
566 goto ERROR2; 614 goto ERROR2;
615 }
567 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");
568 goto ERROR2; 618 goto ERROR2;
619 }
569 psiconv_buffer_free(extra_buf); 620 psiconv_buffer_free(extra_buf);
570 621
571 psiconv_progress(config,lev,0,"End of embedded object section"); 622 psiconv_progress(config,lev,0,"End of embedded object section");
572 return 0; 623 return 0;
573 624

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

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