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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 351 - (hide annotations)
Wed Oct 22 19:53:40 2014 UTC (9 years, 5 months ago) by frodo
File MIME type: text/plain
File size: 72151 byte(s)
(Frodo) Update copyright year in all source files

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

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