--- psiconv/trunk/lib/psiconv/parse_sheet.c 2001/01/17 00:05:08 94 +++ psiconv/trunk/lib/psiconv/parse_sheet.c 2001/01/22 20:36:50 97 @@ -182,3 +182,182 @@ return res; } +int psiconv_parse_sheet_workbook_section(const psiconv_buffer buf, int lev, + psiconv_u32 off, int *length, + psiconv_sheet_workbook_section *result) +{ + int res=0; + psiconv_u32 temp,formulas_off; + int len=0; + + psiconv_progress(lev+1,off,"Going to read the sheet workbook section"); + if (!(*result = malloc(sizeof(**result)))) + goto ERROR1; + + psiconv_progress(lev+2,off+len, + "Going to read the initial byte (%02x expected)",0x04); + temp = psiconv_read_u8(buf,lev+2,off+len,&res); + if (res) + goto ERROR2; + if (temp != 0x04) { + psiconv_warn(lev+2,off+len, + "Sheet workbook section initial byte unknown value (ignored)"); + psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); + } + len ++; + + psiconv_progress(lev+2,off+len, + "Going to read the offset of the 1st ??? Section"); + temp = psiconv_read_u32(buf,lev+2,off+len,&res); + if (res) + goto ERROR2; + psiconv_debug(lev+2,off+len,"Offset: %04x",temp); + len += 4; + + psiconv_progress(lev+2,off+len, + "Going to read the offset of the Formulas List"); + formulas_off = psiconv_read_u32(buf,lev+2,off+len,&res); + if (res) + goto ERROR2; + psiconv_debug(lev+2,off+len,"Offset: %04x",formulas_off); + len += 4; + + psiconv_progress(lev+2,off+len, + "Going to read the offset of the 3rd ??? Section"); + temp = psiconv_read_u32(buf,lev+2,off+len,&res); + if (res) + goto ERROR2; + psiconv_debug(lev+2,off+len,"Offset: %04x",temp); + len += 4; + + psiconv_progress(lev+2,off+len, + "Going to read the offset of the 4th ??? Section"); + temp = psiconv_read_u32(buf,lev+2,off+len,&res); + if (res) + goto ERROR2; + psiconv_debug(lev+2,off+len,"Offset: %04x",temp); + len += 4; + + psiconv_progress(lev+2,off+len,"Going to read the formulas list"); + if ((res = psiconv_parse_sheet_formula_list(buf,lev+2,formulas_off,NULL, + &(*result)->formulas))) + goto ERROR2; + + + if (length) + *length = len; + + psiconv_progress(lev,off+len-1, + "End of sheet workbook section (total length: %08x)", len); + return 0; + +ERROR2: + free (*result); +ERROR1: + psiconv_warn(lev+1,off,"Reading of Sheet Workbook Section failed"); + if (length) + *length = 0; + if (!res) + return -PSICONV_E_NOMEM; + else + return res; +} + +int psiconv_parse_sheet_formula(const psiconv_buffer buf, int lev, + psiconv_u32 off, int *length, + psiconv_sheet_formula *result) +{ + int res=0; + int len=0; + // int leng; + + psiconv_progress(lev+1,off,"Going to read a sheet formula"); + if (!(*result = malloc(sizeof(**result)))) + goto ERROR1; + + psiconv_progress(lev+2,off+len,"COP OUT: DOING NOTHING..."); + + if (length) + *length = len; + + psiconv_progress(lev,off+len-1, + "End of the sheet formula (total length: %08x)", len); + return 0; + +// ERROR2: + free(*result); +ERROR1: + psiconv_warn(lev+1,off,"Reading of Sheet Formula failed"); + if (length) + *length = 0; + if (!res) + return -PSICONV_E_NOMEM; + else + return res; +} + +int psiconv_parse_sheet_formula_list(const psiconv_buffer buf, int lev, + psiconv_u32 off, int *length, + psiconv_sheet_formula_list *result) +{ + int res=0; + int len=0; + psiconv_u32 temp; + psiconv_sheet_formula formula; + psiconv_u32 listlen,i; + int leng; + + psiconv_progress(lev+1,off,"Going to read the sheet formula table"); + if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_formula_s)))) + goto ERROR1; + + psiconv_progress(lev+2,off+len, + "Going to read the initial byte (%02x expected)",0x02); + temp = psiconv_read_u8(buf,lev+2,off+len,&res); + if (res) + goto ERROR2; + if (temp != 0x02) { + psiconv_warn(lev+2,off+len, + "Sheet formula table initial byte unknown value (ignored)"); + psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); + } + len ++; + + psiconv_progress(lev+2,off+len, + "Going to read the number of formulas"); + listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); + if (res) + goto ERROR2; + psiconv_debug(lev+2,off+len,"Number of formulas: %d",listlen); + len += leng; + + psiconv_progress(lev+2,off+len,"Going to read all formulas"); + for (i = 0; i < listlen; i++) { + psiconv_progress(lev+3,off+len,"Going to read formula %d",i); + if ((res = psiconv_parse_sheet_formula(buf,lev+3,off+len,&leng,&formula))) + goto ERROR2; + if ((res = psiconv_list_add(*result,formula))) + goto ERROR3; + len += leng; + } + + if (length) + *length = len; + + psiconv_progress(lev,off+len-1, + "End of sheet formula table (total length: %08x)", len); + return 0; + +ERROR3: + psiconv_free_sheet_formula(formula); +ERROR2: + psiconv_list_free(*result); +ERROR1: + psiconv_warn(lev+1,off,"Reading of Sheet Formula Table failed"); + if (length) + *length = 0; + if (!res) + return -PSICONV_E_NOMEM; + else + return res; +}