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