--- psiconv/trunk/lib/psiconv/parse_driver.c 2003/11/25 17:57:05 168 +++ psiconv/trunk/lib/psiconv/parse_driver.c 2005/11/15 15:52:34 270 @@ -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-2005 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,27 @@ #include "parse.h" #include "parse_routines.h" +#include "unicode.h" #ifdef DMALLOC #include #endif +/* Compare whether application id names match. + Sought must be lower case; the comparison is case insensitive */ +static psiconv_bool_t applid_matches(psiconv_string_t found, + const char *sought) +{ + int i; + if (psiconv_unicode_strlen(found) != strlen(sought)) + return psiconv_bool_false; + for (i = 0; i < strlen(sought); i++) + if ((found[i] != sought[i]) && + ((sought[i] < 'a') || (sought[i] > 'z') || + (found[i] != sought[i] + 'A' - 'a'))) + return psiconv_bool_false; + return psiconv_bool_true; +} psiconv_file_type_t psiconv_file_type(const psiconv_config config, psiconv_buffer buf,int *length, @@ -95,7 +111,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 +147,7 @@ goto ERROR4; if ((res = psiconv_list_add((*result)->sections,clipart))) goto ERROR5; + free(clipart); } psiconv_free_jumptable_section(table); @@ -141,7 +158,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,"Data structure corruption"); goto ERROR3; } psiconv_free_clipart_section(clipart); @@ -152,7 +169,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 +213,7 @@ goto ERROR4; if ((res = psiconv_list_add((*result)->sections,paint))) goto ERROR5; + free(paint); } psiconv_free_jumptable_section(table); @@ -206,7 +224,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,"Data structure corruption"); goto ERROR3; } psiconv_free_paint_data_section(paint); @@ -217,7 +235,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 +294,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 +306,12 @@ goto ERROR3; } if ((appl_id->id != PSICONV_ID_SKETCH) || - strcmp(appl_id->name,"Paint.app")) { + !applid_matches(appl_id->name,"paint.app")) { 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); @@ -317,7 +335,7 @@ psiconv_free_application_id_section(appl_id); psiconv_free_section_table_section(table); - psiconv_progress(config,lev+1,off,"End of word file"); + psiconv_progress(config,lev+1,off,"End of sketch file"); return res; ERROR4: @@ -327,7 +345,7 @@ ERROR2: free(*result); ERROR1: - psiconv_warn(config,lev+1,off,"Reading of Scketch File failed"); + psiconv_error(config,lev+1,off,"Reading of Sketch File failed"); if (res == 0) return -PSICONV_E_NOMEM; else @@ -394,7 +412,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 +423,14 @@ &appl_id))) goto ERROR3; } + if ((appl_id->id != PSICONV_ID_TEXTED) || - strcmp(appl_id->name,"TextEd.app")) { + !applid_matches(appl_id->name,"texted.app")) { 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 +442,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 +462,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 +495,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 +556,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 +584,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 +596,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 +608,12 @@ goto ERROR4; } if ((appl_id->id != PSICONV_ID_WORD) || - strcmp(appl_id->name,"Word.app")) { + !applid_matches(appl_id->name,"word.app")) { 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 +625,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 +640,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 +655,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 +700,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 +756,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 +780,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 +792,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 +804,12 @@ goto ERROR4; } if ((appl_id->id != PSICONV_ID_SHEET) || - strcmp(appl_id->name,"Sheet.app")) { + !applid_matches(appl_id->name,"sheet.app")) { 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 +821,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 +836,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 +865,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