/[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 120 Revision 128
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 27
28static psiconv_sheet_cell_layout psiconv_basic_cell_layout(void)
29{
30 psiconv_sheet_cell_layout result;
31 if (!(result = malloc(sizeof(*result))))
32 goto ERROR1;
33 if (!(result->character = psiconv_basic_character_layout()))
34 goto ERROR2;
35 if (!(result->paragraph = psiconv_basic_paragraph_layout()))
36 goto ERROR3;
37 if (!(result->numberformat = malloc(sizeof(*result->numberformat))))
38 goto ERROR4;
39 result->numberformat->code = psiconv_numberformat_general;
40 result->numberformat->decimal = 2;
41 return result;
42ERROR4:
43 psiconv_free_paragraph_layout(result->paragraph);
44ERROR3:
45 psiconv_free_character_layout(result->character);
46ERROR2:
47 free(result);
48ERROR1:
49 return NULL;
50}
51
52static psiconv_sheet_cell_layout psiconv_clone_cell_layout
53 (psiconv_sheet_cell_layout original)
54{
55 psiconv_sheet_cell_layout result;
56 if (!(result = malloc(sizeof(*result))))
57 goto ERROR1;
58 if (!(result->character =
59 psiconv_clone_character_layout(original->character)))
60 goto ERROR2;
61 if (!(result->paragraph =
62 psiconv_clone_paragraph_layout(original->paragraph)))
63 goto ERROR3;
64 if (!(result->numberformat = malloc(sizeof(*result->numberformat))))
65 goto ERROR4;
66 result->numberformat->code = original->numberformat->code;
67 result->numberformat->decimal = original->numberformat->decimal;
68 return result;
69ERROR4:
70 psiconv_free_paragraph_layout(result->paragraph);
71ERROR3:
72 psiconv_free_character_layout(result->character);
73ERROR2:
74 free(result);
75ERROR1:
76 return NULL;
77}
78
28int psiconv_parse_sheet_numberformat(const psiconv_buffer buf, int lev, 79int psiconv_parse_sheet_numberformat(const psiconv_buffer buf, int lev,
29 psiconv_u32 off, int *length, 80 psiconv_u32 off, int *length,
30 psiconv_sheet_numberformat *result) 81 psiconv_sheet_numberformat result)
31{ 82{
32 int res=0; 83 int res=0;
33 int len=0; 84 int len=0;
34 psiconv_u8 temp; 85 psiconv_u8 temp;
35 86
36 psiconv_progress(lev+1,off,"Going to read a sheet numberformat"); 87 psiconv_progress(lev+1,off,"Going to read a sheet numberformat");
37 if (!(*result = malloc(sizeof(**result))))
38 goto ERROR1;
39 88
40 psiconv_progress(lev+2,off+len, 89 psiconv_progress(lev+2,off+len,
41 "Going to read the initial byte (%02x expected)",0x02); 90 "Going to read the initial byte (%02x expected)",0x02);
42 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 91 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
43 if (res) 92 if (res)
44 goto ERROR2; 93 goto ERROR1;
45 if (temp != 0x02) { 94 if (temp != 0x02) {
46 psiconv_warn(lev+2,off+len, 95 psiconv_warn(lev+2,off+len,
47 "Sheet numberformat initial byte unknown value (ignored)"); 96 "Sheet numberformat initial byte unknown value (ignored)");
48 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); 97 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
49 } 98 }
50 len ++; 99 len ++;
51 100
52 psiconv_progress(lev+2,off+len, "Going to read the code byte"); 101 psiconv_progress(lev+2,off+len, "Going to read the code byte");
53 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 102 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
54 if (res) 103 if (res)
55 goto ERROR2; 104 goto ERROR1;
56 psiconv_debug(lev+2,off+len,"Code: %02x",temp); 105 psiconv_debug(lev+2,off+len,"Code: %02x",temp);
57 if (temp == 0x00) 106 if (temp == 0x00)
58 (*result)->code = psiconv_numberformat_general; 107 result->code = psiconv_numberformat_general;
59 else if (temp == 0x02) 108 else if (temp == 0x02)
60 (*result)->code = psiconv_numberformat_fixeddecimal; 109 result->code = psiconv_numberformat_fixeddecimal;
61 else if (temp == 0x04) 110 else if (temp == 0x04)
62 (*result)->code = psiconv_numberformat_scientific; 111 result->code = psiconv_numberformat_scientific;
63 else if (temp == 0x06) 112 else if (temp == 0x06)
64 (*result)->code = psiconv_numberformat_currency; 113 result->code = psiconv_numberformat_currency;
65 else if (temp == 0x08) 114 else if (temp == 0x08)
66 (*result)->code = psiconv_numberformat_percent; 115 result->code = psiconv_numberformat_percent;
67 else if (temp == 0x0A) 116 else if (temp == 0x0A)
68 (*result)->code = psiconv_numberformat_triads; 117 result->code = psiconv_numberformat_triads;
69 else if (temp == 0x0C) 118 else if (temp == 0x0C)
70 (*result)->code = psiconv_numberformat_boolean; 119 result->code = psiconv_numberformat_boolean;
71 else if (temp == 0x0E) 120 else if (temp == 0x0E)
72 (*result)->code = psiconv_numberformat_text; 121 result->code = psiconv_numberformat_text;
73 else if (temp == 0x10) 122 else if (temp == 0x10)
74 (*result)->code = psiconv_numberformat_date_ddmm; 123 result->code = psiconv_numberformat_date_dmm;
75 else if (temp == 0x12) 124 else if (temp == 0x12)
76 (*result)->code = psiconv_numberformat_date_mmdd; 125 result->code = psiconv_numberformat_date_mmd;
77 else if (temp == 0x14) 126 else if (temp == 0x14)
78 (*result)->code = psiconv_numberformat_date_ddmmyy; 127 result->code = psiconv_numberformat_date_ddmmyy;
79 else if (temp == 0x16) 128 else if (temp == 0x16)
80 (*result)->code = psiconv_numberformat_date_mmddyy; 129 result->code = psiconv_numberformat_date_mmddyy;
81 else if (temp == 0x18) 130 else if (temp == 0x18)
82 (*result)->code = psiconv_numberformat_date_yymmdd; 131 result->code = psiconv_numberformat_date_yymmdd;
83 else if (temp == 0x1A) 132 else if (temp == 0x1A)
84 (*result)->code = psiconv_numberformat_date_ddmmm; 133 result->code = psiconv_numberformat_date_dmmm;
85 else if (temp == 0x1C) 134 else if (temp == 0x1C)
86 (*result)->code = psiconv_numberformat_date_ddmmmyy; 135 result->code = psiconv_numberformat_date_dmmmyy;
87 else if (temp == 0x1E) 136 else if (temp == 0x1E)
88 (*result)->code = psiconv_numberformat_date_ddmmmyyyy; 137 result->code = psiconv_numberformat_date_ddmmmyy;
89 else if (temp == 0x20) 138 else if (temp == 0x20)
90 (*result)->code = psiconv_numberformat_date_mmm; 139 result->code = psiconv_numberformat_date_mmm;
91 else if (temp == 0x22) 140 else if (temp == 0x22)
92 (*result)->code = psiconv_numberformat_date_monthname; 141 result->code = psiconv_numberformat_date_monthname;
93 else if (temp == 0x24) 142 else if (temp == 0x24)
94 (*result)->code = psiconv_numberformat_date_mmmyy; 143 result->code = psiconv_numberformat_date_mmmyy;
95 else if (temp == 0x26) 144 else if (temp == 0x26)
96 (*result)->code = psiconv_numberformat_date_monthnameyy; 145 result->code = psiconv_numberformat_date_monthnameyy;
97 else if (temp == 0x28) 146 else if (temp == 0x28)
98 (*result)->code = psiconv_numberformat_date_monthnameddyyyy; 147 result->code = psiconv_numberformat_date_monthnamedyyyy;
99 else if (temp == 0x2A) 148 else if (temp == 0x2A)
100 (*result)->code = psiconv_numberformat_datetime_ddmmyyyyhhii; 149 result->code = psiconv_numberformat_datetime_ddmmyyyyhhii;
101 else if (temp == 0x2C) 150 else if (temp == 0x2C)
102 (*result)->code = psiconv_numberformat_datetime_ddmmyyyyHHii; 151 result->code = psiconv_numberformat_datetime_ddmmyyyyHHii;
103 else if (temp == 0x2E) 152 else if (temp == 0x2E)
104 (*result)->code = psiconv_numberformat_datetime_mmddyyyyhhii; 153 result->code = psiconv_numberformat_datetime_mmddyyyyhhii;
105 else if (temp == 0x30) 154 else if (temp == 0x30)
106 (*result)->code = psiconv_numberformat_datetime_mmddyyyyHHii; 155 result->code = psiconv_numberformat_datetime_mmddyyyyHHii;
107 else if (temp == 0x32) 156 else if (temp == 0x32)
108 (*result)->code = psiconv_numberformat_datetime_yyyymmddhhii; 157 result->code = psiconv_numberformat_datetime_yyyymmddhhii;
109 else if (temp == 0x34) 158 else if (temp == 0x34)
110 (*result)->code = psiconv_numberformat_datetime_yyyymmddHHii; 159 result->code = psiconv_numberformat_datetime_yyyymmddHHii;
111 else if (temp == 0x36) 160 else if (temp == 0x36)
112 (*result)->code = psiconv_numberformat_time_hhii; 161 result->code = psiconv_numberformat_time_hhii;
113 else if (temp == 0x38) 162 else if (temp == 0x38)
114 (*result)->code = psiconv_numberformat_time_hhiiss; 163 result->code = psiconv_numberformat_time_hhiiss;
115 else if (temp == 0x3A) 164 else if (temp == 0x3A)
116 (*result)->code = psiconv_numberformat_time_HHii; 165 result->code = psiconv_numberformat_time_HHii;
117 else if (temp == 0x3C) 166 else if (temp == 0x3C)
118 (*result)->code = psiconv_numberformat_time_HHiiss; 167 result->code = psiconv_numberformat_time_HHiiss;
119 else { 168 else {
120 psiconv_warn(lev+2,off+len,"Unknown number format (assumed general)"); 169 psiconv_warn(lev+2,off+len,"Unknown number format (assumed general)");
121 (*result)->code = psiconv_numberformat_general; 170 result->code = psiconv_numberformat_general;
122 } 171 }
123 len ++; 172 len ++;
124 173
125 psiconv_progress(lev+2,off+len, "Going to read the number of decimals"); 174 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); 175 result->decimal = psiconv_read_u8(buf,lev+2,off+len,&res) >> 1;
127 if (res) 176 if (res)
128 goto ERROR2; 177 goto ERROR1;
129 psiconv_debug(lev+2,off+len,"Decimals: %d",(*result)->decimal); 178 psiconv_debug(lev+2,off+len,"Decimals: %d",result->decimal);
130 len ++; 179 len ++;
131 180
132 if (length) 181 if (length)
133 *length = len; 182 *length = len;
134 183
135 psiconv_progress(lev,off+len-1, 184 psiconv_progress(lev,off+len-1,
136 "End of sheet number format (total length: %08x)", len); 185 "End of sheet number format (total length: %08x)", len);
137 return 0; 186 return 0;
138 187
139ERROR2:
140 free (*result);
141ERROR1: 188ERROR1:
142 psiconv_warn(lev+1,off,"Reading of Sheet Number Format failed"); 189 psiconv_warn(lev+1,off,"Reading of Sheet Number Format failed");
143 if (length) 190 if (length)
144 *length = 0; 191 *length = 0;
145 if (!res) 192 if (!res)
456 else 503 else
457 return res; 504 return res;
458} 505}
459 506
460int psiconv_parse_sheet_cell(const psiconv_buffer buf, int lev, 507int psiconv_parse_sheet_cell(const psiconv_buffer buf, int lev,
461 psiconv_u32 off, int *length, 508 psiconv_u32 off, int *length,
462 psiconv_sheet_cell *result) 509 psiconv_sheet_cell *result,
510 const psiconv_sheet_cell_layout default_layout,
511 const psiconv_sheet_line_list row_default_layouts,
512 const psiconv_sheet_line_list col_default_layouts)
463{ 513{
464 int res=0; 514 int res=0;
465 int len=0; 515 int len=0;
466 psiconv_u32 temp; 516 psiconv_u32 temp;
467 psiconv_bool_t has_layout; 517 psiconv_bool_t has_layout;
574 psiconv_warn(lev+2,off+len,"Unknown Sheet Cell type: %02x",(*result)->type); 624 psiconv_warn(lev+2,off+len,"Unknown Sheet Cell type: %02x",(*result)->type);
575 res = PSICONV_E_PARSE; 625 res = PSICONV_E_PARSE;
576 goto ERROR2; 626 goto ERROR2;
577 } 627 }
578 628
629 if (!((*result)->layout = psiconv_clone_cell_layout(
630 psiconv_get_default_layout(row_default_layouts,
631 col_default_layouts,
632 default_layout,
633 (*result)->row,
634 (*result)->column))))
635 goto ERROR2;
579 if (has_layout) { 636 if (has_layout) {
580 if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len, 637 if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len,
581 &leng,&(*result)->layout))) 638 &leng,(*result)->layout)))
582 goto ERROR2; 639 goto ERROR2;
583 len += leng; 640 len += leng;
584 } 641 }
585 642
586 if ((*result)->calculated) { 643 if ((*result)->calculated) {
611 else 668 else
612 return res; 669 return res;
613} 670}
614 671
615int psiconv_parse_sheet_cell_list(const psiconv_buffer buf, int lev, 672int psiconv_parse_sheet_cell_list(const psiconv_buffer buf, int lev,
616 psiconv_u32 off, int *length, 673 psiconv_u32 off, int *length,
617 psiconv_sheet_cell_list *result) 674 psiconv_sheet_cell_list *result,
675 const psiconv_sheet_cell_layout default_layout,
676 const psiconv_sheet_line_list row_default_layouts,
677 const psiconv_sheet_line_list col_default_layouts)
618{ 678{
619 int res=0; 679 int res=0;
620 int len=0; 680 int len=0;
621 psiconv_u32 temp; 681 psiconv_u32 temp;
622 psiconv_sheet_cell cell; 682 psiconv_sheet_cell cell;
660 len += leng; 720 len += leng;
661 721
662 psiconv_progress(lev+2,off+len,"Going to read all cells"); 722 psiconv_progress(lev+2,off+len,"Going to read all cells");
663 for (i = 0; i < listlen; i++) { 723 for (i = 0; i < listlen; i++) {
664 psiconv_progress(lev+3,off+len,"Going to read cell %d",i); 724 psiconv_progress(lev+3,off+len,"Going to read cell %d",i);
665 if ((res = psiconv_parse_sheet_cell(buf,lev+3,off+len,&leng,&cell))) 725 if ((res = psiconv_parse_sheet_cell(buf,lev+3,off+len,&leng,&cell,
726 default_layout,row_default_layouts,
727 col_default_layouts)))
666 goto ERROR2; 728 goto ERROR2;
667 if ((res = psiconv_list_add(*result,cell))) 729 if ((res = psiconv_list_add(*result,cell)))
668 goto ERROR3; 730 goto ERROR3;
669 free(cell); 731 free(cell);
670 len += leng; 732 len += leng;
778 return res; 840 return res;
779} 841}
780 842
781int psiconv_parse_sheet_cell_layout(const psiconv_buffer buf, int lev, 843int psiconv_parse_sheet_cell_layout(const psiconv_buffer buf, int lev,
782 psiconv_u32 off, int *length, 844 psiconv_u32 off, int *length,
783 psiconv_sheet_cell_layout *result) 845 psiconv_sheet_cell_layout result)
784 846
785{ 847{
786 int res=0; 848 int res=0;
787 int len=0; 849 int len=0;
788 int leng; 850 int leng;
789 psiconv_u8 temp; 851 psiconv_u8 temp;
790 852
791 psiconv_progress(lev+1,off,"Going to read a sheet cell layout"); 853 psiconv_progress(lev+1,off,"Going to read a sheet cell layout");
792 if (!(*result = malloc(sizeof(**result))))
793 goto ERROR1;
794 854
795 (*result)->character = NULL;
796 (*result)->paragraph = NULL;
797 (*result)->numberformat = NULL;
798
799 psiconv_progress(lev+2,off+len, 855 psiconv_progress(lev+2,off+len,
800 "Going to read the first byte (%02x expected)",0x02); 856 "Going to read the first byte (%02x expected)",0x02);
801 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 857 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
802 if (res) 858 if (res)
803 goto ERROR2; 859 goto ERROR1;
804 if (temp != 0x02) { 860 if (temp != 0x02) {
805 psiconv_warn(lev+2,off+len, 861 psiconv_warn(lev+2,off+len,
806 "Worksheet section initial byte unknown value (ignored)"); 862 "Worksheet section initial byte unknown value (ignored)");
807 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); 863 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
808 } 864 }
809 len ++; 865 len ++;
810 866
811 psiconv_progress(lev+2,off+len,"Going to read the default formats flag"); 867 psiconv_progress(lev+2,off+len,"Going to read the default formats flag");
812 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 868 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
813 if (res) 869 if (res)
814 goto ERROR2; 870 goto ERROR1;
815 len ++; 871 len ++;
816 872
817 if (temp & 0x01) { 873 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"); 874 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, 875 if ((res = psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng,
822 (*result)->paragraph))) 876 result->paragraph)))
823 goto ERROR2; 877 goto ERROR1;
824 len += leng; 878 len += leng;
825 } 879 }
826 880
827 if (temp & 0x02) { 881 if (temp & 0x02) {
828 psiconv_progress(lev+3,off+len,"Going to read the default character codes"); 882 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, 883 if ((res = psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng,
832 (*result)->character))) 884 result->character)))
833 goto ERROR2; 885 goto ERROR1;
834 len += leng; 886 len += leng;
835 } 887 }
836 888
837 if (temp & 0x04) { 889 if (temp & 0x04) {
838 psiconv_progress(lev+3,off+len, "Going to read the default number format"); 890 psiconv_progress(lev+3,off+len, "Going to read the default number format");
839 psiconv_parse_sheet_numberformat(buf,lev+3,off+len,&leng, 891 psiconv_parse_sheet_numberformat(buf,lev+3,off+len,&leng,
840 &(*result)->numberformat); 892 result->numberformat);
841 len += leng; 893 len += leng;
842 } 894 }
843 895
844 if (length) 896 if (length)
845 *length = len; 897 *length = len;
847 psiconv_progress(lev,off+len-1, 899 psiconv_progress(lev,off+len-1,
848 "End of sheet cell layout (total length: %08x)", len); 900 "End of sheet cell layout (total length: %08x)", len);
849 901
850 return 0; 902 return 0;
851 903
852ERROR2:
853 psiconv_free_sheet_cell_layout(*result);
854ERROR1: 904ERROR1:
855 psiconv_warn(lev+1,off,"Reading of sheet cell layout failed"); 905 psiconv_warn(lev+1,off,"Reading of sheet cell layout failed");
856 if (length) 906 if (length)
857 *length = 0; 907 *length = 0;
858 if (!res) 908 if (!res)
865int psiconv_parse_sheet_worksheet(const psiconv_buffer buf, int lev, 915int psiconv_parse_sheet_worksheet(const psiconv_buffer buf, int lev,
866 psiconv_u32 off, int *length, 916 psiconv_u32 off, int *length,
867 psiconv_sheet_worksheet *result) 917 psiconv_sheet_worksheet *result)
868{ 918{
869 int res=0; 919 int res=0;
870 psiconv_u32 temp,cells_off,grid_off; 920 psiconv_u32 temp,cells_off,grid_off,rows_off,cols_off;
871 int len=0; 921 int len=0;
872 int leng; 922 int leng;
873 923
874 psiconv_progress(lev+1,off,"Going to read the sheet worksheet section"); 924 psiconv_progress(lev+1,off,"Going to read the sheet worksheet section");
875 if (!(*result = malloc(sizeof(**result)))) 925 if (!(*result = malloc(sizeof(**result))))
898 "Worksheet section flags byte unknown bits (ignored)"); 948 "Worksheet section flags byte unknown bits (ignored)");
899 } 949 }
900 len ++; 950 len ++;
901 951
902 psiconv_progress(lev+2,off+len,"Going to read the default cell layout"); 952 psiconv_progress(lev+2,off+len,"Going to read the default cell layout");
953 if (!((*result)->default_layout = psiconv_basic_cell_layout()))
954 goto ERROR2;
903 if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len,&leng, 955 if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len,&leng,
904 &(*result)->default_layout))) 956 (*result)->default_layout)))
905 goto ERROR2; 957 goto ERROR3;
906 len += leng; 958 len += leng;
907 959
908 psiconv_progress(lev+2,off+len, 960 psiconv_progress(lev+2,off+len,
961 "Going to read the offset of the row defaults Section");
962 rows_off = psiconv_read_u32(buf,lev+2,off+len,&res);
963 if (res)
964 goto ERROR3;
965 psiconv_debug(lev+2,off+len,"Offset: %04x",rows_off);
966 len += 4;
967
968 psiconv_progress(lev+2,off+len,
969 "Going to read the offset of the column defaults Section");
970 cols_off = psiconv_read_u32(buf,lev+2,off+len,&res);
971 if (res)
972 goto ERROR3;
973 psiconv_debug(lev+2,off+len,"Offset: %04x",cols_off);
974 len += 4;
975
976 psiconv_progress(lev+2,off+len,
977 "Going to read the offset of the Cells List");
978 cells_off = psiconv_read_u32(buf,lev+2,off+len,&res);
979 if (res)
980 goto ERROR3;
981 psiconv_debug(lev+2,off+len,"Offset: %04x",cells_off);
982 len += 4;
983
984 psiconv_progress(lev+2,off+len,
985 "Going to read the offset of the Grid Section");
986 grid_off = psiconv_read_u32(buf,lev+2,off+len,&res);
987 if (res)
988 goto ERROR3;
989 psiconv_debug(lev+2,off+len,"Offset: %04x",grid_off);
990 len += 4;
991
992 psiconv_progress(lev+2,off+len,
909 "Going to read the offset of the 1st ??? Section"); 993 "Going to read the offset of the 3rd ??? Section");
910 temp = psiconv_read_u32(buf,lev+2,off+len,&res); 994 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
911 if (res) 995 if (res)
912 goto ERROR3; 996 goto ERROR3;
913 psiconv_debug(lev+2,off+len,"Offset: %04x",temp); 997 psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
914 len += 4; 998 len += 4;
915 999
916 psiconv_progress(lev+2,off+len, 1000 psiconv_progress(lev+2,off+len,"Going to read the row defaults");
917 "Going to read the offset of the 2nd ??? Section"); 1001 if ((res = psiconv_parse_sheet_line_list(buf,lev+2,rows_off,NULL,
918 temp = psiconv_read_u32(buf,lev+2,off+len,&res); 1002 &(*result)->row_default_layouts,
919 if (res) 1003 (*result)->default_layout)))
920 goto ERROR3; 1004 goto ERROR3;
921 psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
922 len += 4;
923 1005
924 psiconv_progress(lev+2,off+len, 1006 psiconv_progress(lev+2,off+len,"Going to read the column defaults");
925 "Going to read the offset of the Cells List"); 1007 if ((res = psiconv_parse_sheet_line_list(buf,lev+2,cols_off,NULL,
926 cells_off = psiconv_read_u32(buf,lev+2,off+len,&res); 1008 &(*result)->col_default_layouts,
927 if (res) 1009 (*result)->default_layout)))
928 goto ERROR3; 1010 goto ERROR4;
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 1011
948 psiconv_progress(lev+2,off+len,"Going to read the cells list"); 1012 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, 1013 if ((res = psiconv_parse_sheet_cell_list(buf,lev+2,cells_off,NULL,
950 &(*result)->cells))) 1014 &(*result)->cells,
1015 (*result)->default_layout,
1016 (*result)->row_default_layouts,
1017 (*result)->col_default_layouts)))
951 goto ERROR3; 1018 goto ERROR5;
952 1019
953 1020
954/* TODO: parse grid section */ 1021/* TODO: parse grid section */
955 1022
956 if (length) 1023 if (length)
958 1025
959 psiconv_progress(lev,off+len-1, 1026 psiconv_progress(lev,off+len-1,
960 "End of sheet worksheet section (total length: %08x)", len); 1027 "End of sheet worksheet section (total length: %08x)", len);
961 return 0; 1028 return 0;
962 1029
1030ERROR5:
1031 psiconv_free_sheet_line_list((*result)->col_default_layouts);
1032ERROR4:
1033 psiconv_free_sheet_line_list((*result)->row_default_layouts);
963ERROR3: 1034ERROR3:
964 psiconv_free_sheet_cell_layout((*result)->default_layout); 1035 psiconv_free_sheet_cell_layout((*result)->default_layout);
965ERROR2: 1036ERROR2:
966 free (*result); 1037 free (*result);
967ERROR1: 1038ERROR1:
972 return -PSICONV_E_NOMEM; 1043 return -PSICONV_E_NOMEM;
973 else 1044 else
974 return res; 1045 return res;
975} 1046}
976 1047
1048int psiconv_parse_sheet_line(const psiconv_buffer buf, int lev,
1049 psiconv_u32 off, int *length,
1050 psiconv_sheet_line *result,
1051 const psiconv_sheet_cell_layout default_layout)
1052{
1053 int res=0;
1054 int len=0;
1055 int leng;
977 1056
1057
1058 psiconv_progress(lev+1,off,"Going to read a sheet line");
1059 if (!(*result = malloc(sizeof(**result))))
1060 goto ERROR1;
1061
1062 psiconv_progress(lev+2,off+len,"Going to read the line number");
1063 (*result)->position = psiconv_read_X(buf,lev+2,off+len,&leng,&res);
1064 if (res)
1065 goto ERROR2;
1066 psiconv_debug(lev+2,off+len,"Line number: %d\n",(*result)->position);
1067 len += leng;
1068
1069 if (!((*result)->layout = psiconv_clone_cell_layout(default_layout)))
1070 goto ERROR2;
1071 if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len,
1072 &leng,(*result)->layout)))
1073 goto ERROR3;
1074 len += leng;
1075
1076 if (length)
1077 *length = len;
1078
1079 psiconv_progress(lev,off+len-1,
1080 "End of the sheet line (total length: %08x)", len);
1081 return 0;
1082
1083ERROR3:
1084 psiconv_free_sheet_cell_layout((*result)->layout);
1085ERROR2:
1086 free (*result);
1087ERROR1:
1088 psiconv_warn(lev+1,off,"Reading of the sheet line failed");
1089 if (length)
1090 *length = 0;
1091 if (!res)
1092 return -PSICONV_E_NOMEM;
1093 else
1094 return res;
1095}
1096
1097
1098int psiconv_parse_sheet_line_list(const psiconv_buffer buf, int lev,
1099 psiconv_u32 off, int *length,
1100 psiconv_sheet_line_list *result,
1101 const psiconv_sheet_cell_layout default_layout)
1102{
1103 int res=0;
1104 int len=0;
1105 psiconv_u32 temp;
1106 psiconv_sheet_line line;
1107 psiconv_u32 listlen,i;
1108 int leng;
1109
1110 psiconv_progress(lev+1,off,"Going to read the sheet line list");
1111 if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_line_s))))
1112 goto ERROR1;
1113
1114 psiconv_progress(lev+2,off+len,
1115 "Going to read the initial byte (%02x expected)",0x02);
1116 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
1117 if (res)
1118 goto ERROR2;
1119 if (temp != 0x02) {
1120 psiconv_warn(lev+2,off+len,
1121 "Sheet line list initial byte unknown value (ignored)");
1122 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
1123 }
1124 len ++;
1125
1126 psiconv_progress(lev+2,off+len,
1127 "Going to read the number of defined lines");
1128 listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res);
1129 if (res)
1130 goto ERROR2;
1131 psiconv_debug(lev+2,off+len,"Number of defined lines: %d",listlen);
1132 len += leng;
1133
1134 psiconv_progress(lev+2,off+len,"Going to read all lines");
1135 for (i = 0; i < listlen; i++) {
1136 psiconv_progress(lev+3,off+len,"Going to read line %d",i);
1137 if ((res = psiconv_parse_sheet_line(buf,lev+3,off+len,&leng,&line,
1138 default_layout)))
1139 goto ERROR2;
1140 if ((res = psiconv_list_add(*result,line)))
1141 goto ERROR3;
1142 free(line);
1143 len += leng;
1144 }
1145
1146 if (length)
1147 *length = len;
1148
1149 psiconv_progress(lev,off+len-1,
1150 "End of sheet line list (total length: %08x)", len);
1151 return 0;
1152
1153ERROR3:
1154 psiconv_free_sheet_line(line);
1155ERROR2:
1156 psiconv_free_sheet_line_list(*result);
1157ERROR1:
1158 psiconv_warn(lev+1,off,"Reading of Sheet Line List failed");
1159 if (length)
1160 *length = 0;
1161 if (!res)
1162 return -PSICONV_E_NOMEM;
1163 else
1164 return res;
1165}
1166

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

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