--- psiconv/trunk/lib/psiconv/parse_formula.c 2001/01/31 00:35:06 102 +++ psiconv/trunk/lib/psiconv/parse_formula.c 2001/01/31 00:41:43 103 @@ -291,6 +291,61 @@ {psiconv_formula_unknown,0,"*UNKNOWN*"}, {psiconv_formula_unknown,0,"*UNKNOWN*"}}; +static psiconv_string_t psiconv_read_sheet_string(const psiconv_buffer buf, + int lev, + psiconv_u32 off,int *length, int *status) +{ + int stringlen,i,len,localstatus; + psiconv_string_t result; + char *res_copy; + + psiconv_progress(lev+1,off,"Going to read a sheet string"); + + stringlen = psiconv_read_u8(buf,lev+2,off,&localstatus); + if (localstatus) + goto ERROR1; + psiconv_debug(lev+2,off,"Length: %i",stringlen); + len = 1; + + result = malloc(stringlen + 1); + if (!result) + goto ERROR1; + for (i = 0; (i < stringlen) && !localstatus; i++) + result[i] = psiconv_read_u8(buf,lev,off+i+len,&localstatus); + if (localstatus) + goto ERROR2; + result[stringlen] = 0; + len += stringlen; + + res_copy = psiconv_make_printable(result); + if (!res_copy) + goto ERROR2; + psiconv_debug(lev+2,off,"Contents: `%s'",res_copy); + free(res_copy); + + if (length) + *length = len; + + if (status) + *status = 0; + + psiconv_progress(lev+1,off+len-1,"End of sheet string (total length: %08x)", + len); + + return result; + + +ERROR2: + free(result); +ERROR1: + psiconv_warn(lev+1,off,"Reading of sheet string failed"); + if (status) + *status = localstatus; + if (length) + *length = 0; + return NULL; +} + static int psiconv_parse_sheet_ref(const psiconv_buffer buf,int lev, psiconv_u32 off, int *length, @@ -490,6 +545,18 @@ goto ERROR8; formula->type = formula_elements[marker].formula_type; len += leng; + if ((res = psiconv_list_add(formula_stack,formula))) + goto ERROR8; + formula->type = psiconv_formula_unknown; + } else if (formula_elements[marker].formula_type == + psiconv_formula_dat_string) { + psiconv_progress(lev+3,off+len,"Next item: a string"); + formula->data.dat_string = + psiconv_read_sheet_string(buf,lev+2,off+len,&leng,&res); + if (res) + goto ERROR8; + formula->type = formula_elements[marker].formula_type; + len += leng; if ((res = psiconv_list_add(formula_stack,formula))) goto ERROR8; formula->type = psiconv_formula_unknown;