--- psiconv/trunk/lib/psiconv/parse_driver.c 1999/10/27 13:09:40 18 +++ psiconv/trunk/lib/psiconv/parse_driver.c 2000/12/10 20:27:27 60 @@ -24,6 +24,8 @@ #include "parse_routines.h" #include "data.h" +int psiconv_verbosity = PSICONV_VERB_WARN; + psiconv_file_type_t psiconv_file_type(psiconv_buffer buf,int *length, psiconv_header_section *result) { @@ -65,6 +67,12 @@ else if ((*result)->type == psiconv_mbm_file) res = psiconv_parse_mbm_file(buf,lev+2,leng, (psiconv_mbm_f *)(&((*result)->file))); + else if ((*result)->type == psiconv_sketch_file) + res = psiconv_parse_sketch_file(buf,lev+2,leng, + (psiconv_sketch_f *)(&((*result)->file))); + else if ((*result)->type == psiconv_clipart_file) + res = psiconv_parse_clipart_file(buf,lev+2,leng, + (psiconv_clipart_f *)(&((*result)->file))); else { psiconv_warn(lev+1,off,"Can't parse this file yet!"); (*result)->file = NULL; @@ -74,12 +82,41 @@ return res; } +int psiconv_parse_clipart_file(const psiconv_buffer buf,int lev, + psiconv_u32 off, psiconv_clipart_f *result) +{ + int res=0; + int i; + psiconv_jumptable_section table; + psiconv_clipart_section clipart; + psiconv_u32 *entry; + + psiconv_progress(lev+1,off,"Going to read a clipart file"); + (*result) = malloc(sizeof(**result)); + + psiconv_progress(lev+2,off,"Going to read the MBM jumptable"); + res |= psiconv_parse_jumptable_section(buf,lev+2,off, NULL,&table); + + psiconv_progress(lev+2,off,"Going to read the clipart sections"); + (*result)->sections = psiconv_list_new(sizeof(*clipart)); + for (i = 0; i < psiconv_list_length(table); i ++) { + entry = psiconv_list_get(table,i); + psiconv_progress(lev+3,off,"Going to read clipart section %i",i); + psiconv_parse_clipart_section(buf,lev+3,*entry,NULL,&clipart); + psiconv_list_add((*result)->sections,clipart); + } + + psiconv_free_jumptable_section(table); + psiconv_progress(lev+1,off,"End of clipart file"); + return res; +} + int psiconv_parse_mbm_file(const psiconv_buffer buf,int lev, psiconv_u32 off, psiconv_mbm_f *result) { int res=0; int i; - psiconv_mbm_jumptable_section table; + psiconv_jumptable_section table; psiconv_paint_data_section paint; psiconv_u32 *entry; psiconv_u32 sto; @@ -92,22 +129,111 @@ psiconv_debug(lev+2,off,"Offset: %08x",sto); psiconv_progress(lev+2,off,"Going to read the MBM jumptable"); - res |= psiconv_parse_mbm_jumptable_section(buf,lev+2,sto, NULL,&table); + res |= psiconv_parse_jumptable_section(buf,lev+2,sto, NULL,&table); psiconv_progress(lev+2,off,"Going to read the picture sections"); (*result)->sections = psiconv_list_new(sizeof(*paint)); for (i = 0; i < psiconv_list_length(table); i ++) { entry = psiconv_list_get(table,i); psiconv_progress(lev+3,off,"Going to read picture section %i",i); - psiconv_parse_paint_data_section(buf,lev+3,*entry,NULL,&paint); + psiconv_parse_paint_data_section(buf,lev+3,*entry,NULL,0,&paint); psiconv_list_add((*result)->sections,paint); } - psiconv_free_mbm_jumptable_section(table); + psiconv_free_jumptable_section(table); psiconv_progress(lev+1,off,"End of mbm file"); return res; } +int psiconv_parse_sketch_file(const psiconv_buffer buf,int lev, + psiconv_u32 off, + psiconv_sketch_f *result) +{ + psiconv_section_table_section table; + psiconv_application_id_section appl_id; + psiconv_u32 applid_sec = 0; + psiconv_u32 sketch_sec = 0; + psiconv_u32 sto; + psiconv_section_table_entry entry; + int i; + int res=0; + char *temp_str; + + psiconv_progress(lev+1,off,"Going to read a sketch file"); + *result = malloc(sizeof(**result)); + + psiconv_progress(lev+2,off, + "Going to read the offset of the section table section"); + sto = psiconv_read_u32(buf,lev+2,off); + psiconv_debug(lev+2,off,"Offset: %08x",sto); + + psiconv_progress(lev+2,sto, "Going to read the section table section"); + res |= psiconv_parse_section_table_section(buf,lev+2,sto, NULL,&table); + + for (i = 0; i < psiconv_list_length(table); i ++) { + psiconv_progress(lev+2,sto, "Going to read entry %d",i); + entry = psiconv_list_get(table,i); + if (entry->id == PSICONV_ID_APPL_ID_SECTION) { + applid_sec = entry->offset; + psiconv_debug(lev+3,sto, + "Found the Application ID section at %08x",applid_sec); + } else if (entry->id == PSICONV_ID_SKETCH_SECTION) { + sketch_sec = entry->offset; + psiconv_debug(lev+3,sto, + "Found the Sketch section at %08x",sketch_sec); + } else { + psiconv_warn(lev+3,sto, + "Found unknown section in the Section Table"); + psiconv_debug(lev+3,sto, + "Section ID %08x, offset %08x",entry->id,entry->offset); + res = -1; + } + } + + psiconv_progress(lev+2,sto, "Looking for the Application ID section"); + if (! applid_sec) { + psiconv_warn(lev+2,sto, + "Application ID section not found in the section table"); + res = -1; + } else { + psiconv_debug(lev+2,sto, + "Application ID section at offset %08x",applid_sec); + res |= psiconv_parse_application_id_section(buf,lev+2,applid_sec,NULL, + &appl_id); + } + if ((appl_id->id != PSICONV_ID_SKETCH) || + strcmp(appl_id->name,"Paint.app")) { + psiconv_warn(lev+2,applid_sec, + "Application ID section contains unexpected data"); + psiconv_debug(lev+2,applid_sec,"ID: %08x expected, %08x found", + PSICONV_ID_SKETCH,appl_id->id); + temp_str = psiconv_make_printable(appl_id->name); + psiconv_debug(lev+2,applid_sec,"Name: `%s' expected, `%s' found", + "Paint.app",temp_str); + free(temp_str); + } + + psiconv_progress(lev+2,sto, "Looking for the Sketch section"); + if (! sketch_sec) { + psiconv_warn(lev+2,sto, + "Sketch section not found in the section table"); + res = -1; + } else { + psiconv_debug(lev+2,sto, + "Sketch section at offset %08x",applid_sec); + res |= psiconv_parse_sketch_section(buf,lev+2,sketch_sec,NULL,0, + &(*result)->sketch_sec); + } + + psiconv_free_application_id_section(appl_id); + psiconv_free_section_table_section(table); + + psiconv_progress(lev+1,off,"End of word file"); + return res; +} + + + int psiconv_parse_texted_file(const psiconv_buffer buf,int lev, psiconv_u32 off, psiconv_texted_f *result) @@ -128,7 +254,8 @@ psiconv_progress(lev+1,off,"Going to read a texted file"); *result = malloc(sizeof(**result)); - psiconv_progress(lev+2,off,"Going to read the offset of the MBM jumptable"); + psiconv_progress(lev+2,off, + "Going to read the offset of the section table section"); sto = psiconv_read_u32(buf,lev+2,off); psiconv_debug(lev+2,off,"Offset: %08x",sto); @@ -178,7 +305,7 @@ PSICONV_ID_TEXTED,appl_id->id); temp_str = psiconv_make_printable(appl_id->name); psiconv_debug(lev+2,applid_sec,"Name: `%s' expected, `%s' found", - PSICONV_ID_TEXTED,temp_str); + "TextEd.app",temp_str); free(temp_str); } @@ -243,7 +370,8 @@ psiconv_progress(lev+1,off,"Going to read a word file"); *result = malloc(sizeof(**result)); - psiconv_progress(lev+2,off,"Going to read the offset of the MBM jumptable"); + psiconv_progress(lev+2,off, + "Going to read the offset of the section table section"); sto = psiconv_read_u32(buf,lev+2,off); psiconv_debug(lev+2,off,"Offset: %08x",sto); @@ -324,7 +452,7 @@ PSICONV_ID_WORD,appl_id->id); temp_str = psiconv_make_printable(appl_id->name); psiconv_debug(lev+2,applid_sec,"Name: `%s' expected, `%s' found", - PSICONV_ID_WORD,temp_str); + "Word.app",temp_str); free(temp_str); }