1 | /* |
1 | /* |
2 | parse_driver.c - Part of psiconv, a PSION 5 file formats converter |
2 | parse_driver.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. |
… | |
… | |
23 | #include <stdlib.h> |
23 | #include <stdlib.h> |
24 | #include <string.h> |
24 | #include <string.h> |
25 | |
25 | |
26 | #include "parse.h" |
26 | #include "parse.h" |
27 | #include "parse_routines.h" |
27 | #include "parse_routines.h" |
|
|
28 | #include "unicode.h" |
28 | |
29 | |
29 | #ifdef DMALLOC |
30 | #ifdef DMALLOC |
30 | #include <dmalloc.h> |
31 | #include <dmalloc.h> |
31 | #endif |
32 | #endif |
32 | |
33 | |
|
|
34 | static psiconv_ucs2 unicode_paint[10] = { 'P','a','i','n','t','.','a','p','p',0 }; |
|
|
35 | static psiconv_ucs2 unicode_texted[11] ={ 'T','e','x','t','E','d','.','a','p','p',0 }; |
|
|
36 | static psiconv_ucs2 unicode_word[9] = { 'W','o','r','d','.','a','p','p',0 }; |
|
|
37 | static psiconv_ucs2 unicode_sheet[10] = { 'S','h','e','e','t','.','a','p','p',0 }; |
33 | |
38 | |
34 | psiconv_file_type_t psiconv_file_type(const psiconv_config config, |
39 | psiconv_file_type_t psiconv_file_type(const psiconv_config config, |
35 | psiconv_buffer buf,int *length, |
40 | psiconv_buffer buf,int *length, |
36 | psiconv_header_section *result) |
41 | psiconv_header_section *result) |
37 | { |
42 | { |
… | |
… | |
93 | return 0; |
98 | return 0; |
94 | |
99 | |
95 | ERROR2: |
100 | ERROR2: |
96 | free(*result); |
101 | free(*result); |
97 | ERROR1: |
102 | ERROR1: |
98 | psiconv_warn(config,lev+1,off,"Reading of Psion File failed"); |
103 | psiconv_error(config,lev+1,off,"Reading of Psion File failed"); |
99 | if (res == 0) |
104 | if (res == 0) |
100 | return -PSICONV_E_NOMEM; |
105 | return -PSICONV_E_NOMEM; |
101 | else |
106 | else |
102 | return res; |
107 | return res; |
103 | } |
108 | } |
… | |
… | |
139 | ERROR5: |
144 | ERROR5: |
140 | psiconv_free_clipart_section(clipart); |
145 | psiconv_free_clipart_section(clipart); |
141 | ERROR4: |
146 | ERROR4: |
142 | for (i = 0; i < psiconv_list_length((*result)->sections); i++) { |
147 | for (i = 0; i < psiconv_list_length((*result)->sections); i++) { |
143 | if (!(clipart = psiconv_list_get((*result)->sections,i))) { |
148 | if (!(clipart = psiconv_list_get((*result)->sections,i))) { |
144 | psiconv_warn(config,lev+1,off,"Massive memory corruption"); |
149 | psiconv_error(config,lev+1,off,"Massive memory corruption"); |
145 | goto ERROR3; |
150 | goto ERROR3; |
146 | } |
151 | } |
147 | psiconv_free_clipart_section(clipart); |
152 | psiconv_free_clipart_section(clipart); |
148 | } |
153 | } |
149 | psiconv_list_free((*result)->sections); |
154 | psiconv_list_free((*result)->sections); |
150 | ERROR3: |
155 | ERROR3: |
151 | psiconv_free_jumptable_section(table); |
156 | psiconv_free_jumptable_section(table); |
152 | ERROR2: |
157 | ERROR2: |
153 | free(*result); |
158 | free(*result); |
154 | ERROR1: |
159 | ERROR1: |
155 | psiconv_warn(config,lev+1,off,"Reading of Clipart File failed"); |
160 | psiconv_error(config,lev+1,off,"Reading of Clipart File failed"); |
156 | if (res == 0) |
161 | if (res == 0) |
157 | return -PSICONV_E_NOMEM; |
162 | return -PSICONV_E_NOMEM; |
158 | else |
163 | else |
159 | return res; |
164 | return res; |
160 | } |
165 | } |
… | |
… | |
204 | ERROR5: |
209 | ERROR5: |
205 | psiconv_free_paint_data_section(paint); |
210 | psiconv_free_paint_data_section(paint); |
206 | ERROR4: |
211 | ERROR4: |
207 | for (i = 0; i < psiconv_list_length((*result)->sections); i++) { |
212 | for (i = 0; i < psiconv_list_length((*result)->sections); i++) { |
208 | if (!(paint = psiconv_list_get((*result)->sections,i))) { |
213 | if (!(paint = psiconv_list_get((*result)->sections,i))) { |
209 | psiconv_warn(config,lev+1,off,"Massive memory corruption"); |
214 | psiconv_error(config,lev+1,off,"Massive memory corruption"); |
210 | goto ERROR3; |
215 | goto ERROR3; |
211 | } |
216 | } |
212 | psiconv_free_paint_data_section(paint); |
217 | psiconv_free_paint_data_section(paint); |
213 | } |
218 | } |
214 | psiconv_list_free((*result)->sections); |
219 | psiconv_list_free((*result)->sections); |
215 | ERROR3: |
220 | ERROR3: |
216 | psiconv_free_jumptable_section(table); |
221 | psiconv_free_jumptable_section(table); |
217 | ERROR2: |
222 | ERROR2: |
218 | free(*result); |
223 | free(*result); |
219 | ERROR1: |
224 | ERROR1: |
220 | psiconv_warn(config,lev+1,off,"Reading of MBM File failed"); |
225 | psiconv_error(config,lev+1,off,"Reading of MBM File failed"); |
221 | if (res == 0) |
226 | if (res == 0) |
222 | return -PSICONV_E_NOMEM; |
227 | return -PSICONV_E_NOMEM; |
223 | else |
228 | else |
224 | return res; |
229 | return res; |
225 | } |
230 | } |
… | |
… | |
274 | } |
279 | } |
275 | } |
280 | } |
276 | |
281 | |
277 | psiconv_progress(config,lev+2,sto, "Looking for the Application ID section"); |
282 | psiconv_progress(config,lev+2,sto, "Looking for the Application ID section"); |
278 | if (! applid_sec) { |
283 | if (! applid_sec) { |
279 | psiconv_warn(config,lev+2,sto, |
284 | psiconv_error(config,lev+2,sto, |
280 | "Application ID section not found in the section table"); |
285 | "Application ID section not found in the section table"); |
281 | res = -PSICONV_E_PARSE; |
286 | res = -PSICONV_E_PARSE; |
282 | goto ERROR3; |
287 | goto ERROR3; |
283 | } else { |
288 | } else { |
284 | psiconv_debug(config,lev+2,sto, |
289 | psiconv_debug(config,lev+2,sto, |
… | |
… | |
286 | if ((res = psiconv_parse_application_id_section(config,buf,lev+2,applid_sec,NULL, |
291 | if ((res = psiconv_parse_application_id_section(config,buf,lev+2,applid_sec,NULL, |
287 | &appl_id))) |
292 | &appl_id))) |
288 | goto ERROR3; |
293 | goto ERROR3; |
289 | } |
294 | } |
290 | if ((appl_id->id != PSICONV_ID_SKETCH) || |
295 | if ((appl_id->id != PSICONV_ID_SKETCH) || |
291 | strcmp(appl_id->name,"Paint.app")) { |
296 | psiconv_unicode_strcmp(appl_id->name,unicode_paint)) { |
292 | psiconv_warn(config,lev+2,applid_sec, |
297 | psiconv_warn(config,lev+2,applid_sec, |
293 | "Application ID section contains unexpected data"); |
298 | "Application ID section contains unexpected data"); |
294 | psiconv_debug(config,lev+2,applid_sec,"ID: %08x expected, %08x found", |
299 | psiconv_debug(config,lev+2,applid_sec,"ID: %08x expected, %08x found", |
295 | PSICONV_ID_SKETCH,appl_id->id); |
300 | PSICONV_ID_SKETCH,appl_id->id); |
296 | if (!(temp_str = psiconv_make_printable(appl_id->name))) |
301 | if (!(temp_str = psiconv_make_printable(config,appl_id->name))) |
297 | goto ERROR4; |
302 | goto ERROR4; |
298 | psiconv_debug(config,lev+2,applid_sec,"Name: `%s' expected, `%s' found", |
303 | psiconv_debug(config,lev+2,applid_sec,"Name: `%s' expected, `%s' found", |
299 | "Paint.app",temp_str); |
304 | "Paint.app",temp_str); |
300 | free(temp_str); |
305 | free(temp_str); |
301 | res = -PSICONV_E_PARSE; |
306 | res = -PSICONV_E_PARSE; |
… | |
… | |
315 | } |
320 | } |
316 | |
321 | |
317 | psiconv_free_application_id_section(appl_id); |
322 | psiconv_free_application_id_section(appl_id); |
318 | psiconv_free_section_table_section(table); |
323 | psiconv_free_section_table_section(table); |
319 | |
324 | |
320 | psiconv_progress(config,lev+1,off,"End of word file"); |
325 | psiconv_progress(config,lev+1,off,"End of sketch file"); |
321 | return res; |
326 | return res; |
322 | |
327 | |
323 | ERROR4: |
328 | ERROR4: |
324 | psiconv_free_application_id_section(appl_id); |
329 | psiconv_free_application_id_section(appl_id); |
325 | ERROR3: |
330 | ERROR3: |
326 | free(table); |
331 | free(table); |
327 | ERROR2: |
332 | ERROR2: |
328 | free(*result); |
333 | free(*result); |
329 | ERROR1: |
334 | ERROR1: |
330 | psiconv_warn(config,lev+1,off,"Reading of Scketch File failed"); |
335 | psiconv_error(config,lev+1,off,"Reading of Sketch File failed"); |
331 | if (res == 0) |
336 | if (res == 0) |
332 | return -PSICONV_E_NOMEM; |
337 | return -PSICONV_E_NOMEM; |
333 | else |
338 | else |
334 | return res; |
339 | return res; |
335 | } |
340 | } |
… | |
… | |
392 | } |
397 | } |
393 | } |
398 | } |
394 | |
399 | |
395 | psiconv_progress(config,lev+2,sto, "Looking for the Application ID section"); |
400 | psiconv_progress(config,lev+2,sto, "Looking for the Application ID section"); |
396 | if (! applid_sec) { |
401 | if (! applid_sec) { |
397 | psiconv_warn(config,lev+2,sto, |
402 | psiconv_error(config,lev+2,sto, |
398 | "Application ID section not found in the section table"); |
403 | "Application ID section not found in the section table"); |
399 | res = -PSICONV_E_PARSE; |
404 | res = -PSICONV_E_PARSE; |
400 | goto ERROR3; |
405 | goto ERROR3; |
401 | } else { |
406 | } else { |
402 | psiconv_debug(config,lev+2,sto, |
407 | psiconv_debug(config,lev+2,sto, |
403 | "Application ID section at offset %08x",applid_sec); |
408 | "Application ID section at offset %08x",applid_sec); |
404 | if ((res = psiconv_parse_application_id_section(config,buf,lev+2,applid_sec,NULL, |
409 | if ((res = psiconv_parse_application_id_section(config,buf,lev+2,applid_sec,NULL, |
405 | &appl_id))) |
410 | &appl_id))) |
406 | goto ERROR3; |
411 | goto ERROR3; |
407 | } |
412 | } |
|
|
413 | |
408 | if ((appl_id->id != PSICONV_ID_TEXTED) || |
414 | if ((appl_id->id != PSICONV_ID_TEXTED) || |
409 | strcmp(appl_id->name,"TextEd.app")) { |
415 | psiconv_unicode_strcmp(appl_id->name,unicode_texted)) { |
410 | psiconv_warn(config,lev+2,applid_sec, |
416 | psiconv_warn(config,lev+2,applid_sec, |
411 | "Application ID section contains unexpected data"); |
417 | "Application ID section contains unexpected data"); |
412 | psiconv_debug(config,lev+2,applid_sec,"ID: %08x expected, %08x found", |
418 | psiconv_debug(config,lev+2,applid_sec,"ID: %08x expected, %08x found", |
413 | PSICONV_ID_TEXTED,appl_id->id); |
419 | PSICONV_ID_TEXTED,appl_id->id); |
414 | if (!(temp_str = psiconv_make_printable(appl_id->name))) |
420 | if (!(temp_str = psiconv_make_printable(config,appl_id->name))) |
415 | goto ERROR4; |
421 | goto ERROR4; |
416 | psiconv_debug(config,lev+2,applid_sec,"Name: `%s' expected, `%s' found", |
422 | psiconv_debug(config,lev+2,applid_sec,"Name: `%s' expected, `%s' found", |
417 | "TextEd.app",temp_str); |
423 | "TextEd.app",temp_str); |
418 | free(temp_str); |
424 | free(temp_str); |
419 | res = -PSICONV_E_PARSE; |
425 | res = -PSICONV_E_PARSE; |
… | |
… | |
421 | } |
427 | } |
422 | |
428 | |
423 | psiconv_progress(config,lev+2,sto, |
429 | psiconv_progress(config,lev+2,sto, |
424 | "Looking for the Page layout section"); |
430 | "Looking for the Page layout section"); |
425 | if (! page_sec) { |
431 | if (! page_sec) { |
426 | psiconv_warn(config,lev+2,sto, |
432 | psiconv_error(config,lev+2,sto, |
427 | "Page layout section not found in the section table"); |
433 | "Page layout section not found in the section table"); |
428 | res = -PSICONV_E_PARSE; |
434 | res = -PSICONV_E_PARSE; |
429 | goto ERROR4; |
435 | goto ERROR4; |
430 | } else { |
436 | } else { |
431 | psiconv_debug(config,lev+2,sto, |
437 | psiconv_debug(config,lev+2,sto, |
… | |
… | |
441 | goto ERROR6; |
447 | goto ERROR6; |
442 | |
448 | |
443 | psiconv_progress(config,lev+2,sto, |
449 | psiconv_progress(config,lev+2,sto, |
444 | "Looking for the TextEd section"); |
450 | "Looking for the TextEd section"); |
445 | if (! texted_sec) { |
451 | if (! texted_sec) { |
446 | psiconv_warn(config,lev+2,sto, |
452 | psiconv_error(config,lev+2,sto, |
447 | "TextEd section not found in the section table"); |
453 | "TextEd section not found in the section table"); |
448 | res = -PSICONV_E_PARSE; |
454 | res = -PSICONV_E_PARSE; |
449 | goto ERROR7; |
455 | goto ERROR7; |
450 | } else { |
456 | } else { |
451 | psiconv_debug(config,lev+2,sto, "TextEd section at offset %08x",texted_sec); |
457 | psiconv_debug(config,lev+2,sto, "TextEd section at offset %08x",texted_sec); |
… | |
… | |
474 | ERROR3: |
480 | ERROR3: |
475 | psiconv_free_section_table_section(table); |
481 | psiconv_free_section_table_section(table); |
476 | ERROR2: |
482 | ERROR2: |
477 | free(*result); |
483 | free(*result); |
478 | ERROR1: |
484 | ERROR1: |
479 | psiconv_warn(config,lev+1,off,"Reading of TextEd File failed"); |
485 | psiconv_error(config,lev+1,off,"Reading of TextEd File failed"); |
480 | if (res == 0) |
486 | if (res == 0) |
481 | return -PSICONV_E_NOMEM; |
487 | return -PSICONV_E_NOMEM; |
482 | else |
488 | else |
483 | return res; |
489 | return res; |
484 | } |
490 | } |
… | |
… | |
535 | psiconv_debug(config,lev+3,sto, "Found the Text section at %08x",text_sec); |
541 | psiconv_debug(config,lev+3,sto, "Found the Text section at %08x",text_sec); |
536 | } else if (entry->id == PSICONV_ID_PASSWORD_SECTION) { |
542 | } else if (entry->id == PSICONV_ID_PASSWORD_SECTION) { |
537 | pwd_sec = entry->offset; |
543 | pwd_sec = entry->offset; |
538 | psiconv_debug(config,lev+3,sto, |
544 | psiconv_debug(config,lev+3,sto, |
539 | "Found the Password section at %08x",pwd_sec); |
545 | "Found the Password section at %08x",pwd_sec); |
540 | psiconv_warn(config,lev+3,sto, |
546 | psiconv_error(config,lev+3,sto, |
541 | "Password section found - can't read encrypted data"); |
547 | "Password section found - can't read encrypted data"); |
542 | res = -PSICONV_E_PARSE; |
548 | res = -PSICONV_E_PARSE; |
543 | goto ERROR3; |
549 | goto ERROR3; |
544 | } else if (entry->id == PSICONV_ID_WORD_STATUS_SECTION) { |
550 | } else if (entry->id == PSICONV_ID_WORD_STATUS_SECTION) { |
545 | status_sec = entry->offset; |
551 | status_sec = entry->offset; |
… | |
… | |
563 | |
569 | |
564 | |
570 | |
565 | psiconv_progress(config,lev+2,sto, |
571 | psiconv_progress(config,lev+2,sto, |
566 | "Looking for the Status section"); |
572 | "Looking for the Status section"); |
567 | if (!status_sec) { |
573 | if (!status_sec) { |
568 | psiconv_warn(config,lev+2,sto, "Status section not found in the section table"); |
574 | psiconv_error(config,lev+2,sto, "Status section not found in the section table"); |
569 | res = -PSICONV_E_PARSE; |
575 | res = -PSICONV_E_PARSE; |
570 | goto ERROR3; |
576 | goto ERROR3; |
571 | } else { |
577 | } else { |
572 | psiconv_debug(config,lev+2,sto, "Status section at offset %08x",status_sec); |
578 | psiconv_debug(config,lev+2,sto, "Status section at offset %08x",status_sec); |
573 | if ((res = psiconv_parse_word_status_section(config,buf,lev+2,status_sec,NULL, |
579 | if ((res = psiconv_parse_word_status_section(config,buf,lev+2,status_sec,NULL, |
… | |
… | |
575 | goto ERROR3; |
581 | goto ERROR3; |
576 | } |
582 | } |
577 | |
583 | |
578 | psiconv_progress(config,lev+2,sto, "Looking for the Application ID section"); |
584 | psiconv_progress(config,lev+2,sto, "Looking for the Application ID section"); |
579 | if (! applid_sec) { |
585 | if (! applid_sec) { |
580 | psiconv_warn(config,lev+2,sto, |
586 | psiconv_error(config,lev+2,sto, |
581 | "Application ID section not found in the section table"); |
587 | "Application ID section not found in the section table"); |
582 | res = -PSICONV_E_PARSE; |
588 | res = -PSICONV_E_PARSE; |
583 | goto ERROR4; |
589 | goto ERROR4; |
584 | } else { |
590 | } else { |
585 | psiconv_debug(config,lev+2,sto, |
591 | psiconv_debug(config,lev+2,sto, |
… | |
… | |
587 | if ((res = psiconv_parse_application_id_section(config,buf,lev+2,applid_sec,NULL, |
593 | if ((res = psiconv_parse_application_id_section(config,buf,lev+2,applid_sec,NULL, |
588 | &appl_id))) |
594 | &appl_id))) |
589 | goto ERROR4; |
595 | goto ERROR4; |
590 | } |
596 | } |
591 | if ((appl_id->id != PSICONV_ID_WORD) || |
597 | if ((appl_id->id != PSICONV_ID_WORD) || |
592 | strcmp(appl_id->name,"Word.app")) { |
598 | psiconv_unicode_strcmp(appl_id->name,unicode_word)) { |
593 | psiconv_warn(config,lev+2,applid_sec, |
599 | psiconv_warn(config,lev+2,applid_sec, |
594 | "Application ID section contains unexpected data"); |
600 | "Application ID section contains unexpected data"); |
595 | psiconv_debug(config,lev+2,applid_sec,"ID: %08x expected, %08x found", |
601 | psiconv_debug(config,lev+2,applid_sec,"ID: %08x expected, %08x found", |
596 | PSICONV_ID_WORD,appl_id->id); |
602 | PSICONV_ID_WORD,appl_id->id); |
597 | if (!(temp_str = psiconv_make_printable(appl_id->name))) |
603 | if (!(temp_str = psiconv_make_printable(config,appl_id->name))) |
598 | goto ERROR5; |
604 | goto ERROR5; |
599 | psiconv_debug(config,lev+2,applid_sec,"Name: `%s' expected, `%s' found", |
605 | psiconv_debug(config,lev+2,applid_sec,"Name: `%s' expected, `%s' found", |
600 | "Word.app",temp_str); |
606 | "Word.app",temp_str); |
601 | free(temp_str); |
607 | free(temp_str); |
602 | res = -PSICONV_E_PARSE; |
608 | res = -PSICONV_E_PARSE; |
… | |
… | |
604 | } |
610 | } |
605 | |
611 | |
606 | psiconv_progress(config,lev+2,sto, |
612 | psiconv_progress(config,lev+2,sto, |
607 | "Looking for the Page layout section"); |
613 | "Looking for the Page layout section"); |
608 | if (! page_sec) { |
614 | if (! page_sec) { |
609 | psiconv_warn(config,lev+2,sto, |
615 | psiconv_error(config,lev+2,sto, |
610 | "Page layout section not found in the section table"); |
616 | "Page layout section not found in the section table"); |
611 | res = -PSICONV_E_PARSE; |
617 | res = -PSICONV_E_PARSE; |
612 | goto ERROR5; |
618 | goto ERROR5; |
613 | } else { |
619 | } else { |
614 | psiconv_debug(config,lev+2,sto, |
620 | psiconv_debug(config,lev+2,sto, |
… | |
… | |
619 | } |
625 | } |
620 | |
626 | |
621 | psiconv_progress(config,lev+2,sto, |
627 | psiconv_progress(config,lev+2,sto, |
622 | "Looking for the Word Style section"); |
628 | "Looking for the Word Style section"); |
623 | if (!styles_sec) { |
629 | if (!styles_sec) { |
624 | psiconv_warn(config,lev+2,sto, |
630 | psiconv_error(config,lev+2,sto, |
625 | "Word styles section not found in the section table"); |
631 | "Word styles section not found in the section table"); |
626 | res = -PSICONV_E_PARSE; |
632 | res = -PSICONV_E_PARSE; |
627 | goto ERROR6; |
633 | goto ERROR6; |
628 | } else { |
634 | } else { |
629 | psiconv_debug(config,lev+2,sto, |
635 | psiconv_debug(config,lev+2,sto, |
… | |
… | |
634 | } |
640 | } |
635 | |
641 | |
636 | psiconv_progress(config,lev+2,sto, |
642 | psiconv_progress(config,lev+2,sto, |
637 | "Looking for the Text section"); |
643 | "Looking for the Text section"); |
638 | if (!text_sec) { |
644 | if (!text_sec) { |
639 | psiconv_warn(config,lev+2,sto, "Text section not found in the section table"); |
645 | psiconv_error(config,lev+2,sto, "Text section not found in the section table"); |
640 | res = -PSICONV_E_PARSE; |
646 | res = -PSICONV_E_PARSE; |
641 | goto ERROR7; |
647 | goto ERROR7; |
642 | } else { |
648 | } else { |
643 | psiconv_debug(config,lev+2,sto, |
649 | psiconv_debug(config,lev+2,sto, |
644 | "Text section at offset %08x",text_sec); |
650 | "Text section at offset %08x",text_sec); |
… | |
… | |
679 | ERROR3: |
685 | ERROR3: |
680 | psiconv_free_section_table_section(table); |
686 | psiconv_free_section_table_section(table); |
681 | ERROR2: |
687 | ERROR2: |
682 | free(*result); |
688 | free(*result); |
683 | ERROR1: |
689 | ERROR1: |
684 | psiconv_warn(config,lev+1,off,"Reading of Word File failed"); |
690 | psiconv_error(config,lev+1,off,"Reading of Word File failed"); |
685 | if (res == 0) |
691 | if (res == 0) |
686 | return -PSICONV_E_NOMEM; |
692 | return -PSICONV_E_NOMEM; |
687 | else |
693 | else |
688 | return res; |
694 | return res; |
689 | } |
695 | } |
… | |
… | |
735 | "Found the Page Layout section at %08x",page_sec); |
741 | "Found the Page Layout section at %08x",page_sec); |
736 | } else if (entry->id == PSICONV_ID_PASSWORD_SECTION) { |
742 | } else if (entry->id == PSICONV_ID_PASSWORD_SECTION) { |
737 | pwd_sec = entry->offset; |
743 | pwd_sec = entry->offset; |
738 | psiconv_debug(config,lev+3,sto, |
744 | psiconv_debug(config,lev+3,sto, |
739 | "Found the Password section at %08x",pwd_sec); |
745 | "Found the Password section at %08x",pwd_sec); |
740 | psiconv_warn(config,lev+3,sto, |
746 | psiconv_error(config,lev+3,sto, |
741 | "Password section found - can't read encrypted data"); |
747 | "Password section found - can't read encrypted data"); |
742 | res = -PSICONV_E_PARSE; |
748 | res = -PSICONV_E_PARSE; |
743 | goto ERROR3; |
749 | goto ERROR3; |
744 | } else if (entry->id == PSICONV_ID_SHEET_WORKBOOK_SECTION) { |
750 | } else if (entry->id == PSICONV_ID_SHEET_WORKBOOK_SECTION) { |
745 | workbook_sec = entry->offset; |
751 | workbook_sec = entry->offset; |
… | |
… | |
759 | |
765 | |
760 | |
766 | |
761 | psiconv_progress(config,lev+2,sto, |
767 | psiconv_progress(config,lev+2,sto, |
762 | "Looking for the Status section"); |
768 | "Looking for the Status section"); |
763 | if (!status_sec) { |
769 | if (!status_sec) { |
764 | psiconv_warn(config,lev+2,sto, "Status section not found in the section table"); |
770 | psiconv_error(config,lev+2,sto, "Status section not found in the section table"); |
765 | res = -PSICONV_E_PARSE; |
771 | res = -PSICONV_E_PARSE; |
766 | goto ERROR3; |
772 | goto ERROR3; |
767 | } else { |
773 | } else { |
768 | psiconv_debug(config,lev+2,sto, "Status section at offset %08x",status_sec); |
774 | psiconv_debug(config,lev+2,sto, "Status section at offset %08x",status_sec); |
769 | if ((res = psiconv_parse_sheet_status_section(config,buf,lev+2,status_sec,NULL, |
775 | if ((res = psiconv_parse_sheet_status_section(config,buf,lev+2,status_sec,NULL, |
… | |
… | |
771 | goto ERROR3; |
777 | goto ERROR3; |
772 | } |
778 | } |
773 | |
779 | |
774 | psiconv_progress(config,lev+2,sto, "Looking for the Application ID section"); |
780 | psiconv_progress(config,lev+2,sto, "Looking for the Application ID section"); |
775 | if (! applid_sec) { |
781 | if (! applid_sec) { |
776 | psiconv_warn(config,lev+2,sto, |
782 | psiconv_error(config,lev+2,sto, |
777 | "Application ID section not found in the section table"); |
783 | "Application ID section not found in the section table"); |
778 | res = -PSICONV_E_PARSE; |
784 | res = -PSICONV_E_PARSE; |
779 | goto ERROR4; |
785 | goto ERROR4; |
780 | } else { |
786 | } else { |
781 | psiconv_debug(config,lev+2,sto, |
787 | psiconv_debug(config,lev+2,sto, |
… | |
… | |
783 | if ((res = psiconv_parse_application_id_section(config,buf,lev+2,applid_sec,NULL, |
789 | if ((res = psiconv_parse_application_id_section(config,buf,lev+2,applid_sec,NULL, |
784 | &appl_id))) |
790 | &appl_id))) |
785 | goto ERROR4; |
791 | goto ERROR4; |
786 | } |
792 | } |
787 | if ((appl_id->id != PSICONV_ID_SHEET) || |
793 | if ((appl_id->id != PSICONV_ID_SHEET) || |
788 | strcmp(appl_id->name,"Sheet.app")) { |
794 | psiconv_unicode_strcmp(appl_id->name,unicode_sheet)) { |
789 | psiconv_warn(config,lev+2,applid_sec, |
795 | psiconv_warn(config,lev+2,applid_sec, |
790 | "Application ID section contains unexpected data"); |
796 | "Application ID section contains unexpected data"); |
791 | psiconv_debug(config,lev+2,applid_sec,"ID: %08x expected, %08x found", |
797 | psiconv_debug(config,lev+2,applid_sec,"ID: %08x expected, %08x found", |
792 | PSICONV_ID_SHEET,appl_id->id); |
798 | PSICONV_ID_SHEET,appl_id->id); |
793 | if (!(temp_str = psiconv_make_printable(appl_id->name))) |
799 | if (!(temp_str = psiconv_make_printable(config,appl_id->name))) |
794 | goto ERROR5; |
800 | goto ERROR5; |
795 | psiconv_debug(config,lev+2,applid_sec,"Name: `%s' expected, `%s' found", |
801 | psiconv_debug(config,lev+2,applid_sec,"Name: `%s' expected, `%s' found", |
796 | "Sheet.app",temp_str); |
802 | "Sheet.app",temp_str); |
797 | free(temp_str); |
803 | free(temp_str); |
798 | res = -PSICONV_E_PARSE; |
804 | res = -PSICONV_E_PARSE; |
… | |
… | |
800 | } |
806 | } |
801 | |
807 | |
802 | psiconv_progress(config,lev+2,sto, |
808 | psiconv_progress(config,lev+2,sto, |
803 | "Looking for the Page layout section"); |
809 | "Looking for the Page layout section"); |
804 | if (! page_sec) { |
810 | if (! page_sec) { |
805 | psiconv_warn(config,lev+2,sto, |
811 | psiconv_error(config,lev+2,sto, |
806 | "Page layout section not found in the section table"); |
812 | "Page layout section not found in the section table"); |
807 | res = -PSICONV_E_PARSE; |
813 | res = -PSICONV_E_PARSE; |
808 | goto ERROR5; |
814 | goto ERROR5; |
809 | } else { |
815 | } else { |
810 | psiconv_debug(config,lev+2,sto, |
816 | psiconv_debug(config,lev+2,sto, |
… | |
… | |
815 | } |
821 | } |
816 | |
822 | |
817 | psiconv_progress(config,lev+2,sto, |
823 | psiconv_progress(config,lev+2,sto, |
818 | "Looking for the Sheet Workbook section"); |
824 | "Looking for the Sheet Workbook section"); |
819 | if (! workbook_sec) { |
825 | if (! workbook_sec) { |
820 | psiconv_warn(config,lev+2,sto, |
826 | psiconv_error(config,lev+2,sto, |
821 | "Sheet workbook section not found in the section table"); |
827 | "Sheet workbook section not found in the section table"); |
822 | res = -PSICONV_E_PARSE; |
828 | res = -PSICONV_E_PARSE; |
823 | goto ERROR6; |
829 | goto ERROR6; |
824 | } else { |
830 | } else { |
825 | psiconv_debug(config,lev+2,sto, |
831 | psiconv_debug(config,lev+2,sto, |
… | |
… | |
844 | ERROR3: |
850 | ERROR3: |
845 | psiconv_free_section_table_section(table); |
851 | psiconv_free_section_table_section(table); |
846 | ERROR2: |
852 | ERROR2: |
847 | free(*result); |
853 | free(*result); |
848 | ERROR1: |
854 | ERROR1: |
849 | psiconv_warn(config,lev+1,off,"Reading of Sheet File failed"); |
855 | psiconv_error(config,lev+1,off,"Reading of Sheet File failed"); |
850 | if (res == 0) |
856 | if (res == 0) |
851 | return -PSICONV_E_NOMEM; |
857 | return -PSICONV_E_NOMEM; |
852 | else |
858 | else |
853 | return res; |
859 | return res; |
854 | } |
860 | } |