… | |
… | |
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 | |
|
|
28 | #ifdef DMALLOC |
|
|
29 | #include <dmalloc.h> |
|
|
30 | #endif |
|
|
31 | |
|
|
32 | static psiconv_sheet_cell_layout psiconv_basic_cell_layout(void) |
|
|
33 | { |
|
|
34 | psiconv_sheet_cell_layout result; |
|
|
35 | if (!(result = malloc(sizeof(*result)))) |
|
|
36 | goto ERROR1; |
|
|
37 | if (!(result->character = psiconv_basic_character_layout())) |
|
|
38 | goto ERROR2; |
|
|
39 | if (!(result->paragraph = psiconv_basic_paragraph_layout())) |
|
|
40 | goto ERROR3; |
|
|
41 | if (!(result->numberformat = malloc(sizeof(*result->numberformat)))) |
|
|
42 | goto ERROR4; |
|
|
43 | result->numberformat->code = psiconv_numberformat_general; |
|
|
44 | result->numberformat->decimal = 2; |
|
|
45 | return result; |
|
|
46 | ERROR4: |
|
|
47 | psiconv_free_paragraph_layout(result->paragraph); |
|
|
48 | ERROR3: |
|
|
49 | psiconv_free_character_layout(result->character); |
|
|
50 | ERROR2: |
|
|
51 | free(result); |
|
|
52 | ERROR1: |
|
|
53 | return NULL; |
|
|
54 | } |
|
|
55 | |
|
|
56 | static psiconv_sheet_cell_layout psiconv_clone_cell_layout |
|
|
57 | (psiconv_sheet_cell_layout original) |
|
|
58 | { |
|
|
59 | psiconv_sheet_cell_layout result; |
|
|
60 | if (!(result = malloc(sizeof(*result)))) |
|
|
61 | goto ERROR1; |
|
|
62 | if (!(result->character = |
|
|
63 | psiconv_clone_character_layout(original->character))) |
|
|
64 | goto ERROR2; |
|
|
65 | if (!(result->paragraph = |
|
|
66 | psiconv_clone_paragraph_layout(original->paragraph))) |
|
|
67 | goto ERROR3; |
|
|
68 | if (!(result->numberformat = malloc(sizeof(*result->numberformat)))) |
|
|
69 | goto ERROR4; |
|
|
70 | result->numberformat->code = original->numberformat->code; |
|
|
71 | result->numberformat->decimal = original->numberformat->decimal; |
|
|
72 | return result; |
|
|
73 | ERROR4: |
|
|
74 | psiconv_free_paragraph_layout(result->paragraph); |
|
|
75 | ERROR3: |
|
|
76 | psiconv_free_character_layout(result->character); |
|
|
77 | ERROR2: |
|
|
78 | free(result); |
|
|
79 | ERROR1: |
|
|
80 | return NULL; |
|
|
81 | } |
|
|
82 | |
|
|
83 | static psiconv_sheet_cell_reference_t |
|
|
84 | psiconv_read_var_cellref (const psiconv_config config, |
|
|
85 | const psiconv_buffer buf, int lev, |
|
|
86 | psiconv_u32 off, int *length, |
|
|
87 | int *status) |
|
|
88 | { |
|
|
89 | int len=0; |
|
|
90 | int res; |
|
|
91 | psiconv_sheet_cell_reference_t result; |
|
|
92 | psiconv_u32 temp; |
|
|
93 | |
|
|
94 | psiconv_progress(config,lev+1,off+len,"Going to read a sheet cell reference"); |
|
|
95 | psiconv_progress(config,lev+2,off+len, |
|
|
96 | "Going to read the initial byte (%02x expected)",0x00); |
|
|
97 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
|
|
98 | if (res) |
|
|
99 | goto ERROR1; |
|
|
100 | if (temp != 0x00) { |
|
|
101 | psiconv_warn(config,lev+2,off+len, |
|
|
102 | "Sheet cell reference initial byte unknown value (ignored)"); |
|
|
103 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
|
|
104 | } |
|
|
105 | len ++; |
|
|
106 | |
|
|
107 | temp = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
|
|
108 | if (res) |
|
|
109 | goto ERROR1; |
|
|
110 | if (temp & 0xffff0000) { |
|
|
111 | psiconv_warn(config,lev+2,off+len, |
|
|
112 | "Sheet cell row reference to unknown row (reset)"); |
|
|
113 | } |
|
|
114 | result.row.offset = temp; |
|
|
115 | result.row.absolute = psiconv_bool_true; |
|
|
116 | len += 4; |
|
|
117 | |
|
|
118 | temp = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
|
|
119 | if (res) |
|
|
120 | goto ERROR1; |
|
|
121 | if (temp & 0xffff0000) { |
|
|
122 | psiconv_warn(config,lev+2,off+len, |
|
|
123 | "Sheet cell column reference to unknown row (reset)"); |
|
|
124 | } |
|
|
125 | result.column.offset = temp; |
|
|
126 | result.column.absolute = psiconv_bool_true; |
|
|
127 | len += 4; |
|
|
128 | |
|
|
129 | if (length) |
|
|
130 | *length = len; |
|
|
131 | |
|
|
132 | psiconv_progress(config,lev,off+len-1, |
|
|
133 | "End of sheet column reference (total length: %08x)", len); |
|
|
134 | return result; |
|
|
135 | ERROR1: |
|
|
136 | psiconv_warn(config,lev+1,off,"Reading of Sheet Column Reference failed"); |
|
|
137 | if (length) |
|
|
138 | *length = 0; |
|
|
139 | if (status) |
|
|
140 | *status = res?res:-PSICONV_E_NOMEM; |
|
|
141 | return result; |
|
|
142 | } |
|
|
143 | |
|
|
144 | static psiconv_sheet_cell_block_t |
|
|
145 | psiconv_read_var_cellblock (const psiconv_config config, |
|
|
146 | const psiconv_buffer buf, int lev, |
|
|
147 | psiconv_u32 off, int *length, |
|
|
148 | int *status) |
|
|
149 | { |
|
|
150 | int len=0; |
|
|
151 | int res; |
|
|
152 | psiconv_sheet_cell_block_t result; |
|
|
153 | psiconv_u32 temp; |
|
|
154 | |
|
|
155 | psiconv_progress(config,lev+1,off+len,"Going to read a sheet cell block reference"); |
|
|
156 | psiconv_progress(config,lev+2,off+len, |
|
|
157 | "Going to read the initial byte (%02x expected)",0x00); |
|
|
158 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
|
|
159 | if (res) |
|
|
160 | goto ERROR1; |
|
|
161 | if (temp != 0x00) { |
|
|
162 | psiconv_warn(config,lev+2,off+len, |
|
|
163 | "Sheet cell reference initial byte unknown value (ignored)"); |
|
|
164 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
|
|
165 | } |
|
|
166 | len ++; |
|
|
167 | |
|
|
168 | temp = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
|
|
169 | if (res) |
|
|
170 | goto ERROR1; |
|
|
171 | if (temp & 0xffff0000) { |
|
|
172 | psiconv_warn(config,lev+2,off+len, |
|
|
173 | "Sheet block initial row reference to unknown row (reset)"); |
|
|
174 | } |
|
|
175 | result.first.row.offset = temp; |
|
|
176 | result.first.row.absolute = psiconv_bool_true; |
|
|
177 | len += 4; |
|
|
178 | |
|
|
179 | temp = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
|
|
180 | if (res) |
|
|
181 | goto ERROR1; |
|
|
182 | if (temp & 0xffff0000) { |
|
|
183 | psiconv_warn(config,lev+2,off+len, |
|
|
184 | "Sheet block initial column reference to unknown row (reset)"); |
|
|
185 | } |
|
|
186 | result.first.column.offset = temp; |
|
|
187 | result.first.column.absolute = psiconv_bool_true; |
|
|
188 | len += 4; |
|
|
189 | |
|
|
190 | temp = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
|
|
191 | if (res) |
|
|
192 | goto ERROR1; |
|
|
193 | if (temp & 0xffff0000) { |
|
|
194 | psiconv_warn(config,lev+2,off+len, |
|
|
195 | "Sheet block final row reference to unknown row (reset)"); |
|
|
196 | } |
|
|
197 | result.last.row.offset = temp; |
|
|
198 | result.last.row.absolute = psiconv_bool_true; |
|
|
199 | len += 4; |
|
|
200 | |
|
|
201 | temp = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
|
|
202 | if (res) |
|
|
203 | goto ERROR1; |
|
|
204 | if (temp & 0xffff0000) { |
|
|
205 | psiconv_warn(config,lev+2,off+len, |
|
|
206 | "Sheet block final column reference to unknown row (reset)"); |
|
|
207 | } |
|
|
208 | result.last.column.offset = temp; |
|
|
209 | result.last.column.absolute = psiconv_bool_true; |
|
|
210 | len += 4; |
|
|
211 | |
|
|
212 | if (length) |
|
|
213 | *length = len; |
|
|
214 | |
|
|
215 | psiconv_progress(config,lev,off+len-1, |
|
|
216 | "End of sheet cell block reference (total length: %08x)", |
|
|
217 | len); |
|
|
218 | return result; |
|
|
219 | ERROR1: |
|
|
220 | psiconv_warn(config,lev+1,off,"Reading of Sheet Cell Block Reference failed"); |
|
|
221 | if (length) |
|
|
222 | *length = 0; |
|
|
223 | if (status) |
|
|
224 | *status = res?res:-PSICONV_E_NOMEM; |
|
|
225 | return result; |
|
|
226 | } |
|
|
227 | |
28 | int psiconv_parse_sheet_numberformat(const psiconv_buffer buf, int lev, |
228 | int psiconv_parse_sheet_numberformat(const psiconv_config config, |
|
|
229 | const psiconv_buffer buf, int lev, |
29 | psiconv_u32 off, int *length, |
230 | psiconv_u32 off, int *length, |
30 | psiconv_sheet_numberformat *result) |
231 | psiconv_sheet_numberformat result) |
31 | { |
232 | { |
32 | int res=0; |
233 | int res=0; |
33 | int len=0; |
234 | int len=0; |
34 | psiconv_u8 temp; |
235 | psiconv_u8 temp; |
35 | |
236 | |
36 | psiconv_progress(lev+1,off,"Going to read a sheet numberformat"); |
237 | psiconv_progress(config,lev+1,off,"Going to read a sheet numberformat"); |
37 | if (!(*result = malloc(sizeof(**result)))) |
|
|
38 | goto ERROR1; |
|
|
39 | |
238 | |
40 | psiconv_progress(lev+2,off+len, |
239 | psiconv_progress(config,lev+2,off+len, |
41 | "Going to read the initial byte (%02x expected)",0x02); |
240 | "Going to read the initial byte (%02x expected)",0x02); |
42 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
241 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
43 | if (res) |
242 | if (res) |
44 | goto ERROR2; |
243 | goto ERROR1; |
45 | if (temp != 0x02) { |
244 | if (temp != 0x02) { |
46 | psiconv_warn(lev+2,off+len, |
245 | psiconv_warn(config,lev+2,off+len, |
47 | "Sheet numberformat initial byte unknown value (ignored)"); |
246 | "Sheet numberformat initial byte unknown value (ignored)"); |
48 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
247 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
49 | } |
248 | } |
50 | len ++; |
249 | len ++; |
51 | |
250 | |
52 | psiconv_progress(lev+2,off+len, "Going to read the code byte"); |
251 | psiconv_progress(config,lev+2,off+len, "Going to read the code byte"); |
53 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
252 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
54 | if (res) |
253 | if (res) |
55 | goto ERROR2; |
254 | goto ERROR1; |
56 | psiconv_debug(lev+2,off+len,"Code: %02x",temp); |
255 | psiconv_debug(config,lev+2,off+len,"Code: %02x",temp); |
57 | if (temp == 0x00) |
256 | if (temp == 0x00) |
58 | (*result)->code = psiconv_numberformat_general; |
257 | result->code = psiconv_numberformat_general; |
59 | else if (temp == 0x02) |
258 | else if (temp == 0x02) |
60 | (*result)->code = psiconv_numberformat_fixeddecimal; |
259 | result->code = psiconv_numberformat_fixeddecimal; |
61 | else if (temp == 0x04) |
260 | else if (temp == 0x04) |
62 | (*result)->code = psiconv_numberformat_scientific; |
261 | result->code = psiconv_numberformat_scientific; |
63 | else if (temp == 0x06) |
262 | else if (temp == 0x06) |
64 | (*result)->code = psiconv_numberformat_currency; |
263 | result->code = psiconv_numberformat_currency; |
65 | else if (temp == 0x08) |
264 | else if (temp == 0x08) |
66 | (*result)->code = psiconv_numberformat_percent; |
265 | result->code = psiconv_numberformat_percent; |
67 | else if (temp == 0x0A) |
266 | else if (temp == 0x0A) |
68 | (*result)->code = psiconv_numberformat_triads; |
267 | result->code = psiconv_numberformat_triads; |
69 | else if (temp == 0x0C) |
268 | else if (temp == 0x0C) |
70 | (*result)->code = psiconv_numberformat_boolean; |
269 | result->code = psiconv_numberformat_boolean; |
71 | else if (temp == 0x0E) |
270 | else if (temp == 0x0E) |
72 | (*result)->code = psiconv_numberformat_text; |
271 | result->code = psiconv_numberformat_text; |
73 | else if (temp == 0x10) |
272 | else if (temp == 0x10) |
74 | (*result)->code = psiconv_numberformat_date_ddmm; |
273 | result->code = psiconv_numberformat_date_dmm; |
75 | else if (temp == 0x12) |
274 | else if (temp == 0x12) |
76 | (*result)->code = psiconv_numberformat_date_mmdd; |
275 | result->code = psiconv_numberformat_date_mmd; |
77 | else if (temp == 0x14) |
276 | else if (temp == 0x14) |
78 | (*result)->code = psiconv_numberformat_date_ddmmyy; |
277 | result->code = psiconv_numberformat_date_ddmmyy; |
79 | else if (temp == 0x16) |
278 | else if (temp == 0x16) |
80 | (*result)->code = psiconv_numberformat_date_mmddyy; |
279 | result->code = psiconv_numberformat_date_mmddyy; |
81 | else if (temp == 0x18) |
280 | else if (temp == 0x18) |
82 | (*result)->code = psiconv_numberformat_date_yymmdd; |
281 | result->code = psiconv_numberformat_date_yymmdd; |
83 | else if (temp == 0x1A) |
282 | else if (temp == 0x1A) |
84 | (*result)->code = psiconv_numberformat_date_ddmmm; |
283 | result->code = psiconv_numberformat_date_dmmm; |
85 | else if (temp == 0x1C) |
284 | else if (temp == 0x1C) |
86 | (*result)->code = psiconv_numberformat_date_ddmmmyy; |
285 | result->code = psiconv_numberformat_date_dmmmyy; |
87 | else if (temp == 0x1E) |
286 | else if (temp == 0x1E) |
88 | (*result)->code = psiconv_numberformat_date_ddmmmyyyy; |
287 | result->code = psiconv_numberformat_date_ddmmmyy; |
89 | else if (temp == 0x20) |
288 | else if (temp == 0x20) |
90 | (*result)->code = psiconv_numberformat_date_mmm; |
289 | result->code = psiconv_numberformat_date_mmm; |
91 | else if (temp == 0x22) |
290 | else if (temp == 0x22) |
92 | (*result)->code = psiconv_numberformat_date_monthname; |
291 | result->code = psiconv_numberformat_date_monthname; |
93 | else if (temp == 0x24) |
292 | else if (temp == 0x24) |
94 | (*result)->code = psiconv_numberformat_date_mmmyy; |
293 | result->code = psiconv_numberformat_date_mmmyy; |
95 | else if (temp == 0x26) |
294 | else if (temp == 0x26) |
96 | (*result)->code = psiconv_numberformat_date_monthnameyy; |
295 | result->code = psiconv_numberformat_date_monthnameyy; |
97 | else if (temp == 0x28) |
296 | else if (temp == 0x28) |
98 | (*result)->code = psiconv_numberformat_date_monthnameddyyyy; |
297 | result->code = psiconv_numberformat_date_monthnamedyyyy; |
99 | else if (temp == 0x2A) |
298 | else if (temp == 0x2A) |
100 | (*result)->code = psiconv_numberformat_datetime_ddmmyyyyhhii; |
299 | result->code = psiconv_numberformat_datetime_ddmmyyyyhhii; |
101 | else if (temp == 0x2C) |
300 | else if (temp == 0x2C) |
102 | (*result)->code = psiconv_numberformat_datetime_ddmmyyyyHHii; |
301 | result->code = psiconv_numberformat_datetime_ddmmyyyyHHii; |
103 | else if (temp == 0x2E) |
302 | else if (temp == 0x2E) |
104 | (*result)->code = psiconv_numberformat_datetime_mmddyyyyhhii; |
303 | result->code = psiconv_numberformat_datetime_mmddyyyyhhii; |
105 | else if (temp == 0x30) |
304 | else if (temp == 0x30) |
106 | (*result)->code = psiconv_numberformat_datetime_mmddyyyyHHii; |
305 | result->code = psiconv_numberformat_datetime_mmddyyyyHHii; |
107 | else if (temp == 0x32) |
306 | else if (temp == 0x32) |
108 | (*result)->code = psiconv_numberformat_datetime_yyyymmddhhii; |
307 | result->code = psiconv_numberformat_datetime_yyyymmddhhii; |
109 | else if (temp == 0x34) |
308 | else if (temp == 0x34) |
110 | (*result)->code = psiconv_numberformat_datetime_yyyymmddHHii; |
309 | result->code = psiconv_numberformat_datetime_yyyymmddHHii; |
111 | else if (temp == 0x36) |
310 | else if (temp == 0x36) |
112 | (*result)->code = psiconv_numberformat_time_hhii; |
311 | result->code = psiconv_numberformat_time_hhii; |
113 | else if (temp == 0x38) |
312 | else if (temp == 0x38) |
114 | (*result)->code = psiconv_numberformat_time_hhiiss; |
313 | result->code = psiconv_numberformat_time_hhiiss; |
115 | else if (temp == 0x3A) |
314 | else if (temp == 0x3A) |
116 | (*result)->code = psiconv_numberformat_time_HHii; |
315 | result->code = psiconv_numberformat_time_HHii; |
117 | else if (temp == 0x3C) |
316 | else if (temp == 0x3C) |
118 | (*result)->code = psiconv_numberformat_time_HHiiss; |
317 | result->code = psiconv_numberformat_time_HHiiss; |
119 | else { |
318 | else { |
120 | psiconv_warn(lev+2,off+len,"Unknown number format (assumed general)"); |
319 | psiconv_warn(config,lev+2,off+len,"Unknown number format (assumed general)"); |
121 | (*result)->code = psiconv_numberformat_general; |
320 | result->code = psiconv_numberformat_general; |
122 | } |
321 | } |
123 | len ++; |
322 | len ++; |
124 | |
323 | |
125 | psiconv_progress(lev+2,off+len, "Going to read the number of decimals"); |
324 | psiconv_progress(config,lev+2,off+len, "Going to read the number of decimals"); |
126 | (*result)->decimal = psiconv_read_u8(buf,lev+2,off+len,&res); |
325 | result->decimal = psiconv_read_u8(config,buf,lev+2,off+len,&res) >> 1; |
127 | if (res) |
326 | if (res) |
128 | goto ERROR2; |
327 | goto ERROR1; |
129 | psiconv_debug(lev+2,off+len,"Decimals: %d",(*result)->decimal); |
328 | psiconv_debug(config,lev+2,off+len,"Decimals: %d",result->decimal); |
130 | len ++; |
329 | len ++; |
131 | |
330 | |
132 | if (length) |
331 | if (length) |
133 | *length = len; |
332 | *length = len; |
134 | |
333 | |
135 | psiconv_progress(lev,off+len-1, |
334 | psiconv_progress(config,lev,off+len-1, |
136 | "End of sheet number format (total length: %08x)", len); |
335 | "End of sheet number format (total length: %08x)", len); |
137 | return 0; |
336 | return 0; |
138 | |
337 | |
139 | ERROR2: |
338 | ERROR1: |
140 | free (*result); |
|
|
141 | ERROR1: |
|
|
142 | psiconv_warn(lev+1,off,"Reading of Sheet Number Format failed"); |
339 | psiconv_warn(config,lev+1,off,"Reading of Sheet Number Format failed"); |
143 | if (length) |
340 | if (length) |
144 | *length = 0; |
341 | *length = 0; |
145 | if (!res) |
342 | if (!res) |
146 | return -PSICONV_E_NOMEM; |
343 | return -PSICONV_E_NOMEM; |
147 | else |
344 | else |
148 | return res; |
345 | return res; |
149 | } |
346 | } |
150 | |
347 | |
151 | int psiconv_parse_sheet_status_section(const psiconv_buffer buf, int lev, |
348 | int psiconv_parse_sheet_status_section(const psiconv_config config, |
|
|
349 | const psiconv_buffer buf, int lev, |
152 | psiconv_u32 off, int *length, |
350 | psiconv_u32 off, int *length, |
153 | psiconv_sheet_status_section *result) |
351 | psiconv_sheet_status_section *result) |
154 | { |
352 | { |
155 | int res=0; |
353 | int res=0; |
156 | int len=0; |
354 | int len=0; |
157 | psiconv_u32 temp; |
355 | psiconv_u32 temp; |
158 | int leng; |
356 | int leng; |
159 | |
357 | |
160 | psiconv_progress(lev+1,off,"Going to read the sheet status section"); |
358 | psiconv_progress(config,lev+1,off,"Going to read the sheet status section"); |
161 | if (!(*result = malloc(sizeof(**result)))) |
359 | if (!(*result = malloc(sizeof(**result)))) |
162 | goto ERROR1; |
360 | goto ERROR1; |
163 | |
361 | |
164 | psiconv_progress(lev+2,off+len, |
362 | psiconv_progress(config,lev+2,off+len, |
165 | "Going to read the initial byte (%02x expected)",0x02); |
363 | "Going to read the initial byte (%02x expected)",0x02); |
166 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
364 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
167 | if (res) |
365 | if (res) |
168 | goto ERROR2; |
366 | goto ERROR2; |
169 | if (temp != 0x02) { |
367 | if (temp != 0x02) { |
170 | psiconv_warn(lev+2,off+len, |
368 | psiconv_warn(config,lev+2,off+len, |
171 | "Sheet status section initial byte unknown value (ignored)"); |
369 | "Sheet status section initial byte unknown value (ignored)"); |
172 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
370 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
173 | } |
371 | } |
174 | len ++; |
372 | len ++; |
175 | |
373 | |
176 | psiconv_progress(lev+2,off+len, |
374 | psiconv_progress(config,lev+2,off+len, |
177 | "Going to read the cursor row"); |
375 | "Going to read the cursor row"); |
178 | (*result)->cursor_row = psiconv_read_u32(buf,lev+2,off + len,&res); |
376 | (*result)->cursor_row = psiconv_read_u32(config,buf,lev+2,off + len,&res); |
179 | if (res) |
377 | if (res) |
180 | goto ERROR2; |
378 | goto ERROR2; |
181 | psiconv_debug(lev+2,off+len,"Cursor row: %08x", |
379 | psiconv_debug(config,lev+2,off+len,"Cursor row: %08x", |
182 | (*result)->cursor_row); |
380 | (*result)->cursor_row); |
183 | len += 0x04; |
381 | len += 0x04; |
184 | |
382 | |
185 | psiconv_progress(lev+2,off+len, |
383 | psiconv_progress(config,lev+2,off+len, |
186 | "Going to read the cursor column"); |
384 | "Going to read the cursor column"); |
187 | (*result)->cursor_column = psiconv_read_u32(buf,lev+2,off + len,&res); |
385 | (*result)->cursor_column = psiconv_read_u32(config,buf,lev+2,off + len,&res); |
188 | if (res) |
386 | if (res) |
189 | goto ERROR2; |
387 | goto ERROR2; |
190 | psiconv_debug(lev+2,off+len,"Cursor column: %08x", |
388 | psiconv_debug(config,lev+2,off+len,"Cursor column: %08x", |
191 | (*result)->cursor_column); |
389 | (*result)->cursor_column); |
192 | len += 0x04; |
390 | len += 0x04; |
193 | |
391 | |
194 | psiconv_progress(lev+2,off+len,"Going to read initially display graph"); |
392 | psiconv_progress(config,lev+2,off+len,"Going to read initially display graph"); |
195 | if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng, |
393 | if ((res = psiconv_parse_bool(config,buf,lev+2,off+len,&leng, |
196 | &(*result)->show_graph))) |
394 | &(*result)->show_graph))) |
197 | goto ERROR2; |
395 | goto ERROR2; |
198 | len += leng; |
396 | len += leng; |
199 | |
397 | |
200 | psiconv_progress(lev+2,off+len, |
398 | psiconv_progress(config,lev+2,off+len, |
201 | "Going to read the toolbar status byte"); |
399 | "Going to read the toolbar status byte"); |
202 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
400 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
203 | if (res) |
401 | if (res) |
204 | goto ERROR2; |
402 | goto ERROR2; |
205 | |
403 | |
206 | (*result)->show_side_sheet_toolbar = temp&0x01 ? psiconv_bool_true : |
404 | (*result)->show_side_sheet_toolbar = temp&0x01 ? psiconv_bool_true : |
207 | psiconv_bool_false; |
405 | psiconv_bool_false; |
208 | psiconv_debug(lev+2,off+len,"Show side sheet toolbar: %02x", |
406 | psiconv_debug(config,lev+2,off+len,"Show side sheet toolbar: %02x", |
209 | (*result)->show_side_sheet_toolbar); |
407 | (*result)->show_side_sheet_toolbar); |
210 | (*result)->show_top_sheet_toolbar = temp&0x02 ? psiconv_bool_true : |
408 | (*result)->show_top_sheet_toolbar = temp&0x02 ? psiconv_bool_true : |
211 | psiconv_bool_false; |
409 | psiconv_bool_false; |
212 | psiconv_debug(lev+2,off+len,"Show top sheet toolbar: %02x", |
410 | psiconv_debug(config,lev+2,off+len,"Show top sheet toolbar: %02x", |
213 | (*result)->show_top_sheet_toolbar); |
411 | (*result)->show_top_sheet_toolbar); |
214 | (*result)->show_side_graph_toolbar = temp&0x04 ? psiconv_bool_true : |
412 | (*result)->show_side_graph_toolbar = temp&0x04 ? psiconv_bool_true : |
215 | psiconv_bool_false; |
413 | psiconv_bool_false; |
216 | psiconv_debug(lev+2,off+len,"Show side graph toolbar: %02x", |
414 | psiconv_debug(config,lev+2,off+len,"Show side graph toolbar: %02x", |
217 | (*result)->show_side_graph_toolbar); |
415 | (*result)->show_side_graph_toolbar); |
218 | (*result)->show_top_graph_toolbar = temp&0x08 ? psiconv_bool_true : |
416 | (*result)->show_top_graph_toolbar = temp&0x08 ? psiconv_bool_true : |
219 | psiconv_bool_false; |
417 | psiconv_bool_false; |
220 | psiconv_debug(lev+2,off+len,"Show top graph toolbar: %02x", |
418 | psiconv_debug(config,lev+2,off+len,"Show top graph toolbar: %02x", |
221 | (*result)->show_top_graph_toolbar); |
419 | (*result)->show_top_graph_toolbar); |
222 | if (temp & 0xf0) { |
420 | if (temp & 0xf0) { |
223 | psiconv_warn(lev+2,off+len,"Sheet status section toolbar byte " |
421 | psiconv_warn(config,lev+2,off+len,"Sheet status section toolbar byte " |
224 | "flags contains unknown flags (ignored)"); |
422 | "flags contains unknown flags (ignored)"); |
225 | psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0xf0); |
423 | psiconv_debug(config,lev+2,off+len,"Unknown flags: %02x",temp & 0xf0); |
226 | } |
424 | } |
227 | len ++; |
425 | len ++; |
228 | |
426 | |
229 | psiconv_progress(lev+2,off+len, |
427 | psiconv_progress(config,lev+2,off+len, |
230 | "Going to read the scrollbar status byte"); |
428 | "Going to read the scrollbar status byte"); |
231 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
429 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
232 | if (res) |
430 | if (res) |
233 | goto ERROR2; |
431 | goto ERROR2; |
234 | if ((temp & 0x03) == 0x03) { |
432 | if ((temp & 0x03) == 0x03) { |
235 | psiconv_warn(lev+2,off+len,"Sheet status section scrollbar byte " |
433 | psiconv_warn(config,lev+2,off+len,"Sheet status section scrollbar byte " |
236 | "flags contains unknown flags (ignored)"); |
434 | "flags contains unknown flags (ignored)"); |
237 | psiconv_debug(lev+2,off+len,"Unknown flag: %02x",temp & 0x03); |
435 | psiconv_debug(config,lev+2,off+len,"Unknown flag: %02x",temp & 0x03); |
238 | } |
436 | } |
239 | (*result)->show_horizontal_scrollbar = (temp&0x03) == 1? psiconv_triple_off : |
437 | (*result)->show_horizontal_scrollbar = (temp&0x03) == 1? psiconv_triple_off : |
240 | (temp&0x03) == 2? psiconv_triple_auto: |
438 | (temp&0x03) == 2? psiconv_triple_auto: |
241 | psiconv_triple_on; |
439 | psiconv_triple_on; |
242 | psiconv_debug(lev+2,off+len,"Show horizontal scrollbar: %02x", |
440 | psiconv_debug(config,lev+2,off+len,"Show horizontal scrollbar: %02x", |
243 | (*result)->show_horizontal_scrollbar); |
441 | (*result)->show_horizontal_scrollbar); |
244 | if ((temp & 0x0c) == 0x0c) { |
442 | if ((temp & 0x0c) == 0x0c) { |
245 | psiconv_warn(lev+2,off+len,"Sheet status section scrollbar byte " |
443 | psiconv_warn(config,lev+2,off+len,"Sheet status section scrollbar byte " |
246 | "flags contains unknown flags (ignored)"); |
444 | "flags contains unknown flags (ignored)"); |
247 | psiconv_debug(lev+2,off+len,"Unknown flag: %02x",temp & 0x0c); |
445 | psiconv_debug(config,lev+2,off+len,"Unknown flag: %02x",temp & 0x0c); |
248 | } |
446 | } |
249 | (*result)->show_vertical_scrollbar = (temp&0x0c) ==0x04? psiconv_triple_off: |
447 | (*result)->show_vertical_scrollbar = (temp&0x0c) ==0x04? psiconv_triple_off: |
250 | (temp&0x0c) ==0x08? psiconv_triple_auto: |
448 | (temp&0x0c) ==0x08? psiconv_triple_auto: |
251 | psiconv_triple_on; |
449 | psiconv_triple_on; |
252 | psiconv_debug(lev+2,off+len,"Show vertical scrollbar: %02x", |
450 | psiconv_debug(config,lev+2,off+len,"Show vertical scrollbar: %02x", |
253 | (*result)->show_vertical_scrollbar); |
451 | (*result)->show_vertical_scrollbar); |
254 | if (temp & 0xf0) { |
452 | if (temp & 0xf0) { |
255 | psiconv_warn(lev+2,off+len,"Sheet status section scrollbar byte " |
453 | psiconv_warn(config,lev+2,off+len,"Sheet status section scrollbar byte " |
256 | "flags contains unknown flags (ignored)"); |
454 | "flags contains unknown flags (ignored)"); |
257 | psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0xf0); |
455 | psiconv_debug(config,lev+2,off+len,"Unknown flags: %02x",temp & 0xf0); |
258 | } |
456 | } |
259 | len ++; |
457 | len ++; |
260 | |
458 | |
261 | psiconv_progress(lev+2,off+len, |
459 | psiconv_progress(config,lev+2,off+len, |
262 | "Going to read an unknown byte (%02x expected)",0x00); |
460 | "Going to read an unknown byte (%02x expected)",0x00); |
263 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
461 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
264 | if (res) |
462 | if (res) |
265 | goto ERROR2; |
463 | goto ERROR2; |
266 | if (temp != 0x00) { |
464 | if (temp != 0x00) { |
267 | psiconv_warn(lev+2,off+len, |
465 | psiconv_warn(config,lev+2,off+len, |
268 | "Sheet status section unknown byte unknown value (ignored)"); |
466 | "Sheet status section unknown byte unknown value (ignored)"); |
269 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
467 | psiconv_debug(config,lev+2,off+len,"Unknown byte: %02x",temp); |
270 | } |
468 | } |
271 | len ++; |
469 | len ++; |
272 | |
470 | |
273 | psiconv_progress(lev+2,off+len,"Going to read sheet display size"); |
471 | psiconv_progress(config,lev+2,off+len,"Going to read sheet display size"); |
274 | (*result)->sheet_display_size = psiconv_read_u32(buf,lev+2,off + len,&res); |
472 | (*result)->sheet_display_size = psiconv_read_u32(config,buf,lev+2,off + len,&res); |
275 | if (res) |
473 | if (res) |
276 | goto ERROR2; |
474 | goto ERROR2; |
277 | psiconv_debug(lev+2,off+len,"Sheet display size: %08x", |
475 | psiconv_debug(config,lev+2,off+len,"Sheet display size: %08x", |
278 | (*result)->sheet_display_size); |
476 | (*result)->sheet_display_size); |
279 | len += 0x04; |
477 | len += 0x04; |
280 | |
478 | |
281 | psiconv_progress(lev+2,off+len,"Going to read graph display size"); |
479 | psiconv_progress(config,lev+2,off+len,"Going to read graph display size"); |
282 | (*result)->graph_display_size = psiconv_read_u32(buf,lev+2,off + len,&res); |
480 | (*result)->graph_display_size = psiconv_read_u32(config,buf,lev+2,off + len,&res); |
283 | if (res) |
481 | if (res) |
284 | goto ERROR2; |
482 | goto ERROR2; |
285 | psiconv_debug(lev+2,off+len,"Graph display size: %08x", |
483 | psiconv_debug(config,lev+2,off+len,"Graph display size: %08x", |
286 | (*result)->graph_display_size); |
484 | (*result)->graph_display_size); |
287 | len += 0x04; |
485 | len += 0x04; |
288 | |
486 | |
289 | if (length) |
487 | if (length) |
290 | *length = len; |
488 | *length = len; |
291 | |
489 | |
292 | psiconv_progress(lev,off+len-1, |
490 | psiconv_progress(config,lev,off+len-1, |
293 | "End of sheet status section (total length: %08x)", len); |
491 | "End of sheet status section (total length: %08x)", len); |
294 | return 0; |
492 | return 0; |
295 | |
493 | |
296 | ERROR2: |
494 | ERROR2: |
297 | free (*result); |
495 | free (*result); |
298 | ERROR1: |
496 | ERROR1: |
299 | psiconv_warn(lev+1,off,"Reading of Sheet Status Section failed"); |
497 | psiconv_warn(config,lev+1,off,"Reading of Sheet Status Section failed"); |
300 | if (length) |
498 | if (length) |
301 | *length = 0; |
499 | *length = 0; |
302 | if (!res) |
500 | if (!res) |
303 | return -PSICONV_E_NOMEM; |
501 | return -PSICONV_E_NOMEM; |
304 | else |
502 | else |
305 | return res; |
503 | return res; |
306 | } |
504 | } |
307 | |
505 | |
308 | int psiconv_parse_sheet_workbook_section(const psiconv_buffer buf, int lev, |
506 | int psiconv_parse_sheet_workbook_section(const psiconv_config config, |
|
|
507 | const psiconv_buffer buf, int lev, |
309 | psiconv_u32 off, int *length, |
508 | psiconv_u32 off, int *length, |
310 | psiconv_sheet_workbook_section *result) |
509 | psiconv_sheet_workbook_section *result) |
311 | { |
510 | { |
312 | int res=0; |
511 | int res=0,with_name; |
313 | psiconv_u32 temp,formulas_off,worksheets_off; |
512 | psiconv_u32 temp,formulas_off,worksheets_off,info_off,var_off,name_off=0; |
314 | int len=0; |
513 | int len=0; |
315 | |
514 | |
316 | psiconv_progress(lev+1,off,"Going to read the sheet workbook section"); |
515 | psiconv_progress(config,lev+1,off,"Going to read the sheet workbook section"); |
317 | if (!(*result = malloc(sizeof(**result)))) |
516 | if (!(*result = malloc(sizeof(**result)))) |
318 | goto ERROR1; |
517 | goto ERROR1; |
319 | |
518 | |
320 | psiconv_progress(lev+2,off+len, |
519 | psiconv_progress(config,lev+2,off+len, |
321 | "Going to read the initial byte (%02x expected)",0x04); |
520 | "Going to read the initial byte (%02x or %02x expected)", |
|
|
521 | 0x02,0x04); |
322 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
522 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
323 | if (res) |
523 | if (res) |
324 | goto ERROR2; |
524 | goto ERROR2; |
325 | if (temp != 0x04) { |
525 | if ((temp != 0x04) && temp !=0x02) { |
326 | psiconv_warn(lev+2,off+len, |
526 | psiconv_warn(config,lev+2,off+len, |
327 | "Sheet workbook section initial byte unknown value (ignored)"); |
527 | "Sheet workbook section initial byte unknown value (ignored)"); |
328 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
528 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
329 | } |
529 | } |
|
|
530 | with_name = temp ==0x04; |
330 | len ++; |
531 | len ++; |
331 | |
532 | |
332 | psiconv_progress(lev+2,off+len, |
533 | psiconv_progress(config,lev+2,off+len, |
333 | "Going to read the offset of the 1st ??? Section"); |
534 | "Going to read the offset of the sheet info Section"); |
334 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
535 | info_off = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
335 | if (res) |
536 | if (res) |
336 | goto ERROR2; |
537 | goto ERROR2; |
337 | psiconv_debug(lev+2,off+len,"Offset: %04x",temp); |
538 | psiconv_debug(config,lev+2,off+len,"Offset: %04x",info_off); |
338 | len += 4; |
539 | len += 4; |
339 | |
540 | |
340 | psiconv_progress(lev+2,off+len, |
541 | psiconv_progress(config,lev+2,off+len, |
341 | "Going to read the offset of the Formulas List"); |
542 | "Going to read the offset of the Formulas List"); |
342 | formulas_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
543 | formulas_off = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
343 | if (res) |
544 | if (res) |
344 | goto ERROR2; |
545 | goto ERROR2; |
345 | psiconv_debug(lev+2,off+len,"Offset: %04x",formulas_off); |
546 | psiconv_debug(config,lev+2,off+len,"Offset: %04x",formulas_off); |
346 | len += 4; |
547 | len += 4; |
347 | |
548 | |
348 | psiconv_progress(lev+2,off+len, |
549 | psiconv_progress(config,lev+2,off+len, |
349 | "Going to read the offset of the Worksheet List"); |
550 | "Going to read the offset of the Worksheet List"); |
350 | worksheets_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
551 | worksheets_off = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
351 | if (res) |
552 | if (res) |
352 | goto ERROR2; |
553 | goto ERROR2; |
353 | psiconv_debug(lev+2,off+len,"Offset: %04x",worksheets_off); |
554 | psiconv_debug(config,lev+2,off+len,"Offset: %04x",worksheets_off); |
354 | len += 4; |
555 | len += 4; |
355 | |
556 | |
356 | psiconv_progress(lev+2,off+len, |
557 | psiconv_progress(config,lev+2,off+len, |
|
|
558 | "Going to read the offset of the Variable List"); |
|
|
559 | var_off = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
|
|
560 | if (res) |
|
|
561 | goto ERROR2; |
|
|
562 | psiconv_debug(config,lev+2,off+len,"Offset: %04x",var_off); |
|
|
563 | len += 4; |
|
|
564 | |
|
|
565 | if (with_name) { |
|
|
566 | psiconv_progress(config,lev+2,off+len, |
357 | "Going to read the offset of the 4th ??? Section"); |
567 | "Going to read the offset of the Name Section"); |
358 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
568 | name_off = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
359 | if (res) |
569 | if (res) |
360 | goto ERROR2; |
570 | goto ERROR2; |
361 | psiconv_debug(lev+2,off+len,"Offset: %04x",temp); |
571 | psiconv_debug(config,lev+2,off+len,"Offset: %04x",name_off); |
362 | len += 4; |
572 | len += 4; |
|
|
573 | } |
363 | |
574 | |
|
|
575 | |
|
|
576 | psiconv_progress(config,lev+2,off+len,"Going to read the info section"); |
|
|
577 | if ((res = psiconv_parse_sheet_info_section(config,buf,lev+2,info_off,NULL, |
|
|
578 | &(*result)->info))) |
|
|
579 | goto ERROR2; |
|
|
580 | |
|
|
581 | psiconv_progress(config,lev+2,off+len,"Going to read the variables list"); |
|
|
582 | if ((res = psiconv_parse_sheet_variable_list(config,buf,lev+2,var_off,NULL, |
|
|
583 | &(*result)->variables))) |
|
|
584 | goto ERROR3; |
|
|
585 | |
364 | psiconv_progress(lev+2,off+len,"Going to read the formulas list"); |
586 | psiconv_progress(config,lev+2,off+len,"Going to read the formulas list"); |
365 | if ((res = psiconv_parse_sheet_formula_table(buf,lev+2,formulas_off,NULL, |
587 | if ((res = psiconv_parse_sheet_formula_list(config,buf,lev+2,formulas_off,NULL, |
366 | &(*result)->formulas))) |
588 | &(*result)->formulas))) |
367 | goto ERROR2; |
589 | goto ERROR4; |
368 | |
590 | |
369 | psiconv_progress(lev+2,off+len,"Going to read the worksheet list"); |
591 | psiconv_progress(config,lev+2,off+len,"Going to read the worksheet list"); |
370 | if ((res = psiconv_parse_sheet_worksheet_list(buf,lev+2,worksheets_off, |
592 | if ((res = psiconv_parse_sheet_worksheet_list(config,buf,lev+2,worksheets_off, |
371 | NULL,&(*result)->worksheets))) |
593 | NULL,&(*result)->worksheets))) |
372 | goto ERROR2; |
594 | goto ERROR5; |
373 | |
595 | |
|
|
596 | if (with_name) { |
|
|
597 | psiconv_progress(config,lev+2,off+len,"Going to read the name section"); |
|
|
598 | if ((res = psiconv_parse_sheet_name_section(config,buf,lev+2,name_off,NULL, |
|
|
599 | &(*result)->name))) |
|
|
600 | goto ERROR6; |
|
|
601 | } else |
|
|
602 | (*result)->name = NULL; |
374 | |
603 | |
375 | if (length) |
604 | if (length) |
376 | *length = len; |
605 | *length = len; |
377 | |
606 | |
378 | psiconv_progress(lev,off+len-1, |
607 | psiconv_progress(config,lev,off+len-1, |
379 | "End of sheet workbook section (total length: %08x)", len); |
608 | "End of sheet workbook section (total length: %08x)", len); |
380 | return 0; |
609 | return 0; |
381 | |
610 | |
|
|
611 | ERROR6: |
|
|
612 | psiconv_free_sheet_worksheet_list((*result)->worksheets); |
|
|
613 | ERROR5: |
|
|
614 | psiconv_free_formula_list((*result)->formulas); |
|
|
615 | ERROR4: |
|
|
616 | psiconv_free_sheet_variable_list((*result)->variables); |
|
|
617 | ERROR3: |
|
|
618 | psiconv_free_sheet_info_section((*result)->info); |
382 | ERROR2: |
619 | ERROR2: |
383 | free (*result); |
620 | free (*result); |
384 | ERROR1: |
621 | ERROR1: |
385 | psiconv_warn(lev+1,off,"Reading of Sheet Workbook Section failed"); |
622 | psiconv_warn(config,lev+1,off,"Reading of Sheet Workbook Section failed"); |
386 | if (length) |
623 | if (length) |
387 | *length = 0; |
624 | *length = 0; |
388 | if (!res) |
625 | if (!res) |
389 | return -PSICONV_E_NOMEM; |
626 | return -PSICONV_E_NOMEM; |
390 | else |
627 | else |
391 | return res; |
628 | return res; |
392 | } |
629 | } |
393 | |
630 | |
394 | int psiconv_parse_sheet_formula_table(const psiconv_buffer buf, int lev, |
631 | int psiconv_parse_sheet_name_section(const psiconv_config config, |
|
|
632 | const psiconv_buffer buf, int lev, |
395 | psiconv_u32 off, int *length, |
633 | psiconv_u32 off, int *length, |
|
|
634 | psiconv_sheet_name_section *result) |
|
|
635 | { |
|
|
636 | int res=0; |
|
|
637 | psiconv_u32 temp; |
|
|
638 | int len=0,leng; |
|
|
639 | |
|
|
640 | psiconv_progress(config,lev+1,off,"Going to read the sheet name section"); |
|
|
641 | if (!(*result = malloc(sizeof(**result)))) |
|
|
642 | goto ERROR1; |
|
|
643 | |
|
|
644 | psiconv_progress(config,lev+2,off+len, |
|
|
645 | "Going to read the initial byte (%02x expected)",0x02); |
|
|
646 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
|
|
647 | if (res) |
|
|
648 | goto ERROR2; |
|
|
649 | if (temp != 0x02) { |
|
|
650 | psiconv_warn(config,lev+2,off+len, |
|
|
651 | "Sheet name section initial byte unknown value (ignored)"); |
|
|
652 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
|
|
653 | } |
|
|
654 | len ++; |
|
|
655 | |
|
|
656 | psiconv_progress(config,lev+2,off+len, "Going to read the sheet name"); |
|
|
657 | (*result)->name = psiconv_read_string(config,buf,lev+2,off+len,&leng,&res); |
|
|
658 | if (res) |
|
|
659 | goto ERROR2; |
|
|
660 | len += leng; |
|
|
661 | |
|
|
662 | if (length) |
|
|
663 | *length = len; |
|
|
664 | |
|
|
665 | psiconv_progress(config,lev,off+len-1, |
|
|
666 | "End of sheet name section (total length: %08x)", len); |
|
|
667 | return 0; |
|
|
668 | |
|
|
669 | ERROR2: |
|
|
670 | free(*result); |
|
|
671 | ERROR1: |
|
|
672 | psiconv_warn(config,lev+1,off,"Reading of Sheet Name Section failed"); |
|
|
673 | if (length) |
|
|
674 | *length = 0; |
|
|
675 | if (!res) |
|
|
676 | return -PSICONV_E_NOMEM; |
|
|
677 | else |
|
|
678 | return res; |
|
|
679 | } |
|
|
680 | |
|
|
681 | int psiconv_parse_sheet_info_section(const psiconv_config config, |
|
|
682 | const psiconv_buffer buf, int lev, |
|
|
683 | psiconv_u32 off, int *length, |
|
|
684 | psiconv_sheet_info_section *result) |
|
|
685 | { |
|
|
686 | int res=0; |
|
|
687 | psiconv_u32 temp; |
|
|
688 | int len=0,leng; |
|
|
689 | |
|
|
690 | psiconv_progress(config,lev+1,off,"Going to read the sheet info section"); |
|
|
691 | if (!(*result = malloc(sizeof(**result)))) |
|
|
692 | goto ERROR1; |
|
|
693 | |
|
|
694 | psiconv_progress(config,lev+2,off+len, |
|
|
695 | "Going to read the initial byte (%02x expected)",0x02); |
|
|
696 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
|
|
697 | if (res) |
|
|
698 | goto ERROR2; |
|
|
699 | if (temp != 0x02) { |
|
|
700 | psiconv_warn(config,lev+2,off+len, |
|
|
701 | "Sheet info section initial byte unknown value (ignored)"); |
|
|
702 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
|
|
703 | } |
|
|
704 | len ++; |
|
|
705 | |
|
|
706 | psiconv_progress(config,lev+2,off+len, "Going to read an unknown Xint"); |
|
|
707 | temp = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res); |
|
|
708 | if (res) |
|
|
709 | goto ERROR2; |
|
|
710 | psiconv_debug(config,lev+2,off+len,"Value: %d\n",temp); |
|
|
711 | len += leng; |
|
|
712 | |
|
|
713 | psiconv_progress(config,lev+2,off+len, "Going to read the flags byte"); |
|
|
714 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
|
|
715 | if (res) |
|
|
716 | goto ERROR2; |
|
|
717 | (*result)->auto_recalc = temp & 0x01 ? psiconv_bool_true:psiconv_bool_false; |
|
|
718 | psiconv_debug(config,lev+2,off+len,"Auto recalculation: %02x", |
|
|
719 | (*result)->auto_recalc); |
|
|
720 | if ((temp & 0xfe) != 0x02) { |
|
|
721 | psiconv_warn(config,lev+2,off+len,"Sheet Info Section flags byte " |
|
|
722 | "contains unknown flags (ignored)"); |
|
|
723 | psiconv_debug(config,lev+2,off+len,"Unknown flags: %02x",temp &0xfe); |
|
|
724 | } |
|
|
725 | |
|
|
726 | len ++; |
|
|
727 | |
|
|
728 | |
|
|
729 | if (length) |
|
|
730 | *length = len; |
|
|
731 | |
|
|
732 | psiconv_progress(config,lev,off+len-1, |
|
|
733 | "End of sheet info section (total length: %08x)", len); |
|
|
734 | return 0; |
|
|
735 | |
|
|
736 | ERROR2: |
|
|
737 | free(*result); |
|
|
738 | ERROR1: |
|
|
739 | psiconv_warn(config,lev+1,off,"Reading of Sheet Name Section failed"); |
|
|
740 | if (length) |
|
|
741 | *length = 0; |
|
|
742 | if (!res) |
|
|
743 | return -PSICONV_E_NOMEM; |
|
|
744 | else |
|
|
745 | return res; |
|
|
746 | } |
|
|
747 | |
|
|
748 | int psiconv_parse_sheet_formula_list(const psiconv_config config, |
|
|
749 | const psiconv_buffer buf, int lev, |
|
|
750 | psiconv_u32 off, int *length, |
396 | psiconv_formula_list *result) |
751 | psiconv_formula_list *result) |
397 | { |
752 | { |
398 | int res=0; |
753 | int res=0; |
399 | int len=0; |
754 | int len=0; |
400 | psiconv_u32 temp; |
755 | psiconv_u32 temp; |
401 | psiconv_formula formula; |
756 | psiconv_formula formula; |
402 | psiconv_u32 listlen,i; |
757 | psiconv_u32 listlen,i; |
403 | int leng; |
758 | int leng; |
404 | |
759 | |
405 | psiconv_progress(lev+1,off,"Going to read the sheet formula table"); |
760 | psiconv_progress(config,lev+1,off,"Going to read the sheet formula list"); |
406 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_formula_s)))) |
761 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_formula_s)))) |
407 | goto ERROR1; |
762 | goto ERROR1; |
408 | |
763 | |
409 | psiconv_progress(lev+2,off+len, |
764 | psiconv_progress(config,lev+2,off+len, |
410 | "Going to read the initial byte (%02x expected)",0x02); |
765 | "Going to read the initial byte (%02x expected)",0x02); |
411 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
766 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
412 | if (res) |
767 | if (res) |
413 | goto ERROR2; |
768 | goto ERROR2; |
414 | if (temp != 0x02) { |
769 | if (temp != 0x02) { |
415 | psiconv_warn(lev+2,off+len, |
770 | psiconv_warn(config,lev+2,off+len, |
416 | "Sheet formula table initial byte unknown value (ignored)"); |
771 | "Sheet formula list initial byte unknown value (ignored)"); |
417 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
772 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
418 | } |
773 | } |
419 | len ++; |
774 | len ++; |
420 | |
775 | |
421 | psiconv_progress(lev+2,off+len, |
776 | psiconv_progress(config,lev+2,off+len, |
422 | "Going to read the number of formulas"); |
777 | "Going to read the number of formulas"); |
423 | listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
778 | listlen = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res); |
424 | if (res) |
779 | if (res) |
425 | goto ERROR2; |
780 | goto ERROR2; |
426 | psiconv_debug(lev+2,off+len,"Number of formulas: %d",listlen); |
781 | psiconv_debug(config,lev+2,off+len,"Number of formulas: %d",listlen); |
427 | len += leng; |
782 | len += leng; |
428 | |
783 | |
429 | psiconv_progress(lev+2,off+len,"Going to read all formulas"); |
784 | psiconv_progress(config,lev+2,off+len,"Going to read all formulas"); |
430 | for (i = 0; i < listlen; i++) { |
785 | for (i = 0; i < listlen; i++) { |
431 | psiconv_progress(lev+3,off+len,"Going to read formula %d",i); |
786 | psiconv_progress(config,lev+3,off+len,"Going to read formula %d",i); |
432 | if ((res = psiconv_parse_formula(buf,lev+3,off+len,&leng,&formula))) |
787 | if ((res = psiconv_parse_formula(config,buf,lev+3,off+len,&leng,&formula))) |
433 | goto ERROR2; |
788 | goto ERROR2; |
434 | if ((res = psiconv_list_add(*result,formula))) |
789 | if ((res = psiconv_list_add(*result,formula))) |
435 | goto ERROR3; |
790 | goto ERROR3; |
|
|
791 | free(formula); |
436 | len += leng; |
792 | len += leng; |
437 | } |
793 | } |
438 | |
794 | |
439 | if (length) |
795 | if (length) |
440 | *length = len; |
796 | *length = len; |
441 | |
797 | |
442 | psiconv_progress(lev,off+len-1, |
798 | psiconv_progress(config,lev,off+len-1, |
443 | "End of sheet formula table (total length: %08x)", len); |
799 | "End of sheet formula list (total length: %08x)", len); |
444 | return 0; |
800 | return 0; |
445 | |
801 | |
446 | ERROR3: |
802 | ERROR3: |
447 | psiconv_free_formula(formula); |
803 | psiconv_free_formula(formula); |
448 | ERROR2: |
804 | ERROR2: |
449 | psiconv_list_free(*result); |
805 | psiconv_list_free(*result); |
450 | ERROR1: |
806 | ERROR1: |
451 | psiconv_warn(lev+1,off,"Reading of Sheet Formula Table failed"); |
807 | psiconv_warn(config,lev+1,off,"Reading of Sheet Formula list failed"); |
452 | if (length) |
808 | if (length) |
453 | *length = 0; |
809 | *length = 0; |
454 | if (!res) |
810 | if (!res) |
455 | return -PSICONV_E_NOMEM; |
811 | return -PSICONV_E_NOMEM; |
456 | else |
812 | else |
457 | return res; |
813 | return res; |
458 | } |
814 | } |
459 | |
815 | |
460 | int psiconv_parse_sheet_cell(const psiconv_buffer buf, int lev, |
816 | int psiconv_parse_sheet_cell(const psiconv_config config, |
|
|
817 | const psiconv_buffer buf, int lev, |
461 | psiconv_u32 off, int *length, |
818 | psiconv_u32 off, int *length, |
462 | psiconv_sheet_cell *result) |
819 | psiconv_sheet_cell *result, |
|
|
820 | const psiconv_sheet_cell_layout default_layout, |
|
|
821 | const psiconv_sheet_line_list row_default_layouts, |
|
|
822 | const psiconv_sheet_line_list col_default_layouts) |
463 | { |
823 | { |
464 | int res=0; |
824 | int res=0; |
465 | int len=0; |
825 | int len=0; |
466 | psiconv_u32 temp; |
826 | psiconv_u32 temp; |
467 | psiconv_bool_t has_layout; |
827 | psiconv_bool_t has_layout; |
468 | int leng; |
828 | int leng; |
469 | |
829 | |
470 | psiconv_progress(lev+1,off,"Going to read a sheet cell structure"); |
830 | psiconv_progress(config,lev+1,off,"Going to read a sheet cell structure"); |
471 | if (!(*result = malloc(sizeof(**result)))) |
831 | if (!(*result = malloc(sizeof(**result)))) |
472 | goto ERROR1; |
832 | goto ERROR1; |
473 | |
833 | |
474 | (*result)->layout = NULL; |
834 | (*result)->layout = NULL; |
475 | (*result)->type = psiconv_cell_blank; |
835 | (*result)->type = psiconv_cell_blank; |
476 | |
836 | |
477 | psiconv_progress(lev+2,off+len,"Going to read the cell position"); |
837 | psiconv_progress(config,lev+2,off+len,"Going to read the cell position"); |
478 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
838 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
479 | if (res) |
839 | if (res) |
480 | goto ERROR2; |
840 | goto ERROR2; |
481 | len ++; |
841 | len ++; |
482 | temp += psiconv_read_u8(buf,lev+2,off+len,&res) << 8; |
842 | temp += psiconv_read_u8(config,buf,lev+2,off+len,&res) << 8; |
483 | if (res) |
843 | if (res) |
484 | goto ERROR2; |
844 | goto ERROR2; |
485 | len ++; |
845 | len ++; |
486 | temp += psiconv_read_u8(buf,lev+2,off+len,&res) << 16; |
846 | temp += psiconv_read_u8(config,buf,lev+2,off+len,&res) << 16; |
487 | if (res) |
847 | if (res) |
488 | goto ERROR2; |
848 | goto ERROR2; |
489 | len ++; |
849 | len ++; |
490 | (*result)->column = (temp >> 2) & 0xFF; |
850 | (*result)->column = (temp >> 2) & 0xFF; |
491 | (*result)->row = (temp >> 10) & 0x3FFF; |
851 | (*result)->row = (temp >> 10) & 0x3FFF; |
492 | psiconv_debug(lev+2,off+len,"Cell position is col:%02x row:%04x", |
852 | psiconv_debug(config,lev+2,off+len,"Cell position is col:%02x row:%04x", |
493 | (*result)->column,(*result)->row); |
853 | (*result)->column,(*result)->row); |
494 | if (temp & 0x03) { |
854 | if (temp & 0x03) { |
495 | psiconv_warn(lev+2,off+len,"Unknown flags in cell position (ignored)"); |
855 | psiconv_warn(config,lev+2,off+len,"Unknown flags in cell position (ignored)"); |
496 | psiconv_debug(lev+2,off+len,"Flags: %02x",temp & 0x03); |
856 | psiconv_debug(config,lev+2,off+len,"Flags: %02x",temp & 0x03); |
497 | } |
857 | } |
498 | |
858 | |
499 | psiconv_progress(lev+2,off+len,"Going to read the cell type"); |
859 | psiconv_progress(config,lev+2,off+len,"Going to read the cell type"); |
500 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
860 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
501 | if (res) |
861 | if (res) |
502 | goto ERROR2; |
862 | goto ERROR2; |
503 | len ++; |
863 | len ++; |
504 | (*result)->type = (temp >> 5) & 0x07; |
864 | (*result)->type = (temp >> 5) & 0x07; |
505 | (*result)->calculated = (temp & 0x08)?psiconv_bool_true:psiconv_bool_false; |
865 | (*result)->calculated = (temp & 0x08)?psiconv_bool_true:psiconv_bool_false; |
506 | has_layout = (temp & 0x10)?psiconv_bool_true:psiconv_bool_false; |
866 | has_layout = (temp & 0x10)?psiconv_bool_true:psiconv_bool_false; |
507 | |
867 | |
508 | psiconv_progress(lev+2,off+len,"Going to read the cell value"); |
868 | psiconv_progress(config,lev+2,off+len,"Going to read the cell value"); |
509 | if ((*result)->type == psiconv_cell_blank) { |
869 | if ((*result)->type == psiconv_cell_blank) { |
510 | psiconv_debug(lev+2,off+len,"Cell type is blank: no value given."); |
870 | psiconv_debug(config,lev+2,off+len,"Cell type is blank: no value given."); |
511 | } else if ((*result)->type == psiconv_cell_int) { |
871 | } else if ((*result)->type == psiconv_cell_int) { |
512 | psiconv_progress(lev+2,off+len,"Going to read an integer"); |
872 | psiconv_progress(config,lev+2,off+len,"Going to read an integer"); |
513 | (*result)->data.dat_int = psiconv_read_u32(buf,lev+2,off+len,&res); |
873 | (*result)->data.dat_int = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
514 | if (res) |
874 | if (res) |
515 | goto ERROR2; |
875 | goto ERROR2; |
516 | len += 4; |
876 | len += 4; |
517 | psiconv_debug(lev+2,off+len,"Cell contents: %ld",(*result)->data.dat_int); |
877 | psiconv_debug(config,lev+2,off+len,"Cell contents: %ld",(*result)->data.dat_int); |
518 | |
878 | |
519 | } else if ((*result)->type == psiconv_cell_bool) { |
879 | } else if ((*result)->type == psiconv_cell_bool) { |
520 | psiconv_progress(lev+2,off+len,"Going to read a boolean"); |
880 | psiconv_progress(config,lev+2,off+len,"Going to read a boolean"); |
521 | if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng, |
881 | if ((res = psiconv_parse_bool(config,buf,lev+2,off+len,&leng, |
522 | &(*result)->data.dat_bool))) |
882 | &(*result)->data.dat_bool))) |
523 | goto ERROR2; |
883 | goto ERROR2; |
524 | psiconv_debug(lev+2,off+len,"Cell contents: %01x",temp); |
884 | psiconv_debug(config,lev+2,off+len,"Cell contents: %01x",temp); |
525 | (*result)->data.dat_bool = temp?psiconv_bool_true:psiconv_bool_false; |
885 | (*result)->data.dat_bool = temp?psiconv_bool_true:psiconv_bool_false; |
526 | len += leng; |
886 | len += leng; |
527 | } else if ((*result)->type == psiconv_cell_error) { |
887 | } else if ((*result)->type == psiconv_cell_error) { |
528 | psiconv_progress(lev+2,off+len,"Going to read the error code"); |
888 | psiconv_progress(config,lev+2,off+len,"Going to read the error code"); |
529 | temp = psiconv_read_u16(buf,lev+2,off+len,&res); |
889 | temp = psiconv_read_u16(config,buf,lev+2,off+len,&res); |
530 | if (res) |
890 | if (res) |
531 | goto ERROR2; |
891 | goto ERROR2; |
532 | if (temp == 0) |
892 | if (temp == 0) |
533 | (*result)->data.dat_error = psiconv_sheet_error_none; |
893 | (*result)->data.dat_error = psiconv_sheet_error_none; |
534 | else if (temp == 1) |
894 | else if (temp == 1) |
… | |
… | |
544 | else if (temp == 6) |
904 | else if (temp == 6) |
545 | (*result)->data.dat_error = psiconv_sheet_error_number; |
905 | (*result)->data.dat_error = psiconv_sheet_error_number; |
546 | else if (temp == 7) |
906 | else if (temp == 7) |
547 | (*result)->data.dat_error = psiconv_sheet_error_notavail; |
907 | (*result)->data.dat_error = psiconv_sheet_error_notavail; |
548 | else { |
908 | else { |
549 | psiconv_warn(lev+2,off+len,"Unknown error code (default assumed)"); |
909 | psiconv_warn(config,lev+2,off+len,"Unknown error code (default assumed)"); |
550 | psiconv_debug(lev+2,off+len,"Error code: %04x",temp); |
910 | psiconv_debug(config,lev+2,off+len,"Error code: %04x",temp); |
551 | (*result)->data.dat_error = psiconv_sheet_error_none; |
911 | (*result)->data.dat_error = psiconv_sheet_error_none; |
552 | } |
912 | } |
553 | psiconv_debug(lev+2,off+len,"Cell contents: %04x", |
913 | psiconv_debug(config,lev+2,off+len,"Cell contents: %04x", |
554 | (*result)->data.dat_error); |
914 | (*result)->data.dat_error); |
555 | len += 2; |
915 | len += 2; |
556 | } else if ((*result)->type == psiconv_cell_float) { |
916 | } else if ((*result)->type == psiconv_cell_float) { |
557 | psiconv_progress(lev+2,off+len,"Going to read a float"); |
917 | psiconv_progress(config,lev+2,off+len,"Going to read a float"); |
558 | (*result)->data.dat_float = |
918 | (*result)->data.dat_float = |
559 | psiconv_read_float(buf,lev+2,off+len,&leng,&res); |
919 | psiconv_read_float(config,buf,lev+2,off+len,&leng,&res); |
560 | if (res) |
920 | if (res) |
561 | goto ERROR2; |
921 | goto ERROR2; |
562 | psiconv_debug(lev+2,off+len,"Cell contents: %f",(*result)->data.dat_float); |
922 | psiconv_debug(config,lev+2,off+len,"Cell contents: %f",(*result)->data.dat_float); |
563 | len += leng; |
923 | len += leng; |
564 | } else if ((*result)->type == psiconv_cell_string) { |
924 | } else if ((*result)->type == psiconv_cell_string) { |
565 | psiconv_progress(lev+2,off+len,"Going to read a string"); |
925 | psiconv_progress(config,lev+2,off+len,"Going to read a string"); |
566 | (*result)->data.dat_string = |
926 | (*result)->data.dat_string = |
567 | psiconv_read_string(buf,lev+2,off+len,&leng,&res); |
927 | psiconv_read_string(config,buf,lev+2,off+len,&leng,&res); |
568 | if (res) |
928 | if (res) |
569 | goto ERROR2; |
929 | goto ERROR2; |
570 | psiconv_debug(lev+2,off+len,"Cell contents: `%s'", |
930 | psiconv_debug(config,lev+2,off+len,"Cell contents: `%s'", |
571 | (*result)->data.dat_string); |
931 | (*result)->data.dat_string); |
572 | len += leng; |
932 | len += leng; |
573 | } else { |
933 | } else { |
574 | psiconv_warn(lev+2,off+len,"Unknown Sheet Cell type: %02x",(*result)->type); |
934 | psiconv_warn(config,lev+2,off+len,"Unknown Sheet Cell type: %02x",(*result)->type); |
575 | res = PSICONV_E_PARSE; |
935 | res = PSICONV_E_PARSE; |
576 | goto ERROR2; |
936 | goto ERROR2; |
577 | } |
937 | } |
578 | |
938 | |
|
|
939 | if (!((*result)->layout = psiconv_clone_cell_layout( |
|
|
940 | psiconv_get_default_layout(row_default_layouts, |
|
|
941 | col_default_layouts, |
|
|
942 | default_layout, |
|
|
943 | (*result)->row, |
|
|
944 | (*result)->column)))) |
|
|
945 | goto ERROR2; |
579 | if (has_layout) { |
946 | if (has_layout) { |
580 | if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len, |
947 | if ((res = psiconv_parse_sheet_cell_layout(config,buf,lev+2,off+len, |
581 | &leng,&(*result)->layout))) |
948 | &leng,(*result)->layout))) |
582 | goto ERROR2; |
949 | goto ERROR2; |
583 | len += leng; |
950 | len += leng; |
584 | } |
951 | } |
585 | |
952 | |
586 | if ((*result)->calculated) { |
953 | if ((*result)->calculated) { |
587 | psiconv_progress(lev+2,off+len,"Going to read the cell formula reference"); |
954 | psiconv_progress(config,lev+2,off+len,"Going to read the cell formula reference"); |
588 | temp = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
955 | temp = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res); |
589 | if (res) |
956 | if (res) |
590 | goto ERROR2; |
957 | goto ERROR2; |
591 | psiconv_debug(lev+2,off+len,"Cell formula reference: %d",temp); |
958 | psiconv_debug(config,lev+2,off+len,"Cell formula reference: %d",temp); |
592 | len += leng; |
959 | len += leng; |
593 | (*result)->ref_formula = temp; |
960 | (*result)->ref_formula = temp; |
594 | } |
961 | } |
595 | |
962 | |
596 | if (length) |
963 | if (length) |
597 | *length = len; |
964 | *length = len; |
598 | |
965 | |
599 | psiconv_progress(lev,off+len-1, |
966 | psiconv_progress(config,lev,off+len-1, |
600 | "End of sheet cell structure (total length: %08x)", len); |
967 | "End of sheet cell structure (total length: %08x)", len); |
601 | return 0; |
968 | return 0; |
602 | |
969 | |
603 | ERROR2: |
970 | ERROR2: |
604 | psiconv_free_sheet_cell(*result); |
971 | psiconv_free_sheet_cell(*result); |
605 | ERROR1: |
972 | ERROR1: |
606 | psiconv_warn(lev+1,off,"Reading of Sheet Cell Structure failed"); |
973 | psiconv_warn(config,lev+1,off,"Reading of Sheet Cell Structure failed"); |
607 | if (length) |
974 | if (length) |
608 | *length = 0; |
975 | *length = 0; |
609 | if (!res) |
976 | if (!res) |
610 | return -PSICONV_E_NOMEM; |
977 | return -PSICONV_E_NOMEM; |
611 | else |
978 | else |
612 | return res; |
979 | return res; |
613 | } |
980 | } |
614 | |
981 | |
615 | int psiconv_parse_sheet_cell_list(const psiconv_buffer buf, int lev, |
982 | int psiconv_parse_sheet_cell_list(const psiconv_config config, |
|
|
983 | const psiconv_buffer buf, int lev, |
616 | psiconv_u32 off, int *length, |
984 | psiconv_u32 off, int *length, |
617 | psiconv_sheet_cell_list *result) |
985 | psiconv_sheet_cell_list *result, |
|
|
986 | const psiconv_sheet_cell_layout default_layout, |
|
|
987 | const psiconv_sheet_line_list row_default_layouts, |
|
|
988 | const psiconv_sheet_line_list col_default_layouts) |
618 | { |
989 | { |
619 | int res=0; |
990 | int res=0; |
620 | int len=0; |
991 | int len=0; |
621 | psiconv_u32 temp; |
992 | psiconv_u32 temp; |
622 | psiconv_sheet_cell cell; |
993 | psiconv_sheet_cell cell; |
623 | psiconv_u32 listlen,i; |
994 | psiconv_u32 listlen,i; |
624 | int leng; |
995 | int leng; |
625 | |
996 | |
626 | psiconv_progress(lev+1,off,"Going to read the sheet cell list"); |
997 | psiconv_progress(config,lev+1,off,"Going to read the sheet cell list"); |
627 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_cell_s)))) |
998 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_cell_s)))) |
628 | goto ERROR1; |
999 | goto ERROR1; |
629 | |
1000 | |
630 | psiconv_progress(lev+2,off+len, |
1001 | psiconv_progress(config,lev+2,off+len, |
631 | "Going to read the initial byte (%02x expected)",0x02); |
1002 | "Going to read the initial byte (%02x expected)",0x02); |
632 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1003 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
633 | if (res) |
1004 | if (res) |
634 | goto ERROR2; |
1005 | goto ERROR2; |
635 | if (temp != 0x02) { |
1006 | if (temp != 0x02) { |
636 | psiconv_warn(lev+2,off+len, |
1007 | psiconv_warn(config,lev+2,off+len, |
637 | "Sheet cell list initial byte unknown value (ignored)"); |
1008 | "Sheet cell list initial byte unknown value (ignored)"); |
638 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
1009 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
639 | } |
1010 | } |
640 | len ++; |
1011 | len ++; |
641 | |
1012 | |
642 | psiconv_progress(lev+2,off+len, |
1013 | psiconv_progress(config,lev+2,off+len, |
643 | "Going to read the initial byte (%02x expected)",0x00); |
1014 | "Going to read the initial byte (%02x expected)",0x00); |
644 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1015 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
645 | if (res) |
1016 | if (res) |
646 | goto ERROR2; |
1017 | goto ERROR2; |
647 | if (temp != 0x00) { |
1018 | if (temp != 0x00) { |
648 | psiconv_warn(lev+2,off+len, |
1019 | psiconv_warn(config,lev+2,off+len, |
649 | "Sheet cell list initial byte unknown value (ignored)"); |
1020 | "Sheet cell list initial byte unknown value (ignored)"); |
650 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
1021 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
651 | } |
1022 | } |
652 | len ++; |
1023 | len ++; |
653 | |
1024 | |
654 | psiconv_progress(lev+2,off+len, |
1025 | psiconv_progress(config,lev+2,off+len, |
655 | "Going to read the number of defined cells"); |
1026 | "Going to read the number of defined cells"); |
656 | listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
1027 | listlen = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res); |
657 | if (res) |
1028 | if (res) |
658 | goto ERROR2; |
1029 | goto ERROR2; |
659 | psiconv_debug(lev+2,off+len,"Number of defined cells: %d",listlen); |
1030 | psiconv_debug(config,lev+2,off+len,"Number of defined cells: %d",listlen); |
660 | len += leng; |
1031 | len += leng; |
661 | |
1032 | |
662 | psiconv_progress(lev+2,off+len,"Going to read all cells"); |
1033 | psiconv_progress(config,lev+2,off+len,"Going to read all cells"); |
663 | for (i = 0; i < listlen; i++) { |
1034 | for (i = 0; i < listlen; i++) { |
664 | psiconv_progress(lev+3,off+len,"Going to read cell %d",i); |
1035 | psiconv_progress(config,lev+3,off+len,"Going to read cell %d",i); |
665 | if ((res = psiconv_parse_sheet_cell(buf,lev+3,off+len,&leng,&cell))) |
1036 | if ((res = psiconv_parse_sheet_cell(config,buf,lev+3,off+len,&leng,&cell, |
|
|
1037 | default_layout,row_default_layouts, |
|
|
1038 | col_default_layouts))) |
666 | goto ERROR2; |
1039 | goto ERROR2; |
667 | if ((res = psiconv_list_add(*result,cell))) |
1040 | if ((res = psiconv_list_add(*result,cell))) |
668 | goto ERROR3; |
1041 | goto ERROR3; |
|
|
1042 | free(cell); |
669 | len += leng; |
1043 | len += leng; |
670 | } |
1044 | } |
671 | |
1045 | |
672 | if (length) |
1046 | if (length) |
673 | *length = len; |
1047 | *length = len; |
674 | |
1048 | |
675 | psiconv_progress(lev,off+len-1, |
1049 | psiconv_progress(config,lev,off+len-1, |
676 | "End of sheet cell list (total length: %08x)", len); |
1050 | "End of sheet cell list (total length: %08x)", len); |
677 | return 0; |
1051 | return 0; |
678 | |
1052 | |
679 | ERROR3: |
1053 | ERROR3: |
680 | psiconv_free_sheet_cell(cell); |
1054 | psiconv_free_sheet_cell(cell); |
681 | ERROR2: |
1055 | ERROR2: |
682 | psiconv_free_sheet_cell_list(*result); |
1056 | psiconv_free_sheet_cell_list(*result); |
683 | ERROR1: |
1057 | ERROR1: |
684 | psiconv_warn(lev+1,off,"Reading of Sheet Cells List failed"); |
1058 | psiconv_warn(config,lev+1,off,"Reading of Sheet Cells List failed"); |
685 | if (length) |
1059 | if (length) |
686 | *length = 0; |
1060 | *length = 0; |
687 | if (!res) |
1061 | if (!res) |
688 | return -PSICONV_E_NOMEM; |
1062 | return -PSICONV_E_NOMEM; |
689 | else |
1063 | else |
690 | return res; |
1064 | return res; |
691 | } |
1065 | } |
692 | |
1066 | |
693 | |
1067 | |
694 | int psiconv_parse_sheet_worksheet_list( const psiconv_buffer buf, int lev, |
1068 | int psiconv_parse_sheet_worksheet_list(const psiconv_config config, |
|
|
1069 | const psiconv_buffer buf, int lev, |
695 | psiconv_u32 off, int *length, |
1070 | psiconv_u32 off, int *length, |
696 | psiconv_sheet_worksheet_list *result) |
1071 | psiconv_sheet_worksheet_list *result) |
697 | { |
1072 | { |
698 | psiconv_sheet_worksheet worksheet; |
1073 | psiconv_sheet_worksheet worksheet; |
699 | int res=0; |
1074 | int res=0; |
700 | int len=0; |
1075 | int len=0; |
701 | psiconv_u8 temp; |
1076 | psiconv_u8 temp; |
702 | psiconv_u32 offset; |
1077 | psiconv_u32 offset; |
703 | int leng,i,nr; |
1078 | int leng,i,nr; |
704 | |
1079 | |
705 | psiconv_progress(lev+1,off,"Going to read the worksheet list"); |
1080 | psiconv_progress(config,lev+1,off,"Going to read the worksheet list"); |
706 | if (!(*result = psiconv_list_new(sizeof(*worksheet)))) |
1081 | if (!(*result = psiconv_list_new(sizeof(*worksheet)))) |
707 | goto ERROR1; |
1082 | goto ERROR1; |
708 | |
1083 | |
709 | psiconv_progress(lev+2,off+len, |
1084 | psiconv_progress(config,lev+2,off+len, |
710 | "Going to read the initial bytes (%02x expected)",0x02); |
1085 | "Going to read the initial bytes (%02x expected)",0x02); |
711 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1086 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
712 | if (res) |
1087 | if (res) |
713 | goto ERROR2; |
1088 | goto ERROR2; |
714 | if (temp != 0x02) { |
1089 | if (temp != 0x02) { |
715 | psiconv_warn(lev+2,off+len, |
1090 | psiconv_warn(config,lev+2,off+len, |
716 | "Sheet worksheet list initial byte unknown value (ignored)"); |
1091 | "Sheet worksheet list initial byte unknown value (ignored)"); |
717 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
1092 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
718 | } |
1093 | } |
719 | len ++; |
1094 | len ++; |
720 | |
1095 | |
721 | psiconv_progress(lev+2,off+len,"Going to read the list length"); |
1096 | psiconv_progress(config,lev+2,off+len,"Going to read the list length"); |
722 | nr = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
1097 | nr = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res); |
723 | if (res) |
1098 | if (res) |
724 | goto ERROR2; |
1099 | goto ERROR2; |
725 | psiconv_debug(lev+2,off+len,"Length: %02x",nr); |
1100 | psiconv_debug(config,lev+2,off+len,"Length: %02x",nr); |
726 | len += leng; |
1101 | len += leng; |
727 | |
1102 | |
728 | psiconv_progress(lev+2,off+len,"Going to read the list"); |
1103 | psiconv_progress(config,lev+2,off+len,"Going to read the list"); |
729 | for (i=0 ; i < nr; i++) { |
1104 | for (i=0 ; i < nr; i++) { |
730 | psiconv_progress(lev+3,off+len,"Going to read element %d",i); |
1105 | psiconv_progress(config,lev+3,off+len,"Going to read element %d",i); |
731 | psiconv_progress(lev+4,off+len, |
1106 | psiconv_progress(config,lev+4,off+len, |
732 | "Going to read the initial byte (%02x expected)",0x00); |
1107 | "Going to read the initial byte (%02x expected)",0x00); |
733 | temp = psiconv_read_u8(buf,lev+4,off+len,&res); |
1108 | temp = psiconv_read_u8(config,buf,lev+4,off+len,&res); |
734 | if (res) |
1109 | if (res) |
735 | goto ERROR2; |
1110 | goto ERROR2; |
736 | if (temp != 0x00) { |
1111 | if (temp != 0x00) { |
737 | psiconv_warn(lev+4,off+len, |
1112 | psiconv_warn(config,lev+4,off+len, |
738 | "Sheet worksheet element initial byte unknown value (ignored)"); |
1113 | "Sheet worksheet element initial byte unknown value (ignored)"); |
739 | psiconv_debug(lev+4,off+len,"Initial byte: %02x",temp); |
1114 | psiconv_debug(config,lev+4,off+len,"Initial byte: %02x",temp); |
740 | } |
1115 | } |
741 | len ++; |
1116 | len ++; |
742 | |
1117 | |
743 | psiconv_progress(lev+4,off+len,"Going to read the worksheet offset"); |
1118 | psiconv_progress(config,lev+4,off+len,"Going to read the worksheet offset"); |
744 | offset = psiconv_read_u32(buf,lev+2,off+len,&res); |
1119 | offset = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
745 | if (res) |
1120 | if (res) |
746 | goto ERROR2; |
1121 | goto ERROR2; |
747 | psiconv_debug(lev+4,off+len,"Offset: %08x",offset); |
1122 | psiconv_debug(config,lev+4,off+len,"Offset: %08x",offset); |
748 | len += 4; |
1123 | len += 4; |
749 | |
1124 | |
750 | if ((res = psiconv_parse_sheet_worksheet(buf,lev+4,offset,NULL, |
1125 | if ((res = psiconv_parse_sheet_worksheet(config,buf,lev+4,offset,NULL, |
751 | &worksheet))) |
1126 | &worksheet))) |
752 | goto ERROR2; |
1127 | goto ERROR2; |
753 | if ((res = psiconv_list_add(*result,worksheet))) |
1128 | if ((res = psiconv_list_add(*result,worksheet))) |
754 | goto ERROR3; |
1129 | goto ERROR3; |
755 | psiconv_free_sheet_worksheet(worksheet); |
1130 | free(worksheet); |
756 | } |
1131 | } |
757 | |
1132 | |
758 | if (length) |
1133 | if (length) |
759 | *length = len; |
1134 | *length = len; |
760 | |
1135 | |
761 | psiconv_progress(lev,off+len-1, |
1136 | psiconv_progress(config,lev,off+len-1, |
762 | "End of worksheet list (total length: %08x)", len); |
1137 | "End of worksheet list (total length: %08x)", len); |
763 | |
1138 | |
764 | return 0; |
1139 | return 0; |
765 | |
1140 | |
766 | ERROR3: |
1141 | ERROR3: |
767 | psiconv_free_sheet_worksheet(worksheet); |
1142 | psiconv_free_sheet_worksheet(worksheet); |
768 | ERROR2: |
1143 | ERROR2: |
769 | psiconv_free_sheet_worksheet_list(*result); |
1144 | psiconv_free_sheet_worksheet_list(*result); |
770 | ERROR1: |
1145 | ERROR1: |
771 | psiconv_warn(lev+1,off,"Reading of worksheet list failed"); |
1146 | psiconv_warn(config,lev+1,off,"Reading of worksheet list failed"); |
772 | if (length) |
1147 | if (length) |
773 | *length = 0; |
1148 | *length = 0; |
774 | if (!res) |
1149 | if (!res) |
775 | return -PSICONV_E_NOMEM; |
1150 | return -PSICONV_E_NOMEM; |
776 | else |
1151 | else |
777 | return res; |
1152 | return res; |
778 | } |
1153 | } |
779 | |
1154 | |
780 | int psiconv_parse_sheet_cell_layout(const psiconv_buffer buf, int lev, |
1155 | int psiconv_parse_sheet_cell_layout(const psiconv_config config, |
|
|
1156 | const psiconv_buffer buf, int lev, |
781 | psiconv_u32 off, int *length, |
1157 | psiconv_u32 off, int *length, |
782 | psiconv_sheet_cell_layout *result) |
1158 | psiconv_sheet_cell_layout result) |
783 | |
1159 | |
784 | { |
1160 | { |
785 | int res=0; |
1161 | int res=0; |
786 | int len=0; |
1162 | int len=0; |
787 | int leng; |
1163 | int leng; |
788 | psiconv_u8 temp; |
1164 | psiconv_u8 temp; |
789 | |
1165 | |
790 | psiconv_progress(lev+1,off,"Going to read a sheet cell layout"); |
1166 | psiconv_progress(config,lev+1,off,"Going to read a sheet cell layout"); |
791 | if (!(*result = malloc(sizeof(**result)))) |
|
|
792 | goto ERROR1; |
|
|
793 | |
1167 | |
794 | (*result)->character = NULL; |
|
|
795 | (*result)->paragraph = NULL; |
|
|
796 | (*result)->numberformat = NULL; |
|
|
797 | |
|
|
798 | psiconv_progress(lev+2,off+len, |
1168 | psiconv_progress(config,lev+2,off+len, |
799 | "Going to read the first byte (%02x expected)",0x02); |
1169 | "Going to read the first byte (%02x expected)",0x02); |
800 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1170 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
801 | if (res) |
1171 | if (res) |
802 | goto ERROR2; |
1172 | goto ERROR1; |
803 | if (temp != 0x02) { |
1173 | if (temp != 0x02) { |
804 | psiconv_warn(lev+2,off+len, |
1174 | psiconv_warn(config,lev+2,off+len, |
805 | "Worksheet section initial byte unknown value (ignored)"); |
1175 | "Worksheet section initial byte unknown value (ignored)"); |
806 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
1176 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
807 | } |
1177 | } |
808 | len ++; |
1178 | len ++; |
809 | |
1179 | |
810 | psiconv_progress(lev+2,off+len,"Going to read the default formats flag"); |
1180 | psiconv_progress(config,lev+2,off+len,"Going to read the default formats flag"); |
811 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1181 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
812 | if (res) |
1182 | if (res) |
813 | goto ERROR2; |
1183 | goto ERROR1; |
814 | len ++; |
1184 | len ++; |
815 | |
1185 | |
816 | if (temp & 0x01) { |
1186 | 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"); |
1187 | psiconv_progress(config,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, |
1188 | if ((res = psiconv_parse_paragraph_layout_list(config,buf,lev+3,off+len,&leng, |
821 | (*result)->paragraph))) |
1189 | result->paragraph))) |
822 | goto ERROR2; |
1190 | goto ERROR1; |
823 | len += leng; |
1191 | len += leng; |
824 | } |
1192 | } |
825 | |
1193 | |
826 | if (temp & 0x02) { |
1194 | if (temp & 0x02) { |
827 | psiconv_progress(lev+3,off+len,"Going to read the default character codes"); |
1195 | psiconv_progress(config,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, |
1196 | if ((res = psiconv_parse_character_layout_list(config,buf,lev+3,off+len,&leng, |
831 | (*result)->character))) |
1197 | result->character))) |
832 | goto ERROR2; |
1198 | goto ERROR1; |
833 | len += leng; |
1199 | len += leng; |
834 | } |
1200 | } |
835 | |
1201 | |
836 | if (temp & 0x04) { |
1202 | if (temp & 0x04) { |
837 | psiconv_progress(lev+3,off+len, "Going to read the default number format"); |
1203 | psiconv_progress(config,lev+3,off+len, "Going to read the default number format"); |
838 | psiconv_parse_sheet_numberformat(buf,lev+3,off+len,&leng, |
1204 | psiconv_parse_sheet_numberformat(config,buf,lev+3,off+len,&leng, |
839 | &(*result)->numberformat); |
1205 | result->numberformat); |
840 | len += leng; |
1206 | len += leng; |
841 | } |
1207 | } |
842 | |
1208 | |
843 | if (length) |
1209 | if (length) |
844 | *length = len; |
1210 | *length = len; |
845 | |
1211 | |
846 | psiconv_progress(lev,off+len-1, |
1212 | psiconv_progress(config,lev,off+len-1, |
847 | "End of sheet cell layout (total length: %08x)", len); |
1213 | "End of sheet cell layout (total length: %08x)", len); |
848 | |
1214 | |
849 | return 0; |
1215 | return 0; |
850 | |
1216 | |
851 | ERROR2: |
1217 | ERROR1: |
852 | psiconv_free_sheet_cell_layout(*result); |
|
|
853 | ERROR1: |
|
|
854 | psiconv_warn(lev+1,off,"Reading of sheet cell layout failed"); |
1218 | psiconv_warn(config,lev+1,off,"Reading of sheet cell layout failed"); |
855 | if (length) |
1219 | if (length) |
856 | *length = 0; |
1220 | *length = 0; |
857 | if (!res) |
1221 | if (!res) |
858 | return -PSICONV_E_NOMEM; |
1222 | return -PSICONV_E_NOMEM; |
859 | else |
1223 | else |
860 | return res; |
1224 | return res; |
861 | } |
1225 | } |
862 | |
1226 | |
863 | |
1227 | |
864 | int psiconv_parse_sheet_worksheet(const psiconv_buffer buf, int lev, |
1228 | int psiconv_parse_sheet_worksheet(const psiconv_config config, |
|
|
1229 | const psiconv_buffer buf, int lev, |
865 | psiconv_u32 off, int *length, |
1230 | psiconv_u32 off, int *length, |
866 | psiconv_sheet_worksheet *result) |
1231 | psiconv_sheet_worksheet *result) |
867 | { |
1232 | { |
868 | int res=0; |
1233 | int res=0; |
869 | psiconv_u32 temp,cells_off,grid_off; |
1234 | psiconv_u32 temp,cells_off,grid_off,rows_off,cols_off,unknown_off; |
870 | int len=0; |
1235 | int len=0; |
871 | int leng; |
1236 | int leng; |
872 | |
1237 | |
873 | psiconv_progress(lev+1,off,"Going to read the sheet worksheet section"); |
1238 | psiconv_progress(config,lev+1,off,"Going to read the sheet worksheet section"); |
874 | if (!(*result = malloc(sizeof(**result)))) |
1239 | if (!(*result = malloc(sizeof(**result)))) |
875 | goto ERROR1; |
1240 | goto ERROR1; |
876 | |
1241 | |
877 | psiconv_progress(lev+2,off+len, |
1242 | psiconv_progress(config,lev+2,off+len, |
878 | "Going to read the initial bytes (%02x expected)",0x04); |
1243 | "Going to read the initial bytes (%02x expected)",0x04); |
879 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1244 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
880 | if (res) |
1245 | if (res) |
881 | goto ERROR2; |
1246 | goto ERROR2; |
882 | if (temp != 0x04) { |
1247 | if (temp != 0x04) { |
883 | psiconv_warn(lev+2,off+len, |
1248 | psiconv_warn(config,lev+2,off+len, |
884 | "Worksheet section initial byte unknown value (ignored)"); |
1249 | "Worksheet section initial byte unknown value (ignored)"); |
885 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
1250 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
886 | } |
1251 | } |
887 | len ++; |
1252 | len ++; |
888 | |
1253 | |
889 | psiconv_progress(lev+2,off+len, "Going to read the flags byte"); |
1254 | psiconv_progress(config,lev+2,off+len, "Going to read the flags byte"); |
890 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1255 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
891 | if (res) |
1256 | if (res) |
892 | goto ERROR2; |
1257 | goto ERROR2; |
893 | psiconv_debug(lev+2,off+len,"Flags byte: %02x",temp); |
1258 | psiconv_debug(config,lev+2,off+len,"Flags byte: %02x",temp); |
894 | (*result)->show_zeros = (temp & 0x01)?psiconv_bool_true:psiconv_bool_false; |
1259 | (*result)->show_zeros = (temp & 0x01)?psiconv_bool_true:psiconv_bool_false; |
895 | if (temp & 0xfe) { |
1260 | if (temp & 0xfe) { |
896 | psiconv_warn(lev+2,off+len, |
1261 | psiconv_warn(config,lev+2,off+len, |
897 | "Worksheet section flags byte unknown bits (ignored)"); |
1262 | "Worksheet section flags byte unknown bits (ignored)"); |
898 | } |
1263 | } |
899 | len ++; |
1264 | len ++; |
900 | |
1265 | |
901 | psiconv_progress(lev+2,off+len,"Going to read the default cell layout"); |
1266 | psiconv_progress(config,lev+2,off+len,"Going to read the default cell layout"); |
|
|
1267 | if (!((*result)->default_layout = psiconv_basic_cell_layout())) |
|
|
1268 | goto ERROR2; |
902 | if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len,&leng, |
1269 | if ((res = psiconv_parse_sheet_cell_layout(config,buf,lev+2,off+len,&leng, |
903 | &(*result)->default_layout))) |
1270 | (*result)->default_layout))) |
904 | goto ERROR2; |
1271 | goto ERROR3; |
905 | len += leng; |
1272 | len += leng; |
906 | |
1273 | |
907 | psiconv_progress(lev+2,off+len, |
1274 | psiconv_progress(config,lev+2,off+len, |
908 | "Going to read the offset of the 1st ??? Section"); |
1275 | "Going to read the offset of the row defaults Section"); |
909 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
1276 | rows_off = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
910 | if (res) |
1277 | if (res) |
911 | goto ERROR3; |
1278 | goto ERROR3; |
912 | psiconv_debug(lev+2,off+len,"Offset: %04x",temp); |
1279 | psiconv_debug(config,lev+2,off+len,"Offset: %04x",rows_off); |
913 | len += 4; |
1280 | len += 4; |
914 | |
1281 | |
915 | psiconv_progress(lev+2,off+len, |
1282 | psiconv_progress(config,lev+2,off+len, |
916 | "Going to read the offset of the 2nd ??? Section"); |
1283 | "Going to read the offset of the column defaults Section"); |
917 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
1284 | cols_off = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
918 | if (res) |
1285 | if (res) |
919 | goto ERROR3; |
1286 | goto ERROR3; |
920 | psiconv_debug(lev+2,off+len,"Offset: %04x",temp); |
1287 | psiconv_debug(config,lev+2,off+len,"Offset: %04x",cols_off); |
921 | len += 4; |
1288 | len += 4; |
922 | |
1289 | |
923 | psiconv_progress(lev+2,off+len, |
1290 | psiconv_progress(config,lev+2,off+len, |
924 | "Going to read the offset of the Cells List"); |
1291 | "Going to read the offset of the Cells List"); |
925 | cells_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
1292 | cells_off = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
926 | if (res) |
1293 | if (res) |
927 | goto ERROR3; |
1294 | goto ERROR3; |
928 | psiconv_debug(lev+2,off+len,"Offset: %04x",cells_off); |
1295 | psiconv_debug(config,lev+2,off+len,"Offset: %04x",cells_off); |
929 | len += 4; |
1296 | len += 4; |
930 | |
1297 | |
931 | psiconv_progress(lev+2,off+len, |
1298 | psiconv_progress(config,lev+2,off+len, |
932 | "Going to read the offset of the Grid Section"); |
1299 | "Going to read the offset of the Grid Section"); |
933 | grid_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
1300 | grid_off = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
934 | if (res) |
1301 | if (res) |
935 | goto ERROR3; |
1302 | goto ERROR3; |
936 | psiconv_debug(lev+2,off+len,"Offset: %04x",grid_off); |
1303 | psiconv_debug(config,lev+2,off+len,"Offset: %04x",grid_off); |
937 | len += 4; |
1304 | len += 4; |
938 | |
1305 | |
939 | psiconv_progress(lev+2,off+len, |
1306 | psiconv_progress(config,lev+2,off+len, |
940 | "Going to read the offset of the 3rd ??? Section"); |
1307 | "Going to read the offset of the 3rd ??? Section"); |
941 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
1308 | unknown_off = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
942 | if (res) |
1309 | if (res) |
943 | goto ERROR3; |
1310 | goto ERROR3; |
944 | psiconv_debug(lev+2,off+len,"Offset: %04x",temp); |
1311 | psiconv_debug(config,lev+2,off+len,"Offset: %04x",unknown_off); |
945 | len += 4; |
1312 | len += 4; |
946 | |
1313 | |
947 | psiconv_progress(lev+2,off+len,"Going to read the cells list"); |
1314 | psiconv_progress(config,lev+2,off+len, |
948 | if ((res = psiconv_parse_sheet_cell_list(buf,lev+2,cells_off,NULL, |
1315 | "Going to read a long of the 3rd ??? Section " |
949 | &(*result)->cells))) |
1316 | "(%08x expected)",0x00); |
|
|
1317 | temp = psiconv_read_u32(config,buf,lev+2,unknown_off,&res); |
|
|
1318 | if (res) |
950 | goto ERROR3; |
1319 | goto ERROR3; |
|
|
1320 | if (temp != 0x00) { |
|
|
1321 | psiconv_warn(config,lev+2,unknown_off, |
|
|
1322 | "Unknown worksheet subsection has unknown contents (ignored)"); |
|
|
1323 | psiconv_debug(config,lev+2,unknown_off,"Offset: %04x",temp); |
951 | |
1324 | } |
|
|
1325 | len += 4; |
952 | |
1326 | |
953 | /* TODO: parse grid section */ |
1327 | psiconv_progress(config,lev+2,off+len,"Going to read the row defaults"); |
|
|
1328 | if ((res = psiconv_parse_sheet_line_list(config,buf,lev+2,rows_off,NULL, |
|
|
1329 | &(*result)->row_default_layouts, |
|
|
1330 | (*result)->default_layout))) |
|
|
1331 | goto ERROR3; |
|
|
1332 | |
|
|
1333 | psiconv_progress(config,lev+2,off+len,"Going to read the column defaults"); |
|
|
1334 | if ((res = psiconv_parse_sheet_line_list(config,buf,lev+2,cols_off,NULL, |
|
|
1335 | &(*result)->col_default_layouts, |
|
|
1336 | (*result)->default_layout))) |
|
|
1337 | goto ERROR4; |
|
|
1338 | |
|
|
1339 | psiconv_progress(config,lev+2,off+len,"Going to read the cells list"); |
|
|
1340 | if ((res = psiconv_parse_sheet_cell_list(config,buf,lev+2,cells_off,NULL, |
|
|
1341 | &(*result)->cells, |
|
|
1342 | (*result)->default_layout, |
|
|
1343 | (*result)->row_default_layouts, |
|
|
1344 | (*result)->col_default_layouts))) |
|
|
1345 | goto ERROR5; |
|
|
1346 | |
|
|
1347 | |
|
|
1348 | psiconv_progress(config,lev+2,off+len,"Going to read the grid section"); |
|
|
1349 | if ((res = psiconv_parse_sheet_grid_section(config,buf,lev+2,grid_off,NULL, |
|
|
1350 | &(*result)->grid))) |
|
|
1351 | goto ERROR6; |
|
|
1352 | |
|
|
1353 | |
954 | |
1354 | |
955 | if (length) |
1355 | if (length) |
956 | *length = len; |
1356 | *length = len; |
957 | |
1357 | |
958 | psiconv_progress(lev,off+len-1, |
1358 | psiconv_progress(config,lev,off+len-1, |
959 | "End of sheet worksheet section (total length: %08x)", len); |
1359 | "End of sheet worksheet section (total length: %08x)", len); |
960 | return 0; |
1360 | return 0; |
961 | |
1361 | |
|
|
1362 | ERROR6: |
|
|
1363 | psiconv_free_sheet_cell_list((*result)->cells); |
|
|
1364 | ERROR5: |
|
|
1365 | psiconv_free_sheet_line_list((*result)->col_default_layouts); |
|
|
1366 | ERROR4: |
|
|
1367 | psiconv_free_sheet_line_list((*result)->row_default_layouts); |
962 | ERROR3: |
1368 | ERROR3: |
963 | psiconv_free_sheet_cell_layout((*result)->default_layout); |
1369 | psiconv_free_sheet_cell_layout((*result)->default_layout); |
964 | ERROR2: |
1370 | ERROR2: |
965 | free (*result); |
1371 | free (*result); |
966 | ERROR1: |
1372 | ERROR1: |
967 | psiconv_warn(lev+1,off,"Reading of Sheet Worksheet Section failed"); |
1373 | psiconv_warn(config,lev+1,off,"Reading of Sheet Worksheet Section failed"); |
968 | if (length) |
1374 | if (length) |
969 | *length = 0; |
1375 | *length = 0; |
970 | if (!res) |
1376 | if (!res) |
971 | return -PSICONV_E_NOMEM; |
1377 | return -PSICONV_E_NOMEM; |
972 | else |
1378 | else |
973 | return res; |
1379 | return res; |
974 | } |
1380 | } |
975 | |
1381 | |
|
|
1382 | int psiconv_parse_sheet_line(const psiconv_config config, |
|
|
1383 | const psiconv_buffer buf, int lev, |
|
|
1384 | psiconv_u32 off, int *length, |
|
|
1385 | psiconv_sheet_line *result, |
|
|
1386 | const psiconv_sheet_cell_layout default_layout) |
|
|
1387 | { |
|
|
1388 | int res=0; |
|
|
1389 | int len=0; |
|
|
1390 | int leng; |
976 | |
1391 | |
|
|
1392 | |
|
|
1393 | psiconv_progress(config,lev+1,off,"Going to read a sheet line"); |
|
|
1394 | if (!(*result = malloc(sizeof(**result)))) |
|
|
1395 | goto ERROR1; |
|
|
1396 | |
|
|
1397 | psiconv_progress(config,lev+2,off+len,"Going to read the line number"); |
|
|
1398 | (*result)->position = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res); |
|
|
1399 | if (res) |
|
|
1400 | goto ERROR2; |
|
|
1401 | psiconv_debug(config,lev+2,off+len,"Line number: %d\n",(*result)->position); |
|
|
1402 | len += leng; |
|
|
1403 | |
|
|
1404 | if (!((*result)->layout = psiconv_clone_cell_layout(default_layout))) |
|
|
1405 | goto ERROR2; |
|
|
1406 | if ((res = psiconv_parse_sheet_cell_layout(config,buf,lev+2,off+len, |
|
|
1407 | &leng,(*result)->layout))) |
|
|
1408 | goto ERROR3; |
|
|
1409 | len += leng; |
|
|
1410 | |
|
|
1411 | if (length) |
|
|
1412 | *length = len; |
|
|
1413 | |
|
|
1414 | psiconv_progress(config,lev,off+len-1, |
|
|
1415 | "End of the sheet line (total length: %08x)", len); |
|
|
1416 | return 0; |
|
|
1417 | |
|
|
1418 | ERROR3: |
|
|
1419 | psiconv_free_sheet_cell_layout((*result)->layout); |
|
|
1420 | ERROR2: |
|
|
1421 | free (*result); |
|
|
1422 | ERROR1: |
|
|
1423 | psiconv_warn(config,lev+1,off,"Reading of the sheet line failed"); |
|
|
1424 | if (length) |
|
|
1425 | *length = 0; |
|
|
1426 | if (!res) |
|
|
1427 | return -PSICONV_E_NOMEM; |
|
|
1428 | else |
|
|
1429 | return res; |
|
|
1430 | } |
|
|
1431 | |
|
|
1432 | |
|
|
1433 | int psiconv_parse_sheet_line_list(const psiconv_config config, |
|
|
1434 | const psiconv_buffer buf, int lev, |
|
|
1435 | psiconv_u32 off, int *length, |
|
|
1436 | psiconv_sheet_line_list *result, |
|
|
1437 | const psiconv_sheet_cell_layout default_layout) |
|
|
1438 | { |
|
|
1439 | int res=0; |
|
|
1440 | int len=0; |
|
|
1441 | psiconv_u32 temp; |
|
|
1442 | psiconv_sheet_line line; |
|
|
1443 | psiconv_u32 listlen,i; |
|
|
1444 | int leng; |
|
|
1445 | |
|
|
1446 | psiconv_progress(config,lev+1,off,"Going to read the sheet line list"); |
|
|
1447 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_line_s)))) |
|
|
1448 | goto ERROR1; |
|
|
1449 | |
|
|
1450 | psiconv_progress(config,lev+2,off+len, |
|
|
1451 | "Going to read the initial byte (%02x expected)",0x02); |
|
|
1452 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
|
|
1453 | if (res) |
|
|
1454 | goto ERROR2; |
|
|
1455 | if (temp != 0x02) { |
|
|
1456 | psiconv_warn(config,lev+2,off+len, |
|
|
1457 | "Sheet line list initial byte unknown value (ignored)"); |
|
|
1458 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
|
|
1459 | } |
|
|
1460 | len ++; |
|
|
1461 | |
|
|
1462 | psiconv_progress(config,lev+2,off+len, |
|
|
1463 | "Going to read the number of defined lines"); |
|
|
1464 | listlen = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res); |
|
|
1465 | if (res) |
|
|
1466 | goto ERROR2; |
|
|
1467 | psiconv_debug(config,lev+2,off+len,"Number of defined lines: %d",listlen); |
|
|
1468 | len += leng; |
|
|
1469 | |
|
|
1470 | psiconv_progress(config,lev+2,off+len,"Going to read all lines"); |
|
|
1471 | for (i = 0; i < listlen; i++) { |
|
|
1472 | psiconv_progress(config,lev+3,off+len,"Going to read line %d",i); |
|
|
1473 | if ((res = psiconv_parse_sheet_line(config,buf,lev+3,off+len,&leng,&line, |
|
|
1474 | default_layout))) |
|
|
1475 | goto ERROR2; |
|
|
1476 | if ((res = psiconv_list_add(*result,line))) |
|
|
1477 | goto ERROR3; |
|
|
1478 | free(line); |
|
|
1479 | len += leng; |
|
|
1480 | } |
|
|
1481 | |
|
|
1482 | if (length) |
|
|
1483 | *length = len; |
|
|
1484 | |
|
|
1485 | psiconv_progress(config,lev,off+len-1, |
|
|
1486 | "End of sheet line list (total length: %08x)", len); |
|
|
1487 | return 0; |
|
|
1488 | |
|
|
1489 | ERROR3: |
|
|
1490 | psiconv_free_sheet_line(line); |
|
|
1491 | ERROR2: |
|
|
1492 | psiconv_free_sheet_line_list(*result); |
|
|
1493 | ERROR1: |
|
|
1494 | psiconv_warn(config,lev+1,off,"Reading of Sheet Line List failed"); |
|
|
1495 | if (length) |
|
|
1496 | *length = 0; |
|
|
1497 | if (!res) |
|
|
1498 | return -PSICONV_E_NOMEM; |
|
|
1499 | else |
|
|
1500 | return res; |
|
|
1501 | } |
|
|
1502 | |
|
|
1503 | int psiconv_parse_sheet_variable(const psiconv_config config, |
|
|
1504 | const psiconv_buffer buf, int lev, |
|
|
1505 | psiconv_u32 off, int *length, |
|
|
1506 | psiconv_sheet_variable *result) |
|
|
1507 | { |
|
|
1508 | int res=0; |
|
|
1509 | int len=0; |
|
|
1510 | psiconv_u32 marker; |
|
|
1511 | int leng; |
|
|
1512 | |
|
|
1513 | psiconv_progress(config,lev+1,off,"Going to read a sheet variable"); |
|
|
1514 | if (!(*result = malloc(sizeof(**result)))) |
|
|
1515 | goto ERROR1; |
|
|
1516 | |
|
|
1517 | psiconv_progress(config,lev+2,off+len, "Going to read the variable name"); |
|
|
1518 | (*result)->name = psiconv_read_string(config,buf,lev+2,off+len,&leng,&res); |
|
|
1519 | if (res) |
|
|
1520 | goto ERROR2; |
|
|
1521 | len += leng; |
|
|
1522 | |
|
|
1523 | psiconv_progress(config,lev+2,off+len,"Going to read the type marker"); |
|
|
1524 | marker = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
|
|
1525 | if (res) |
|
|
1526 | goto ERROR3; |
|
|
1527 | psiconv_debug(config,lev+2,off+len,"Marker: %02x",marker); |
|
|
1528 | len ++; |
|
|
1529 | |
|
|
1530 | if (marker == 0x00) { |
|
|
1531 | (*result)->type = psiconv_var_int; |
|
|
1532 | psiconv_progress(config,lev+2,off+len,"Going to read a signed integer"); |
|
|
1533 | (*result)->data.dat_int = psiconv_read_sint(config,buf,lev+2,off+len,&leng,&res); |
|
|
1534 | if (res) |
|
|
1535 | goto ERROR3; |
|
|
1536 | psiconv_debug(config,lev+2,off+len,"Value: %d",(*result)->data.dat_int); |
|
|
1537 | len += leng; |
|
|
1538 | } else if (marker == 0x01) { |
|
|
1539 | (*result)->type = psiconv_var_float; |
|
|
1540 | psiconv_progress(config,lev+2,off+len,"Going to read a floating point number"); |
|
|
1541 | (*result)->data.dat_float = psiconv_read_float(config,buf,lev+2,off+len,&leng, |
|
|
1542 | &res); |
|
|
1543 | if (res) |
|
|
1544 | goto ERROR3; |
|
|
1545 | psiconv_debug(config,lev+2,off+len,"Value: %f",(*result)->data.dat_float); |
|
|
1546 | len += leng; |
|
|
1547 | } else if (marker == 0x02) { |
|
|
1548 | (*result)->type = psiconv_var_string; |
|
|
1549 | psiconv_progress(config,lev+2,off+len,"Going to read a string"); |
|
|
1550 | (*result)->data.dat_string = psiconv_read_string(config,buf,lev+2,off+len,&leng, |
|
|
1551 | &res); |
|
|
1552 | if (res) |
|
|
1553 | goto ERROR3; |
|
|
1554 | len += leng; |
|
|
1555 | } else if (marker == 0x03) { |
|
|
1556 | (*result)->type = psiconv_var_cellref; |
|
|
1557 | psiconv_progress(config,lev+2,off+len,"Going to read a cell reference"); |
|
|
1558 | (*result)->data.dat_cellref = psiconv_read_var_cellref(config,buf,lev+2,off+len, |
|
|
1559 | &leng, &res); |
|
|
1560 | if (res) |
|
|
1561 | goto ERROR3; |
|
|
1562 | len += leng; |
|
|
1563 | } else if (marker == 0x04) { |
|
|
1564 | (*result)->type = psiconv_var_cellblock; |
|
|
1565 | psiconv_progress(config,lev+2,off+len,"Going to read a cell block reference"); |
|
|
1566 | (*result)->data.dat_cellblock = psiconv_read_var_cellblock(config,buf,lev+2, |
|
|
1567 | off+len, |
|
|
1568 | &leng, &res); |
|
|
1569 | if (res) |
|
|
1570 | goto ERROR3; |
|
|
1571 | len += leng; |
|
|
1572 | } else { |
|
|
1573 | psiconv_warn(config,lev+2,off+len,"Sheet variable unknown type marker"); |
|
|
1574 | res = -PSICONV_E_PARSE; |
|
|
1575 | goto ERROR3; |
|
|
1576 | } |
|
|
1577 | |
|
|
1578 | psiconv_progress(config,lev+2,off+len,"Going to read the variable number"); |
|
|
1579 | (*result)->number = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
|
|
1580 | if (res) |
|
|
1581 | goto ERROR4; |
|
|
1582 | psiconv_debug(config,lev+2,off+len,"Number: %08x",(*result)->number); |
|
|
1583 | len += 4; |
|
|
1584 | |
|
|
1585 | if (length) |
|
|
1586 | *length = len; |
|
|
1587 | |
|
|
1588 | psiconv_progress(config,lev,off+len-1, |
|
|
1589 | "End of sheet variable (total length: %08x)", len); |
|
|
1590 | return 0; |
|
|
1591 | |
|
|
1592 | ERROR4: |
|
|
1593 | if ((*result)->type == psiconv_var_string) |
|
|
1594 | free((*result)->data.dat_string); |
|
|
1595 | ERROR3: |
|
|
1596 | free((*result)->name); |
|
|
1597 | ERROR2: |
|
|
1598 | free (*result); |
|
|
1599 | ERROR1: |
|
|
1600 | psiconv_warn(config,lev+1,off,"Reading of Sheet Variable failed"); |
|
|
1601 | if (length) |
|
|
1602 | *length = 0; |
|
|
1603 | if (!res) |
|
|
1604 | return -PSICONV_E_NOMEM; |
|
|
1605 | else |
|
|
1606 | return res; |
|
|
1607 | } |
|
|
1608 | |
|
|
1609 | |
|
|
1610 | int psiconv_parse_sheet_variable_list(const psiconv_config config, |
|
|
1611 | const psiconv_buffer buf, int lev, |
|
|
1612 | psiconv_u32 off, int *length, |
|
|
1613 | psiconv_sheet_variable_list *result) |
|
|
1614 | { |
|
|
1615 | int res=0; |
|
|
1616 | int len=0; |
|
|
1617 | psiconv_u32 temp; |
|
|
1618 | psiconv_sheet_variable variable; |
|
|
1619 | psiconv_u32 listlen,i; |
|
|
1620 | int leng; |
|
|
1621 | |
|
|
1622 | psiconv_progress(config,lev+1,off,"Going to read the sheet variable list"); |
|
|
1623 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_variable_s)))) |
|
|
1624 | goto ERROR1; |
|
|
1625 | |
|
|
1626 | psiconv_progress(config,lev+2,off+len, |
|
|
1627 | "Going to read the initial byte (%02x expected)",0x02); |
|
|
1628 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
|
|
1629 | if (res) |
|
|
1630 | goto ERROR2; |
|
|
1631 | if (temp != 0x02) { |
|
|
1632 | psiconv_warn(config,lev+2,off+len, |
|
|
1633 | "Sheet variable list initial byte unknown value (ignored)"); |
|
|
1634 | psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp); |
|
|
1635 | } |
|
|
1636 | len ++; |
|
|
1637 | |
|
|
1638 | psiconv_progress(config,lev+2,off+len, |
|
|
1639 | "Going to read the number of variables"); |
|
|
1640 | listlen = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res); |
|
|
1641 | if (res) |
|
|
1642 | goto ERROR2; |
|
|
1643 | psiconv_debug(config,lev+2,off+len,"Number of variables: %d",listlen); |
|
|
1644 | len += leng; |
|
|
1645 | |
|
|
1646 | psiconv_progress(config,lev+2,off+len,"Going to read all variables"); |
|
|
1647 | for (i = 0; i < listlen; i++) { |
|
|
1648 | psiconv_progress(config,lev+3,off+len,"Going to read variable %d",i); |
|
|
1649 | if ((res = psiconv_parse_sheet_variable(config,buf,lev+3,off+len,&leng,&variable))) |
|
|
1650 | goto ERROR2; |
|
|
1651 | if ((res = psiconv_list_add(*result,variable))) |
|
|
1652 | goto ERROR3; |
|
|
1653 | len += leng; |
|
|
1654 | } |
|
|
1655 | |
|
|
1656 | if (length) |
|
|
1657 | *length = len; |
|
|
1658 | |
|
|
1659 | psiconv_progress(config,lev,off+len-1, |
|
|
1660 | "End of sheet variabels list (total length: %08x)", len); |
|
|
1661 | return 0; |
|
|
1662 | |
|
|
1663 | ERROR3: |
|
|
1664 | psiconv_free_sheet_variable(variable); |
|
|
1665 | ERROR2: |
|
|
1666 | psiconv_list_free(*result); |
|
|
1667 | ERROR1: |
|
|
1668 | psiconv_warn(config,lev+1,off,"Reading of Sheet Variable list failed"); |
|
|
1669 | if (length) |
|
|
1670 | *length = 0; |
|
|
1671 | if (!res) |
|
|
1672 | return -PSICONV_E_NOMEM; |
|
|
1673 | else |
|
|
1674 | return res; |
|
|
1675 | } |
|
|
1676 | |
|
|
1677 | int psiconv_parse_sheet_grid_section(const psiconv_config config, |
|
|
1678 | const psiconv_buffer buf, int lev, |
|
|
1679 | psiconv_u32 off, int *length, |
|
|
1680 | psiconv_sheet_grid_section *result) |
|
|
1681 | { |
|
|
1682 | int res=0,i; |
|
|
1683 | int len=0,leng; |
|
|
1684 | psiconv_u32 temp; |
|
|
1685 | |
|
|
1686 | psiconv_progress(config,lev+1,off,"Going to read the sheet grid section"); |
|
|
1687 | if (!(*result = malloc(sizeof(**result)))) |
|
|
1688 | goto ERROR1; |
|
|
1689 | |
|
|
1690 | psiconv_progress(config,lev+2,off+len, "Going to read the first flags byte"); |
|
|
1691 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
|
|
1692 | if (res) |
|
|
1693 | goto ERROR2; |
|
|
1694 | (*result)->show_column_titles = temp&0x01?psiconv_bool_true: |
|
|
1695 | psiconv_bool_false; |
|
|
1696 | psiconv_debug(config,lev+2,off+len, |
|
|
1697 | "Show column titles: %s", |
|
|
1698 | (*result)->show_column_titles?"true":"false"); |
|
|
1699 | (*result)->show_row_titles = temp&0x02?psiconv_bool_true:psiconv_bool_false; |
|
|
1700 | psiconv_debug(config,lev+2,off+len, |
|
|
1701 | "Show row titles: %s", |
|
|
1702 | (*result)->show_row_titles?"true":"false"); |
|
|
1703 | (*result)->show_vertical_grid = temp&0x04?psiconv_bool_true: |
|
|
1704 | psiconv_bool_false; |
|
|
1705 | psiconv_debug(config,lev+2,off+len, |
|
|
1706 | "Show vertical grid: %s", |
|
|
1707 | (*result)->show_vertical_grid?"true":"false"); |
|
|
1708 | (*result)->show_horizontal_grid = temp&0x07?psiconv_bool_true: |
|
|
1709 | psiconv_bool_false; |
|
|
1710 | psiconv_debug(config,lev+2,off+len, |
|
|
1711 | "Show horizontal grid: %s", |
|
|
1712 | (*result)->show_horizontal_grid?"true":"false"); |
|
|
1713 | (*result)->freeze_rows = temp&0x80?psiconv_bool_true:psiconv_bool_false; |
|
|
1714 | psiconv_debug(config,lev+2,off+len, |
|
|
1715 | "Freeze rows: %s", |
|
|
1716 | (*result)->freeze_rows?"true":"false"); |
|
|
1717 | if ((temp & 0x70) != 0x30) { |
|
|
1718 | psiconv_warn(config,lev+2,off+len, |
|
|
1719 | "Grid section first flag byte has unknown bits (ignored)"); |
|
|
1720 | psiconv_debug(config,lev+2,off+len,"Bits: %02x (%02x expected)",temp&0x70,0x30); |
|
|
1721 | } |
|
|
1722 | len ++; |
|
|
1723 | |
|
|
1724 | psiconv_progress(config,lev+2,off+len, "Going to read the second flags byte"); |
|
|
1725 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
|
|
1726 | if (res) |
|
|
1727 | goto ERROR2; |
|
|
1728 | (*result)->freeze_columns = temp&0x01?psiconv_bool_true:psiconv_bool_false; |
|
|
1729 | psiconv_debug(config,lev+2,off+len, |
|
|
1730 | "Freeze columns: %s", (*result)->freeze_columns?"true":"false"); |
|
|
1731 | if ((temp & 0xfe) != 0x80) { |
|
|
1732 | psiconv_warn(config,lev+2,off+len, |
|
|
1733 | "Grid section second flag byte has unknown bits (ignored)"); |
|
|
1734 | psiconv_debug(config,lev+2,off+len,"Bits: %02x (%02x expected)",temp&0xfe,0x80); |
|
|
1735 | } |
|
|
1736 | len ++; |
|
|
1737 | |
|
|
1738 | psiconv_progress(config,lev+2,off+len, |
|
|
1739 | "Going to an unknown byte (%02x expected)",0x90); |
|
|
1740 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
|
|
1741 | if (res) |
|
|
1742 | goto ERROR2; |
|
|
1743 | if (temp != 0x90) { |
|
|
1744 | psiconv_warn(config,lev+2,off+len, |
|
|
1745 | "Grid section third byte unknown value (ignored)"); |
|
|
1746 | psiconv_debug(config,lev+2,off+len,"Value: %02x",temp); |
|
|
1747 | } |
|
|
1748 | len ++; |
|
|
1749 | |
|
|
1750 | psiconv_progress(config,lev+2,off+len, "Going to read the fourth flags byte"); |
|
|
1751 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
|
|
1752 | if (res) |
|
|
1753 | goto ERROR2; |
|
|
1754 | (*result)->show_page_breaks = temp&0x04?psiconv_bool_true:psiconv_bool_false; |
|
|
1755 | psiconv_debug(config,lev+2,off+len, |
|
|
1756 | "Show page breaks: %s", |
|
|
1757 | (*result)->show_page_breaks?"true":"false"); |
|
|
1758 | if ((temp & 0xfc) != 0x00) { |
|
|
1759 | psiconv_warn(config,lev+2,off+len, |
|
|
1760 | "Grid section fourth flag byte has unknown bits (ignored)"); |
|
|
1761 | psiconv_debug(config,lev+2,off+len,"Bits: %02x (%02x expected)",temp&0xfc,0x00); |
|
|
1762 | } |
|
|
1763 | len ++; |
|
|
1764 | |
|
|
1765 | psiconv_progress(config,lev+2,off+len,"Going to read the first visible row"); |
|
|
1766 | (*result)->first_row = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
|
|
1767 | if (res) |
|
|
1768 | goto ERROR2; |
|
|
1769 | psiconv_debug(config,lev+2,off+len,"First row: %d",(*result)->first_row); |
|
|
1770 | len += 4; |
|
|
1771 | |
|
|
1772 | psiconv_progress(config,lev+2,off+len,"Going to read the first visible column"); |
|
|
1773 | (*result)->first_column = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
|
|
1774 | if (res) |
|
|
1775 | goto ERROR2; |
|
|
1776 | psiconv_debug(config,lev+2,off+len,"First column: %d",(*result)->first_column); |
|
|
1777 | len += 4; |
|
|
1778 | |
|
|
1779 | psiconv_progress(config,lev+2,off+len,"Going to read the last visible row"); |
|
|
1780 | (*result)->last_row = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
|
|
1781 | if (res) |
|
|
1782 | goto ERROR2; |
|
|
1783 | psiconv_debug(config,lev+2,off+len,"Last row: %d",(*result)->last_row); |
|
|
1784 | len += 4; |
|
|
1785 | |
|
|
1786 | psiconv_progress(config,lev+2,off+len,"Going to read the last visible column"); |
|
|
1787 | (*result)->last_column = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
|
|
1788 | if (res) |
|
|
1789 | goto ERROR2; |
|
|
1790 | psiconv_debug(config,lev+2,off+len,"Last column: %d",(*result)->last_column); |
|
|
1791 | len += 4; |
|
|
1792 | |
|
|
1793 | psiconv_progress(config,lev+2,off+len,"Going to read the default row height"); |
|
|
1794 | (*result)->default_row_height = psiconv_read_length(config,buf,lev+2,off+len, |
|
|
1795 | &leng,&res); |
|
|
1796 | if (res) |
|
|
1797 | goto ERROR2; |
|
|
1798 | psiconv_debug(config,lev+2,off+len,"Default row height: %f", |
|
|
1799 | (*result)->default_row_height); |
|
|
1800 | len += leng; |
|
|
1801 | |
|
|
1802 | psiconv_progress(config,lev+2,off+len,"Going to read the row heights list"); |
|
|
1803 | if ((res = psiconv_parse_sheet_grid_size_list(config,buf,lev+2,off+len,&leng, |
|
|
1804 | &(*result)->row_heights))) |
|
|
1805 | goto ERROR2; |
|
|
1806 | len += leng; |
|
|
1807 | |
|
|
1808 | psiconv_progress(config,lev+2,off+len,"Going to read the default column height"); |
|
|
1809 | (*result)->default_column_width = psiconv_read_length(config,buf,lev+2,off+len, |
|
|
1810 | &leng,&res); |
|
|
1811 | if (res) |
|
|
1812 | goto ERROR3; |
|
|
1813 | psiconv_debug(config,lev+2,off+len,"Default column width: %f", |
|
|
1814 | (*result)->default_column_width); |
|
|
1815 | len += leng; |
|
|
1816 | |
|
|
1817 | psiconv_progress(config,lev+2,off+len,"Going to read the column heights list"); |
|
|
1818 | if ((res = psiconv_parse_sheet_grid_size_list(config,buf,lev+2,off+len,&leng, |
|
|
1819 | &(*result)->column_heights))) |
|
|
1820 | goto ERROR3; |
|
|
1821 | len += leng; |
|
|
1822 | |
|
|
1823 | psiconv_progress(config,lev+2,off+len, |
|
|
1824 | "Going to read an unknown word (%04x expected)",0x00); |
|
|
1825 | temp = psiconv_read_u16(config,buf,lev+2,off+len,&res); |
|
|
1826 | if (res) |
|
|
1827 | goto ERROR4; |
|
|
1828 | if (temp != 0x00) { |
|
|
1829 | psiconv_warn(config,lev+2,off+len, |
|
|
1830 | "Grid section unknown word has unknown value (ignored)"); |
|
|
1831 | psiconv_debug(config,lev+2,off+len,"Value: %04x",temp); |
|
|
1832 | } |
|
|
1833 | len += 2; |
|
|
1834 | |
|
|
1835 | psiconv_progress(config,lev+2,off+len,"Going to read the row breaks list"); |
|
|
1836 | if ((res = psiconv_parse_sheet_grid_break_list(config,buf,lev+2,off+len,&leng, |
|
|
1837 | &(*result)->row_page_breaks))) |
|
|
1838 | goto ERROR4; |
|
|
1839 | len += leng; |
|
|
1840 | |
|
|
1841 | psiconv_progress(config,lev+2,off+len,"Going to read the column breaks list"); |
|
|
1842 | if ((res = psiconv_parse_sheet_grid_break_list(config,buf,lev+2,off+len,&leng, |
|
|
1843 | &(*result)->column_page_breaks))) |
|
|
1844 | goto ERROR5; |
|
|
1845 | len += leng; |
|
|
1846 | |
|
|
1847 | |
|
|
1848 | psiconv_progress(config,lev+2,off+len, |
|
|
1849 | "Going to read 22 unknown bytes (%02x expected)",0x00); |
|
|
1850 | for (i = 0; i < 22 ; i++) { |
|
|
1851 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
|
|
1852 | if (res) |
|
|
1853 | goto ERROR6; |
|
|
1854 | if (temp != 0x00) { |
|
|
1855 | psiconv_warn(config,lev+2,off+len, |
|
|
1856 | "Grid section unknown byte %d has unknown value (ignored)", |
|
|
1857 | i); |
|
|
1858 | psiconv_debug(config,lev+2,off+len,"Value: %02x",temp); |
|
|
1859 | } |
|
|
1860 | len += 1; |
|
|
1861 | } |
|
|
1862 | |
|
|
1863 | if ((*result)->freeze_rows || (*result)->freeze_columns) { |
|
|
1864 | |
|
|
1865 | psiconv_progress(config,lev+2,off+len,"Going to read number of frozen rows"); |
|
|
1866 | (*result)->frozen_rows = psiconv_read_u32(config,buf,lev+2,off+len, &res); |
|
|
1867 | if (res) |
|
|
1868 | goto ERROR6; |
|
|
1869 | psiconv_debug(config,lev+2,off+len,"Number of frozen rows: %d", |
|
|
1870 | (*result)->frozen_rows); |
|
|
1871 | len += leng; |
|
|
1872 | |
|
|
1873 | psiconv_progress(config,lev+2,off+len,"Going to read number of frozen columns"); |
|
|
1874 | (*result)->frozen_columns = psiconv_read_u32(config,buf,lev+2,off+len, &res); |
|
|
1875 | if (res) |
|
|
1876 | goto ERROR6; |
|
|
1877 | psiconv_debug(config,lev+2,off+len,"Number of frozen columns: %d", |
|
|
1878 | (*result)->frozen_columns); |
|
|
1879 | len += leng; |
|
|
1880 | |
|
|
1881 | psiconv_progress(config,lev+2,off+len,"Going to read first unfrozen row"); |
|
|
1882 | (*result)->first_unfrozen_row_displayed = psiconv_read_u32(config,buf,lev+2, |
|
|
1883 | off+len, &res); |
|
|
1884 | if (res) |
|
|
1885 | goto ERROR6; |
|
|
1886 | psiconv_debug(config,lev+2,off+len,"First row: %d", |
|
|
1887 | (*result)->first_unfrozen_row_displayed); |
|
|
1888 | len += leng; |
|
|
1889 | |
|
|
1890 | psiconv_progress(config,lev+2,off+len,"Going to read first unfrozen column"); |
|
|
1891 | (*result)->first_unfrozen_column_displayed = psiconv_read_u32(config,buf,lev+2, |
|
|
1892 | off+len,&res); |
|
|
1893 | if (res) |
|
|
1894 | goto ERROR6; |
|
|
1895 | psiconv_debug(config,lev+2,off+len,"First column: %d", |
|
|
1896 | (*result)->first_unfrozen_column_displayed); |
|
|
1897 | len += leng; |
|
|
1898 | } else |
|
|
1899 | (*result)->frozen_rows = (*result)->frozen_columns = |
|
|
1900 | (*result)->first_unfrozen_row_displayed = |
|
|
1901 | (*result)->first_unfrozen_column_displayed = 0; |
|
|
1902 | |
|
|
1903 | psiconv_progress(config,lev+2,off+len, |
|
|
1904 | "Going to read 3 unknown bytes (%02x expected)",0xff); |
|
|
1905 | for (i = 0; i < 3 ; i++) { |
|
|
1906 | temp = psiconv_read_u8(config,buf,lev+2,off+len,&res); |
|
|
1907 | if (res) |
|
|
1908 | goto ERROR6; |
|
|
1909 | if (temp != 0xff) { |
|
|
1910 | psiconv_warn(config,lev+2,off+len, |
|
|
1911 | "Grid section unknown byte %d has unknown value (ignored)", |
|
|
1912 | i); |
|
|
1913 | psiconv_debug(config,lev+2,off+len,"Value: %02x",temp); |
|
|
1914 | } |
|
|
1915 | len ++; |
|
|
1916 | } |
|
|
1917 | |
|
|
1918 | if (length) |
|
|
1919 | *length = len; |
|
|
1920 | |
|
|
1921 | psiconv_progress(config,lev,off+len-1, |
|
|
1922 | "End of sheet grid section (total length: %08x)", len); |
|
|
1923 | return 0; |
|
|
1924 | |
|
|
1925 | ERROR6: |
|
|
1926 | psiconv_free_sheet_grid_break_list((*result)->column_page_breaks); |
|
|
1927 | ERROR5: |
|
|
1928 | psiconv_free_sheet_grid_break_list((*result)->row_page_breaks); |
|
|
1929 | ERROR4: |
|
|
1930 | psiconv_free_sheet_grid_size_list((*result)->column_heights); |
|
|
1931 | ERROR3: |
|
|
1932 | psiconv_free_sheet_grid_size_list((*result)->row_heights); |
|
|
1933 | ERROR2: |
|
|
1934 | free(*result); |
|
|
1935 | ERROR1: |
|
|
1936 | psiconv_warn(config,lev+1,off,"Reading of Sheet Grid Section failed"); |
|
|
1937 | if (length) |
|
|
1938 | *length = 0; |
|
|
1939 | if (!res) |
|
|
1940 | return -PSICONV_E_NOMEM; |
|
|
1941 | else |
|
|
1942 | return res; |
|
|
1943 | } |
|
|
1944 | |
|
|
1945 | |
|
|
1946 | int psiconv_parse_sheet_grid_size_list(const psiconv_config config, |
|
|
1947 | const psiconv_buffer buf, int lev, |
|
|
1948 | psiconv_u32 off, int *length, |
|
|
1949 | psiconv_sheet_grid_size_list *result) |
|
|
1950 | { |
|
|
1951 | int res=0; |
|
|
1952 | int len=0,i; |
|
|
1953 | int leng,listlen; |
|
|
1954 | psiconv_sheet_grid_size size; |
|
|
1955 | |
|
|
1956 | psiconv_progress(config,lev+1,off,"Going to read a sheet grid size list"); |
|
|
1957 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_grid_size_s)))) |
|
|
1958 | goto ERROR1; |
|
|
1959 | |
|
|
1960 | psiconv_progress(config,lev+2,off+len, |
|
|
1961 | "Going to read the number of elements"); |
|
|
1962 | listlen = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res); |
|
|
1963 | if (res) |
|
|
1964 | goto ERROR2; |
|
|
1965 | psiconv_debug(config,lev+2,off+len,"Number of elements: %d",listlen); |
|
|
1966 | len += leng; |
|
|
1967 | |
|
|
1968 | psiconv_progress(config,lev+2,off+len,"Going to read all elements"); |
|
|
1969 | for (i = 0; i < listlen; i++) { |
|
|
1970 | psiconv_progress(config,lev+3,off+len,"Going to read element %d",i); |
|
|
1971 | if ((res = psiconv_parse_sheet_grid_size(config,buf,lev+3,off+len,&leng,&size))) |
|
|
1972 | goto ERROR2; |
|
|
1973 | if ((res = psiconv_list_add(*result,size))) |
|
|
1974 | goto ERROR3; |
|
|
1975 | free(size); |
|
|
1976 | len += leng; |
|
|
1977 | } |
|
|
1978 | |
|
|
1979 | if (length) |
|
|
1980 | *length = len; |
|
|
1981 | |
|
|
1982 | psiconv_progress(config,lev,off+len-1, |
|
|
1983 | "End of sheet grid size list (total length: %08x)", len); |
|
|
1984 | return 0; |
|
|
1985 | |
|
|
1986 | ERROR3: |
|
|
1987 | psiconv_free_sheet_grid_size(size); |
|
|
1988 | ERROR2: |
|
|
1989 | psiconv_list_free(*result); |
|
|
1990 | ERROR1: |
|
|
1991 | psiconv_warn(config,lev+1,off,"Reading of Sheet Grid Size List failed"); |
|
|
1992 | if (length) |
|
|
1993 | *length = 0; |
|
|
1994 | if (!res) |
|
|
1995 | return -PSICONV_E_NOMEM; |
|
|
1996 | else |
|
|
1997 | return res; |
|
|
1998 | } |
|
|
1999 | |
|
|
2000 | int psiconv_parse_sheet_grid_size(const psiconv_config config, |
|
|
2001 | const psiconv_buffer buf, int lev, |
|
|
2002 | psiconv_u32 off, int *length, |
|
|
2003 | psiconv_sheet_grid_size *result) |
|
|
2004 | { |
|
|
2005 | int res=0; |
|
|
2006 | int len=0; |
|
|
2007 | int leng; |
|
|
2008 | |
|
|
2009 | psiconv_progress(config,lev+1,off,"Going to read a sheet grid size"); |
|
|
2010 | |
|
|
2011 | if (!(*result = malloc(sizeof(**result)))) |
|
|
2012 | goto ERROR1; |
|
|
2013 | |
|
|
2014 | psiconv_progress(config,lev+2,off+len, "Going to read the row or column number"); |
|
|
2015 | (*result)->line_number = psiconv_read_u32(config,buf,lev+2,off+len,&res); |
|
|
2016 | if (res) |
|
|
2017 | goto ERROR2; |
|
|
2018 | psiconv_debug(config,lev+2,off+len,"Line number: %d\n",(*result)->line_number); |
|
|
2019 | len += 4; |
|
|
2020 | |
|
|
2021 | psiconv_progress(config,lev+2,off+len, "Going to read the row or column height"); |
|
|
2022 | (*result)->size = psiconv_read_length(config,buf,lev+2,off+len,&leng,&res); |
|
|
2023 | if (res) |
|
|
2024 | goto ERROR2; |
|
|
2025 | psiconv_debug(config,lev+2,off+len,"Size: %f\n",(*result)->size); |
|
|
2026 | len += leng; |
|
|
2027 | |
|
|
2028 | if (length) |
|
|
2029 | *length = len; |
|
|
2030 | |
|
|
2031 | psiconv_progress(config,lev,off+len-1, |
|
|
2032 | "End of sheet grid size(total length: %08x)", len); |
|
|
2033 | return 0; |
|
|
2034 | |
|
|
2035 | ERROR2: |
|
|
2036 | free (*result); |
|
|
2037 | ERROR1: |
|
|
2038 | psiconv_warn(config,lev+1,off,"Reading of Sheet Grid Size failed"); |
|
|
2039 | if (length) |
|
|
2040 | *length = 0; |
|
|
2041 | if (!res) |
|
|
2042 | return -PSICONV_E_NOMEM; |
|
|
2043 | else |
|
|
2044 | return res; |
|
|
2045 | } |
|
|
2046 | |
|
|
2047 | |
|
|
2048 | int psiconv_parse_sheet_grid_break_list(const psiconv_config config, |
|
|
2049 | const psiconv_buffer buf, int lev, |
|
|
2050 | psiconv_u32 off, int *length, |
|
|
2051 | psiconv_sheet_grid_break_list *result) |
|
|
2052 | { |
|
|
2053 | int res=0; |
|
|
2054 | int len=0,i; |
|
|
2055 | int leng,listlen; |
|
|
2056 | psiconv_u32 nr; |
|
|
2057 | |
|
|
2058 | psiconv_progress(config,lev+1,off,"Going to read a sheet grid break list"); |
|
|
2059 | if (!(*result = psiconv_list_new(sizeof(psiconv_u32)))) |
|
|
2060 | goto ERROR1; |
|
|
2061 | |
|
|
2062 | psiconv_progress(config,lev+2,off+len, |
|
|
2063 | "Going to read the number of elements"); |
|
|
2064 | listlen = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res); |
|
|
2065 | if (res) |
|
|
2066 | goto ERROR2; |
|
|
2067 | psiconv_debug(config,lev+2,off+len,"Number of elements: %d",listlen); |
|
|
2068 | len += leng; |
|
|
2069 | |
|
|
2070 | psiconv_progress(config,lev+2,off+len,"Going to read all elements"); |
|
|
2071 | for (i = 0; i < listlen; i++) { |
|
|
2072 | psiconv_progress(config,lev+3,off+len,"Going to read element %d",i); |
|
|
2073 | nr = psiconv_read_u32(config,buf,lev+3,off+len,&res); |
|
|
2074 | if (res) |
|
|
2075 | goto ERROR2; |
|
|
2076 | if ((res = psiconv_list_add(*result,&nr))) |
|
|
2077 | goto ERROR2; |
|
|
2078 | len += leng; |
|
|
2079 | } |
|
|
2080 | |
|
|
2081 | if (length) |
|
|
2082 | *length = len; |
|
|
2083 | |
|
|
2084 | psiconv_progress(config,lev,off+len-1, |
|
|
2085 | "End of sheet grid break list (total length: %08x)", len); |
|
|
2086 | return 0; |
|
|
2087 | |
|
|
2088 | ERROR2: |
|
|
2089 | psiconv_list_free(*result); |
|
|
2090 | ERROR1: |
|
|
2091 | psiconv_warn(config,lev+1,off,"Reading of Sheet Grid break List failed"); |
|
|
2092 | if (length) |
|
|
2093 | *length = 0; |
|
|
2094 | if (!res) |
|
|
2095 | return -PSICONV_E_NOMEM; |
|
|
2096 | else |
|
|
2097 | return res; |
|
|
2098 | } |
|
|
2099 | |