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