--- psiconv/trunk/lib/psiconv/parse_driver.c 2000/12/15 17:17:45 66 +++ psiconv/trunk/lib/psiconv/parse_driver.c 2001/01/17 12:04:12 95 @@ -18,11 +18,12 @@ */ #include "config.h" +#include "compat.h" + #include #include "parse.h" #include "parse_routines.h" -#include "data.h" psiconv_file_type_t psiconv_file_type(psiconv_buffer buf,int *length, psiconv_header_section *result) @@ -72,6 +73,9 @@ else if ((*result)->type == psiconv_clipart_file) res = psiconv_parse_clipart_file(buf,lev+2,leng, (psiconv_clipart_f *)(&((*result)->file))); + else if ((*result)->type == psiconv_sheet_file) + res = psiconv_parse_sheet_file(buf,lev+2,leng, + (psiconv_sheet_f *)(&((*result)->file))); else { psiconv_warn(lev+1,off,"Can't parse this file yet!"); (*result)->file = NULL; @@ -646,7 +650,7 @@ psiconv_free_section_table_section(table); psiconv_progress(lev+1,off,"End of word file"); - return res; + return 0; ERROR8: @@ -668,5 +672,169 @@ if (res == 0) return -PSICONV_E_NOMEM; else + return res; +} + +int psiconv_parse_sheet_file(const psiconv_buffer buf,int lev, psiconv_u32 off, + psiconv_sheet_f *result) +{ + int res=0; + psiconv_section_table_section table; + psiconv_application_id_section appl_id; + char *temp_str; + psiconv_u32 pwd_sec = 0; + psiconv_u32 status_sec = 0; + psiconv_u32 page_sec = 0; + psiconv_u32 applid_sec = 0; + psiconv_u32 workbook_sec = 0; + psiconv_section_table_entry entry; + psiconv_u32 sto; + int i; + + psiconv_progress(lev+1,off,"Going to read a sheet file"); + if (!(*result = malloc(sizeof(**result)))) + goto ERROR1; + + psiconv_progress(lev+2,off, + "Going to read the offset of the section table section"); + sto = psiconv_read_u32(buf,lev+2,off,&res); + if (res) + goto ERROR2; + psiconv_debug(lev+2,off,"Offset: %08x",sto); + + psiconv_progress(lev+2,sto, + "Going to read the section table section"); + if ((res = psiconv_parse_section_table_section(buf,lev+2,sto, NULL,&table))) + goto ERROR2; + + for (i = 0; i < psiconv_list_length(table); i ++) { + psiconv_progress(lev+2,sto, "Going to read entry %d",i); + if (!(entry = psiconv_list_get(table,i))) + goto ERROR3; + 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_PAGE_LAYOUT_SECTION) { + page_sec = entry->offset; + psiconv_debug(lev+3,sto, + "Found the Page Layout section at %08x",page_sec); + } else if (entry->id == PSICONV_ID_PASSWORD_SECTION) { + pwd_sec = entry->offset; + psiconv_debug(lev+3,sto, + "Found the Password section at %08x",pwd_sec); + psiconv_warn(lev+3,sto, + "Password section found - can't read encrypted data"); + res = -PSICONV_E_PARSE; + goto ERROR3; + } else if (entry->id == PSICONV_ID_SHEET_WORKBOOK_SECTION) { + workbook_sec = entry->offset; + psiconv_debug(lev+3,sto, + "Found the Sheet Workbook section at %08x",workbook_sec); + } else if (entry->id == PSICONV_ID_SHEET_STATUS_SECTION) { + status_sec = entry->offset; + psiconv_debug(lev+3,sto, + "Found the Sheet Status section at %08x",status_sec); + } else { + psiconv_warn(lev+3,sto, + "Found unknown section in the Section Table (ignoring)"); + psiconv_debug(lev+3,sto, + "Section ID %08x, offset %08x",entry->id,entry->offset); + } + } + + + psiconv_progress(lev+2,sto, + "Looking for the Status section"); + if (!status_sec) { + psiconv_warn(lev+2,sto, "Status section not found in the section table"); + res = -PSICONV_E_PARSE; + goto ERROR3; + } else { + psiconv_debug(lev+2,sto, "Status section at offset %08x",status_sec); + if ((res = psiconv_parse_sheet_status_section(buf,lev+2,status_sec,NULL, + &((*result)->status_sec)))) + goto ERROR3; + } + + 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 = -PSICONV_E_PARSE; + goto ERROR4; + } else { + psiconv_debug(lev+2,sto, + "Application ID section at offset %08x",applid_sec); + if ((res = psiconv_parse_application_id_section(buf,lev+2,applid_sec,NULL, + &appl_id))) + goto ERROR4; + } + if ((appl_id->id != PSICONV_ID_SHEET) || + strcmp(appl_id->name,"Sheet.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_SHEET,appl_id->id); + if (!(temp_str = psiconv_make_printable(appl_id->name))) + goto ERROR5; + psiconv_debug(lev+2,applid_sec,"Name: `%s' expected, `%s' found", + "Sheet.app",temp_str); + free(temp_str); + res = -PSICONV_E_PARSE; + goto ERROR5; + } + + psiconv_progress(lev+2,sto, + "Looking for the Page layout section"); + if (! page_sec) { + psiconv_warn(lev+2,sto, + "Page layout section not found in the section table"); + res = -PSICONV_E_PARSE; + goto ERROR5; + } else { + psiconv_debug(lev+2,sto, + "Page layout section at offset %08x",page_sec); + if ((res = psiconv_parse_page_layout_section(buf,lev+2,page_sec,NULL, + &(*result)->page_sec))) + goto ERROR5; + } + + psiconv_progress(lev+2,sto, + "Looking for the Sheet Workbook section"); + if (! workbook_sec) { + psiconv_warn(lev+2,sto, + "Sheet workbook section not found in the section table"); + res = -PSICONV_E_PARSE; + goto ERROR6; + } else { + psiconv_debug(lev+2,sto, + "Sheet workbook section at offset %08x",page_sec); + if ((res = psiconv_parse_sheet_workbook_section(buf,lev+2,workbook_sec,NULL, + &(*result)->workbook_sec))) + goto ERROR6; + } + + psiconv_free_application_id_section(appl_id); + psiconv_free_section_table_section(table); + + psiconv_progress(lev+1,off,"End of Sheet file"); + return 0; + +ERROR6: + psiconv_free_page_layout_section((*result)->page_sec); +ERROR5: + psiconv_free_application_id_section(appl_id); +ERROR4: + psiconv_free_sheet_status_section((*result)->status_sec); +ERROR3: + psiconv_free_section_table_section(table); +ERROR2: + free(*result); +ERROR1: + psiconv_warn(lev+1,off,"Reading of Sheet File failed"); + if (res == 0) + return -PSICONV_E_NOMEM; + else return res; }