… | |
… | |
72 | psiconv_free_character_layout(result->character); |
72 | psiconv_free_character_layout(result->character); |
73 | ERROR2: |
73 | ERROR2: |
74 | free(result); |
74 | free(result); |
75 | ERROR1: |
75 | ERROR1: |
76 | return NULL; |
76 | return NULL; |
|
|
77 | } |
|
|
78 | |
|
|
79 | static psiconv_sheet_cell_reference_t |
|
|
80 | psiconv_read_var_cellref (const psiconv_buffer buf, int lev, |
|
|
81 | psiconv_u32 off, int *length, |
|
|
82 | int *status) |
|
|
83 | { |
|
|
84 | int len=0; |
|
|
85 | int res; |
|
|
86 | psiconv_sheet_cell_reference_t result; |
|
|
87 | psiconv_u32 temp; |
|
|
88 | |
|
|
89 | psiconv_progress(lev+1,off+len,"Going to read a sheet cell reference"); |
|
|
90 | psiconv_progress(lev+2,off+len, |
|
|
91 | "Going to read the initial byte (%02x expected)",0x00); |
|
|
92 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
93 | if (res) |
|
|
94 | goto ERROR1; |
|
|
95 | if (temp != 0x00) { |
|
|
96 | psiconv_warn(lev+2,off+len, |
|
|
97 | "Sheet cell reference initial byte unknown value (ignored)"); |
|
|
98 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
99 | } |
|
|
100 | len ++; |
|
|
101 | |
|
|
102 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
103 | if (res) |
|
|
104 | goto ERROR1; |
|
|
105 | if (temp & 0xffff0000) { |
|
|
106 | psiconv_warn(lev+2,off+len, |
|
|
107 | "Sheet cell row reference to unknown row (reset)"); |
|
|
108 | } |
|
|
109 | result.row.offset = temp; |
|
|
110 | result.row.absolute = psiconv_bool_true; |
|
|
111 | len += 4; |
|
|
112 | |
|
|
113 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
114 | if (res) |
|
|
115 | goto ERROR1; |
|
|
116 | if (temp & 0xffff0000) { |
|
|
117 | psiconv_warn(lev+2,off+len, |
|
|
118 | "Sheet cell column reference to unknown row (reset)"); |
|
|
119 | } |
|
|
120 | result.column.offset = temp; |
|
|
121 | result.column.absolute = psiconv_bool_true; |
|
|
122 | len += 4; |
|
|
123 | |
|
|
124 | if (length) |
|
|
125 | *length = len; |
|
|
126 | |
|
|
127 | psiconv_progress(lev,off+len-1, |
|
|
128 | "End of sheet column reference (total length: %08x)", len); |
|
|
129 | return result; |
|
|
130 | ERROR1: |
|
|
131 | psiconv_warn(lev+1,off,"Reading of Sheet Column Reference failed"); |
|
|
132 | if (length) |
|
|
133 | *length = 0; |
|
|
134 | if (status) |
|
|
135 | *status = res?res:-PSICONV_E_NOMEM; |
|
|
136 | return result; |
|
|
137 | } |
|
|
138 | |
|
|
139 | static psiconv_sheet_cell_block_t |
|
|
140 | psiconv_read_var_cellblock (const psiconv_buffer buf, int lev, |
|
|
141 | psiconv_u32 off, int *length, |
|
|
142 | int *status) |
|
|
143 | { |
|
|
144 | int len=0; |
|
|
145 | int res; |
|
|
146 | psiconv_sheet_cell_block_t result; |
|
|
147 | psiconv_u32 temp; |
|
|
148 | |
|
|
149 | psiconv_progress(lev+1,off+len,"Going to read a sheet cell block reference"); |
|
|
150 | psiconv_progress(lev+2,off+len, |
|
|
151 | "Going to read the initial byte (%02x expected)",0x00); |
|
|
152 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
153 | if (res) |
|
|
154 | goto ERROR1; |
|
|
155 | if (temp != 0x00) { |
|
|
156 | psiconv_warn(lev+2,off+len, |
|
|
157 | "Sheet cell reference initial byte unknown value (ignored)"); |
|
|
158 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
159 | } |
|
|
160 | len ++; |
|
|
161 | |
|
|
162 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
163 | if (res) |
|
|
164 | goto ERROR1; |
|
|
165 | if (temp & 0xffff0000) { |
|
|
166 | psiconv_warn(lev+2,off+len, |
|
|
167 | "Sheet block initial row reference to unknown row (reset)"); |
|
|
168 | } |
|
|
169 | result.first.row.offset = temp; |
|
|
170 | result.first.row.absolute = psiconv_bool_true; |
|
|
171 | len += 4; |
|
|
172 | |
|
|
173 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
174 | if (res) |
|
|
175 | goto ERROR1; |
|
|
176 | if (temp & 0xffff0000) { |
|
|
177 | psiconv_warn(lev+2,off+len, |
|
|
178 | "Sheet block initial column reference to unknown row (reset)"); |
|
|
179 | } |
|
|
180 | result.first.column.offset = temp; |
|
|
181 | result.first.column.absolute = psiconv_bool_true; |
|
|
182 | len += 4; |
|
|
183 | |
|
|
184 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
185 | if (res) |
|
|
186 | goto ERROR1; |
|
|
187 | if (temp & 0xffff0000) { |
|
|
188 | psiconv_warn(lev+2,off+len, |
|
|
189 | "Sheet block final row reference to unknown row (reset)"); |
|
|
190 | } |
|
|
191 | result.last.row.offset = temp; |
|
|
192 | result.last.row.absolute = psiconv_bool_true; |
|
|
193 | len += 4; |
|
|
194 | |
|
|
195 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
196 | if (res) |
|
|
197 | goto ERROR1; |
|
|
198 | if (temp & 0xffff0000) { |
|
|
199 | psiconv_warn(lev+2,off+len, |
|
|
200 | "Sheet block final column reference to unknown row (reset)"); |
|
|
201 | } |
|
|
202 | result.last.column.offset = temp; |
|
|
203 | result.last.column.absolute = psiconv_bool_true; |
|
|
204 | len += 4; |
|
|
205 | |
|
|
206 | if (length) |
|
|
207 | *length = len; |
|
|
208 | |
|
|
209 | psiconv_progress(lev,off+len-1, |
|
|
210 | "End of sheet cell block reference (total length: %08x)", |
|
|
211 | len); |
|
|
212 | return result; |
|
|
213 | ERROR1: |
|
|
214 | psiconv_warn(lev+1,off,"Reading of Sheet Cell Block Reference failed"); |
|
|
215 | if (length) |
|
|
216 | *length = 0; |
|
|
217 | if (status) |
|
|
218 | *status = res?res:-PSICONV_E_NOMEM; |
|
|
219 | return result; |
77 | } |
220 | } |
78 | |
221 | |
79 | int psiconv_parse_sheet_numberformat(const psiconv_buffer buf, int lev, |
222 | int psiconv_parse_sheet_numberformat(const psiconv_buffer buf, int lev, |
80 | psiconv_u32 off, int *length, |
223 | psiconv_u32 off, int *length, |
81 | psiconv_sheet_numberformat result) |
224 | psiconv_sheet_numberformat result) |
… | |
… | |
311 | if (res) |
454 | if (res) |
312 | goto ERROR2; |
455 | goto ERROR2; |
313 | if (temp != 0x00) { |
456 | if (temp != 0x00) { |
314 | psiconv_warn(lev+2,off+len, |
457 | psiconv_warn(lev+2,off+len, |
315 | "Sheet status section unknown byte unknown value (ignored)"); |
458 | "Sheet status section unknown byte unknown value (ignored)"); |
316 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
459 | psiconv_debug(lev+2,off+len,"Unknown byte: %02x",temp); |
317 | } |
460 | } |
318 | len ++; |
461 | len ++; |
319 | |
462 | |
320 | psiconv_progress(lev+2,off+len,"Going to read sheet display size"); |
463 | psiconv_progress(lev+2,off+len,"Going to read sheet display size"); |
321 | (*result)->sheet_display_size = psiconv_read_u32(buf,lev+2,off + len,&res); |
464 | (*result)->sheet_display_size = psiconv_read_u32(buf,lev+2,off + len,&res); |
… | |
… | |
354 | |
497 | |
355 | int psiconv_parse_sheet_workbook_section(const psiconv_buffer buf, int lev, |
498 | int psiconv_parse_sheet_workbook_section(const psiconv_buffer buf, int lev, |
356 | psiconv_u32 off, int *length, |
499 | psiconv_u32 off, int *length, |
357 | psiconv_sheet_workbook_section *result) |
500 | psiconv_sheet_workbook_section *result) |
358 | { |
501 | { |
359 | int res=0; |
502 | int res=0,with_name; |
360 | psiconv_u32 temp,formulas_off,worksheets_off; |
503 | psiconv_u32 temp,formulas_off,worksheets_off,info_off,var_off,name_off=0; |
361 | int len=0; |
504 | int len=0; |
362 | |
505 | |
363 | psiconv_progress(lev+1,off,"Going to read the sheet workbook section"); |
506 | psiconv_progress(lev+1,off,"Going to read the sheet workbook section"); |
364 | if (!(*result = malloc(sizeof(**result)))) |
507 | if (!(*result = malloc(sizeof(**result)))) |
365 | goto ERROR1; |
508 | goto ERROR1; |
366 | |
509 | |
367 | psiconv_progress(lev+2,off+len, |
510 | psiconv_progress(lev+2,off+len, |
368 | "Going to read the initial byte (%02x expected)",0x04); |
511 | "Going to read the initial byte (%02x or %02x expected)", |
|
|
512 | 0x02,0x04); |
369 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
513 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
370 | if (res) |
514 | if (res) |
371 | goto ERROR2; |
515 | goto ERROR2; |
372 | if (temp != 0x04) { |
516 | if ((temp != 0x04) && temp !=0x02) { |
373 | psiconv_warn(lev+2,off+len, |
517 | psiconv_warn(lev+2,off+len, |
374 | "Sheet workbook section initial byte unknown value (ignored)"); |
518 | "Sheet workbook section initial byte unknown value (ignored)"); |
375 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
519 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
376 | } |
520 | } |
|
|
521 | with_name = temp ==0x04; |
377 | len ++; |
522 | len ++; |
378 | |
523 | |
379 | psiconv_progress(lev+2,off+len, |
524 | psiconv_progress(lev+2,off+len, |
380 | "Going to read the offset of the 1st ??? Section"); |
525 | "Going to read the offset of the sheet info Section"); |
381 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
526 | info_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
382 | if (res) |
527 | if (res) |
383 | goto ERROR2; |
528 | goto ERROR2; |
384 | psiconv_debug(lev+2,off+len,"Offset: %04x",temp); |
529 | psiconv_debug(lev+2,off+len,"Offset: %04x",info_off); |
385 | len += 4; |
530 | len += 4; |
386 | |
531 | |
387 | psiconv_progress(lev+2,off+len, |
532 | psiconv_progress(lev+2,off+len, |
388 | "Going to read the offset of the Formulas List"); |
533 | "Going to read the offset of the Formulas List"); |
389 | formulas_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
534 | formulas_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
… | |
… | |
399 | goto ERROR2; |
544 | goto ERROR2; |
400 | psiconv_debug(lev+2,off+len,"Offset: %04x",worksheets_off); |
545 | psiconv_debug(lev+2,off+len,"Offset: %04x",worksheets_off); |
401 | len += 4; |
546 | len += 4; |
402 | |
547 | |
403 | psiconv_progress(lev+2,off+len, |
548 | psiconv_progress(lev+2,off+len, |
|
|
549 | "Going to read the offset of the Variable List"); |
|
|
550 | var_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
551 | if (res) |
|
|
552 | goto ERROR2; |
|
|
553 | psiconv_debug(lev+2,off+len,"Offset: %04x",var_off); |
|
|
554 | len += 4; |
|
|
555 | |
|
|
556 | if (with_name) { |
|
|
557 | psiconv_progress(lev+2,off+len, |
404 | "Going to read the offset of the 4th ??? Section"); |
558 | "Going to read the offset of the Name Section"); |
405 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
559 | name_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
406 | if (res) |
560 | if (res) |
407 | goto ERROR2; |
561 | goto ERROR2; |
408 | psiconv_debug(lev+2,off+len,"Offset: %04x",temp); |
562 | psiconv_debug(lev+2,off+len,"Offset: %04x",name_off); |
409 | len += 4; |
563 | len += 4; |
|
|
564 | } |
|
|
565 | |
|
|
566 | |
|
|
567 | psiconv_progress(lev+2,off+len,"Going to read the info section"); |
|
|
568 | if ((res = psiconv_parse_sheet_info_section(buf,lev+2,info_off,NULL, |
|
|
569 | &(*result)->info))) |
|
|
570 | goto ERROR2; |
|
|
571 | |
|
|
572 | psiconv_progress(lev+2,off+len,"Going to read the variables list"); |
|
|
573 | if ((res = psiconv_parse_sheet_variable_list(buf,lev+2,var_off,NULL, |
|
|
574 | &(*result)->variables))) |
|
|
575 | goto ERROR3; |
410 | |
576 | |
411 | psiconv_progress(lev+2,off+len,"Going to read the formulas list"); |
577 | psiconv_progress(lev+2,off+len,"Going to read the formulas list"); |
412 | if ((res = psiconv_parse_sheet_formula_table(buf,lev+2,formulas_off,NULL, |
578 | if ((res = psiconv_parse_sheet_formula_list(buf,lev+2,formulas_off,NULL, |
413 | &(*result)->formulas))) |
579 | &(*result)->formulas))) |
414 | goto ERROR2; |
580 | goto ERROR4; |
415 | |
581 | |
416 | psiconv_progress(lev+2,off+len,"Going to read the worksheet list"); |
582 | psiconv_progress(lev+2,off+len,"Going to read the worksheet list"); |
417 | if ((res = psiconv_parse_sheet_worksheet_list(buf,lev+2,worksheets_off, |
583 | if ((res = psiconv_parse_sheet_worksheet_list(buf,lev+2,worksheets_off, |
418 | NULL,&(*result)->worksheets))) |
584 | NULL,&(*result)->worksheets))) |
419 | goto ERROR2; |
585 | goto ERROR5; |
420 | |
586 | |
|
|
587 | if (with_name) { |
|
|
588 | psiconv_progress(lev+2,off+len,"Going to read the name section"); |
|
|
589 | if ((res = psiconv_parse_sheet_name_section(buf,lev+2,name_off,NULL, |
|
|
590 | &(*result)->name))) |
|
|
591 | goto ERROR6; |
|
|
592 | } else |
|
|
593 | (*result)->name = NULL; |
421 | |
594 | |
422 | if (length) |
595 | if (length) |
423 | *length = len; |
596 | *length = len; |
424 | |
597 | |
425 | psiconv_progress(lev,off+len-1, |
598 | psiconv_progress(lev,off+len-1, |
426 | "End of sheet workbook section (total length: %08x)", len); |
599 | "End of sheet workbook section (total length: %08x)", len); |
427 | return 0; |
600 | return 0; |
428 | |
601 | |
|
|
602 | ERROR6: |
|
|
603 | psiconv_free_sheet_worksheet_list((*result)->worksheets); |
|
|
604 | ERROR5: |
|
|
605 | psiconv_free_formula_list((*result)->formulas); |
|
|
606 | ERROR4: |
|
|
607 | psiconv_free_sheet_variable_list((*result)->variables); |
|
|
608 | ERROR3: |
|
|
609 | psiconv_free_sheet_info_section((*result)->info); |
429 | ERROR2: |
610 | ERROR2: |
430 | free (*result); |
611 | free (*result); |
431 | ERROR1: |
612 | ERROR1: |
432 | psiconv_warn(lev+1,off,"Reading of Sheet Workbook Section failed"); |
613 | psiconv_warn(lev+1,off,"Reading of Sheet Workbook Section failed"); |
433 | if (length) |
614 | if (length) |
… | |
… | |
436 | return -PSICONV_E_NOMEM; |
617 | return -PSICONV_E_NOMEM; |
437 | else |
618 | else |
438 | return res; |
619 | return res; |
439 | } |
620 | } |
440 | |
621 | |
|
|
622 | int psiconv_parse_sheet_name_section(const psiconv_buffer buf, int lev, |
|
|
623 | psiconv_u32 off, int *length, |
|
|
624 | psiconv_sheet_name_section *result) |
|
|
625 | { |
|
|
626 | int res=0; |
|
|
627 | psiconv_u32 temp; |
|
|
628 | int len=0,leng; |
|
|
629 | |
|
|
630 | psiconv_progress(lev+1,off,"Going to read the sheet name section"); |
|
|
631 | if (!(*result = malloc(sizeof(**result)))) |
|
|
632 | goto ERROR1; |
|
|
633 | |
|
|
634 | psiconv_progress(lev+2,off+len, |
|
|
635 | "Going to read the initial byte (%02x expected)",0x02); |
|
|
636 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
637 | if (res) |
|
|
638 | goto ERROR2; |
|
|
639 | if (temp != 0x02) { |
|
|
640 | psiconv_warn(lev+2,off+len, |
|
|
641 | "Sheet name section initial byte unknown value (ignored)"); |
|
|
642 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
643 | } |
|
|
644 | len ++; |
|
|
645 | |
|
|
646 | psiconv_progress(lev+2,off+len, "Going to read the sheet name"); |
|
|
647 | (*result)->name = psiconv_read_string(buf,lev+2,off+len,&leng,&res); |
|
|
648 | if (res) |
|
|
649 | goto ERROR2; |
|
|
650 | len += leng; |
|
|
651 | |
|
|
652 | if (length) |
|
|
653 | *length = len; |
|
|
654 | |
|
|
655 | psiconv_progress(lev,off+len-1, |
|
|
656 | "End of sheet name section (total length: %08x)", len); |
|
|
657 | return 0; |
|
|
658 | |
|
|
659 | ERROR2: |
|
|
660 | free(*result); |
|
|
661 | ERROR1: |
|
|
662 | psiconv_warn(lev+1,off,"Reading of Sheet Name Section failed"); |
|
|
663 | if (length) |
|
|
664 | *length = 0; |
|
|
665 | if (!res) |
|
|
666 | return -PSICONV_E_NOMEM; |
|
|
667 | else |
|
|
668 | return res; |
|
|
669 | } |
|
|
670 | |
|
|
671 | int psiconv_parse_sheet_info_section(const psiconv_buffer buf, int lev, |
|
|
672 | psiconv_u32 off, int *length, |
|
|
673 | psiconv_sheet_info_section *result) |
|
|
674 | { |
|
|
675 | int res=0; |
|
|
676 | psiconv_u32 temp; |
|
|
677 | int len=0,leng; |
|
|
678 | |
|
|
679 | psiconv_progress(lev+1,off,"Going to read the sheet info section"); |
|
|
680 | if (!(*result = malloc(sizeof(**result)))) |
|
|
681 | goto ERROR1; |
|
|
682 | |
|
|
683 | psiconv_progress(lev+2,off+len, |
|
|
684 | "Going to read the initial byte (%02x expected)",0x02); |
|
|
685 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
686 | if (res) |
|
|
687 | goto ERROR2; |
|
|
688 | if (temp != 0x02) { |
|
|
689 | psiconv_warn(lev+2,off+len, |
|
|
690 | "Sheet info section initial byte unknown value (ignored)"); |
|
|
691 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
692 | } |
|
|
693 | len ++; |
|
|
694 | |
|
|
695 | psiconv_progress(lev+2,off+len, "Going to read an unknown Xint"); |
|
|
696 | temp = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
|
|
697 | if (res) |
|
|
698 | goto ERROR2; |
|
|
699 | psiconv_debug(lev+2,off+len,"Value: %d\n",temp); |
|
|
700 | len += leng; |
|
|
701 | |
|
|
702 | psiconv_progress(lev+2,off+len, "Going to read the flags byte"); |
|
|
703 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
704 | if (res) |
|
|
705 | goto ERROR2; |
|
|
706 | (*result)->auto_recalc = temp & 0x01 ? psiconv_bool_true:psiconv_bool_false; |
|
|
707 | psiconv_debug(lev+2,off+len,"Auto recalculation: %02x", |
|
|
708 | (*result)->auto_recalc); |
|
|
709 | if ((temp & 0xfe) != 0x02) { |
|
|
710 | psiconv_warn(lev+2,off+len,"Sheet Info Section flags byte " |
|
|
711 | "contains unknown flags (ignored)"); |
|
|
712 | psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp &0xfe); |
|
|
713 | } |
|
|
714 | |
|
|
715 | len ++; |
|
|
716 | |
|
|
717 | |
|
|
718 | if (length) |
|
|
719 | *length = len; |
|
|
720 | |
|
|
721 | psiconv_progress(lev,off+len-1, |
|
|
722 | "End of sheet info section (total length: %08x)", len); |
|
|
723 | return 0; |
|
|
724 | |
|
|
725 | ERROR2: |
|
|
726 | free(*result); |
|
|
727 | ERROR1: |
|
|
728 | psiconv_warn(lev+1,off,"Reading of Sheet Name Section failed"); |
|
|
729 | if (length) |
|
|
730 | *length = 0; |
|
|
731 | if (!res) |
|
|
732 | return -PSICONV_E_NOMEM; |
|
|
733 | else |
|
|
734 | return res; |
|
|
735 | } |
|
|
736 | |
441 | int psiconv_parse_sheet_formula_table(const psiconv_buffer buf, int lev, |
737 | int psiconv_parse_sheet_formula_list(const psiconv_buffer buf, int lev, |
442 | psiconv_u32 off, int *length, |
738 | psiconv_u32 off, int *length, |
443 | psiconv_formula_list *result) |
739 | psiconv_formula_list *result) |
444 | { |
740 | { |
445 | int res=0; |
741 | int res=0; |
446 | int len=0; |
742 | int len=0; |
447 | psiconv_u32 temp; |
743 | psiconv_u32 temp; |
448 | psiconv_formula formula; |
744 | psiconv_formula formula; |
449 | psiconv_u32 listlen,i; |
745 | psiconv_u32 listlen,i; |
450 | int leng; |
746 | int leng; |
451 | |
747 | |
452 | psiconv_progress(lev+1,off,"Going to read the sheet formula table"); |
748 | psiconv_progress(lev+1,off,"Going to read the sheet formula list"); |
453 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_formula_s)))) |
749 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_formula_s)))) |
454 | goto ERROR1; |
750 | goto ERROR1; |
455 | |
751 | |
456 | psiconv_progress(lev+2,off+len, |
752 | psiconv_progress(lev+2,off+len, |
457 | "Going to read the initial byte (%02x expected)",0x02); |
753 | "Going to read the initial byte (%02x expected)",0x02); |
458 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
754 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
459 | if (res) |
755 | if (res) |
460 | goto ERROR2; |
756 | goto ERROR2; |
461 | if (temp != 0x02) { |
757 | if (temp != 0x02) { |
462 | psiconv_warn(lev+2,off+len, |
758 | psiconv_warn(lev+2,off+len, |
463 | "Sheet formula table initial byte unknown value (ignored)"); |
759 | "Sheet formula list initial byte unknown value (ignored)"); |
464 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
760 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
465 | } |
761 | } |
466 | len ++; |
762 | len ++; |
467 | |
763 | |
468 | psiconv_progress(lev+2,off+len, |
764 | psiconv_progress(lev+2,off+len, |
… | |
… | |
478 | psiconv_progress(lev+3,off+len,"Going to read formula %d",i); |
774 | psiconv_progress(lev+3,off+len,"Going to read formula %d",i); |
479 | if ((res = psiconv_parse_formula(buf,lev+3,off+len,&leng,&formula))) |
775 | if ((res = psiconv_parse_formula(buf,lev+3,off+len,&leng,&formula))) |
480 | goto ERROR2; |
776 | goto ERROR2; |
481 | if ((res = psiconv_list_add(*result,formula))) |
777 | if ((res = psiconv_list_add(*result,formula))) |
482 | goto ERROR3; |
778 | goto ERROR3; |
|
|
779 | free(formula); |
483 | len += leng; |
780 | len += leng; |
484 | } |
781 | } |
485 | |
782 | |
486 | if (length) |
783 | if (length) |
487 | *length = len; |
784 | *length = len; |
488 | |
785 | |
489 | psiconv_progress(lev,off+len-1, |
786 | psiconv_progress(lev,off+len-1, |
490 | "End of sheet formula table (total length: %08x)", len); |
787 | "End of sheet formula list (total length: %08x)", len); |
491 | return 0; |
788 | return 0; |
492 | |
789 | |
493 | ERROR3: |
790 | ERROR3: |
494 | psiconv_free_formula(formula); |
791 | psiconv_free_formula(formula); |
495 | ERROR2: |
792 | ERROR2: |
496 | psiconv_list_free(*result); |
793 | psiconv_list_free(*result); |
497 | ERROR1: |
794 | ERROR1: |
498 | psiconv_warn(lev+1,off,"Reading of Sheet Formula Table failed"); |
795 | psiconv_warn(lev+1,off,"Reading of Sheet Formula list failed"); |
499 | if (length) |
796 | if (length) |
500 | *length = 0; |
797 | *length = 0; |
501 | if (!res) |
798 | if (!res) |
502 | return -PSICONV_E_NOMEM; |
799 | return -PSICONV_E_NOMEM; |
503 | else |
800 | else |
… | |
… | |
915 | int psiconv_parse_sheet_worksheet(const psiconv_buffer buf, int lev, |
1212 | int psiconv_parse_sheet_worksheet(const psiconv_buffer buf, int lev, |
916 | psiconv_u32 off, int *length, |
1213 | psiconv_u32 off, int *length, |
917 | psiconv_sheet_worksheet *result) |
1214 | psiconv_sheet_worksheet *result) |
918 | { |
1215 | { |
919 | int res=0; |
1216 | int res=0; |
920 | psiconv_u32 temp,cells_off,grid_off,rows_off,cols_off; |
1217 | psiconv_u32 temp,cells_off,grid_off,rows_off,cols_off,unknown_off; |
921 | int len=0; |
1218 | int len=0; |
922 | int leng; |
1219 | int leng; |
923 | |
1220 | |
924 | psiconv_progress(lev+1,off,"Going to read the sheet worksheet section"); |
1221 | psiconv_progress(lev+1,off,"Going to read the sheet worksheet section"); |
925 | if (!(*result = malloc(sizeof(**result)))) |
1222 | if (!(*result = malloc(sizeof(**result)))) |
… | |
… | |
989 | psiconv_debug(lev+2,off+len,"Offset: %04x",grid_off); |
1286 | psiconv_debug(lev+2,off+len,"Offset: %04x",grid_off); |
990 | len += 4; |
1287 | len += 4; |
991 | |
1288 | |
992 | psiconv_progress(lev+2,off+len, |
1289 | psiconv_progress(lev+2,off+len, |
993 | "Going to read the offset of the 3rd ??? Section"); |
1290 | "Going to read the offset of the 3rd ??? Section"); |
994 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
1291 | unknown_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
995 | if (res) |
1292 | if (res) |
996 | goto ERROR3; |
1293 | goto ERROR3; |
|
|
1294 | psiconv_debug(lev+2,off+len,"Offset: %04x",unknown_off); |
|
|
1295 | len += 4; |
|
|
1296 | |
|
|
1297 | psiconv_progress(lev+2,off+len, |
|
|
1298 | "Going to read a long of the 3rd ??? Section " |
|
|
1299 | "(%08x expected)",0x00); |
|
|
1300 | temp = psiconv_read_u32(buf,lev+2,unknown_off,&res); |
|
|
1301 | if (res) |
|
|
1302 | goto ERROR3; |
|
|
1303 | if (temp != 0x00) { |
|
|
1304 | psiconv_warn(lev+2,unknown_off, |
|
|
1305 | "Unknown worksheet subsection has unknown contents (ignored)"); |
997 | psiconv_debug(lev+2,off+len,"Offset: %04x",temp); |
1306 | psiconv_debug(lev+2,unknown_off,"Offset: %04x",temp); |
|
|
1307 | } |
998 | len += 4; |
1308 | len += 4; |
999 | |
1309 | |
1000 | psiconv_progress(lev+2,off+len,"Going to read the row defaults"); |
1310 | psiconv_progress(lev+2,off+len,"Going to read the row defaults"); |
1001 | if ((res = psiconv_parse_sheet_line_list(buf,lev+2,rows_off,NULL, |
1311 | if ((res = psiconv_parse_sheet_line_list(buf,lev+2,rows_off,NULL, |
1002 | &(*result)->row_default_layouts, |
1312 | &(*result)->row_default_layouts, |
… | |
… | |
1016 | (*result)->row_default_layouts, |
1326 | (*result)->row_default_layouts, |
1017 | (*result)->col_default_layouts))) |
1327 | (*result)->col_default_layouts))) |
1018 | goto ERROR5; |
1328 | goto ERROR5; |
1019 | |
1329 | |
1020 | |
1330 | |
1021 | /* TODO: parse grid section */ |
1331 | psiconv_progress(lev+2,off+len,"Going to read the grid section"); |
|
|
1332 | if ((res = psiconv_parse_sheet_grid_section(buf,lev+2,grid_off,NULL, |
|
|
1333 | &(*result)->grid))) |
|
|
1334 | goto ERROR6; |
|
|
1335 | |
|
|
1336 | |
1022 | |
1337 | |
1023 | if (length) |
1338 | if (length) |
1024 | *length = len; |
1339 | *length = len; |
1025 | |
1340 | |
1026 | psiconv_progress(lev,off+len-1, |
1341 | psiconv_progress(lev,off+len-1, |
1027 | "End of sheet worksheet section (total length: %08x)", len); |
1342 | "End of sheet worksheet section (total length: %08x)", len); |
1028 | return 0; |
1343 | return 0; |
1029 | |
1344 | |
|
|
1345 | ERROR6: |
|
|
1346 | psiconv_free_sheet_cell_list((*result)->cells); |
1030 | ERROR5: |
1347 | ERROR5: |
1031 | psiconv_free_sheet_line_list((*result)->col_default_layouts); |
1348 | psiconv_free_sheet_line_list((*result)->col_default_layouts); |
1032 | ERROR4: |
1349 | ERROR4: |
1033 | psiconv_free_sheet_line_list((*result)->row_default_layouts); |
1350 | psiconv_free_sheet_line_list((*result)->row_default_layouts); |
1034 | ERROR3: |
1351 | ERROR3: |
… | |
… | |
1162 | return -PSICONV_E_NOMEM; |
1479 | return -PSICONV_E_NOMEM; |
1163 | else |
1480 | else |
1164 | return res; |
1481 | return res; |
1165 | } |
1482 | } |
1166 | |
1483 | |
|
|
1484 | int psiconv_parse_sheet_variable(const psiconv_buffer buf, int lev, |
|
|
1485 | psiconv_u32 off, int *length, |
|
|
1486 | psiconv_sheet_variable *result) |
|
|
1487 | { |
|
|
1488 | int res=0; |
|
|
1489 | int len=0; |
|
|
1490 | psiconv_u32 marker; |
|
|
1491 | int leng; |
|
|
1492 | |
|
|
1493 | psiconv_progress(lev+1,off,"Going to read a sheet variable"); |
|
|
1494 | if (!(*result = malloc(sizeof(**result)))) |
|
|
1495 | goto ERROR1; |
|
|
1496 | |
|
|
1497 | psiconv_progress(lev+2,off+len, "Going to read the variable name"); |
|
|
1498 | (*result)->name = psiconv_read_string(buf,lev+2,off+len,&leng,&res); |
|
|
1499 | if (res) |
|
|
1500 | goto ERROR2; |
|
|
1501 | len += leng; |
|
|
1502 | |
|
|
1503 | psiconv_progress(lev+2,off+len,"Going to read the type marker"); |
|
|
1504 | marker = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
1505 | if (res) |
|
|
1506 | goto ERROR3; |
|
|
1507 | psiconv_debug(lev+2,off+len,"Marker: %02x",marker); |
|
|
1508 | len ++; |
|
|
1509 | |
|
|
1510 | if (marker == 0x00) { |
|
|
1511 | (*result)->type = psiconv_var_int; |
|
|
1512 | psiconv_progress(lev+2,off+len,"Going to read a signed integer"); |
|
|
1513 | (*result)->data.dat_int = psiconv_read_sint(buf,lev+2,off+len,&leng,&res); |
|
|
1514 | if (res) |
|
|
1515 | goto ERROR3; |
|
|
1516 | psiconv_debug(lev+2,off+len,"Value: %d",(*result)->data.dat_int); |
|
|
1517 | len += leng; |
|
|
1518 | } else if (marker == 0x01) { |
|
|
1519 | (*result)->type = psiconv_var_float; |
|
|
1520 | psiconv_progress(lev+2,off+len,"Going to read a floating point number"); |
|
|
1521 | (*result)->data.dat_float = psiconv_read_float(buf,lev+2,off+len,&leng, |
|
|
1522 | &res); |
|
|
1523 | if (res) |
|
|
1524 | goto ERROR3; |
|
|
1525 | psiconv_debug(lev+2,off+len,"Value: %f",(*result)->data.dat_float); |
|
|
1526 | len += leng; |
|
|
1527 | } else if (marker == 0x02) { |
|
|
1528 | (*result)->type = psiconv_var_string; |
|
|
1529 | psiconv_progress(lev+2,off+len,"Going to read a string"); |
|
|
1530 | (*result)->data.dat_string = psiconv_read_string(buf,lev+2,off+len,&leng, |
|
|
1531 | &res); |
|
|
1532 | if (res) |
|
|
1533 | goto ERROR3; |
|
|
1534 | len += leng; |
|
|
1535 | } else if (marker == 0x03) { |
|
|
1536 | (*result)->type = psiconv_var_cellref; |
|
|
1537 | psiconv_progress(lev+2,off+len,"Going to read a cell reference"); |
|
|
1538 | (*result)->data.dat_cellref = psiconv_read_var_cellref(buf,lev+2,off+len, |
|
|
1539 | &leng, &res); |
|
|
1540 | if (res) |
|
|
1541 | goto ERROR3; |
|
|
1542 | len += leng; |
|
|
1543 | } else if (marker == 0x04) { |
|
|
1544 | (*result)->type = psiconv_var_cellblock; |
|
|
1545 | psiconv_progress(lev+2,off+len,"Going to read a cell block reference"); |
|
|
1546 | (*result)->data.dat_cellblock = psiconv_read_var_cellblock(buf,lev+2, |
|
|
1547 | off+len, |
|
|
1548 | &leng, &res); |
|
|
1549 | if (res) |
|
|
1550 | goto ERROR3; |
|
|
1551 | len += leng; |
|
|
1552 | } else { |
|
|
1553 | psiconv_warn(lev+2,off+len,"Sheet variable unknown type marker"); |
|
|
1554 | res = -PSICONV_E_PARSE; |
|
|
1555 | goto ERROR3; |
|
|
1556 | } |
|
|
1557 | |
|
|
1558 | psiconv_progress(lev+2,off+len,"Going to read the variable number"); |
|
|
1559 | (*result)->number = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
1560 | if (res) |
|
|
1561 | goto ERROR4; |
|
|
1562 | psiconv_debug(lev+2,off+len,"Number: %08x",(*result)->number); |
|
|
1563 | len += 4; |
|
|
1564 | |
|
|
1565 | if (length) |
|
|
1566 | *length = len; |
|
|
1567 | |
|
|
1568 | psiconv_progress(lev,off+len-1, |
|
|
1569 | "End of sheet variable (total length: %08x)", len); |
|
|
1570 | return 0; |
|
|
1571 | |
|
|
1572 | ERROR4: |
|
|
1573 | if ((*result)->type == psiconv_var_string) |
|
|
1574 | free((*result)->data.dat_string); |
|
|
1575 | ERROR3: |
|
|
1576 | free((*result)->name); |
|
|
1577 | ERROR2: |
|
|
1578 | free (*result); |
|
|
1579 | ERROR1: |
|
|
1580 | psiconv_warn(lev+1,off,"Reading of Sheet Variable failed"); |
|
|
1581 | if (length) |
|
|
1582 | *length = 0; |
|
|
1583 | if (!res) |
|
|
1584 | return -PSICONV_E_NOMEM; |
|
|
1585 | else |
|
|
1586 | return res; |
|
|
1587 | } |
|
|
1588 | |
|
|
1589 | |
|
|
1590 | int psiconv_parse_sheet_variable_list(const psiconv_buffer buf, int lev, |
|
|
1591 | psiconv_u32 off, int *length, |
|
|
1592 | psiconv_sheet_variable_list *result) |
|
|
1593 | { |
|
|
1594 | int res=0; |
|
|
1595 | int len=0; |
|
|
1596 | psiconv_u32 temp; |
|
|
1597 | psiconv_sheet_variable variable; |
|
|
1598 | psiconv_u32 listlen,i; |
|
|
1599 | int leng; |
|
|
1600 | |
|
|
1601 | psiconv_progress(lev+1,off,"Going to read the sheet variable list"); |
|
|
1602 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_variable_s)))) |
|
|
1603 | goto ERROR1; |
|
|
1604 | |
|
|
1605 | psiconv_progress(lev+2,off+len, |
|
|
1606 | "Going to read the initial byte (%02x expected)",0x02); |
|
|
1607 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
1608 | if (res) |
|
|
1609 | goto ERROR2; |
|
|
1610 | if (temp != 0x02) { |
|
|
1611 | psiconv_warn(lev+2,off+len, |
|
|
1612 | "Sheet variable list initial byte unknown value (ignored)"); |
|
|
1613 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
1614 | } |
|
|
1615 | len ++; |
|
|
1616 | |
|
|
1617 | psiconv_progress(lev+2,off+len, |
|
|
1618 | "Going to read the number of variables"); |
|
|
1619 | listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
|
|
1620 | if (res) |
|
|
1621 | goto ERROR2; |
|
|
1622 | psiconv_debug(lev+2,off+len,"Number of variables: %d",listlen); |
|
|
1623 | len += leng; |
|
|
1624 | |
|
|
1625 | psiconv_progress(lev+2,off+len,"Going to read all variables"); |
|
|
1626 | for (i = 0; i < listlen; i++) { |
|
|
1627 | psiconv_progress(lev+3,off+len,"Going to read variable %d",i); |
|
|
1628 | if ((res = psiconv_parse_sheet_variable(buf,lev+3,off+len,&leng,&variable))) |
|
|
1629 | goto ERROR2; |
|
|
1630 | if ((res = psiconv_list_add(*result,variable))) |
|
|
1631 | goto ERROR3; |
|
|
1632 | len += leng; |
|
|
1633 | } |
|
|
1634 | |
|
|
1635 | if (length) |
|
|
1636 | *length = len; |
|
|
1637 | |
|
|
1638 | psiconv_progress(lev,off+len-1, |
|
|
1639 | "End of sheet variabels list (total length: %08x)", len); |
|
|
1640 | return 0; |
|
|
1641 | |
|
|
1642 | ERROR3: |
|
|
1643 | psiconv_free_sheet_variable(variable); |
|
|
1644 | ERROR2: |
|
|
1645 | psiconv_list_free(*result); |
|
|
1646 | ERROR1: |
|
|
1647 | psiconv_warn(lev+1,off,"Reading of Sheet Variable list failed"); |
|
|
1648 | if (length) |
|
|
1649 | *length = 0; |
|
|
1650 | if (!res) |
|
|
1651 | return -PSICONV_E_NOMEM; |
|
|
1652 | else |
|
|
1653 | return res; |
|
|
1654 | } |
|
|
1655 | |
|
|
1656 | int psiconv_parse_sheet_grid_section(const psiconv_buffer buf, int lev, |
|
|
1657 | psiconv_u32 off, int *length, |
|
|
1658 | psiconv_sheet_grid_section *result) |
|
|
1659 | { |
|
|
1660 | int res=0,i; |
|
|
1661 | int len=0,leng; |
|
|
1662 | psiconv_u32 temp; |
|
|
1663 | |
|
|
1664 | psiconv_progress(lev+1,off,"Going to read the sheet grid section"); |
|
|
1665 | if (!(*result = malloc(sizeof(**result)))) |
|
|
1666 | goto ERROR1; |
|
|
1667 | |
|
|
1668 | psiconv_progress(lev+2,off+len, "Going to read the first flags byte"); |
|
|
1669 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
1670 | if (res) |
|
|
1671 | goto ERROR2; |
|
|
1672 | (*result)->show_column_titles = temp&0x01?psiconv_bool_true: |
|
|
1673 | psiconv_bool_false; |
|
|
1674 | psiconv_debug(lev+2,off+len, |
|
|
1675 | "Show column titles: %s", |
|
|
1676 | (*result)->show_column_titles?"true":"false"); |
|
|
1677 | (*result)->show_row_titles = temp&0x02?psiconv_bool_true:psiconv_bool_false; |
|
|
1678 | psiconv_debug(lev+2,off+len, |
|
|
1679 | "Show row titles: %s", |
|
|
1680 | (*result)->show_row_titles?"true":"false"); |
|
|
1681 | (*result)->show_vertical_grid = temp&0x04?psiconv_bool_true: |
|
|
1682 | psiconv_bool_false; |
|
|
1683 | psiconv_debug(lev+2,off+len, |
|
|
1684 | "Show vertical grid: %s", |
|
|
1685 | (*result)->show_vertical_grid?"true":"false"); |
|
|
1686 | (*result)->show_horizontal_grid = temp&0x07?psiconv_bool_true: |
|
|
1687 | psiconv_bool_false; |
|
|
1688 | psiconv_debug(lev+2,off+len, |
|
|
1689 | "Show horizontal grid: %s", |
|
|
1690 | (*result)->show_horizontal_grid?"true":"false"); |
|
|
1691 | (*result)->freeze_rows = temp&0x80?psiconv_bool_true:psiconv_bool_false; |
|
|
1692 | psiconv_debug(lev+2,off+len, |
|
|
1693 | "Freeze rows: %s", |
|
|
1694 | (*result)->freeze_rows?"true":"false"); |
|
|
1695 | if ((temp & 0x70) != 0x30) { |
|
|
1696 | psiconv_warn(lev+2,off+len, |
|
|
1697 | "Grid section first flag byte has unknown bits (ignored)"); |
|
|
1698 | psiconv_debug(lev+2,off+len,"Bits: %02x (%02x expected)",temp&0x70,0x30); |
|
|
1699 | } |
|
|
1700 | len ++; |
|
|
1701 | |
|
|
1702 | psiconv_progress(lev+2,off+len, "Going to read the second flags byte"); |
|
|
1703 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
1704 | if (res) |
|
|
1705 | goto ERROR2; |
|
|
1706 | (*result)->freeze_columns = temp&0x01?psiconv_bool_true:psiconv_bool_false; |
|
|
1707 | psiconv_debug(lev+2,off+len, |
|
|
1708 | "Freeze columns: %s", (*result)->freeze_columns?"true":"false"); |
|
|
1709 | if ((temp & 0xfe) != 0x80) { |
|
|
1710 | psiconv_warn(lev+2,off+len, |
|
|
1711 | "Grid section second flag byte has unknown bits (ignored)"); |
|
|
1712 | psiconv_debug(lev+2,off+len,"Bits: %02x (%02x expected)",temp&0xfe,0x80); |
|
|
1713 | } |
|
|
1714 | len ++; |
|
|
1715 | |
|
|
1716 | psiconv_progress(lev+2,off+len, |
|
|
1717 | "Going to an unknown byte (%02x expected)",0x90); |
|
|
1718 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
1719 | if (res) |
|
|
1720 | goto ERROR2; |
|
|
1721 | if (temp != 0x90) { |
|
|
1722 | psiconv_warn(lev+2,off+len, |
|
|
1723 | "Grid section third byte unknown value (ignored)"); |
|
|
1724 | psiconv_debug(lev+2,off+len,"Value: %02x",temp); |
|
|
1725 | } |
|
|
1726 | len ++; |
|
|
1727 | |
|
|
1728 | psiconv_progress(lev+2,off+len, "Going to read the fourth flags byte"); |
|
|
1729 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
1730 | if (res) |
|
|
1731 | goto ERROR2; |
|
|
1732 | (*result)->show_page_breaks = temp&0x04?psiconv_bool_true:psiconv_bool_false; |
|
|
1733 | psiconv_debug(lev+2,off+len, |
|
|
1734 | "Show page breaks: %s", |
|
|
1735 | (*result)->show_page_breaks?"true":"false"); |
|
|
1736 | if ((temp & 0xfc) != 0x00) { |
|
|
1737 | psiconv_warn(lev+2,off+len, |
|
|
1738 | "Grid section fourth flag byte has unknown bits (ignored)"); |
|
|
1739 | psiconv_debug(lev+2,off+len,"Bits: %02x (%02x expected)",temp&0xfc,0x00); |
|
|
1740 | } |
|
|
1741 | len ++; |
|
|
1742 | |
|
|
1743 | psiconv_progress(lev+2,off+len,"Going to read the first visible row"); |
|
|
1744 | (*result)->first_row = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
1745 | if (res) |
|
|
1746 | goto ERROR2; |
|
|
1747 | psiconv_debug(lev+2,off+len,"First row: %d",(*result)->first_row); |
|
|
1748 | len += 4; |
|
|
1749 | |
|
|
1750 | psiconv_progress(lev+2,off+len,"Going to read the first visible column"); |
|
|
1751 | (*result)->first_column = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
1752 | if (res) |
|
|
1753 | goto ERROR2; |
|
|
1754 | psiconv_debug(lev+2,off+len,"First column: %d",(*result)->first_column); |
|
|
1755 | len += 4; |
|
|
1756 | |
|
|
1757 | psiconv_progress(lev+2,off+len,"Going to read the last visible row"); |
|
|
1758 | (*result)->last_row = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
1759 | if (res) |
|
|
1760 | goto ERROR2; |
|
|
1761 | psiconv_debug(lev+2,off+len,"Last row: %d",(*result)->last_row); |
|
|
1762 | len += 4; |
|
|
1763 | |
|
|
1764 | psiconv_progress(lev+2,off+len,"Going to read the last visible column"); |
|
|
1765 | (*result)->last_column = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
1766 | if (res) |
|
|
1767 | goto ERROR2; |
|
|
1768 | psiconv_debug(lev+2,off+len,"Last column: %d",(*result)->last_column); |
|
|
1769 | len += 4; |
|
|
1770 | |
|
|
1771 | psiconv_progress(lev+2,off+len,"Going to read the default row height"); |
|
|
1772 | (*result)->default_row_height = psiconv_read_length(buf,lev+2,off+len, |
|
|
1773 | &leng,&res); |
|
|
1774 | if (res) |
|
|
1775 | goto ERROR2; |
|
|
1776 | psiconv_debug(lev+2,off+len,"Default row height: %f", |
|
|
1777 | (*result)->default_row_height); |
|
|
1778 | len += leng; |
|
|
1779 | |
|
|
1780 | psiconv_progress(lev+2,off+len,"Going to read the row heights list"); |
|
|
1781 | if ((res = psiconv_parse_sheet_grid_size_list(buf,lev+2,off+len,&leng, |
|
|
1782 | &(*result)->row_heights))) |
|
|
1783 | goto ERROR2; |
|
|
1784 | len += leng; |
|
|
1785 | |
|
|
1786 | psiconv_progress(lev+2,off+len,"Going to read the default column height"); |
|
|
1787 | (*result)->default_column_width = psiconv_read_length(buf,lev+2,off+len, |
|
|
1788 | &leng,&res); |
|
|
1789 | if (res) |
|
|
1790 | goto ERROR3; |
|
|
1791 | psiconv_debug(lev+2,off+len,"Default column width: %f", |
|
|
1792 | (*result)->default_column_width); |
|
|
1793 | len += leng; |
|
|
1794 | |
|
|
1795 | psiconv_progress(lev+2,off+len,"Going to read the column heights list"); |
|
|
1796 | if ((res = psiconv_parse_sheet_grid_size_list(buf,lev+2,off+len,&leng, |
|
|
1797 | &(*result)->column_heights))) |
|
|
1798 | goto ERROR3; |
|
|
1799 | len += leng; |
|
|
1800 | |
|
|
1801 | psiconv_progress(lev+2,off+len, |
|
|
1802 | "Going to read an unknown word (%04x expected)",0x00); |
|
|
1803 | temp = psiconv_read_u16(buf,lev+2,off+len,&res); |
|
|
1804 | if (res) |
|
|
1805 | goto ERROR4; |
|
|
1806 | if (temp != 0x00) { |
|
|
1807 | psiconv_warn(lev+2,off+len, |
|
|
1808 | "Grid section unknown word has unknown value (ignored)"); |
|
|
1809 | psiconv_debug(lev+2,off+len,"Value: %04x",temp); |
|
|
1810 | } |
|
|
1811 | len += 2; |
|
|
1812 | |
|
|
1813 | psiconv_progress(lev+2,off+len,"Going to read the row breaks list"); |
|
|
1814 | if ((res = psiconv_parse_sheet_grid_break_list(buf,lev+2,off+len,&leng, |
|
|
1815 | &(*result)->row_page_breaks))) |
|
|
1816 | goto ERROR4; |
|
|
1817 | len += leng; |
|
|
1818 | |
|
|
1819 | psiconv_progress(lev+2,off+len,"Going to read the column breaks list"); |
|
|
1820 | if ((res = psiconv_parse_sheet_grid_break_list(buf,lev+2,off+len,&leng, |
|
|
1821 | &(*result)->column_page_breaks))) |
|
|
1822 | goto ERROR5; |
|
|
1823 | len += leng; |
|
|
1824 | |
|
|
1825 | |
|
|
1826 | psiconv_progress(lev+2,off+len, |
|
|
1827 | "Going to read 22 unknown bytes (%02x expected)",0x00); |
|
|
1828 | for (i = 0; i < 22 ; i++) { |
|
|
1829 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
1830 | if (res) |
|
|
1831 | goto ERROR6; |
|
|
1832 | if (temp != 0x00) { |
|
|
1833 | psiconv_warn(lev+2,off+len, |
|
|
1834 | "Grid section unknown byte %d has unknown value (ignored)", |
|
|
1835 | i); |
|
|
1836 | psiconv_debug(lev+2,off+len,"Value: %02x",temp); |
|
|
1837 | } |
|
|
1838 | len += 1; |
|
|
1839 | } |
|
|
1840 | |
|
|
1841 | if ((*result)->freeze_rows || (*result)->freeze_columns) { |
|
|
1842 | |
|
|
1843 | psiconv_progress(lev+2,off+len,"Going to read number of frozen rows"); |
|
|
1844 | (*result)->frozen_rows = psiconv_read_u32(buf,lev+2,off+len, &res); |
|
|
1845 | if (res) |
|
|
1846 | goto ERROR6; |
|
|
1847 | psiconv_debug(lev+2,off+len,"Number of frozen rows: %d", |
|
|
1848 | (*result)->frozen_rows); |
|
|
1849 | len += leng; |
|
|
1850 | |
|
|
1851 | psiconv_progress(lev+2,off+len,"Going to read number of frozen columns"); |
|
|
1852 | (*result)->frozen_columns = psiconv_read_u32(buf,lev+2,off+len, &res); |
|
|
1853 | if (res) |
|
|
1854 | goto ERROR6; |
|
|
1855 | psiconv_debug(lev+2,off+len,"Number of frozen columns: %d", |
|
|
1856 | (*result)->frozen_columns); |
|
|
1857 | len += leng; |
|
|
1858 | |
|
|
1859 | psiconv_progress(lev+2,off+len,"Going to read first unfrozen row"); |
|
|
1860 | (*result)->first_unfrozen_row_displayed = psiconv_read_u32(buf,lev+2, |
|
|
1861 | off+len, &res); |
|
|
1862 | if (res) |
|
|
1863 | goto ERROR6; |
|
|
1864 | psiconv_debug(lev+2,off+len,"First row: %d", |
|
|
1865 | (*result)->first_unfrozen_row_displayed); |
|
|
1866 | len += leng; |
|
|
1867 | |
|
|
1868 | psiconv_progress(lev+2,off+len,"Going to read first unfrozen column"); |
|
|
1869 | (*result)->first_unfrozen_column_displayed = psiconv_read_u32(buf,lev+2, |
|
|
1870 | off+len,&res); |
|
|
1871 | if (res) |
|
|
1872 | goto ERROR6; |
|
|
1873 | psiconv_debug(lev+2,off+len,"First column: %d", |
|
|
1874 | (*result)->first_unfrozen_column_displayed); |
|
|
1875 | len += leng; |
|
|
1876 | } else |
|
|
1877 | (*result)->frozen_rows = (*result)->frozen_columns = |
|
|
1878 | (*result)->first_unfrozen_row_displayed = |
|
|
1879 | (*result)->first_unfrozen_column_displayed = 0; |
|
|
1880 | |
|
|
1881 | psiconv_progress(lev+2,off+len, |
|
|
1882 | "Going to read 3 unknown bytes (%02x expected)",0xff); |
|
|
1883 | for (i = 0; i < 3 ; i++) { |
|
|
1884 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
1885 | if (res) |
|
|
1886 | goto ERROR6; |
|
|
1887 | if (temp != 0xff) { |
|
|
1888 | psiconv_warn(lev+2,off+len, |
|
|
1889 | "Grid section unknown byte %d has unknown value (ignored)", |
|
|
1890 | i); |
|
|
1891 | psiconv_debug(lev+2,off+len,"Value: %02x",temp); |
|
|
1892 | } |
|
|
1893 | len ++; |
|
|
1894 | } |
|
|
1895 | |
|
|
1896 | if (length) |
|
|
1897 | *length = len; |
|
|
1898 | |
|
|
1899 | psiconv_progress(lev,off+len-1, |
|
|
1900 | "End of sheet grid section (total length: %08x)", len); |
|
|
1901 | return 0; |
|
|
1902 | |
|
|
1903 | ERROR6: |
|
|
1904 | psiconv_free_sheet_grid_break_list((*result)->column_page_breaks); |
|
|
1905 | ERROR5: |
|
|
1906 | psiconv_free_sheet_grid_break_list((*result)->row_page_breaks); |
|
|
1907 | ERROR4: |
|
|
1908 | psiconv_free_sheet_grid_size_list((*result)->column_heights); |
|
|
1909 | ERROR3: |
|
|
1910 | psiconv_free_sheet_grid_size_list((*result)->row_heights); |
|
|
1911 | ERROR2: |
|
|
1912 | free(*result); |
|
|
1913 | ERROR1: |
|
|
1914 | psiconv_warn(lev+1,off,"Reading of Sheet Grid Section failed"); |
|
|
1915 | if (length) |
|
|
1916 | *length = 0; |
|
|
1917 | if (!res) |
|
|
1918 | return -PSICONV_E_NOMEM; |
|
|
1919 | else |
|
|
1920 | return res; |
|
|
1921 | } |
|
|
1922 | |
|
|
1923 | |
|
|
1924 | int psiconv_parse_sheet_grid_size_list(const psiconv_buffer buf, int lev, |
|
|
1925 | psiconv_u32 off, int *length, |
|
|
1926 | psiconv_sheet_grid_size_list *result) |
|
|
1927 | { |
|
|
1928 | int res=0; |
|
|
1929 | int len=0,i; |
|
|
1930 | int leng,listlen; |
|
|
1931 | psiconv_sheet_grid_size size; |
|
|
1932 | |
|
|
1933 | psiconv_progress(lev+1,off,"Going to read a sheet grid size list"); |
|
|
1934 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_grid_size_s)))) |
|
|
1935 | goto ERROR1; |
|
|
1936 | |
|
|
1937 | psiconv_progress(lev+2,off+len, |
|
|
1938 | "Going to read the number of elements"); |
|
|
1939 | listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
|
|
1940 | if (res) |
|
|
1941 | goto ERROR2; |
|
|
1942 | psiconv_debug(lev+2,off+len,"Number of elements: %d",listlen); |
|
|
1943 | len += leng; |
|
|
1944 | |
|
|
1945 | psiconv_progress(lev+2,off+len,"Going to read all elements"); |
|
|
1946 | for (i = 0; i < listlen; i++) { |
|
|
1947 | psiconv_progress(lev+3,off+len,"Going to read element %d",i); |
|
|
1948 | if ((res = psiconv_parse_sheet_grid_size(buf,lev+3,off+len,&leng,&size))) |
|
|
1949 | goto ERROR2; |
|
|
1950 | if ((res = psiconv_list_add(*result,size))) |
|
|
1951 | goto ERROR3; |
|
|
1952 | free(size); |
|
|
1953 | len += leng; |
|
|
1954 | } |
|
|
1955 | |
|
|
1956 | if (length) |
|
|
1957 | *length = len; |
|
|
1958 | |
|
|
1959 | psiconv_progress(lev,off+len-1, |
|
|
1960 | "End of sheet grid size list (total length: %08x)", len); |
|
|
1961 | return 0; |
|
|
1962 | |
|
|
1963 | ERROR3: |
|
|
1964 | psiconv_free_sheet_grid_size(size); |
|
|
1965 | ERROR2: |
|
|
1966 | psiconv_list_free(*result); |
|
|
1967 | ERROR1: |
|
|
1968 | psiconv_warn(lev+1,off,"Reading of Sheet Grid Size List failed"); |
|
|
1969 | if (length) |
|
|
1970 | *length = 0; |
|
|
1971 | if (!res) |
|
|
1972 | return -PSICONV_E_NOMEM; |
|
|
1973 | else |
|
|
1974 | return res; |
|
|
1975 | } |
|
|
1976 | |
|
|
1977 | int psiconv_parse_sheet_grid_size(const psiconv_buffer buf, int lev, |
|
|
1978 | psiconv_u32 off, int *length, |
|
|
1979 | psiconv_sheet_grid_size *result) |
|
|
1980 | { |
|
|
1981 | int res=0; |
|
|
1982 | int len=0; |
|
|
1983 | int leng; |
|
|
1984 | |
|
|
1985 | psiconv_progress(lev+1,off,"Going to read a sheet grid size"); |
|
|
1986 | |
|
|
1987 | if (!(*result = malloc(sizeof(**result)))) |
|
|
1988 | goto ERROR1; |
|
|
1989 | |
|
|
1990 | psiconv_progress(lev+2,off+len, "Going to read the row or column number"); |
|
|
1991 | (*result)->line_number = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
1992 | if (res) |
|
|
1993 | goto ERROR2; |
|
|
1994 | psiconv_debug(lev+2,off+len,"Line number: %d\n",(*result)->line_number); |
|
|
1995 | len += 4; |
|
|
1996 | |
|
|
1997 | psiconv_progress(lev+2,off+len, "Going to read the row or column height"); |
|
|
1998 | (*result)->size = psiconv_read_length(buf,lev+2,off+len,&leng,&res); |
|
|
1999 | if (res) |
|
|
2000 | goto ERROR2; |
|
|
2001 | psiconv_debug(lev+2,off+len,"Size: %f\n",(*result)->size); |
|
|
2002 | len += leng; |
|
|
2003 | |
|
|
2004 | if (length) |
|
|
2005 | *length = len; |
|
|
2006 | |
|
|
2007 | psiconv_progress(lev,off+len-1, |
|
|
2008 | "End of sheet grid size(total length: %08x)", len); |
|
|
2009 | return 0; |
|
|
2010 | |
|
|
2011 | ERROR2: |
|
|
2012 | free (*result); |
|
|
2013 | ERROR1: |
|
|
2014 | psiconv_warn(lev+1,off,"Reading of Sheet Grid Size failed"); |
|
|
2015 | if (length) |
|
|
2016 | *length = 0; |
|
|
2017 | if (!res) |
|
|
2018 | return -PSICONV_E_NOMEM; |
|
|
2019 | else |
|
|
2020 | return res; |
|
|
2021 | } |
|
|
2022 | |
|
|
2023 | |
|
|
2024 | int psiconv_parse_sheet_grid_break_list(const psiconv_buffer buf, int lev, |
|
|
2025 | psiconv_u32 off, int *length, |
|
|
2026 | psiconv_sheet_grid_break_list *result) |
|
|
2027 | { |
|
|
2028 | int res=0; |
|
|
2029 | int len=0,i; |
|
|
2030 | int leng,listlen; |
|
|
2031 | psiconv_u32 nr; |
|
|
2032 | |
|
|
2033 | psiconv_progress(lev+1,off,"Going to read a sheet grid break list"); |
|
|
2034 | if (!(*result = psiconv_list_new(sizeof(psiconv_u32)))) |
|
|
2035 | goto ERROR1; |
|
|
2036 | |
|
|
2037 | psiconv_progress(lev+2,off+len, |
|
|
2038 | "Going to read the number of elements"); |
|
|
2039 | listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
|
|
2040 | if (res) |
|
|
2041 | goto ERROR2; |
|
|
2042 | psiconv_debug(lev+2,off+len,"Number of elements: %d",listlen); |
|
|
2043 | len += leng; |
|
|
2044 | |
|
|
2045 | psiconv_progress(lev+2,off+len,"Going to read all elements"); |
|
|
2046 | for (i = 0; i < listlen; i++) { |
|
|
2047 | psiconv_progress(lev+3,off+len,"Going to read element %d",i); |
|
|
2048 | nr = psiconv_read_u32(buf,lev+3,off+len,&res); |
|
|
2049 | if (res) |
|
|
2050 | goto ERROR2; |
|
|
2051 | if ((res = psiconv_list_add(*result,&nr))) |
|
|
2052 | goto ERROR2; |
|
|
2053 | len += leng; |
|
|
2054 | } |
|
|
2055 | |
|
|
2056 | if (length) |
|
|
2057 | *length = len; |
|
|
2058 | |
|
|
2059 | psiconv_progress(lev,off+len-1, |
|
|
2060 | "End of sheet grid break list (total length: %08x)", len); |
|
|
2061 | return 0; |
|
|
2062 | |
|
|
2063 | ERROR2: |
|
|
2064 | psiconv_list_free(*result); |
|
|
2065 | ERROR1: |
|
|
2066 | psiconv_warn(lev+1,off,"Reading of Sheet Grid break List failed"); |
|
|
2067 | if (length) |
|
|
2068 | *length = 0; |
|
|
2069 | if (!res) |
|
|
2070 | return -PSICONV_E_NOMEM; |
|
|
2071 | else |
|
|
2072 | return res; |
|
|
2073 | } |
|
|
2074 | |