--- psiconv/trunk/lib/psiconv/parse_driver.c 1999/10/13 19:15:59 17 +++ psiconv/trunk/lib/psiconv/parse_driver.c 1999/10/27 13:09:40 18 @@ -24,14 +24,21 @@ #include "parse_routines.h" #include "data.h" -psiconv_file_type_t psiconv_file_type(psiconv_buffer buf) +psiconv_file_type_t psiconv_file_type(psiconv_buffer buf,int *length, + psiconv_header_section *result) { psiconv_header_section header; psiconv_file_type_t res; + int leng; - psiconv_parse_header_section(buf,0,0,NULL,&header); + psiconv_parse_header_section(buf,0,0,&leng,&header); res = header->file; - psiconv_free_header_section(header); + if (result) + *result = header; + else + psiconv_free_header_section(header); + if (length) + *length = leng; return res; } @@ -40,22 +47,23 @@ int res=0; int lev=0; int off=0; + int leng; (*result) = malloc(sizeof(**result)); - (*result)->type = psiconv_file_type(buf); + (*result)->type = psiconv_file_type(buf,&leng,NULL); if ((*result)->type == psiconv_unknown_file) { psiconv_warn(lev+1,off,"Unknown file type: can't parse!"); (*result)->file = NULL; res = -1; } else if ((*result)->type == psiconv_word_file) - res = psiconv_parse_word_file(buf,lev+2,off, + res = psiconv_parse_word_file(buf,lev+2,leng, (psiconv_word_f *)(&((*result)->file))); else if ((*result)->type == psiconv_texted_file) - res = psiconv_parse_texted_file(buf,lev+2,off, + res = psiconv_parse_texted_file(buf,lev+2,leng, (psiconv_texted_f *)(&((*result)->file))); else if ((*result)->type == psiconv_mbm_file) - res = psiconv_parse_mbm_file(buf,lev+2,off, + res = psiconv_parse_mbm_file(buf,lev+2,leng, (psiconv_mbm_f *)(&((*result)->file))); else { psiconv_warn(lev+1,off,"Can't parse this file yet!"); @@ -73,19 +81,18 @@ int i; psiconv_mbm_jumptable_section table; psiconv_paint_data_section paint; - psiconv_header_section header; psiconv_u32 *entry; + psiconv_u32 sto; psiconv_progress(lev+1,off,"Going to read a mbm file"); *result = malloc(sizeof(**result)); - psiconv_progress(lev+2,off, "Going to read the header section"); - res |= psiconv_parse_header_section(buf,lev+2,off,NULL,&header); + psiconv_progress(lev+2,off,"Going to read the offset of the MBM jumptable"); + sto = psiconv_read_u32(buf,lev+2,off); + 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, - header->section_table_offset, - NULL,&table); + res |= psiconv_parse_mbm_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)); @@ -96,17 +103,16 @@ psiconv_list_add((*result)->sections,paint); } - psiconv_free_header_section(header); psiconv_free_mbm_jumptable_section(table); psiconv_progress(lev+1,off,"End of mbm file"); return res; } -int psiconv_parse_texted_file(const psiconv_buffer buf,int lev, psiconv_u32 off, +int psiconv_parse_texted_file(const psiconv_buffer buf,int lev, + psiconv_u32 off, psiconv_texted_f *result) { int res=0; - psiconv_header_section header; psiconv_section_table_section table; psiconv_application_id_section appl_id; char *temp_str; @@ -115,54 +121,51 @@ psiconv_u32 page_sec = 0; psiconv_u32 texted_sec = 0; psiconv_u32 applid_sec = 0; + psiconv_u32 sto; psiconv_section_table_entry entry; int i; psiconv_progress(lev+1,off,"Going to read a texted file"); *result = malloc(sizeof(**result)); - psiconv_progress(lev+2,off, "Going to read the header section"); - res |= psiconv_parse_header_section(buf,lev+2,off,NULL,&header); + psiconv_progress(lev+2,off,"Going to read the offset of the MBM jumptable"); + sto = psiconv_read_u32(buf,lev+2,off); + psiconv_debug(lev+2,off,"Offset: %08x",sto); - psiconv_progress(lev+2,header->section_table_offset, - "Going to read the section table section"); - res |= psiconv_parse_section_table_section(buf,lev+2, - header->section_table_offset, - NULL,&table); + 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,header->section_table_offset, - "Going to read entry %d",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,header->section_table_offset, + psiconv_debug(lev+3,sto, "Found the Application ID section at %08x",applid_sec); } else if (entry->id == PSICONV_ID_PAGE_LAYOUT_SECTION) { page_sec = entry->offset; - psiconv_debug(lev+3,header->section_table_offset, + psiconv_debug(lev+3,sto, "Found the Page Layout section at %08x",page_sec); } else if (entry->id == PSICONV_ID_TEXTED) { texted_sec = entry->offset; - psiconv_debug(lev+3,header->section_table_offset, + psiconv_debug(lev+3,sto, "Found the TextEd section at %08x",texted_sec); } else { - psiconv_warn(lev+3,header->section_table_offset, + psiconv_warn(lev+3,sto, "Found unknown section in the Section Table"); - psiconv_debug(lev+3,header->section_table_offset, + psiconv_debug(lev+3,sto, "Section ID %08x, offset %08x",entry->id,entry->offset); res = -1; } } - psiconv_progress(lev+2,header->section_table_offset, - "Looking for the Application ID section"); + psiconv_progress(lev+2,sto, "Looking for the Application ID section"); if (! applid_sec) { - psiconv_warn(lev+2,header->section_table_offset, + psiconv_warn(lev+2,sto, "Application ID section not found in the section table"); res = -1; } else { - psiconv_debug(lev+2,header->section_table_offset, + 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); @@ -179,15 +182,15 @@ free(temp_str); } - psiconv_progress(lev+2,header->section_table_offset, + psiconv_progress(lev+2,sto, "Looking for the Page layout section"); if (! page_sec) { - psiconv_warn(lev+2,header->section_table_offset, + psiconv_warn(lev+2,sto, "Page layout section not found in the section table"); (*result)->page_sec = NULL; res = -1; } else { - psiconv_debug(lev+2,header->section_table_offset, + psiconv_debug(lev+2,sto, "Page layout section at offset %08x",page_sec); res |= psiconv_parse_page_layout_section(buf,lev+2,page_sec,NULL, &(*result)->page_sec); @@ -196,16 +199,15 @@ base_char = psiconv_basic_character_layout(); base_para = psiconv_basic_paragraph_layout(); - psiconv_progress(lev+2,header->section_table_offset, + psiconv_progress(lev+2,sto, "Looking for the TextEd section"); if (! texted_sec) { - psiconv_warn(lev+2,header->section_table_offset, + psiconv_warn(lev+2,sto, "TextEd section not found in the section table"); (*result)->texted_sec = NULL; res = -1; } else { - psiconv_debug(lev+2,header->section_table_offset, - "TextEd section at offset %08x",texted_sec); + psiconv_debug(lev+2,sto, "TextEd section at offset %08x",texted_sec); res |= psiconv_parse_texted_section(buf,lev+2,texted_sec,NULL, &(*result)->texted_sec, base_char,base_para); @@ -214,7 +216,6 @@ psiconv_free_paragraph_layout(base_para); psiconv_free_application_id_section(appl_id); - psiconv_free_header_section(header); psiconv_free_section_table_section(table); psiconv_progress(lev+1,off,"End of word file"); @@ -225,7 +226,6 @@ psiconv_word_f *result) { int res=0; - psiconv_header_section header; psiconv_section_table_section table; psiconv_application_id_section appl_id; char *temp_str; @@ -237,86 +237,81 @@ psiconv_u32 layout_sec = 0; psiconv_u32 applid_sec = 0; psiconv_section_table_entry entry; + psiconv_u32 sto; int i; psiconv_progress(lev+1,off,"Going to read a word file"); *result = malloc(sizeof(**result)); - psiconv_progress(lev+2,off, "Going to read the header section"); - res |= psiconv_parse_header_section(buf,lev+2,off,NULL,&header); + psiconv_progress(lev+2,off,"Going to read the offset of the MBM jumptable"); + sto = psiconv_read_u32(buf,lev+2,off); + psiconv_debug(lev+2,off,"Offset: %08x",sto); - psiconv_progress(lev+2,header->section_table_offset, + psiconv_progress(lev+2,sto, "Going to read the section table section"); - res |= psiconv_parse_section_table_section(buf,lev+2, - header->section_table_offset, - NULL,&table); + 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,header->section_table_offset, - "Going to read entry %d",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,header->section_table_offset, + psiconv_debug(lev+3,sto, "Found the Application ID section at %08x",applid_sec); } else if (entry->id == PSICONV_ID_PAGE_LAYOUT_SECTION) { page_sec = entry->offset; - psiconv_debug(lev+3,header->section_table_offset, + psiconv_debug(lev+3,sto, "Found the Page Layout section at %08x",page_sec); } else if (entry->id == PSICONV_ID_TEXT_SECTION) { text_sec = entry->offset; - psiconv_debug(lev+3,header->section_table_offset, - "Found the Text section at %08x",text_sec); + psiconv_debug(lev+3,sto, "Found the Text section at %08x",text_sec); } else if (entry->id == PSICONV_ID_PASSWORD_SECTION) { pwd_sec = entry->offset; - psiconv_debug(lev+3,header->section_table_offset, + psiconv_debug(lev+3,sto, "Found the Password section at %08x",pwd_sec); - psiconv_warn(lev+3,header->section_table_offset, + psiconv_warn(lev+3,sto, "Password section found - can't read encrypted data"); res = -1; } else if (entry->id == PSICONV_ID_WORD_STATUS_SECTION) { status_sec = entry->offset; - psiconv_debug(lev+3,header->section_table_offset, + psiconv_debug(lev+3,sto, "Found the Word Status section at %08x",status_sec); } else if (entry->id == PSICONV_ID_WORD_STYLES_SECTION) { styles_sec = entry->offset; - psiconv_debug(lev+3,header->section_table_offset, + psiconv_debug(lev+3,sto, "Found the Word Styles section at %08x",styles_sec); } else if (entry->id == PSICONV_ID_LAYOUT_SECTION) { layout_sec = entry->offset; - psiconv_debug(lev+3,header->section_table_offset, + psiconv_debug(lev+3,sto, "Found the Layout section at %08x",layout_sec); } else { - psiconv_warn(lev+3,header->section_table_offset, + psiconv_warn(lev+3,sto, "Found unknown section in the Section Table"); - psiconv_debug(lev+3,header->section_table_offset, + psiconv_debug(lev+3,sto, "Section ID %08x, offset %08x",entry->id,entry->offset); res = -1; } } - psiconv_progress(lev+2,header->section_table_offset, + psiconv_progress(lev+2,sto, "Looking for the Status section"); if (!status_sec) { - psiconv_warn(lev+2,header->section_table_offset, - "Status section not found in the section table"); + psiconv_warn(lev+2,sto, "Status section not found in the section table"); res = -1; } else { - psiconv_debug(lev+2,header->section_table_offset, - "Status section at offset %08x",status_sec); + psiconv_debug(lev+2,sto, "Status section at offset %08x",status_sec); res |= psiconv_parse_word_status_section(buf,lev+2,status_sec,NULL, &((*result)->status_sec)); } - psiconv_progress(lev+2,header->section_table_offset, - "Looking for the Application ID section"); + psiconv_progress(lev+2,sto, "Looking for the Application ID section"); if (! applid_sec) { - psiconv_warn(lev+2,header->section_table_offset, + psiconv_warn(lev+2,sto, "Application ID section not found in the section table"); res = -1; } else { - psiconv_debug(lev+2,header->section_table_offset, + 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); @@ -333,69 +328,67 @@ free(temp_str); } - psiconv_progress(lev+2,header->section_table_offset, + psiconv_progress(lev+2,sto, "Looking for the Page layout section"); if (! page_sec) { - psiconv_warn(lev+2,header->section_table_offset, + psiconv_warn(lev+2,sto, "Page layout section not found in the section table"); (*result)->page_sec = NULL; res = -1; } else { - psiconv_debug(lev+2,header->section_table_offset, + psiconv_debug(lev+2,sto, "Page layout section at offset %08x",page_sec); res |= psiconv_parse_page_layout_section(buf,lev+2,page_sec,NULL, &(*result)->page_sec); } - psiconv_progress(lev+2,header->section_table_offset, + psiconv_progress(lev+2,sto, "Looking for the Word Style section"); if (!styles_sec) { - psiconv_warn(lev+2,header->section_table_offset, + psiconv_warn(lev+2,sto, "Word styles section not found in the section table"); (*result)->styles_sec = NULL; res = -1; } else { - psiconv_debug(lev+2,header->section_table_offset, + psiconv_debug(lev+2,sto, "Word styles section at offset %08x",styles_sec); res |= psiconv_parse_word_styles_section(buf,lev+2,styles_sec,NULL, &(*result)->styles_sec); } - psiconv_progress(lev+2,header->section_table_offset, + psiconv_progress(lev+2,sto, "Looking for the Text section"); if (!text_sec) { - psiconv_warn(lev+2,header->section_table_offset, - "Text section not found in the section table"); + psiconv_warn(lev+2,sto, "Text section not found in the section table"); (*result)->paragraphs = NULL; res = -1; } else { - psiconv_debug(lev+2,header->section_table_offset, + psiconv_debug(lev+2,sto, "Text section at offset %08x",text_sec); res |= psiconv_parse_text_section(buf,lev+2,text_sec,NULL, &(*result)->paragraphs); } if (((*result)->paragraphs) && ((*result)->styles_sec)) { - psiconv_progress(lev+2,header->section_table_offset, + psiconv_progress(lev+2,sto, "Looking for the Layout section"); if (!layout_sec) { - psiconv_debug(lev+2,header->section_table_offset, + psiconv_debug(lev+2,sto, "Layout section not found in the section table"); res = -1; } else { - psiconv_debug(lev+2,header->section_table_offset, + psiconv_debug(lev+2,sto, "Layout section at offset %08x",layout_sec); res |= psiconv_parse_styled_layout_section(buf,lev+2,layout_sec,NULL, (*result)->paragraphs, (*result)->styles_sec); } } else - psiconv_debug(lev+2,header->section_table_offset, + psiconv_debug(lev+2,sto, "Skipping search for Layout section, as either the " "text or the word styles section was not found"); psiconv_free_application_id_section(appl_id); - psiconv_free_header_section(header); psiconv_free_section_table_section(table); psiconv_progress(lev+1,off,"End of word file");