/[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 110 Revision 111
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
28int psiconv_parse_sheet_numberformat(const psiconv_buffer buf, int lev,
29 psiconv_u32 off, int *length,
30 psiconv_sheet_numberformat *result)
31{
32 int res=0;
33 int len=0;
34 psiconv_u8 temp;
35
36 psiconv_progress(lev+1,off,"Going to read a sheet numberformat");
37 if (!(*result = malloc(sizeof(**result))))
38 goto ERROR1;
39
40 psiconv_progress(lev+2,off+len,
41 "Going to read the initial byte (%02x expected)",0x02);
42 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
43 if (res)
44 goto ERROR2;
45 if (temp != 0x02) {
46 psiconv_warn(lev+2,off+len,
47 "Sheet numberformat initial byte unknown value (ignored)");
48 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
49 }
50 len ++;
51
52 psiconv_progress(lev+2,off+len, "Going to read the code byte");
53 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
54 if (res)
55 goto ERROR2;
56 psiconv_debug(lev+2,off+len,"Code: %02x",temp);
57 if (temp == 0x00)
58 (*result)->code = psiconv_numberformat_general;
59 else if (temp == 0x02)
60 (*result)->code = psiconv_numberformat_fixeddecimal;
61 else if (temp == 0x04)
62 (*result)->code = psiconv_numberformat_scientific;
63 else if (temp == 0x06)
64 (*result)->code = psiconv_numberformat_currency;
65 else if (temp == 0x08)
66 (*result)->code = psiconv_numberformat_percent;
67 else if (temp == 0x0A)
68 (*result)->code = psiconv_numberformat_triads;
69 else if (temp == 0x0C)
70 (*result)->code = psiconv_numberformat_boolean;
71 else if (temp == 0x0E)
72 (*result)->code = psiconv_numberformat_text;
73 else if (temp == 0x10)
74 (*result)->code = psiconv_numberformat_date_ddmm;
75 else if (temp == 0x12)
76 (*result)->code = psiconv_numberformat_date_mmdd;
77 else if (temp == 0x14)
78 (*result)->code = psiconv_numberformat_date_ddmmyy;
79 else if (temp == 0x16)
80 (*result)->code = psiconv_numberformat_date_mmddyy;
81 else if (temp == 0x18)
82 (*result)->code = psiconv_numberformat_date_yymmdd;
83 else if (temp == 0x1A)
84 (*result)->code = psiconv_numberformat_date_ddmmm;
85 else if (temp == 0x1C)
86 (*result)->code = psiconv_numberformat_date_ddmmmyy;
87 else if (temp == 0x1E)
88 (*result)->code = psiconv_numberformat_date_ddmmmyyyy;
89 else if (temp == 0x20)
90 (*result)->code = psiconv_numberformat_date_mmm;
91 else if (temp == 0x22)
92 (*result)->code = psiconv_numberformat_date_monthname;
93 else if (temp == 0x24)
94 (*result)->code = psiconv_numberformat_date_mmmyy;
95 else if (temp == 0x26)
96 (*result)->code = psiconv_numberformat_date_monthnameyy;
97 else if (temp == 0x28)
98 (*result)->code = psiconv_numberformat_date_monthnameddyyyy;
99 else if (temp == 0x2A)
100 (*result)->code = psiconv_numberformat_datetime_ddmmyyyyhhii;
101 else if (temp == 0x2C)
102 (*result)->code = psiconv_numberformat_datetime_ddmmyyyyHHii;
103 else if (temp == 0x2E)
104 (*result)->code = psiconv_numberformat_datetime_mmddyyyyhhii;
105 else if (temp == 0x30)
106 (*result)->code = psiconv_numberformat_datetime_mmddyyyyHHii;
107 else if (temp == 0x32)
108 (*result)->code = psiconv_numberformat_datetime_yyyymmddhhii;
109 else if (temp == 0x34)
110 (*result)->code = psiconv_numberformat_datetime_yyyymmddHHii;
111 else if (temp == 0x36)
112 (*result)->code = psiconv_numberformat_time_hhii;
113 else if (temp == 0x38)
114 (*result)->code = psiconv_numberformat_time_hhiiss;
115 else if (temp == 0x3A)
116 (*result)->code = psiconv_numberformat_time_HHii;
117 else if (temp == 0x3C)
118 (*result)->code = psiconv_numberformat_time_HHiiss;
119 else {
120 psiconv_warn(lev+2,off+len,"Unknown number format (assumed general)");
121 (*result)->code = psiconv_numberformat_general;
122 }
123 len ++;
124
125 psiconv_progress(lev+2,off+len, "Going to read the number of decimals");
126 (*result)->decimal = psiconv_read_u8(buf,lev+2,off+len,&res);
127 if (res)
128 goto ERROR2;
129 psiconv_debug(lev+2,off+len,"Decimals: %d",(*result)->decimal);
130 len ++;
131
132 if (length)
133 *length = len;
134
135 psiconv_progress(lev,off+len-1,
136 "End of sheet number format (total length: %08x)", len);
137 return 0;
138
139ERROR2:
140 free (*result);
141ERROR1:
142 psiconv_warn(lev+1,off,"Reading of Sheet Number Format failed");
143 if (length)
144 *length = 0;
145 if (!res)
146 return -PSICONV_E_NOMEM;
147 else
148 return res;
149}
27 150
28int psiconv_parse_sheet_status_section(const psiconv_buffer buf, int lev, 151int psiconv_parse_sheet_status_section(const psiconv_buffer buf, int lev,
29 psiconv_u32 off, int *length, 152 psiconv_u32 off, int *length,
30 psiconv_sheet_status_section *result) 153 psiconv_sheet_status_section *result)
31{ 154{
221 goto ERROR2; 344 goto ERROR2;
222 psiconv_debug(lev+2,off+len,"Offset: %04x",formulas_off); 345 psiconv_debug(lev+2,off+len,"Offset: %04x",formulas_off);
223 len += 4; 346 len += 4;
224 347
225 psiconv_progress(lev+2,off+len, 348 psiconv_progress(lev+2,off+len,
226 "Going to read the offset of the Worksheets Section"); 349 "Going to read the offset of the Worksheet List");
227 worksheets_off = psiconv_read_u32(buf,lev+2,off+len,&res); 350 worksheets_off = psiconv_read_u32(buf,lev+2,off+len,&res);
228 if (res) 351 if (res)
229 goto ERROR2; 352 goto ERROR2;
230 psiconv_debug(lev+2,off+len,"Offset: %04x",temp); 353 psiconv_debug(lev+2,off+len,"Offset: %04x",worksheets_off);
231 len += 4; 354 len += 4;
232 355
233 psiconv_progress(lev+2,off+len, 356 psiconv_progress(lev+2,off+len,
234 "Going to read the offset of the 4th ??? Section"); 357 "Going to read the offset of the 4th ??? Section");
235 temp = psiconv_read_u32(buf,lev+2,off+len,&res); 358 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
241 psiconv_progress(lev+2,off+len,"Going to read the formulas list"); 364 psiconv_progress(lev+2,off+len,"Going to read the formulas list");
242 if ((res = psiconv_parse_sheet_formula_table(buf,lev+2,formulas_off,NULL, 365 if ((res = psiconv_parse_sheet_formula_table(buf,lev+2,formulas_off,NULL,
243 &(*result)->formulas))) 366 &(*result)->formulas)))
244 goto ERROR2; 367 goto ERROR2;
245 368
246 psiconv_progress(lev+2,off+len,"Going to read the worksheets"); 369 psiconv_progress(lev+2,off+len,"Going to read the worksheet list");
247 if ((res = psiconv_parse_sheet_worksheet_section(buf,lev+2,worksheets_off, 370 if ((res = psiconv_parse_sheet_worksheet_list(buf,lev+2,worksheets_off,
248 NULL,&(*result)->worksheet))) 371 NULL,&(*result)->worksheets)))
249 goto ERROR2; 372 goto ERROR2;
250 373
251 374
252 if (length) 375 if (length)
253 *length = len; 376 *length = len;
346 469
347 psiconv_progress(lev+1,off,"Going to read a sheet cell structure"); 470 psiconv_progress(lev+1,off,"Going to read a sheet cell structure");
348 if (!(*result = malloc(sizeof(**result)))) 471 if (!(*result = malloc(sizeof(**result))))
349 goto ERROR1; 472 goto ERROR1;
350 473
474 (*result)->layout = NULL;
475 (*result)->type = psiconv_cell_blank;
476
351 psiconv_progress(lev+2,off+len,"Going to read the cell position"); 477 psiconv_progress(lev+2,off+len,"Going to read the cell position");
352 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 478 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
353 if (res) 479 if (res)
354 goto ERROR2; 480 goto ERROR2;
355 len ++; 481 len ++;
363 len ++; 489 len ++;
364 (*result)->column = (temp >> 2) & 0xFF; 490 (*result)->column = (temp >> 2) & 0xFF;
365 (*result)->row = (temp >> 10) & 0x3FFF; 491 (*result)->row = (temp >> 10) & 0x3FFF;
366 psiconv_debug(lev+2,off+len,"Cell position is col:%02x row:%04x", 492 psiconv_debug(lev+2,off+len,"Cell position is col:%02x row:%04x",
367 (*result)->column,(*result)->row); 493 (*result)->column,(*result)->row);
494 if (temp & 0x03) {
495 psiconv_warn(lev+2,off+len,"Unknown flags in cell position (ignored)");
496 psiconv_debug(lev+2,off+len,"Flags: %02x",temp & 0x03);
497 }
368 498
369 psiconv_progress(lev+2,off+len,"Going to read the cell type"); 499 psiconv_progress(lev+2,off+len,"Going to read the cell type");
370 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 500 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
371 if (res) 501 if (res)
372 goto ERROR2; 502 goto ERROR2;
386 len += 4; 516 len += 4;
387 psiconv_debug(lev+2,off+len,"Cell contents: %ld",(*result)->data.dat_int); 517 psiconv_debug(lev+2,off+len,"Cell contents: %ld",(*result)->data.dat_int);
388 518
389 } else if ((*result)->type == psiconv_cell_bool) { 519 } else if ((*result)->type == psiconv_cell_bool) {
390 psiconv_progress(lev+2,off+len,"Going to read a boolean"); 520 psiconv_progress(lev+2,off+len,"Going to read a boolean");
391 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 521 if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng,
392 if (res) 522 &(*result)->data.dat_bool)))
393 goto ERROR2; 523 goto ERROR2;
394 len ++;
395 psiconv_debug(lev+2,off+len,"Cell contents: %01x",temp); 524 psiconv_debug(lev+2,off+len,"Cell contents: %01x",temp);
396 (*result)->data.dat_bool = temp?psiconv_bool_true:psiconv_bool_false; 525 (*result)->data.dat_bool = temp?psiconv_bool_true:psiconv_bool_false;
397 526 len += leng;
398 } else if ((*result)->type == psiconv_cell_error) { 527 } else if ((*result)->type == psiconv_cell_error) {
399 psiconv_progress(lev+2,off+len,"Going to read the error code"); 528 psiconv_progress(lev+2,off+len,"Going to read the error code");
400 (*result)->data.dat_error = psiconv_read_u16(buf,lev+2,off+len,&res); 529 temp = psiconv_read_u16(buf,lev+2,off+len,&res);
401 if (res) 530 if (res)
402 goto ERROR2; 531 goto ERROR2;
403 len += 2; 532 if (temp == 0)
533 (*result)->data.dat_error = psiconv_sheet_error_none;
534 else if (temp == 1)
535 (*result)->data.dat_error = psiconv_sheet_error_null;
536 else if (temp == 2)
537 (*result)->data.dat_error = psiconv_sheet_error_divzero;
538 else if (temp == 3)
539 (*result)->data.dat_error = psiconv_sheet_error_value;
540 else if (temp == 4)
541 (*result)->data.dat_error = psiconv_sheet_error_reference;
542 else if (temp == 5)
543 (*result)->data.dat_error = psiconv_sheet_error_name;
544 else if (temp == 6)
545 (*result)->data.dat_error = psiconv_sheet_error_number;
546 else if (temp == 7)
547 (*result)->data.dat_error = psiconv_sheet_error_notavail;
548 else {
549 psiconv_warn(lev+2,off+len,"Unknown error code (default assumed)");
550 psiconv_debug(lev+2,off+len,"Error code: %04x",temp);
551 (*result)->data.dat_error = psiconv_sheet_error_none;
552 }
404 psiconv_debug(lev+2,off+len,"Cell contents: %04x", 553 psiconv_debug(lev+2,off+len,"Cell contents: %04x",
405 (*result)->data.dat_error); 554 (*result)->data.dat_error);
406 555 len += 2;
407 } else if ((*result)->type == psiconv_cell_float) { 556 } else if ((*result)->type == psiconv_cell_float) {
408 psiconv_progress(lev+2,off+len,"Going to read a float"); 557 psiconv_progress(lev+2,off+len,"Going to read a float");
409 (*result)->data.dat_float = 558 (*result)->data.dat_float =
410 psiconv_read_float(buf,lev+2,off+len,&leng,&res); 559 psiconv_read_float(buf,lev+2,off+len,&leng,&res);
411 if (res) 560 if (res)
412 goto ERROR2; 561 goto ERROR2;
413 len += leng;
414 psiconv_debug(lev+2,off+len,"Cell contents: %f",(*result)->data.dat_float); 562 psiconv_debug(lev+2,off+len,"Cell contents: %f",(*result)->data.dat_float);
415 563 len += leng;
416 } else if ((*result)->type == psiconv_cell_string) { 564 } else if ((*result)->type == psiconv_cell_string) {
417 psiconv_progress(lev+2,off+len,"Going to read a string"); 565 psiconv_progress(lev+2,off+len,"Going to read a string");
418 (*result)->data.dat_string = 566 (*result)->data.dat_string =
419 psiconv_read_short_string(buf,lev+2,off+len,&leng,&res); 567 psiconv_read_string(buf,lev+2,off+len,&leng,&res);
420 if (res) 568 if (res)
421 goto ERROR2; 569 goto ERROR2;
422 len += leng;
423 psiconv_debug(lev+2,off+len,"Cell contents: `%s'", 570 psiconv_debug(lev+2,off+len,"Cell contents: `%s'",
424 (*result)->data.dat_string); 571 (*result)->data.dat_string);
572 len += leng;
425 } else { 573 } else {
426 psiconv_warn(lev+2,off+len,"Unknown Sheet Cell type: %02x",(*result)->type); 574 psiconv_warn(lev+2,off+len,"Unknown Sheet Cell type: %02x",(*result)->type);
575 res = PSICONV_E_PARSE;
576 goto ERROR2;
427 } 577 }
428 578
429 if (has_layout) { 579 if (has_layout) {
430 psiconv_progress(lev+2,off+len,"Going to read the cell layout"); 580 if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len,
431 581 &leng,&(*result)->layout)))
432 psiconv_progress(lev+2,off+len,"Going to read the cell layout flags");
433 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
434 if (res)
435 goto ERROR2;
436 len ++;
437
438 if (temp & 0x01) {
439 if (!((*result)->paragraph = psiconv_basic_paragraph_layout()))
440 goto ERROR2; 582 goto ERROR2;
441 psiconv_progress(lev+3,off+len,"Going to read the paragraph codes");
442 if ((res = psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng,
443 (*result)->paragraph)))
444 goto ERROR2;
445 len += leng; 583 len += leng;
446 }
447
448 if (temp & 0x02) {
449 psiconv_progress(lev+3,off+len,"Going to read the character codes");
450 if (!((*result)->character = psiconv_basic_character_layout()))
451 goto ERROR2;
452 if ((res = psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng,
453 (*result)->character)))
454 goto ERROR2;
455 len += leng;
456 }
457
458 if (temp & 0x04) {
459/* TODO: default number format */
460 psiconv_read_u8(buf,lev+2,off+len,&res);
461 if (res)
462 goto ERROR2;
463 len ++;
464 psiconv_read_u8(buf,lev+2,off+len,&res);
465 if (res)
466 goto ERROR2;
467 len ++;
468 psiconv_read_u8(buf,lev+2,off+len,&res);
469 if (res)
470 goto ERROR2;
471 len ++;
472 }
473 } 584 }
474 585
475 if ((*result)->calculated) { 586 if ((*result)->calculated) {
476 psiconv_progress(lev+2,off+len,"Going to read the cell formula reference"); 587 psiconv_progress(lev+2,off+len,"Going to read the cell formula reference");
477 temp = psiconv_read_X(buf,lev+2,off+len,&leng,&res); 588 temp = psiconv_read_X(buf,lev+2,off+len,&leng,&res);
478 if (res) 589 if (res)
479 goto ERROR2; 590 goto ERROR2;
480 psiconv_debug(lev+2,off+len,"Cell formula reference: %d",temp); 591 psiconv_debug(lev+2,off+len,"Cell formula reference: %d",temp);
481 len += leng; 592 len += leng;
482 (*result)->ref_formula = temp; 593 (*result)->ref_formula = temp;
483 } 594 }
484 595
485 if (length) 596 if (length)
486 *length = len; 597 *length = len;
487 598
510 psiconv_u32 temp; 621 psiconv_u32 temp;
511 psiconv_sheet_cell cell; 622 psiconv_sheet_cell cell;
512 psiconv_u32 listlen,i; 623 psiconv_u32 listlen,i;
513 int leng; 624 int leng;
514 625
515 psiconv_progress(lev+1,off,"Going to read the sheet cells list"); 626 psiconv_progress(lev+1,off,"Going to read the sheet cell list");
516 if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_cell_s)))) 627 if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_cell_s))))
517 goto ERROR1; 628 goto ERROR1;
518 629
519 psiconv_progress(lev+2,off+len, 630 psiconv_progress(lev+2,off+len,
520 "Going to read the initial byte (%02x expected)",0x02); 631 "Going to read the initial byte (%02x expected)",0x02);
578 else 689 else
579 return res; 690 return res;
580} 691}
581 692
582 693
583int psiconv_parse_sheet_worksheet_section(const psiconv_buffer buf, int lev, 694int psiconv_parse_sheet_worksheet_list( const psiconv_buffer buf, int lev,
584 psiconv_u32 off, int *length, 695 psiconv_u32 off, int *length,
585 psiconv_sheet_worksheet_section *result) 696 psiconv_sheet_worksheet_list *result)
586{ 697{
698 psiconv_sheet_worksheet worksheet;
587 int res=0; 699 int res=0;
588 psiconv_u32 temp,cells_off,grid_off;
589 int len=0; 700 int len=0;
701 psiconv_u8 temp;
702 psiconv_u32 offset;
590 int leng; 703 int leng,i,nr;
591 704
592 /* TODO: this is the section that might be an XListE instead... */ 705 psiconv_progress(lev+1,off,"Going to read the worksheet list");
706 if (!(*result = psiconv_list_new(sizeof(*worksheet))))
707 goto ERROR1;
708
593 psiconv_progress(lev+2,off+len, 709 psiconv_progress(lev+2,off+len,
594 "Going to read the initial bytes (%02x expected)",0x02); 710 "Going to read the initial bytes (%02x expected)",0x02);
595 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 711 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
596 if (res) 712 if (res)
597 goto ERROR1; 713 goto ERROR2;
598 if (temp != 0x04) { 714 if (temp != 0x02) {
599 psiconv_warn(lev+2,off+len, 715 psiconv_warn(lev+2,off+len,
600 "Sheet worksheet section initial byte unknown value (ignored)"); 716 "Sheet worksheet list initial byte unknown value (ignored)");
601 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); 717 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
602 } 718 }
603 len ++; 719 len ++;
604 720
721 psiconv_progress(lev+2,off+len,"Going to read the list length");
722 nr = psiconv_read_X(buf,lev+2,off+len,&leng,&res);
723 if (res)
724 goto ERROR2;
725 psiconv_debug(lev+2,off+len,"Length: %02x",nr);
726 len += leng;
727
728 psiconv_progress(lev+2,off+len,"Going to read the list");
729 for (i=0 ; i < nr; i++) {
730 psiconv_progress(lev+3,off+len,"Going to read element %d",i);
605 psiconv_progress(lev+2,off+len, 731 psiconv_progress(lev+4,off+len,
606 "Going to read the initial bytes (%02x expected)",0x02);
607 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
608 if (res)
609 goto ERROR1;
610 if (temp != 0x04) {
611 psiconv_warn(lev+2,off+len,
612 "Sheet worksheet section initial byte unknown value (ignored)");
613 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
614 }
615 len ++;
616
617 psiconv_progress(lev+2,off+len,
618 "Going to read the initial bytes (%02x expected)",0x00); 732 "Going to read the initial byte (%02x expected)",0x00);
619 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 733 temp = psiconv_read_u8(buf,lev+4,off+len,&res);
620 if (res)
621 goto ERROR1;
622 if (temp != 0x04) {
623 psiconv_warn(lev+2,off+len,
624 "Sheet worksheet section initial byte unknown value (ignored)");
625 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
626 }
627 len ++;
628
629 psiconv_progress(lev+2,off+len,
630 "Going to read the offset of the Worksheet Section");
631 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
632 if (res)
633 goto ERROR1;
634 psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
635 len += 4;
636
637 len = 0;
638 off = temp;
639
640 /* this is the real worksheet section from here */
641
642 psiconv_progress(lev+1,off,"Going to read the sheet worksheet section");
643 if (!(*result = malloc(sizeof(**result))))
644 goto ERROR1;
645
646 psiconv_progress(lev+2,off+len,
647 "Going to read the initial bytes (%02x expected)",0x04);
648 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
649 if (res)
650 goto ERROR2;
651 if (temp != 0x04) {
652 psiconv_warn(lev+2,off+len,
653 "Worksheet section initial byte unknown value (ignored)");
654 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
655 }
656 len ++;
657
658 psiconv_progress(lev+2,off+len,
659 "Going to read the initial bytes (%02x expected)",0x01);
660 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
661 if (res)
662 goto ERROR2;
663 if (temp != 0x01) {
664 psiconv_warn(lev+2,off+len,
665 "Worksheet section initial byte unknown value (ignored)");
666 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
667 }
668 len ++;
669
670 psiconv_progress(lev+2,off+len,
671 "Going to read the initial bytes (%02x expected)",0x02);
672 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
673 if (res)
674 goto ERROR2;
675 if (temp != 0x02) {
676 psiconv_warn(lev+2,off+len,
677 "Worksheet section initial byte unknown value (ignored)");
678 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
679 }
680 len ++;
681
682 psiconv_progress(lev+2,off+len,"Going to read the default formats flag");
683 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
684 if (res)
685 goto ERROR2;
686 len ++;
687
688 if (temp & 0x01) {
689 if (!((*result)->paragraph = psiconv_basic_paragraph_layout()))
690 goto ERROR2;
691 psiconv_progress(lev+3,off+len,"Going to read the default paragraph codes");
692 if ((res = psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng,
693 (*result)->paragraph)))
694 goto ERROR2_1;
695 len += leng;
696 }
697
698 if (temp & 0x02) {
699 psiconv_progress(lev+3,off+len,"Going to read the default character codes");
700 if (!((*result)->character = psiconv_basic_character_layout()))
701 goto ERROR2_1;
702 if ((res = psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng,
703 (*result)->character)))
704 goto ERROR2_2;
705 len += leng;
706 }
707
708 if (temp & 0x04) {
709/* TODO: default number format */
710 psiconv_read_u8(buf,lev+2,off+len,&res);
711 if (res) 734 if (res)
712 goto ERROR2_3; 735 goto ERROR2;
736 if (temp != 0x00) {
737 psiconv_warn(lev+4,off+len,
738 "Sheet worksheet element initial byte unknown value (ignored)");
739 psiconv_debug(lev+4,off+len,"Initial byte: %02x",temp);
740 }
713 len ++; 741 len ++;
742
743 psiconv_progress(lev+4,off+len,"Going to read the worksheet offset");
714 psiconv_read_u8(buf,lev+2,off+len,&res); 744 offset = psiconv_read_u32(buf,lev+2,off+len,&res);
715 if (res) 745 if (res)
716 goto ERROR2_3; 746 goto ERROR2;
747 psiconv_debug(lev+4,off+len,"Offset: %08x",offset);
717 len ++; 748 len += 4;
718 psiconv_read_u8(buf,lev+2,off+len,&res); 749
719 if (res) 750 if ((res = psiconv_parse_sheet_worksheet(buf,lev+4,offset,NULL,
751 &worksheet)))
720 goto ERROR2_3; 752 goto ERROR2;
721 len ++; 753 if ((res = psiconv_list_add(*result,worksheet)))
722 }
723
724 psiconv_progress(lev+2,off+len,
725 "Going to read the offset of the 1st ??? Section");
726 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
727 if (res)
728 goto ERROR2; 754 goto ERROR3;
729 psiconv_debug(lev+2,off+len,"Offset: %04x",temp); 755 psiconv_free_sheet_worksheet(worksheet);
730 len += 4;
731
732 psiconv_progress(lev+2,off+len,
733 "Going to read the offset of the 2nd ??? Section");
734 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
735 if (res)
736 goto ERROR2;
737 psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
738 len += 4;
739
740 psiconv_progress(lev+2,off+len,
741 "Going to read the offset of the Cells List");
742 cells_off = psiconv_read_u32(buf,lev+2,off+len,&res);
743 if (res)
744 goto ERROR2;
745 psiconv_debug(lev+2,off+len,"Offset: %04x",cells_off);
746 len += 4;
747
748 psiconv_progress(lev+2,off+len,
749 "Going to read the offset of the Grid Section");
750 grid_off = psiconv_read_u32(buf,lev+2,off+len,&res);
751 if (res)
752 goto ERROR2;
753 psiconv_debug(lev+2,off+len,"Offset: %04x",grid_off);
754 len += 4;
755
756 psiconv_progress(lev+2,off+len,
757 "Going to read the offset of the 3rd ??? Section");
758 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
759 if (res)
760 goto ERROR2;
761 psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
762 len += 4;
763
764 psiconv_progress(lev+2,off+len,"Going to read the cells list");
765 if ((res = psiconv_parse_sheet_cell_list(buf,lev+2,cells_off,NULL,
766 &(*result)->cells)))
767 goto ERROR2;
768 756 }
769 757
770/* TODO: parse grid section */
771
772 if (length) 758 if (length)
773 *length = len; 759 *length = len;
774 760
775 psiconv_progress(lev,off+len-1, 761 psiconv_progress(lev,off+len-1,
776 "End of sheet worksheet section (total length: %08x)", len); 762 "End of worksheet list (total length: %08x)", len);
763
777 return 0; 764 return 0;
778 765
779ERROR2_3: 766ERROR3:
780 psiconv_free_numberformat((*result)->numberformat); 767 psiconv_free_sheet_worksheet(worksheet);
781ERROR2_2:
782 psiconv_free_character_layout((*result)->character);
783ERROR2_1:
784 psiconv_free_paragraph_layout((*result)->paragraph);
785goto ERROR2;
786
787ERROR2: 768ERROR2:
788 free (*result); 769 psiconv_free_sheet_worksheet_list(*result);
789ERROR1: 770ERROR1:
790 psiconv_warn(lev+1,off,"Reading of Sheet Worksheet Section failed"); 771 psiconv_warn(lev+1,off,"Reading of worksheet list failed");
791 if (length) 772 if (length)
792 *length = 0; 773 *length = 0;
793 if (!res) 774 if (!res)
794 return -PSICONV_E_NOMEM; 775 return -PSICONV_E_NOMEM;
795 else 776 else
796 return res; 777 return res;
797} 778}
798 779
780int psiconv_parse_sheet_cell_layout(const psiconv_buffer buf, int lev,
781 psiconv_u32 off, int *length,
782 psiconv_sheet_cell_layout *result)
799 783
784{
785 int res=0;
786 int len=0;
787 int leng;
788 psiconv_u8 temp;
789
790 psiconv_progress(lev+1,off,"Going to read a sheet cell layout");
791 if (!(*result = malloc(sizeof(**result))))
792 goto ERROR1;
793
794 (*result)->character = NULL;
795 (*result)->paragraph = NULL;
796 (*result)->numberformat = NULL;
797
798 psiconv_progress(lev+2,off+len,
799 "Going to read the first byte (%02x expected)",0x02);
800 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
801 if (res)
802 goto ERROR2;
803 if (temp != 0x02) {
804 psiconv_warn(lev+2,off+len,
805 "Worksheet section initial byte unknown value (ignored)");
806 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
807 }
808 len ++;
809
810 psiconv_progress(lev+2,off+len,"Going to read the default formats flag");
811 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
812 if (res)
813 goto ERROR2;
814 len ++;
815
816 if (temp & 0x01) {
817 if (!((*result)->paragraph = psiconv_basic_paragraph_layout()))
818 goto ERROR2;
819 psiconv_progress(lev+3,off+len,"Going to read the default paragraph codes");
820 if ((res = psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng,
821 (*result)->paragraph)))
822 goto ERROR2;
823 len += leng;
824 }
825
826 if (temp & 0x02) {
827 psiconv_progress(lev+3,off+len,"Going to read the default character codes");
828 if (!((*result)->character = psiconv_basic_character_layout()))
829 goto ERROR2;
830 if ((res = psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng,
831 (*result)->character)))
832 goto ERROR2;
833 len += leng;
834 }
835
836 if (temp & 0x04) {
837 psiconv_progress(lev+3,off+len, "Going to read the default number format");
838 psiconv_parse_sheet_numberformat(buf,lev+3,off+len,&leng,
839 &(*result)->numberformat);
840 len += leng;
841 }
842
843 if (length)
844 *length = len;
845
846 psiconv_progress(lev,off+len-1,
847 "End of sheet cell layout (total length: %08x)", len);
848
849 return 0;
850
851ERROR2:
852 psiconv_free_sheet_cell_layout(*result);
853ERROR1:
854 psiconv_warn(lev+1,off,"Reading of sheet cell layout failed");
855 if (length)
856 *length = 0;
857 if (!res)
858 return -PSICONV_E_NOMEM;
859 else
860 return res;
861}
862
863
864int psiconv_parse_sheet_worksheet(const psiconv_buffer buf, int lev,
865 psiconv_u32 off, int *length,
866 psiconv_sheet_worksheet *result)
867{
868 int res=0;
869 psiconv_u32 temp,cells_off,grid_off;
870 int len=0;
871 int leng;
872
873 psiconv_progress(lev+1,off,"Going to read the sheet worksheet section");
874 if (!(*result = malloc(sizeof(**result))))
875 goto ERROR1;
876
877 psiconv_progress(lev+2,off+len,
878 "Going to read the initial bytes (%02x expected)",0x04);
879 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
880 if (res)
881 goto ERROR2;
882 if (temp != 0x04) {
883 psiconv_warn(lev+2,off+len,
884 "Worksheet section initial byte unknown value (ignored)");
885 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
886 }
887 len ++;
888
889 psiconv_progress(lev+2,off+len, "Going to read the flags byte");
890 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
891 if (res)
892 goto ERROR2;
893 psiconv_debug(lev+2,off+len,"Flags byte: %02x",temp);
894 (*result)->show_zeros = (temp & 0x01)?psiconv_bool_true:psiconv_bool_false;
895 if (temp & 0xfe) {
896 psiconv_warn(lev+2,off+len,
897 "Worksheet section flags byte unknown bits (ignored)");
898 }
899 len ++;
900
901 psiconv_progress(lev+2,off+len,"Going to read the default cell layout");
902 if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len,&leng,
903 &(*result)->default_layout)))
904 goto ERROR2;
905 len += leng;
906
907 psiconv_progress(lev+2,off+len,
908 "Going to read the offset of the 1st ??? Section");
909 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
910 if (res)
911 goto ERROR3;
912 psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
913 len += 4;
914
915 psiconv_progress(lev+2,off+len,
916 "Going to read the offset of the 2nd ??? Section");
917 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
918 if (res)
919 goto ERROR3;
920 psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
921 len += 4;
922
923 psiconv_progress(lev+2,off+len,
924 "Going to read the offset of the Cells List");
925 cells_off = psiconv_read_u32(buf,lev+2,off+len,&res);
926 if (res)
927 goto ERROR3;
928 psiconv_debug(lev+2,off+len,"Offset: %04x",cells_off);
929 len += 4;
930
931 psiconv_progress(lev+2,off+len,
932 "Going to read the offset of the Grid Section");
933 grid_off = psiconv_read_u32(buf,lev+2,off+len,&res);
934 if (res)
935 goto ERROR3;
936 psiconv_debug(lev+2,off+len,"Offset: %04x",grid_off);
937 len += 4;
938
939 psiconv_progress(lev+2,off+len,
940 "Going to read the offset of the 3rd ??? Section");
941 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
942 if (res)
943 goto ERROR3;
944 psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
945 len += 4;
946
947 psiconv_progress(lev+2,off+len,"Going to read the cells list");
948 if ((res = psiconv_parse_sheet_cell_list(buf,lev+2,cells_off,NULL,
949 &(*result)->cells)))
950 goto ERROR3;
951
952
953/* TODO: parse grid section */
954
955 if (length)
956 *length = len;
957
958 psiconv_progress(lev,off+len-1,
959 "End of sheet worksheet section (total length: %08x)", len);
960 return 0;
961
962ERROR3:
963 psiconv_free_sheet_cell_layout((*result)->default_layout);
964ERROR2:
965 free (*result);
966ERROR1:
967 psiconv_warn(lev+1,off,"Reading of Sheet Worksheet Section failed");
968 if (length)
969 *length = 0;
970 if (!res)
971 return -PSICONV_E_NOMEM;
972 else
973 return res;
974}
975
976

Legend:
Removed from v.110  
changed lines
  Added in v.111

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