1 | /* |
1 | /* |
2 | parse_common.c - Part of psiconv, a PSION 5 file formats converter |
2 | parse_common.c - Part of psiconv, a PSION 5 file formats converter |
3 | Copyright (c) 1999, 2000 Frodo Looijaard <frodol@dds.nl> |
3 | Copyright (c) 1999-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. |
… | |
… | |
69 | len += 4; |
69 | len += 4; |
70 | psiconv_debug(config,lev+2,off+len,"File is a Clipart file"); |
70 | psiconv_debug(config,lev+2,off+len,"File is a Clipart file"); |
71 | goto DONE; |
71 | goto DONE; |
72 | } |
72 | } |
73 | if ((*result)->uid1 != PSICONV_ID_PSION5) { |
73 | if ((*result)->uid1 != PSICONV_ID_PSION5) { |
74 | psiconv_warn(config,lev+2,off+len, |
74 | psiconv_error(config,lev+2,off+len, |
75 | "UID1 has unknown value. This is probably " |
75 | "UID1 has unknown value. This is probably " |
76 | "not a (parsable) Psion 5 file"); |
76 | "not a (parsable) Psion 5 file"); |
77 | res = -PSICONV_E_PARSE; |
77 | res = -PSICONV_E_PARSE; |
78 | goto ERROR2; |
78 | goto ERROR2; |
79 | } |
79 | } |
… | |
… | |
123 | goto ERROR2; |
123 | goto ERROR2; |
124 | if (temp == psiconv_checkuid((*result)->uid1,(*result)->uid2, |
124 | if (temp == psiconv_checkuid((*result)->uid1,(*result)->uid2, |
125 | (*result)->uid3)) |
125 | (*result)->uid3)) |
126 | psiconv_debug(config,lev+2,off+len,"Checksum %08x is correct",temp); |
126 | psiconv_debug(config,lev+2,off+len,"Checksum %08x is correct",temp); |
127 | else { |
127 | else { |
128 | psiconv_warn(config,lev+2,off+len,"Checksum failed, file corrupted!"); |
128 | psiconv_error(config,lev+2,off+len,"Checksum failed, file corrupted!"); |
129 | psiconv_debug(config,lev+2,off+len,"Expected checksum %08x, found %08x", |
129 | psiconv_debug(config,lev+2,off+len,"Expected checksum %08x, found %08x", |
130 | psiconv_checkuid((*result)->uid1,(*result)->uid2, |
130 | psiconv_checkuid((*result)->uid1,(*result)->uid2, |
131 | (*result)->uid3),temp); |
131 | (*result)->uid3),temp); |
132 | res = -PSICONV_E_PARSE; |
132 | res = -PSICONV_E_PARSE; |
133 | goto ERROR2; |
133 | goto ERROR2; |
… | |
… | |
144 | return res; |
144 | return res; |
145 | |
145 | |
146 | ERROR2: |
146 | ERROR2: |
147 | free(*result); |
147 | free(*result); |
148 | ERROR1: |
148 | ERROR1: |
149 | psiconv_warn(config,lev+1,off,"Reading of Header Section failed"); |
149 | psiconv_error(config,lev+1,off,"Reading of Header Section failed"); |
150 | if (length) |
150 | if (length) |
151 | *length = 0; |
151 | *length = 0; |
152 | if (res == 0) |
152 | if (res == 0) |
153 | return -PSICONV_E_NOMEM; |
153 | return -PSICONV_E_NOMEM; |
154 | else |
154 | else |
… | |
… | |
211 | ERROR3: |
211 | ERROR3: |
212 | free(entry); |
212 | free(entry); |
213 | ERROR2: |
213 | ERROR2: |
214 | psiconv_list_free(*result); |
214 | psiconv_list_free(*result); |
215 | ERROR1: |
215 | ERROR1: |
216 | psiconv_warn(config,lev+1,off,"Reading of Section Table Section failed"); |
216 | psiconv_error(config,lev+1,off,"Reading of Section Table Section failed"); |
217 | if (length) |
217 | if (length) |
218 | *length = 0; |
218 | *length = 0; |
219 | if (res == 0) |
219 | if (res == 0) |
220 | return -PSICONV_E_NOMEM; |
220 | return -PSICONV_E_NOMEM; |
221 | else |
221 | else |
… | |
… | |
256 | |
256 | |
257 | return res; |
257 | return res; |
258 | ERROR2: |
258 | ERROR2: |
259 | free(*result); |
259 | free(*result); |
260 | ERROR1: |
260 | ERROR1: |
261 | psiconv_warn(config,lev+1,off,"Reading of Application ID Section failed"); |
261 | psiconv_error(config,lev+1,off,"Reading of Application ID Section failed"); |
262 | if (length) |
262 | if (length) |
263 | *length = 0; |
263 | *length = 0; |
264 | if (res == 0) |
264 | if (res == 0) |
265 | return -PSICONV_E_NOMEM; |
265 | return -PSICONV_E_NOMEM; |
266 | else |
266 | else |
… | |
… | |
275 | int res = 0; |
275 | int res = 0; |
276 | int len=0; |
276 | int len=0; |
277 | |
277 | |
278 | psiconv_u32 text_len; |
278 | psiconv_u32 text_len; |
279 | psiconv_paragraph para; |
279 | psiconv_paragraph para; |
|
|
280 | psiconv_ucs2 temp; |
|
|
281 | psiconv_list line; |
280 | |
282 | |
281 | int nr; |
283 | int nr; |
282 | int i,j,start,leng,temp; |
284 | int i,leng; |
283 | char *str_copy; |
285 | char *str_copy; |
284 | |
286 | |
285 | psiconv_progress(config,lev+1,off,"Going to parse the text section"); |
287 | psiconv_progress(config,lev+1,off,"Going to parse the text section"); |
286 | psiconv_progress(config,lev+2,off,"Reading the text length"); |
|
|
287 | |
288 | |
288 | if(!(*result = psiconv_list_new(sizeof(*para)))) |
289 | if(!(*result = psiconv_list_new(sizeof(*para)))) |
289 | goto ERROR1; |
290 | goto ERROR1; |
290 | if (!(para = malloc(sizeof(*para)))) |
291 | if (!(para = malloc(sizeof(*para)))) |
291 | goto ERROR2; |
292 | goto ERROR2; |
292 | |
293 | |
|
|
294 | psiconv_progress(config,lev+2,off,"Reading the text length"); |
293 | text_len = psiconv_read_X(config,buf,lev+2,off,&leng,&res); |
295 | text_len = psiconv_read_X(config,buf,lev+2,off,&leng,&res); |
294 | if (res) |
296 | if (res) |
295 | goto ERROR3; |
297 | goto ERROR3; |
296 | psiconv_debug(config,lev+2,off,"Length: %08x",text_len); |
298 | psiconv_debug(config,lev+2,off,"Length: %08x",text_len); |
297 | len += leng; |
299 | len += leng; |
298 | |
300 | |
299 | psiconv_progress(config,lev+2,off+len,"Going to read all paragraph text"); |
301 | if (!(line = psiconv_list_new(sizeof(psiconv_ucs2)))) |
|
|
302 | goto ERROR3; |
|
|
303 | |
|
|
304 | i = 0; |
300 | nr = 0; |
305 | nr = 0; |
301 | start = 0; |
306 | while (i < text_len) { |
302 | for (i = 0; i < text_len; i++) { |
|
|
303 | temp = psiconv_read_u8(config,buf,lev+2,off+len+i,&res); |
307 | temp = psiconv_unicode_read_char(config,buf,lev+2,off+len+i,&leng,&res); |
304 | if (res) |
308 | if (res) |
305 | goto ERROR3; |
309 | goto ERROR4; |
306 | if (temp == 0x06) { |
310 | if (i + leng > text_len) { |
307 | if (!(para->text = malloc(i - start + 1))) |
311 | psiconv_error(config,lev+2,off+len+i,"Malformed text section"); |
|
|
312 | res = PSICONV_E_PARSE; |
|
|
313 | goto ERROR4; |
|
|
314 | } |
|
|
315 | if ((temp == 0x06) || (i + leng == text_len)) { |
|
|
316 | if (!(para->text = psiconv_unicode_from_list(line))) |
|
|
317 | goto ERROR4; |
|
|
318 | |
|
|
319 | if (!(str_copy = psiconv_make_printable(config,para->text))) |
308 | goto ERROR3; |
320 | goto ERROR5; |
309 | for (j = 0; j < i - start; j++) { |
|
|
310 | temp = psiconv_read_u8(config,buf,lev+1,off + len + start + j,&res); |
|
|
311 | if (res) |
|
|
312 | goto ERROR4; |
|
|
313 | para->text[j] = temp; |
|
|
314 | } |
|
|
315 | para->text[j] = 0; |
|
|
316 | |
|
|
317 | if ((res = psiconv_list_add(*result,para))) |
|
|
318 | goto ERROR4; |
|
|
319 | |
|
|
320 | if (!(str_copy = psiconv_make_printable(para->text))) |
|
|
321 | goto ERROR3; |
|
|
322 | psiconv_debug(config,lev+2,off+i+len,"Line %d: %d characters",nr, |
321 | psiconv_debug(config,lev+2,off+i+len,"Line %d: %d characters",nr, |
323 | strlen(str_copy) +1); |
322 | strlen(str_copy) +1); |
324 | psiconv_debug(config,lev+2,off+i+len,"Line %d: `%s'",nr,str_copy); |
323 | psiconv_debug(config,lev+2,off+i+len,"Line %d: `%s'",nr,str_copy); |
325 | free(str_copy); |
324 | free(str_copy); |
|
|
325 | i += leng; |
326 | |
326 | |
327 | start = i + 1; |
327 | if (!(para->in_lines = psiconv_list_new(sizeof( |
|
|
328 | struct psiconv_in_line_layout_s)))) |
|
|
329 | goto ERROR5; |
|
|
330 | if (!(para->replacements = psiconv_list_new(sizeof( |
|
|
331 | struct psiconv_replacement_s)))) |
|
|
332 | goto ERROR6; |
|
|
333 | if (!(para->base_character = psiconv_basic_character_layout())) |
|
|
334 | goto ERROR7; |
|
|
335 | if (!(para->base_paragraph = psiconv_basic_paragraph_layout())) |
|
|
336 | goto ERROR8; |
|
|
337 | para->base_style = 0; |
|
|
338 | |
|
|
339 | if ((res = psiconv_list_add(*result,para))) |
|
|
340 | goto ERROR9; |
|
|
341 | psiconv_progress(config,lev+2,off+len+i,"Starting a new line"); |
|
|
342 | psiconv_list_empty(line); |
328 | nr ++; |
343 | nr ++; |
|
|
344 | } else { |
|
|
345 | if ((res = psiconv_list_add(line,&temp))) |
|
|
346 | goto ERROR4; |
|
|
347 | i += leng; |
329 | } |
348 | } |
330 | } |
349 | } |
331 | |
350 | |
332 | if (start != text_len) { |
351 | psiconv_list_free(line); |
333 | psiconv_warn(config,lev+2,off+start+len, |
|
|
334 | "Last line does not end on EOL (%d characters left)", len - start); |
|
|
335 | if (!(para->text = malloc(text_len - start + 1))) |
|
|
336 | goto ERROR3; |
|
|
337 | for (j = 0; j < text_len - start; j++) { |
|
|
338 | temp = psiconv_read_u8(config,buf,lev+2,off + start + j + len, &res); |
|
|
339 | if (res) |
|
|
340 | goto ERROR4; |
|
|
341 | para->text[j] = temp; |
|
|
342 | } |
|
|
343 | para->text[text_len - start] = 0; |
|
|
344 | if ((res = psiconv_list_add(*result,para))) |
|
|
345 | goto ERROR4; |
|
|
346 | if (!(str_copy = psiconv_make_printable(para->text))) |
|
|
347 | goto ERROR3; |
|
|
348 | psiconv_debug(config,lev+2,off+start+len,"Last line: %d characters",nr, |
|
|
349 | strlen(str_copy)+1); |
|
|
350 | psiconv_debug(config,lev+2,off+start+len,"Last line: `%s'",str_copy); |
|
|
351 | free(str_copy); |
|
|
352 | } |
|
|
353 | |
|
|
354 | free(para); |
352 | free(para); |
355 | |
353 | |
356 | /* Initialize the remaining parts of each paragraph */ |
|
|
357 | for (i = 0; i < psiconv_list_length(*result); i ++) { |
|
|
358 | if (!(para = psiconv_list_get(*result,i))) { |
|
|
359 | psiconv_warn(config,lev+2,off+len,"Massive memory corruption"); |
|
|
360 | goto ERROR2_0; |
|
|
361 | } |
|
|
362 | if (!(para->in_lines = psiconv_list_new(sizeof( |
|
|
363 | struct psiconv_in_line_layout_s)))) |
|
|
364 | goto ERROR2_0; |
|
|
365 | if (!(para->replacements = psiconv_list_new(sizeof( |
|
|
366 | struct psiconv_replacement_s)))) |
|
|
367 | goto ERROR2_1; |
|
|
368 | if (!(para->base_character = psiconv_basic_character_layout())) |
|
|
369 | goto ERROR2_2; |
|
|
370 | if (!(para->base_paragraph = psiconv_basic_paragraph_layout())) |
|
|
371 | goto ERROR2_3; |
|
|
372 | para->base_style = 0; |
|
|
373 | } |
|
|
374 | |
|
|
375 | |
|
|
376 | len += text_len; |
354 | len += text_len; |
377 | |
355 | |
378 | if (length) |
356 | if (length) |
379 | *length = len; |
357 | *length = len; |
380 | |
358 | |
381 | psiconv_progress(config,lev+1,off+len-1,"End of text section (total length: %08x", |
359 | psiconv_progress(config,lev+1,off+len-1, |
382 | len); |
360 | "End of text section (total length: %08x", len); |
383 | |
361 | |
384 | return res; |
362 | return res; |
385 | |
363 | |
386 | ERROR2_3: |
364 | ERROR9: |
|
|
365 | psiconv_free_paragraph_layout(para->base_paragraph); |
|
|
366 | ERROR8: |
387 | psiconv_free_character_layout(para->base_character); |
367 | psiconv_free_character_layout(para->base_character); |
388 | ERROR2_2: |
368 | ERROR7: |
389 | psiconv_list_free(para->replacements); |
369 | psiconv_list_free(para->replacements); |
390 | ERROR2_1: |
370 | ERROR6: |
391 | psiconv_list_free(para->in_lines); |
371 | psiconv_list_free(para->in_lines); |
392 | ERROR2_0: |
372 | ERROR5: |
393 | for (j = 0; j < i; j++) { |
373 | free(para->text); |
394 | if (!(para = psiconv_list_get(*result,j))) { |
|
|
395 | psiconv_warn(config,lev+1,off,"Massive memory corruption..."); |
|
|
396 | break; |
|
|
397 | } |
|
|
398 | psiconv_list_free(para->in_lines); |
|
|
399 | psiconv_list_free(para->replacements); |
|
|
400 | psiconv_free_character_layout(para->base_character); |
|
|
401 | psiconv_free_paragraph_layout(para->base_paragraph); |
|
|
402 | } |
|
|
403 | goto ERROR2; |
|
|
404 | |
|
|
405 | ERROR4: |
374 | ERROR4: |
406 | free(para->text); |
375 | psiconv_list_free(line); |
407 | ERROR3: |
376 | ERROR3: |
408 | free(para); |
377 | free(para); |
409 | ERROR2: |
378 | ERROR2: |
410 | for (i = 0; i < psiconv_list_length(*result);i++) { |
379 | psiconv_free_text_and_layout(*result); |
411 | if (!(para = psiconv_list_get(*result,i))) { |
|
|
412 | psiconv_warn(config,lev+1,off,"Massive memory corruption..."); |
|
|
413 | break; |
|
|
414 | } |
|
|
415 | free(para->text); |
|
|
416 | } |
|
|
417 | psiconv_list_free(*result); |
|
|
418 | ERROR1: |
380 | ERROR1: |
419 | psiconv_warn(config,lev+1,off,"Reading of Text Section failed"); |
381 | psiconv_error(config,lev+1,off,"Reading of Text Section failed"); |
420 | if (length) |
382 | if (length) |
421 | *length = 0; |
383 | *length = 0; |
422 | if (!res) |
384 | if (!res) |
423 | return -PSICONV_E_NOMEM; |
385 | return -PSICONV_E_NOMEM; |
424 | else |
386 | else |
… | |
… | |
588 | |
550 | |
589 | psiconv_progress(config,lev+4,off+len,"Going to read the paragraph length"); |
551 | psiconv_progress(config,lev+4,off+len,"Going to read the paragraph length"); |
590 | temp = psiconv_read_u32(config,buf,lev+4,off+len,&res); |
552 | temp = psiconv_read_u32(config,buf,lev+4,off+len,&res); |
591 | if (res) |
553 | if (res) |
592 | goto ERROR4; |
554 | goto ERROR4; |
593 | if (temp != strlen(para->text)+1) { |
555 | if (temp != psiconv_unicode_strlen(para->text)+1) { |
594 | psiconv_warn(config,lev+4,off+len, |
556 | psiconv_warn(config,lev+4,off+len, |
595 | "Disagreement of the length of paragraph in layout section"); |
557 | "Disagreement of the length of paragraph in layout section"); |
596 | psiconv_debug(config,lev+4,off+len, |
558 | psiconv_debug(config,lev+4,off+len, |
597 | "Paragraph length: layout section says %d, counted %d", |
559 | "Paragraph length: layout section says %d, counted %d", |
598 | temp,strlen(para->text)+1); |
560 | temp,psiconv_unicode_strlen(para->text)+1); |
599 | } else |
561 | } else |
600 | psiconv_debug(config,lev+4,off+len,"Paragraph length: %d",temp); |
562 | psiconv_debug(config,lev+4,off+len,"Paragraph length: %d",temp); |
601 | len += 4; |
563 | len += 4; |
602 | |
564 | |
603 | psiconv_progress(config,lev+4,off+len,"Going to read the paragraph type"); |
565 | psiconv_progress(config,lev+4,off+len,"Going to read the paragraph type"); |
… | |
… | |
606 | goto ERROR4; |
568 | goto ERROR4; |
607 | if (temp != 0x00) { |
569 | if (temp != 0x00) { |
608 | psiconv_debug(config,lev+4,off+len,"Type: %02x",temp); |
570 | psiconv_debug(config,lev+4,off+len,"Type: %02x",temp); |
609 | for (j = 0; j < psiconv_list_length(anon_styles); j++) { |
571 | for (j = 0; j < psiconv_list_length(anon_styles); j++) { |
610 | if (!(anon_ptr = psiconv_list_get(anon_styles,j))) { |
572 | if (!(anon_ptr = psiconv_list_get(anon_styles,j))) { |
611 | psiconv_warn(config,lev+4,off+len,"Massive memory curruption"); |
573 | psiconv_error(config,lev+4,off+len,"Data structure corruption"); |
612 | goto ERROR4; |
574 | goto ERROR4; |
613 | } |
575 | } |
614 | if (temp == anon_ptr->nr) |
576 | if (temp == anon_ptr->nr) |
615 | break; |
577 | break; |
616 | } |
578 | } |
617 | if (j == psiconv_list_length(anon_styles)) { |
579 | if (j == psiconv_list_length(anon_styles)) { |
618 | psiconv_warn(config,lev+4,off+len,"Layout section paragraph type unknown"); |
580 | psiconv_warn(config,lev+4,off+len,"Layout section paragraph type unknown"); |
619 | psiconv_debug(config,lev+4,off+len,"Unknown type - using base styles instead"); |
581 | psiconv_debug(config,lev+4,off+len,"Unknown type - using base styles instead"); |
620 | para->base_style = 0; |
582 | para->base_style = 0; |
621 | if (!(temp_style = psiconv_get_style(styles,0))) { |
583 | if (!(temp_style = psiconv_get_style(styles,0))) { |
622 | psiconv_warn(config,lev+4,off,"Base style unknown"); |
584 | psiconv_error(config,lev+4,off,"Base style unknown"); |
623 | goto ERROR4; |
585 | goto ERROR4; |
624 | } |
586 | } |
625 | if (!(temp_para = psiconv_clone_paragraph_layout |
587 | if (!(temp_para = psiconv_clone_paragraph_layout |
626 | (temp_style->paragraph))) |
588 | (temp_style->paragraph))) |
627 | goto ERROR4; |
589 | goto ERROR4; |
… | |
… | |
665 | temp = 0x00; |
627 | temp = 0x00; |
666 | |
628 | |
667 | if (!(temp_style = psiconv_get_style (styles,temp))) { |
629 | if (!(temp_style = psiconv_get_style (styles,temp))) { |
668 | psiconv_warn(config,lev+4,off,"Unknown Style referenced"); |
630 | psiconv_warn(config,lev+4,off,"Unknown Style referenced"); |
669 | if (!(temp_style = psiconv_get_style(styles,0))) { |
631 | if (!(temp_style = psiconv_get_style(styles,0))) { |
670 | psiconv_warn(config,lev+4,off,"Base style unknown"); |
632 | psiconv_error(config,lev+4,off,"Base style unknown"); |
671 | goto ERROR4; |
633 | goto ERROR4; |
672 | } |
634 | } |
673 | } |
635 | } |
674 | |
636 | |
675 | if (!(temp_para = psiconv_clone_paragraph_layout(temp_style->paragraph))) |
637 | if (!(temp_para = psiconv_clone_paragraph_layout(temp_style->paragraph))) |
… | |
… | |
712 | psiconv_progress(config,lev+3,off+len, |
674 | psiconv_progress(config,lev+3,off+len, |
713 | "Going to read the text layout inline elements"); |
675 | "Going to read the text layout inline elements"); |
714 | total = 0; |
676 | total = 0; |
715 | for (i = 0; i < psiconv_list_length(result); i++) { |
677 | for (i = 0; i < psiconv_list_length(result); i++) { |
716 | if (!(para = psiconv_list_get(result,i))) { |
678 | if (!(para = psiconv_list_get(result,i))) { |
717 | psiconv_warn(config,lev+3,off+len,"Massive memory corruption"); |
679 | psiconv_error(config,lev+3,off+len,"Data structure corruption"); |
718 | goto ERROR4; |
680 | goto ERROR4; |
719 | } |
681 | } |
720 | line_length = -1; |
682 | line_length = -1; |
721 | for (j = 0; j < inline_count[i]; j++) { |
683 | for (j = 0; j < inline_count[i]; j++) { |
722 | psiconv_progress(config,lev+3,off+len,"Element %d: Paragraph %d, element %d", |
684 | psiconv_progress(config,lev+3,off+len,"Element %d: Paragraph %d, element %d", |
… | |
… | |
795 | in_line.object_height); |
757 | in_line.object_height); |
796 | len += leng; |
758 | len += leng; |
797 | } else if (temp != 0x00) { |
759 | } else if (temp != 0x00) { |
798 | psiconv_warn(config,lev+4,off+len,"Layout section unknown inline type"); |
760 | psiconv_warn(config,lev+4,off+len,"Layout section unknown inline type"); |
799 | } |
761 | } |
800 | if (line_length + in_line.length > strlen(para->text)) { |
762 | if (line_length + in_line.length > psiconv_unicode_strlen(para->text)) { |
801 | psiconv_warn(config,lev+4,off+len, |
763 | psiconv_warn(config,lev+4,off+len, |
802 | "Layout section inlines: line length mismatch"); |
764 | "Layout section inlines: line length mismatch"); |
803 | res = -1; |
765 | res = -1; |
804 | in_line.length = strlen(para->text) - line_length; |
766 | in_line.length = psiconv_unicode_strlen(para->text) - line_length; |
805 | } |
767 | } |
806 | line_length += in_line.length; |
768 | line_length += in_line.length; |
807 | if ((res = psiconv_list_add(para->in_lines,&in_line))) |
769 | if ((res = psiconv_list_add(para->in_lines,&in_line))) |
808 | goto ERROR5; |
770 | goto ERROR5; |
809 | } |
771 | } |
… | |
… | |
817 | |
779 | |
818 | free(inline_count); |
780 | free(inline_count); |
819 | |
781 | |
820 | for (i = 0 ; i < psiconv_list_length(anon_styles); i ++) { |
782 | for (i = 0 ; i < psiconv_list_length(anon_styles); i ++) { |
821 | if (!(anon_ptr = psiconv_list_get(anon_styles,i))) { |
783 | if (!(anon_ptr = psiconv_list_get(anon_styles,i))) { |
822 | psiconv_warn(config,lev+4,off+len,"Massive memory corruption"); |
784 | psiconv_error(config,lev+4,off+len,"Data structure corruption"); |
823 | goto ERROR2; |
785 | goto ERROR2; |
824 | } |
786 | } |
825 | psiconv_free_character_layout(anon_ptr->character); |
787 | psiconv_free_character_layout(anon_ptr->character); |
826 | psiconv_free_paragraph_layout(anon_ptr->paragraph); |
788 | psiconv_free_paragraph_layout(anon_ptr->paragraph); |
827 | } |
789 | } |
… | |
… | |
859 | ERROR4: |
821 | ERROR4: |
860 | free(inline_count); |
822 | free(inline_count); |
861 | ERROR3: |
823 | ERROR3: |
862 | for (i = 0; i < psiconv_list_length(anon_styles); i++) { |
824 | for (i = 0; i < psiconv_list_length(anon_styles); i++) { |
863 | if (!(anon_ptr = psiconv_list_get(anon_styles,i))) { |
825 | if (!(anon_ptr = psiconv_list_get(anon_styles,i))) { |
864 | psiconv_warn(config,lev+1,off,"Massive memory corruption"); |
826 | psiconv_error(config,lev+1,off,"Data structure corruption"); |
865 | break; |
827 | break; |
866 | } |
828 | } |
867 | psiconv_free_paragraph_layout(anon_ptr->paragraph); |
829 | psiconv_free_paragraph_layout(anon_ptr->paragraph); |
868 | psiconv_free_character_layout(anon_ptr->character); |
830 | psiconv_free_character_layout(anon_ptr->character); |
869 | } |
831 | } |
870 | |
832 | |
871 | ERROR2: |
833 | ERROR2: |
872 | psiconv_list_free(anon_styles); |
834 | psiconv_list_free(anon_styles); |
873 | ERROR1: |
835 | ERROR1: |
874 | psiconv_warn(config,lev+1,off,"Reading of Layout Section failed"); |
836 | psiconv_error(config,lev+1,off,"Reading of Layout Section failed"); |
875 | if (length) |
837 | if (length) |
876 | *length = 0; |
838 | *length = 0; |
877 | if (!res) |
839 | if (!res) |
878 | return -PSICONV_E_NOMEM; |
840 | return -PSICONV_E_NOMEM; |
879 | else |
841 | else |
… | |
… | |
910 | goto ERROR3; |
872 | goto ERROR3; |
911 | if (!(styles_section->normal->paragraph = |
873 | if (!(styles_section->normal->paragraph = |
912 | psiconv_clone_paragraph_layout(base_para))) |
874 | psiconv_clone_paragraph_layout(base_para))) |
913 | goto ERROR4; |
875 | goto ERROR4; |
914 | styles_section->normal->hotkey = 0; |
876 | styles_section->normal->hotkey = 0; |
|
|
877 | |
915 | if (!(styles_section->normal->name = strdup(""))) |
878 | if (!(styles_section->normal->name = psiconv_unicode_empty_string())) |
916 | goto ERROR5; |
879 | goto ERROR5; |
917 | if (!(styles_section->styles = psiconv_list_new(sizeof( |
880 | if (!(styles_section->styles = psiconv_list_new(sizeof( |
918 | struct psiconv_word_style_s)))) |
881 | struct psiconv_word_style_s)))) |
919 | goto ERROR6; |
882 | goto ERROR6; |
920 | |
883 | |
… | |
… | |
933 | ERROR3: |
896 | ERROR3: |
934 | free(styles_section->normal); |
897 | free(styles_section->normal); |
935 | ERROR2: |
898 | ERROR2: |
936 | free(styles_section); |
899 | free(styles_section); |
937 | ERROR1: |
900 | ERROR1: |
938 | psiconv_warn(config,lev+1,off,"Reading of Styleless Layout Section failed"); |
901 | psiconv_error(config,lev+1,off,"Reading of Styleless Layout Section failed"); |
939 | if (length) |
902 | if (length) |
940 | *length = 0; |
903 | *length = 0; |
941 | if (!res) |
904 | if (!res) |
942 | return -PSICONV_E_NOMEM; |
905 | return -PSICONV_E_NOMEM; |
943 | else |
906 | else |
… | |
… | |
1061 | psiconv_warn(config,lev+3,0,"Can't parse embedded object (still continuing)"); |
1024 | psiconv_warn(config,lev+3,0,"Can't parse embedded object (still continuing)"); |
1062 | (*result)->object->file = NULL; |
1025 | (*result)->object->file = NULL; |
1063 | } |
1026 | } |
1064 | } |
1027 | } |
1065 | |
1028 | |
|
|
1029 | psiconv_buffer_free(subbuf); |
|
|
1030 | psiconv_free_section_table_section(table); |
|
|
1031 | |
1066 | if (length) |
1032 | if (length) |
1067 | *length = len; |
1033 | *length = len; |
1068 | |
1034 | |
1069 | psiconv_progress(config,lev+1,off+len-1,"End of Embedded Object Section " |
1035 | psiconv_progress(config,lev+1,off+len-1,"End of Embedded Object Section " |
1070 | "(total length: %08x)",len); |
1036 | "(total length: %08x)",len); |
… | |
… | |
1081 | ERROR3: |
1047 | ERROR3: |
1082 | psiconv_free_object_display_section((*result)->display); |
1048 | psiconv_free_object_display_section((*result)->display); |
1083 | ERROR2: |
1049 | ERROR2: |
1084 | psiconv_free_section_table_section(table); |
1050 | psiconv_free_section_table_section(table); |
1085 | ERROR1: |
1051 | ERROR1: |
1086 | psiconv_warn(config,lev+1,off,"Reading Embedded Object failed"); |
1052 | psiconv_error(config,lev+1,off,"Reading Embedded Object failed"); |
1087 | |
1053 | |
1088 | if (length) |
1054 | if (length) |
1089 | *length = 0; |
1055 | *length = 0; |
1090 | |
1056 | |
1091 | if (res == 0) |
1057 | if (res == 0) |
… | |
… | |
1130 | off = entry->offset; |
1096 | off = entry->offset; |
1131 | break; |
1097 | break; |
1132 | } |
1098 | } |
1133 | } |
1099 | } |
1134 | if (i == psiconv_list_length(table)) { |
1100 | if (i == psiconv_list_length(table)) { |
1135 | psiconv_warn(config,lev+2,off,"No Application ID Section found"); |
1101 | psiconv_error(config,lev+2,off,"No Application ID Section found"); |
1136 | res = PSICONV_E_PARSE; |
1102 | res = PSICONV_E_PARSE; |
1137 | goto ERROR2; |
1103 | goto ERROR2; |
1138 | } |
1104 | } |
1139 | |
1105 | |
1140 | psiconv_progress(config,lev+2,off,"Going to read the Application ID Section"); |
1106 | psiconv_progress(config,lev+2,off,"Going to read the Application ID Section"); |
… | |
… | |
1232 | return res; |
1198 | return res; |
1233 | |
1199 | |
1234 | ERROR2: |
1200 | ERROR2: |
1235 | free(*result); |
1201 | free(*result); |
1236 | ERROR1: |
1202 | ERROR1: |
1237 | psiconv_warn(config,lev+1,off+len,"Reading of Object Display Section failed"); |
1203 | psiconv_error(config,lev+1,off+len,"Reading of Object Display Section failed"); |
1238 | if (length) |
1204 | if (length) |
1239 | *length=0; |
1205 | *length=0; |
1240 | if (!res) |
1206 | if (!res) |
1241 | return -PSICONV_E_NOMEM; |
1207 | return -PSICONV_E_NOMEM; |
1242 | else |
1208 | else |
… | |
… | |
1258 | |
1224 | |
1259 | psiconv_progress(config,lev+2,off+len,"Going to read the icon name"); |
1225 | psiconv_progress(config,lev+2,off+len,"Going to read the icon name"); |
1260 | (*result)->icon_name = psiconv_read_string(config,buf,lev+2,off+len,&leng,&res); |
1226 | (*result)->icon_name = psiconv_read_string(config,buf,lev+2,off+len,&leng,&res); |
1261 | if (res) |
1227 | if (res) |
1262 | goto ERROR2; |
1228 | goto ERROR2; |
1263 | psiconv_debug(config,lev+2,off+len,"Icon name: %s",(*result)->icon_name); |
|
|
1264 | len += leng; |
1229 | len += leng; |
1265 | |
1230 | |
1266 | psiconv_progress(config,lev+2,off+len,"Going to read the icon width"); |
1231 | psiconv_progress(config,lev+2,off+len,"Going to read the icon width"); |
1267 | (*result)->icon_width = psiconv_read_length(config,buf,lev+2,off+len,&leng,&res); |
1232 | (*result)->icon_width = psiconv_read_length(config,buf,lev+2,off+len,&leng,&res); |
1268 | if (res) |
1233 | if (res) |
… | |
… | |
1287 | ERROR3: |
1252 | ERROR3: |
1288 | free((*result)->icon_name); |
1253 | free((*result)->icon_name); |
1289 | ERROR2: |
1254 | ERROR2: |
1290 | free(*result); |
1255 | free(*result); |
1291 | ERROR1: |
1256 | ERROR1: |
1292 | psiconv_warn(config,lev+1,off+len,"Reading of Object Icon Section failed"); |
1257 | psiconv_error(config,lev+1,off+len,"Reading of Object Icon Section failed"); |
1293 | if (length) |
1258 | if (length) |
1294 | *length=0; |
1259 | *length=0; |
1295 | if (!res) |
1260 | if (!res) |
1296 | return -PSICONV_E_NOMEM; |
1261 | return -PSICONV_E_NOMEM; |
1297 | else |
1262 | else |