/[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 120
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);
553 psiconv_progress(lev+3,off+len,"Going to read cell %d",i); 664 psiconv_progress(lev+3,off+len,"Going to read cell %d",i);
554 if ((res = psiconv_parse_sheet_cell(buf,lev+3,off+len,&leng,&cell))) 665 if ((res = psiconv_parse_sheet_cell(buf,lev+3,off+len,&leng,&cell)))
555 goto ERROR2; 666 goto ERROR2;
556 if ((res = psiconv_list_add(*result,cell))) 667 if ((res = psiconv_list_add(*result,cell)))
557 goto ERROR3; 668 goto ERROR3;
669 free(cell);
558 len += leng; 670 len += leng;
559 } 671 }
560 672
561 if (length) 673 if (length)
562 *length = len; 674 *length = len;
578 else 690 else
579 return res; 691 return res;
580} 692}
581 693
582 694
583int psiconv_parse_sheet_worksheet_section(const psiconv_buffer buf, int lev, 695int psiconv_parse_sheet_worksheet_list( const psiconv_buffer buf, int lev,
584 psiconv_u32 off, int *length, 696 psiconv_u32 off, int *length,
585 psiconv_sheet_worksheet_section *result) 697 psiconv_sheet_worksheet_list *result)
586{ 698{
699 psiconv_sheet_worksheet worksheet;
587 int res=0; 700 int res=0;
588 psiconv_u32 temp,cells_off,grid_off;
589 int len=0; 701 int len=0;
702 psiconv_u8 temp;
703 psiconv_u32 offset;
590 int leng; 704 int leng,i,nr;
591 705
592 /* TODO: this is the section that might be an XListE instead... */ 706 psiconv_progress(lev+1,off,"Going to read the worksheet list");
707 if (!(*result = psiconv_list_new(sizeof(*worksheet))))
708 goto ERROR1;
709
593 psiconv_progress(lev+2,off+len, 710 psiconv_progress(lev+2,off+len,
594 "Going to read the initial bytes (%02x expected)",0x02); 711 "Going to read the initial bytes (%02x expected)",0x02);
595 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 712 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
596 if (res) 713 if (res)
597 goto ERROR1; 714 goto ERROR2;
598 if (temp != 0x04) { 715 if (temp != 0x02) {
599 psiconv_warn(lev+2,off+len, 716 psiconv_warn(lev+2,off+len,
600 "Sheet worksheet section initial byte unknown value (ignored)"); 717 "Sheet worksheet list initial byte unknown value (ignored)");
601 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); 718 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
602 } 719 }
603 len ++; 720 len ++;
604 721
722 psiconv_progress(lev+2,off+len,"Going to read the list length");
723 nr = psiconv_read_X(buf,lev+2,off+len,&leng,&res);
724 if (res)
725 goto ERROR2;
726 psiconv_debug(lev+2,off+len,"Length: %02x",nr);
727 len += leng;
728
729 psiconv_progress(lev+2,off+len,"Going to read the list");
730 for (i=0 ; i < nr; i++) {
731 psiconv_progress(lev+3,off+len,"Going to read element %d",i);
605 psiconv_progress(lev+2,off+len, 732 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); 733 "Going to read the initial byte (%02x expected)",0x00);
619 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 734 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) 735 if (res)
712 goto ERROR2_3; 736 goto ERROR2;
737 if (temp != 0x00) {
738 psiconv_warn(lev+4,off+len,
739 "Sheet worksheet element initial byte unknown value (ignored)");
740 psiconv_debug(lev+4,off+len,"Initial byte: %02x",temp);
741 }
713 len ++; 742 len ++;
743
744 psiconv_progress(lev+4,off+len,"Going to read the worksheet offset");
714 psiconv_read_u8(buf,lev+2,off+len,&res); 745 offset = psiconv_read_u32(buf,lev+2,off+len,&res);
715 if (res) 746 if (res)
716 goto ERROR2_3; 747 goto ERROR2;
748 psiconv_debug(lev+4,off+len,"Offset: %08x",offset);
717 len ++; 749 len += 4;
718 psiconv_read_u8(buf,lev+2,off+len,&res); 750
719 if (res) 751 if ((res = psiconv_parse_sheet_worksheet(buf,lev+4,offset,NULL,
752 &worksheet)))
720 goto ERROR2_3; 753 goto ERROR2;
721 len ++; 754 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; 755 goto ERROR3;
729 psiconv_debug(lev+2,off+len,"Offset: %04x",temp); 756 free(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 757 }
769 758
770/* TODO: parse grid section */
771
772 if (length) 759 if (length)
773 *length = len; 760 *length = len;
774 761
775 psiconv_progress(lev,off+len-1, 762 psiconv_progress(lev,off+len-1,
776 "End of sheet worksheet section (total length: %08x)", len); 763 "End of worksheet list (total length: %08x)", len);
764
777 return 0; 765 return 0;
778 766
779ERROR2_3: 767ERROR3:
780 psiconv_free_numberformat((*result)->numberformat); 768 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: 769ERROR2:
788 free (*result); 770 psiconv_free_sheet_worksheet_list(*result);
789ERROR1: 771ERROR1:
790 psiconv_warn(lev+1,off,"Reading of Sheet Worksheet Section failed"); 772 psiconv_warn(lev+1,off,"Reading of worksheet list failed");
791 if (length) 773 if (length)
792 *length = 0; 774 *length = 0;
793 if (!res) 775 if (!res)
794 return -PSICONV_E_NOMEM; 776 return -PSICONV_E_NOMEM;
795 else 777 else
796 return res; 778 return res;
797} 779}
798 780
781int psiconv_parse_sheet_cell_layout(const psiconv_buffer buf, int lev,
782 psiconv_u32 off, int *length,
783 psiconv_sheet_cell_layout *result)
799 784
785{
786 int res=0;
787 int len=0;
788 int leng;
789 psiconv_u8 temp;
790
791 psiconv_progress(lev+1,off,"Going to read a sheet cell layout");
792 if (!(*result = malloc(sizeof(**result))))
793 goto ERROR1;
794
795 (*result)->character = NULL;
796 (*result)->paragraph = NULL;
797 (*result)->numberformat = NULL;
798
799 psiconv_progress(lev+2,off+len,
800 "Going to read the first byte (%02x expected)",0x02);
801 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
802 if (res)
803 goto ERROR2;
804 if (temp != 0x02) {
805 psiconv_warn(lev+2,off+len,
806 "Worksheet section initial byte unknown value (ignored)");
807 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
808 }
809 len ++;
810
811 psiconv_progress(lev+2,off+len,"Going to read the default formats flag");
812 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
813 if (res)
814 goto ERROR2;
815 len ++;
816
817 if (temp & 0x01) {
818 if (!((*result)->paragraph = psiconv_basic_paragraph_layout()))
819 goto ERROR2;
820 psiconv_progress(lev+3,off+len,"Going to read the default paragraph codes");
821 if ((res = psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng,
822 (*result)->paragraph)))
823 goto ERROR2;
824 len += leng;
825 }
826
827 if (temp & 0x02) {
828 psiconv_progress(lev+3,off+len,"Going to read the default character codes");
829 if (!((*result)->character = psiconv_basic_character_layout()))
830 goto ERROR2;
831 if ((res = psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng,
832 (*result)->character)))
833 goto ERROR2;
834 len += leng;
835 }
836
837 if (temp & 0x04) {
838 psiconv_progress(lev+3,off+len, "Going to read the default number format");
839 psiconv_parse_sheet_numberformat(buf,lev+3,off+len,&leng,
840 &(*result)->numberformat);
841 len += leng;
842 }
843
844 if (length)
845 *length = len;
846
847 psiconv_progress(lev,off+len-1,
848 "End of sheet cell layout (total length: %08x)", len);
849
850 return 0;
851
852ERROR2:
853 psiconv_free_sheet_cell_layout(*result);
854ERROR1:
855 psiconv_warn(lev+1,off,"Reading of sheet cell layout failed");
856 if (length)
857 *length = 0;
858 if (!res)
859 return -PSICONV_E_NOMEM;
860 else
861 return res;
862}
863
864
865int psiconv_parse_sheet_worksheet(const psiconv_buffer buf, int lev,
866 psiconv_u32 off, int *length,
867 psiconv_sheet_worksheet *result)
868{
869 int res=0;
870 psiconv_u32 temp,cells_off,grid_off;
871 int len=0;
872 int leng;
873
874 psiconv_progress(lev+1,off,"Going to read the sheet worksheet section");
875 if (!(*result = malloc(sizeof(**result))))
876 goto ERROR1;
877
878 psiconv_progress(lev+2,off+len,
879 "Going to read the initial bytes (%02x expected)",0x04);
880 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
881 if (res)
882 goto ERROR2;
883 if (temp != 0x04) {
884 psiconv_warn(lev+2,off+len,
885 "Worksheet section initial byte unknown value (ignored)");
886 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
887 }
888 len ++;
889
890 psiconv_progress(lev+2,off+len, "Going to read the flags byte");
891 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
892 if (res)
893 goto ERROR2;
894 psiconv_debug(lev+2,off+len,"Flags byte: %02x",temp);
895 (*result)->show_zeros = (temp & 0x01)?psiconv_bool_true:psiconv_bool_false;
896 if (temp & 0xfe) {
897 psiconv_warn(lev+2,off+len,
898 "Worksheet section flags byte unknown bits (ignored)");
899 }
900 len ++;
901
902 psiconv_progress(lev+2,off+len,"Going to read the default cell layout");
903 if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len,&leng,
904 &(*result)->default_layout)))
905 goto ERROR2;
906 len += leng;
907
908 psiconv_progress(lev+2,off+len,
909 "Going to read the offset of the 1st ??? Section");
910 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
911 if (res)
912 goto ERROR3;
913 psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
914 len += 4;
915
916 psiconv_progress(lev+2,off+len,
917 "Going to read the offset of the 2nd ??? Section");
918 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
919 if (res)
920 goto ERROR3;
921 psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
922 len += 4;
923
924 psiconv_progress(lev+2,off+len,
925 "Going to read the offset of the Cells List");
926 cells_off = psiconv_read_u32(buf,lev+2,off+len,&res);
927 if (res)
928 goto ERROR3;
929 psiconv_debug(lev+2,off+len,"Offset: %04x",cells_off);
930 len += 4;
931
932 psiconv_progress(lev+2,off+len,
933 "Going to read the offset of the Grid Section");
934 grid_off = psiconv_read_u32(buf,lev+2,off+len,&res);
935 if (res)
936 goto ERROR3;
937 psiconv_debug(lev+2,off+len,"Offset: %04x",grid_off);
938 len += 4;
939
940 psiconv_progress(lev+2,off+len,
941 "Going to read the offset of the 3rd ??? Section");
942 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
943 if (res)
944 goto ERROR3;
945 psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
946 len += 4;
947
948 psiconv_progress(lev+2,off+len,"Going to read the cells list");
949 if ((res = psiconv_parse_sheet_cell_list(buf,lev+2,cells_off,NULL,
950 &(*result)->cells)))
951 goto ERROR3;
952
953
954/* TODO: parse grid section */
955
956 if (length)
957 *length = len;
958
959 psiconv_progress(lev,off+len-1,
960 "End of sheet worksheet section (total length: %08x)", len);
961 return 0;
962
963ERROR3:
964 psiconv_free_sheet_cell_layout((*result)->default_layout);
965ERROR2:
966 free (*result);
967ERROR1:
968 psiconv_warn(lev+1,off,"Reading of Sheet Worksheet Section failed");
969 if (length)
970 *length = 0;
971 if (!res)
972 return -PSICONV_E_NOMEM;
973 else
974 return res;
975}
976
977

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

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