--- psiconv/trunk/lib/psiconv/parse_sheet.c 2001/01/17 12:04:12 95 +++ psiconv/trunk/lib/psiconv/parse_sheet.c 2001/07/01 20:40:52 122 @@ -25,6 +25,176 @@ #include "parse_routines.h" #include "error.h" +static psiconv_sheet_cell_layout psiconv_basic_cell_layout(void) +{ + psiconv_sheet_cell_layout result; + if (!(result = malloc(sizeof(*result)))) + goto ERROR1; + if (!(result->character = psiconv_basic_character_layout())) + goto ERROR2; + if (!(result->paragraph = psiconv_basic_paragraph_layout())) + goto ERROR3; + if (!(result->numberformat = malloc(sizeof(*result->numberformat)))) + goto ERROR4; + result->numberformat->code = psiconv_numberformat_general; + result->numberformat->decimal = 2; + return result; +ERROR4: + psiconv_free_paragraph_layout(result->paragraph); +ERROR3: + psiconv_free_character_layout(result->character); +ERROR2: + free(result); +ERROR1: + return NULL; +} + +static psiconv_sheet_cell_layout psiconv_clone_cell_layout + (psiconv_sheet_cell_layout original) +{ + psiconv_sheet_cell_layout result; + if (!(result = malloc(sizeof(*result)))) + goto ERROR1; + if (!(result->character = + psiconv_clone_character_layout(original->character))) + goto ERROR2; + if (!(result->paragraph = + psiconv_clone_paragraph_layout(original->paragraph))) + goto ERROR3; + if (!(result->numberformat = malloc(sizeof(*result->numberformat)))) + goto ERROR4; + result->numberformat->code = original->numberformat->code; + result->numberformat->decimal = original->numberformat->decimal; + return result; +ERROR4: + psiconv_free_paragraph_layout(result->paragraph); +ERROR3: + psiconv_free_character_layout(result->character); +ERROR2: + free(result); +ERROR1: + return NULL; +} + +int psiconv_parse_sheet_numberformat(const psiconv_buffer buf, int lev, + psiconv_u32 off, int *length, + psiconv_sheet_numberformat result) +{ + int res=0; + int len=0; + psiconv_u8 temp; + + psiconv_progress(lev+1,off,"Going to read a sheet numberformat"); + + 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 ERROR1; + if (temp != 0x02) { + psiconv_warn(lev+2,off+len, + "Sheet numberformat 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 code byte"); + temp = psiconv_read_u8(buf,lev+2,off+len,&res); + if (res) + goto ERROR1; + psiconv_debug(lev+2,off+len,"Code: %02x",temp); + if (temp == 0x00) + result->code = psiconv_numberformat_general; + else if (temp == 0x02) + result->code = psiconv_numberformat_fixeddecimal; + else if (temp == 0x04) + result->code = psiconv_numberformat_scientific; + else if (temp == 0x06) + result->code = psiconv_numberformat_currency; + else if (temp == 0x08) + result->code = psiconv_numberformat_percent; + else if (temp == 0x0A) + result->code = psiconv_numberformat_triads; + else if (temp == 0x0C) + result->code = psiconv_numberformat_boolean; + else if (temp == 0x0E) + result->code = psiconv_numberformat_text; + else if (temp == 0x10) + result->code = psiconv_numberformat_date_dmm; + else if (temp == 0x12) + result->code = psiconv_numberformat_date_mmd; + else if (temp == 0x14) + result->code = psiconv_numberformat_date_ddmmyy; + else if (temp == 0x16) + result->code = psiconv_numberformat_date_mmddyy; + else if (temp == 0x18) + result->code = psiconv_numberformat_date_yymmdd; + else if (temp == 0x1A) + result->code = psiconv_numberformat_date_dmmm; + else if (temp == 0x1C) + result->code = psiconv_numberformat_date_dmmmyy; + else if (temp == 0x1E) + result->code = psiconv_numberformat_date_ddmmmyy; + else if (temp == 0x20) + result->code = psiconv_numberformat_date_mmm; + else if (temp == 0x22) + result->code = psiconv_numberformat_date_monthname; + else if (temp == 0x24) + result->code = psiconv_numberformat_date_mmmyy; + else if (temp == 0x26) + result->code = psiconv_numberformat_date_monthnameyy; + else if (temp == 0x28) + result->code = psiconv_numberformat_date_monthnamedyyyy; + else if (temp == 0x2A) + result->code = psiconv_numberformat_datetime_ddmmyyyyhhii; + else if (temp == 0x2C) + result->code = psiconv_numberformat_datetime_ddmmyyyyHHii; + else if (temp == 0x2E) + result->code = psiconv_numberformat_datetime_mmddyyyyhhii; + else if (temp == 0x30) + result->code = psiconv_numberformat_datetime_mmddyyyyHHii; + else if (temp == 0x32) + result->code = psiconv_numberformat_datetime_yyyymmddhhii; + else if (temp == 0x34) + result->code = psiconv_numberformat_datetime_yyyymmddHHii; + else if (temp == 0x36) + result->code = psiconv_numberformat_time_hhii; + else if (temp == 0x38) + result->code = psiconv_numberformat_time_hhiiss; + else if (temp == 0x3A) + result->code = psiconv_numberformat_time_HHii; + else if (temp == 0x3C) + result->code = psiconv_numberformat_time_HHiiss; + else { + psiconv_warn(lev+2,off+len,"Unknown number format (assumed general)"); + result->code = psiconv_numberformat_general; + } + len ++; + + psiconv_progress(lev+2,off+len, "Going to read the number of decimals"); + result->decimal = psiconv_read_u8(buf,lev+2,off+len,&res) >> 1; + if (res) + goto ERROR1; + psiconv_debug(lev+2,off+len,"Decimals: %d",result->decimal); + len ++; + + if (length) + *length = len; + + psiconv_progress(lev,off+len-1, + "End of sheet number format (total length: %08x)", len); + return 0; + +ERROR1: + psiconv_warn(lev+1,off,"Reading of Sheet Number Format failed"); + if (length) + *length = 0; + if (!res) + return -PSICONV_E_NOMEM; + else + return res; +} + int psiconv_parse_sheet_status_section(const psiconv_buffer buf, int lev, psiconv_u32 off, int *length, psiconv_sheet_status_section *result) @@ -173,7 +343,7 @@ ERROR2: free (*result); ERROR1: - psiconv_warn(lev+1,off,"Reading of Sjeet Status Section failed"); + psiconv_warn(lev+1,off,"Reading of Sheet Status Section failed"); if (length) *length = 0; if (!res) @@ -187,7 +357,7 @@ psiconv_sheet_workbook_section *result) { int res=0; - psiconv_u32 temp; + psiconv_u32 temp,formulas_off,worksheets_off; int len=0; psiconv_progress(lev+1,off,"Going to read the sheet workbook section"); @@ -215,19 +385,19 @@ len += 4; psiconv_progress(lev+2,off+len, - "Going to read the offset of the 2nd ??? Section"); - temp = psiconv_read_u32(buf,lev+2,off+len,&res); + "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",temp); + 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); + "Going to read the offset of the Worksheet List"); + worksheets_off = psiconv_read_u32(buf,lev+2,off+len,&res); if (res) goto ERROR2; - psiconv_debug(lev+2,off+len,"Offset: %04x",temp); + psiconv_debug(lev+2,off+len,"Offset: %04x",worksheets_off); len += 4; psiconv_progress(lev+2,off+len, @@ -238,6 +408,17 @@ 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_table(buf,lev+2,formulas_off,NULL, + &(*result)->formulas))) + goto ERROR2; + + psiconv_progress(lev+2,off+len,"Going to read the worksheet list"); + if ((res = psiconv_parse_sheet_worksheet_list(buf,lev+2,worksheets_off, + NULL,&(*result)->worksheets))) + goto ERROR2; + + if (length) *length = len; @@ -256,3 +437,584 @@ else return res; } + +int psiconv_parse_sheet_formula_table(const psiconv_buffer buf, int lev, + psiconv_u32 off, int *length, + psiconv_formula_list *result) +{ + int res=0; + int len=0; + psiconv_u32 temp; + psiconv_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_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_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_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; +} + +int psiconv_parse_sheet_cell(const psiconv_buffer buf, int lev, + psiconv_u32 off, int *length, + psiconv_sheet_cell *result, + const psiconv_sheet_cell_layout default_layout) +{ + int res=0; + int len=0; + psiconv_u32 temp; + psiconv_bool_t has_layout; + int leng; + + psiconv_progress(lev+1,off,"Going to read a sheet cell structure"); + if (!(*result = malloc(sizeof(**result)))) + goto ERROR1; + + (*result)->layout = NULL; + (*result)->type = psiconv_cell_blank; + + psiconv_progress(lev+2,off+len,"Going to read the cell position"); + temp = psiconv_read_u8(buf,lev+2,off+len,&res); + if (res) + goto ERROR2; + len ++; + temp += psiconv_read_u8(buf,lev+2,off+len,&res) << 8; + if (res) + goto ERROR2; + len ++; + temp += psiconv_read_u8(buf,lev+2,off+len,&res) << 16; + if (res) + goto ERROR2; + len ++; + (*result)->column = (temp >> 2) & 0xFF; + (*result)->row = (temp >> 10) & 0x3FFF; + psiconv_debug(lev+2,off+len,"Cell position is col:%02x row:%04x", + (*result)->column,(*result)->row); + if (temp & 0x03) { + psiconv_warn(lev+2,off+len,"Unknown flags in cell position (ignored)"); + psiconv_debug(lev+2,off+len,"Flags: %02x",temp & 0x03); + } + + psiconv_progress(lev+2,off+len,"Going to read the cell type"); + temp = psiconv_read_u8(buf,lev+2,off+len,&res); + if (res) + goto ERROR2; + len ++; + (*result)->type = (temp >> 5) & 0x07; + (*result)->calculated = (temp & 0x08)?psiconv_bool_true:psiconv_bool_false; + has_layout = (temp & 0x10)?psiconv_bool_true:psiconv_bool_false; + + psiconv_progress(lev+2,off+len,"Going to read the cell value"); + if ((*result)->type == psiconv_cell_blank) { + psiconv_debug(lev+2,off+len,"Cell type is blank: no value given."); + } else if ((*result)->type == psiconv_cell_int) { + psiconv_progress(lev+2,off+len,"Going to read an integer"); + (*result)->data.dat_int = psiconv_read_u32(buf,lev+2,off+len,&res); + if (res) + goto ERROR2; + len += 4; + psiconv_debug(lev+2,off+len,"Cell contents: %ld",(*result)->data.dat_int); + + } else if ((*result)->type == psiconv_cell_bool) { + psiconv_progress(lev+2,off+len,"Going to read a boolean"); + if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng, + &(*result)->data.dat_bool))) + goto ERROR2; + psiconv_debug(lev+2,off+len,"Cell contents: %01x",temp); + (*result)->data.dat_bool = temp?psiconv_bool_true:psiconv_bool_false; + len += leng; + } else if ((*result)->type == psiconv_cell_error) { + psiconv_progress(lev+2,off+len,"Going to read the error code"); + temp = psiconv_read_u16(buf,lev+2,off+len,&res); + if (res) + goto ERROR2; + if (temp == 0) + (*result)->data.dat_error = psiconv_sheet_error_none; + else if (temp == 1) + (*result)->data.dat_error = psiconv_sheet_error_null; + else if (temp == 2) + (*result)->data.dat_error = psiconv_sheet_error_divzero; + else if (temp == 3) + (*result)->data.dat_error = psiconv_sheet_error_value; + else if (temp == 4) + (*result)->data.dat_error = psiconv_sheet_error_reference; + else if (temp == 5) + (*result)->data.dat_error = psiconv_sheet_error_name; + else if (temp == 6) + (*result)->data.dat_error = psiconv_sheet_error_number; + else if (temp == 7) + (*result)->data.dat_error = psiconv_sheet_error_notavail; + else { + psiconv_warn(lev+2,off+len,"Unknown error code (default assumed)"); + psiconv_debug(lev+2,off+len,"Error code: %04x",temp); + (*result)->data.dat_error = psiconv_sheet_error_none; + } + psiconv_debug(lev+2,off+len,"Cell contents: %04x", + (*result)->data.dat_error); + len += 2; + } else if ((*result)->type == psiconv_cell_float) { + psiconv_progress(lev+2,off+len,"Going to read a float"); + (*result)->data.dat_float = + psiconv_read_float(buf,lev+2,off+len,&leng,&res); + if (res) + goto ERROR2; + psiconv_debug(lev+2,off+len,"Cell contents: %f",(*result)->data.dat_float); + len += leng; + } else if ((*result)->type == psiconv_cell_string) { + psiconv_progress(lev+2,off+len,"Going to read a string"); + (*result)->data.dat_string = + psiconv_read_string(buf,lev+2,off+len,&leng,&res); + if (res) + goto ERROR2; + psiconv_debug(lev+2,off+len,"Cell contents: `%s'", + (*result)->data.dat_string); + len += leng; + } else { + psiconv_warn(lev+2,off+len,"Unknown Sheet Cell type: %02x",(*result)->type); + res = PSICONV_E_PARSE; + goto ERROR2; + } + + if (!((*result)->layout = psiconv_clone_cell_layout(default_layout))) + goto ERROR2; + if (has_layout) { + if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len, + &leng,(*result)->layout))) + goto ERROR2; + len += leng; + } + + if ((*result)->calculated) { + psiconv_progress(lev+2,off+len,"Going to read the cell formula reference"); + temp = psiconv_read_X(buf,lev+2,off+len,&leng,&res); + if (res) + goto ERROR2; + psiconv_debug(lev+2,off+len,"Cell formula reference: %d",temp); + len += leng; + (*result)->ref_formula = temp; + } + + if (length) + *length = len; + + psiconv_progress(lev,off+len-1, + "End of sheet cell structure (total length: %08x)", len); + return 0; + +ERROR2: + psiconv_free_sheet_cell(*result); +ERROR1: + psiconv_warn(lev+1,off,"Reading of Sheet Cell Structure failed"); + if (length) + *length = 0; + if (!res) + return -PSICONV_E_NOMEM; + else + return res; +} + +int psiconv_parse_sheet_cell_list(const psiconv_buffer buf, int lev, + psiconv_u32 off, int *length, + psiconv_sheet_cell_list *result, + const psiconv_sheet_cell_layout default_layout) +{ + int res=0; + int len=0; + psiconv_u32 temp; + psiconv_sheet_cell cell; + psiconv_u32 listlen,i; + int leng; + + psiconv_progress(lev+1,off,"Going to read the sheet cell list"); + if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_cell_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 cell list 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 initial byte (%02x expected)",0x00); + temp = psiconv_read_u8(buf,lev+2,off+len,&res); + if (res) + goto ERROR2; + if (temp != 0x00) { + psiconv_warn(lev+2,off+len, + "Sheet cell list 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 defined cells"); + listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); + if (res) + goto ERROR2; + psiconv_debug(lev+2,off+len,"Number of defined cells: %d",listlen); + len += leng; + + psiconv_progress(lev+2,off+len,"Going to read all cells"); + for (i = 0; i < listlen; i++) { + psiconv_progress(lev+3,off+len,"Going to read cell %d",i); + if ((res = psiconv_parse_sheet_cell(buf,lev+3,off+len,&leng,&cell, + default_layout))) + goto ERROR2; + if ((res = psiconv_list_add(*result,cell))) + goto ERROR3; + free(cell); + len += leng; + } + + if (length) + *length = len; + + psiconv_progress(lev,off+len-1, + "End of sheet cell list (total length: %08x)", len); + return 0; + +ERROR3: + psiconv_free_sheet_cell(cell); +ERROR2: + psiconv_free_sheet_cell_list(*result); +ERROR1: + psiconv_warn(lev+1,off,"Reading of Sheet Cells List failed"); + if (length) + *length = 0; + if (!res) + return -PSICONV_E_NOMEM; + else + return res; +} + + +int psiconv_parse_sheet_worksheet_list( const psiconv_buffer buf, int lev, + psiconv_u32 off, int *length, + psiconv_sheet_worksheet_list *result) +{ + psiconv_sheet_worksheet worksheet; + int res=0; + int len=0; + psiconv_u8 temp; + psiconv_u32 offset; + int leng,i,nr; + + psiconv_progress(lev+1,off,"Going to read the worksheet list"); + if (!(*result = psiconv_list_new(sizeof(*worksheet)))) + goto ERROR1; + + psiconv_progress(lev+2,off+len, + "Going to read the initial bytes (%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 worksheet list 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 list length"); + nr = psiconv_read_X(buf,lev+2,off+len,&leng,&res); + if (res) + goto ERROR2; + psiconv_debug(lev+2,off+len,"Length: %02x",nr); + len += leng; + + psiconv_progress(lev+2,off+len,"Going to read the list"); + for (i=0 ; i < nr; i++) { + psiconv_progress(lev+3,off+len,"Going to read element %d",i); + psiconv_progress(lev+4,off+len, + "Going to read the initial byte (%02x expected)",0x00); + temp = psiconv_read_u8(buf,lev+4,off+len,&res); + if (res) + goto ERROR2; + if (temp != 0x00) { + psiconv_warn(lev+4,off+len, + "Sheet worksheet element initial byte unknown value (ignored)"); + psiconv_debug(lev+4,off+len,"Initial byte: %02x",temp); + } + len ++; + + psiconv_progress(lev+4,off+len,"Going to read the worksheet offset"); + offset = psiconv_read_u32(buf,lev+2,off+len,&res); + if (res) + goto ERROR2; + psiconv_debug(lev+4,off+len,"Offset: %08x",offset); + len += 4; + + if ((res = psiconv_parse_sheet_worksheet(buf,lev+4,offset,NULL, + &worksheet))) + goto ERROR2; + if ((res = psiconv_list_add(*result,worksheet))) + goto ERROR3; + free(worksheet); + } + + if (length) + *length = len; + + psiconv_progress(lev,off+len-1, + "End of worksheet list (total length: %08x)", len); + + return 0; + +ERROR3: + psiconv_free_sheet_worksheet(worksheet); +ERROR2: + psiconv_free_sheet_worksheet_list(*result); +ERROR1: + psiconv_warn(lev+1,off,"Reading of worksheet list failed"); + if (length) + *length = 0; + if (!res) + return -PSICONV_E_NOMEM; + else + return res; +} + +int psiconv_parse_sheet_cell_layout(const psiconv_buffer buf, int lev, + psiconv_u32 off, int *length, + psiconv_sheet_cell_layout result) + +{ + int res=0; + int len=0; + int leng; + psiconv_u8 temp; + + psiconv_progress(lev+1,off,"Going to read a sheet cell layout"); + + psiconv_progress(lev+2,off+len, + "Going to read the first byte (%02x expected)",0x02); + temp = psiconv_read_u8(buf,lev+2,off+len,&res); + if (res) + goto ERROR1; + if (temp != 0x02) { + psiconv_warn(lev+2,off+len, + "Worksheet 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 default formats flag"); + temp = psiconv_read_u8(buf,lev+2,off+len,&res); + if (res) + goto ERROR1; + len ++; + + if (temp & 0x01) { + psiconv_progress(lev+3,off+len,"Going to read the default paragraph codes"); + if ((res = psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng, + result->paragraph))) + goto ERROR1; + len += leng; + } + + if (temp & 0x02) { + psiconv_progress(lev+3,off+len,"Going to read the default character codes"); + if ((res = psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng, + result->character))) + goto ERROR1; + len += leng; + } + + if (temp & 0x04) { + psiconv_progress(lev+3,off+len, "Going to read the default number format"); + psiconv_parse_sheet_numberformat(buf,lev+3,off+len,&leng, + result->numberformat); + len += leng; + } + + if (length) + *length = len; + + psiconv_progress(lev,off+len-1, + "End of sheet cell layout (total length: %08x)", len); + + return 0; + +ERROR1: + psiconv_warn(lev+1,off,"Reading of sheet cell layout failed"); + if (length) + *length = 0; + if (!res) + return -PSICONV_E_NOMEM; + else + return res; +} + + +int psiconv_parse_sheet_worksheet(const psiconv_buffer buf, int lev, + psiconv_u32 off, int *length, + psiconv_sheet_worksheet *result) +{ + int res=0; + psiconv_u32 temp,cells_off,grid_off; + int len=0; + int leng; + + psiconv_progress(lev+1,off,"Going to read the sheet worksheet section"); + if (!(*result = malloc(sizeof(**result)))) + goto ERROR1; + + psiconv_progress(lev+2,off+len, + "Going to read the initial bytes (%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, + "Worksheet 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 flags byte"); + temp = psiconv_read_u8(buf,lev+2,off+len,&res); + if (res) + goto ERROR2; + psiconv_debug(lev+2,off+len,"Flags byte: %02x",temp); + (*result)->show_zeros = (temp & 0x01)?psiconv_bool_true:psiconv_bool_false; + if (temp & 0xfe) { + psiconv_warn(lev+2,off+len, + "Worksheet section flags byte unknown bits (ignored)"); + } + len ++; + + psiconv_progress(lev+2,off+len,"Going to read the default cell layout"); + if (!((*result)->default_layout = psiconv_basic_cell_layout())) + goto ERROR2; + if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len,&leng, + (*result)->default_layout))) + goto ERROR3; + len += leng; + + 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 ERROR3; + psiconv_debug(lev+2,off+len,"Offset: %04x",temp); + len += 4; + + psiconv_progress(lev+2,off+len, + "Going to read the offset of the 2nd ??? Section"); + temp = psiconv_read_u32(buf,lev+2,off+len,&res); + if (res) + goto ERROR3; + psiconv_debug(lev+2,off+len,"Offset: %04x",temp); + len += 4; + + psiconv_progress(lev+2,off+len, + "Going to read the offset of the Cells List"); + cells_off = psiconv_read_u32(buf,lev+2,off+len,&res); + if (res) + goto ERROR3; + psiconv_debug(lev+2,off+len,"Offset: %04x",cells_off); + len += 4; + + psiconv_progress(lev+2,off+len, + "Going to read the offset of the Grid Section"); + grid_off = psiconv_read_u32(buf,lev+2,off+len,&res); + if (res) + goto ERROR3; + psiconv_debug(lev+2,off+len,"Offset: %04x",grid_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 ERROR3; + psiconv_debug(lev+2,off+len,"Offset: %04x",temp); + len += 4; + + psiconv_progress(lev+2,off+len,"Going to read the cells list"); + if ((res = psiconv_parse_sheet_cell_list(buf,lev+2,cells_off,NULL, + &(*result)->cells, + (*result)->default_layout))) + goto ERROR3; + + +/* TODO: parse grid section */ + + if (length) + *length = len; + + psiconv_progress(lev,off+len-1, + "End of sheet worksheet section (total length: %08x)", len); + return 0; + +ERROR3: + psiconv_free_sheet_cell_layout((*result)->default_layout); +ERROR2: + free (*result); +ERROR1: + psiconv_warn(lev+1,off,"Reading of Sheet Worksheet Section failed"); + if (length) + *length = 0; + if (!res) + return -PSICONV_E_NOMEM; + else + return res; +} + +