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

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

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

Revision 128 Revision 129
72 psiconv_free_character_layout(result->character); 72 psiconv_free_character_layout(result->character);
73ERROR2: 73ERROR2:
74 free(result); 74 free(result);
75ERROR1: 75ERROR1:
76 return NULL; 76 return NULL;
77}
78
79static 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;
130ERROR1:
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
139static 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;
213ERROR1:
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
79int psiconv_parse_sheet_numberformat(const psiconv_buffer buf, int lev, 222int 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
355int psiconv_parse_sheet_workbook_section(const psiconv_buffer buf, int lev, 498int 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 $02xexpected)",
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,
404 "Going to read the offset of the 4th ??? Section"); 549 "Going to read the offset of the Variable List");
405 temp = psiconv_read_u32(buf,lev+2,off+len,&res); 550 var_off = psiconv_read_u32(buf,lev+2,off+len,&res);
406 if (res) 551 if (res)
407 goto ERROR2; 552 goto ERROR2;
408 psiconv_debug(lev+2,off+len,"Offset: %04x",temp); 553 psiconv_debug(lev+2,off+len,"Offset: %04x",var_off);
409 len += 4; 554 len += 4;
410 555
556 if (with_name) {
557 psiconv_progress(lev+2,off+len,
558 "Going to read the offset of the Name Section");
559 name_off = psiconv_read_u32(buf,lev+2,off+len,&res);
560 if (res)
561 goto ERROR2;
562 psiconv_debug(lev+2,off+len,"Offset: %04x",name_off);
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;
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
590 if ((res = psiconv_parse_sheet_name_section(buf,lev+2,name_off,NULL,
591 &(*result)->name)))
592 goto ERROR6;
593 } else
594 (*result)->name = NULL;
421 595
422 if (length) 596 if (length)
423 *length = len; 597 *length = len;
424 598
425 psiconv_progress(lev,off+len-1, 599 psiconv_progress(lev,off+len-1,
426 "End of sheet workbook section (total length: %08x)", len); 600 "End of sheet workbook section (total length: %08x)", len);
427 return 0; 601 return 0;
428 602
603ERROR6:
604 psiconv_free_sheet_worksheet_list((*result)->worksheets);
605ERROR5:
606 psiconv_free_formula_list((*result)->formulas);
607ERROR4:
608 psiconv_free_sheet_variable_list((*result)->variables);
609ERROR3:
610 psiconv_free_sheet_info_section((*result)->info);
429ERROR2: 611ERROR2:
430 free (*result); 612 free (*result);
431ERROR1: 613ERROR1:
432 psiconv_warn(lev+1,off,"Reading of Sheet Workbook Section failed"); 614 psiconv_warn(lev+1,off,"Reading of Sheet Workbook Section failed");
433 if (length) 615 if (length)
436 return -PSICONV_E_NOMEM; 618 return -PSICONV_E_NOMEM;
437 else 619 else
438 return res; 620 return res;
439} 621}
440 622
623int psiconv_parse_sheet_name_section(const psiconv_buffer buf, int lev,
624 psiconv_u32 off, int *length,
625 psiconv_sheet_name_section *result)
626{
627 int res=0;
628 psiconv_u32 temp;
629 int len=0,leng;
630
631 psiconv_progress(lev+1,off,"Going to read the sheet name section");
632 if (!(*result = malloc(sizeof(**result))))
633 goto ERROR1;
634
635 psiconv_progress(lev+2,off+len,
636 "Going to read the initial byte (%02x expected)",0x02);
637 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
638 if (res)
639 goto ERROR2;
640 if (temp != 0x02) {
641 psiconv_warn(lev+2,off+len,
642 "Sheet name section initial byte unknown value (ignored)");
643 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
644 }
645 len ++;
646
647 psiconv_progress(lev+2,off+len, "Going to read the sheet name");
648 (*result)->name = psiconv_read_string(buf,lev+2,off+len,&leng,&res);
649 if (res)
650 goto ERROR2;
651 len += leng;
652
653 if (length)
654 *length = len;
655
656 psiconv_progress(lev,off+len-1,
657 "End of sheet name section (total length: %08x)", len);
658 return 0;
659
660ERROR2:
661 free(*result);
662ERROR1:
663 psiconv_warn(lev+1,off,"Reading of Sheet Name Section failed");
664 if (length)
665 *length = 0;
666 if (!res)
667 return -PSICONV_E_NOMEM;
668 else
669 return res;
670}
671
672int psiconv_parse_sheet_info_section(const psiconv_buffer buf, int lev,
673 psiconv_u32 off, int *length,
674 psiconv_sheet_info_section *result)
675{
676 int res=0;
677 psiconv_u32 temp;
678 int len=0;
679
680 psiconv_progress(lev+1,off,"Going to read the sheet info section");
681 if (!(*result = malloc(sizeof(**result))))
682 goto ERROR1;
683
684 psiconv_progress(lev+2,off+len,
685 "Going to read the initial byte (%02x expected)",0x02);
686 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
687 if (res)
688 goto ERROR2;
689 if (temp != 0x02) {
690 psiconv_warn(lev+2,off+len,
691 "Sheet info section initial byte unknown value (ignored)");
692 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
693 }
694 len ++;
695
696 psiconv_progress(lev+2,off+len, "Going to read the flags byte");
697 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
698 if (res)
699 goto ERROR2;
700 (*result)->auto_recalc = temp & 0x01 ? psiconv_bool_true:psiconv_bool_false;
701 psiconv_debug(lev+2,off+len,"Auto recalculation: %02x",
702 (*result)->auto_recalc);
703 if ((temp & 0xfe) != 0x02) {
704 psiconv_warn(lev+2,off+len,"Sheet Info Section flags byte "
705 "contains unknown flags (ignored)");
706 psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp &0xfe);
707 }
708
709 len ++;
710
711
712 if (length)
713 *length = len;
714
715 psiconv_progress(lev,off+len-1,
716 "End of sheet info section (total length: %08x)", len);
717 return 0;
718
719ERROR2:
720 free(*result);
721ERROR1:
722 psiconv_warn(lev+1,off,"Reading of Sheet Name Section failed");
723 if (length)
724 *length = 0;
725 if (!res)
726 return -PSICONV_E_NOMEM;
727 else
728 return res;
729}
730
441int psiconv_parse_sheet_formula_table(const psiconv_buffer buf, int lev, 731int psiconv_parse_sheet_formula_list(const psiconv_buffer buf, int lev,
442 psiconv_u32 off, int *length, 732 psiconv_u32 off, int *length,
443 psiconv_formula_list *result) 733 psiconv_formula_list *result)
444{ 734{
445 int res=0; 735 int res=0;
446 int len=0; 736 int len=0;
447 psiconv_u32 temp; 737 psiconv_u32 temp;
448 psiconv_formula formula; 738 psiconv_formula formula;
449 psiconv_u32 listlen,i; 739 psiconv_u32 listlen,i;
450 int leng; 740 int leng;
451 741
452 psiconv_progress(lev+1,off,"Going to read the sheet formula table"); 742 psiconv_progress(lev+1,off,"Going to read the sheet formula list");
453 if (!(*result = psiconv_list_new(sizeof(struct psiconv_formula_s)))) 743 if (!(*result = psiconv_list_new(sizeof(struct psiconv_formula_s))))
454 goto ERROR1; 744 goto ERROR1;
455 745
456 psiconv_progress(lev+2,off+len, 746 psiconv_progress(lev+2,off+len,
457 "Going to read the initial byte (%02x expected)",0x02); 747 "Going to read the initial byte (%02x expected)",0x02);
458 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 748 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
459 if (res) 749 if (res)
460 goto ERROR2; 750 goto ERROR2;
461 if (temp != 0x02) { 751 if (temp != 0x02) {
462 psiconv_warn(lev+2,off+len, 752 psiconv_warn(lev+2,off+len,
463 "Sheet formula table initial byte unknown value (ignored)"); 753 "Sheet formula list initial byte unknown value (ignored)");
464 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); 754 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
465 } 755 }
466 len ++; 756 len ++;
467 757
468 psiconv_progress(lev+2,off+len, 758 psiconv_progress(lev+2,off+len,
485 775
486 if (length) 776 if (length)
487 *length = len; 777 *length = len;
488 778
489 psiconv_progress(lev,off+len-1, 779 psiconv_progress(lev,off+len-1,
490 "End of sheet formula table (total length: %08x)", len); 780 "End of sheet formula list (total length: %08x)", len);
491 return 0; 781 return 0;
492 782
493ERROR3: 783ERROR3:
494 psiconv_free_formula(formula); 784 psiconv_free_formula(formula);
495ERROR2: 785ERROR2:
496 psiconv_list_free(*result); 786 psiconv_list_free(*result);
497ERROR1: 787ERROR1:
498 psiconv_warn(lev+1,off,"Reading of Sheet Formula Table failed"); 788 psiconv_warn(lev+1,off,"Reading of Sheet Formula list failed");
499 if (length) 789 if (length)
500 *length = 0; 790 *length = 0;
501 if (!res) 791 if (!res)
502 return -PSICONV_E_NOMEM; 792 return -PSICONV_E_NOMEM;
503 else 793 else
1162 return -PSICONV_E_NOMEM; 1452 return -PSICONV_E_NOMEM;
1163 else 1453 else
1164 return res; 1454 return res;
1165} 1455}
1166 1456
1457int psiconv_parse_sheet_variable(const psiconv_buffer buf, int lev,
1458 psiconv_u32 off, int *length,
1459 psiconv_sheet_variable *result)
1460{
1461 int res=0;
1462 int len=0;
1463 psiconv_u32 marker;
1464 int leng;
1465
1466 psiconv_progress(lev+1,off,"Going to read a sheet variable");
1467 if (!(*result = malloc(sizeof(**result))))
1468 goto ERROR1;
1469
1470 psiconv_progress(lev+2,off+len, "Going to read the variable name");
1471 (*result)->name = psiconv_read_string(buf,lev+2,off+len,&leng,&res);
1472 if (res)
1473 goto ERROR2;
1474 len += leng;
1475
1476 psiconv_progress(lev+2,off+len,"Going to read the type marker");
1477 marker = psiconv_read_u8(buf,lev+2,off+len,&res);
1478 if (res)
1479 goto ERROR3;
1480 psiconv_debug(lev+2,off+len,"Marker: %02x",marker);
1481 len ++;
1482
1483 if (marker == 0x00) {
1484 (*result)->type = psiconv_var_int;
1485 psiconv_progress(lev+2,off+len,"Going to read a signed integer");
1486 (*result)->data.dat_int = psiconv_read_sint(buf,lev+2,off+len,&leng,&res);
1487 if (res)
1488 goto ERROR3;
1489 psiconv_debug(lev+2,off+len,"Value: %d",(*result)->data.dat_int);
1490 len += leng;
1491 } else if (marker == 0x01) {
1492 (*result)->type = psiconv_var_float;
1493 psiconv_progress(lev+2,off+len,"Going to read a floating point number");
1494 (*result)->data.dat_float = psiconv_read_float(buf,lev+2,off+len,&leng,
1495 &res);
1496 if (res)
1497 goto ERROR3;
1498 psiconv_debug(lev+2,off+len,"Value: %f",(*result)->data.dat_float);
1499 len += leng;
1500 } else if (marker == 0x02) {
1501 (*result)->type = psiconv_var_string;
1502 psiconv_progress(lev+2,off+len,"Going to read a string");
1503 (*result)->data.dat_string = psiconv_read_string(buf,lev+2,off+len,&leng,
1504 &res);
1505 if (res)
1506 goto ERROR3;
1507 len += leng;
1508 } else if (marker == 0x03) {
1509 (*result)->type = psiconv_var_cellref;
1510 psiconv_progress(lev+2,off+len,"Going to read a cell reference");
1511 (*result)->data.dat_cellref = psiconv_read_var_cellref(buf,lev+2,off+len,
1512 &leng, &res);
1513 if (res)
1514 goto ERROR3;
1515 len += leng;
1516 } else if (marker == 0x04) {
1517 (*result)->type = psiconv_var_cellblock;
1518 psiconv_progress(lev+2,off+len,"Going to read a cell block reference");
1519 (*result)->data.dat_cellblock = psiconv_read_var_cellblock(buf,lev+2,
1520 off+len,
1521 &leng, &res);
1522 if (res)
1523 goto ERROR3;
1524 len += leng;
1525 } else {
1526 psiconv_warn(lev+2,off+len,"Sheet variable unknown type marker");
1527 res = -PSICONV_E_PARSE;
1528 goto ERROR3;
1529 }
1530
1531 psiconv_progress(lev+2,off+len,"Going to read the variable number");
1532 (*result)->number = psiconv_read_u32(buf,lev+2,off+len,&res);
1533 if (res)
1534 goto ERROR4;
1535 psiconv_debug(lev+2,off+len,"Number: %08x",(*result)->number);
1536 len += 4;
1537
1538 if (length)
1539 *length = len;
1540
1541 psiconv_progress(lev,off+len-1,
1542 "End of sheet variable (total length: %08x)", len);
1543 return 0;
1544
1545ERROR4:
1546 if ((*result)->type == psiconv_var_string)
1547 free((*result)->data.dat_string);
1548ERROR3:
1549 free((*result)->name);
1550ERROR2:
1551 free (*result);
1552ERROR1:
1553 psiconv_warn(lev+1,off,"Reading of Sheet Variable failed");
1554 if (length)
1555 *length = 0;
1556 if (!res)
1557 return -PSICONV_E_NOMEM;
1558 else
1559 return res;
1560}
1561
1562
1563int psiconv_parse_sheet_variable_list(const psiconv_buffer buf, int lev,
1564 psiconv_u32 off, int *length,
1565 psiconv_sheet_variable_list *result)
1566{
1567 int res=0;
1568 int len=0;
1569 psiconv_u32 temp;
1570 psiconv_sheet_variable variable;
1571 psiconv_u32 listlen,i;
1572 int leng;
1573
1574 psiconv_progress(lev+1,off,"Going to read the sheet variable list");
1575 if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_variable_s))))
1576 goto ERROR1;
1577
1578 psiconv_progress(lev+2,off+len,
1579 "Going to read the initial byte (%02x expected)",0x02);
1580 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
1581 if (res)
1582 goto ERROR2;
1583 if (temp != 0x02) {
1584 psiconv_warn(lev+2,off+len,
1585 "Sheet variable list initial byte unknown value (ignored)");
1586 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
1587 }
1588 len ++;
1589
1590 psiconv_progress(lev+2,off+len,
1591 "Going to read the number of variables");
1592 listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res);
1593 if (res)
1594 goto ERROR2;
1595 psiconv_debug(lev+2,off+len,"Number of variables: %d",listlen);
1596 len += leng;
1597
1598 psiconv_progress(lev+2,off+len,"Going to read all variables");
1599 for (i = 0; i < listlen; i++) {
1600 psiconv_progress(lev+3,off+len,"Going to read variable %d",i);
1601 if ((res = psiconv_parse_sheet_variable(buf,lev+3,off+len,&leng,&variable)))
1602 goto ERROR2;
1603 if ((res = psiconv_list_add(*result,variable)))
1604 goto ERROR3;
1605 len += leng;
1606 }
1607
1608 if (length)
1609 *length = len;
1610
1611 psiconv_progress(lev,off+len-1,
1612 "End of sheet variabels list (total length: %08x)", len);
1613 return 0;
1614
1615ERROR3:
1616 psiconv_free_sheet_variable(variable);
1617ERROR2:
1618 psiconv_list_free(*result);
1619ERROR1:
1620 psiconv_warn(lev+1,off,"Reading of Sheet Variable list failed");
1621 if (length)
1622 *length = 0;
1623 if (!res)
1624 return -PSICONV_E_NOMEM;
1625 else
1626 return res;
1627}

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

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