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-2005 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 | { |
… | |
… | |
134 | psiconv_progress(config,lev+3,off,"Going to read clipart section %i",i); |
145 | psiconv_progress(config,lev+3,off,"Going to read clipart section %i",i); |
135 | if ((res = psiconv_parse_clipart_section(config,buf,lev+3,*entry,NULL,&clipart))) |
146 | if ((res = psiconv_parse_clipart_section(config,buf,lev+3,*entry,NULL,&clipart))) |
136 | goto ERROR4; |
147 | goto ERROR4; |
137 | if ((res = psiconv_list_add((*result)->sections,clipart))) |
148 | if ((res = psiconv_list_add((*result)->sections,clipart))) |
138 | goto ERROR5; |
149 | goto ERROR5; |
|
|
150 | free(clipart); |
139 | } |
151 | } |
140 | |
152 | |
141 | psiconv_free_jumptable_section(table); |
153 | psiconv_free_jumptable_section(table); |
142 | psiconv_progress(config,lev+1,off,"End of clipart file"); |
154 | psiconv_progress(config,lev+1,off,"End of clipart file"); |
143 | return res; |
155 | return res; |
144 | ERROR5: |
156 | ERROR5: |
145 | psiconv_free_clipart_section(clipart); |
157 | psiconv_free_clipart_section(clipart); |
146 | ERROR4: |
158 | ERROR4: |
147 | for (i = 0; i < psiconv_list_length((*result)->sections); i++) { |
159 | for (i = 0; i < psiconv_list_length((*result)->sections); i++) { |
148 | if (!(clipart = psiconv_list_get((*result)->sections,i))) { |
160 | if (!(clipart = psiconv_list_get((*result)->sections,i))) { |
149 | psiconv_error(config,lev+1,off,"Massive memory corruption"); |
161 | psiconv_error(config,lev+1,off,"Data structure corruption"); |
150 | goto ERROR3; |
162 | goto ERROR3; |
151 | } |
163 | } |
152 | psiconv_free_clipart_section(clipart); |
164 | psiconv_free_clipart_section(clipart); |
153 | } |
165 | } |
154 | psiconv_list_free((*result)->sections); |
166 | psiconv_list_free((*result)->sections); |
… | |
… | |
199 | if ((res = psiconv_parse_paint_data_section(config,buf,lev+3,*entry,NULL, |
211 | if ((res = psiconv_parse_paint_data_section(config,buf,lev+3,*entry,NULL, |
200 | 0,&paint))) |
212 | 0,&paint))) |
201 | goto ERROR4; |
213 | goto ERROR4; |
202 | if ((res = psiconv_list_add((*result)->sections,paint))) |
214 | if ((res = psiconv_list_add((*result)->sections,paint))) |
203 | goto ERROR5; |
215 | goto ERROR5; |
|
|
216 | free(paint); |
204 | } |
217 | } |
205 | |
218 | |
206 | psiconv_free_jumptable_section(table); |
219 | psiconv_free_jumptable_section(table); |
207 | psiconv_progress(config,lev+1,off,"End of mbm file"); |
220 | psiconv_progress(config,lev+1,off,"End of mbm file"); |
208 | return 0; |
221 | return 0; |
209 | ERROR5: |
222 | ERROR5: |
210 | psiconv_free_paint_data_section(paint); |
223 | psiconv_free_paint_data_section(paint); |
211 | ERROR4: |
224 | ERROR4: |
212 | for (i = 0; i < psiconv_list_length((*result)->sections); i++) { |
225 | for (i = 0; i < psiconv_list_length((*result)->sections); i++) { |
213 | if (!(paint = psiconv_list_get((*result)->sections,i))) { |
226 | if (!(paint = psiconv_list_get((*result)->sections,i))) { |
214 | psiconv_error(config,lev+1,off,"Massive memory corruption"); |
227 | psiconv_error(config,lev+1,off,"Data structure corruption"); |
215 | goto ERROR3; |
228 | goto ERROR3; |
216 | } |
229 | } |
217 | psiconv_free_paint_data_section(paint); |
230 | psiconv_free_paint_data_section(paint); |
218 | } |
231 | } |
219 | psiconv_list_free((*result)->sections); |
232 | psiconv_list_free((*result)->sections); |
… | |
… | |
291 | 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, |
292 | &appl_id))) |
305 | &appl_id))) |
293 | goto ERROR3; |
306 | goto ERROR3; |
294 | } |
307 | } |
295 | if ((appl_id->id != PSICONV_ID_SKETCH) || |
308 | if ((appl_id->id != PSICONV_ID_SKETCH) || |
296 | psiconv_unicode_strcmp(appl_id->name,unicode_paint)) { |
309 | !applid_matches(appl_id->name,"paint.app")) { |
297 | psiconv_warn(config,lev+2,applid_sec, |
310 | psiconv_warn(config,lev+2,applid_sec, |
298 | "Application ID section contains unexpected data"); |
311 | "Application ID section contains unexpected data"); |
299 | 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", |
300 | PSICONV_ID_SKETCH,appl_id->id); |
313 | PSICONV_ID_SKETCH,appl_id->id); |
301 | if (!(temp_str = psiconv_make_printable(config,appl_id->name))) |
314 | if (!(temp_str = psiconv_make_printable(config,appl_id->name))) |
… | |
… | |
410 | &appl_id))) |
423 | &appl_id))) |
411 | goto ERROR3; |
424 | goto ERROR3; |
412 | } |
425 | } |
413 | |
426 | |
414 | if ((appl_id->id != PSICONV_ID_TEXTED) || |
427 | if ((appl_id->id != PSICONV_ID_TEXTED) || |
415 | psiconv_unicode_strcmp(appl_id->name,unicode_texted)) { |
428 | !applid_matches(appl_id->name,"texted.app")) { |
416 | psiconv_warn(config,lev+2,applid_sec, |
429 | psiconv_warn(config,lev+2,applid_sec, |
417 | "Application ID section contains unexpected data"); |
430 | "Application ID section contains unexpected data"); |
418 | 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", |
419 | PSICONV_ID_TEXTED,appl_id->id); |
432 | PSICONV_ID_TEXTED,appl_id->id); |
420 | if (!(temp_str = psiconv_make_printable(config,appl_id->name))) |
433 | if (!(temp_str = psiconv_make_printable(config,appl_id->name))) |
… | |
… | |
593 | 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, |
594 | &appl_id))) |
607 | &appl_id))) |
595 | goto ERROR4; |
608 | goto ERROR4; |
596 | } |
609 | } |
597 | if ((appl_id->id != PSICONV_ID_WORD) || |
610 | if ((appl_id->id != PSICONV_ID_WORD) || |
598 | psiconv_unicode_strcmp(appl_id->name,unicode_word)) { |
611 | !applid_matches(appl_id->name,"word.app")) { |
599 | psiconv_warn(config,lev+2,applid_sec, |
612 | psiconv_warn(config,lev+2,applid_sec, |
600 | "Application ID section contains unexpected data"); |
613 | "Application ID section contains unexpected data"); |
601 | 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", |
602 | PSICONV_ID_WORD,appl_id->id); |
615 | PSICONV_ID_WORD,appl_id->id); |
603 | if (!(temp_str = psiconv_make_printable(config,appl_id->name))) |
616 | if (!(temp_str = psiconv_make_printable(config,appl_id->name))) |
… | |
… | |
789 | 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, |
790 | &appl_id))) |
803 | &appl_id))) |
791 | goto ERROR4; |
804 | goto ERROR4; |
792 | } |
805 | } |
793 | if ((appl_id->id != PSICONV_ID_SHEET) || |
806 | if ((appl_id->id != PSICONV_ID_SHEET) || |
794 | psiconv_unicode_strcmp(appl_id->name,unicode_sheet)) { |
807 | !applid_matches(appl_id->name,"sheet.app")) { |
795 | psiconv_warn(config,lev+2,applid_sec, |
808 | psiconv_warn(config,lev+2,applid_sec, |
796 | "Application ID section contains unexpected data"); |
809 | "Application ID section contains unexpected data"); |
797 | 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", |
798 | PSICONV_ID_SHEET,appl_id->id); |
811 | PSICONV_ID_SHEET,appl_id->id); |
799 | if (!(temp_str = psiconv_make_printable(config,appl_id->name))) |
812 | if (!(temp_str = psiconv_make_printable(config,appl_id->name))) |