--- psiconv/trunk/lib/psiconv/parse_driver.c 2003/11/25 22:08:48 170 +++ psiconv/trunk/lib/psiconv/parse_driver.c 2004/02/09 23:12:58 208 @@ -1,6 +1,6 @@ /* parse_driver.c - Part of psiconv, a PSION 5 file formats converter - Copyright (c) 1999, 2000 Frodo Looijaard + Copyright (c) 1999-2004 Frodo Looijaard This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,11 +25,16 @@ #include "parse.h" #include "parse_routines.h" +#include "unicode.h" #ifdef DMALLOC #include #endif +static psiconv_ucs2 unicode_paint[10] = { 'P','a','i','n','t','.','a','p','p',0 }; +static psiconv_ucs2 unicode_texted[11] ={ 'T','e','x','t','E','d','.','a','p','p',0 }; +static psiconv_ucs2 unicode_word[9] = { 'W','o','r','d','.','a','p','p',0 }; +static psiconv_ucs2 unicode_sheet[10] = { 'S','h','e','e','t','.','a','p','p',0 }; psiconv_file_type_t psiconv_file_type(const psiconv_config config, psiconv_buffer buf,int *length, @@ -95,7 +100,7 @@ ERROR2: free(*result); ERROR1: - psiconv_warn(config,lev+1,off,"Reading of Psion File failed"); + psiconv_error(config,lev+1,off,"Reading of Psion File failed"); if (res == 0) return -PSICONV_E_NOMEM; else @@ -131,6 +136,7 @@ goto ERROR4; if ((res = psiconv_list_add((*result)->sections,clipart))) goto ERROR5; + free(clipart); } psiconv_free_jumptable_section(table); @@ -141,7 +147,7 @@ ERROR4: for (i = 0; i < psiconv_list_length((*result)->sections); i++) { if (!(clipart = psiconv_list_get((*result)->sections,i))) { - psiconv_warn(config,lev+1,off,"Massive memory corruption"); + psiconv_error(config,lev+1,off,"Massive memory corruption"); goto ERROR3; } psiconv_free_clipart_section(clipart); @@ -152,7 +158,7 @@ ERROR2: free(*result); ERROR1: - psiconv_warn(config,lev+1,off,"Reading of Clipart File failed"); + psiconv_error(config,lev+1,off,"Reading of Clipart File failed"); if (res == 0) return -PSICONV_E_NOMEM; else @@ -196,6 +202,7 @@ goto ERROR4; if ((res = psiconv_list_add((*result)->sections,paint))) goto ERROR5; + free(paint); } psiconv_free_jumptable_section(table); @@ -206,7 +213,7 @@ ERROR4: for (i = 0; i < psiconv_list_length((*result)->sections); i++) { if (!(paint = psiconv_list_get((*result)->sections,i))) { - psiconv_warn(config,lev+1,off,"Massive memory corruption"); + psiconv_error(config,lev+1,off,"Massive memory corruption"); goto ERROR3; } psiconv_free_paint_data_section(paint); @@ -217,7 +224,7 @@ ERROR2: free(*result); ERROR1: - psiconv_warn(config,lev+1,off,"Reading of MBM File failed"); + psiconv_error(config,lev+1,off,"Reading of MBM File failed"); if (res == 0) return -PSICONV_E_NOMEM; else @@ -276,7 +283,7 @@ psiconv_progress(config,lev+2,sto, "Looking for the Application ID section"); if (! applid_sec) { - psiconv_warn(config,lev+2,sto, + psiconv_error(config,lev+2,sto, "Application ID section not found in the section table"); res = -PSICONV_E_PARSE; goto ERROR3; @@ -288,12 +295,12 @@ goto ERROR3; } if ((appl_id->id != PSICONV_ID_SKETCH) || - strcmp(appl_id->name,"Paint.app")) { + psiconv_unicode_strcmp(appl_id->name,unicode_paint)) { psiconv_warn(config,lev+2,applid_sec, "Application ID section contains unexpected data"); psiconv_debug(config,lev+2,applid_sec,"ID: %08x expected, %08x found", PSICONV_ID_SKETCH,appl_id->id); - if (!(temp_str = psiconv_make_printable(appl_id->name))) + if (!(temp_str = psiconv_make_printable(config,appl_id->name))) goto ERROR4; psiconv_debug(config,lev+2,applid_sec,"Name: `%s' expected, `%s' found", "Paint.app",temp_str); @@ -327,7 +334,7 @@ ERROR2: free(*result); ERROR1: - psiconv_warn(config,lev+1,off,"Reading of Sketch File failed"); + psiconv_error(config,lev+1,off,"Reading of Sketch File failed"); if (res == 0) return -PSICONV_E_NOMEM; else @@ -394,7 +401,7 @@ psiconv_progress(config,lev+2,sto, "Looking for the Application ID section"); if (! applid_sec) { - psiconv_warn(config,lev+2,sto, + psiconv_error(config,lev+2,sto, "Application ID section not found in the section table"); res = -PSICONV_E_PARSE; goto ERROR3; @@ -405,13 +412,14 @@ &appl_id))) goto ERROR3; } + if ((appl_id->id != PSICONV_ID_TEXTED) || - strcmp(appl_id->name,"TextEd.app")) { + psiconv_unicode_strcmp(appl_id->name,unicode_texted)) { psiconv_warn(config,lev+2,applid_sec, "Application ID section contains unexpected data"); psiconv_debug(config,lev+2,applid_sec,"ID: %08x expected, %08x found", PSICONV_ID_TEXTED,appl_id->id); - if (!(temp_str = psiconv_make_printable(appl_id->name))) + if (!(temp_str = psiconv_make_printable(config,appl_id->name))) goto ERROR4; psiconv_debug(config,lev+2,applid_sec,"Name: `%s' expected, `%s' found", "TextEd.app",temp_str); @@ -423,7 +431,7 @@ psiconv_progress(config,lev+2,sto, "Looking for the Page layout section"); if (! page_sec) { - psiconv_warn(config,lev+2,sto, + psiconv_error(config,lev+2,sto, "Page layout section not found in the section table"); res = -PSICONV_E_PARSE; goto ERROR4; @@ -443,7 +451,7 @@ psiconv_progress(config,lev+2,sto, "Looking for the TextEd section"); if (! texted_sec) { - psiconv_warn(config,lev+2,sto, + psiconv_error(config,lev+2,sto, "TextEd section not found in the section table"); res = -PSICONV_E_PARSE; goto ERROR7; @@ -476,7 +484,7 @@ ERROR2: free(*result); ERROR1: - psiconv_warn(config,lev+1,off,"Reading of TextEd File failed"); + psiconv_error(config,lev+1,off,"Reading of TextEd File failed"); if (res == 0) return -PSICONV_E_NOMEM; else @@ -537,7 +545,7 @@ pwd_sec = entry->offset; psiconv_debug(config,lev+3,sto, "Found the Password section at %08x",pwd_sec); - psiconv_warn(config,lev+3,sto, + psiconv_error(config,lev+3,sto, "Password section found - can't read encrypted data"); res = -PSICONV_E_PARSE; goto ERROR3; @@ -565,7 +573,7 @@ psiconv_progress(config,lev+2,sto, "Looking for the Status section"); if (!status_sec) { - psiconv_warn(config,lev+2,sto, "Status section not found in the section table"); + psiconv_error(config,lev+2,sto, "Status section not found in the section table"); res = -PSICONV_E_PARSE; goto ERROR3; } else { @@ -577,7 +585,7 @@ psiconv_progress(config,lev+2,sto, "Looking for the Application ID section"); if (! applid_sec) { - psiconv_warn(config,lev+2,sto, + psiconv_error(config,lev+2,sto, "Application ID section not found in the section table"); res = -PSICONV_E_PARSE; goto ERROR4; @@ -589,12 +597,12 @@ goto ERROR4; } if ((appl_id->id != PSICONV_ID_WORD) || - strcmp(appl_id->name,"Word.app")) { + psiconv_unicode_strcmp(appl_id->name,unicode_word)) { psiconv_warn(config,lev+2,applid_sec, "Application ID section contains unexpected data"); psiconv_debug(config,lev+2,applid_sec,"ID: %08x expected, %08x found", PSICONV_ID_WORD,appl_id->id); - if (!(temp_str = psiconv_make_printable(appl_id->name))) + if (!(temp_str = psiconv_make_printable(config,appl_id->name))) goto ERROR5; psiconv_debug(config,lev+2,applid_sec,"Name: `%s' expected, `%s' found", "Word.app",temp_str); @@ -606,7 +614,7 @@ psiconv_progress(config,lev+2,sto, "Looking for the Page layout section"); if (! page_sec) { - psiconv_warn(config,lev+2,sto, + psiconv_error(config,lev+2,sto, "Page layout section not found in the section table"); res = -PSICONV_E_PARSE; goto ERROR5; @@ -621,7 +629,7 @@ psiconv_progress(config,lev+2,sto, "Looking for the Word Style section"); if (!styles_sec) { - psiconv_warn(config,lev+2,sto, + psiconv_error(config,lev+2,sto, "Word styles section not found in the section table"); res = -PSICONV_E_PARSE; goto ERROR6; @@ -636,7 +644,7 @@ psiconv_progress(config,lev+2,sto, "Looking for the Text section"); if (!text_sec) { - psiconv_warn(config,lev+2,sto, "Text section not found in the section table"); + psiconv_error(config,lev+2,sto, "Text section not found in the section table"); res = -PSICONV_E_PARSE; goto ERROR7; } else { @@ -681,7 +689,7 @@ ERROR2: free(*result); ERROR1: - psiconv_warn(config,lev+1,off,"Reading of Word File failed"); + psiconv_error(config,lev+1,off,"Reading of Word File failed"); if (res == 0) return -PSICONV_E_NOMEM; else @@ -737,7 +745,7 @@ pwd_sec = entry->offset; psiconv_debug(config,lev+3,sto, "Found the Password section at %08x",pwd_sec); - psiconv_warn(config,lev+3,sto, + psiconv_error(config,lev+3,sto, "Password section found - can't read encrypted data"); res = -PSICONV_E_PARSE; goto ERROR3; @@ -761,7 +769,7 @@ psiconv_progress(config,lev+2,sto, "Looking for the Status section"); if (!status_sec) { - psiconv_warn(config,lev+2,sto, "Status section not found in the section table"); + psiconv_error(config,lev+2,sto, "Status section not found in the section table"); res = -PSICONV_E_PARSE; goto ERROR3; } else { @@ -773,7 +781,7 @@ psiconv_progress(config,lev+2,sto, "Looking for the Application ID section"); if (! applid_sec) { - psiconv_warn(config,lev+2,sto, + psiconv_error(config,lev+2,sto, "Application ID section not found in the section table"); res = -PSICONV_E_PARSE; goto ERROR4; @@ -785,12 +793,12 @@ goto ERROR4; } if ((appl_id->id != PSICONV_ID_SHEET) || - strcmp(appl_id->name,"Sheet.app")) { + psiconv_unicode_strcmp(appl_id->name,unicode_sheet)) { psiconv_warn(config,lev+2,applid_sec, "Application ID section contains unexpected data"); psiconv_debug(config,lev+2,applid_sec,"ID: %08x expected, %08x found", PSICONV_ID_SHEET,appl_id->id); - if (!(temp_str = psiconv_make_printable(appl_id->name))) + if (!(temp_str = psiconv_make_printable(config,appl_id->name))) goto ERROR5; psiconv_debug(config,lev+2,applid_sec,"Name: `%s' expected, `%s' found", "Sheet.app",temp_str); @@ -802,7 +810,7 @@ psiconv_progress(config,lev+2,sto, "Looking for the Page layout section"); if (! page_sec) { - psiconv_warn(config,lev+2,sto, + psiconv_error(config,lev+2,sto, "Page layout section not found in the section table"); res = -PSICONV_E_PARSE; goto ERROR5; @@ -817,7 +825,7 @@ psiconv_progress(config,lev+2,sto, "Looking for the Sheet Workbook section"); if (! workbook_sec) { - psiconv_warn(config,lev+2,sto, + psiconv_error(config,lev+2,sto, "Sheet workbook section not found in the section table"); res = -PSICONV_E_PARSE; goto ERROR6; @@ -846,7 +854,7 @@ ERROR2: free(*result); ERROR1: - psiconv_warn(config,lev+1,off,"Reading of Sheet File failed"); + psiconv_error(config,lev+1,off,"Reading of Sheet File failed"); if (res == 0) return -PSICONV_E_NOMEM; else