… | |
… | |
22 | |
22 | |
23 | #include <stdlib.h> |
23 | #include <stdlib.h> |
24 | |
24 | |
25 | #include "parse_routines.h" |
25 | #include "parse_routines.h" |
26 | #include "error.h" |
26 | #include "error.h" |
|
|
27 | |
|
|
28 | static psiconv_sheet_cell_layout psiconv_basic_cell_layout(void) |
|
|
29 | { |
|
|
30 | psiconv_sheet_cell_layout result; |
|
|
31 | if (!(result = malloc(sizeof(*result)))) |
|
|
32 | goto ERROR1; |
|
|
33 | if (!(result->character = psiconv_basic_character_layout())) |
|
|
34 | goto ERROR2; |
|
|
35 | if (!(result->paragraph = psiconv_basic_paragraph_layout())) |
|
|
36 | goto ERROR3; |
|
|
37 | if (!(result->numberformat = malloc(sizeof(*result->numberformat)))) |
|
|
38 | goto ERROR4; |
|
|
39 | result->numberformat->code = psiconv_numberformat_general; |
|
|
40 | result->numberformat->decimal = 2; |
|
|
41 | return result; |
|
|
42 | ERROR4: |
|
|
43 | psiconv_free_paragraph_layout(result->paragraph); |
|
|
44 | ERROR3: |
|
|
45 | psiconv_free_character_layout(result->character); |
|
|
46 | ERROR2: |
|
|
47 | free(result); |
|
|
48 | ERROR1: |
|
|
49 | return NULL; |
|
|
50 | } |
|
|
51 | |
|
|
52 | static psiconv_sheet_cell_layout psiconv_clone_cell_layout |
|
|
53 | (psiconv_sheet_cell_layout original) |
|
|
54 | { |
|
|
55 | psiconv_sheet_cell_layout result; |
|
|
56 | if (!(result = malloc(sizeof(*result)))) |
|
|
57 | goto ERROR1; |
|
|
58 | if (!(result->character = |
|
|
59 | psiconv_clone_character_layout(original->character))) |
|
|
60 | goto ERROR2; |
|
|
61 | if (!(result->paragraph = |
|
|
62 | psiconv_clone_paragraph_layout(original->paragraph))) |
|
|
63 | goto ERROR3; |
|
|
64 | if (!(result->numberformat = malloc(sizeof(*result->numberformat)))) |
|
|
65 | goto ERROR4; |
|
|
66 | result->numberformat->code = original->numberformat->code; |
|
|
67 | result->numberformat->decimal = original->numberformat->decimal; |
|
|
68 | return result; |
|
|
69 | ERROR4: |
|
|
70 | psiconv_free_paragraph_layout(result->paragraph); |
|
|
71 | ERROR3: |
|
|
72 | psiconv_free_character_layout(result->character); |
|
|
73 | ERROR2: |
|
|
74 | free(result); |
|
|
75 | ERROR1: |
|
|
76 | return NULL; |
|
|
77 | } |
|
|
78 | |
|
|
79 | static psiconv_sheet_cell_reference_t |
|
|
80 | psiconv_read_var_cellref (const psiconv_buffer buf, int lev, |
|
|
81 | psiconv_u32 off, int *length, |
|
|
82 | int *status) |
|
|
83 | { |
|
|
84 | int len=0; |
|
|
85 | int res; |
|
|
86 | psiconv_sheet_cell_reference_t result; |
|
|
87 | psiconv_u32 temp; |
|
|
88 | |
|
|
89 | psiconv_progress(lev+1,off+len,"Going to read a sheet cell reference"); |
|
|
90 | psiconv_progress(lev+2,off+len, |
|
|
91 | "Going to read the initial byte (%02x expected)",0x00); |
|
|
92 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
93 | if (res) |
|
|
94 | goto ERROR1; |
|
|
95 | if (temp != 0x00) { |
|
|
96 | psiconv_warn(lev+2,off+len, |
|
|
97 | "Sheet cell reference initial byte unknown value (ignored)"); |
|
|
98 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
99 | } |
|
|
100 | len ++; |
|
|
101 | |
|
|
102 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
103 | if (res) |
|
|
104 | goto ERROR1; |
|
|
105 | if (temp & 0xffff0000) { |
|
|
106 | psiconv_warn(lev+2,off+len, |
|
|
107 | "Sheet cell row reference to unknown row (reset)"); |
|
|
108 | } |
|
|
109 | result.row.offset = temp; |
|
|
110 | result.row.absolute = psiconv_bool_true; |
|
|
111 | len += 4; |
|
|
112 | |
|
|
113 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
114 | if (res) |
|
|
115 | goto ERROR1; |
|
|
116 | if (temp & 0xffff0000) { |
|
|
117 | psiconv_warn(lev+2,off+len, |
|
|
118 | "Sheet cell column reference to unknown row (reset)"); |
|
|
119 | } |
|
|
120 | result.column.offset = temp; |
|
|
121 | result.column.absolute = psiconv_bool_true; |
|
|
122 | len += 4; |
|
|
123 | |
|
|
124 | if (length) |
|
|
125 | *length = len; |
|
|
126 | |
|
|
127 | psiconv_progress(lev,off+len-1, |
|
|
128 | "End of sheet column reference (total length: %08x)", len); |
|
|
129 | return result; |
|
|
130 | ERROR1: |
|
|
131 | psiconv_warn(lev+1,off,"Reading of Sheet Column Reference failed"); |
|
|
132 | if (length) |
|
|
133 | *length = 0; |
|
|
134 | if (status) |
|
|
135 | *status = res?res:-PSICONV_E_NOMEM; |
|
|
136 | return result; |
|
|
137 | } |
|
|
138 | |
|
|
139 | static psiconv_sheet_cell_block_t |
|
|
140 | psiconv_read_var_cellblock (const psiconv_buffer buf, int lev, |
|
|
141 | psiconv_u32 off, int *length, |
|
|
142 | int *status) |
|
|
143 | { |
|
|
144 | int len=0; |
|
|
145 | int res; |
|
|
146 | psiconv_sheet_cell_block_t result; |
|
|
147 | psiconv_u32 temp; |
|
|
148 | |
|
|
149 | psiconv_progress(lev+1,off+len,"Going to read a sheet cell block reference"); |
|
|
150 | psiconv_progress(lev+2,off+len, |
|
|
151 | "Going to read the initial byte (%02x expected)",0x00); |
|
|
152 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
153 | if (res) |
|
|
154 | goto ERROR1; |
|
|
155 | if (temp != 0x00) { |
|
|
156 | psiconv_warn(lev+2,off+len, |
|
|
157 | "Sheet cell reference initial byte unknown value (ignored)"); |
|
|
158 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
159 | } |
|
|
160 | len ++; |
|
|
161 | |
|
|
162 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
163 | if (res) |
|
|
164 | goto ERROR1; |
|
|
165 | if (temp & 0xffff0000) { |
|
|
166 | psiconv_warn(lev+2,off+len, |
|
|
167 | "Sheet block initial row reference to unknown row (reset)"); |
|
|
168 | } |
|
|
169 | result.first.row.offset = temp; |
|
|
170 | result.first.row.absolute = psiconv_bool_true; |
|
|
171 | len += 4; |
|
|
172 | |
|
|
173 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
174 | if (res) |
|
|
175 | goto ERROR1; |
|
|
176 | if (temp & 0xffff0000) { |
|
|
177 | psiconv_warn(lev+2,off+len, |
|
|
178 | "Sheet block initial column reference to unknown row (reset)"); |
|
|
179 | } |
|
|
180 | result.first.column.offset = temp; |
|
|
181 | result.first.column.absolute = psiconv_bool_true; |
|
|
182 | len += 4; |
|
|
183 | |
|
|
184 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
185 | if (res) |
|
|
186 | goto ERROR1; |
|
|
187 | if (temp & 0xffff0000) { |
|
|
188 | psiconv_warn(lev+2,off+len, |
|
|
189 | "Sheet block final row reference to unknown row (reset)"); |
|
|
190 | } |
|
|
191 | result.last.row.offset = temp; |
|
|
192 | result.last.row.absolute = psiconv_bool_true; |
|
|
193 | len += 4; |
|
|
194 | |
|
|
195 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
196 | if (res) |
|
|
197 | goto ERROR1; |
|
|
198 | if (temp & 0xffff0000) { |
|
|
199 | psiconv_warn(lev+2,off+len, |
|
|
200 | "Sheet block final column reference to unknown row (reset)"); |
|
|
201 | } |
|
|
202 | result.last.column.offset = temp; |
|
|
203 | result.last.column.absolute = psiconv_bool_true; |
|
|
204 | len += 4; |
|
|
205 | |
|
|
206 | if (length) |
|
|
207 | *length = len; |
|
|
208 | |
|
|
209 | psiconv_progress(lev,off+len-1, |
|
|
210 | "End of sheet cell block reference (total length: %08x)", |
|
|
211 | len); |
|
|
212 | return result; |
|
|
213 | ERROR1: |
|
|
214 | psiconv_warn(lev+1,off,"Reading of Sheet Cell Block Reference failed"); |
|
|
215 | if (length) |
|
|
216 | *length = 0; |
|
|
217 | if (status) |
|
|
218 | *status = res?res:-PSICONV_E_NOMEM; |
|
|
219 | return result; |
|
|
220 | } |
|
|
221 | |
|
|
222 | int psiconv_parse_sheet_numberformat(const psiconv_buffer buf, int lev, |
|
|
223 | psiconv_u32 off, int *length, |
|
|
224 | psiconv_sheet_numberformat result) |
|
|
225 | { |
|
|
226 | int res=0; |
|
|
227 | int len=0; |
|
|
228 | psiconv_u8 temp; |
|
|
229 | |
|
|
230 | psiconv_progress(lev+1,off,"Going to read a sheet numberformat"); |
|
|
231 | |
|
|
232 | psiconv_progress(lev+2,off+len, |
|
|
233 | "Going to read the initial byte (%02x expected)",0x02); |
|
|
234 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
235 | if (res) |
|
|
236 | goto ERROR1; |
|
|
237 | if (temp != 0x02) { |
|
|
238 | psiconv_warn(lev+2,off+len, |
|
|
239 | "Sheet numberformat initial byte unknown value (ignored)"); |
|
|
240 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
241 | } |
|
|
242 | len ++; |
|
|
243 | |
|
|
244 | psiconv_progress(lev+2,off+len, "Going to read the code byte"); |
|
|
245 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
246 | if (res) |
|
|
247 | goto ERROR1; |
|
|
248 | psiconv_debug(lev+2,off+len,"Code: %02x",temp); |
|
|
249 | if (temp == 0x00) |
|
|
250 | result->code = psiconv_numberformat_general; |
|
|
251 | else if (temp == 0x02) |
|
|
252 | result->code = psiconv_numberformat_fixeddecimal; |
|
|
253 | else if (temp == 0x04) |
|
|
254 | result->code = psiconv_numberformat_scientific; |
|
|
255 | else if (temp == 0x06) |
|
|
256 | result->code = psiconv_numberformat_currency; |
|
|
257 | else if (temp == 0x08) |
|
|
258 | result->code = psiconv_numberformat_percent; |
|
|
259 | else if (temp == 0x0A) |
|
|
260 | result->code = psiconv_numberformat_triads; |
|
|
261 | else if (temp == 0x0C) |
|
|
262 | result->code = psiconv_numberformat_boolean; |
|
|
263 | else if (temp == 0x0E) |
|
|
264 | result->code = psiconv_numberformat_text; |
|
|
265 | else if (temp == 0x10) |
|
|
266 | result->code = psiconv_numberformat_date_dmm; |
|
|
267 | else if (temp == 0x12) |
|
|
268 | result->code = psiconv_numberformat_date_mmd; |
|
|
269 | else if (temp == 0x14) |
|
|
270 | result->code = psiconv_numberformat_date_ddmmyy; |
|
|
271 | else if (temp == 0x16) |
|
|
272 | result->code = psiconv_numberformat_date_mmddyy; |
|
|
273 | else if (temp == 0x18) |
|
|
274 | result->code = psiconv_numberformat_date_yymmdd; |
|
|
275 | else if (temp == 0x1A) |
|
|
276 | result->code = psiconv_numberformat_date_dmmm; |
|
|
277 | else if (temp == 0x1C) |
|
|
278 | result->code = psiconv_numberformat_date_dmmmyy; |
|
|
279 | else if (temp == 0x1E) |
|
|
280 | result->code = psiconv_numberformat_date_ddmmmyy; |
|
|
281 | else if (temp == 0x20) |
|
|
282 | result->code = psiconv_numberformat_date_mmm; |
|
|
283 | else if (temp == 0x22) |
|
|
284 | result->code = psiconv_numberformat_date_monthname; |
|
|
285 | else if (temp == 0x24) |
|
|
286 | result->code = psiconv_numberformat_date_mmmyy; |
|
|
287 | else if (temp == 0x26) |
|
|
288 | result->code = psiconv_numberformat_date_monthnameyy; |
|
|
289 | else if (temp == 0x28) |
|
|
290 | result->code = psiconv_numberformat_date_monthnamedyyyy; |
|
|
291 | else if (temp == 0x2A) |
|
|
292 | result->code = psiconv_numberformat_datetime_ddmmyyyyhhii; |
|
|
293 | else if (temp == 0x2C) |
|
|
294 | result->code = psiconv_numberformat_datetime_ddmmyyyyHHii; |
|
|
295 | else if (temp == 0x2E) |
|
|
296 | result->code = psiconv_numberformat_datetime_mmddyyyyhhii; |
|
|
297 | else if (temp == 0x30) |
|
|
298 | result->code = psiconv_numberformat_datetime_mmddyyyyHHii; |
|
|
299 | else if (temp == 0x32) |
|
|
300 | result->code = psiconv_numberformat_datetime_yyyymmddhhii; |
|
|
301 | else if (temp == 0x34) |
|
|
302 | result->code = psiconv_numberformat_datetime_yyyymmddHHii; |
|
|
303 | else if (temp == 0x36) |
|
|
304 | result->code = psiconv_numberformat_time_hhii; |
|
|
305 | else if (temp == 0x38) |
|
|
306 | result->code = psiconv_numberformat_time_hhiiss; |
|
|
307 | else if (temp == 0x3A) |
|
|
308 | result->code = psiconv_numberformat_time_HHii; |
|
|
309 | else if (temp == 0x3C) |
|
|
310 | result->code = psiconv_numberformat_time_HHiiss; |
|
|
311 | else { |
|
|
312 | psiconv_warn(lev+2,off+len,"Unknown number format (assumed general)"); |
|
|
313 | result->code = psiconv_numberformat_general; |
|
|
314 | } |
|
|
315 | len ++; |
|
|
316 | |
|
|
317 | psiconv_progress(lev+2,off+len, "Going to read the number of decimals"); |
|
|
318 | result->decimal = psiconv_read_u8(buf,lev+2,off+len,&res) >> 1; |
|
|
319 | if (res) |
|
|
320 | goto ERROR1; |
|
|
321 | psiconv_debug(lev+2,off+len,"Decimals: %d",result->decimal); |
|
|
322 | len ++; |
|
|
323 | |
|
|
324 | if (length) |
|
|
325 | *length = len; |
|
|
326 | |
|
|
327 | psiconv_progress(lev,off+len-1, |
|
|
328 | "End of sheet number format (total length: %08x)", len); |
|
|
329 | return 0; |
|
|
330 | |
|
|
331 | ERROR1: |
|
|
332 | psiconv_warn(lev+1,off,"Reading of Sheet Number Format failed"); |
|
|
333 | if (length) |
|
|
334 | *length = 0; |
|
|
335 | if (!res) |
|
|
336 | return -PSICONV_E_NOMEM; |
|
|
337 | else |
|
|
338 | return res; |
|
|
339 | } |
27 | |
340 | |
28 | int psiconv_parse_sheet_status_section(const psiconv_buffer buf, int lev, |
341 | int psiconv_parse_sheet_status_section(const psiconv_buffer buf, int lev, |
29 | psiconv_u32 off, int *length, |
342 | psiconv_u32 off, int *length, |
30 | psiconv_sheet_status_section *result) |
343 | psiconv_sheet_status_section *result) |
31 | { |
344 | { |
… | |
… | |
141 | if (res) |
454 | if (res) |
142 | goto ERROR2; |
455 | goto ERROR2; |
143 | if (temp != 0x00) { |
456 | if (temp != 0x00) { |
144 | psiconv_warn(lev+2,off+len, |
457 | psiconv_warn(lev+2,off+len, |
145 | "Sheet status section unknown byte unknown value (ignored)"); |
458 | "Sheet status section unknown byte unknown value (ignored)"); |
146 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
459 | psiconv_debug(lev+2,off+len,"Unknown byte: %02x",temp); |
147 | } |
460 | } |
148 | len ++; |
461 | len ++; |
149 | |
462 | |
150 | psiconv_progress(lev+2,off+len,"Going to read sheet display size"); |
463 | psiconv_progress(lev+2,off+len,"Going to read sheet display size"); |
151 | (*result)->sheet_display_size = psiconv_read_u32(buf,lev+2,off + len,&res); |
464 | (*result)->sheet_display_size = psiconv_read_u32(buf,lev+2,off + len,&res); |
… | |
… | |
171 | return 0; |
484 | return 0; |
172 | |
485 | |
173 | ERROR2: |
486 | ERROR2: |
174 | free (*result); |
487 | free (*result); |
175 | ERROR1: |
488 | ERROR1: |
176 | psiconv_warn(lev+1,off,"Reading of Sjeet Status Section failed"); |
489 | psiconv_warn(lev+1,off,"Reading of Sheet Status Section failed"); |
177 | if (length) |
490 | if (length) |
178 | *length = 0; |
491 | *length = 0; |
179 | if (!res) |
492 | if (!res) |
180 | return -PSICONV_E_NOMEM; |
493 | return -PSICONV_E_NOMEM; |
181 | else |
494 | else |
182 | return res; |
495 | return res; |
183 | } |
496 | } |
184 | |
497 | |
|
|
498 | int psiconv_parse_sheet_workbook_section(const psiconv_buffer buf, int lev, |
|
|
499 | psiconv_u32 off, int *length, |
|
|
500 | psiconv_sheet_workbook_section *result) |
|
|
501 | { |
|
|
502 | int res=0,with_name; |
|
|
503 | psiconv_u32 temp,formulas_off,worksheets_off,info_off,var_off,name_off=0; |
|
|
504 | int len=0; |
|
|
505 | |
|
|
506 | psiconv_progress(lev+1,off,"Going to read the sheet workbook section"); |
|
|
507 | if (!(*result = malloc(sizeof(**result)))) |
|
|
508 | goto ERROR1; |
|
|
509 | |
|
|
510 | psiconv_progress(lev+2,off+len, |
|
|
511 | "Going to read the initial byte (%02x or %02x expected)", |
|
|
512 | 0x02,0x04); |
|
|
513 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
514 | if (res) |
|
|
515 | goto ERROR2; |
|
|
516 | if ((temp != 0x04) && temp !=0x02) { |
|
|
517 | psiconv_warn(lev+2,off+len, |
|
|
518 | "Sheet workbook section initial byte unknown value (ignored)"); |
|
|
519 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
520 | } |
|
|
521 | with_name = temp ==0x04; |
|
|
522 | len ++; |
|
|
523 | |
|
|
524 | psiconv_progress(lev+2,off+len, |
|
|
525 | "Going to read the offset of the sheet info Section"); |
|
|
526 | info_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
527 | if (res) |
|
|
528 | goto ERROR2; |
|
|
529 | psiconv_debug(lev+2,off+len,"Offset: %04x",info_off); |
|
|
530 | len += 4; |
|
|
531 | |
|
|
532 | psiconv_progress(lev+2,off+len, |
|
|
533 | "Going to read the offset of the Formulas List"); |
|
|
534 | formulas_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
535 | if (res) |
|
|
536 | goto ERROR2; |
|
|
537 | psiconv_debug(lev+2,off+len,"Offset: %04x",formulas_off); |
|
|
538 | len += 4; |
|
|
539 | |
|
|
540 | psiconv_progress(lev+2,off+len, |
|
|
541 | "Going to read the offset of the Worksheet List"); |
|
|
542 | worksheets_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
543 | if (res) |
|
|
544 | goto ERROR2; |
|
|
545 | psiconv_debug(lev+2,off+len,"Offset: %04x",worksheets_off); |
|
|
546 | len += 4; |
|
|
547 | |
|
|
548 | psiconv_progress(lev+2,off+len, |
|
|
549 | "Going to read the offset of the Variable List"); |
|
|
550 | var_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
551 | if (res) |
|
|
552 | goto ERROR2; |
|
|
553 | psiconv_debug(lev+2,off+len,"Offset: %04x",var_off); |
|
|
554 | len += 4; |
|
|
555 | |
|
|
556 | if (with_name) { |
|
|
557 | psiconv_progress(lev+2,off+len, |
|
|
558 | "Going to read the offset of the Name Section"); |
|
|
559 | name_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
560 | if (res) |
|
|
561 | goto ERROR2; |
|
|
562 | psiconv_debug(lev+2,off+len,"Offset: %04x",name_off); |
|
|
563 | len += 4; |
|
|
564 | } |
|
|
565 | |
|
|
566 | |
|
|
567 | psiconv_progress(lev+2,off+len,"Going to read the info section"); |
|
|
568 | if ((res = psiconv_parse_sheet_info_section(buf,lev+2,info_off,NULL, |
|
|
569 | &(*result)->info))) |
|
|
570 | goto ERROR2; |
|
|
571 | |
|
|
572 | psiconv_progress(lev+2,off+len,"Going to read the variables list"); |
|
|
573 | if ((res = psiconv_parse_sheet_variable_list(buf,lev+2,var_off,NULL, |
|
|
574 | &(*result)->variables))) |
|
|
575 | goto ERROR3; |
|
|
576 | |
|
|
577 | psiconv_progress(lev+2,off+len,"Going to read the formulas list"); |
|
|
578 | if ((res = psiconv_parse_sheet_formula_list(buf,lev+2,formulas_off,NULL, |
|
|
579 | &(*result)->formulas))) |
|
|
580 | goto ERROR4; |
|
|
581 | |
|
|
582 | psiconv_progress(lev+2,off+len,"Going to read the worksheet list"); |
|
|
583 | if ((res = psiconv_parse_sheet_worksheet_list(buf,lev+2,worksheets_off, |
|
|
584 | NULL,&(*result)->worksheets))) |
|
|
585 | goto ERROR5; |
|
|
586 | |
|
|
587 | if (with_name) { |
|
|
588 | psiconv_progress(lev+2,off+len,"Going to read the name section"); |
|
|
589 | if ((res = psiconv_parse_sheet_name_section(buf,lev+2,name_off,NULL, |
|
|
590 | &(*result)->name))) |
|
|
591 | goto ERROR6; |
|
|
592 | } else |
|
|
593 | (*result)->name = NULL; |
|
|
594 | |
|
|
595 | if (length) |
|
|
596 | *length = len; |
|
|
597 | |
|
|
598 | psiconv_progress(lev,off+len-1, |
|
|
599 | "End of sheet workbook section (total length: %08x)", len); |
|
|
600 | return 0; |
|
|
601 | |
|
|
602 | ERROR6: |
|
|
603 | psiconv_free_sheet_worksheet_list((*result)->worksheets); |
|
|
604 | ERROR5: |
|
|
605 | psiconv_free_formula_list((*result)->formulas); |
|
|
606 | ERROR4: |
|
|
607 | psiconv_free_sheet_variable_list((*result)->variables); |
|
|
608 | ERROR3: |
|
|
609 | psiconv_free_sheet_info_section((*result)->info); |
|
|
610 | ERROR2: |
|
|
611 | free (*result); |
|
|
612 | ERROR1: |
|
|
613 | psiconv_warn(lev+1,off,"Reading of Sheet Workbook Section failed"); |
|
|
614 | if (length) |
|
|
615 | *length = 0; |
|
|
616 | if (!res) |
|
|
617 | return -PSICONV_E_NOMEM; |
|
|
618 | else |
|
|
619 | return res; |
|
|
620 | } |
|
|
621 | |
|
|
622 | int psiconv_parse_sheet_name_section(const psiconv_buffer buf, int lev, |
|
|
623 | psiconv_u32 off, int *length, |
|
|
624 | psiconv_sheet_name_section *result) |
|
|
625 | { |
|
|
626 | int res=0; |
|
|
627 | psiconv_u32 temp; |
|
|
628 | int len=0,leng; |
|
|
629 | |
|
|
630 | psiconv_progress(lev+1,off,"Going to read the sheet name section"); |
|
|
631 | if (!(*result = malloc(sizeof(**result)))) |
|
|
632 | goto ERROR1; |
|
|
633 | |
|
|
634 | psiconv_progress(lev+2,off+len, |
|
|
635 | "Going to read the initial byte (%02x expected)",0x02); |
|
|
636 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
637 | if (res) |
|
|
638 | goto ERROR2; |
|
|
639 | if (temp != 0x02) { |
|
|
640 | psiconv_warn(lev+2,off+len, |
|
|
641 | "Sheet name section initial byte unknown value (ignored)"); |
|
|
642 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
643 | } |
|
|
644 | len ++; |
|
|
645 | |
|
|
646 | psiconv_progress(lev+2,off+len, "Going to read the sheet name"); |
|
|
647 | (*result)->name = psiconv_read_string(buf,lev+2,off+len,&leng,&res); |
|
|
648 | if (res) |
|
|
649 | goto ERROR2; |
|
|
650 | len += leng; |
|
|
651 | |
|
|
652 | if (length) |
|
|
653 | *length = len; |
|
|
654 | |
|
|
655 | psiconv_progress(lev,off+len-1, |
|
|
656 | "End of sheet name section (total length: %08x)", len); |
|
|
657 | return 0; |
|
|
658 | |
|
|
659 | ERROR2: |
|
|
660 | free(*result); |
|
|
661 | ERROR1: |
|
|
662 | psiconv_warn(lev+1,off,"Reading of Sheet Name Section failed"); |
|
|
663 | if (length) |
|
|
664 | *length = 0; |
|
|
665 | if (!res) |
|
|
666 | return -PSICONV_E_NOMEM; |
|
|
667 | else |
|
|
668 | return res; |
|
|
669 | } |
|
|
670 | |
|
|
671 | int psiconv_parse_sheet_info_section(const psiconv_buffer buf, int lev, |
|
|
672 | psiconv_u32 off, int *length, |
|
|
673 | psiconv_sheet_info_section *result) |
|
|
674 | { |
|
|
675 | int res=0; |
|
|
676 | psiconv_u32 temp; |
|
|
677 | int len=0,leng; |
|
|
678 | |
|
|
679 | psiconv_progress(lev+1,off,"Going to read the sheet info section"); |
|
|
680 | if (!(*result = malloc(sizeof(**result)))) |
|
|
681 | goto ERROR1; |
|
|
682 | |
|
|
683 | psiconv_progress(lev+2,off+len, |
|
|
684 | "Going to read the initial byte (%02x expected)",0x02); |
|
|
685 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
686 | if (res) |
|
|
687 | goto ERROR2; |
|
|
688 | if (temp != 0x02) { |
|
|
689 | psiconv_warn(lev+2,off+len, |
|
|
690 | "Sheet info section initial byte unknown value (ignored)"); |
|
|
691 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
692 | } |
|
|
693 | len ++; |
|
|
694 | |
|
|
695 | psiconv_progress(lev+2,off+len, "Going to read an unknown Xint"); |
|
|
696 | temp = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
|
|
697 | if (res) |
|
|
698 | goto ERROR2; |
|
|
699 | psiconv_debug(lev+2,off+len,"Value: %d\n",temp); |
|
|
700 | len += leng; |
|
|
701 | |
|
|
702 | psiconv_progress(lev+2,off+len, "Going to read the flags byte"); |
|
|
703 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
704 | if (res) |
|
|
705 | goto ERROR2; |
|
|
706 | (*result)->auto_recalc = temp & 0x01 ? psiconv_bool_true:psiconv_bool_false; |
|
|
707 | psiconv_debug(lev+2,off+len,"Auto recalculation: %02x", |
|
|
708 | (*result)->auto_recalc); |
|
|
709 | if ((temp & 0xfe) != 0x02) { |
|
|
710 | psiconv_warn(lev+2,off+len,"Sheet Info Section flags byte " |
|
|
711 | "contains unknown flags (ignored)"); |
|
|
712 | psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp &0xfe); |
|
|
713 | } |
|
|
714 | |
|
|
715 | len ++; |
|
|
716 | |
|
|
717 | |
|
|
718 | if (length) |
|
|
719 | *length = len; |
|
|
720 | |
|
|
721 | psiconv_progress(lev,off+len-1, |
|
|
722 | "End of sheet info section (total length: %08x)", len); |
|
|
723 | return 0; |
|
|
724 | |
|
|
725 | ERROR2: |
|
|
726 | free(*result); |
|
|
727 | ERROR1: |
|
|
728 | psiconv_warn(lev+1,off,"Reading of Sheet Name Section failed"); |
|
|
729 | if (length) |
|
|
730 | *length = 0; |
|
|
731 | if (!res) |
|
|
732 | return -PSICONV_E_NOMEM; |
|
|
733 | else |
|
|
734 | return res; |
|
|
735 | } |
|
|
736 | |
|
|
737 | int psiconv_parse_sheet_formula_list(const psiconv_buffer buf, int lev, |
|
|
738 | psiconv_u32 off, int *length, |
|
|
739 | psiconv_formula_list *result) |
|
|
740 | { |
|
|
741 | int res=0; |
|
|
742 | int len=0; |
|
|
743 | psiconv_u32 temp; |
|
|
744 | psiconv_formula formula; |
|
|
745 | psiconv_u32 listlen,i; |
|
|
746 | int leng; |
|
|
747 | |
|
|
748 | psiconv_progress(lev+1,off,"Going to read the sheet formula list"); |
|
|
749 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_formula_s)))) |
|
|
750 | goto ERROR1; |
|
|
751 | |
|
|
752 | psiconv_progress(lev+2,off+len, |
|
|
753 | "Going to read the initial byte (%02x expected)",0x02); |
|
|
754 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
755 | if (res) |
|
|
756 | goto ERROR2; |
|
|
757 | if (temp != 0x02) { |
|
|
758 | psiconv_warn(lev+2,off+len, |
|
|
759 | "Sheet formula list initial byte unknown value (ignored)"); |
|
|
760 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
761 | } |
|
|
762 | len ++; |
|
|
763 | |
|
|
764 | psiconv_progress(lev+2,off+len, |
|
|
765 | "Going to read the number of formulas"); |
|
|
766 | listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
|
|
767 | if (res) |
|
|
768 | goto ERROR2; |
|
|
769 | psiconv_debug(lev+2,off+len,"Number of formulas: %d",listlen); |
|
|
770 | len += leng; |
|
|
771 | |
|
|
772 | psiconv_progress(lev+2,off+len,"Going to read all formulas"); |
|
|
773 | for (i = 0; i < listlen; i++) { |
|
|
774 | psiconv_progress(lev+3,off+len,"Going to read formula %d",i); |
|
|
775 | if ((res = psiconv_parse_formula(buf,lev+3,off+len,&leng,&formula))) |
|
|
776 | goto ERROR2; |
|
|
777 | if ((res = psiconv_list_add(*result,formula))) |
|
|
778 | goto ERROR3; |
|
|
779 | len += leng; |
|
|
780 | } |
|
|
781 | |
|
|
782 | if (length) |
|
|
783 | *length = len; |
|
|
784 | |
|
|
785 | psiconv_progress(lev,off+len-1, |
|
|
786 | "End of sheet formula list (total length: %08x)", len); |
|
|
787 | return 0; |
|
|
788 | |
|
|
789 | ERROR3: |
|
|
790 | psiconv_free_formula(formula); |
|
|
791 | ERROR2: |
|
|
792 | psiconv_list_free(*result); |
|
|
793 | ERROR1: |
|
|
794 | psiconv_warn(lev+1,off,"Reading of Sheet Formula list failed"); |
|
|
795 | if (length) |
|
|
796 | *length = 0; |
|
|
797 | if (!res) |
|
|
798 | return -PSICONV_E_NOMEM; |
|
|
799 | else |
|
|
800 | return res; |
|
|
801 | } |
|
|
802 | |
|
|
803 | int psiconv_parse_sheet_cell(const psiconv_buffer buf, int lev, |
|
|
804 | psiconv_u32 off, int *length, |
|
|
805 | psiconv_sheet_cell *result, |
|
|
806 | const psiconv_sheet_cell_layout default_layout, |
|
|
807 | const psiconv_sheet_line_list row_default_layouts, |
|
|
808 | const psiconv_sheet_line_list col_default_layouts) |
|
|
809 | { |
|
|
810 | int res=0; |
|
|
811 | int len=0; |
|
|
812 | psiconv_u32 temp; |
|
|
813 | psiconv_bool_t has_layout; |
|
|
814 | int leng; |
|
|
815 | |
|
|
816 | psiconv_progress(lev+1,off,"Going to read a sheet cell structure"); |
|
|
817 | if (!(*result = malloc(sizeof(**result)))) |
|
|
818 | goto ERROR1; |
|
|
819 | |
|
|
820 | (*result)->layout = NULL; |
|
|
821 | (*result)->type = psiconv_cell_blank; |
|
|
822 | |
|
|
823 | psiconv_progress(lev+2,off+len,"Going to read the cell position"); |
|
|
824 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
825 | if (res) |
|
|
826 | goto ERROR2; |
|
|
827 | len ++; |
|
|
828 | temp += psiconv_read_u8(buf,lev+2,off+len,&res) << 8; |
|
|
829 | if (res) |
|
|
830 | goto ERROR2; |
|
|
831 | len ++; |
|
|
832 | temp += psiconv_read_u8(buf,lev+2,off+len,&res) << 16; |
|
|
833 | if (res) |
|
|
834 | goto ERROR2; |
|
|
835 | len ++; |
|
|
836 | (*result)->column = (temp >> 2) & 0xFF; |
|
|
837 | (*result)->row = (temp >> 10) & 0x3FFF; |
|
|
838 | psiconv_debug(lev+2,off+len,"Cell position is col:%02x row:%04x", |
|
|
839 | (*result)->column,(*result)->row); |
|
|
840 | if (temp & 0x03) { |
|
|
841 | psiconv_warn(lev+2,off+len,"Unknown flags in cell position (ignored)"); |
|
|
842 | psiconv_debug(lev+2,off+len,"Flags: %02x",temp & 0x03); |
|
|
843 | } |
|
|
844 | |
|
|
845 | psiconv_progress(lev+2,off+len,"Going to read the cell type"); |
|
|
846 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
847 | if (res) |
|
|
848 | goto ERROR2; |
|
|
849 | len ++; |
|
|
850 | (*result)->type = (temp >> 5) & 0x07; |
|
|
851 | (*result)->calculated = (temp & 0x08)?psiconv_bool_true:psiconv_bool_false; |
|
|
852 | has_layout = (temp & 0x10)?psiconv_bool_true:psiconv_bool_false; |
|
|
853 | |
|
|
854 | psiconv_progress(lev+2,off+len,"Going to read the cell value"); |
|
|
855 | if ((*result)->type == psiconv_cell_blank) { |
|
|
856 | psiconv_debug(lev+2,off+len,"Cell type is blank: no value given."); |
|
|
857 | } else if ((*result)->type == psiconv_cell_int) { |
|
|
858 | psiconv_progress(lev+2,off+len,"Going to read an integer"); |
|
|
859 | (*result)->data.dat_int = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
860 | if (res) |
|
|
861 | goto ERROR2; |
|
|
862 | len += 4; |
|
|
863 | psiconv_debug(lev+2,off+len,"Cell contents: %ld",(*result)->data.dat_int); |
|
|
864 | |
|
|
865 | } else if ((*result)->type == psiconv_cell_bool) { |
|
|
866 | psiconv_progress(lev+2,off+len,"Going to read a boolean"); |
|
|
867 | if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng, |
|
|
868 | &(*result)->data.dat_bool))) |
|
|
869 | goto ERROR2; |
|
|
870 | psiconv_debug(lev+2,off+len,"Cell contents: %01x",temp); |
|
|
871 | (*result)->data.dat_bool = temp?psiconv_bool_true:psiconv_bool_false; |
|
|
872 | len += leng; |
|
|
873 | } else if ((*result)->type == psiconv_cell_error) { |
|
|
874 | psiconv_progress(lev+2,off+len,"Going to read the error code"); |
|
|
875 | temp = psiconv_read_u16(buf,lev+2,off+len,&res); |
|
|
876 | if (res) |
|
|
877 | goto ERROR2; |
|
|
878 | if (temp == 0) |
|
|
879 | (*result)->data.dat_error = psiconv_sheet_error_none; |
|
|
880 | else if (temp == 1) |
|
|
881 | (*result)->data.dat_error = psiconv_sheet_error_null; |
|
|
882 | else if (temp == 2) |
|
|
883 | (*result)->data.dat_error = psiconv_sheet_error_divzero; |
|
|
884 | else if (temp == 3) |
|
|
885 | (*result)->data.dat_error = psiconv_sheet_error_value; |
|
|
886 | else if (temp == 4) |
|
|
887 | (*result)->data.dat_error = psiconv_sheet_error_reference; |
|
|
888 | else if (temp == 5) |
|
|
889 | (*result)->data.dat_error = psiconv_sheet_error_name; |
|
|
890 | else if (temp == 6) |
|
|
891 | (*result)->data.dat_error = psiconv_sheet_error_number; |
|
|
892 | else if (temp == 7) |
|
|
893 | (*result)->data.dat_error = psiconv_sheet_error_notavail; |
|
|
894 | else { |
|
|
895 | psiconv_warn(lev+2,off+len,"Unknown error code (default assumed)"); |
|
|
896 | psiconv_debug(lev+2,off+len,"Error code: %04x",temp); |
|
|
897 | (*result)->data.dat_error = psiconv_sheet_error_none; |
|
|
898 | } |
|
|
899 | psiconv_debug(lev+2,off+len,"Cell contents: %04x", |
|
|
900 | (*result)->data.dat_error); |
|
|
901 | len += 2; |
|
|
902 | } else if ((*result)->type == psiconv_cell_float) { |
|
|
903 | psiconv_progress(lev+2,off+len,"Going to read a float"); |
|
|
904 | (*result)->data.dat_float = |
|
|
905 | psiconv_read_float(buf,lev+2,off+len,&leng,&res); |
|
|
906 | if (res) |
|
|
907 | goto ERROR2; |
|
|
908 | psiconv_debug(lev+2,off+len,"Cell contents: %f",(*result)->data.dat_float); |
|
|
909 | len += leng; |
|
|
910 | } else if ((*result)->type == psiconv_cell_string) { |
|
|
911 | psiconv_progress(lev+2,off+len,"Going to read a string"); |
|
|
912 | (*result)->data.dat_string = |
|
|
913 | psiconv_read_string(buf,lev+2,off+len,&leng,&res); |
|
|
914 | if (res) |
|
|
915 | goto ERROR2; |
|
|
916 | psiconv_debug(lev+2,off+len,"Cell contents: `%s'", |
|
|
917 | (*result)->data.dat_string); |
|
|
918 | len += leng; |
|
|
919 | } else { |
|
|
920 | psiconv_warn(lev+2,off+len,"Unknown Sheet Cell type: %02x",(*result)->type); |
|
|
921 | res = PSICONV_E_PARSE; |
|
|
922 | goto ERROR2; |
|
|
923 | } |
|
|
924 | |
|
|
925 | if (!((*result)->layout = psiconv_clone_cell_layout( |
|
|
926 | psiconv_get_default_layout(row_default_layouts, |
|
|
927 | col_default_layouts, |
|
|
928 | default_layout, |
|
|
929 | (*result)->row, |
|
|
930 | (*result)->column)))) |
|
|
931 | goto ERROR2; |
|
|
932 | if (has_layout) { |
|
|
933 | if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len, |
|
|
934 | &leng,(*result)->layout))) |
|
|
935 | goto ERROR2; |
|
|
936 | len += leng; |
|
|
937 | } |
|
|
938 | |
|
|
939 | if ((*result)->calculated) { |
|
|
940 | psiconv_progress(lev+2,off+len,"Going to read the cell formula reference"); |
|
|
941 | temp = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
|
|
942 | if (res) |
|
|
943 | goto ERROR2; |
|
|
944 | psiconv_debug(lev+2,off+len,"Cell formula reference: %d",temp); |
|
|
945 | len += leng; |
|
|
946 | (*result)->ref_formula = temp; |
|
|
947 | } |
|
|
948 | |
|
|
949 | if (length) |
|
|
950 | *length = len; |
|
|
951 | |
|
|
952 | psiconv_progress(lev,off+len-1, |
|
|
953 | "End of sheet cell structure (total length: %08x)", len); |
|
|
954 | return 0; |
|
|
955 | |
|
|
956 | ERROR2: |
|
|
957 | psiconv_free_sheet_cell(*result); |
|
|
958 | ERROR1: |
|
|
959 | psiconv_warn(lev+1,off,"Reading of Sheet Cell Structure failed"); |
|
|
960 | if (length) |
|
|
961 | *length = 0; |
|
|
962 | if (!res) |
|
|
963 | return -PSICONV_E_NOMEM; |
|
|
964 | else |
|
|
965 | return res; |
|
|
966 | } |
|
|
967 | |
|
|
968 | int psiconv_parse_sheet_cell_list(const psiconv_buffer buf, int lev, |
|
|
969 | psiconv_u32 off, int *length, |
|
|
970 | psiconv_sheet_cell_list *result, |
|
|
971 | const psiconv_sheet_cell_layout default_layout, |
|
|
972 | const psiconv_sheet_line_list row_default_layouts, |
|
|
973 | const psiconv_sheet_line_list col_default_layouts) |
|
|
974 | { |
|
|
975 | int res=0; |
|
|
976 | int len=0; |
|
|
977 | psiconv_u32 temp; |
|
|
978 | psiconv_sheet_cell cell; |
|
|
979 | psiconv_u32 listlen,i; |
|
|
980 | int leng; |
|
|
981 | |
|
|
982 | psiconv_progress(lev+1,off,"Going to read the sheet cell list"); |
|
|
983 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_cell_s)))) |
|
|
984 | goto ERROR1; |
|
|
985 | |
|
|
986 | psiconv_progress(lev+2,off+len, |
|
|
987 | "Going to read the initial byte (%02x expected)",0x02); |
|
|
988 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
989 | if (res) |
|
|
990 | goto ERROR2; |
|
|
991 | if (temp != 0x02) { |
|
|
992 | psiconv_warn(lev+2,off+len, |
|
|
993 | "Sheet cell list initial byte unknown value (ignored)"); |
|
|
994 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
995 | } |
|
|
996 | len ++; |
|
|
997 | |
|
|
998 | psiconv_progress(lev+2,off+len, |
|
|
999 | "Going to read the initial byte (%02x expected)",0x00); |
|
|
1000 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
1001 | if (res) |
|
|
1002 | goto ERROR2; |
|
|
1003 | if (temp != 0x00) { |
|
|
1004 | psiconv_warn(lev+2,off+len, |
|
|
1005 | "Sheet cell list initial byte unknown value (ignored)"); |
|
|
1006 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
1007 | } |
|
|
1008 | len ++; |
|
|
1009 | |
|
|
1010 | psiconv_progress(lev+2,off+len, |
|
|
1011 | "Going to read the number of defined cells"); |
|
|
1012 | listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
|
|
1013 | if (res) |
|
|
1014 | goto ERROR2; |
|
|
1015 | psiconv_debug(lev+2,off+len,"Number of defined cells: %d",listlen); |
|
|
1016 | len += leng; |
|
|
1017 | |
|
|
1018 | psiconv_progress(lev+2,off+len,"Going to read all cells"); |
|
|
1019 | for (i = 0; i < listlen; i++) { |
|
|
1020 | psiconv_progress(lev+3,off+len,"Going to read cell %d",i); |
|
|
1021 | if ((res = psiconv_parse_sheet_cell(buf,lev+3,off+len,&leng,&cell, |
|
|
1022 | default_layout,row_default_layouts, |
|
|
1023 | col_default_layouts))) |
|
|
1024 | goto ERROR2; |
|
|
1025 | if ((res = psiconv_list_add(*result,cell))) |
|
|
1026 | goto ERROR3; |
|
|
1027 | free(cell); |
|
|
1028 | len += leng; |
|
|
1029 | } |
|
|
1030 | |
|
|
1031 | if (length) |
|
|
1032 | *length = len; |
|
|
1033 | |
|
|
1034 | psiconv_progress(lev,off+len-1, |
|
|
1035 | "End of sheet cell list (total length: %08x)", len); |
|
|
1036 | return 0; |
|
|
1037 | |
|
|
1038 | ERROR3: |
|
|
1039 | psiconv_free_sheet_cell(cell); |
|
|
1040 | ERROR2: |
|
|
1041 | psiconv_free_sheet_cell_list(*result); |
|
|
1042 | ERROR1: |
|
|
1043 | psiconv_warn(lev+1,off,"Reading of Sheet Cells List failed"); |
|
|
1044 | if (length) |
|
|
1045 | *length = 0; |
|
|
1046 | if (!res) |
|
|
1047 | return -PSICONV_E_NOMEM; |
|
|
1048 | else |
|
|
1049 | return res; |
|
|
1050 | } |
|
|
1051 | |
|
|
1052 | |
|
|
1053 | int psiconv_parse_sheet_worksheet_list( const psiconv_buffer buf, int lev, |
|
|
1054 | psiconv_u32 off, int *length, |
|
|
1055 | psiconv_sheet_worksheet_list *result) |
|
|
1056 | { |
|
|
1057 | psiconv_sheet_worksheet worksheet; |
|
|
1058 | int res=0; |
|
|
1059 | int len=0; |
|
|
1060 | psiconv_u8 temp; |
|
|
1061 | psiconv_u32 offset; |
|
|
1062 | int leng,i,nr; |
|
|
1063 | |
|
|
1064 | psiconv_progress(lev+1,off,"Going to read the worksheet list"); |
|
|
1065 | if (!(*result = psiconv_list_new(sizeof(*worksheet)))) |
|
|
1066 | goto ERROR1; |
|
|
1067 | |
|
|
1068 | psiconv_progress(lev+2,off+len, |
|
|
1069 | "Going to read the initial bytes (%02x expected)",0x02); |
|
|
1070 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
1071 | if (res) |
|
|
1072 | goto ERROR2; |
|
|
1073 | if (temp != 0x02) { |
|
|
1074 | psiconv_warn(lev+2,off+len, |
|
|
1075 | "Sheet worksheet list initial byte unknown value (ignored)"); |
|
|
1076 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
1077 | } |
|
|
1078 | len ++; |
|
|
1079 | |
|
|
1080 | psiconv_progress(lev+2,off+len,"Going to read the list length"); |
|
|
1081 | nr = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
|
|
1082 | if (res) |
|
|
1083 | goto ERROR2; |
|
|
1084 | psiconv_debug(lev+2,off+len,"Length: %02x",nr); |
|
|
1085 | len += leng; |
|
|
1086 | |
|
|
1087 | psiconv_progress(lev+2,off+len,"Going to read the list"); |
|
|
1088 | for (i=0 ; i < nr; i++) { |
|
|
1089 | psiconv_progress(lev+3,off+len,"Going to read element %d",i); |
|
|
1090 | psiconv_progress(lev+4,off+len, |
|
|
1091 | "Going to read the initial byte (%02x expected)",0x00); |
|
|
1092 | temp = psiconv_read_u8(buf,lev+4,off+len,&res); |
|
|
1093 | if (res) |
|
|
1094 | goto ERROR2; |
|
|
1095 | if (temp != 0x00) { |
|
|
1096 | psiconv_warn(lev+4,off+len, |
|
|
1097 | "Sheet worksheet element initial byte unknown value (ignored)"); |
|
|
1098 | psiconv_debug(lev+4,off+len,"Initial byte: %02x",temp); |
|
|
1099 | } |
|
|
1100 | len ++; |
|
|
1101 | |
|
|
1102 | psiconv_progress(lev+4,off+len,"Going to read the worksheet offset"); |
|
|
1103 | offset = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
1104 | if (res) |
|
|
1105 | goto ERROR2; |
|
|
1106 | psiconv_debug(lev+4,off+len,"Offset: %08x",offset); |
|
|
1107 | len += 4; |
|
|
1108 | |
|
|
1109 | if ((res = psiconv_parse_sheet_worksheet(buf,lev+4,offset,NULL, |
|
|
1110 | &worksheet))) |
|
|
1111 | goto ERROR2; |
|
|
1112 | if ((res = psiconv_list_add(*result,worksheet))) |
|
|
1113 | goto ERROR3; |
|
|
1114 | free(worksheet); |
|
|
1115 | } |
|
|
1116 | |
|
|
1117 | if (length) |
|
|
1118 | *length = len; |
|
|
1119 | |
|
|
1120 | psiconv_progress(lev,off+len-1, |
|
|
1121 | "End of worksheet list (total length: %08x)", len); |
|
|
1122 | |
|
|
1123 | return 0; |
|
|
1124 | |
|
|
1125 | ERROR3: |
|
|
1126 | psiconv_free_sheet_worksheet(worksheet); |
|
|
1127 | ERROR2: |
|
|
1128 | psiconv_free_sheet_worksheet_list(*result); |
|
|
1129 | ERROR1: |
|
|
1130 | psiconv_warn(lev+1,off,"Reading of worksheet list failed"); |
|
|
1131 | if (length) |
|
|
1132 | *length = 0; |
|
|
1133 | if (!res) |
|
|
1134 | return -PSICONV_E_NOMEM; |
|
|
1135 | else |
|
|
1136 | return res; |
|
|
1137 | } |
|
|
1138 | |
|
|
1139 | int psiconv_parse_sheet_cell_layout(const psiconv_buffer buf, int lev, |
|
|
1140 | psiconv_u32 off, int *length, |
|
|
1141 | psiconv_sheet_cell_layout result) |
|
|
1142 | |
|
|
1143 | { |
|
|
1144 | int res=0; |
|
|
1145 | int len=0; |
|
|
1146 | int leng; |
|
|
1147 | psiconv_u8 temp; |
|
|
1148 | |
|
|
1149 | psiconv_progress(lev+1,off,"Going to read a sheet cell layout"); |
|
|
1150 | |
|
|
1151 | psiconv_progress(lev+2,off+len, |
|
|
1152 | "Going to read the first byte (%02x expected)",0x02); |
|
|
1153 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
1154 | if (res) |
|
|
1155 | goto ERROR1; |
|
|
1156 | if (temp != 0x02) { |
|
|
1157 | psiconv_warn(lev+2,off+len, |
|
|
1158 | "Worksheet section initial byte unknown value (ignored)"); |
|
|
1159 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
1160 | } |
|
|
1161 | len ++; |
|
|
1162 | |
|
|
1163 | psiconv_progress(lev+2,off+len,"Going to read the default formats flag"); |
|
|
1164 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
1165 | if (res) |
|
|
1166 | goto ERROR1; |
|
|
1167 | len ++; |
|
|
1168 | |
|
|
1169 | if (temp & 0x01) { |
|
|
1170 | psiconv_progress(lev+3,off+len,"Going to read the default paragraph codes"); |
|
|
1171 | if ((res = psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng, |
|
|
1172 | result->paragraph))) |
|
|
1173 | goto ERROR1; |
|
|
1174 | len += leng; |
|
|
1175 | } |
|
|
1176 | |
|
|
1177 | if (temp & 0x02) { |
|
|
1178 | psiconv_progress(lev+3,off+len,"Going to read the default character codes"); |
|
|
1179 | if ((res = psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng, |
|
|
1180 | result->character))) |
|
|
1181 | goto ERROR1; |
|
|
1182 | len += leng; |
|
|
1183 | } |
|
|
1184 | |
|
|
1185 | if (temp & 0x04) { |
|
|
1186 | psiconv_progress(lev+3,off+len, "Going to read the default number format"); |
|
|
1187 | psiconv_parse_sheet_numberformat(buf,lev+3,off+len,&leng, |
|
|
1188 | result->numberformat); |
|
|
1189 | len += leng; |
|
|
1190 | } |
|
|
1191 | |
|
|
1192 | if (length) |
|
|
1193 | *length = len; |
|
|
1194 | |
|
|
1195 | psiconv_progress(lev,off+len-1, |
|
|
1196 | "End of sheet cell layout (total length: %08x)", len); |
|
|
1197 | |
|
|
1198 | return 0; |
|
|
1199 | |
|
|
1200 | ERROR1: |
|
|
1201 | psiconv_warn(lev+1,off,"Reading of sheet cell layout failed"); |
|
|
1202 | if (length) |
|
|
1203 | *length = 0; |
|
|
1204 | if (!res) |
|
|
1205 | return -PSICONV_E_NOMEM; |
|
|
1206 | else |
|
|
1207 | return res; |
|
|
1208 | } |
|
|
1209 | |
|
|
1210 | |
|
|
1211 | int psiconv_parse_sheet_worksheet(const psiconv_buffer buf, int lev, |
|
|
1212 | psiconv_u32 off, int *length, |
|
|
1213 | psiconv_sheet_worksheet *result) |
|
|
1214 | { |
|
|
1215 | int res=0; |
|
|
1216 | psiconv_u32 temp,cells_off,grid_off,rows_off,cols_off,unknown_off; |
|
|
1217 | int len=0; |
|
|
1218 | int leng; |
|
|
1219 | |
|
|
1220 | psiconv_progress(lev+1,off,"Going to read the sheet worksheet section"); |
|
|
1221 | if (!(*result = malloc(sizeof(**result)))) |
|
|
1222 | goto ERROR1; |
|
|
1223 | |
|
|
1224 | psiconv_progress(lev+2,off+len, |
|
|
1225 | "Going to read the initial bytes (%02x expected)",0x04); |
|
|
1226 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
1227 | if (res) |
|
|
1228 | goto ERROR2; |
|
|
1229 | if (temp != 0x04) { |
|
|
1230 | psiconv_warn(lev+2,off+len, |
|
|
1231 | "Worksheet section initial byte unknown value (ignored)"); |
|
|
1232 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
1233 | } |
|
|
1234 | len ++; |
|
|
1235 | |
|
|
1236 | psiconv_progress(lev+2,off+len, "Going to read the flags byte"); |
|
|
1237 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
1238 | if (res) |
|
|
1239 | goto ERROR2; |
|
|
1240 | psiconv_debug(lev+2,off+len,"Flags byte: %02x",temp); |
|
|
1241 | (*result)->show_zeros = (temp & 0x01)?psiconv_bool_true:psiconv_bool_false; |
|
|
1242 | if (temp & 0xfe) { |
|
|
1243 | psiconv_warn(lev+2,off+len, |
|
|
1244 | "Worksheet section flags byte unknown bits (ignored)"); |
|
|
1245 | } |
|
|
1246 | len ++; |
|
|
1247 | |
|
|
1248 | psiconv_progress(lev+2,off+len,"Going to read the default cell layout"); |
|
|
1249 | if (!((*result)->default_layout = psiconv_basic_cell_layout())) |
|
|
1250 | goto ERROR2; |
|
|
1251 | if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len,&leng, |
|
|
1252 | (*result)->default_layout))) |
|
|
1253 | goto ERROR3; |
|
|
1254 | len += leng; |
|
|
1255 | |
|
|
1256 | psiconv_progress(lev+2,off+len, |
|
|
1257 | "Going to read the offset of the row defaults Section"); |
|
|
1258 | rows_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
1259 | if (res) |
|
|
1260 | goto ERROR3; |
|
|
1261 | psiconv_debug(lev+2,off+len,"Offset: %04x",rows_off); |
|
|
1262 | len += 4; |
|
|
1263 | |
|
|
1264 | psiconv_progress(lev+2,off+len, |
|
|
1265 | "Going to read the offset of the column defaults Section"); |
|
|
1266 | cols_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
1267 | if (res) |
|
|
1268 | goto ERROR3; |
|
|
1269 | psiconv_debug(lev+2,off+len,"Offset: %04x",cols_off); |
|
|
1270 | len += 4; |
|
|
1271 | |
|
|
1272 | psiconv_progress(lev+2,off+len, |
|
|
1273 | "Going to read the offset of the Cells List"); |
|
|
1274 | cells_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
1275 | if (res) |
|
|
1276 | goto ERROR3; |
|
|
1277 | psiconv_debug(lev+2,off+len,"Offset: %04x",cells_off); |
|
|
1278 | len += 4; |
|
|
1279 | |
|
|
1280 | psiconv_progress(lev+2,off+len, |
|
|
1281 | "Going to read the offset of the Grid Section"); |
|
|
1282 | grid_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
1283 | if (res) |
|
|
1284 | goto ERROR3; |
|
|
1285 | psiconv_debug(lev+2,off+len,"Offset: %04x",grid_off); |
|
|
1286 | len += 4; |
|
|
1287 | |
|
|
1288 | psiconv_progress(lev+2,off+len, |
|
|
1289 | "Going to read the offset of the 3rd ??? Section"); |
|
|
1290 | unknown_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
1291 | if (res) |
|
|
1292 | goto ERROR3; |
|
|
1293 | psiconv_debug(lev+2,off+len,"Offset: %04x",unknown_off); |
|
|
1294 | len += 4; |
|
|
1295 | |
|
|
1296 | psiconv_progress(lev+2,off+len, |
|
|
1297 | "Going to read a long of the 3rd ??? Section " |
|
|
1298 | "(%08x expected)",0x00); |
|
|
1299 | temp = psiconv_read_u32(buf,lev+2,unknown_off,&res); |
|
|
1300 | if (res) |
|
|
1301 | goto ERROR3; |
|
|
1302 | if (temp != 0x00) { |
|
|
1303 | psiconv_warn(lev+2,unknown_off, |
|
|
1304 | "Unknown worksheet subsection has unknown contents (ignored)"); |
|
|
1305 | psiconv_debug(lev+2,unknown_off,"Offset: %04x",temp); |
|
|
1306 | } |
|
|
1307 | len += 4; |
|
|
1308 | |
|
|
1309 | psiconv_progress(lev+2,off+len,"Going to read the row defaults"); |
|
|
1310 | if ((res = psiconv_parse_sheet_line_list(buf,lev+2,rows_off,NULL, |
|
|
1311 | &(*result)->row_default_layouts, |
|
|
1312 | (*result)->default_layout))) |
|
|
1313 | goto ERROR3; |
|
|
1314 | |
|
|
1315 | psiconv_progress(lev+2,off+len,"Going to read the column defaults"); |
|
|
1316 | if ((res = psiconv_parse_sheet_line_list(buf,lev+2,cols_off,NULL, |
|
|
1317 | &(*result)->col_default_layouts, |
|
|
1318 | (*result)->default_layout))) |
|
|
1319 | goto ERROR4; |
|
|
1320 | |
|
|
1321 | psiconv_progress(lev+2,off+len,"Going to read the cells list"); |
|
|
1322 | if ((res = psiconv_parse_sheet_cell_list(buf,lev+2,cells_off,NULL, |
|
|
1323 | &(*result)->cells, |
|
|
1324 | (*result)->default_layout, |
|
|
1325 | (*result)->row_default_layouts, |
|
|
1326 | (*result)->col_default_layouts))) |
|
|
1327 | goto ERROR5; |
|
|
1328 | |
|
|
1329 | |
|
|
1330 | /* TODO: parse grid section */ |
|
|
1331 | |
|
|
1332 | if (length) |
|
|
1333 | *length = len; |
|
|
1334 | |
|
|
1335 | psiconv_progress(lev,off+len-1, |
|
|
1336 | "End of sheet worksheet section (total length: %08x)", len); |
|
|
1337 | return 0; |
|
|
1338 | |
|
|
1339 | ERROR5: |
|
|
1340 | psiconv_free_sheet_line_list((*result)->col_default_layouts); |
|
|
1341 | ERROR4: |
|
|
1342 | psiconv_free_sheet_line_list((*result)->row_default_layouts); |
|
|
1343 | ERROR3: |
|
|
1344 | psiconv_free_sheet_cell_layout((*result)->default_layout); |
|
|
1345 | ERROR2: |
|
|
1346 | free (*result); |
|
|
1347 | ERROR1: |
|
|
1348 | psiconv_warn(lev+1,off,"Reading of Sheet Worksheet Section failed"); |
|
|
1349 | if (length) |
|
|
1350 | *length = 0; |
|
|
1351 | if (!res) |
|
|
1352 | return -PSICONV_E_NOMEM; |
|
|
1353 | else |
|
|
1354 | return res; |
|
|
1355 | } |
|
|
1356 | |
|
|
1357 | int psiconv_parse_sheet_line(const psiconv_buffer buf, int lev, |
|
|
1358 | psiconv_u32 off, int *length, |
|
|
1359 | psiconv_sheet_line *result, |
|
|
1360 | const psiconv_sheet_cell_layout default_layout) |
|
|
1361 | { |
|
|
1362 | int res=0; |
|
|
1363 | int len=0; |
|
|
1364 | int leng; |
|
|
1365 | |
|
|
1366 | |
|
|
1367 | psiconv_progress(lev+1,off,"Going to read a sheet line"); |
|
|
1368 | if (!(*result = malloc(sizeof(**result)))) |
|
|
1369 | goto ERROR1; |
|
|
1370 | |
|
|
1371 | psiconv_progress(lev+2,off+len,"Going to read the line number"); |
|
|
1372 | (*result)->position = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
|
|
1373 | if (res) |
|
|
1374 | goto ERROR2; |
|
|
1375 | psiconv_debug(lev+2,off+len,"Line number: %d\n",(*result)->position); |
|
|
1376 | len += leng; |
|
|
1377 | |
|
|
1378 | if (!((*result)->layout = psiconv_clone_cell_layout(default_layout))) |
|
|
1379 | goto ERROR2; |
|
|
1380 | if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len, |
|
|
1381 | &leng,(*result)->layout))) |
|
|
1382 | goto ERROR3; |
|
|
1383 | len += leng; |
|
|
1384 | |
|
|
1385 | if (length) |
|
|
1386 | *length = len; |
|
|
1387 | |
|
|
1388 | psiconv_progress(lev,off+len-1, |
|
|
1389 | "End of the sheet line (total length: %08x)", len); |
|
|
1390 | return 0; |
|
|
1391 | |
|
|
1392 | ERROR3: |
|
|
1393 | psiconv_free_sheet_cell_layout((*result)->layout); |
|
|
1394 | ERROR2: |
|
|
1395 | free (*result); |
|
|
1396 | ERROR1: |
|
|
1397 | psiconv_warn(lev+1,off,"Reading of the sheet line failed"); |
|
|
1398 | if (length) |
|
|
1399 | *length = 0; |
|
|
1400 | if (!res) |
|
|
1401 | return -PSICONV_E_NOMEM; |
|
|
1402 | else |
|
|
1403 | return res; |
|
|
1404 | } |
|
|
1405 | |
|
|
1406 | |
|
|
1407 | int psiconv_parse_sheet_line_list(const psiconv_buffer buf, int lev, |
|
|
1408 | psiconv_u32 off, int *length, |
|
|
1409 | psiconv_sheet_line_list *result, |
|
|
1410 | const psiconv_sheet_cell_layout default_layout) |
|
|
1411 | { |
|
|
1412 | int res=0; |
|
|
1413 | int len=0; |
|
|
1414 | psiconv_u32 temp; |
|
|
1415 | psiconv_sheet_line line; |
|
|
1416 | psiconv_u32 listlen,i; |
|
|
1417 | int leng; |
|
|
1418 | |
|
|
1419 | psiconv_progress(lev+1,off,"Going to read the sheet line list"); |
|
|
1420 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_line_s)))) |
|
|
1421 | goto ERROR1; |
|
|
1422 | |
|
|
1423 | psiconv_progress(lev+2,off+len, |
|
|
1424 | "Going to read the initial byte (%02x expected)",0x02); |
|
|
1425 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
1426 | if (res) |
|
|
1427 | goto ERROR2; |
|
|
1428 | if (temp != 0x02) { |
|
|
1429 | psiconv_warn(lev+2,off+len, |
|
|
1430 | "Sheet line list initial byte unknown value (ignored)"); |
|
|
1431 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
1432 | } |
|
|
1433 | len ++; |
|
|
1434 | |
|
|
1435 | psiconv_progress(lev+2,off+len, |
|
|
1436 | "Going to read the number of defined lines"); |
|
|
1437 | listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
|
|
1438 | if (res) |
|
|
1439 | goto ERROR2; |
|
|
1440 | psiconv_debug(lev+2,off+len,"Number of defined lines: %d",listlen); |
|
|
1441 | len += leng; |
|
|
1442 | |
|
|
1443 | psiconv_progress(lev+2,off+len,"Going to read all lines"); |
|
|
1444 | for (i = 0; i < listlen; i++) { |
|
|
1445 | psiconv_progress(lev+3,off+len,"Going to read line %d",i); |
|
|
1446 | if ((res = psiconv_parse_sheet_line(buf,lev+3,off+len,&leng,&line, |
|
|
1447 | default_layout))) |
|
|
1448 | goto ERROR2; |
|
|
1449 | if ((res = psiconv_list_add(*result,line))) |
|
|
1450 | goto ERROR3; |
|
|
1451 | free(line); |
|
|
1452 | len += leng; |
|
|
1453 | } |
|
|
1454 | |
|
|
1455 | if (length) |
|
|
1456 | *length = len; |
|
|
1457 | |
|
|
1458 | psiconv_progress(lev,off+len-1, |
|
|
1459 | "End of sheet line list (total length: %08x)", len); |
|
|
1460 | return 0; |
|
|
1461 | |
|
|
1462 | ERROR3: |
|
|
1463 | psiconv_free_sheet_line(line); |
|
|
1464 | ERROR2: |
|
|
1465 | psiconv_free_sheet_line_list(*result); |
|
|
1466 | ERROR1: |
|
|
1467 | psiconv_warn(lev+1,off,"Reading of Sheet Line List failed"); |
|
|
1468 | if (length) |
|
|
1469 | *length = 0; |
|
|
1470 | if (!res) |
|
|
1471 | return -PSICONV_E_NOMEM; |
|
|
1472 | else |
|
|
1473 | return res; |
|
|
1474 | } |
|
|
1475 | |
|
|
1476 | int psiconv_parse_sheet_variable(const psiconv_buffer buf, int lev, |
|
|
1477 | psiconv_u32 off, int *length, |
|
|
1478 | psiconv_sheet_variable *result) |
|
|
1479 | { |
|
|
1480 | int res=0; |
|
|
1481 | int len=0; |
|
|
1482 | psiconv_u32 marker; |
|
|
1483 | int leng; |
|
|
1484 | |
|
|
1485 | psiconv_progress(lev+1,off,"Going to read a sheet variable"); |
|
|
1486 | if (!(*result = malloc(sizeof(**result)))) |
|
|
1487 | goto ERROR1; |
|
|
1488 | |
|
|
1489 | psiconv_progress(lev+2,off+len, "Going to read the variable name"); |
|
|
1490 | (*result)->name = psiconv_read_string(buf,lev+2,off+len,&leng,&res); |
|
|
1491 | if (res) |
|
|
1492 | goto ERROR2; |
|
|
1493 | len += leng; |
|
|
1494 | |
|
|
1495 | psiconv_progress(lev+2,off+len,"Going to read the type marker"); |
|
|
1496 | marker = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
1497 | if (res) |
|
|
1498 | goto ERROR3; |
|
|
1499 | psiconv_debug(lev+2,off+len,"Marker: %02x",marker); |
|
|
1500 | len ++; |
|
|
1501 | |
|
|
1502 | if (marker == 0x00) { |
|
|
1503 | (*result)->type = psiconv_var_int; |
|
|
1504 | psiconv_progress(lev+2,off+len,"Going to read a signed integer"); |
|
|
1505 | (*result)->data.dat_int = psiconv_read_sint(buf,lev+2,off+len,&leng,&res); |
|
|
1506 | if (res) |
|
|
1507 | goto ERROR3; |
|
|
1508 | psiconv_debug(lev+2,off+len,"Value: %d",(*result)->data.dat_int); |
|
|
1509 | len += leng; |
|
|
1510 | } else if (marker == 0x01) { |
|
|
1511 | (*result)->type = psiconv_var_float; |
|
|
1512 | psiconv_progress(lev+2,off+len,"Going to read a floating point number"); |
|
|
1513 | (*result)->data.dat_float = psiconv_read_float(buf,lev+2,off+len,&leng, |
|
|
1514 | &res); |
|
|
1515 | if (res) |
|
|
1516 | goto ERROR3; |
|
|
1517 | psiconv_debug(lev+2,off+len,"Value: %f",(*result)->data.dat_float); |
|
|
1518 | len += leng; |
|
|
1519 | } else if (marker == 0x02) { |
|
|
1520 | (*result)->type = psiconv_var_string; |
|
|
1521 | psiconv_progress(lev+2,off+len,"Going to read a string"); |
|
|
1522 | (*result)->data.dat_string = psiconv_read_string(buf,lev+2,off+len,&leng, |
|
|
1523 | &res); |
|
|
1524 | if (res) |
|
|
1525 | goto ERROR3; |
|
|
1526 | len += leng; |
|
|
1527 | } else if (marker == 0x03) { |
|
|
1528 | (*result)->type = psiconv_var_cellref; |
|
|
1529 | psiconv_progress(lev+2,off+len,"Going to read a cell reference"); |
|
|
1530 | (*result)->data.dat_cellref = psiconv_read_var_cellref(buf,lev+2,off+len, |
|
|
1531 | &leng, &res); |
|
|
1532 | if (res) |
|
|
1533 | goto ERROR3; |
|
|
1534 | len += leng; |
|
|
1535 | } else if (marker == 0x04) { |
|
|
1536 | (*result)->type = psiconv_var_cellblock; |
|
|
1537 | psiconv_progress(lev+2,off+len,"Going to read a cell block reference"); |
|
|
1538 | (*result)->data.dat_cellblock = psiconv_read_var_cellblock(buf,lev+2, |
|
|
1539 | off+len, |
|
|
1540 | &leng, &res); |
|
|
1541 | if (res) |
|
|
1542 | goto ERROR3; |
|
|
1543 | len += leng; |
|
|
1544 | } else { |
|
|
1545 | psiconv_warn(lev+2,off+len,"Sheet variable unknown type marker"); |
|
|
1546 | res = -PSICONV_E_PARSE; |
|
|
1547 | goto ERROR3; |
|
|
1548 | } |
|
|
1549 | |
|
|
1550 | psiconv_progress(lev+2,off+len,"Going to read the variable number"); |
|
|
1551 | (*result)->number = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
1552 | if (res) |
|
|
1553 | goto ERROR4; |
|
|
1554 | psiconv_debug(lev+2,off+len,"Number: %08x",(*result)->number); |
|
|
1555 | len += 4; |
|
|
1556 | |
|
|
1557 | if (length) |
|
|
1558 | *length = len; |
|
|
1559 | |
|
|
1560 | psiconv_progress(lev,off+len-1, |
|
|
1561 | "End of sheet variable (total length: %08x)", len); |
|
|
1562 | return 0; |
|
|
1563 | |
|
|
1564 | ERROR4: |
|
|
1565 | if ((*result)->type == psiconv_var_string) |
|
|
1566 | free((*result)->data.dat_string); |
|
|
1567 | ERROR3: |
|
|
1568 | free((*result)->name); |
|
|
1569 | ERROR2: |
|
|
1570 | free (*result); |
|
|
1571 | ERROR1: |
|
|
1572 | psiconv_warn(lev+1,off,"Reading of Sheet Variable failed"); |
|
|
1573 | if (length) |
|
|
1574 | *length = 0; |
|
|
1575 | if (!res) |
|
|
1576 | return -PSICONV_E_NOMEM; |
|
|
1577 | else |
|
|
1578 | return res; |
|
|
1579 | } |
|
|
1580 | |
|
|
1581 | |
|
|
1582 | int psiconv_parse_sheet_variable_list(const psiconv_buffer buf, int lev, |
|
|
1583 | psiconv_u32 off, int *length, |
|
|
1584 | psiconv_sheet_variable_list *result) |
|
|
1585 | { |
|
|
1586 | int res=0; |
|
|
1587 | int len=0; |
|
|
1588 | psiconv_u32 temp; |
|
|
1589 | psiconv_sheet_variable variable; |
|
|
1590 | psiconv_u32 listlen,i; |
|
|
1591 | int leng; |
|
|
1592 | |
|
|
1593 | psiconv_progress(lev+1,off,"Going to read the sheet variable list"); |
|
|
1594 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_variable_s)))) |
|
|
1595 | goto ERROR1; |
|
|
1596 | |
|
|
1597 | psiconv_progress(lev+2,off+len, |
|
|
1598 | "Going to read the initial byte (%02x expected)",0x02); |
|
|
1599 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
1600 | if (res) |
|
|
1601 | goto ERROR2; |
|
|
1602 | if (temp != 0x02) { |
|
|
1603 | psiconv_warn(lev+2,off+len, |
|
|
1604 | "Sheet variable list initial byte unknown value (ignored)"); |
|
|
1605 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
1606 | } |
|
|
1607 | len ++; |
|
|
1608 | |
|
|
1609 | psiconv_progress(lev+2,off+len, |
|
|
1610 | "Going to read the number of variables"); |
|
|
1611 | listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
|
|
1612 | if (res) |
|
|
1613 | goto ERROR2; |
|
|
1614 | psiconv_debug(lev+2,off+len,"Number of variables: %d",listlen); |
|
|
1615 | len += leng; |
|
|
1616 | |
|
|
1617 | psiconv_progress(lev+2,off+len,"Going to read all variables"); |
|
|
1618 | for (i = 0; i < listlen; i++) { |
|
|
1619 | psiconv_progress(lev+3,off+len,"Going to read variable %d",i); |
|
|
1620 | if ((res = psiconv_parse_sheet_variable(buf,lev+3,off+len,&leng,&variable))) |
|
|
1621 | goto ERROR2; |
|
|
1622 | if ((res = psiconv_list_add(*result,variable))) |
|
|
1623 | goto ERROR3; |
|
|
1624 | len += leng; |
|
|
1625 | } |
|
|
1626 | |
|
|
1627 | if (length) |
|
|
1628 | *length = len; |
|
|
1629 | |
|
|
1630 | psiconv_progress(lev,off+len-1, |
|
|
1631 | "End of sheet variabels list (total length: %08x)", len); |
|
|
1632 | return 0; |
|
|
1633 | |
|
|
1634 | ERROR3: |
|
|
1635 | psiconv_free_sheet_variable(variable); |
|
|
1636 | ERROR2: |
|
|
1637 | psiconv_list_free(*result); |
|
|
1638 | ERROR1: |
|
|
1639 | psiconv_warn(lev+1,off,"Reading of Sheet Variable list failed"); |
|
|
1640 | if (length) |
|
|
1641 | *length = 0; |
|
|
1642 | if (!res) |
|
|
1643 | return -PSICONV_E_NOMEM; |
|
|
1644 | else |
|
|
1645 | return res; |
|
|
1646 | } |