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