/[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 168 - (hide annotations)
Tue Nov 25 17:57:05 2003 UTC (20 years, 5 months ago) by frodo
File MIME type: text/plain
File size: 72091 byte(s)
(Frodo) config stuff and image generation stuff

* All parse and generate functions have a new config parameter
* New files configuration.[ch] in the psiconv lib
* Some image generation stuff (not ready, but won't do any harm)

1 frodo 94 /*
2     parse_sheet.c - Part of psiconv, a PSION 5 file formats converter
3     Copyright (c) 2001 Frodo Looijaard <frodol@dds.nl>
4    
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 168 psiconv_warn(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 168 psiconv_warn(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 168 psiconv_warn(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 168 psiconv_warn(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 168 psiconv_warn(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 168 psiconv_warn(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 168 psiconv_warn(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 168 psiconv_warn(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    
830 frodo 168 psiconv_progress(config,lev+1,off,"Going to read a sheet cell structure");
831 frodo 110 if (!(*result = malloc(sizeof(**result))))
832     goto ERROR1;
833    
834 frodo 111 (*result)->layout = NULL;
835     (*result)->type = psiconv_cell_blank;
836    
837 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the cell position");
838     temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
839 frodo 110 if (res)
840     goto ERROR2;
841     len ++;
842 frodo 168 temp += psiconv_read_u8(config,buf,lev+2,off+len,&res) << 8;
843 frodo 110 if (res)
844     goto ERROR2;
845     len ++;
846 frodo 168 temp += psiconv_read_u8(config,buf,lev+2,off+len,&res) << 16;
847 frodo 110 if (res)
848     goto ERROR2;
849     len ++;
850     (*result)->column = (temp >> 2) & 0xFF;
851     (*result)->row = (temp >> 10) & 0x3FFF;
852 frodo 168 psiconv_debug(config,lev+2,off+len,"Cell position is col:%02x row:%04x",
853 frodo 110 (*result)->column,(*result)->row);
854 frodo 111 if (temp & 0x03) {
855 frodo 168 psiconv_warn(config,lev+2,off+len,"Unknown flags in cell position (ignored)");
856     psiconv_debug(config,lev+2,off+len,"Flags: %02x",temp & 0x03);
857 frodo 111 }
858 frodo 110
859 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the cell type");
860     temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
861 frodo 110 if (res)
862     goto ERROR2;
863     len ++;
864     (*result)->type = (temp >> 5) & 0x07;
865     (*result)->calculated = (temp & 0x08)?psiconv_bool_true:psiconv_bool_false;
866     has_layout = (temp & 0x10)?psiconv_bool_true:psiconv_bool_false;
867    
868 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the cell value");
869 frodo 110 if ((*result)->type == psiconv_cell_blank) {
870 frodo 168 psiconv_debug(config,lev+2,off+len,"Cell type is blank: no value given.");
871 frodo 110 } else if ((*result)->type == psiconv_cell_int) {
872 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read an integer");
873     (*result)->data.dat_int = psiconv_read_u32(config,buf,lev+2,off+len,&res);
874 frodo 110 if (res)
875     goto ERROR2;
876     len += 4;
877 frodo 168 psiconv_debug(config,lev+2,off+len,"Cell contents: %ld",(*result)->data.dat_int);
878 frodo 110
879     } else if ((*result)->type == psiconv_cell_bool) {
880 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read a boolean");
881     if ((res = psiconv_parse_bool(config,buf,lev+2,off+len,&leng,
882 frodo 111 &(*result)->data.dat_bool)))
883 frodo 110 goto ERROR2;
884 frodo 168 psiconv_debug(config,lev+2,off+len,"Cell contents: %01x",temp);
885 frodo 110 (*result)->data.dat_bool = temp?psiconv_bool_true:psiconv_bool_false;
886 frodo 111 len += leng;
887 frodo 110 } else if ((*result)->type == psiconv_cell_error) {
888 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the error code");
889     temp = psiconv_read_u16(config,buf,lev+2,off+len,&res);
890 frodo 111 if (res)
891     goto ERROR2;
892     if (temp == 0)
893     (*result)->data.dat_error = psiconv_sheet_error_none;
894     else if (temp == 1)
895     (*result)->data.dat_error = psiconv_sheet_error_null;
896     else if (temp == 2)
897     (*result)->data.dat_error = psiconv_sheet_error_divzero;
898     else if (temp == 3)
899     (*result)->data.dat_error = psiconv_sheet_error_value;
900     else if (temp == 4)
901     (*result)->data.dat_error = psiconv_sheet_error_reference;
902     else if (temp == 5)
903     (*result)->data.dat_error = psiconv_sheet_error_name;
904     else if (temp == 6)
905     (*result)->data.dat_error = psiconv_sheet_error_number;
906     else if (temp == 7)
907     (*result)->data.dat_error = psiconv_sheet_error_notavail;
908     else {
909 frodo 168 psiconv_warn(config,lev+2,off+len,"Unknown error code (default assumed)");
910     psiconv_debug(config,lev+2,off+len,"Error code: %04x",temp);
911 frodo 111 (*result)->data.dat_error = psiconv_sheet_error_none;
912     }
913 frodo 168 psiconv_debug(config,lev+2,off+len,"Cell contents: %04x",
914 frodo 111 (*result)->data.dat_error);
915     len += 2;
916 frodo 110 } else if ((*result)->type == psiconv_cell_float) {
917 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read a float");
918 frodo 110 (*result)->data.dat_float =
919 frodo 168 psiconv_read_float(config,buf,lev+2,off+len,&leng,&res);
920 frodo 111 if (res)
921     goto ERROR2;
922 frodo 168 psiconv_debug(config,lev+2,off+len,"Cell contents: %f",(*result)->data.dat_float);
923 frodo 111 len += leng;
924 frodo 110 } else if ((*result)->type == psiconv_cell_string) {
925 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read a string");
926 frodo 110 (*result)->data.dat_string =
927 frodo 168 psiconv_read_string(config,buf,lev+2,off+len,&leng,&res);
928 frodo 111 if (res)
929     goto ERROR2;
930 frodo 168 psiconv_debug(config,lev+2,off+len,"Cell contents: `%s'",
931 frodo 110 (*result)->data.dat_string);
932 frodo 111 len += leng;
933 frodo 110 } else {
934 frodo 168 psiconv_warn(config,lev+2,off+len,"Unknown Sheet Cell type: %02x",(*result)->type);
935 frodo 111 res = PSICONV_E_PARSE;
936     goto ERROR2;
937 frodo 110 }
938    
939 frodo 128 if (!((*result)->layout = psiconv_clone_cell_layout(
940     psiconv_get_default_layout(row_default_layouts,
941     col_default_layouts,
942     default_layout,
943     (*result)->row,
944     (*result)->column))))
945 frodo 121 goto ERROR2;
946 frodo 110 if (has_layout) {
947 frodo 168 if ((res = psiconv_parse_sheet_cell_layout(config,buf,lev+2,off+len,
948 frodo 121 &leng,(*result)->layout)))
949 frodo 110 goto ERROR2;
950 frodo 111 len += leng;
951 frodo 110 }
952    
953     if ((*result)->calculated) {
954 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the cell formula reference");
955     temp = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res);
956 frodo 110 if (res)
957     goto ERROR2;
958 frodo 168 psiconv_debug(config,lev+2,off+len,"Cell formula reference: %d",temp);
959 frodo 110 len += leng;
960 frodo 111 (*result)->ref_formula = temp;
961 frodo 110 }
962    
963     if (length)
964     *length = len;
965    
966 frodo 168 psiconv_progress(config,lev,off+len-1,
967 frodo 110 "End of sheet cell structure (total length: %08x)", len);
968     return 0;
969    
970     ERROR2:
971     psiconv_free_sheet_cell(*result);
972     ERROR1:
973 frodo 168 psiconv_warn(config,lev+1,off,"Reading of Sheet Cell Structure failed");
974 frodo 110 if (length)
975     *length = 0;
976     if (!res)
977     return -PSICONV_E_NOMEM;
978     else
979     return res;
980     }
981    
982 frodo 168 int psiconv_parse_sheet_cell_list(const psiconv_config config,
983     const psiconv_buffer buf, int lev,
984 frodo 128 psiconv_u32 off, int *length,
985     psiconv_sheet_cell_list *result,
986     const psiconv_sheet_cell_layout default_layout,
987     const psiconv_sheet_line_list row_default_layouts,
988     const psiconv_sheet_line_list col_default_layouts)
989 frodo 110 {
990     int res=0;
991     int len=0;
992     psiconv_u32 temp;
993     psiconv_sheet_cell cell;
994     psiconv_u32 listlen,i;
995     int leng;
996    
997 frodo 168 psiconv_progress(config,lev+1,off,"Going to read the sheet cell list");
998 frodo 110 if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_cell_s))))
999     goto ERROR1;
1000    
1001 frodo 168 psiconv_progress(config,lev+2,off+len,
1002 frodo 110 "Going to read the initial byte (%02x expected)",0x02);
1003 frodo 168 temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
1004 frodo 110 if (res)
1005     goto ERROR2;
1006     if (temp != 0x02) {
1007 frodo 168 psiconv_warn(config,lev+2,off+len,
1008 frodo 110 "Sheet cell list initial byte unknown value (ignored)");
1009 frodo 168 psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp);
1010 frodo 110 }
1011     len ++;
1012    
1013 frodo 168 psiconv_progress(config,lev+2,off+len,
1014 frodo 110 "Going to read the initial byte (%02x expected)",0x00);
1015 frodo 168 temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
1016 frodo 110 if (res)
1017     goto ERROR2;
1018     if (temp != 0x00) {
1019 frodo 168 psiconv_warn(config,lev+2,off+len,
1020 frodo 110 "Sheet cell list initial byte unknown value (ignored)");
1021 frodo 168 psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp);
1022 frodo 110 }
1023     len ++;
1024    
1025 frodo 168 psiconv_progress(config,lev+2,off+len,
1026 frodo 110 "Going to read the number of defined cells");
1027 frodo 168 listlen = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res);
1028 frodo 110 if (res)
1029     goto ERROR2;
1030 frodo 168 psiconv_debug(config,lev+2,off+len,"Number of defined cells: %d",listlen);
1031 frodo 110 len += leng;
1032    
1033 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read all cells");
1034 frodo 110 for (i = 0; i < listlen; i++) {
1035 frodo 168 psiconv_progress(config,lev+3,off+len,"Going to read cell %d",i);
1036     if ((res = psiconv_parse_sheet_cell(config,buf,lev+3,off+len,&leng,&cell,
1037 frodo 128 default_layout,row_default_layouts,
1038     col_default_layouts)))
1039 frodo 110 goto ERROR2;
1040     if ((res = psiconv_list_add(*result,cell)))
1041     goto ERROR3;
1042 frodo 120 free(cell);
1043 frodo 110 len += leng;
1044     }
1045    
1046     if (length)
1047     *length = len;
1048    
1049 frodo 168 psiconv_progress(config,lev,off+len-1,
1050 frodo 110 "End of sheet cell list (total length: %08x)", len);
1051     return 0;
1052    
1053     ERROR3:
1054     psiconv_free_sheet_cell(cell);
1055     ERROR2:
1056     psiconv_free_sheet_cell_list(*result);
1057     ERROR1:
1058 frodo 168 psiconv_warn(config,lev+1,off,"Reading of Sheet Cells List failed");
1059 frodo 110 if (length)
1060     *length = 0;
1061     if (!res)
1062     return -PSICONV_E_NOMEM;
1063     else
1064     return res;
1065     }
1066    
1067    
1068 frodo 168 int psiconv_parse_sheet_worksheet_list(const psiconv_config config,
1069     const psiconv_buffer buf, int lev,
1070     psiconv_u32 off, int *length,
1071     psiconv_sheet_worksheet_list *result)
1072 frodo 110 {
1073 frodo 111 psiconv_sheet_worksheet worksheet;
1074 frodo 110 int res=0;
1075     int len=0;
1076 frodo 111 psiconv_u8 temp;
1077     psiconv_u32 offset;
1078     int leng,i,nr;
1079 frodo 110
1080 frodo 168 psiconv_progress(config,lev+1,off,"Going to read the worksheet list");
1081 frodo 111 if (!(*result = psiconv_list_new(sizeof(*worksheet))))
1082     goto ERROR1;
1083    
1084 frodo 168 psiconv_progress(config,lev+2,off+len,
1085 frodo 110 "Going to read the initial bytes (%02x expected)",0x02);
1086 frodo 168 temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
1087 frodo 110 if (res)
1088 frodo 111 goto ERROR2;
1089     if (temp != 0x02) {
1090 frodo 168 psiconv_warn(config,lev+2,off+len,
1091 frodo 111 "Sheet worksheet list initial byte unknown value (ignored)");
1092 frodo 168 psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp);
1093 frodo 110 }
1094     len ++;
1095    
1096 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the list length");
1097     nr = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res);
1098 frodo 110 if (res)
1099 frodo 111 goto ERROR2;
1100 frodo 168 psiconv_debug(config,lev+2,off+len,"Length: %02x",nr);
1101 frodo 111 len += leng;
1102 frodo 110
1103 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the list");
1104 frodo 111 for (i=0 ; i < nr; i++) {
1105 frodo 168 psiconv_progress(config,lev+3,off+len,"Going to read element %d",i);
1106     psiconv_progress(config,lev+4,off+len,
1107 frodo 111 "Going to read the initial byte (%02x expected)",0x00);
1108 frodo 168 temp = psiconv_read_u8(config,buf,lev+4,off+len,&res);
1109 frodo 111 if (res)
1110     goto ERROR2;
1111     if (temp != 0x00) {
1112 frodo 168 psiconv_warn(config,lev+4,off+len,
1113 frodo 111 "Sheet worksheet element initial byte unknown value (ignored)");
1114 frodo 168 psiconv_debug(config,lev+4,off+len,"Initial byte: %02x",temp);
1115 frodo 111 }
1116     len ++;
1117    
1118 frodo 168 psiconv_progress(config,lev+4,off+len,"Going to read the worksheet offset");
1119     offset = psiconv_read_u32(config,buf,lev+2,off+len,&res);
1120 frodo 111 if (res)
1121     goto ERROR2;
1122 frodo 168 psiconv_debug(config,lev+4,off+len,"Offset: %08x",offset);
1123 frodo 111 len += 4;
1124    
1125 frodo 168 if ((res = psiconv_parse_sheet_worksheet(config,buf,lev+4,offset,NULL,
1126 frodo 111 &worksheet)))
1127     goto ERROR2;
1128     if ((res = psiconv_list_add(*result,worksheet)))
1129     goto ERROR3;
1130 frodo 120 free(worksheet);
1131 frodo 110 }
1132    
1133 frodo 111 if (length)
1134     *length = len;
1135 frodo 110
1136 frodo 168 psiconv_progress(config,lev,off+len-1,
1137 frodo 111 "End of worksheet list (total length: %08x)", len);
1138 frodo 110
1139 frodo 111 return 0;
1140    
1141     ERROR3:
1142     psiconv_free_sheet_worksheet(worksheet);
1143     ERROR2:
1144     psiconv_free_sheet_worksheet_list(*result);
1145     ERROR1:
1146 frodo 168 psiconv_warn(config,lev+1,off,"Reading of worksheet list failed");
1147 frodo 111 if (length)
1148     *length = 0;
1149     if (!res)
1150     return -PSICONV_E_NOMEM;
1151     else
1152     return res;
1153     }
1154    
1155 frodo 168 int psiconv_parse_sheet_cell_layout(const psiconv_config config,
1156     const psiconv_buffer buf, int lev,
1157 frodo 111 psiconv_u32 off, int *length,
1158 frodo 121 psiconv_sheet_cell_layout result)
1159 frodo 111
1160     {
1161     int res=0;
1162     int len=0;
1163     int leng;
1164     psiconv_u8 temp;
1165    
1166 frodo 168 psiconv_progress(config,lev+1,off,"Going to read a sheet cell layout");
1167 frodo 110
1168 frodo 168 psiconv_progress(config,lev+2,off+len,
1169 frodo 111 "Going to read the first byte (%02x expected)",0x02);
1170 frodo 168 temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
1171 frodo 110 if (res)
1172 frodo 121 goto ERROR1;
1173 frodo 110 if (temp != 0x02) {
1174 frodo 168 psiconv_warn(config,lev+2,off+len,
1175 frodo 110 "Worksheet section initial byte unknown value (ignored)");
1176 frodo 168 psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp);
1177 frodo 110 }
1178     len ++;
1179    
1180 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the default formats flag");
1181     temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
1182 frodo 110 if (res)
1183 frodo 121 goto ERROR1;
1184 frodo 110 len ++;
1185    
1186     if (temp & 0x01) {
1187 frodo 168 psiconv_progress(config,lev+3,off+len,"Going to read the default paragraph codes");
1188     if ((res = psiconv_parse_paragraph_layout_list(config,buf,lev+3,off+len,&leng,
1189 frodo 121 result->paragraph)))
1190     goto ERROR1;
1191 frodo 110 len += leng;
1192     }
1193    
1194     if (temp & 0x02) {
1195 frodo 168 psiconv_progress(config,lev+3,off+len,"Going to read the default character codes");
1196     if ((res = psiconv_parse_character_layout_list(config,buf,lev+3,off+len,&leng,
1197 frodo 121 result->character)))
1198     goto ERROR1;
1199 frodo 110 len += leng;
1200     }
1201    
1202     if (temp & 0x04) {
1203 frodo 168 psiconv_progress(config,lev+3,off+len, "Going to read the default number format");
1204     psiconv_parse_sheet_numberformat(config,buf,lev+3,off+len,&leng,
1205 frodo 121 result->numberformat);
1206 frodo 111 len += leng;
1207 frodo 110 }
1208 frodo 111
1209     if (length)
1210     *length = len;
1211    
1212 frodo 168 psiconv_progress(config,lev,off+len-1,
1213 frodo 111 "End of sheet cell layout (total length: %08x)", len);
1214    
1215     return 0;
1216    
1217     ERROR1:
1218 frodo 168 psiconv_warn(config,lev+1,off,"Reading of sheet cell layout failed");
1219 frodo 111 if (length)
1220     *length = 0;
1221     if (!res)
1222     return -PSICONV_E_NOMEM;
1223     else
1224     return res;
1225     }
1226 frodo 110
1227 frodo 111
1228 frodo 168 int psiconv_parse_sheet_worksheet(const psiconv_config config,
1229     const psiconv_buffer buf, int lev,
1230     psiconv_u32 off, int *length,
1231     psiconv_sheet_worksheet *result)
1232 frodo 111 {
1233     int res=0;
1234 frodo 133 psiconv_u32 temp,cells_off,grid_off,rows_off,cols_off,unknown_off;
1235 frodo 111 int len=0;
1236     int leng;
1237    
1238 frodo 168 psiconv_progress(config,lev+1,off,"Going to read the sheet worksheet section");
1239 frodo 111 if (!(*result = malloc(sizeof(**result))))
1240     goto ERROR1;
1241    
1242 frodo 168 psiconv_progress(config,lev+2,off+len,
1243 frodo 111 "Going to read the initial bytes (%02x expected)",0x04);
1244 frodo 168 temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
1245 frodo 111 if (res)
1246     goto ERROR2;
1247     if (temp != 0x04) {
1248 frodo 168 psiconv_warn(config,lev+2,off+len,
1249 frodo 111 "Worksheet section initial byte unknown value (ignored)");
1250 frodo 168 psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp);
1251 frodo 111 }
1252     len ++;
1253    
1254 frodo 168 psiconv_progress(config,lev+2,off+len, "Going to read the flags byte");
1255     temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
1256 frodo 111 if (res)
1257     goto ERROR2;
1258 frodo 168 psiconv_debug(config,lev+2,off+len,"Flags byte: %02x",temp);
1259 frodo 111 (*result)->show_zeros = (temp & 0x01)?psiconv_bool_true:psiconv_bool_false;
1260     if (temp & 0xfe) {
1261 frodo 168 psiconv_warn(config,lev+2,off+len,
1262 frodo 111 "Worksheet section flags byte unknown bits (ignored)");
1263     }
1264     len ++;
1265    
1266 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the default cell layout");
1267 frodo 121 if (!((*result)->default_layout = psiconv_basic_cell_layout()))
1268     goto ERROR2;
1269 frodo 168 if ((res = psiconv_parse_sheet_cell_layout(config,buf,lev+2,off+len,&leng,
1270 frodo 121 (*result)->default_layout)))
1271     goto ERROR3;
1272 frodo 111 len += leng;
1273    
1274 frodo 168 psiconv_progress(config,lev+2,off+len,
1275 frodo 128 "Going to read the offset of the row defaults Section");
1276 frodo 168 rows_off = psiconv_read_u32(config,buf,lev+2,off+len,&res);
1277 frodo 110 if (res)
1278 frodo 111 goto ERROR3;
1279 frodo 168 psiconv_debug(config,lev+2,off+len,"Offset: %04x",rows_off);
1280 frodo 110 len += 4;
1281    
1282 frodo 168 psiconv_progress(config,lev+2,off+len,
1283 frodo 128 "Going to read the offset of the column defaults Section");
1284 frodo 168 cols_off = psiconv_read_u32(config,buf,lev+2,off+len,&res);
1285 frodo 110 if (res)
1286 frodo 111 goto ERROR3;
1287 frodo 168 psiconv_debug(config,lev+2,off+len,"Offset: %04x",cols_off);
1288 frodo 110 len += 4;
1289    
1290 frodo 168 psiconv_progress(config,lev+2,off+len,
1291 frodo 110 "Going to read the offset of the Cells List");
1292 frodo 168 cells_off = psiconv_read_u32(config,buf,lev+2,off+len,&res);
1293 frodo 110 if (res)
1294 frodo 111 goto ERROR3;
1295 frodo 168 psiconv_debug(config,lev+2,off+len,"Offset: %04x",cells_off);
1296 frodo 110 len += 4;
1297    
1298 frodo 168 psiconv_progress(config,lev+2,off+len,
1299 frodo 110 "Going to read the offset of the Grid Section");
1300 frodo 168 grid_off = psiconv_read_u32(config,buf,lev+2,off+len,&res);
1301 frodo 110 if (res)
1302 frodo 111 goto ERROR3;
1303 frodo 168 psiconv_debug(config,lev+2,off+len,"Offset: %04x",grid_off);
1304 frodo 110 len += 4;
1305    
1306 frodo 168 psiconv_progress(config,lev+2,off+len,
1307 frodo 110 "Going to read the offset of the 3rd ??? Section");
1308 frodo 168 unknown_off = psiconv_read_u32(config,buf,lev+2,off+len,&res);
1309 frodo 110 if (res)
1310 frodo 111 goto ERROR3;
1311 frodo 168 psiconv_debug(config,lev+2,off+len,"Offset: %04x",unknown_off);
1312 frodo 110 len += 4;
1313    
1314 frodo 168 psiconv_progress(config,lev+2,off+len,
1315 frodo 133 "Going to read a long of the 3rd ??? Section "
1316     "(%08x expected)",0x00);
1317 frodo 168 temp = psiconv_read_u32(config,buf,lev+2,unknown_off,&res);
1318 frodo 133 if (res)
1319     goto ERROR3;
1320     if (temp != 0x00) {
1321 frodo 168 psiconv_warn(config,lev+2,unknown_off,
1322 frodo 133 "Unknown worksheet subsection has unknown contents (ignored)");
1323 frodo 168 psiconv_debug(config,lev+2,unknown_off,"Offset: %04x",temp);
1324 frodo 133 }
1325     len += 4;
1326    
1327 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the row defaults");
1328     if ((res = psiconv_parse_sheet_line_list(config,buf,lev+2,rows_off,NULL,
1329 frodo 128 &(*result)->row_default_layouts,
1330     (*result)->default_layout)))
1331     goto ERROR3;
1332    
1333 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the column defaults");
1334     if ((res = psiconv_parse_sheet_line_list(config,buf,lev+2,cols_off,NULL,
1335 frodo 128 &(*result)->col_default_layouts,
1336     (*result)->default_layout)))
1337     goto ERROR4;
1338    
1339 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the cells list");
1340     if ((res = psiconv_parse_sheet_cell_list(config,buf,lev+2,cells_off,NULL,
1341 frodo 121 &(*result)->cells,
1342 frodo 128 (*result)->default_layout,
1343     (*result)->row_default_layouts,
1344     (*result)->col_default_layouts)))
1345     goto ERROR5;
1346 frodo 110
1347    
1348 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the grid section");
1349     if ((res = psiconv_parse_sheet_grid_section(config,buf,lev+2,grid_off,NULL,
1350 frodo 134 &(*result)->grid)))
1351     goto ERROR6;
1352    
1353    
1354 frodo 110
1355     if (length)
1356     *length = len;
1357    
1358 frodo 168 psiconv_progress(config,lev,off+len-1,
1359 frodo 110 "End of sheet worksheet section (total length: %08x)", len);
1360     return 0;
1361    
1362 frodo 134 ERROR6:
1363     psiconv_free_sheet_cell_list((*result)->cells);
1364 frodo 128 ERROR5:
1365     psiconv_free_sheet_line_list((*result)->col_default_layouts);
1366     ERROR4:
1367     psiconv_free_sheet_line_list((*result)->row_default_layouts);
1368 frodo 111 ERROR3:
1369     psiconv_free_sheet_cell_layout((*result)->default_layout);
1370 frodo 110 ERROR2:
1371     free (*result);
1372     ERROR1:
1373 frodo 168 psiconv_warn(config,lev+1,off,"Reading of Sheet Worksheet Section failed");
1374 frodo 110 if (length)
1375     *length = 0;
1376     if (!res)
1377     return -PSICONV_E_NOMEM;
1378     else
1379     return res;
1380     }
1381    
1382 frodo 168 int psiconv_parse_sheet_line(const psiconv_config config,
1383     const psiconv_buffer buf, int lev,
1384 frodo 128 psiconv_u32 off, int *length,
1385     psiconv_sheet_line *result,
1386     const psiconv_sheet_cell_layout default_layout)
1387     {
1388     int res=0;
1389     int len=0;
1390     int leng;
1391 frodo 110
1392 frodo 128
1393 frodo 168 psiconv_progress(config,lev+1,off,"Going to read a sheet line");
1394 frodo 128 if (!(*result = malloc(sizeof(**result))))
1395     goto ERROR1;
1396    
1397 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the line number");
1398     (*result)->position = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res);
1399 frodo 128 if (res)
1400     goto ERROR2;
1401 frodo 168 psiconv_debug(config,lev+2,off+len,"Line number: %d\n",(*result)->position);
1402 frodo 128 len += leng;
1403    
1404     if (!((*result)->layout = psiconv_clone_cell_layout(default_layout)))
1405     goto ERROR2;
1406 frodo 168 if ((res = psiconv_parse_sheet_cell_layout(config,buf,lev+2,off+len,
1407 frodo 128 &leng,(*result)->layout)))
1408     goto ERROR3;
1409     len += leng;
1410    
1411     if (length)
1412     *length = len;
1413    
1414 frodo 168 psiconv_progress(config,lev,off+len-1,
1415 frodo 128 "End of the sheet line (total length: %08x)", len);
1416     return 0;
1417    
1418     ERROR3:
1419     psiconv_free_sheet_cell_layout((*result)->layout);
1420     ERROR2:
1421     free (*result);
1422     ERROR1:
1423 frodo 168 psiconv_warn(config,lev+1,off,"Reading of the sheet line failed");
1424 frodo 128 if (length)
1425     *length = 0;
1426     if (!res)
1427     return -PSICONV_E_NOMEM;
1428     else
1429     return res;
1430     }
1431    
1432    
1433 frodo 168 int psiconv_parse_sheet_line_list(const psiconv_config config,
1434     const psiconv_buffer buf, int lev,
1435 frodo 128 psiconv_u32 off, int *length,
1436     psiconv_sheet_line_list *result,
1437     const psiconv_sheet_cell_layout default_layout)
1438     {
1439     int res=0;
1440     int len=0;
1441     psiconv_u32 temp;
1442     psiconv_sheet_line line;
1443     psiconv_u32 listlen,i;
1444     int leng;
1445    
1446 frodo 168 psiconv_progress(config,lev+1,off,"Going to read the sheet line list");
1447 frodo 128 if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_line_s))))
1448     goto ERROR1;
1449    
1450 frodo 168 psiconv_progress(config,lev+2,off+len,
1451 frodo 128 "Going to read the initial byte (%02x expected)",0x02);
1452 frodo 168 temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
1453 frodo 128 if (res)
1454     goto ERROR2;
1455     if (temp != 0x02) {
1456 frodo 168 psiconv_warn(config,lev+2,off+len,
1457 frodo 128 "Sheet line list initial byte unknown value (ignored)");
1458 frodo 168 psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp);
1459 frodo 128 }
1460     len ++;
1461    
1462 frodo 168 psiconv_progress(config,lev+2,off+len,
1463 frodo 128 "Going to read the number of defined lines");
1464 frodo 168 listlen = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res);
1465 frodo 128 if (res)
1466     goto ERROR2;
1467 frodo 168 psiconv_debug(config,lev+2,off+len,"Number of defined lines: %d",listlen);
1468 frodo 128 len += leng;
1469    
1470 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read all lines");
1471 frodo 128 for (i = 0; i < listlen; i++) {
1472 frodo 168 psiconv_progress(config,lev+3,off+len,"Going to read line %d",i);
1473     if ((res = psiconv_parse_sheet_line(config,buf,lev+3,off+len,&leng,&line,
1474 frodo 128 default_layout)))
1475     goto ERROR2;
1476     if ((res = psiconv_list_add(*result,line)))
1477     goto ERROR3;
1478     free(line);
1479     len += leng;
1480     }
1481    
1482     if (length)
1483     *length = len;
1484    
1485 frodo 168 psiconv_progress(config,lev,off+len-1,
1486 frodo 128 "End of sheet line list (total length: %08x)", len);
1487     return 0;
1488    
1489     ERROR3:
1490     psiconv_free_sheet_line(line);
1491     ERROR2:
1492     psiconv_free_sheet_line_list(*result);
1493     ERROR1:
1494 frodo 168 psiconv_warn(config,lev+1,off,"Reading of Sheet Line List failed");
1495 frodo 128 if (length)
1496     *length = 0;
1497     if (!res)
1498     return -PSICONV_E_NOMEM;
1499     else
1500     return res;
1501     }
1502    
1503 frodo 168 int psiconv_parse_sheet_variable(const psiconv_config config,
1504     const psiconv_buffer buf, int lev,
1505     psiconv_u32 off, int *length,
1506     psiconv_sheet_variable *result)
1507 frodo 129 {
1508     int res=0;
1509     int len=0;
1510     psiconv_u32 marker;
1511     int leng;
1512    
1513 frodo 168 psiconv_progress(config,lev+1,off,"Going to read a sheet variable");
1514 frodo 129 if (!(*result = malloc(sizeof(**result))))
1515     goto ERROR1;
1516    
1517 frodo 168 psiconv_progress(config,lev+2,off+len, "Going to read the variable name");
1518     (*result)->name = psiconv_read_string(config,buf,lev+2,off+len,&leng,&res);
1519 frodo 129 if (res)
1520     goto ERROR2;
1521     len += leng;
1522    
1523 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the type marker");
1524     marker = psiconv_read_u8(config,buf,lev+2,off+len,&res);
1525 frodo 129 if (res)
1526     goto ERROR3;
1527 frodo 168 psiconv_debug(config,lev+2,off+len,"Marker: %02x",marker);
1528 frodo 129 len ++;
1529    
1530     if (marker == 0x00) {
1531     (*result)->type = psiconv_var_int;
1532 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read a signed integer");
1533     (*result)->data.dat_int = psiconv_read_sint(config,buf,lev+2,off+len,&leng,&res);
1534 frodo 129 if (res)
1535     goto ERROR3;
1536 frodo 168 psiconv_debug(config,lev+2,off+len,"Value: %d",(*result)->data.dat_int);
1537 frodo 129 len += leng;
1538     } else if (marker == 0x01) {
1539     (*result)->type = psiconv_var_float;
1540 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read a floating point number");
1541     (*result)->data.dat_float = psiconv_read_float(config,buf,lev+2,off+len,&leng,
1542 frodo 129 &res);
1543     if (res)
1544     goto ERROR3;
1545 frodo 168 psiconv_debug(config,lev+2,off+len,"Value: %f",(*result)->data.dat_float);
1546 frodo 129 len += leng;
1547     } else if (marker == 0x02) {
1548     (*result)->type = psiconv_var_string;
1549 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read a string");
1550     (*result)->data.dat_string = psiconv_read_string(config,buf,lev+2,off+len,&leng,
1551 frodo 129 &res);
1552     if (res)
1553     goto ERROR3;
1554     len += leng;
1555     } else if (marker == 0x03) {
1556     (*result)->type = psiconv_var_cellref;
1557 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read a cell reference");
1558     (*result)->data.dat_cellref = psiconv_read_var_cellref(config,buf,lev+2,off+len,
1559 frodo 129 &leng, &res);
1560     if (res)
1561     goto ERROR3;
1562     len += leng;
1563     } else if (marker == 0x04) {
1564     (*result)->type = psiconv_var_cellblock;
1565 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read a cell block reference");
1566     (*result)->data.dat_cellblock = psiconv_read_var_cellblock(config,buf,lev+2,
1567 frodo 129 off+len,
1568     &leng, &res);
1569     if (res)
1570     goto ERROR3;
1571     len += leng;
1572     } else {
1573 frodo 168 psiconv_warn(config,lev+2,off+len,"Sheet variable unknown type marker");
1574 frodo 129 res = -PSICONV_E_PARSE;
1575     goto ERROR3;
1576     }
1577    
1578 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the variable number");
1579     (*result)->number = psiconv_read_u32(config,buf,lev+2,off+len,&res);
1580 frodo 129 if (res)
1581     goto ERROR4;
1582 frodo 168 psiconv_debug(config,lev+2,off+len,"Number: %08x",(*result)->number);
1583 frodo 129 len += 4;
1584    
1585     if (length)
1586     *length = len;
1587    
1588 frodo 168 psiconv_progress(config,lev,off+len-1,
1589 frodo 129 "End of sheet variable (total length: %08x)", len);
1590     return 0;
1591    
1592     ERROR4:
1593     if ((*result)->type == psiconv_var_string)
1594     free((*result)->data.dat_string);
1595     ERROR3:
1596     free((*result)->name);
1597     ERROR2:
1598     free (*result);
1599     ERROR1:
1600 frodo 168 psiconv_warn(config,lev+1,off,"Reading of Sheet Variable failed");
1601 frodo 129 if (length)
1602     *length = 0;
1603     if (!res)
1604     return -PSICONV_E_NOMEM;
1605     else
1606     return res;
1607     }
1608    
1609    
1610 frodo 168 int psiconv_parse_sheet_variable_list(const psiconv_config config,
1611     const psiconv_buffer buf, int lev,
1612 frodo 129 psiconv_u32 off, int *length,
1613     psiconv_sheet_variable_list *result)
1614     {
1615     int res=0;
1616     int len=0;
1617     psiconv_u32 temp;
1618     psiconv_sheet_variable variable;
1619     psiconv_u32 listlen,i;
1620     int leng;
1621    
1622 frodo 168 psiconv_progress(config,lev+1,off,"Going to read the sheet variable list");
1623 frodo 129 if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_variable_s))))
1624     goto ERROR1;
1625    
1626 frodo 168 psiconv_progress(config,lev+2,off+len,
1627 frodo 129 "Going to read the initial byte (%02x expected)",0x02);
1628 frodo 168 temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
1629 frodo 129 if (res)
1630     goto ERROR2;
1631     if (temp != 0x02) {
1632 frodo 168 psiconv_warn(config,lev+2,off+len,
1633 frodo 129 "Sheet variable list initial byte unknown value (ignored)");
1634 frodo 168 psiconv_debug(config,lev+2,off+len,"Initial byte: %02x",temp);
1635 frodo 129 }
1636     len ++;
1637    
1638 frodo 168 psiconv_progress(config,lev+2,off+len,
1639 frodo 129 "Going to read the number of variables");
1640 frodo 168 listlen = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res);
1641 frodo 129 if (res)
1642     goto ERROR2;
1643 frodo 168 psiconv_debug(config,lev+2,off+len,"Number of variables: %d",listlen);
1644 frodo 129 len += leng;
1645    
1646 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read all variables");
1647 frodo 129 for (i = 0; i < listlen; i++) {
1648 frodo 168 psiconv_progress(config,lev+3,off+len,"Going to read variable %d",i);
1649     if ((res = psiconv_parse_sheet_variable(config,buf,lev+3,off+len,&leng,&variable)))
1650 frodo 129 goto ERROR2;
1651     if ((res = psiconv_list_add(*result,variable)))
1652     goto ERROR3;
1653     len += leng;
1654     }
1655    
1656     if (length)
1657     *length = len;
1658    
1659 frodo 168 psiconv_progress(config,lev,off+len-1,
1660 frodo 129 "End of sheet variabels list (total length: %08x)", len);
1661     return 0;
1662    
1663     ERROR3:
1664     psiconv_free_sheet_variable(variable);
1665     ERROR2:
1666     psiconv_list_free(*result);
1667     ERROR1:
1668 frodo 168 psiconv_warn(config,lev+1,off,"Reading of Sheet Variable list failed");
1669 frodo 129 if (length)
1670     *length = 0;
1671     if (!res)
1672     return -PSICONV_E_NOMEM;
1673     else
1674     return res;
1675     }
1676 frodo 134
1677 frodo 168 int psiconv_parse_sheet_grid_section(const psiconv_config config,
1678     const psiconv_buffer buf, int lev,
1679 frodo 134 psiconv_u32 off, int *length,
1680     psiconv_sheet_grid_section *result)
1681     {
1682     int res=0,i;
1683     int len=0,leng;
1684     psiconv_u32 temp;
1685    
1686 frodo 168 psiconv_progress(config,lev+1,off,"Going to read the sheet grid section");
1687 frodo 134 if (!(*result = malloc(sizeof(**result))))
1688     goto ERROR1;
1689    
1690 frodo 168 psiconv_progress(config,lev+2,off+len, "Going to read the first flags byte");
1691     temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
1692 frodo 134 if (res)
1693     goto ERROR2;
1694     (*result)->show_column_titles = temp&0x01?psiconv_bool_true:
1695     psiconv_bool_false;
1696 frodo 168 psiconv_debug(config,lev+2,off+len,
1697 frodo 134 "Show column titles: %s",
1698     (*result)->show_column_titles?"true":"false");
1699     (*result)->show_row_titles = temp&0x02?psiconv_bool_true:psiconv_bool_false;
1700 frodo 168 psiconv_debug(config,lev+2,off+len,
1701 frodo 134 "Show row titles: %s",
1702     (*result)->show_row_titles?"true":"false");
1703     (*result)->show_vertical_grid = temp&0x04?psiconv_bool_true:
1704     psiconv_bool_false;
1705 frodo 168 psiconv_debug(config,lev+2,off+len,
1706 frodo 134 "Show vertical grid: %s",
1707     (*result)->show_vertical_grid?"true":"false");
1708     (*result)->show_horizontal_grid = temp&0x07?psiconv_bool_true:
1709     psiconv_bool_false;
1710 frodo 168 psiconv_debug(config,lev+2,off+len,
1711 frodo 134 "Show horizontal grid: %s",
1712     (*result)->show_horizontal_grid?"true":"false");
1713     (*result)->freeze_rows = temp&0x80?psiconv_bool_true:psiconv_bool_false;
1714 frodo 168 psiconv_debug(config,lev+2,off+len,
1715 frodo 134 "Freeze rows: %s",
1716     (*result)->freeze_rows?"true":"false");
1717     if ((temp & 0x70) != 0x30) {
1718 frodo 168 psiconv_warn(config,lev+2,off+len,
1719 frodo 134 "Grid section first flag byte has unknown bits (ignored)");
1720 frodo 168 psiconv_debug(config,lev+2,off+len,"Bits: %02x (%02x expected)",temp&0x70,0x30);
1721 frodo 134 }
1722     len ++;
1723    
1724 frodo 168 psiconv_progress(config,lev+2,off+len, "Going to read the second flags byte");
1725     temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
1726 frodo 134 if (res)
1727     goto ERROR2;
1728     (*result)->freeze_columns = temp&0x01?psiconv_bool_true:psiconv_bool_false;
1729 frodo 168 psiconv_debug(config,lev+2,off+len,
1730 frodo 134 "Freeze columns: %s", (*result)->freeze_columns?"true":"false");
1731     if ((temp & 0xfe) != 0x80) {
1732 frodo 168 psiconv_warn(config,lev+2,off+len,
1733 frodo 134 "Grid section second flag byte has unknown bits (ignored)");
1734 frodo 168 psiconv_debug(config,lev+2,off+len,"Bits: %02x (%02x expected)",temp&0xfe,0x80);
1735 frodo 134 }
1736     len ++;
1737    
1738 frodo 168 psiconv_progress(config,lev+2,off+len,
1739 frodo 134 "Going to an unknown byte (%02x expected)",0x90);
1740 frodo 168 temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
1741 frodo 134 if (res)
1742     goto ERROR2;
1743     if (temp != 0x90) {
1744 frodo 168 psiconv_warn(config,lev+2,off+len,
1745 frodo 134 "Grid section third byte unknown value (ignored)");
1746 frodo 168 psiconv_debug(config,lev+2,off+len,"Value: %02x",temp);
1747 frodo 134 }
1748     len ++;
1749    
1750 frodo 168 psiconv_progress(config,lev+2,off+len, "Going to read the fourth flags byte");
1751     temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
1752 frodo 134 if (res)
1753     goto ERROR2;
1754     (*result)->show_page_breaks = temp&0x04?psiconv_bool_true:psiconv_bool_false;
1755 frodo 168 psiconv_debug(config,lev+2,off+len,
1756 frodo 134 "Show page breaks: %s",
1757     (*result)->show_page_breaks?"true":"false");
1758     if ((temp & 0xfc) != 0x00) {
1759 frodo 168 psiconv_warn(config,lev+2,off+len,
1760 frodo 134 "Grid section fourth flag byte has unknown bits (ignored)");
1761 frodo 168 psiconv_debug(config,lev+2,off+len,"Bits: %02x (%02x expected)",temp&0xfc,0x00);
1762 frodo 134 }
1763     len ++;
1764    
1765 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the first visible row");
1766     (*result)->first_row = psiconv_read_u32(config,buf,lev+2,off+len,&res);
1767 frodo 134 if (res)
1768     goto ERROR2;
1769 frodo 168 psiconv_debug(config,lev+2,off+len,"First row: %d",(*result)->first_row);
1770 frodo 134 len += 4;
1771    
1772 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the first visible column");
1773     (*result)->first_column = psiconv_read_u32(config,buf,lev+2,off+len,&res);
1774 frodo 134 if (res)
1775     goto ERROR2;
1776 frodo 168 psiconv_debug(config,lev+2,off+len,"First column: %d",(*result)->first_column);
1777 frodo 134 len += 4;
1778    
1779 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the last visible row");
1780     (*result)->last_row = psiconv_read_u32(config,buf,lev+2,off+len,&res);
1781 frodo 134 if (res)
1782     goto ERROR2;
1783 frodo 168 psiconv_debug(config,lev+2,off+len,"Last row: %d",(*result)->last_row);
1784 frodo 134 len += 4;
1785    
1786 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the last visible column");
1787     (*result)->last_column = psiconv_read_u32(config,buf,lev+2,off+len,&res);
1788 frodo 134 if (res)
1789     goto ERROR2;
1790 frodo 168 psiconv_debug(config,lev+2,off+len,"Last column: %d",(*result)->last_column);
1791 frodo 134 len += 4;
1792    
1793 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the default row height");
1794     (*result)->default_row_height = psiconv_read_length(config,buf,lev+2,off+len,
1795 frodo 134 &leng,&res);
1796     if (res)
1797     goto ERROR2;
1798 frodo 168 psiconv_debug(config,lev+2,off+len,"Default row height: %f",
1799 frodo 134 (*result)->default_row_height);
1800     len += leng;
1801    
1802 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the row heights list");
1803     if ((res = psiconv_parse_sheet_grid_size_list(config,buf,lev+2,off+len,&leng,
1804 frodo 134 &(*result)->row_heights)))
1805     goto ERROR2;
1806     len += leng;
1807    
1808 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the default column height");
1809     (*result)->default_column_width = psiconv_read_length(config,buf,lev+2,off+len,
1810 frodo 134 &leng,&res);
1811     if (res)
1812     goto ERROR3;
1813 frodo 168 psiconv_debug(config,lev+2,off+len,"Default column width: %f",
1814 frodo 134 (*result)->default_column_width);
1815     len += leng;
1816    
1817 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the column heights list");
1818     if ((res = psiconv_parse_sheet_grid_size_list(config,buf,lev+2,off+len,&leng,
1819 frodo 134 &(*result)->column_heights)))
1820     goto ERROR3;
1821     len += leng;
1822    
1823 frodo 168 psiconv_progress(config,lev+2,off+len,
1824 frodo 134 "Going to read an unknown word (%04x expected)",0x00);
1825 frodo 168 temp = psiconv_read_u16(config,buf,lev+2,off+len,&res);
1826 frodo 134 if (res)
1827     goto ERROR4;
1828     if (temp != 0x00) {
1829 frodo 168 psiconv_warn(config,lev+2,off+len,
1830 frodo 134 "Grid section unknown word has unknown value (ignored)");
1831 frodo 168 psiconv_debug(config,lev+2,off+len,"Value: %04x",temp);
1832 frodo 134 }
1833     len += 2;
1834    
1835 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the row breaks list");
1836     if ((res = psiconv_parse_sheet_grid_break_list(config,buf,lev+2,off+len,&leng,
1837 frodo 134 &(*result)->row_page_breaks)))
1838     goto ERROR4;
1839     len += leng;
1840    
1841 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read the column breaks list");
1842     if ((res = psiconv_parse_sheet_grid_break_list(config,buf,lev+2,off+len,&leng,
1843 frodo 134 &(*result)->column_page_breaks)))
1844     goto ERROR5;
1845     len += leng;
1846    
1847    
1848 frodo 168 psiconv_progress(config,lev+2,off+len,
1849 frodo 134 "Going to read 22 unknown bytes (%02x expected)",0x00);
1850     for (i = 0; i < 22 ; i++) {
1851 frodo 168 temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
1852 frodo 134 if (res)
1853     goto ERROR6;
1854     if (temp != 0x00) {
1855 frodo 168 psiconv_warn(config,lev+2,off+len,
1856 frodo 134 "Grid section unknown byte %d has unknown value (ignored)",
1857     i);
1858 frodo 168 psiconv_debug(config,lev+2,off+len,"Value: %02x",temp);
1859 frodo 134 }
1860     len += 1;
1861     }
1862    
1863     if ((*result)->freeze_rows || (*result)->freeze_columns) {
1864    
1865 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read number of frozen rows");
1866     (*result)->frozen_rows = psiconv_read_u32(config,buf,lev+2,off+len, &res);
1867 frodo 134 if (res)
1868     goto ERROR6;
1869 frodo 168 psiconv_debug(config,lev+2,off+len,"Number of frozen rows: %d",
1870 frodo 134 (*result)->frozen_rows);
1871     len += leng;
1872    
1873 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read number of frozen columns");
1874     (*result)->frozen_columns = psiconv_read_u32(config,buf,lev+2,off+len, &res);
1875 frodo 134 if (res)
1876     goto ERROR6;
1877 frodo 168 psiconv_debug(config,lev+2,off+len,"Number of frozen columns: %d",
1878 frodo 134 (*result)->frozen_columns);
1879     len += leng;
1880    
1881 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read first unfrozen row");
1882     (*result)->first_unfrozen_row_displayed = psiconv_read_u32(config,buf,lev+2,
1883 frodo 134 off+len, &res);
1884     if (res)
1885     goto ERROR6;
1886 frodo 168 psiconv_debug(config,lev+2,off+len,"First row: %d",
1887 frodo 134 (*result)->first_unfrozen_row_displayed);
1888     len += leng;
1889    
1890 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read first unfrozen column");
1891     (*result)->first_unfrozen_column_displayed = psiconv_read_u32(config,buf,lev+2,
1892 frodo 134 off+len,&res);
1893     if (res)
1894     goto ERROR6;
1895 frodo 168 psiconv_debug(config,lev+2,off+len,"First column: %d",
1896 frodo 134 (*result)->first_unfrozen_column_displayed);
1897     len += leng;
1898     } else
1899     (*result)->frozen_rows = (*result)->frozen_columns =
1900     (*result)->first_unfrozen_row_displayed =
1901     (*result)->first_unfrozen_column_displayed = 0;
1902    
1903 frodo 168 psiconv_progress(config,lev+2,off+len,
1904 frodo 134 "Going to read 3 unknown bytes (%02x expected)",0xff);
1905     for (i = 0; i < 3 ; i++) {
1906 frodo 168 temp = psiconv_read_u8(config,buf,lev+2,off+len,&res);
1907 frodo 134 if (res)
1908     goto ERROR6;
1909     if (temp != 0xff) {
1910 frodo 168 psiconv_warn(config,lev+2,off+len,
1911 frodo 134 "Grid section unknown byte %d has unknown value (ignored)",
1912     i);
1913 frodo 168 psiconv_debug(config,lev+2,off+len,"Value: %02x",temp);
1914 frodo 134 }
1915     len ++;
1916     }
1917    
1918     if (length)
1919     *length = len;
1920    
1921 frodo 168 psiconv_progress(config,lev,off+len-1,
1922 frodo 134 "End of sheet grid section (total length: %08x)", len);
1923     return 0;
1924    
1925     ERROR6:
1926     psiconv_free_sheet_grid_break_list((*result)->column_page_breaks);
1927     ERROR5:
1928     psiconv_free_sheet_grid_break_list((*result)->row_page_breaks);
1929     ERROR4:
1930     psiconv_free_sheet_grid_size_list((*result)->column_heights);
1931     ERROR3:
1932     psiconv_free_sheet_grid_size_list((*result)->row_heights);
1933     ERROR2:
1934     free(*result);
1935     ERROR1:
1936 frodo 168 psiconv_warn(config,lev+1,off,"Reading of Sheet Grid Section failed");
1937 frodo 134 if (length)
1938     *length = 0;
1939     if (!res)
1940     return -PSICONV_E_NOMEM;
1941     else
1942     return res;
1943     }
1944    
1945    
1946 frodo 168 int psiconv_parse_sheet_grid_size_list(const psiconv_config config,
1947     const psiconv_buffer buf, int lev,
1948 frodo 134 psiconv_u32 off, int *length,
1949     psiconv_sheet_grid_size_list *result)
1950     {
1951     int res=0;
1952     int len=0,i;
1953     int leng,listlen;
1954     psiconv_sheet_grid_size size;
1955    
1956 frodo 168 psiconv_progress(config,lev+1,off,"Going to read a sheet grid size list");
1957 frodo 134 if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_grid_size_s))))
1958     goto ERROR1;
1959    
1960 frodo 168 psiconv_progress(config,lev+2,off+len,
1961 frodo 134 "Going to read the number of elements");
1962 frodo 168 listlen = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res);
1963 frodo 134 if (res)
1964     goto ERROR2;
1965 frodo 168 psiconv_debug(config,lev+2,off+len,"Number of elements: %d",listlen);
1966 frodo 134 len += leng;
1967    
1968 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read all elements");
1969 frodo 134 for (i = 0; i < listlen; i++) {
1970 frodo 168 psiconv_progress(config,lev+3,off+len,"Going to read element %d",i);
1971     if ((res = psiconv_parse_sheet_grid_size(config,buf,lev+3,off+len,&leng,&size)))
1972 frodo 134 goto ERROR2;
1973     if ((res = psiconv_list_add(*result,size)))
1974     goto ERROR3;
1975     free(size);
1976     len += leng;
1977     }
1978    
1979     if (length)
1980     *length = len;
1981    
1982 frodo 168 psiconv_progress(config,lev,off+len-1,
1983 frodo 134 "End of sheet grid size list (total length: %08x)", len);
1984     return 0;
1985    
1986     ERROR3:
1987     psiconv_free_sheet_grid_size(size);
1988     ERROR2:
1989     psiconv_list_free(*result);
1990     ERROR1:
1991 frodo 168 psiconv_warn(config,lev+1,off,"Reading of Sheet Grid Size List failed");
1992 frodo 134 if (length)
1993     *length = 0;
1994     if (!res)
1995     return -PSICONV_E_NOMEM;
1996     else
1997     return res;
1998     }
1999    
2000 frodo 168 int psiconv_parse_sheet_grid_size(const psiconv_config config,
2001     const psiconv_buffer buf, int lev,
2002 frodo 134 psiconv_u32 off, int *length,
2003     psiconv_sheet_grid_size *result)
2004     {
2005     int res=0;
2006     int len=0;
2007     int leng;
2008    
2009 frodo 168 psiconv_progress(config,lev+1,off,"Going to read a sheet grid size");
2010 frodo 134
2011     if (!(*result = malloc(sizeof(**result))))
2012     goto ERROR1;
2013    
2014 frodo 168 psiconv_progress(config,lev+2,off+len, "Going to read the row or column number");
2015     (*result)->line_number = psiconv_read_u32(config,buf,lev+2,off+len,&res);
2016 frodo 134 if (res)
2017     goto ERROR2;
2018 frodo 168 psiconv_debug(config,lev+2,off+len,"Line number: %d\n",(*result)->line_number);
2019 frodo 134 len += 4;
2020    
2021 frodo 168 psiconv_progress(config,lev+2,off+len, "Going to read the row or column height");
2022     (*result)->size = psiconv_read_length(config,buf,lev+2,off+len,&leng,&res);
2023 frodo 134 if (res)
2024     goto ERROR2;
2025 frodo 168 psiconv_debug(config,lev+2,off+len,"Size: %f\n",(*result)->size);
2026 frodo 134 len += leng;
2027    
2028     if (length)
2029     *length = len;
2030    
2031 frodo 168 psiconv_progress(config,lev,off+len-1,
2032 frodo 134 "End of sheet grid size(total length: %08x)", len);
2033     return 0;
2034    
2035     ERROR2:
2036     free (*result);
2037     ERROR1:
2038 frodo 168 psiconv_warn(config,lev+1,off,"Reading of Sheet Grid Size failed");
2039 frodo 134 if (length)
2040     *length = 0;
2041     if (!res)
2042     return -PSICONV_E_NOMEM;
2043     else
2044     return res;
2045     }
2046    
2047    
2048 frodo 168 int psiconv_parse_sheet_grid_break_list(const psiconv_config config,
2049     const psiconv_buffer buf, int lev,
2050 frodo 134 psiconv_u32 off, int *length,
2051     psiconv_sheet_grid_break_list *result)
2052     {
2053     int res=0;
2054     int len=0,i;
2055     int leng,listlen;
2056     psiconv_u32 nr;
2057    
2058 frodo 168 psiconv_progress(config,lev+1,off,"Going to read a sheet grid break list");
2059 frodo 134 if (!(*result = psiconv_list_new(sizeof(psiconv_u32))))
2060     goto ERROR1;
2061    
2062 frodo 168 psiconv_progress(config,lev+2,off+len,
2063 frodo 134 "Going to read the number of elements");
2064 frodo 168 listlen = psiconv_read_X(config,buf,lev+2,off+len,&leng,&res);
2065 frodo 134 if (res)
2066     goto ERROR2;
2067 frodo 168 psiconv_debug(config,lev+2,off+len,"Number of elements: %d",listlen);
2068 frodo 134 len += leng;
2069    
2070 frodo 168 psiconv_progress(config,lev+2,off+len,"Going to read all elements");
2071 frodo 134 for (i = 0; i < listlen; i++) {
2072 frodo 168 psiconv_progress(config,lev+3,off+len,"Going to read element %d",i);
2073     nr = psiconv_read_u32(config,buf,lev+3,off+len,&res);
2074 frodo 134 if (res)
2075     goto ERROR2;
2076     if ((res = psiconv_list_add(*result,&nr)))
2077     goto ERROR2;
2078     len += leng;
2079     }
2080    
2081     if (length)
2082     *length = len;
2083    
2084 frodo 168 psiconv_progress(config,lev,off+len-1,
2085 frodo 134 "End of sheet grid break list (total length: %08x)", len);
2086     return 0;
2087    
2088     ERROR2:
2089     psiconv_list_free(*result);
2090     ERROR1:
2091 frodo 168 psiconv_warn(config,lev+1,off,"Reading of Sheet Grid break List failed");
2092 frodo 134 if (length)
2093     *length = 0;
2094     if (!res)
2095     return -PSICONV_E_NOMEM;
2096     else
2097     return res;
2098     }
2099    

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