… | |
… | |
46 | {psiconv_formula_op_mul,2,"*"}, |
46 | {psiconv_formula_op_mul,2,"*"}, |
47 | {psiconv_formula_op_div,2,"/"}, |
47 | {psiconv_formula_op_div,2,"/"}, |
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_unknown,0,"*UNKNOWN*"}, |
51 | {psiconv_formula_op_not,1,"NOT"}, |
52 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, |
52 | {psiconv_formula_op_and,2,"AND"}, |
53 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, /* 10 */ |
53 | {psiconv_formula_op_or,2,"OR"}, /* 10 */ |
54 | {psiconv_formula_op_con,2,"&"}, |
54 | {psiconv_formula_op_con,2,"&"}, |
55 | {psiconv_formula_op_bra,1,"{}"}, |
55 | {psiconv_formula_op_bra,1,"()"}, |
56 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, |
56 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, |
57 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, |
57 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, |
58 | {psiconv_formula_mark_eof,0,"End of formula"}, |
58 | {psiconv_formula_mark_eof,0,"End of formula"}, |
59 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, |
59 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, |
60 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, |
60 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, |
… | |
… | |
284 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, |
284 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, |
285 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, |
285 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, |
286 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, |
286 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, |
287 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, |
287 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, |
288 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, |
288 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, |
289 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, |
|
|
290 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, |
|
|
291 | {psiconv_formula_unknown,0,"*UNKNOWN*"}, |
|
|
292 | {psiconv_formula_unknown,0,"*UNKNOWN*"}}; |
289 | {psiconv_formula_unknown,0,"*UNKNOWN*"}}; |
293 | |
290 | |
294 | static psiconv_string_t psiconv_read_sheet_string(const psiconv_buffer buf, |
291 | static psiconv_string_t psiconv_read_sheet_string(const psiconv_buffer buf, |
295 | int lev, |
292 | int lev, |
296 | psiconv_u32 off,int *length, int *status) |
293 | psiconv_u32 off,int *length, int *status) |
… | |
… | |
447 | { |
444 | { |
448 | int res=0; |
445 | int res=0; |
449 | int len=0; |
446 | int len=0; |
450 | int leng; |
447 | int leng; |
451 | int eof = 0; |
448 | int eof = 0; |
452 | psiconv_u8 marker; |
449 | psiconv_u8 marker,submarker; |
453 | psiconv_formula_list formula_stack; |
450 | psiconv_formula_list formula_stack; |
454 | psiconv_formula formula,subformula1,subformula2,subformula3,subformula4; |
451 | psiconv_formula formula,subformula,subformula1,subformula2, |
|
|
452 | subformula3,subformula4; |
|
|
453 | psiconv_u16 temp,nr_of_subs; |
455 | |
454 | |
456 | psiconv_progress(lev+1,off,"Going to read a formula element list"); |
455 | psiconv_progress(lev+1,off,"Going to read a formula element list"); |
457 | if (!(*result = malloc(sizeof(**result)))) |
456 | if (!(*result = malloc(sizeof(**result)))) |
458 | goto ERROR1; |
457 | goto ERROR1; |
459 | if (!(formula_stack = psiconv_list_new(sizeof(struct psiconv_formula_s)))) |
458 | if (!(formula_stack = psiconv_list_new(sizeof(struct psiconv_formula_s)))) |
… | |
… | |
530 | formula->type = formula_elements[marker].formula_type; |
529 | formula->type = formula_elements[marker].formula_type; |
531 | len += leng; |
530 | len += leng; |
532 | if ((res = psiconv_list_add(formula_stack,formula))) |
531 | if ((res = psiconv_list_add(formula_stack,formula))) |
533 | goto ERROR8; |
532 | goto ERROR8; |
534 | formula->type = psiconv_formula_unknown; |
533 | formula->type = psiconv_formula_unknown; |
535 | } else if (formula_elements[marker].formula_type == |
534 | } else if ((formula_elements[marker].formula_type == |
|
|
535 | psiconv_formula_dat_cellblock) || |
|
|
536 | (formula_elements[marker].formula_type == |
536 | psiconv_formula_dat_cellblock) { |
537 | psiconv_formula_dat_vcellblock)) { |
537 | psiconv_progress(lev+3,off+len,"Next item: a cell block"); |
538 | psiconv_progress(lev+3,off+len,"Next item: a cell block"); |
538 | if ((res = psiconv_parse_sheet_cell_block(buf,lev+2,off+len,&leng, |
539 | if ((res = psiconv_parse_sheet_cell_block(buf,lev+2,off+len,&leng, |
539 | &formula->data.dat_cellblock))) |
540 | &formula->data.dat_cellblock))) |
540 | goto ERROR8; |
541 | goto ERROR8; |
541 | formula->type = formula_elements[marker].formula_type; |
542 | formula->type = formula_elements[marker].formula_type; |
… | |
… | |
560 | (formula_elements[marker].formula_type == |
561 | (formula_elements[marker].formula_type == |
561 | psiconv_formula_dat_vcellblock)) { |
562 | psiconv_formula_dat_vcellblock)) { |
562 | psiconv_warn(lev+3,off+len,"Not yet supported formula mark!"); |
563 | psiconv_warn(lev+3,off+len,"Not yet supported formula mark!"); |
563 | goto ERROR8; |
564 | goto ERROR8; |
564 | } else if (formula_elements[marker].number_of_args == -1) { |
565 | } else if (formula_elements[marker].number_of_args == -1) { |
565 | psiconv_warn(lev+3,off+len,"Vararg functions not yet supported!"); |
566 | psiconv_progress(lev+3,off+len,"Going to parse a vararg function"); |
|
|
567 | if (!(formula->data.fun_operands = |
|
|
568 | psiconv_list_new(sizeof(*formula)))) |
|
|
569 | goto ERROR8; |
|
|
570 | formula->type = formula_elements[marker].formula_type; |
|
|
571 | nr_of_subs = 0; |
|
|
572 | do { |
|
|
573 | nr_of_subs ++; |
|
|
574 | psiconv_progress(lev+4,off+len,"Going to read vararg argument %d", |
|
|
575 | nr_of_subs); |
|
|
576 | if ((res = psiconv_parse_formula_element_list(buf,lev+4,off+len,&leng, |
|
|
577 | &subformula,maxlen))) |
|
|
578 | goto ERROR8; |
|
|
579 | len += leng; |
|
|
580 | if ((res = psiconv_list_add(formula->data.fun_operands,subformula))) { |
|
|
581 | psiconv_free_formula(subformula); |
|
|
582 | goto ERROR8; |
|
|
583 | } |
|
|
584 | free(subformula); |
|
|
585 | psiconv_progress(lev+4,off+len,"Going to read the next marker"); |
|
|
586 | submarker = psiconv_read_u8(buf,lev+4,off+len,&res); |
|
|
587 | len ++; |
|
|
588 | if (res) |
|
|
589 | goto ERROR8; |
|
|
590 | } while (formula_elements[submarker].formula_type |
|
|
591 | == psiconv_formula_mark_opsep); |
|
|
592 | if (formula_elements[submarker].formula_type |
|
|
593 | != psiconv_formula_mark_opend) { |
|
|
594 | psiconv_warn(lev+3,off+len,"Formula corrupted!"); |
|
|
595 | psiconv_debug(lev+3,off+len,"Found unexpected marker %02x",submarker); |
566 | goto ERROR8; |
596 | goto ERROR8; |
|
|
597 | } |
|
|
598 | psiconv_progress(lev+3,off+len,"Going to read the repeated marker %02x", |
|
|
599 | marker); |
|
|
600 | submarker = psiconv_read_u8(buf,lev+3,off+len,&res); |
|
|
601 | if (res) |
|
|
602 | goto ERROR8; |
|
|
603 | if (submarker != marker) { |
|
|
604 | psiconv_warn(lev+3,off+len,"Formula corrupted!"); |
|
|
605 | psiconv_debug(lev+3,off+len,"Expected marker %02x, found %02x", |
|
|
606 | marker,submarker); |
|
|
607 | goto ERROR8; |
|
|
608 | } |
|
|
609 | len++; |
|
|
610 | psiconv_progress(lev+3,off+len, |
|
|
611 | "Going to read the number of arguments (%d expected)", |
|
|
612 | nr_of_subs); |
|
|
613 | temp = psiconv_read_u16(buf,lev+3,off+len,&res); |
|
|
614 | if (res) |
|
|
615 | goto ERROR8; |
|
|
616 | if (temp != nr_of_subs) { |
|
|
617 | psiconv_warn(lev+3,off+len,"Formula corrupted!"); |
|
|
618 | psiconv_debug(lev+3,off+len, |
|
|
619 | "Read %d arguments, but formula says there are %d", |
|
|
620 | nr_of_subs,temp); |
|
|
621 | goto ERROR8; |
|
|
622 | } |
|
|
623 | len += 2; |
|
|
624 | if ((res = psiconv_list_add(formula_stack,formula))) |
|
|
625 | goto ERROR8; |
|
|
626 | formula->type = psiconv_formula_unknown; |
567 | } else { |
627 | } else { |
568 | if (formula_elements[marker].number_of_args > 0) |
628 | if (formula_elements[marker].number_of_args > 0) |
569 | if ((res = psiconv_list_pop(formula_stack,subformula1))) |
629 | if ((res = psiconv_list_pop(formula_stack,subformula1))) |
570 | goto ERROR8; |
630 | goto ERROR8; |
571 | if (formula_elements[marker].number_of_args > 1) |
631 | if (formula_elements[marker].number_of_args > 1) |