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-2004 Frodo Looijaard <frodol@dds.nl> |
3 | Copyright (c) 1999-2014 Frodo Looijaard <frodo@frodo.looijaard.name> |
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. |
… | |
… | |
29 | |
29 | |
30 | #ifdef DMALLOC |
30 | #ifdef DMALLOC |
31 | #include <dmalloc.h> |
31 | #include <dmalloc.h> |
32 | #endif |
32 | #endif |
33 | |
33 | |
34 | static psiconv_ucs2 unicode_paint[10] = { 'P','a','i','n','t','.','a','p','p',0 }; |
34 | /* Compare whether application id names match. |
35 | static psiconv_ucs2 unicode_texted[11] ={ 'T','e','x','t','E','d','.','a','p','p',0 }; |
35 | Sought must be lower case; the comparison is case insensitive */ |
36 | static psiconv_ucs2 unicode_word[9] = { 'W','o','r','d','.','a','p','p',0 }; |
36 | static psiconv_bool_t applid_matches(psiconv_string_t found, |
37 | static psiconv_ucs2 unicode_sheet[10] = { 'S','h','e','e','t','.','a','p','p',0 }; |
37 | const char *sought) |
|
|
38 | { |
|
|
39 | int i; |
|
|
40 | if (psiconv_unicode_strlen(found) != strlen(sought)) |
|
|
41 | return psiconv_bool_false; |
|
|
42 | for (i = 0; i < strlen(sought); i++) |
|
|
43 | if ((found[i] != sought[i]) && |
|
|
44 | ((sought[i] < 'a') || (sought[i] > 'z') || |
|
|
45 | (found[i] != sought[i] + 'A' - 'a'))) |
|
|
46 | return psiconv_bool_false; |
|
|
47 | return psiconv_bool_true; |
|
|
48 | } |
38 | |
49 | |
39 | psiconv_file_type_t psiconv_file_type(const psiconv_config config, |
50 | psiconv_file_type_t psiconv_file_type(const psiconv_config config, |
40 | psiconv_buffer buf,int *length, |
51 | psiconv_buffer buf,int *length, |
41 | psiconv_header_section *result) |
52 | psiconv_header_section *result) |
42 | { |
53 | { |
… | |
… | |
293 | if ((res = psiconv_parse_application_id_section(config,buf,lev+2,applid_sec,NULL, |
304 | if ((res = psiconv_parse_application_id_section(config,buf,lev+2,applid_sec,NULL, |
294 | &appl_id))) |
305 | &appl_id))) |
295 | goto ERROR3; |
306 | goto ERROR3; |
296 | } |
307 | } |
297 | if ((appl_id->id != PSICONV_ID_SKETCH) || |
308 | if ((appl_id->id != PSICONV_ID_SKETCH) || |
298 | psiconv_unicode_strcmp(appl_id->name,unicode_paint)) { |
309 | !applid_matches(appl_id->name,"paint.app")) { |
299 | psiconv_warn(config,lev+2,applid_sec, |
310 | psiconv_warn(config,lev+2,applid_sec, |
300 | "Application ID section contains unexpected data"); |
311 | "Application ID section contains unexpected data"); |
301 | psiconv_debug(config,lev+2,applid_sec,"ID: %08x expected, %08x found", |
312 | psiconv_debug(config,lev+2,applid_sec,"ID: %08x expected, %08x found", |
302 | PSICONV_ID_SKETCH,appl_id->id); |
313 | PSICONV_ID_SKETCH,appl_id->id); |
303 | if (!(temp_str = psiconv_make_printable(config,appl_id->name))) |
314 | if (!(temp_str = psiconv_make_printable(config,appl_id->name))) |
… | |
… | |
412 | &appl_id))) |
423 | &appl_id))) |
413 | goto ERROR3; |
424 | goto ERROR3; |
414 | } |
425 | } |
415 | |
426 | |
416 | if ((appl_id->id != PSICONV_ID_TEXTED) || |
427 | if ((appl_id->id != PSICONV_ID_TEXTED) || |
417 | psiconv_unicode_strcmp(appl_id->name,unicode_texted)) { |
428 | !applid_matches(appl_id->name,"texted.app")) { |
418 | psiconv_warn(config,lev+2,applid_sec, |
429 | psiconv_warn(config,lev+2,applid_sec, |
419 | "Application ID section contains unexpected data"); |
430 | "Application ID section contains unexpected data"); |
420 | psiconv_debug(config,lev+2,applid_sec,"ID: %08x expected, %08x found", |
431 | psiconv_debug(config,lev+2,applid_sec,"ID: %08x expected, %08x found", |
421 | PSICONV_ID_TEXTED,appl_id->id); |
432 | PSICONV_ID_TEXTED,appl_id->id); |
422 | if (!(temp_str = psiconv_make_printable(config,appl_id->name))) |
433 | if (!(temp_str = psiconv_make_printable(config,appl_id->name))) |
… | |
… | |
595 | if ((res = psiconv_parse_application_id_section(config,buf,lev+2,applid_sec,NULL, |
606 | if ((res = psiconv_parse_application_id_section(config,buf,lev+2,applid_sec,NULL, |
596 | &appl_id))) |
607 | &appl_id))) |
597 | goto ERROR4; |
608 | goto ERROR4; |
598 | } |
609 | } |
599 | if ((appl_id->id != PSICONV_ID_WORD) || |
610 | if ((appl_id->id != PSICONV_ID_WORD) || |
600 | psiconv_unicode_strcmp(appl_id->name,unicode_word)) { |
611 | !applid_matches(appl_id->name,"word.app")) { |
601 | psiconv_warn(config,lev+2,applid_sec, |
612 | psiconv_warn(config,lev+2,applid_sec, |
602 | "Application ID section contains unexpected data"); |
613 | "Application ID section contains unexpected data"); |
603 | psiconv_debug(config,lev+2,applid_sec,"ID: %08x expected, %08x found", |
614 | psiconv_debug(config,lev+2,applid_sec,"ID: %08x expected, %08x found", |
604 | PSICONV_ID_WORD,appl_id->id); |
615 | PSICONV_ID_WORD,appl_id->id); |
605 | if (!(temp_str = psiconv_make_printable(config,appl_id->name))) |
616 | if (!(temp_str = psiconv_make_printable(config,appl_id->name))) |
… | |
… | |
791 | if ((res = psiconv_parse_application_id_section(config,buf,lev+2,applid_sec,NULL, |
802 | if ((res = psiconv_parse_application_id_section(config,buf,lev+2,applid_sec,NULL, |
792 | &appl_id))) |
803 | &appl_id))) |
793 | goto ERROR4; |
804 | goto ERROR4; |
794 | } |
805 | } |
795 | if ((appl_id->id != PSICONV_ID_SHEET) || |
806 | if ((appl_id->id != PSICONV_ID_SHEET) || |
796 | psiconv_unicode_strcmp(appl_id->name,unicode_sheet)) { |
807 | !applid_matches(appl_id->name,"sheet.app")) { |
797 | psiconv_warn(config,lev+2,applid_sec, |
808 | psiconv_warn(config,lev+2,applid_sec, |
798 | "Application ID section contains unexpected data"); |
809 | "Application ID section contains unexpected data"); |
799 | psiconv_debug(config,lev+2,applid_sec,"ID: %08x expected, %08x found", |
810 | psiconv_debug(config,lev+2,applid_sec,"ID: %08x expected, %08x found", |
800 | PSICONV_ID_SHEET,appl_id->id); |
811 | PSICONV_ID_SHEET,appl_id->id); |
801 | if (!(temp_str = psiconv_make_printable(config,appl_id->name))) |
812 | if (!(temp_str = psiconv_make_printable(config,appl_id->name))) |