… | |
… | |
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 | int psiconv_parse_sheet_numberformat(const psiconv_buffer buf, int lev, |
|
|
80 | psiconv_u32 off, int *length, |
|
|
81 | psiconv_sheet_numberformat result) |
|
|
82 | { |
|
|
83 | int res=0; |
|
|
84 | int len=0; |
|
|
85 | psiconv_u8 temp; |
|
|
86 | |
|
|
87 | psiconv_progress(lev+1,off,"Going to read a sheet numberformat"); |
|
|
88 | |
|
|
89 | psiconv_progress(lev+2,off+len, |
|
|
90 | "Going to read the initial byte (%02x expected)",0x02); |
|
|
91 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
92 | if (res) |
|
|
93 | goto ERROR1; |
|
|
94 | if (temp != 0x02) { |
|
|
95 | psiconv_warn(lev+2,off+len, |
|
|
96 | "Sheet numberformat initial byte unknown value (ignored)"); |
|
|
97 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
98 | } |
|
|
99 | len ++; |
|
|
100 | |
|
|
101 | psiconv_progress(lev+2,off+len, "Going to read the code byte"); |
|
|
102 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
103 | if (res) |
|
|
104 | goto ERROR1; |
|
|
105 | psiconv_debug(lev+2,off+len,"Code: %02x",temp); |
|
|
106 | if (temp == 0x00) |
|
|
107 | result->code = psiconv_numberformat_general; |
|
|
108 | else if (temp == 0x02) |
|
|
109 | result->code = psiconv_numberformat_fixeddecimal; |
|
|
110 | else if (temp == 0x04) |
|
|
111 | result->code = psiconv_numberformat_scientific; |
|
|
112 | else if (temp == 0x06) |
|
|
113 | result->code = psiconv_numberformat_currency; |
|
|
114 | else if (temp == 0x08) |
|
|
115 | result->code = psiconv_numberformat_percent; |
|
|
116 | else if (temp == 0x0A) |
|
|
117 | result->code = psiconv_numberformat_triads; |
|
|
118 | else if (temp == 0x0C) |
|
|
119 | result->code = psiconv_numberformat_boolean; |
|
|
120 | else if (temp == 0x0E) |
|
|
121 | result->code = psiconv_numberformat_text; |
|
|
122 | else if (temp == 0x10) |
|
|
123 | result->code = psiconv_numberformat_date_dmm; |
|
|
124 | else if (temp == 0x12) |
|
|
125 | result->code = psiconv_numberformat_date_mmd; |
|
|
126 | else if (temp == 0x14) |
|
|
127 | result->code = psiconv_numberformat_date_ddmmyy; |
|
|
128 | else if (temp == 0x16) |
|
|
129 | result->code = psiconv_numberformat_date_mmddyy; |
|
|
130 | else if (temp == 0x18) |
|
|
131 | result->code = psiconv_numberformat_date_yymmdd; |
|
|
132 | else if (temp == 0x1A) |
|
|
133 | result->code = psiconv_numberformat_date_dmmm; |
|
|
134 | else if (temp == 0x1C) |
|
|
135 | result->code = psiconv_numberformat_date_dmmmyy; |
|
|
136 | else if (temp == 0x1E) |
|
|
137 | result->code = psiconv_numberformat_date_ddmmmyy; |
|
|
138 | else if (temp == 0x20) |
|
|
139 | result->code = psiconv_numberformat_date_mmm; |
|
|
140 | else if (temp == 0x22) |
|
|
141 | result->code = psiconv_numberformat_date_monthname; |
|
|
142 | else if (temp == 0x24) |
|
|
143 | result->code = psiconv_numberformat_date_mmmyy; |
|
|
144 | else if (temp == 0x26) |
|
|
145 | result->code = psiconv_numberformat_date_monthnameyy; |
|
|
146 | else if (temp == 0x28) |
|
|
147 | result->code = psiconv_numberformat_date_monthnamedyyyy; |
|
|
148 | else if (temp == 0x2A) |
|
|
149 | result->code = psiconv_numberformat_datetime_ddmmyyyyhhii; |
|
|
150 | else if (temp == 0x2C) |
|
|
151 | result->code = psiconv_numberformat_datetime_ddmmyyyyHHii; |
|
|
152 | else if (temp == 0x2E) |
|
|
153 | result->code = psiconv_numberformat_datetime_mmddyyyyhhii; |
|
|
154 | else if (temp == 0x30) |
|
|
155 | result->code = psiconv_numberformat_datetime_mmddyyyyHHii; |
|
|
156 | else if (temp == 0x32) |
|
|
157 | result->code = psiconv_numberformat_datetime_yyyymmddhhii; |
|
|
158 | else if (temp == 0x34) |
|
|
159 | result->code = psiconv_numberformat_datetime_yyyymmddHHii; |
|
|
160 | else if (temp == 0x36) |
|
|
161 | result->code = psiconv_numberformat_time_hhii; |
|
|
162 | else if (temp == 0x38) |
|
|
163 | result->code = psiconv_numberformat_time_hhiiss; |
|
|
164 | else if (temp == 0x3A) |
|
|
165 | result->code = psiconv_numberformat_time_HHii; |
|
|
166 | else if (temp == 0x3C) |
|
|
167 | result->code = psiconv_numberformat_time_HHiiss; |
|
|
168 | else { |
|
|
169 | psiconv_warn(lev+2,off+len,"Unknown number format (assumed general)"); |
|
|
170 | result->code = psiconv_numberformat_general; |
|
|
171 | } |
|
|
172 | len ++; |
|
|
173 | |
|
|
174 | psiconv_progress(lev+2,off+len, "Going to read the number of decimals"); |
|
|
175 | result->decimal = psiconv_read_u8(buf,lev+2,off+len,&res) >> 1; |
|
|
176 | if (res) |
|
|
177 | goto ERROR1; |
|
|
178 | psiconv_debug(lev+2,off+len,"Decimals: %d",result->decimal); |
|
|
179 | len ++; |
|
|
180 | |
|
|
181 | if (length) |
|
|
182 | *length = len; |
|
|
183 | |
|
|
184 | psiconv_progress(lev,off+len-1, |
|
|
185 | "End of sheet number format (total length: %08x)", len); |
|
|
186 | return 0; |
|
|
187 | |
|
|
188 | ERROR1: |
|
|
189 | psiconv_warn(lev+1,off,"Reading of Sheet Number Format failed"); |
|
|
190 | if (length) |
|
|
191 | *length = 0; |
|
|
192 | if (!res) |
|
|
193 | return -PSICONV_E_NOMEM; |
|
|
194 | else |
|
|
195 | return res; |
|
|
196 | } |
27 | |
197 | |
28 | int psiconv_parse_sheet_status_section(const psiconv_buffer buf, int lev, |
198 | int psiconv_parse_sheet_status_section(const psiconv_buffer buf, int lev, |
29 | psiconv_u32 off, int *length, |
199 | psiconv_u32 off, int *length, |
30 | psiconv_sheet_status_section *result) |
200 | psiconv_sheet_status_section *result) |
31 | { |
201 | { |
… | |
… | |
221 | goto ERROR2; |
391 | goto ERROR2; |
222 | psiconv_debug(lev+2,off+len,"Offset: %04x",formulas_off); |
392 | psiconv_debug(lev+2,off+len,"Offset: %04x",formulas_off); |
223 | len += 4; |
393 | len += 4; |
224 | |
394 | |
225 | psiconv_progress(lev+2,off+len, |
395 | psiconv_progress(lev+2,off+len, |
226 | "Going to read the offset of the Worksheets Section"); |
396 | "Going to read the offset of the Worksheet List"); |
227 | worksheets_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
397 | worksheets_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
228 | if (res) |
398 | if (res) |
229 | goto ERROR2; |
399 | goto ERROR2; |
230 | psiconv_debug(lev+2,off+len,"Offset: %04x",temp); |
400 | psiconv_debug(lev+2,off+len,"Offset: %04x",worksheets_off); |
231 | len += 4; |
401 | len += 4; |
232 | |
402 | |
233 | psiconv_progress(lev+2,off+len, |
403 | psiconv_progress(lev+2,off+len, |
234 | "Going to read the offset of the 4th ??? Section"); |
404 | "Going to read the offset of the 4th ??? Section"); |
235 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
405 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
… | |
… | |
241 | psiconv_progress(lev+2,off+len,"Going to read the formulas list"); |
411 | psiconv_progress(lev+2,off+len,"Going to read the formulas list"); |
242 | if ((res = psiconv_parse_sheet_formula_table(buf,lev+2,formulas_off,NULL, |
412 | if ((res = psiconv_parse_sheet_formula_table(buf,lev+2,formulas_off,NULL, |
243 | &(*result)->formulas))) |
413 | &(*result)->formulas))) |
244 | goto ERROR2; |
414 | goto ERROR2; |
245 | |
415 | |
246 | psiconv_progress(lev+2,off+len,"Going to read the worksheets"); |
416 | psiconv_progress(lev+2,off+len,"Going to read the worksheet list"); |
247 | if ((res = psiconv_parse_sheet_worksheet_section(buf,lev+2,worksheets_off, |
417 | if ((res = psiconv_parse_sheet_worksheet_list(buf,lev+2,worksheets_off, |
248 | NULL,&(*result)->worksheet))) |
418 | NULL,&(*result)->worksheets))) |
249 | goto ERROR2; |
419 | goto ERROR2; |
250 | |
420 | |
251 | |
421 | |
252 | if (length) |
422 | if (length) |
253 | *length = len; |
423 | *length = len; |
… | |
… | |
333 | else |
503 | else |
334 | return res; |
504 | return res; |
335 | } |
505 | } |
336 | |
506 | |
337 | int psiconv_parse_sheet_cell(const psiconv_buffer buf, int lev, |
507 | int psiconv_parse_sheet_cell(const psiconv_buffer buf, int lev, |
338 | psiconv_u32 off, int *length, |
508 | psiconv_u32 off, int *length, |
339 | psiconv_sheet_cell *result) |
509 | psiconv_sheet_cell *result, |
|
|
510 | const psiconv_sheet_cell_layout default_layout, |
|
|
511 | const psiconv_sheet_line_list row_default_layouts, |
|
|
512 | const psiconv_sheet_line_list col_default_layouts) |
340 | { |
513 | { |
341 | int res=0; |
514 | int res=0; |
342 | int len=0; |
515 | int len=0; |
343 | psiconv_u32 temp; |
516 | psiconv_u32 temp; |
344 | psiconv_bool_t has_layout; |
517 | psiconv_bool_t has_layout; |
… | |
… | |
346 | |
519 | |
347 | psiconv_progress(lev+1,off,"Going to read a sheet cell structure"); |
520 | psiconv_progress(lev+1,off,"Going to read a sheet cell structure"); |
348 | if (!(*result = malloc(sizeof(**result)))) |
521 | if (!(*result = malloc(sizeof(**result)))) |
349 | goto ERROR1; |
522 | goto ERROR1; |
350 | |
523 | |
|
|
524 | (*result)->layout = NULL; |
|
|
525 | (*result)->type = psiconv_cell_blank; |
|
|
526 | |
351 | psiconv_progress(lev+2,off+len,"Going to read the cell position"); |
527 | psiconv_progress(lev+2,off+len,"Going to read the cell position"); |
352 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
528 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
353 | if (res) |
529 | if (res) |
354 | goto ERROR2; |
530 | goto ERROR2; |
355 | len ++; |
531 | len ++; |
… | |
… | |
363 | len ++; |
539 | len ++; |
364 | (*result)->column = (temp >> 2) & 0xFF; |
540 | (*result)->column = (temp >> 2) & 0xFF; |
365 | (*result)->row = (temp >> 10) & 0x3FFF; |
541 | (*result)->row = (temp >> 10) & 0x3FFF; |
366 | psiconv_debug(lev+2,off+len,"Cell position is col:%02x row:%04x", |
542 | psiconv_debug(lev+2,off+len,"Cell position is col:%02x row:%04x", |
367 | (*result)->column,(*result)->row); |
543 | (*result)->column,(*result)->row); |
|
|
544 | if (temp & 0x03) { |
|
|
545 | psiconv_warn(lev+2,off+len,"Unknown flags in cell position (ignored)"); |
|
|
546 | psiconv_debug(lev+2,off+len,"Flags: %02x",temp & 0x03); |
|
|
547 | } |
368 | |
548 | |
369 | psiconv_progress(lev+2,off+len,"Going to read the cell type"); |
549 | psiconv_progress(lev+2,off+len,"Going to read the cell type"); |
370 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
550 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
371 | if (res) |
551 | if (res) |
372 | goto ERROR2; |
552 | goto ERROR2; |
… | |
… | |
386 | len += 4; |
566 | len += 4; |
387 | psiconv_debug(lev+2,off+len,"Cell contents: %ld",(*result)->data.dat_int); |
567 | psiconv_debug(lev+2,off+len,"Cell contents: %ld",(*result)->data.dat_int); |
388 | |
568 | |
389 | } else if ((*result)->type == psiconv_cell_bool) { |
569 | } else if ((*result)->type == psiconv_cell_bool) { |
390 | psiconv_progress(lev+2,off+len,"Going to read a boolean"); |
570 | psiconv_progress(lev+2,off+len,"Going to read a boolean"); |
391 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
571 | if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng, |
392 | if (res) |
572 | &(*result)->data.dat_bool))) |
393 | goto ERROR2; |
573 | goto ERROR2; |
394 | len ++; |
|
|
395 | psiconv_debug(lev+2,off+len,"Cell contents: %01x",temp); |
574 | psiconv_debug(lev+2,off+len,"Cell contents: %01x",temp); |
396 | (*result)->data.dat_bool = temp?psiconv_bool_true:psiconv_bool_false; |
575 | (*result)->data.dat_bool = temp?psiconv_bool_true:psiconv_bool_false; |
397 | |
576 | len += leng; |
398 | } else if ((*result)->type == psiconv_cell_error) { |
577 | } else if ((*result)->type == psiconv_cell_error) { |
399 | psiconv_progress(lev+2,off+len,"Going to read the error code"); |
578 | psiconv_progress(lev+2,off+len,"Going to read the error code"); |
400 | (*result)->data.dat_error = psiconv_read_u16(buf,lev+2,off+len,&res); |
579 | temp = psiconv_read_u16(buf,lev+2,off+len,&res); |
401 | if (res) |
580 | if (res) |
402 | goto ERROR2; |
581 | goto ERROR2; |
403 | len += 2; |
582 | if (temp == 0) |
|
|
583 | (*result)->data.dat_error = psiconv_sheet_error_none; |
|
|
584 | else if (temp == 1) |
|
|
585 | (*result)->data.dat_error = psiconv_sheet_error_null; |
|
|
586 | else if (temp == 2) |
|
|
587 | (*result)->data.dat_error = psiconv_sheet_error_divzero; |
|
|
588 | else if (temp == 3) |
|
|
589 | (*result)->data.dat_error = psiconv_sheet_error_value; |
|
|
590 | else if (temp == 4) |
|
|
591 | (*result)->data.dat_error = psiconv_sheet_error_reference; |
|
|
592 | else if (temp == 5) |
|
|
593 | (*result)->data.dat_error = psiconv_sheet_error_name; |
|
|
594 | else if (temp == 6) |
|
|
595 | (*result)->data.dat_error = psiconv_sheet_error_number; |
|
|
596 | else if (temp == 7) |
|
|
597 | (*result)->data.dat_error = psiconv_sheet_error_notavail; |
|
|
598 | else { |
|
|
599 | psiconv_warn(lev+2,off+len,"Unknown error code (default assumed)"); |
|
|
600 | psiconv_debug(lev+2,off+len,"Error code: %04x",temp); |
|
|
601 | (*result)->data.dat_error = psiconv_sheet_error_none; |
|
|
602 | } |
404 | psiconv_debug(lev+2,off+len,"Cell contents: %04x", |
603 | psiconv_debug(lev+2,off+len,"Cell contents: %04x", |
405 | (*result)->data.dat_error); |
604 | (*result)->data.dat_error); |
406 | |
605 | len += 2; |
407 | } else if ((*result)->type == psiconv_cell_float) { |
606 | } else if ((*result)->type == psiconv_cell_float) { |
408 | psiconv_progress(lev+2,off+len,"Going to read a float"); |
607 | psiconv_progress(lev+2,off+len,"Going to read a float"); |
409 | (*result)->data.dat_float = |
608 | (*result)->data.dat_float = |
410 | psiconv_read_float(buf,lev+2,off+len,&leng,&res); |
609 | psiconv_read_float(buf,lev+2,off+len,&leng,&res); |
411 | if (res) |
610 | if (res) |
412 | goto ERROR2; |
611 | goto ERROR2; |
413 | len += leng; |
|
|
414 | psiconv_debug(lev+2,off+len,"Cell contents: %f",(*result)->data.dat_float); |
612 | psiconv_debug(lev+2,off+len,"Cell contents: %f",(*result)->data.dat_float); |
415 | |
613 | len += leng; |
416 | } else if ((*result)->type == psiconv_cell_string) { |
614 | } else if ((*result)->type == psiconv_cell_string) { |
417 | psiconv_progress(lev+2,off+len,"Going to read a string"); |
615 | psiconv_progress(lev+2,off+len,"Going to read a string"); |
418 | (*result)->data.dat_string = |
616 | (*result)->data.dat_string = |
419 | psiconv_read_short_string(buf,lev+2,off+len,&leng,&res); |
617 | psiconv_read_string(buf,lev+2,off+len,&leng,&res); |
420 | if (res) |
618 | if (res) |
421 | goto ERROR2; |
619 | goto ERROR2; |
422 | len += leng; |
|
|
423 | psiconv_debug(lev+2,off+len,"Cell contents: `%s'", |
620 | psiconv_debug(lev+2,off+len,"Cell contents: `%s'", |
424 | (*result)->data.dat_string); |
621 | (*result)->data.dat_string); |
|
|
622 | len += leng; |
425 | } else { |
623 | } else { |
426 | psiconv_warn(lev+2,off+len,"Unknown Sheet Cell type: %02x",(*result)->type); |
624 | psiconv_warn(lev+2,off+len,"Unknown Sheet Cell type: %02x",(*result)->type); |
427 | } |
625 | res = PSICONV_E_PARSE; |
|
|
626 | goto ERROR2; |
428 | |
627 | } |
|
|
628 | |
|
|
629 | if (!((*result)->layout = psiconv_clone_cell_layout( |
|
|
630 | psiconv_get_default_layout(row_default_layouts, |
|
|
631 | col_default_layouts, |
|
|
632 | default_layout, |
|
|
633 | (*result)->row, |
|
|
634 | (*result)->column)))) |
|
|
635 | goto ERROR2; |
429 | if (has_layout) { |
636 | if (has_layout) { |
430 | psiconv_progress(lev+2,off+len,"Going to read the cell layout"); |
637 | if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len, |
431 | |
638 | &leng,(*result)->layout))) |
432 | psiconv_progress(lev+2,off+len,"Going to read the cell layout flags"); |
|
|
433 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
434 | if (res) |
|
|
435 | goto ERROR2; |
639 | goto ERROR2; |
436 | len ++; |
|
|
437 | |
|
|
438 | if (temp & 0x01) { |
|
|
439 | if (!((*result)->paragraph = psiconv_basic_paragraph_layout())) |
|
|
440 | goto ERROR2; |
|
|
441 | psiconv_progress(lev+3,off+len,"Going to read the paragraph codes"); |
|
|
442 | if ((res = psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng, |
|
|
443 | (*result)->paragraph))) |
|
|
444 | goto ERROR2; |
|
|
445 | len += leng; |
640 | len += leng; |
446 | } |
|
|
447 | |
|
|
448 | if (temp & 0x02) { |
|
|
449 | psiconv_progress(lev+3,off+len,"Going to read the character codes"); |
|
|
450 | if (!((*result)->character = psiconv_basic_character_layout())) |
|
|
451 | goto ERROR2; |
|
|
452 | if ((res = psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng, |
|
|
453 | (*result)->character))) |
|
|
454 | goto ERROR2; |
|
|
455 | len += leng; |
|
|
456 | } |
|
|
457 | |
|
|
458 | if (temp & 0x04) { |
|
|
459 | /* TODO: default number format */ |
|
|
460 | psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
461 | if (res) |
|
|
462 | goto ERROR2; |
|
|
463 | len ++; |
|
|
464 | psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
465 | if (res) |
|
|
466 | goto ERROR2; |
|
|
467 | len ++; |
|
|
468 | psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
469 | if (res) |
|
|
470 | goto ERROR2; |
|
|
471 | len ++; |
|
|
472 | } |
|
|
473 | } |
641 | } |
474 | |
642 | |
475 | if ((*result)->calculated) { |
643 | if ((*result)->calculated) { |
476 | psiconv_progress(lev+2,off+len,"Going to read the cell formula reference"); |
644 | psiconv_progress(lev+2,off+len,"Going to read the cell formula reference"); |
477 | temp = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
645 | temp = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
478 | if (res) |
646 | if (res) |
479 | goto ERROR2; |
647 | goto ERROR2; |
480 | psiconv_debug(lev+2,off+len,"Cell formula reference: %d",temp); |
648 | psiconv_debug(lev+2,off+len,"Cell formula reference: %d",temp); |
481 | len += leng; |
649 | len += leng; |
482 | (*result)->ref_formula = temp; |
650 | (*result)->ref_formula = temp; |
483 | } |
651 | } |
484 | |
652 | |
485 | if (length) |
653 | if (length) |
486 | *length = len; |
654 | *length = len; |
487 | |
655 | |
… | |
… | |
500 | else |
668 | else |
501 | return res; |
669 | return res; |
502 | } |
670 | } |
503 | |
671 | |
504 | int psiconv_parse_sheet_cell_list(const psiconv_buffer buf, int lev, |
672 | int psiconv_parse_sheet_cell_list(const psiconv_buffer buf, int lev, |
505 | psiconv_u32 off, int *length, |
673 | psiconv_u32 off, int *length, |
506 | psiconv_sheet_cell_list *result) |
674 | psiconv_sheet_cell_list *result, |
|
|
675 | const psiconv_sheet_cell_layout default_layout, |
|
|
676 | const psiconv_sheet_line_list row_default_layouts, |
|
|
677 | const psiconv_sheet_line_list col_default_layouts) |
507 | { |
678 | { |
508 | int res=0; |
679 | int res=0; |
509 | int len=0; |
680 | int len=0; |
510 | psiconv_u32 temp; |
681 | psiconv_u32 temp; |
511 | psiconv_sheet_cell cell; |
682 | psiconv_sheet_cell cell; |
512 | psiconv_u32 listlen,i; |
683 | psiconv_u32 listlen,i; |
513 | int leng; |
684 | int leng; |
514 | |
685 | |
515 | psiconv_progress(lev+1,off,"Going to read the sheet cells list"); |
686 | psiconv_progress(lev+1,off,"Going to read the sheet cell list"); |
516 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_cell_s)))) |
687 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_cell_s)))) |
517 | goto ERROR1; |
688 | goto ERROR1; |
518 | |
689 | |
519 | psiconv_progress(lev+2,off+len, |
690 | psiconv_progress(lev+2,off+len, |
520 | "Going to read the initial byte (%02x expected)",0x02); |
691 | "Going to read the initial byte (%02x expected)",0x02); |
… | |
… | |
549 | len += leng; |
720 | len += leng; |
550 | |
721 | |
551 | psiconv_progress(lev+2,off+len,"Going to read all cells"); |
722 | psiconv_progress(lev+2,off+len,"Going to read all cells"); |
552 | for (i = 0; i < listlen; i++) { |
723 | for (i = 0; i < listlen; i++) { |
553 | psiconv_progress(lev+3,off+len,"Going to read cell %d",i); |
724 | psiconv_progress(lev+3,off+len,"Going to read cell %d",i); |
554 | if ((res = psiconv_parse_sheet_cell(buf,lev+3,off+len,&leng,&cell))) |
725 | if ((res = psiconv_parse_sheet_cell(buf,lev+3,off+len,&leng,&cell, |
|
|
726 | default_layout,row_default_layouts, |
|
|
727 | col_default_layouts))) |
555 | goto ERROR2; |
728 | goto ERROR2; |
556 | if ((res = psiconv_list_add(*result,cell))) |
729 | if ((res = psiconv_list_add(*result,cell))) |
557 | goto ERROR3; |
730 | goto ERROR3; |
|
|
731 | free(cell); |
558 | len += leng; |
732 | len += leng; |
559 | } |
733 | } |
560 | |
734 | |
561 | if (length) |
735 | if (length) |
562 | *length = len; |
736 | *length = len; |
… | |
… | |
578 | else |
752 | else |
579 | return res; |
753 | return res; |
580 | } |
754 | } |
581 | |
755 | |
582 | |
756 | |
583 | int psiconv_parse_sheet_worksheet_section(const psiconv_buffer buf, int lev, |
757 | int psiconv_parse_sheet_worksheet_list( const psiconv_buffer buf, int lev, |
584 | psiconv_u32 off, int *length, |
758 | psiconv_u32 off, int *length, |
585 | psiconv_sheet_worksheet_section *result) |
759 | psiconv_sheet_worksheet_list *result) |
586 | { |
760 | { |
|
|
761 | psiconv_sheet_worksheet worksheet; |
587 | int res=0; |
762 | int res=0; |
588 | psiconv_u32 temp,cells_off,grid_off; |
|
|
589 | int len=0; |
763 | int len=0; |
|
|
764 | psiconv_u8 temp; |
|
|
765 | psiconv_u32 offset; |
590 | int leng; |
766 | int leng,i,nr; |
591 | |
767 | |
592 | /* TODO: this is the section that might be an XListE instead... */ |
|
|
593 | psiconv_progress(lev+2,off+len, |
|
|
594 | "Going to read the initial bytes (%02x expected)",0x02); |
|
|
595 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
596 | if (res) |
|
|
597 | goto ERROR1; |
|
|
598 | if (temp != 0x04) { |
|
|
599 | psiconv_warn(lev+2,off+len, |
|
|
600 | "Sheet worksheet section initial byte unknown value (ignored)"); |
|
|
601 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
602 | } |
|
|
603 | len ++; |
|
|
604 | |
|
|
605 | psiconv_progress(lev+2,off+len, |
|
|
606 | "Going to read the initial bytes (%02x expected)",0x02); |
|
|
607 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
608 | if (res) |
|
|
609 | goto ERROR1; |
|
|
610 | if (temp != 0x04) { |
|
|
611 | psiconv_warn(lev+2,off+len, |
|
|
612 | "Sheet worksheet section initial byte unknown value (ignored)"); |
|
|
613 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
614 | } |
|
|
615 | len ++; |
|
|
616 | |
|
|
617 | psiconv_progress(lev+2,off+len, |
|
|
618 | "Going to read the initial bytes (%02x expected)",0x00); |
|
|
619 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
620 | if (res) |
|
|
621 | goto ERROR1; |
|
|
622 | if (temp != 0x04) { |
|
|
623 | psiconv_warn(lev+2,off+len, |
|
|
624 | "Sheet worksheet section initial byte unknown value (ignored)"); |
|
|
625 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
626 | } |
|
|
627 | len ++; |
|
|
628 | |
|
|
629 | psiconv_progress(lev+2,off+len, |
|
|
630 | "Going to read the offset of the Worksheet Section"); |
|
|
631 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
632 | if (res) |
|
|
633 | goto ERROR1; |
|
|
634 | psiconv_debug(lev+2,off+len,"Offset: %04x",temp); |
|
|
635 | len += 4; |
|
|
636 | |
|
|
637 | len = 0; |
|
|
638 | off = temp; |
|
|
639 | |
|
|
640 | /* this is the real worksheet section from here */ |
|
|
641 | |
|
|
642 | psiconv_progress(lev+1,off,"Going to read the sheet worksheet section"); |
768 | psiconv_progress(lev+1,off,"Going to read the worksheet list"); |
643 | if (!(*result = malloc(sizeof(**result)))) |
769 | if (!(*result = psiconv_list_new(sizeof(*worksheet)))) |
644 | goto ERROR1; |
|
|
645 | |
|
|
646 | psiconv_progress(lev+2,off+len, |
|
|
647 | "Going to read the initial bytes (%02x expected)",0x04); |
|
|
648 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
649 | if (res) |
|
|
650 | goto ERROR2; |
770 | goto ERROR1; |
651 | if (temp != 0x04) { |
|
|
652 | psiconv_warn(lev+2,off+len, |
|
|
653 | "Worksheet section initial byte unknown value (ignored)"); |
|
|
654 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
655 | } |
771 | |
656 | len ++; |
|
|
657 | |
|
|
658 | psiconv_progress(lev+2,off+len, |
|
|
659 | "Going to read the initial bytes (%02x expected)",0x01); |
|
|
660 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
661 | if (res) |
|
|
662 | goto ERROR2; |
|
|
663 | if (temp != 0x01) { |
|
|
664 | psiconv_warn(lev+2,off+len, |
|
|
665 | "Worksheet section initial byte unknown value (ignored)"); |
|
|
666 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
667 | } |
|
|
668 | len ++; |
|
|
669 | |
|
|
670 | psiconv_progress(lev+2,off+len, |
772 | psiconv_progress(lev+2,off+len, |
671 | "Going to read the initial bytes (%02x expected)",0x02); |
773 | "Going to read the initial bytes (%02x expected)",0x02); |
672 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
774 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
673 | if (res) |
775 | if (res) |
674 | goto ERROR2; |
776 | goto ERROR2; |
675 | if (temp != 0x02) { |
777 | if (temp != 0x02) { |
676 | psiconv_warn(lev+2,off+len, |
778 | psiconv_warn(lev+2,off+len, |
677 | "Worksheet section initial byte unknown value (ignored)"); |
779 | "Sheet worksheet list initial byte unknown value (ignored)"); |
678 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
780 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
679 | } |
781 | } |
680 | len ++; |
782 | len ++; |
681 | |
783 | |
|
|
784 | psiconv_progress(lev+2,off+len,"Going to read the list length"); |
|
|
785 | nr = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
|
|
786 | if (res) |
|
|
787 | goto ERROR2; |
|
|
788 | psiconv_debug(lev+2,off+len,"Length: %02x",nr); |
|
|
789 | len += leng; |
|
|
790 | |
682 | psiconv_progress(lev+2,off+len,"Going to read the default formats flag"); |
791 | psiconv_progress(lev+2,off+len,"Going to read the list"); |
|
|
792 | for (i=0 ; i < nr; i++) { |
|
|
793 | psiconv_progress(lev+3,off+len,"Going to read element %d",i); |
|
|
794 | psiconv_progress(lev+4,off+len, |
|
|
795 | "Going to read the initial byte (%02x expected)",0x00); |
683 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
796 | temp = psiconv_read_u8(buf,lev+4,off+len,&res); |
684 | if (res) |
797 | if (res) |
685 | goto ERROR2; |
|
|
686 | len ++; |
|
|
687 | |
|
|
688 | if (temp & 0x01) { |
|
|
689 | if (!((*result)->paragraph = psiconv_basic_paragraph_layout())) |
|
|
690 | goto ERROR2; |
798 | goto ERROR2; |
691 | psiconv_progress(lev+3,off+len,"Going to read the default paragraph codes"); |
|
|
692 | if ((res = psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng, |
|
|
693 | (*result)->paragraph))) |
|
|
694 | goto ERROR2_1; |
|
|
695 | len += leng; |
|
|
696 | } |
|
|
697 | |
|
|
698 | if (temp & 0x02) { |
799 | if (temp != 0x00) { |
|
|
800 | psiconv_warn(lev+4,off+len, |
|
|
801 | "Sheet worksheet element initial byte unknown value (ignored)"); |
|
|
802 | psiconv_debug(lev+4,off+len,"Initial byte: %02x",temp); |
|
|
803 | } |
|
|
804 | len ++; |
|
|
805 | |
699 | psiconv_progress(lev+3,off+len,"Going to read the default character codes"); |
806 | psiconv_progress(lev+4,off+len,"Going to read the worksheet offset"); |
700 | if (!((*result)->character = psiconv_basic_character_layout())) |
|
|
701 | goto ERROR2_1; |
|
|
702 | if ((res = psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng, |
|
|
703 | (*result)->character))) |
|
|
704 | goto ERROR2_2; |
|
|
705 | len += leng; |
|
|
706 | } |
|
|
707 | |
|
|
708 | if (temp & 0x04) { |
|
|
709 | /* TODO: default number format */ |
|
|
710 | psiconv_read_u8(buf,lev+2,off+len,&res); |
807 | offset = psiconv_read_u32(buf,lev+2,off+len,&res); |
711 | if (res) |
808 | if (res) |
712 | goto ERROR2_3; |
809 | goto ERROR2; |
|
|
810 | psiconv_debug(lev+4,off+len,"Offset: %08x",offset); |
713 | len ++; |
811 | len += 4; |
714 | psiconv_read_u8(buf,lev+2,off+len,&res); |
812 | |
715 | if (res) |
813 | if ((res = psiconv_parse_sheet_worksheet(buf,lev+4,offset,NULL, |
|
|
814 | &worksheet))) |
716 | goto ERROR2_3; |
815 | goto ERROR2; |
717 | len ++; |
816 | if ((res = psiconv_list_add(*result,worksheet))) |
718 | psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
719 | if (res) |
|
|
720 | goto ERROR2_3; |
817 | goto ERROR3; |
721 | len ++; |
818 | free(worksheet); |
722 | } |
|
|
723 | |
819 | } |
724 | psiconv_progress(lev+2,off+len, |
|
|
725 | "Going to read the offset of the 1st ??? Section"); |
|
|
726 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
727 | if (res) |
|
|
728 | goto ERROR2; |
|
|
729 | psiconv_debug(lev+2,off+len,"Offset: %04x",temp); |
|
|
730 | len += 4; |
|
|
731 | |
820 | |
732 | psiconv_progress(lev+2,off+len, |
|
|
733 | "Going to read the offset of the 2nd ??? Section"); |
|
|
734 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
735 | if (res) |
|
|
736 | goto ERROR2; |
|
|
737 | psiconv_debug(lev+2,off+len,"Offset: %04x",temp); |
|
|
738 | len += 4; |
|
|
739 | |
|
|
740 | psiconv_progress(lev+2,off+len, |
|
|
741 | "Going to read the offset of the Cells List"); |
|
|
742 | cells_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
743 | if (res) |
|
|
744 | goto ERROR2; |
|
|
745 | psiconv_debug(lev+2,off+len,"Offset: %04x",cells_off); |
|
|
746 | len += 4; |
|
|
747 | |
|
|
748 | psiconv_progress(lev+2,off+len, |
|
|
749 | "Going to read the offset of the Grid Section"); |
|
|
750 | grid_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
751 | if (res) |
|
|
752 | goto ERROR2; |
|
|
753 | psiconv_debug(lev+2,off+len,"Offset: %04x",grid_off); |
|
|
754 | len += 4; |
|
|
755 | |
|
|
756 | psiconv_progress(lev+2,off+len, |
|
|
757 | "Going to read the offset of the 3rd ??? Section"); |
|
|
758 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
759 | if (res) |
|
|
760 | goto ERROR2; |
|
|
761 | psiconv_debug(lev+2,off+len,"Offset: %04x",temp); |
|
|
762 | len += 4; |
|
|
763 | |
|
|
764 | psiconv_progress(lev+2,off+len,"Going to read the cells list"); |
|
|
765 | if ((res = psiconv_parse_sheet_cell_list(buf,lev+2,cells_off,NULL, |
|
|
766 | &(*result)->cells))) |
|
|
767 | goto ERROR2; |
|
|
768 | |
|
|
769 | |
|
|
770 | /* TODO: parse grid section */ |
|
|
771 | |
|
|
772 | if (length) |
821 | if (length) |
773 | *length = len; |
822 | *length = len; |
774 | |
823 | |
775 | psiconv_progress(lev,off+len-1, |
824 | psiconv_progress(lev,off+len-1, |
776 | "End of sheet worksheet section (total length: %08x)", len); |
825 | "End of worksheet list (total length: %08x)", len); |
|
|
826 | |
777 | return 0; |
827 | return 0; |
778 | |
828 | |
779 | ERROR2_3: |
829 | ERROR3: |
780 | psiconv_free_numberformat((*result)->numberformat); |
830 | psiconv_free_sheet_worksheet(worksheet); |
781 | ERROR2_2: |
|
|
782 | psiconv_free_character_layout((*result)->character); |
|
|
783 | ERROR2_1: |
|
|
784 | psiconv_free_paragraph_layout((*result)->paragraph); |
|
|
785 | goto ERROR2; |
|
|
786 | |
|
|
787 | ERROR2: |
831 | ERROR2: |
788 | free (*result); |
832 | psiconv_free_sheet_worksheet_list(*result); |
789 | ERROR1: |
833 | ERROR1: |
790 | psiconv_warn(lev+1,off,"Reading of Sheet Worksheet Section failed"); |
834 | psiconv_warn(lev+1,off,"Reading of worksheet list failed"); |
791 | if (length) |
835 | if (length) |
792 | *length = 0; |
836 | *length = 0; |
793 | if (!res) |
837 | if (!res) |
794 | return -PSICONV_E_NOMEM; |
838 | return -PSICONV_E_NOMEM; |
795 | else |
839 | else |
796 | return res; |
840 | return res; |
797 | } |
841 | } |
798 | |
842 | |
|
|
843 | int psiconv_parse_sheet_cell_layout(const psiconv_buffer buf, int lev, |
|
|
844 | psiconv_u32 off, int *length, |
|
|
845 | psiconv_sheet_cell_layout result) |
799 | |
846 | |
|
|
847 | { |
|
|
848 | int res=0; |
|
|
849 | int len=0; |
|
|
850 | int leng; |
|
|
851 | psiconv_u8 temp; |
|
|
852 | |
|
|
853 | psiconv_progress(lev+1,off,"Going to read a sheet cell layout"); |
|
|
854 | |
|
|
855 | psiconv_progress(lev+2,off+len, |
|
|
856 | "Going to read the first byte (%02x expected)",0x02); |
|
|
857 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
858 | if (res) |
|
|
859 | goto ERROR1; |
|
|
860 | if (temp != 0x02) { |
|
|
861 | psiconv_warn(lev+2,off+len, |
|
|
862 | "Worksheet section initial byte unknown value (ignored)"); |
|
|
863 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
864 | } |
|
|
865 | len ++; |
|
|
866 | |
|
|
867 | psiconv_progress(lev+2,off+len,"Going to read the default formats flag"); |
|
|
868 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
869 | if (res) |
|
|
870 | goto ERROR1; |
|
|
871 | len ++; |
|
|
872 | |
|
|
873 | if (temp & 0x01) { |
|
|
874 | psiconv_progress(lev+3,off+len,"Going to read the default paragraph codes"); |
|
|
875 | if ((res = psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng, |
|
|
876 | result->paragraph))) |
|
|
877 | goto ERROR1; |
|
|
878 | len += leng; |
|
|
879 | } |
|
|
880 | |
|
|
881 | if (temp & 0x02) { |
|
|
882 | psiconv_progress(lev+3,off+len,"Going to read the default character codes"); |
|
|
883 | if ((res = psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng, |
|
|
884 | result->character))) |
|
|
885 | goto ERROR1; |
|
|
886 | len += leng; |
|
|
887 | } |
|
|
888 | |
|
|
889 | if (temp & 0x04) { |
|
|
890 | psiconv_progress(lev+3,off+len, "Going to read the default number format"); |
|
|
891 | psiconv_parse_sheet_numberformat(buf,lev+3,off+len,&leng, |
|
|
892 | result->numberformat); |
|
|
893 | len += leng; |
|
|
894 | } |
|
|
895 | |
|
|
896 | if (length) |
|
|
897 | *length = len; |
|
|
898 | |
|
|
899 | psiconv_progress(lev,off+len-1, |
|
|
900 | "End of sheet cell layout (total length: %08x)", len); |
|
|
901 | |
|
|
902 | return 0; |
|
|
903 | |
|
|
904 | ERROR1: |
|
|
905 | psiconv_warn(lev+1,off,"Reading of sheet cell layout failed"); |
|
|
906 | if (length) |
|
|
907 | *length = 0; |
|
|
908 | if (!res) |
|
|
909 | return -PSICONV_E_NOMEM; |
|
|
910 | else |
|
|
911 | return res; |
|
|
912 | } |
|
|
913 | |
|
|
914 | |
|
|
915 | int psiconv_parse_sheet_worksheet(const psiconv_buffer buf, int lev, |
|
|
916 | psiconv_u32 off, int *length, |
|
|
917 | psiconv_sheet_worksheet *result) |
|
|
918 | { |
|
|
919 | int res=0; |
|
|
920 | psiconv_u32 temp,cells_off,grid_off,rows_off,cols_off; |
|
|
921 | int len=0; |
|
|
922 | int leng; |
|
|
923 | |
|
|
924 | psiconv_progress(lev+1,off,"Going to read the sheet worksheet section"); |
|
|
925 | if (!(*result = malloc(sizeof(**result)))) |
|
|
926 | goto ERROR1; |
|
|
927 | |
|
|
928 | psiconv_progress(lev+2,off+len, |
|
|
929 | "Going to read the initial bytes (%02x expected)",0x04); |
|
|
930 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
931 | if (res) |
|
|
932 | goto ERROR2; |
|
|
933 | if (temp != 0x04) { |
|
|
934 | psiconv_warn(lev+2,off+len, |
|
|
935 | "Worksheet section initial byte unknown value (ignored)"); |
|
|
936 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
937 | } |
|
|
938 | len ++; |
|
|
939 | |
|
|
940 | psiconv_progress(lev+2,off+len, "Going to read the flags byte"); |
|
|
941 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
942 | if (res) |
|
|
943 | goto ERROR2; |
|
|
944 | psiconv_debug(lev+2,off+len,"Flags byte: %02x",temp); |
|
|
945 | (*result)->show_zeros = (temp & 0x01)?psiconv_bool_true:psiconv_bool_false; |
|
|
946 | if (temp & 0xfe) { |
|
|
947 | psiconv_warn(lev+2,off+len, |
|
|
948 | "Worksheet section flags byte unknown bits (ignored)"); |
|
|
949 | } |
|
|
950 | len ++; |
|
|
951 | |
|
|
952 | psiconv_progress(lev+2,off+len,"Going to read the default cell layout"); |
|
|
953 | if (!((*result)->default_layout = psiconv_basic_cell_layout())) |
|
|
954 | goto ERROR2; |
|
|
955 | if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len,&leng, |
|
|
956 | (*result)->default_layout))) |
|
|
957 | goto ERROR3; |
|
|
958 | len += leng; |
|
|
959 | |
|
|
960 | psiconv_progress(lev+2,off+len, |
|
|
961 | "Going to read the offset of the row defaults Section"); |
|
|
962 | rows_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
963 | if (res) |
|
|
964 | goto ERROR3; |
|
|
965 | psiconv_debug(lev+2,off+len,"Offset: %04x",rows_off); |
|
|
966 | len += 4; |
|
|
967 | |
|
|
968 | psiconv_progress(lev+2,off+len, |
|
|
969 | "Going to read the offset of the column defaults Section"); |
|
|
970 | cols_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
971 | if (res) |
|
|
972 | goto ERROR3; |
|
|
973 | psiconv_debug(lev+2,off+len,"Offset: %04x",cols_off); |
|
|
974 | len += 4; |
|
|
975 | |
|
|
976 | psiconv_progress(lev+2,off+len, |
|
|
977 | "Going to read the offset of the Cells List"); |
|
|
978 | cells_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
979 | if (res) |
|
|
980 | goto ERROR3; |
|
|
981 | psiconv_debug(lev+2,off+len,"Offset: %04x",cells_off); |
|
|
982 | len += 4; |
|
|
983 | |
|
|
984 | psiconv_progress(lev+2,off+len, |
|
|
985 | "Going to read the offset of the Grid Section"); |
|
|
986 | grid_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
987 | if (res) |
|
|
988 | goto ERROR3; |
|
|
989 | psiconv_debug(lev+2,off+len,"Offset: %04x",grid_off); |
|
|
990 | len += 4; |
|
|
991 | |
|
|
992 | psiconv_progress(lev+2,off+len, |
|
|
993 | "Going to read the offset of the 3rd ??? Section"); |
|
|
994 | temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
|
|
995 | if (res) |
|
|
996 | goto ERROR3; |
|
|
997 | psiconv_debug(lev+2,off+len,"Offset: %04x",temp); |
|
|
998 | len += 4; |
|
|
999 | |
|
|
1000 | psiconv_progress(lev+2,off+len,"Going to read the row defaults"); |
|
|
1001 | if ((res = psiconv_parse_sheet_line_list(buf,lev+2,rows_off,NULL, |
|
|
1002 | &(*result)->row_default_layouts, |
|
|
1003 | (*result)->default_layout))) |
|
|
1004 | goto ERROR3; |
|
|
1005 | |
|
|
1006 | psiconv_progress(lev+2,off+len,"Going to read the column defaults"); |
|
|
1007 | if ((res = psiconv_parse_sheet_line_list(buf,lev+2,cols_off,NULL, |
|
|
1008 | &(*result)->col_default_layouts, |
|
|
1009 | (*result)->default_layout))) |
|
|
1010 | goto ERROR4; |
|
|
1011 | |
|
|
1012 | psiconv_progress(lev+2,off+len,"Going to read the cells list"); |
|
|
1013 | if ((res = psiconv_parse_sheet_cell_list(buf,lev+2,cells_off,NULL, |
|
|
1014 | &(*result)->cells, |
|
|
1015 | (*result)->default_layout, |
|
|
1016 | (*result)->row_default_layouts, |
|
|
1017 | (*result)->col_default_layouts))) |
|
|
1018 | goto ERROR5; |
|
|
1019 | |
|
|
1020 | |
|
|
1021 | /* TODO: parse grid section */ |
|
|
1022 | |
|
|
1023 | if (length) |
|
|
1024 | *length = len; |
|
|
1025 | |
|
|
1026 | psiconv_progress(lev,off+len-1, |
|
|
1027 | "End of sheet worksheet section (total length: %08x)", len); |
|
|
1028 | return 0; |
|
|
1029 | |
|
|
1030 | ERROR5: |
|
|
1031 | psiconv_free_sheet_line_list((*result)->col_default_layouts); |
|
|
1032 | ERROR4: |
|
|
1033 | psiconv_free_sheet_line_list((*result)->row_default_layouts); |
|
|
1034 | ERROR3: |
|
|
1035 | psiconv_free_sheet_cell_layout((*result)->default_layout); |
|
|
1036 | ERROR2: |
|
|
1037 | free (*result); |
|
|
1038 | ERROR1: |
|
|
1039 | psiconv_warn(lev+1,off,"Reading of Sheet Worksheet Section failed"); |
|
|
1040 | if (length) |
|
|
1041 | *length = 0; |
|
|
1042 | if (!res) |
|
|
1043 | return -PSICONV_E_NOMEM; |
|
|
1044 | else |
|
|
1045 | return res; |
|
|
1046 | } |
|
|
1047 | |
|
|
1048 | int psiconv_parse_sheet_line(const psiconv_buffer buf, int lev, |
|
|
1049 | psiconv_u32 off, int *length, |
|
|
1050 | psiconv_sheet_line *result, |
|
|
1051 | const psiconv_sheet_cell_layout default_layout) |
|
|
1052 | { |
|
|
1053 | int res=0; |
|
|
1054 | int len=0; |
|
|
1055 | int leng; |
|
|
1056 | |
|
|
1057 | |
|
|
1058 | psiconv_progress(lev+1,off,"Going to read a sheet line"); |
|
|
1059 | if (!(*result = malloc(sizeof(**result)))) |
|
|
1060 | goto ERROR1; |
|
|
1061 | |
|
|
1062 | psiconv_progress(lev+2,off+len,"Going to read the line number"); |
|
|
1063 | (*result)->position = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
|
|
1064 | if (res) |
|
|
1065 | goto ERROR2; |
|
|
1066 | psiconv_debug(lev+2,off+len,"Line number: %d\n",(*result)->position); |
|
|
1067 | len += leng; |
|
|
1068 | |
|
|
1069 | if (!((*result)->layout = psiconv_clone_cell_layout(default_layout))) |
|
|
1070 | goto ERROR2; |
|
|
1071 | if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len, |
|
|
1072 | &leng,(*result)->layout))) |
|
|
1073 | goto ERROR3; |
|
|
1074 | len += leng; |
|
|
1075 | |
|
|
1076 | if (length) |
|
|
1077 | *length = len; |
|
|
1078 | |
|
|
1079 | psiconv_progress(lev,off+len-1, |
|
|
1080 | "End of the sheet line (total length: %08x)", len); |
|
|
1081 | return 0; |
|
|
1082 | |
|
|
1083 | ERROR3: |
|
|
1084 | psiconv_free_sheet_cell_layout((*result)->layout); |
|
|
1085 | ERROR2: |
|
|
1086 | free (*result); |
|
|
1087 | ERROR1: |
|
|
1088 | psiconv_warn(lev+1,off,"Reading of the sheet line failed"); |
|
|
1089 | if (length) |
|
|
1090 | *length = 0; |
|
|
1091 | if (!res) |
|
|
1092 | return -PSICONV_E_NOMEM; |
|
|
1093 | else |
|
|
1094 | return res; |
|
|
1095 | } |
|
|
1096 | |
|
|
1097 | |
|
|
1098 | int psiconv_parse_sheet_line_list(const psiconv_buffer buf, int lev, |
|
|
1099 | psiconv_u32 off, int *length, |
|
|
1100 | psiconv_sheet_line_list *result, |
|
|
1101 | const psiconv_sheet_cell_layout default_layout) |
|
|
1102 | { |
|
|
1103 | int res=0; |
|
|
1104 | int len=0; |
|
|
1105 | psiconv_u32 temp; |
|
|
1106 | psiconv_sheet_line line; |
|
|
1107 | psiconv_u32 listlen,i; |
|
|
1108 | int leng; |
|
|
1109 | |
|
|
1110 | psiconv_progress(lev+1,off,"Going to read the sheet line list"); |
|
|
1111 | if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_line_s)))) |
|
|
1112 | goto ERROR1; |
|
|
1113 | |
|
|
1114 | psiconv_progress(lev+2,off+len, |
|
|
1115 | "Going to read the initial byte (%02x expected)",0x02); |
|
|
1116 | temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
|
|
1117 | if (res) |
|
|
1118 | goto ERROR2; |
|
|
1119 | if (temp != 0x02) { |
|
|
1120 | psiconv_warn(lev+2,off+len, |
|
|
1121 | "Sheet line list initial byte unknown value (ignored)"); |
|
|
1122 | psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
|
|
1123 | } |
|
|
1124 | len ++; |
|
|
1125 | |
|
|
1126 | psiconv_progress(lev+2,off+len, |
|
|
1127 | "Going to read the number of defined lines"); |
|
|
1128 | listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
|
|
1129 | if (res) |
|
|
1130 | goto ERROR2; |
|
|
1131 | psiconv_debug(lev+2,off+len,"Number of defined lines: %d",listlen); |
|
|
1132 | len += leng; |
|
|
1133 | |
|
|
1134 | psiconv_progress(lev+2,off+len,"Going to read all lines"); |
|
|
1135 | for (i = 0; i < listlen; i++) { |
|
|
1136 | psiconv_progress(lev+3,off+len,"Going to read line %d",i); |
|
|
1137 | if ((res = psiconv_parse_sheet_line(buf,lev+3,off+len,&leng,&line, |
|
|
1138 | default_layout))) |
|
|
1139 | goto ERROR2; |
|
|
1140 | if ((res = psiconv_list_add(*result,line))) |
|
|
1141 | goto ERROR3; |
|
|
1142 | free(line); |
|
|
1143 | len += leng; |
|
|
1144 | } |
|
|
1145 | |
|
|
1146 | if (length) |
|
|
1147 | *length = len; |
|
|
1148 | |
|
|
1149 | psiconv_progress(lev,off+len-1, |
|
|
1150 | "End of sheet line list (total length: %08x)", len); |
|
|
1151 | return 0; |
|
|
1152 | |
|
|
1153 | ERROR3: |
|
|
1154 | psiconv_free_sheet_line(line); |
|
|
1155 | ERROR2: |
|
|
1156 | psiconv_free_sheet_line_list(*result); |
|
|
1157 | ERROR1: |
|
|
1158 | psiconv_warn(lev+1,off,"Reading of Sheet Line List failed"); |
|
|
1159 | if (length) |
|
|
1160 | *length = 0; |
|
|
1161 | if (!res) |
|
|
1162 | return -PSICONV_E_NOMEM; |
|
|
1163 | else |
|
|
1164 | return res; |
|
|
1165 | } |
|
|
1166 | |