/[public]/psiconv/trunk/lib/psiconv/parse_formula.c
ViewVC logotype

Diff of /psiconv/trunk/lib/psiconv/parse_formula.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 107 Revision 129
48 {psiconv_formula_op_pow,2,"^"}, 48 {psiconv_formula_op_pow,2,"^"},
49 {psiconv_formula_op_pos,1,"+"}, 49 {psiconv_formula_op_pos,1,"+"},
50 {psiconv_formula_op_neg,1,"-"}, 50 {psiconv_formula_op_neg,1,"-"},
51 {psiconv_formula_op_not,1,"NOT"}, 51 {psiconv_formula_op_not,1,"NOT"},
52 {psiconv_formula_op_and,2,"AND"}, 52 {psiconv_formula_op_and,2,"AND"},
53 {psiconv_formula_op_or,2,"OR"}, 53 {psiconv_formula_op_or,2,"OR"}, /* 10 */
54 {psiconv_formula_unknown,0,"*UNKNOWN*"},
55 {psiconv_formula_unknown,0,"*UNKNOWN*"},
56 {psiconv_formula_unknown,0,"*UNKNOWN*"}, /* 10 */
57 {psiconv_formula_op_con,2,"&"}, 54 {psiconv_formula_op_con,2,"&"},
58 {psiconv_formula_op_bra,1,"()"}, 55 {psiconv_formula_op_bra,1,"()"},
59 {psiconv_formula_unknown,0,"*UNKNOWN*"}, 56 {psiconv_formula_unknown,0,"*UNKNOWN*"},
60 {psiconv_formula_unknown,0,"*UNKNOWN*"}, 57 {psiconv_formula_unknown,0,"*UNKNOWN*"},
61 {psiconv_formula_mark_eof,0,"End of formula"}, 58 {psiconv_formula_mark_eof,0,"End of formula"},
289 {psiconv_formula_unknown,0,"*UNKNOWN*"}, 286 {psiconv_formula_unknown,0,"*UNKNOWN*"},
290 {psiconv_formula_unknown,0,"*UNKNOWN*"}, 287 {psiconv_formula_unknown,0,"*UNKNOWN*"},
291 {psiconv_formula_unknown,0,"*UNKNOWN*"}, 288 {psiconv_formula_unknown,0,"*UNKNOWN*"},
292 {psiconv_formula_unknown,0,"*UNKNOWN*"}}; 289 {psiconv_formula_unknown,0,"*UNKNOWN*"}};
293 290
294static psiconv_string_t psiconv_read_sheet_string(const psiconv_buffer buf,
295 int lev,
296 psiconv_u32 off,int *length, int *status)
297{
298 int stringlen,i,len,localstatus;
299 psiconv_string_t result;
300 char *res_copy;
301
302 psiconv_progress(lev+1,off,"Going to read a sheet string");
303
304 stringlen = psiconv_read_u8(buf,lev+2,off,&localstatus);
305 if (localstatus)
306 goto ERROR1;
307 psiconv_debug(lev+2,off,"Length: %i",stringlen);
308 len = 1;
309
310 result = malloc(stringlen + 1);
311 if (!result)
312 goto ERROR1;
313 for (i = 0; (i < stringlen) && !localstatus; i++)
314 result[i] = psiconv_read_u8(buf,lev,off+i+len,&localstatus);
315 if (localstatus)
316 goto ERROR2;
317 result[stringlen] = 0;
318 len += stringlen;
319
320 res_copy = psiconv_make_printable(result);
321 if (!res_copy)
322 goto ERROR2;
323 psiconv_debug(lev+2,off,"Contents: `%s'",res_copy);
324 free(res_copy);
325
326 if (length)
327 *length = len;
328
329 if (status)
330 *status = 0;
331
332 psiconv_progress(lev+1,off+len-1,"End of sheet string (total length: %08x)",
333 len);
334
335 return result;
336
337
338ERROR2:
339 free(result);
340ERROR1:
341 psiconv_warn(lev+1,off,"Reading of sheet string failed");
342 if (status)
343 *status = localstatus;
344 if (length)
345 *length = 0;
346 return NULL;
347}
348
349
350static int psiconv_parse_sheet_ref(const psiconv_buffer buf,int lev, 291static int psiconv_parse_sheet_ref(const psiconv_buffer buf,int lev,
351 psiconv_u32 off, int *length, 292 psiconv_u32 off, int *length,
352 psiconv_sheet_ref_t *result) 293 psiconv_sheet_ref_t *result)
353{ 294{
354 int res; 295 int res;
447{ 388{
448 int res=0; 389 int res=0;
449 int len=0; 390 int len=0;
450 int leng; 391 int leng;
451 int eof = 0; 392 int eof = 0;
452 psiconv_u8 marker,submarker; 393 psiconv_u8 marker,submarker,submarker2;
453 psiconv_formula_list formula_stack; 394 psiconv_formula_list formula_stack;
454 psiconv_formula formula,subformula,subformula1,subformula2, 395 psiconv_formula formula,subformula,subformula1,subformula2,
455 subformula3,subformula4; 396 subformula3,subformula4;
456 psiconv_u16 temp,nr_of_subs; 397 psiconv_u16 temp,nr_of_subs;
457 398
549 formula->type = psiconv_formula_unknown; 490 formula->type = psiconv_formula_unknown;
550 } else if (formula_elements[marker].formula_type == 491 } else if (formula_elements[marker].formula_type ==
551 psiconv_formula_dat_string) { 492 psiconv_formula_dat_string) {
552 psiconv_progress(lev+3,off+len,"Next item: a string"); 493 psiconv_progress(lev+3,off+len,"Next item: a string");
553 formula->data.dat_string = 494 formula->data.dat_string =
554 psiconv_read_sheet_string(buf,lev+2,off+len,&leng,&res); 495 psiconv_read_short_string(buf,lev+2,off+len,&leng,&res);
555 if (res) 496 if (res)
556 goto ERROR8; 497 goto ERROR8;
557 formula->type = formula_elements[marker].formula_type; 498 formula->type = formula_elements[marker].formula_type;
558 len += leng; 499 len += leng;
559 if ((res = psiconv_list_add(formula_stack,formula))) 500 if ((res = psiconv_list_add(formula_stack,formula)))
560 goto ERROR8; 501 goto ERROR8;
561 formula->type = psiconv_formula_unknown; 502 formula->type = psiconv_formula_unknown;
562 } else if ((formula_elements[marker].formula_type == 503 } else if ((formula_elements[marker].formula_type ==
563 psiconv_formula_dat_var) || 504 psiconv_formula_dat_var)) {
564 (formula_elements[marker].formula_type == 505 psiconv_progress(lev+3,off+len,"Next item: a variable reference");
565 psiconv_formula_dat_vcellblock)) { 506 formula->data.dat_variable = psiconv_read_u32(buf,lev+2,off+len,&res);
566 psiconv_warn(lev+3,off+len,"Not yet supported formula mark!"); 507 if (res)
567 goto ERROR8; 508 goto ERROR8;
509 formula->type = formula_elements[marker].formula_type;
510 len += 4;
511 if ((res = psiconv_list_add(formula_stack,formula)))
512 goto ERROR8;
513 formula->type = psiconv_formula_unknown;
568 } else if (formula_elements[marker].number_of_args == -1) { 514 } else if (formula_elements[marker].number_of_args == -1) {
569 psiconv_progress(lev+3,off+len,"Going to parse a vararg function"); 515 psiconv_progress(lev+3,off+len,"Going to parse a vararg function");
570 if (!(formula->data.fun_operands = 516 if (!(formula->data.fun_operands =
571 psiconv_list_new(sizeof(*formula)))) 517 psiconv_list_new(sizeof(*formula))))
572 goto ERROR8; 518 goto ERROR8;
588 psiconv_progress(lev+4,off+len,"Going to read the next marker"); 534 psiconv_progress(lev+4,off+len,"Going to read the next marker");
589 submarker = psiconv_read_u8(buf,lev+4,off+len,&res); 535 submarker = psiconv_read_u8(buf,lev+4,off+len,&res);
590 len ++; 536 len ++;
591 if (res) 537 if (res)
592 goto ERROR8; 538 goto ERROR8;
539 submarker2 = psiconv_read_u8(buf,lev+4,off+len,&res);
540 if (res)
541 goto ERROR8;
593 } while (formula_elements[submarker].formula_type 542 } while ((formula_elements[submarker].formula_type
594 == psiconv_formula_mark_opsep); 543 == psiconv_formula_mark_opsep) &&
544 (formula_elements[submarker2].formula_type
545 != psiconv_formula_mark_opend));
546 if ((formula_elements[submarker].formula_type ==
547 psiconv_formula_mark_opsep) &&
548 (formula_elements[submarker2].formula_type ==
549 psiconv_formula_mark_opend)) {
550 submarker=submarker2;
551 len++;
552 }
595 if (formula_elements[submarker].formula_type 553 if (formula_elements[submarker].formula_type
596 != psiconv_formula_mark_opend) { 554 != psiconv_formula_mark_opend) {
597 psiconv_warn(lev+3,off+len,"Formula corrupted!"); 555 psiconv_warn(lev+3,off+len,"Formula corrupted!");
598 psiconv_debug(lev+3,off+len,"Found unexpected marker %02x",submarker); 556 psiconv_debug(lev+3,off+len,"Found unexpected marker %02x",submarker);
599 goto ERROR8; 557 goto ERROR8;

Legend:
Removed from v.107  
changed lines
  Added in v.129

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26