--- psiconv/trunk/lib/psiconv/parse_sheet.c 2001/07/01 20:40:52 122 +++ psiconv/trunk/lib/psiconv/parse_sheet.c 2001/07/18 12:24:08 128 @@ -507,7 +507,9 @@ 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) + const psiconv_sheet_cell_layout default_layout, + const psiconv_sheet_line_list row_default_layouts, + const psiconv_sheet_line_list col_default_layouts) { int res=0; int len=0; @@ -624,7 +626,12 @@ goto ERROR2; } - if (!((*result)->layout = psiconv_clone_cell_layout(default_layout))) + if (!((*result)->layout = psiconv_clone_cell_layout( + psiconv_get_default_layout(row_default_layouts, + col_default_layouts, + default_layout, + (*result)->row, + (*result)->column)))) goto ERROR2; if (has_layout) { if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len, @@ -663,9 +670,11 @@ } 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) + psiconv_u32 off, int *length, + psiconv_sheet_cell_list *result, + const psiconv_sheet_cell_layout default_layout, + const psiconv_sheet_line_list row_default_layouts, + const psiconv_sheet_line_list col_default_layouts) { int res=0; int len=0; @@ -714,7 +723,8 @@ 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))) + default_layout,row_default_layouts, + col_default_layouts))) goto ERROR2; if ((res = psiconv_list_add(*result,cell))) goto ERROR3; @@ -907,7 +917,7 @@ psiconv_sheet_worksheet *result) { int res=0; - psiconv_u32 temp,cells_off,grid_off; + psiconv_u32 temp,cells_off,grid_off,rows_off,cols_off; int len=0; int leng; @@ -948,19 +958,19 @@ 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); + "Going to read the offset of the row defaults Section"); + rows_off = psiconv_read_u32(buf,lev+2,off+len,&res); if (res) goto ERROR3; - psiconv_debug(lev+2,off+len,"Offset: %04x",temp); + psiconv_debug(lev+2,off+len,"Offset: %04x",rows_off); 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 column defaults Section"); + cols_off = psiconv_read_u32(buf,lev+2,off+len,&res); if (res) goto ERROR3; - psiconv_debug(lev+2,off+len,"Offset: %04x",temp); + psiconv_debug(lev+2,off+len,"Offset: %04x",cols_off); len += 4; psiconv_progress(lev+2,off+len, @@ -987,11 +997,25 @@ psiconv_debug(lev+2,off+len,"Offset: %04x",temp); len += 4; + psiconv_progress(lev+2,off+len,"Going to read the row defaults"); + if ((res = psiconv_parse_sheet_line_list(buf,lev+2,rows_off,NULL, + &(*result)->row_default_layouts, + (*result)->default_layout))) + goto ERROR3; + + psiconv_progress(lev+2,off+len,"Going to read the column defaults"); + if ((res = psiconv_parse_sheet_line_list(buf,lev+2,cols_off,NULL, + &(*result)->col_default_layouts, + (*result)->default_layout))) + goto ERROR4; + 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; + (*result)->default_layout, + (*result)->row_default_layouts, + (*result)->col_default_layouts))) + goto ERROR5; /* TODO: parse grid section */ @@ -1003,6 +1027,10 @@ "End of sheet worksheet section (total length: %08x)", len); return 0; +ERROR5: + psiconv_free_sheet_line_list((*result)->col_default_layouts); +ERROR4: + psiconv_free_sheet_line_list((*result)->row_default_layouts); ERROR3: psiconv_free_sheet_cell_layout((*result)->default_layout); ERROR2: @@ -1017,4 +1045,122 @@ return res; } +int psiconv_parse_sheet_line(const psiconv_buffer buf, int lev, + psiconv_u32 off, int *length, + psiconv_sheet_line *result, + const psiconv_sheet_cell_layout default_layout) +{ + int res=0; + int len=0; + int leng; + + + psiconv_progress(lev+1,off,"Going to read a sheet line"); + if (!(*result = malloc(sizeof(**result)))) + goto ERROR1; + + psiconv_progress(lev+2,off+len,"Going to read the line number"); + (*result)->position = psiconv_read_X(buf,lev+2,off+len,&leng,&res); + if (res) + goto ERROR2; + psiconv_debug(lev+2,off+len,"Line number: %d\n",(*result)->position); + len += leng; + + if (!((*result)->layout = psiconv_clone_cell_layout(default_layout))) + goto ERROR2; + if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len, + &leng,(*result)->layout))) + goto ERROR3; + len += leng; + + if (length) + *length = len; + + psiconv_progress(lev,off+len-1, + "End of the sheet line (total length: %08x)", len); + return 0; + +ERROR3: + psiconv_free_sheet_cell_layout((*result)->layout); +ERROR2: + free (*result); +ERROR1: + psiconv_warn(lev+1,off,"Reading of the sheet line failed"); + if (length) + *length = 0; + if (!res) + return -PSICONV_E_NOMEM; + else + return res; +} + + +int psiconv_parse_sheet_line_list(const psiconv_buffer buf, int lev, + psiconv_u32 off, int *length, + psiconv_sheet_line_list *result, + const psiconv_sheet_cell_layout default_layout) +{ + int res=0; + int len=0; + psiconv_u32 temp; + psiconv_sheet_line line; + psiconv_u32 listlen,i; + int leng; + + psiconv_progress(lev+1,off,"Going to read the sheet line list"); + if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_line_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 line 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 lines"); + listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); + if (res) + goto ERROR2; + psiconv_debug(lev+2,off+len,"Number of defined lines: %d",listlen); + len += leng; + + psiconv_progress(lev+2,off+len,"Going to read all lines"); + for (i = 0; i < listlen; i++) { + psiconv_progress(lev+3,off+len,"Going to read line %d",i); + if ((res = psiconv_parse_sheet_line(buf,lev+3,off+len,&leng,&line, + default_layout))) + goto ERROR2; + if ((res = psiconv_list_add(*result,line))) + goto ERROR3; + free(line); + len += leng; + } + + if (length) + *length = len; + + psiconv_progress(lev,off+len-1, + "End of sheet line list (total length: %08x)", len); + return 0; + +ERROR3: + psiconv_free_sheet_line(line); +ERROR2: + psiconv_free_sheet_line_list(*result); +ERROR1: + psiconv_warn(lev+1,off,"Reading of Sheet Line List failed"); + if (length) + *length = 0; + if (!res) + return -PSICONV_E_NOMEM; + else + return res; +}