/[public]/psiconv/trunk/lib/psiconv/parse_sheet.c
ViewVC logotype

Diff of /psiconv/trunk/lib/psiconv/parse_sheet.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 120 Revision 142
23#include <stdlib.h> 23#include <stdlib.h>
24 24
25#include "parse_routines.h" 25#include "parse_routines.h"
26#include "error.h" 26#include "error.h"
27 27
28#ifdef DMALLOC
29#include <dmalloc.h>
30#endif
31
32static 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;
46ERROR4:
47 psiconv_free_paragraph_layout(result->paragraph);
48ERROR3:
49 psiconv_free_character_layout(result->character);
50ERROR2:
51 free(result);
52ERROR1:
53 return NULL;
54}
55
56static 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;
73ERROR4:
74 psiconv_free_paragraph_layout(result->paragraph);
75ERROR3:
76 psiconv_free_character_layout(result->character);
77ERROR2:
78 free(result);
79ERROR1:
80 return NULL;
81}
82
83static 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;
134ERROR1:
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
143static 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;
217ERROR1:
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
28int psiconv_parse_sheet_numberformat(const psiconv_buffer buf, int lev, 226int psiconv_parse_sheet_numberformat(const psiconv_buffer buf, int lev,
29 psiconv_u32 off, int *length, 227 psiconv_u32 off, int *length,
30 psiconv_sheet_numberformat *result) 228 psiconv_sheet_numberformat result)
31{ 229{
32 int res=0; 230 int res=0;
33 int len=0; 231 int len=0;
34 psiconv_u8 temp; 232 psiconv_u8 temp;
35 233
36 psiconv_progress(lev+1,off,"Going to read a sheet numberformat"); 234 psiconv_progress(lev+1,off,"Going to read a sheet numberformat");
37 if (!(*result = malloc(sizeof(**result))))
38 goto ERROR1;
39 235
40 psiconv_progress(lev+2,off+len, 236 psiconv_progress(lev+2,off+len,
41 "Going to read the initial byte (%02x expected)",0x02); 237 "Going to read the initial byte (%02x expected)",0x02);
42 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 238 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
43 if (res) 239 if (res)
44 goto ERROR2; 240 goto ERROR1;
45 if (temp != 0x02) { 241 if (temp != 0x02) {
46 psiconv_warn(lev+2,off+len, 242 psiconv_warn(lev+2,off+len,
47 "Sheet numberformat initial byte unknown value (ignored)"); 243 "Sheet numberformat initial byte unknown value (ignored)");
48 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); 244 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
49 } 245 }
50 len ++; 246 len ++;
51 247
52 psiconv_progress(lev+2,off+len, "Going to read the code byte"); 248 psiconv_progress(lev+2,off+len, "Going to read the code byte");
53 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 249 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
54 if (res) 250 if (res)
55 goto ERROR2; 251 goto ERROR1;
56 psiconv_debug(lev+2,off+len,"Code: %02x",temp); 252 psiconv_debug(lev+2,off+len,"Code: %02x",temp);
57 if (temp == 0x00) 253 if (temp == 0x00)
58 (*result)->code = psiconv_numberformat_general; 254 result->code = psiconv_numberformat_general;
59 else if (temp == 0x02) 255 else if (temp == 0x02)
60 (*result)->code = psiconv_numberformat_fixeddecimal; 256 result->code = psiconv_numberformat_fixeddecimal;
61 else if (temp == 0x04) 257 else if (temp == 0x04)
62 (*result)->code = psiconv_numberformat_scientific; 258 result->code = psiconv_numberformat_scientific;
63 else if (temp == 0x06) 259 else if (temp == 0x06)
64 (*result)->code = psiconv_numberformat_currency; 260 result->code = psiconv_numberformat_currency;
65 else if (temp == 0x08) 261 else if (temp == 0x08)
66 (*result)->code = psiconv_numberformat_percent; 262 result->code = psiconv_numberformat_percent;
67 else if (temp == 0x0A) 263 else if (temp == 0x0A)
68 (*result)->code = psiconv_numberformat_triads; 264 result->code = psiconv_numberformat_triads;
69 else if (temp == 0x0C) 265 else if (temp == 0x0C)
70 (*result)->code = psiconv_numberformat_boolean; 266 result->code = psiconv_numberformat_boolean;
71 else if (temp == 0x0E) 267 else if (temp == 0x0E)
72 (*result)->code = psiconv_numberformat_text; 268 result->code = psiconv_numberformat_text;
73 else if (temp == 0x10) 269 else if (temp == 0x10)
74 (*result)->code = psiconv_numberformat_date_ddmm; 270 result->code = psiconv_numberformat_date_dmm;
75 else if (temp == 0x12) 271 else if (temp == 0x12)
76 (*result)->code = psiconv_numberformat_date_mmdd; 272 result->code = psiconv_numberformat_date_mmd;
77 else if (temp == 0x14) 273 else if (temp == 0x14)
78 (*result)->code = psiconv_numberformat_date_ddmmyy; 274 result->code = psiconv_numberformat_date_ddmmyy;
79 else if (temp == 0x16) 275 else if (temp == 0x16)
80 (*result)->code = psiconv_numberformat_date_mmddyy; 276 result->code = psiconv_numberformat_date_mmddyy;
81 else if (temp == 0x18) 277 else if (temp == 0x18)
82 (*result)->code = psiconv_numberformat_date_yymmdd; 278 result->code = psiconv_numberformat_date_yymmdd;
83 else if (temp == 0x1A) 279 else if (temp == 0x1A)
84 (*result)->code = psiconv_numberformat_date_ddmmm; 280 result->code = psiconv_numberformat_date_dmmm;
85 else if (temp == 0x1C) 281 else if (temp == 0x1C)
86 (*result)->code = psiconv_numberformat_date_ddmmmyy; 282 result->code = psiconv_numberformat_date_dmmmyy;
87 else if (temp == 0x1E) 283 else if (temp == 0x1E)
88 (*result)->code = psiconv_numberformat_date_ddmmmyyyy; 284 result->code = psiconv_numberformat_date_ddmmmyy;
89 else if (temp == 0x20) 285 else if (temp == 0x20)
90 (*result)->code = psiconv_numberformat_date_mmm; 286 result->code = psiconv_numberformat_date_mmm;
91 else if (temp == 0x22) 287 else if (temp == 0x22)
92 (*result)->code = psiconv_numberformat_date_monthname; 288 result->code = psiconv_numberformat_date_monthname;
93 else if (temp == 0x24) 289 else if (temp == 0x24)
94 (*result)->code = psiconv_numberformat_date_mmmyy; 290 result->code = psiconv_numberformat_date_mmmyy;
95 else if (temp == 0x26) 291 else if (temp == 0x26)
96 (*result)->code = psiconv_numberformat_date_monthnameyy; 292 result->code = psiconv_numberformat_date_monthnameyy;
97 else if (temp == 0x28) 293 else if (temp == 0x28)
98 (*result)->code = psiconv_numberformat_date_monthnameddyyyy; 294 result->code = psiconv_numberformat_date_monthnamedyyyy;
99 else if (temp == 0x2A) 295 else if (temp == 0x2A)
100 (*result)->code = psiconv_numberformat_datetime_ddmmyyyyhhii; 296 result->code = psiconv_numberformat_datetime_ddmmyyyyhhii;
101 else if (temp == 0x2C) 297 else if (temp == 0x2C)
102 (*result)->code = psiconv_numberformat_datetime_ddmmyyyyHHii; 298 result->code = psiconv_numberformat_datetime_ddmmyyyyHHii;
103 else if (temp == 0x2E) 299 else if (temp == 0x2E)
104 (*result)->code = psiconv_numberformat_datetime_mmddyyyyhhii; 300 result->code = psiconv_numberformat_datetime_mmddyyyyhhii;
105 else if (temp == 0x30) 301 else if (temp == 0x30)
106 (*result)->code = psiconv_numberformat_datetime_mmddyyyyHHii; 302 result->code = psiconv_numberformat_datetime_mmddyyyyHHii;
107 else if (temp == 0x32) 303 else if (temp == 0x32)
108 (*result)->code = psiconv_numberformat_datetime_yyyymmddhhii; 304 result->code = psiconv_numberformat_datetime_yyyymmddhhii;
109 else if (temp == 0x34) 305 else if (temp == 0x34)
110 (*result)->code = psiconv_numberformat_datetime_yyyymmddHHii; 306 result->code = psiconv_numberformat_datetime_yyyymmddHHii;
111 else if (temp == 0x36) 307 else if (temp == 0x36)
112 (*result)->code = psiconv_numberformat_time_hhii; 308 result->code = psiconv_numberformat_time_hhii;
113 else if (temp == 0x38) 309 else if (temp == 0x38)
114 (*result)->code = psiconv_numberformat_time_hhiiss; 310 result->code = psiconv_numberformat_time_hhiiss;
115 else if (temp == 0x3A) 311 else if (temp == 0x3A)
116 (*result)->code = psiconv_numberformat_time_HHii; 312 result->code = psiconv_numberformat_time_HHii;
117 else if (temp == 0x3C) 313 else if (temp == 0x3C)
118 (*result)->code = psiconv_numberformat_time_HHiiss; 314 result->code = psiconv_numberformat_time_HHiiss;
119 else { 315 else {
120 psiconv_warn(lev+2,off+len,"Unknown number format (assumed general)"); 316 psiconv_warn(lev+2,off+len,"Unknown number format (assumed general)");
121 (*result)->code = psiconv_numberformat_general; 317 result->code = psiconv_numberformat_general;
122 } 318 }
123 len ++; 319 len ++;
124 320
125 psiconv_progress(lev+2,off+len, "Going to read the number of decimals"); 321 psiconv_progress(lev+2,off+len, "Going to read the number of decimals");
126 (*result)->decimal = psiconv_read_u8(buf,lev+2,off+len,&res); 322 result->decimal = psiconv_read_u8(buf,lev+2,off+len,&res) >> 1;
127 if (res) 323 if (res)
128 goto ERROR2; 324 goto ERROR1;
129 psiconv_debug(lev+2,off+len,"Decimals: %d",(*result)->decimal); 325 psiconv_debug(lev+2,off+len,"Decimals: %d",result->decimal);
130 len ++; 326 len ++;
131 327
132 if (length) 328 if (length)
133 *length = len; 329 *length = len;
134 330
135 psiconv_progress(lev,off+len-1, 331 psiconv_progress(lev,off+len-1,
136 "End of sheet number format (total length: %08x)", len); 332 "End of sheet number format (total length: %08x)", len);
137 return 0; 333 return 0;
138 334
139ERROR2:
140 free (*result);
141ERROR1: 335ERROR1:
142 psiconv_warn(lev+1,off,"Reading of Sheet Number Format failed"); 336 psiconv_warn(lev+1,off,"Reading of Sheet Number Format failed");
143 if (length) 337 if (length)
144 *length = 0; 338 *length = 0;
145 if (!res) 339 if (!res)
264 if (res) 458 if (res)
265 goto ERROR2; 459 goto ERROR2;
266 if (temp != 0x00) { 460 if (temp != 0x00) {
267 psiconv_warn(lev+2,off+len, 461 psiconv_warn(lev+2,off+len,
268 "Sheet status section unknown byte unknown value (ignored)"); 462 "Sheet status section unknown byte unknown value (ignored)");
269 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); 463 psiconv_debug(lev+2,off+len,"Unknown byte: %02x",temp);
270 } 464 }
271 len ++; 465 len ++;
272 466
273 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");
274 (*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);
307 501
308int psiconv_parse_sheet_workbook_section(const psiconv_buffer buf, int lev, 502int psiconv_parse_sheet_workbook_section(const psiconv_buffer buf, int lev,
309 psiconv_u32 off, int *length, 503 psiconv_u32 off, int *length,
310 psiconv_sheet_workbook_section *result) 504 psiconv_sheet_workbook_section *result)
311{ 505{
312 int res=0; 506 int res=0,with_name;
313 psiconv_u32 temp,formulas_off,worksheets_off; 507 psiconv_u32 temp,formulas_off,worksheets_off,info_off,var_off,name_off=0;
314 int len=0; 508 int len=0;
315 509
316 psiconv_progress(lev+1,off,"Going to read the sheet workbook section"); 510 psiconv_progress(lev+1,off,"Going to read the sheet workbook section");
317 if (!(*result = malloc(sizeof(**result)))) 511 if (!(*result = malloc(sizeof(**result))))
318 goto ERROR1; 512 goto ERROR1;
319 513
320 psiconv_progress(lev+2,off+len, 514 psiconv_progress(lev+2,off+len,
321 "Going to read the initial byte (%02x expected)",0x04); 515 "Going to read the initial byte (%02x or %02x expected)",
516 0x02,0x04);
322 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 517 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
323 if (res) 518 if (res)
324 goto ERROR2; 519 goto ERROR2;
325 if (temp != 0x04) { 520 if ((temp != 0x04) && temp !=0x02) {
326 psiconv_warn(lev+2,off+len, 521 psiconv_warn(lev+2,off+len,
327 "Sheet workbook section initial byte unknown value (ignored)"); 522 "Sheet workbook section initial byte unknown value (ignored)");
328 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); 523 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
329 } 524 }
525 with_name = temp ==0x04;
330 len ++; 526 len ++;
331 527
332 psiconv_progress(lev+2,off+len, 528 psiconv_progress(lev+2,off+len,
333 "Going to read the offset of the 1st ??? Section"); 529 "Going to read the offset of the sheet info Section");
334 temp = psiconv_read_u32(buf,lev+2,off+len,&res); 530 info_off = psiconv_read_u32(buf,lev+2,off+len,&res);
335 if (res) 531 if (res)
336 goto ERROR2; 532 goto ERROR2;
337 psiconv_debug(lev+2,off+len,"Offset: %04x",temp); 533 psiconv_debug(lev+2,off+len,"Offset: %04x",info_off);
338 len += 4; 534 len += 4;
339 535
340 psiconv_progress(lev+2,off+len, 536 psiconv_progress(lev+2,off+len,
341 "Going to read the offset of the Formulas List"); 537 "Going to read the offset of the Formulas List");
342 formulas_off = psiconv_read_u32(buf,lev+2,off+len,&res); 538 formulas_off = psiconv_read_u32(buf,lev+2,off+len,&res);
352 goto ERROR2; 548 goto ERROR2;
353 psiconv_debug(lev+2,off+len,"Offset: %04x",worksheets_off); 549 psiconv_debug(lev+2,off+len,"Offset: %04x",worksheets_off);
354 len += 4; 550 len += 4;
355 551
356 psiconv_progress(lev+2,off+len, 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,
357 "Going to read the offset of the 4th ??? Section"); 562 "Going to read the offset of the Name Section");
358 temp = psiconv_read_u32(buf,lev+2,off+len,&res); 563 name_off = psiconv_read_u32(buf,lev+2,off+len,&res);
359 if (res) 564 if (res)
360 goto ERROR2; 565 goto ERROR2;
361 psiconv_debug(lev+2,off+len,"Offset: %04x",temp); 566 psiconv_debug(lev+2,off+len,"Offset: %04x",name_off);
362 len += 4; 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;
363 580
364 psiconv_progress(lev+2,off+len,"Going to read the formulas list"); 581 psiconv_progress(lev+2,off+len,"Going to read the formulas list");
365 if ((res = psiconv_parse_sheet_formula_table(buf,lev+2,formulas_off,NULL, 582 if ((res = psiconv_parse_sheet_formula_list(buf,lev+2,formulas_off,NULL,
366 &(*result)->formulas))) 583 &(*result)->formulas)))
367 goto ERROR2; 584 goto ERROR4;
368 585
369 psiconv_progress(lev+2,off+len,"Going to read the worksheet list"); 586 psiconv_progress(lev+2,off+len,"Going to read the worksheet list");
370 if ((res = psiconv_parse_sheet_worksheet_list(buf,lev+2,worksheets_off, 587 if ((res = psiconv_parse_sheet_worksheet_list(buf,lev+2,worksheets_off,
371 NULL,&(*result)->worksheets))) 588 NULL,&(*result)->worksheets)))
372 goto ERROR2; 589 goto ERROR5;
373 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;
374 598
375 if (length) 599 if (length)
376 *length = len; 600 *length = len;
377 601
378 psiconv_progress(lev,off+len-1, 602 psiconv_progress(lev,off+len-1,
379 "End of sheet workbook section (total length: %08x)", len); 603 "End of sheet workbook section (total length: %08x)", len);
380 return 0; 604 return 0;
381 605
606ERROR6:
607 psiconv_free_sheet_worksheet_list((*result)->worksheets);
608ERROR5:
609 psiconv_free_formula_list((*result)->formulas);
610ERROR4:
611 psiconv_free_sheet_variable_list((*result)->variables);
612ERROR3:
613 psiconv_free_sheet_info_section((*result)->info);
382ERROR2: 614ERROR2:
383 free (*result); 615 free (*result);
384ERROR1: 616ERROR1:
385 psiconv_warn(lev+1,off,"Reading of Sheet Workbook Section failed"); 617 psiconv_warn(lev+1,off,"Reading of Sheet Workbook Section failed");
386 if (length) 618 if (length)
389 return -PSICONV_E_NOMEM; 621 return -PSICONV_E_NOMEM;
390 else 622 else
391 return res; 623 return res;
392} 624}
393 625
626int 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
663ERROR2:
664 free(*result);
665ERROR1:
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
675int 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
729ERROR2:
730 free(*result);
731ERROR1:
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
394int psiconv_parse_sheet_formula_table(const psiconv_buffer buf, int lev, 741int psiconv_parse_sheet_formula_list(const psiconv_buffer buf, int lev,
395 psiconv_u32 off, int *length, 742 psiconv_u32 off, int *length,
396 psiconv_formula_list *result) 743 psiconv_formula_list *result)
397{ 744{
398 int res=0; 745 int res=0;
399 int len=0; 746 int len=0;
400 psiconv_u32 temp; 747 psiconv_u32 temp;
401 psiconv_formula formula; 748 psiconv_formula formula;
402 psiconv_u32 listlen,i; 749 psiconv_u32 listlen,i;
403 int leng; 750 int leng;
404 751
405 psiconv_progress(lev+1,off,"Going to read the sheet formula table"); 752 psiconv_progress(lev+1,off,"Going to read the sheet formula list");
406 if (!(*result = psiconv_list_new(sizeof(struct psiconv_formula_s)))) 753 if (!(*result = psiconv_list_new(sizeof(struct psiconv_formula_s))))
407 goto ERROR1; 754 goto ERROR1;
408 755
409 psiconv_progress(lev+2,off+len, 756 psiconv_progress(lev+2,off+len,
410 "Going to read the initial byte (%02x expected)",0x02); 757 "Going to read the initial byte (%02x expected)",0x02);
411 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 758 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
412 if (res) 759 if (res)
413 goto ERROR2; 760 goto ERROR2;
414 if (temp != 0x02) { 761 if (temp != 0x02) {
415 psiconv_warn(lev+2,off+len, 762 psiconv_warn(lev+2,off+len,
416 "Sheet formula table initial byte unknown value (ignored)"); 763 "Sheet formula list initial byte unknown value (ignored)");
417 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); 764 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
418 } 765 }
419 len ++; 766 len ++;
420 767
421 psiconv_progress(lev+2,off+len, 768 psiconv_progress(lev+2,off+len,
431 psiconv_progress(lev+3,off+len,"Going to read formula %d",i); 778 psiconv_progress(lev+3,off+len,"Going to read formula %d",i);
432 if ((res = psiconv_parse_formula(buf,lev+3,off+len,&leng,&formula))) 779 if ((res = psiconv_parse_formula(buf,lev+3,off+len,&leng,&formula)))
433 goto ERROR2; 780 goto ERROR2;
434 if ((res = psiconv_list_add(*result,formula))) 781 if ((res = psiconv_list_add(*result,formula)))
435 goto ERROR3; 782 goto ERROR3;
783 free(formula);
436 len += leng; 784 len += leng;
437 } 785 }
438 786
439 if (length) 787 if (length)
440 *length = len; 788 *length = len;
441 789
442 psiconv_progress(lev,off+len-1, 790 psiconv_progress(lev,off+len-1,
443 "End of sheet formula table (total length: %08x)", len); 791 "End of sheet formula list (total length: %08x)", len);
444 return 0; 792 return 0;
445 793
446ERROR3: 794ERROR3:
447 psiconv_free_formula(formula); 795 psiconv_free_formula(formula);
448ERROR2: 796ERROR2:
449 psiconv_list_free(*result); 797 psiconv_list_free(*result);
450ERROR1: 798ERROR1:
451 psiconv_warn(lev+1,off,"Reading of Sheet Formula Table failed"); 799 psiconv_warn(lev+1,off,"Reading of Sheet Formula list failed");
452 if (length) 800 if (length)
453 *length = 0; 801 *length = 0;
454 if (!res) 802 if (!res)
455 return -PSICONV_E_NOMEM; 803 return -PSICONV_E_NOMEM;
456 else 804 else
457 return res; 805 return res;
458} 806}
459 807
460int psiconv_parse_sheet_cell(const psiconv_buffer buf, int lev, 808int psiconv_parse_sheet_cell(const psiconv_buffer buf, int lev,
461 psiconv_u32 off, int *length, 809 psiconv_u32 off, int *length,
462 psiconv_sheet_cell *result) 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)
463{ 814{
464 int res=0; 815 int res=0;
465 int len=0; 816 int len=0;
466 psiconv_u32 temp; 817 psiconv_u32 temp;
467 psiconv_bool_t has_layout; 818 psiconv_bool_t has_layout;
574 psiconv_warn(lev+2,off+len,"Unknown Sheet Cell type: %02x",(*result)->type); 925 psiconv_warn(lev+2,off+len,"Unknown Sheet Cell type: %02x",(*result)->type);
575 res = PSICONV_E_PARSE; 926 res = PSICONV_E_PARSE;
576 goto ERROR2; 927 goto ERROR2;
577 } 928 }
578 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;
579 if (has_layout) { 937 if (has_layout) {
580 if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len, 938 if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len,
581 &leng,&(*result)->layout))) 939 &leng,(*result)->layout)))
582 goto ERROR2; 940 goto ERROR2;
583 len += leng; 941 len += leng;
584 } 942 }
585 943
586 if ((*result)->calculated) { 944 if ((*result)->calculated) {
611 else 969 else
612 return res; 970 return res;
613} 971}
614 972
615int psiconv_parse_sheet_cell_list(const psiconv_buffer buf, int lev, 973int psiconv_parse_sheet_cell_list(const psiconv_buffer buf, int lev,
616 psiconv_u32 off, int *length, 974 psiconv_u32 off, int *length,
617 psiconv_sheet_cell_list *result) 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)
618{ 979{
619 int res=0; 980 int res=0;
620 int len=0; 981 int len=0;
621 psiconv_u32 temp; 982 psiconv_u32 temp;
622 psiconv_sheet_cell cell; 983 psiconv_sheet_cell cell;
660 len += leng; 1021 len += leng;
661 1022
662 psiconv_progress(lev+2,off+len,"Going to read all cells"); 1023 psiconv_progress(lev+2,off+len,"Going to read all cells");
663 for (i = 0; i < listlen; i++) { 1024 for (i = 0; i < listlen; i++) {
664 psiconv_progress(lev+3,off+len,"Going to read cell %d",i); 1025 psiconv_progress(lev+3,off+len,"Going to read cell %d",i);
665 if ((res = psiconv_parse_sheet_cell(buf,lev+3,off+len,&leng,&cell))) 1026 if ((res = psiconv_parse_sheet_cell(buf,lev+3,off+len,&leng,&cell,
1027 default_layout,row_default_layouts,
1028 col_default_layouts)))
666 goto ERROR2; 1029 goto ERROR2;
667 if ((res = psiconv_list_add(*result,cell))) 1030 if ((res = psiconv_list_add(*result,cell)))
668 goto ERROR3; 1031 goto ERROR3;
669 free(cell); 1032 free(cell);
670 len += leng; 1033 len += leng;
778 return res; 1141 return res;
779} 1142}
780 1143
781int psiconv_parse_sheet_cell_layout(const psiconv_buffer buf, int lev, 1144int psiconv_parse_sheet_cell_layout(const psiconv_buffer buf, int lev,
782 psiconv_u32 off, int *length, 1145 psiconv_u32 off, int *length,
783 psiconv_sheet_cell_layout *result) 1146 psiconv_sheet_cell_layout result)
784 1147
785{ 1148{
786 int res=0; 1149 int res=0;
787 int len=0; 1150 int len=0;
788 int leng; 1151 int leng;
789 psiconv_u8 temp; 1152 psiconv_u8 temp;
790 1153
791 psiconv_progress(lev+1,off,"Going to read a sheet cell layout"); 1154 psiconv_progress(lev+1,off,"Going to read a sheet cell layout");
792 if (!(*result = malloc(sizeof(**result))))
793 goto ERROR1;
794 1155
795 (*result)->character = NULL;
796 (*result)->paragraph = NULL;
797 (*result)->numberformat = NULL;
798
799 psiconv_progress(lev+2,off+len, 1156 psiconv_progress(lev+2,off+len,
800 "Going to read the first byte (%02x expected)",0x02); 1157 "Going to read the first byte (%02x expected)",0x02);
801 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 1158 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
802 if (res) 1159 if (res)
803 goto ERROR2; 1160 goto ERROR1;
804 if (temp != 0x02) { 1161 if (temp != 0x02) {
805 psiconv_warn(lev+2,off+len, 1162 psiconv_warn(lev+2,off+len,
806 "Worksheet section initial byte unknown value (ignored)"); 1163 "Worksheet section initial byte unknown value (ignored)");
807 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); 1164 psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
808 } 1165 }
809 len ++; 1166 len ++;
810 1167
811 psiconv_progress(lev+2,off+len,"Going to read the default formats flag"); 1168 psiconv_progress(lev+2,off+len,"Going to read the default formats flag");
812 temp = psiconv_read_u8(buf,lev+2,off+len,&res); 1169 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
813 if (res) 1170 if (res)
814 goto ERROR2; 1171 goto ERROR1;
815 len ++; 1172 len ++;
816 1173
817 if (temp & 0x01) { 1174 if (temp & 0x01) {
818 if (!((*result)->paragraph = psiconv_basic_paragraph_layout()))
819 goto ERROR2;
820 psiconv_progress(lev+3,off+len,"Going to read the default paragraph codes"); 1175 psiconv_progress(lev+3,off+len,"Going to read the default paragraph codes");
821 if ((res = psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng, 1176 if ((res = psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng,
822 (*result)->paragraph))) 1177 result->paragraph)))
823 goto ERROR2; 1178 goto ERROR1;
824 len += leng; 1179 len += leng;
825 } 1180 }
826 1181
827 if (temp & 0x02) { 1182 if (temp & 0x02) {
828 psiconv_progress(lev+3,off+len,"Going to read the default character codes"); 1183 psiconv_progress(lev+3,off+len,"Going to read the default character codes");
829 if (!((*result)->character = psiconv_basic_character_layout()))
830 goto ERROR2;
831 if ((res = psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng, 1184 if ((res = psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng,
832 (*result)->character))) 1185 result->character)))
833 goto ERROR2; 1186 goto ERROR1;
834 len += leng; 1187 len += leng;
835 } 1188 }
836 1189
837 if (temp & 0x04) { 1190 if (temp & 0x04) {
838 psiconv_progress(lev+3,off+len, "Going to read the default number format"); 1191 psiconv_progress(lev+3,off+len, "Going to read the default number format");
839 psiconv_parse_sheet_numberformat(buf,lev+3,off+len,&leng, 1192 psiconv_parse_sheet_numberformat(buf,lev+3,off+len,&leng,
840 &(*result)->numberformat); 1193 result->numberformat);
841 len += leng; 1194 len += leng;
842 } 1195 }
843 1196
844 if (length) 1197 if (length)
845 *length = len; 1198 *length = len;
847 psiconv_progress(lev,off+len-1, 1200 psiconv_progress(lev,off+len-1,
848 "End of sheet cell layout (total length: %08x)", len); 1201 "End of sheet cell layout (total length: %08x)", len);
849 1202
850 return 0; 1203 return 0;
851 1204
852ERROR2:
853 psiconv_free_sheet_cell_layout(*result);
854ERROR1: 1205ERROR1:
855 psiconv_warn(lev+1,off,"Reading of sheet cell layout failed"); 1206 psiconv_warn(lev+1,off,"Reading of sheet cell layout failed");
856 if (length) 1207 if (length)
857 *length = 0; 1208 *length = 0;
858 if (!res) 1209 if (!res)
865int psiconv_parse_sheet_worksheet(const psiconv_buffer buf, int lev, 1216int psiconv_parse_sheet_worksheet(const psiconv_buffer buf, int lev,
866 psiconv_u32 off, int *length, 1217 psiconv_u32 off, int *length,
867 psiconv_sheet_worksheet *result) 1218 psiconv_sheet_worksheet *result)
868{ 1219{
869 int res=0; 1220 int res=0;
870 psiconv_u32 temp,cells_off,grid_off; 1221 psiconv_u32 temp,cells_off,grid_off,rows_off,cols_off,unknown_off;
871 int len=0; 1222 int len=0;
872 int leng; 1223 int leng;
873 1224
874 psiconv_progress(lev+1,off,"Going to read the sheet worksheet section"); 1225 psiconv_progress(lev+1,off,"Going to read the sheet worksheet section");
875 if (!(*result = malloc(sizeof(**result)))) 1226 if (!(*result = malloc(sizeof(**result))))
898 "Worksheet section flags byte unknown bits (ignored)"); 1249 "Worksheet section flags byte unknown bits (ignored)");
899 } 1250 }
900 len ++; 1251 len ++;
901 1252
902 psiconv_progress(lev+2,off+len,"Going to read the default cell layout"); 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;
903 if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len,&leng, 1256 if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len,&leng,
904 &(*result)->default_layout))) 1257 (*result)->default_layout)))
905 goto ERROR2; 1258 goto ERROR3;
906 len += leng; 1259 len += leng;
907 1260
908 psiconv_progress(lev+2,off+len, 1261 psiconv_progress(lev+2,off+len,
909 "Going to read the offset of the 1st ??? Section"); 1262 "Going to read the offset of the row defaults Section");
910 temp = psiconv_read_u32(buf,lev+2,off+len,&res); 1263 rows_off = psiconv_read_u32(buf,lev+2,off+len,&res);
911 if (res) 1264 if (res)
912 goto ERROR3; 1265 goto ERROR3;
913 psiconv_debug(lev+2,off+len,"Offset: %04x",temp); 1266 psiconv_debug(lev+2,off+len,"Offset: %04x",rows_off);
914 len += 4; 1267 len += 4;
915 1268
916 psiconv_progress(lev+2,off+len, 1269 psiconv_progress(lev+2,off+len,
917 "Going to read the offset of the 2nd ??? Section"); 1270 "Going to read the offset of the column defaults Section");
918 temp = psiconv_read_u32(buf,lev+2,off+len,&res); 1271 cols_off = psiconv_read_u32(buf,lev+2,off+len,&res);
919 if (res) 1272 if (res)
920 goto ERROR3; 1273 goto ERROR3;
921 psiconv_debug(lev+2,off+len,"Offset: %04x",temp); 1274 psiconv_debug(lev+2,off+len,"Offset: %04x",cols_off);
922 len += 4; 1275 len += 4;
923 1276
924 psiconv_progress(lev+2,off+len, 1277 psiconv_progress(lev+2,off+len,
925 "Going to read the offset of the Cells List"); 1278 "Going to read the offset of the Cells List");
926 cells_off = psiconv_read_u32(buf,lev+2,off+len,&res); 1279 cells_off = psiconv_read_u32(buf,lev+2,off+len,&res);
937 psiconv_debug(lev+2,off+len,"Offset: %04x",grid_off); 1290 psiconv_debug(lev+2,off+len,"Offset: %04x",grid_off);
938 len += 4; 1291 len += 4;
939 1292
940 psiconv_progress(lev+2,off+len, 1293 psiconv_progress(lev+2,off+len,
941 "Going to read the offset of the 3rd ??? Section"); 1294 "Going to read the offset of the 3rd ??? Section");
942 temp = psiconv_read_u32(buf,lev+2,off+len,&res); 1295 unknown_off = psiconv_read_u32(buf,lev+2,off+len,&res);
943 if (res) 1296 if (res)
944 goto ERROR3; 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)");
945 psiconv_debug(lev+2,off+len,"Offset: %04x",temp); 1310 psiconv_debug(lev+2,unknown_off,"Offset: %04x",temp);
1311 }
946 len += 4; 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;
947 1325
948 psiconv_progress(lev+2,off+len,"Going to read the cells list"); 1326 psiconv_progress(lev+2,off+len,"Going to read the cells list");
949 if ((res = psiconv_parse_sheet_cell_list(buf,lev+2,cells_off,NULL, 1327 if ((res = psiconv_parse_sheet_cell_list(buf,lev+2,cells_off,NULL,
950 &(*result)->cells))) 1328 &(*result)->cells,
1329 (*result)->default_layout,
1330 (*result)->row_default_layouts,
1331 (*result)->col_default_layouts)))
951 goto ERROR3; 1332 goto ERROR5;
952 1333
953 1334
954/* TODO: parse grid section */ 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
955 1341
956 if (length) 1342 if (length)
957 *length = len; 1343 *length = len;
958 1344
959 psiconv_progress(lev,off+len-1, 1345 psiconv_progress(lev,off+len-1,
960 "End of sheet worksheet section (total length: %08x)", len); 1346 "End of sheet worksheet section (total length: %08x)", len);
961 return 0; 1347 return 0;
962 1348
1349ERROR6:
1350 psiconv_free_sheet_cell_list((*result)->cells);
1351ERROR5:
1352 psiconv_free_sheet_line_list((*result)->col_default_layouts);
1353ERROR4:
1354 psiconv_free_sheet_line_list((*result)->row_default_layouts);
963ERROR3: 1355ERROR3:
964 psiconv_free_sheet_cell_layout((*result)->default_layout); 1356 psiconv_free_sheet_cell_layout((*result)->default_layout);
965ERROR2: 1357ERROR2:
966 free (*result); 1358 free (*result);
967ERROR1: 1359ERROR1:
972 return -PSICONV_E_NOMEM; 1364 return -PSICONV_E_NOMEM;
973 else 1365 else
974 return res; 1366 return res;
975} 1367}
976 1368
1369int 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;
977 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
1404ERROR3:
1405 psiconv_free_sheet_cell_layout((*result)->layout);
1406ERROR2:
1407 free (*result);
1408ERROR1:
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
1419int 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
1474ERROR3:
1475 psiconv_free_sheet_line(line);
1476ERROR2:
1477 psiconv_free_sheet_line_list(*result);
1478ERROR1:
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
1488int 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
1576ERROR4:
1577 if ((*result)->type == psiconv_var_string)
1578 free((*result)->data.dat_string);
1579ERROR3:
1580 free((*result)->name);
1581ERROR2:
1582 free (*result);
1583ERROR1:
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
1594int 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
1646ERROR3:
1647 psiconv_free_sheet_variable(variable);
1648ERROR2:
1649 psiconv_list_free(*result);
1650ERROR1:
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
1660int 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
1907ERROR6:
1908 psiconv_free_sheet_grid_break_list((*result)->column_page_breaks);
1909ERROR5:
1910 psiconv_free_sheet_grid_break_list((*result)->row_page_breaks);
1911ERROR4:
1912 psiconv_free_sheet_grid_size_list((*result)->column_heights);
1913ERROR3:
1914 psiconv_free_sheet_grid_size_list((*result)->row_heights);
1915ERROR2:
1916 free(*result);
1917ERROR1:
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
1928int 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
1967ERROR3:
1968 psiconv_free_sheet_grid_size(size);
1969ERROR2:
1970 psiconv_list_free(*result);
1971ERROR1:
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
1981int 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
2015ERROR2:
2016 free (*result);
2017ERROR1:
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
2028int 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
2067ERROR2:
2068 psiconv_list_free(*result);
2069ERROR1:
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

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

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