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"); |
308 | goto ERROR3; |
313 | res = PSICONV_E_PARSE; |
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; |
314 | goto ERROR4; |
313 | para->text[j] = temp; |
315 | } |
|
|
316 | if ((temp == 0x06) || (i + leng == text_len)) { |
|
|
317 | if (!(para->text = malloc(sizeof(*(para->text)) * |
|
|
318 | (psiconv_list_length(line) + 1)))) |
|
|
319 | goto ERROR4; |
|
|
320 | for (j = 0; j < psiconv_list_length(line); j++) { |
|
|
321 | if (!(nextcharptr = psiconv_list_get(line,j))) { |
|
|
322 | psiconv_error(config,lev+2,off+i+len,"Internal data corruption"); |
|
|
323 | goto ERROR5; |
|
|
324 | } |
|
|
325 | para->text[j] = *nextcharptr; |
314 | } |
326 | } |
315 | para->text[j] = 0; |
327 | para->text[j] = 0; |
316 | |
328 | |
317 | if ((res = psiconv_list_add(*result,para))) |
329 | if (!(str_copy = psiconv_make_printable(config,para->text))) |
318 | goto ERROR4; |
330 | goto ERROR5; |
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, |
331 | psiconv_debug(config,lev+2,off+i+len,"Line %d: %d characters",nr, |
323 | strlen(str_copy) +1); |
332 | strlen(str_copy) +1); |
324 | psiconv_debug(config,lev+2,off+i+len,"Line %d: `%s'",nr,str_copy); |
333 | psiconv_debug(config,lev+2,off+i+len,"Line %d: `%s'",nr,str_copy); |
325 | free(str_copy); |
334 | free(str_copy); |
|
|
335 | i += leng; |
326 | |
336 | |
327 | start = i + 1; |
337 | if (!(para->in_lines = psiconv_list_new(sizeof( |
|
|
338 | struct psiconv_in_line_layout_s)))) |
|
|
339 | goto ERROR5; |
|
|
340 | if (!(para->replacements = psiconv_list_new(sizeof( |
|
|
341 | struct psiconv_replacement_s)))) |
|
|
342 | goto ERROR6; |
|
|
343 | if (!(para->base_character = psiconv_basic_character_layout())) |
|
|
344 | goto ERROR7; |
|
|
345 | if (!(para->base_paragraph = psiconv_basic_paragraph_layout())) |
|
|
346 | goto ERROR8; |
|
|
347 | para->base_style = 0; |
|
|
348 | |
|
|
349 | if ((res = psiconv_list_add(*result,para))) |
|
|
350 | goto ERROR9; |
|
|
351 | psiconv_progress(config,lev+2,off+len+i,"Starting a new line"); |
|
|
352 | psiconv_list_empty(line); |
328 | nr ++; |
353 | nr ++; |
|
|
354 | } else { |
|
|
355 | if ((res = psiconv_list_add(line,&temp))) |
|
|
356 | goto ERROR4; |
|
|
357 | i += leng; |
329 | } |
358 | } |
330 | } |
359 | } |
331 | |
360 | |
332 | if (start != text_len) { |
361 | 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); |
362 | free(para); |
355 | |
363 | |
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; |
364 | len += text_len; |
377 | |
365 | |
378 | if (length) |
366 | if (length) |
379 | *length = len; |
367 | *length = len; |
380 | |
368 | |
381 | psiconv_progress(config,lev+1,off+len-1,"End of text section (total length: %08x", |
369 | psiconv_progress(config,lev+1,off+len-1, |
382 | len); |
370 | "End of text section (total length: %08x", len); |
383 | |
371 | |
384 | return res; |
372 | return res; |
385 | |
373 | |
386 | ERROR2_3: |
374 | ERROR9: |
|
|
375 | psiconv_free_paragraph_layout(para->base_paragraph); |
|
|
376 | ERROR8: |
387 | psiconv_free_character_layout(para->base_character); |
377 | psiconv_free_character_layout(para->base_character); |
388 | ERROR2_2: |
378 | ERROR7: |
389 | psiconv_list_free(para->replacements); |
379 | psiconv_list_free(para->replacements); |
390 | ERROR2_1: |
380 | ERROR6: |
391 | psiconv_list_free(para->in_lines); |
381 | psiconv_list_free(para->in_lines); |
392 | ERROR2_0: |
382 | ERROR5: |
393 | for (j = 0; j < i; j++) { |
383 | 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: |
384 | ERROR4: |
406 | free(para->text); |
385 | psiconv_list_free(line); |
407 | ERROR3: |
386 | ERROR3: |
408 | free(para); |
387 | free(para); |
409 | ERROR2: |
388 | ERROR2: |
410 | for (i = 0; i < psiconv_list_length(*result);i++) { |
389 | 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: |
390 | ERROR1: |
419 | psiconv_warn(config,lev+1,off,"Reading of Text Section failed"); |
391 | psiconv_error(config,lev+1,off,"Reading of Text Section failed"); |
420 | if (length) |
392 | if (length) |
421 | *length = 0; |
393 | *length = 0; |
422 | if (!res) |
394 | if (!res) |
423 | return -PSICONV_E_NOMEM; |
395 | return -PSICONV_E_NOMEM; |
424 | else |
396 | else |
… | |
… | |
588 | |
560 | |
589 | psiconv_progress(config,lev+4,off+len,"Going to read the paragraph length"); |
561 | 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); |
562 | temp = psiconv_read_u32(config,buf,lev+4,off+len,&res); |
591 | if (res) |
563 | if (res) |
592 | goto ERROR4; |
564 | goto ERROR4; |
593 | if (temp != strlen(para->text)+1) { |
565 | if (temp != psiconv_unicode_strlen(para->text)+1) { |
594 | psiconv_warn(config,lev+4,off+len, |
566 | psiconv_warn(config,lev+4,off+len, |
595 | "Disagreement of the length of paragraph in layout section"); |
567 | "Disagreement of the length of paragraph in layout section"); |
596 | psiconv_debug(config,lev+4,off+len, |
568 | psiconv_debug(config,lev+4,off+len, |
597 | "Paragraph length: layout section says %d, counted %d", |
569 | "Paragraph length: layout section says %d, counted %d", |
598 | temp,strlen(para->text)+1); |
570 | temp,psiconv_unicode_strlen(para->text)+1); |
599 | } else |
571 | } else |
600 | psiconv_debug(config,lev+4,off+len,"Paragraph length: %d",temp); |
572 | psiconv_debug(config,lev+4,off+len,"Paragraph length: %d",temp); |
601 | len += 4; |
573 | len += 4; |
602 | |
574 | |
603 | psiconv_progress(config,lev+4,off+len,"Going to read the paragraph type"); |
575 | psiconv_progress(config,lev+4,off+len,"Going to read the paragraph type"); |
… | |
… | |
606 | goto ERROR4; |
578 | goto ERROR4; |
607 | if (temp != 0x00) { |
579 | if (temp != 0x00) { |
608 | psiconv_debug(config,lev+4,off+len,"Type: %02x",temp); |
580 | psiconv_debug(config,lev+4,off+len,"Type: %02x",temp); |
609 | for (j = 0; j < psiconv_list_length(anon_styles); j++) { |
581 | for (j = 0; j < psiconv_list_length(anon_styles); j++) { |
610 | if (!(anon_ptr = psiconv_list_get(anon_styles,j))) { |
582 | if (!(anon_ptr = psiconv_list_get(anon_styles,j))) { |
611 | psiconv_warn(config,lev+4,off+len,"Massive memory curruption"); |
583 | psiconv_error(config,lev+4,off+len,"Massive memory curruption"); |
612 | goto ERROR4; |
584 | goto ERROR4; |
613 | } |
585 | } |
614 | if (temp == anon_ptr->nr) |
586 | if (temp == anon_ptr->nr) |
615 | break; |
587 | break; |
616 | } |
588 | } |
617 | if (j == psiconv_list_length(anon_styles)) { |
589 | if (j == psiconv_list_length(anon_styles)) { |
618 | psiconv_warn(config,lev+4,off+len,"Layout section paragraph type unknown"); |
590 | 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"); |
591 | psiconv_debug(config,lev+4,off+len,"Unknown type - using base styles instead"); |
620 | para->base_style = 0; |
592 | para->base_style = 0; |
621 | if (!(temp_style = psiconv_get_style(styles,0))) { |
593 | if (!(temp_style = psiconv_get_style(styles,0))) { |
622 | psiconv_warn(config,lev+4,off,"Base style unknown"); |
594 | psiconv_error(config,lev+4,off,"Base style unknown"); |
623 | goto ERROR4; |
595 | goto ERROR4; |
624 | } |
596 | } |
625 | if (!(temp_para = psiconv_clone_paragraph_layout |
597 | if (!(temp_para = psiconv_clone_paragraph_layout |
626 | (temp_style->paragraph))) |
598 | (temp_style->paragraph))) |
627 | goto ERROR4; |
599 | goto ERROR4; |
… | |
… | |
665 | temp = 0x00; |
637 | temp = 0x00; |
666 | |
638 | |
667 | if (!(temp_style = psiconv_get_style (styles,temp))) { |
639 | if (!(temp_style = psiconv_get_style (styles,temp))) { |
668 | psiconv_warn(config,lev+4,off,"Unknown Style referenced"); |
640 | psiconv_warn(config,lev+4,off,"Unknown Style referenced"); |
669 | if (!(temp_style = psiconv_get_style(styles,0))) { |
641 | if (!(temp_style = psiconv_get_style(styles,0))) { |
670 | psiconv_warn(config,lev+4,off,"Base style unknown"); |
642 | psiconv_error(config,lev+4,off,"Base style unknown"); |
671 | goto ERROR4; |
643 | goto ERROR4; |
672 | } |
644 | } |
673 | } |
645 | } |
674 | |
646 | |
675 | if (!(temp_para = psiconv_clone_paragraph_layout(temp_style->paragraph))) |
647 | if (!(temp_para = psiconv_clone_paragraph_layout(temp_style->paragraph))) |
… | |
… | |
712 | psiconv_progress(config,lev+3,off+len, |
684 | psiconv_progress(config,lev+3,off+len, |
713 | "Going to read the text layout inline elements"); |
685 | "Going to read the text layout inline elements"); |
714 | total = 0; |
686 | total = 0; |
715 | for (i = 0; i < psiconv_list_length(result); i++) { |
687 | for (i = 0; i < psiconv_list_length(result); i++) { |
716 | if (!(para = psiconv_list_get(result,i))) { |
688 | if (!(para = psiconv_list_get(result,i))) { |
717 | psiconv_warn(config,lev+3,off+len,"Massive memory corruption"); |
689 | psiconv_error(config,lev+3,off+len,"Massive memory corruption"); |
718 | goto ERROR4; |
690 | goto ERROR4; |
719 | } |
691 | } |
720 | line_length = -1; |
692 | line_length = -1; |
721 | for (j = 0; j < inline_count[i]; j++) { |
693 | for (j = 0; j < inline_count[i]; j++) { |
722 | psiconv_progress(config,lev+3,off+len,"Element %d: Paragraph %d, element %d", |
694 | psiconv_progress(config,lev+3,off+len,"Element %d: Paragraph %d, element %d", |
… | |
… | |
795 | in_line.object_height); |
767 | in_line.object_height); |
796 | len += leng; |
768 | len += leng; |
797 | } else if (temp != 0x00) { |
769 | } else if (temp != 0x00) { |
798 | psiconv_warn(config,lev+4,off+len,"Layout section unknown inline type"); |
770 | psiconv_warn(config,lev+4,off+len,"Layout section unknown inline type"); |
799 | } |
771 | } |
800 | if (line_length + in_line.length > strlen(para->text)) { |
772 | if (line_length + in_line.length > psiconv_unicode_strlen(para->text)) { |
801 | psiconv_warn(config,lev+4,off+len, |
773 | psiconv_warn(config,lev+4,off+len, |
802 | "Layout section inlines: line length mismatch"); |
774 | "Layout section inlines: line length mismatch"); |
803 | res = -1; |
775 | res = -1; |
804 | in_line.length = strlen(para->text) - line_length; |
776 | in_line.length = psiconv_unicode_strlen(para->text) - line_length; |
805 | } |
777 | } |
806 | line_length += in_line.length; |
778 | line_length += in_line.length; |
807 | if ((res = psiconv_list_add(para->in_lines,&in_line))) |
779 | if ((res = psiconv_list_add(para->in_lines,&in_line))) |
808 | goto ERROR5; |
780 | goto ERROR5; |
809 | } |
781 | } |
… | |
… | |
817 | |
789 | |
818 | free(inline_count); |
790 | free(inline_count); |
819 | |
791 | |
820 | for (i = 0 ; i < psiconv_list_length(anon_styles); i ++) { |
792 | for (i = 0 ; i < psiconv_list_length(anon_styles); i ++) { |
821 | if (!(anon_ptr = psiconv_list_get(anon_styles,i))) { |
793 | if (!(anon_ptr = psiconv_list_get(anon_styles,i))) { |
822 | psiconv_warn(config,lev+4,off+len,"Massive memory corruption"); |
794 | psiconv_error(config,lev+4,off+len,"Massive memory corruption"); |
823 | goto ERROR2; |
795 | goto ERROR2; |
824 | } |
796 | } |
825 | psiconv_free_character_layout(anon_ptr->character); |
797 | psiconv_free_character_layout(anon_ptr->character); |
826 | psiconv_free_paragraph_layout(anon_ptr->paragraph); |
798 | psiconv_free_paragraph_layout(anon_ptr->paragraph); |
827 | } |
799 | } |
… | |
… | |
859 | ERROR4: |
831 | ERROR4: |
860 | free(inline_count); |
832 | free(inline_count); |
861 | ERROR3: |
833 | ERROR3: |
862 | for (i = 0; i < psiconv_list_length(anon_styles); i++) { |
834 | for (i = 0; i < psiconv_list_length(anon_styles); i++) { |
863 | if (!(anon_ptr = psiconv_list_get(anon_styles,i))) { |
835 | if (!(anon_ptr = psiconv_list_get(anon_styles,i))) { |
864 | psiconv_warn(config,lev+1,off,"Massive memory corruption"); |
836 | psiconv_error(config,lev+1,off,"Massive memory corruption"); |
865 | break; |
837 | break; |
866 | } |
838 | } |
867 | psiconv_free_paragraph_layout(anon_ptr->paragraph); |
839 | psiconv_free_paragraph_layout(anon_ptr->paragraph); |
868 | psiconv_free_character_layout(anon_ptr->character); |
840 | psiconv_free_character_layout(anon_ptr->character); |
869 | } |
841 | } |
870 | |
842 | |
871 | ERROR2: |
843 | ERROR2: |
872 | psiconv_list_free(anon_styles); |
844 | psiconv_list_free(anon_styles); |
873 | ERROR1: |
845 | ERROR1: |
874 | psiconv_warn(config,lev+1,off,"Reading of Layout Section failed"); |
846 | psiconv_error(config,lev+1,off,"Reading of Layout Section failed"); |
875 | if (length) |
847 | if (length) |
876 | *length = 0; |
848 | *length = 0; |
877 | if (!res) |
849 | if (!res) |
878 | return -PSICONV_E_NOMEM; |
850 | return -PSICONV_E_NOMEM; |
879 | else |
851 | else |
… | |
… | |
910 | goto ERROR3; |
882 | goto ERROR3; |
911 | if (!(styles_section->normal->paragraph = |
883 | if (!(styles_section->normal->paragraph = |
912 | psiconv_clone_paragraph_layout(base_para))) |
884 | psiconv_clone_paragraph_layout(base_para))) |
913 | goto ERROR4; |
885 | goto ERROR4; |
914 | styles_section->normal->hotkey = 0; |
886 | styles_section->normal->hotkey = 0; |
|
|
887 | |
915 | if (!(styles_section->normal->name = strdup(""))) |
888 | if (!(styles_section->normal->name = psiconv_unicode_empty_string())) |
916 | goto ERROR5; |
889 | goto ERROR5; |
917 | if (!(styles_section->styles = psiconv_list_new(sizeof( |
890 | if (!(styles_section->styles = psiconv_list_new(sizeof( |
918 | struct psiconv_word_style_s)))) |
891 | struct psiconv_word_style_s)))) |
919 | goto ERROR6; |
892 | goto ERROR6; |
920 | |
893 | |
… | |
… | |
933 | ERROR3: |
906 | ERROR3: |
934 | free(styles_section->normal); |
907 | free(styles_section->normal); |
935 | ERROR2: |
908 | ERROR2: |
936 | free(styles_section); |
909 | free(styles_section); |
937 | ERROR1: |
910 | ERROR1: |
938 | psiconv_warn(config,lev+1,off,"Reading of Styleless Layout Section failed"); |
911 | psiconv_error(config,lev+1,off,"Reading of Styleless Layout Section failed"); |
939 | if (length) |
912 | if (length) |
940 | *length = 0; |
913 | *length = 0; |
941 | if (!res) |
914 | if (!res) |
942 | return -PSICONV_E_NOMEM; |
915 | return -PSICONV_E_NOMEM; |
943 | else |
916 | else |
… | |
… | |
1061 | psiconv_warn(config,lev+3,0,"Can't parse embedded object (still continuing)"); |
1034 | psiconv_warn(config,lev+3,0,"Can't parse embedded object (still continuing)"); |
1062 | (*result)->object->file = NULL; |
1035 | (*result)->object->file = NULL; |
1063 | } |
1036 | } |
1064 | } |
1037 | } |
1065 | |
1038 | |
|
|
1039 | psiconv_buffer_free(subbuf); |
|
|
1040 | psiconv_free_section_table_section(table); |
|
|
1041 | |
1066 | if (length) |
1042 | if (length) |
1067 | *length = len; |
1043 | *length = len; |
1068 | |
1044 | |
1069 | psiconv_progress(config,lev+1,off+len-1,"End of Embedded Object Section " |
1045 | psiconv_progress(config,lev+1,off+len-1,"End of Embedded Object Section " |
1070 | "(total length: %08x)",len); |
1046 | "(total length: %08x)",len); |
… | |
… | |
1081 | ERROR3: |
1057 | ERROR3: |
1082 | psiconv_free_object_display_section((*result)->display); |
1058 | psiconv_free_object_display_section((*result)->display); |
1083 | ERROR2: |
1059 | ERROR2: |
1084 | psiconv_free_section_table_section(table); |
1060 | psiconv_free_section_table_section(table); |
1085 | ERROR1: |
1061 | ERROR1: |
1086 | psiconv_warn(config,lev+1,off,"Reading Embedded Object failed"); |
1062 | psiconv_error(config,lev+1,off,"Reading Embedded Object failed"); |
1087 | |
1063 | |
1088 | if (length) |
1064 | if (length) |
1089 | *length = 0; |
1065 | *length = 0; |
1090 | |
1066 | |
1091 | if (res == 0) |
1067 | if (res == 0) |
… | |
… | |
1130 | off = entry->offset; |
1106 | off = entry->offset; |
1131 | break; |
1107 | break; |
1132 | } |
1108 | } |
1133 | } |
1109 | } |
1134 | if (i == psiconv_list_length(table)) { |
1110 | if (i == psiconv_list_length(table)) { |
1135 | psiconv_warn(config,lev+2,off,"No Application ID Section found"); |
1111 | psiconv_error(config,lev+2,off,"No Application ID Section found"); |
1136 | res = PSICONV_E_PARSE; |
1112 | res = PSICONV_E_PARSE; |
1137 | goto ERROR2; |
1113 | goto ERROR2; |
1138 | } |
1114 | } |
1139 | |
1115 | |
1140 | psiconv_progress(config,lev+2,off,"Going to read the Application ID Section"); |
1116 | psiconv_progress(config,lev+2,off,"Going to read the Application ID Section"); |
… | |
… | |
1232 | return res; |
1208 | return res; |
1233 | |
1209 | |
1234 | ERROR2: |
1210 | ERROR2: |
1235 | free(*result); |
1211 | free(*result); |
1236 | ERROR1: |
1212 | ERROR1: |
1237 | psiconv_warn(config,lev+1,off+len,"Reading of Object Display Section failed"); |
1213 | psiconv_error(config,lev+1,off+len,"Reading of Object Display Section failed"); |
1238 | if (length) |
1214 | if (length) |
1239 | *length=0; |
1215 | *length=0; |
1240 | if (!res) |
1216 | if (!res) |
1241 | return -PSICONV_E_NOMEM; |
1217 | return -PSICONV_E_NOMEM; |
1242 | else |
1218 | else |
… | |
… | |
1287 | ERROR3: |
1263 | ERROR3: |
1288 | free((*result)->icon_name); |
1264 | free((*result)->icon_name); |
1289 | ERROR2: |
1265 | ERROR2: |
1290 | free(*result); |
1266 | free(*result); |
1291 | ERROR1: |
1267 | ERROR1: |
1292 | psiconv_warn(config,lev+1,off+len,"Reading of Object Icon Section failed"); |
1268 | psiconv_error(config,lev+1,off+len,"Reading of Object Icon Section failed"); |
1293 | if (length) |
1269 | if (length) |
1294 | *length=0; |
1270 | *length=0; |
1295 | if (!res) |
1271 | if (!res) |
1296 | return -PSICONV_E_NOMEM; |
1272 | return -PSICONV_E_NOMEM; |
1297 | else |
1273 | else |