/[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 110 - (hide annotations)
Sun Mar 4 22:10:45 2001 UTC (23 years ago) by frodo
File MIME type: text/plain
File size: 25902 byte(s)
(Frodo) Thomas Decsi's major sheet patch

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     int psiconv_parse_sheet_status_section(const psiconv_buffer buf, int lev,
29     psiconv_u32 off, int *length,
30     psiconv_sheet_status_section *result)
31     {
32     int res=0;
33     int len=0;
34     psiconv_u32 temp;
35     int leng;
36    
37     psiconv_progress(lev+1,off,"Going to read the sheet status section");
38     if (!(*result = malloc(sizeof(**result))))
39     goto ERROR1;
40    
41     psiconv_progress(lev+2,off+len,
42     "Going to read the initial byte (%02x expected)",0x02);
43     temp = psiconv_read_u8(buf,lev+2,off+len,&res);
44     if (res)
45     goto ERROR2;
46     if (temp != 0x02) {
47     psiconv_warn(lev+2,off+len,
48     "Sheet status section initial byte unknown value (ignored)");
49     psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
50     }
51     len ++;
52    
53     psiconv_progress(lev+2,off+len,
54     "Going to read the cursor row");
55     (*result)->cursor_row = psiconv_read_u32(buf,lev+2,off + len,&res);
56     if (res)
57     goto ERROR2;
58     psiconv_debug(lev+2,off+len,"Cursor row: %08x",
59     (*result)->cursor_row);
60     len += 0x04;
61    
62     psiconv_progress(lev+2,off+len,
63     "Going to read the cursor column");
64     (*result)->cursor_column = psiconv_read_u32(buf,lev+2,off + len,&res);
65     if (res)
66     goto ERROR2;
67     psiconv_debug(lev+2,off+len,"Cursor column: %08x",
68     (*result)->cursor_column);
69     len += 0x04;
70    
71     psiconv_progress(lev+2,off+len,"Going to read initially display graph");
72     if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng,
73     &(*result)->show_graph)))
74     goto ERROR2;
75     len += leng;
76    
77     psiconv_progress(lev+2,off+len,
78     "Going to read the toolbar status byte");
79     temp = psiconv_read_u8(buf,lev+2,off+len,&res);
80     if (res)
81     goto ERROR2;
82    
83     (*result)->show_side_sheet_toolbar = temp&0x01 ? psiconv_bool_true :
84     psiconv_bool_false;
85     psiconv_debug(lev+2,off+len,"Show side sheet toolbar: %02x",
86     (*result)->show_side_sheet_toolbar);
87     (*result)->show_top_sheet_toolbar = temp&0x02 ? psiconv_bool_true :
88     psiconv_bool_false;
89     psiconv_debug(lev+2,off+len,"Show top sheet toolbar: %02x",
90     (*result)->show_top_sheet_toolbar);
91     (*result)->show_side_graph_toolbar = temp&0x04 ? psiconv_bool_true :
92     psiconv_bool_false;
93     psiconv_debug(lev+2,off+len,"Show side graph toolbar: %02x",
94     (*result)->show_side_graph_toolbar);
95     (*result)->show_top_graph_toolbar = temp&0x08 ? psiconv_bool_true :
96     psiconv_bool_false;
97     psiconv_debug(lev+2,off+len,"Show top graph toolbar: %02x",
98     (*result)->show_top_graph_toolbar);
99     if (temp & 0xf0) {
100     psiconv_warn(lev+2,off+len,"Sheet status section toolbar byte "
101     "flags contains unknown flags (ignored)");
102     psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0xf0);
103     }
104     len ++;
105    
106     psiconv_progress(lev+2,off+len,
107     "Going to read the scrollbar status byte");
108     temp = psiconv_read_u8(buf,lev+2,off+len,&res);
109     if (res)
110     goto ERROR2;
111     if ((temp & 0x03) == 0x03) {
112     psiconv_warn(lev+2,off+len,"Sheet status section scrollbar byte "
113     "flags contains unknown flags (ignored)");
114     psiconv_debug(lev+2,off+len,"Unknown flag: %02x",temp & 0x03);
115     }
116     (*result)->show_horizontal_scrollbar = (temp&0x03) == 1? psiconv_triple_off :
117     (temp&0x03) == 2? psiconv_triple_auto:
118     psiconv_triple_on;
119     psiconv_debug(lev+2,off+len,"Show horizontal scrollbar: %02x",
120     (*result)->show_horizontal_scrollbar);
121     if ((temp & 0x0c) == 0x0c) {
122     psiconv_warn(lev+2,off+len,"Sheet status section scrollbar byte "
123     "flags contains unknown flags (ignored)");
124     psiconv_debug(lev+2,off+len,"Unknown flag: %02x",temp & 0x0c);
125     }
126     (*result)->show_vertical_scrollbar = (temp&0x0c) ==0x04? psiconv_triple_off:
127     (temp&0x0c) ==0x08? psiconv_triple_auto:
128     psiconv_triple_on;
129     psiconv_debug(lev+2,off+len,"Show vertical scrollbar: %02x",
130     (*result)->show_vertical_scrollbar);
131     if (temp & 0xf0) {
132     psiconv_warn(lev+2,off+len,"Sheet status section scrollbar byte "
133     "flags contains unknown flags (ignored)");
134     psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0xf0);
135     }
136     len ++;
137    
138     psiconv_progress(lev+2,off+len,
139     "Going to read an unknown byte (%02x expected)",0x00);
140     temp = psiconv_read_u8(buf,lev+2,off+len,&res);
141     if (res)
142     goto ERROR2;
143     if (temp != 0x00) {
144     psiconv_warn(lev+2,off+len,
145     "Sheet status section unknown byte unknown value (ignored)");
146     psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
147     }
148     len ++;
149    
150     psiconv_progress(lev+2,off+len,"Going to read sheet display size");
151     (*result)->sheet_display_size = psiconv_read_u32(buf,lev+2,off + len,&res);
152     if (res)
153     goto ERROR2;
154     psiconv_debug(lev+2,off+len,"Sheet display size: %08x",
155     (*result)->sheet_display_size);
156     len += 0x04;
157    
158     psiconv_progress(lev+2,off+len,"Going to read graph display size");
159     (*result)->graph_display_size = psiconv_read_u32(buf,lev+2,off + len,&res);
160     if (res)
161     goto ERROR2;
162     psiconv_debug(lev+2,off+len,"Graph display size: %08x",
163     (*result)->graph_display_size);
164     len += 0x04;
165    
166     if (length)
167     *length = len;
168    
169     psiconv_progress(lev,off+len-1,
170     "End of sheet status section (total length: %08x)", len);
171     return 0;
172    
173     ERROR2:
174     free (*result);
175     ERROR1:
176 frodo 110 psiconv_warn(lev+1,off,"Reading of Sheet Status Section failed");
177 frodo 94 if (length)
178     *length = 0;
179     if (!res)
180     return -PSICONV_E_NOMEM;
181     else
182     return res;
183     }
184    
185 frodo 95 int psiconv_parse_sheet_workbook_section(const psiconv_buffer buf, int lev,
186     psiconv_u32 off, int *length,
187     psiconv_sheet_workbook_section *result)
188     {
189     int res=0;
190 frodo 110 psiconv_u32 temp,formulas_off,worksheets_off;
191 frodo 95 int len=0;
192    
193     psiconv_progress(lev+1,off,"Going to read the sheet workbook section");
194     if (!(*result = malloc(sizeof(**result))))
195     goto ERROR1;
196    
197     psiconv_progress(lev+2,off+len,
198     "Going to read the initial byte (%02x expected)",0x04);
199     temp = psiconv_read_u8(buf,lev+2,off+len,&res);
200     if (res)
201     goto ERROR2;
202     if (temp != 0x04) {
203     psiconv_warn(lev+2,off+len,
204     "Sheet workbook section initial byte unknown value (ignored)");
205     psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
206     }
207     len ++;
208    
209     psiconv_progress(lev+2,off+len,
210     "Going to read the offset of the 1st ??? Section");
211     temp = psiconv_read_u32(buf,lev+2,off+len,&res);
212     if (res)
213     goto ERROR2;
214     psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
215     len += 4;
216    
217     psiconv_progress(lev+2,off+len,
218 frodo 97 "Going to read the offset of the Formulas List");
219     formulas_off = psiconv_read_u32(buf,lev+2,off+len,&res);
220 frodo 95 if (res)
221     goto ERROR2;
222 frodo 97 psiconv_debug(lev+2,off+len,"Offset: %04x",formulas_off);
223 frodo 95 len += 4;
224    
225     psiconv_progress(lev+2,off+len,
226 frodo 110 "Going to read the offset of the Worksheets Section");
227     worksheets_off = psiconv_read_u32(buf,lev+2,off+len,&res);
228 frodo 95 if (res)
229     goto ERROR2;
230     psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
231     len += 4;
232    
233     psiconv_progress(lev+2,off+len,
234     "Going to read the offset of the 4th ??? Section");
235     temp = psiconv_read_u32(buf,lev+2,off+len,&res);
236     if (res)
237     goto ERROR2;
238     psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
239     len += 4;
240    
241 frodo 97 psiconv_progress(lev+2,off+len,"Going to read the formulas list");
242 frodo 98 if ((res = psiconv_parse_sheet_formula_table(buf,lev+2,formulas_off,NULL,
243     &(*result)->formulas)))
244 frodo 97 goto ERROR2;
245    
246 frodo 110 psiconv_progress(lev+2,off+len,"Going to read the worksheets");
247     if ((res = psiconv_parse_sheet_worksheet_section(buf,lev+2,worksheets_off,
248     NULL,&(*result)->worksheet)))
249     goto ERROR2;
250 frodo 97
251 frodo 110
252 frodo 95 if (length)
253     *length = len;
254    
255     psiconv_progress(lev,off+len-1,
256     "End of sheet workbook section (total length: %08x)", len);
257     return 0;
258    
259     ERROR2:
260     free (*result);
261     ERROR1:
262     psiconv_warn(lev+1,off,"Reading of Sheet Workbook Section failed");
263     if (length)
264     *length = 0;
265     if (!res)
266     return -PSICONV_E_NOMEM;
267     else
268     return res;
269     }
270 frodo 97
271 frodo 98 int psiconv_parse_sheet_formula_table(const psiconv_buffer buf, int lev,
272     psiconv_u32 off, int *length,
273     psiconv_formula_list *result)
274 frodo 97 {
275     int res=0;
276     int len=0;
277     psiconv_u32 temp;
278 frodo 98 psiconv_formula formula;
279 frodo 97 psiconv_u32 listlen,i;
280     int leng;
281    
282     psiconv_progress(lev+1,off,"Going to read the sheet formula table");
283 frodo 98 if (!(*result = psiconv_list_new(sizeof(struct psiconv_formula_s))))
284 frodo 97 goto ERROR1;
285    
286     psiconv_progress(lev+2,off+len,
287     "Going to read the initial byte (%02x expected)",0x02);
288     temp = psiconv_read_u8(buf,lev+2,off+len,&res);
289     if (res)
290     goto ERROR2;
291     if (temp != 0x02) {
292     psiconv_warn(lev+2,off+len,
293     "Sheet formula table initial byte unknown value (ignored)");
294     psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
295     }
296     len ++;
297    
298     psiconv_progress(lev+2,off+len,
299     "Going to read the number of formulas");
300     listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res);
301     if (res)
302     goto ERROR2;
303     psiconv_debug(lev+2,off+len,"Number of formulas: %d",listlen);
304     len += leng;
305    
306     psiconv_progress(lev+2,off+len,"Going to read all formulas");
307     for (i = 0; i < listlen; i++) {
308     psiconv_progress(lev+3,off+len,"Going to read formula %d",i);
309 frodo 98 if ((res = psiconv_parse_formula(buf,lev+3,off+len,&leng,&formula)))
310 frodo 97 goto ERROR2;
311     if ((res = psiconv_list_add(*result,formula)))
312     goto ERROR3;
313     len += leng;
314     }
315    
316     if (length)
317     *length = len;
318    
319     psiconv_progress(lev,off+len-1,
320     "End of sheet formula table (total length: %08x)", len);
321     return 0;
322    
323     ERROR3:
324 frodo 98 psiconv_free_formula(formula);
325 frodo 97 ERROR2:
326     psiconv_list_free(*result);
327     ERROR1:
328     psiconv_warn(lev+1,off,"Reading of Sheet Formula Table failed");
329     if (length)
330     *length = 0;
331     if (!res)
332     return -PSICONV_E_NOMEM;
333     else
334     return res;
335     }
336 frodo 110
337     int psiconv_parse_sheet_cell(const psiconv_buffer buf, int lev,
338     psiconv_u32 off, int *length,
339     psiconv_sheet_cell *result)
340     {
341     int res=0;
342     int len=0;
343     psiconv_u32 temp;
344     psiconv_bool_t has_layout;
345     int leng;
346    
347     psiconv_progress(lev+1,off,"Going to read a sheet cell structure");
348     if (!(*result = malloc(sizeof(**result))))
349     goto ERROR1;
350    
351     psiconv_progress(lev+2,off+len,"Going to read the cell position");
352     temp = psiconv_read_u8(buf,lev+2,off+len,&res);
353     if (res)
354     goto ERROR2;
355     len ++;
356     temp += psiconv_read_u8(buf,lev+2,off+len,&res) << 8;
357     if (res)
358     goto ERROR2;
359     len ++;
360     temp += psiconv_read_u8(buf,lev+2,off+len,&res) << 16;
361     if (res)
362     goto ERROR2;
363     len ++;
364     (*result)->column = (temp >> 2) & 0xFF;
365     (*result)->row = (temp >> 10) & 0x3FFF;
366     psiconv_debug(lev+2,off+len,"Cell position is col:%02x row:%04x",
367     (*result)->column,(*result)->row);
368    
369     psiconv_progress(lev+2,off+len,"Going to read the cell type");
370     temp = psiconv_read_u8(buf,lev+2,off+len,&res);
371     if (res)
372     goto ERROR2;
373     len ++;
374     (*result)->type = (temp >> 5) & 0x07;
375     (*result)->calculated = (temp & 0x08)?psiconv_bool_true:psiconv_bool_false;
376     has_layout = (temp & 0x10)?psiconv_bool_true:psiconv_bool_false;
377    
378     psiconv_progress(lev+2,off+len,"Going to read the cell value");
379     if ((*result)->type == psiconv_cell_blank) {
380     psiconv_debug(lev+2,off+len,"Cell type is blank: no value given.");
381     } else if ((*result)->type == psiconv_cell_int) {
382     psiconv_progress(lev+2,off+len,"Going to read an integer");
383     (*result)->data.dat_int = psiconv_read_u32(buf,lev+2,off+len,&res);
384     if (res)
385     goto ERROR2;
386     len += 4;
387     psiconv_debug(lev+2,off+len,"Cell contents: %ld",(*result)->data.dat_int);
388    
389     } else if ((*result)->type == psiconv_cell_bool) {
390     psiconv_progress(lev+2,off+len,"Going to read a boolean");
391     temp = psiconv_read_u8(buf,lev+2,off+len,&res);
392     if (res)
393     goto ERROR2;
394     len ++;
395     psiconv_debug(lev+2,off+len,"Cell contents: %01x",temp);
396     (*result)->data.dat_bool = temp?psiconv_bool_true:psiconv_bool_false;
397    
398     } else if ((*result)->type == psiconv_cell_error) {
399     psiconv_progress(lev+2,off+len,"Going to read the error code");
400     (*result)->data.dat_error = psiconv_read_u16(buf,lev+2,off+len,&res);
401     if (res)
402     goto ERROR2;
403     len += 2;
404     psiconv_debug(lev+2,off+len,"Cell contents: %04x",
405     (*result)->data.dat_error);
406    
407     } else if ((*result)->type == psiconv_cell_float) {
408     psiconv_progress(lev+2,off+len,"Going to read a float");
409     (*result)->data.dat_float =
410     psiconv_read_float(buf,lev+2,off+len,&leng,&res);
411     if (res)
412     goto ERROR2;
413     len += leng;
414     psiconv_debug(lev+2,off+len,"Cell contents: %f",(*result)->data.dat_float);
415    
416     } else if ((*result)->type == psiconv_cell_string) {
417     psiconv_progress(lev+2,off+len,"Going to read a string");
418     (*result)->data.dat_string =
419     psiconv_read_short_string(buf,lev+2,off+len,&leng,&res);
420     if (res)
421     goto ERROR2;
422     len += leng;
423     psiconv_debug(lev+2,off+len,"Cell contents: `%s'",
424     (*result)->data.dat_string);
425     } else {
426     psiconv_warn(lev+2,off+len,"Unknown Sheet Cell type: %02x",(*result)->type);
427     }
428    
429     if (has_layout) {
430     psiconv_progress(lev+2,off+len,"Going to read the cell layout");
431    
432     psiconv_progress(lev+2,off+len,"Going to read the cell layout flags");
433     temp = psiconv_read_u8(buf,lev+2,off+len,&res);
434     if (res)
435     goto ERROR2;
436     len ++;
437    
438     if (temp & 0x01) {
439     if (!((*result)->paragraph = psiconv_basic_paragraph_layout()))
440     goto ERROR2;
441     psiconv_progress(lev+3,off+len,"Going to read the paragraph codes");
442     if ((res = psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng,
443     (*result)->paragraph)))
444     goto ERROR2;
445     len += leng;
446     }
447    
448     if (temp & 0x02) {
449     psiconv_progress(lev+3,off+len,"Going to read the character codes");
450     if (!((*result)->character = psiconv_basic_character_layout()))
451     goto ERROR2;
452     if ((res = psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng,
453     (*result)->character)))
454     goto ERROR2;
455     len += leng;
456     }
457    
458     if (temp & 0x04) {
459     /* TODO: default number format */
460     psiconv_read_u8(buf,lev+2,off+len,&res);
461     if (res)
462     goto ERROR2;
463     len ++;
464     psiconv_read_u8(buf,lev+2,off+len,&res);
465     if (res)
466     goto ERROR2;
467     len ++;
468     psiconv_read_u8(buf,lev+2,off+len,&res);
469     if (res)
470     goto ERROR2;
471     len ++;
472     }
473     }
474    
475     if ((*result)->calculated) {
476     psiconv_progress(lev+2,off+len,"Going to read the cell formula reference");
477     temp = psiconv_read_X(buf,lev+2,off+len,&leng,&res);
478     if (res)
479     goto ERROR2;
480     psiconv_debug(lev+2,off+len,"Cell formula reference: %d",temp);
481     len += leng;
482     (*result)->ref_formula = temp;
483     }
484    
485     if (length)
486     *length = len;
487    
488     psiconv_progress(lev,off+len-1,
489     "End of sheet cell structure (total length: %08x)", len);
490     return 0;
491    
492     ERROR2:
493     psiconv_free_sheet_cell(*result);
494     ERROR1:
495     psiconv_warn(lev+1,off,"Reading of Sheet Cell Structure failed");
496     if (length)
497     *length = 0;
498     if (!res)
499     return -PSICONV_E_NOMEM;
500     else
501     return res;
502     }
503    
504     int psiconv_parse_sheet_cell_list(const psiconv_buffer buf, int lev,
505     psiconv_u32 off, int *length,
506     psiconv_sheet_cell_list *result)
507     {
508     int res=0;
509     int len=0;
510     psiconv_u32 temp;
511     psiconv_sheet_cell cell;
512     psiconv_u32 listlen,i;
513     int leng;
514    
515     psiconv_progress(lev+1,off,"Going to read the sheet cells list");
516     if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_cell_s))))
517     goto ERROR1;
518    
519     psiconv_progress(lev+2,off+len,
520     "Going to read the initial byte (%02x expected)",0x02);
521     temp = psiconv_read_u8(buf,lev+2,off+len,&res);
522     if (res)
523     goto ERROR2;
524     if (temp != 0x02) {
525     psiconv_warn(lev+2,off+len,
526     "Sheet cell list initial byte unknown value (ignored)");
527     psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
528     }
529     len ++;
530    
531     psiconv_progress(lev+2,off+len,
532     "Going to read the initial byte (%02x expected)",0x00);
533     temp = psiconv_read_u8(buf,lev+2,off+len,&res);
534     if (res)
535     goto ERROR2;
536     if (temp != 0x00) {
537     psiconv_warn(lev+2,off+len,
538     "Sheet cell list initial byte unknown value (ignored)");
539     psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
540     }
541     len ++;
542    
543     psiconv_progress(lev+2,off+len,
544     "Going to read the number of defined cells");
545     listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res);
546     if (res)
547     goto ERROR2;
548     psiconv_debug(lev+2,off+len,"Number of defined cells: %d",listlen);
549     len += leng;
550    
551     psiconv_progress(lev+2,off+len,"Going to read all cells");
552     for (i = 0; i < listlen; i++) {
553     psiconv_progress(lev+3,off+len,"Going to read cell %d",i);
554     if ((res = psiconv_parse_sheet_cell(buf,lev+3,off+len,&leng,&cell)))
555     goto ERROR2;
556     if ((res = psiconv_list_add(*result,cell)))
557     goto ERROR3;
558     len += leng;
559     }
560    
561     if (length)
562     *length = len;
563    
564     psiconv_progress(lev,off+len-1,
565     "End of sheet cell list (total length: %08x)", len);
566     return 0;
567    
568     ERROR3:
569     psiconv_free_sheet_cell(cell);
570     ERROR2:
571     psiconv_free_sheet_cell_list(*result);
572     ERROR1:
573     psiconv_warn(lev+1,off,"Reading of Sheet Cells List failed");
574     if (length)
575     *length = 0;
576     if (!res)
577     return -PSICONV_E_NOMEM;
578     else
579     return res;
580     }
581    
582    
583     int psiconv_parse_sheet_worksheet_section(const psiconv_buffer buf, int lev,
584     psiconv_u32 off, int *length,
585     psiconv_sheet_worksheet_section *result)
586     {
587     int res=0;
588     psiconv_u32 temp,cells_off,grid_off;
589     int len=0;
590     int leng;
591    
592     /* TODO: this is the section that might be an XListE instead... */
593     psiconv_progress(lev+2,off+len,
594     "Going to read the initial bytes (%02x expected)",0x02);
595     temp = psiconv_read_u8(buf,lev+2,off+len,&res);
596     if (res)
597     goto ERROR1;
598     if (temp != 0x04) {
599     psiconv_warn(lev+2,off+len,
600     "Sheet worksheet section initial byte unknown value (ignored)");
601     psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
602     }
603     len ++;
604    
605     psiconv_progress(lev+2,off+len,
606     "Going to read the initial bytes (%02x expected)",0x02);
607     temp = psiconv_read_u8(buf,lev+2,off+len,&res);
608     if (res)
609     goto ERROR1;
610     if (temp != 0x04) {
611     psiconv_warn(lev+2,off+len,
612     "Sheet worksheet section initial byte unknown value (ignored)");
613     psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
614     }
615     len ++;
616    
617     psiconv_progress(lev+2,off+len,
618     "Going to read the initial bytes (%02x expected)",0x00);
619     temp = psiconv_read_u8(buf,lev+2,off+len,&res);
620     if (res)
621     goto ERROR1;
622     if (temp != 0x04) {
623     psiconv_warn(lev+2,off+len,
624     "Sheet worksheet section initial byte unknown value (ignored)");
625     psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
626     }
627     len ++;
628    
629     psiconv_progress(lev+2,off+len,
630     "Going to read the offset of the Worksheet Section");
631     temp = psiconv_read_u32(buf,lev+2,off+len,&res);
632     if (res)
633     goto ERROR1;
634     psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
635     len += 4;
636    
637     len = 0;
638     off = temp;
639    
640     /* this is the real worksheet section from here */
641    
642     psiconv_progress(lev+1,off,"Going to read the sheet worksheet section");
643     if (!(*result = malloc(sizeof(**result))))
644     goto ERROR1;
645    
646     psiconv_progress(lev+2,off+len,
647     "Going to read the initial bytes (%02x expected)",0x04);
648     temp = psiconv_read_u8(buf,lev+2,off+len,&res);
649     if (res)
650     goto ERROR2;
651     if (temp != 0x04) {
652     psiconv_warn(lev+2,off+len,
653     "Worksheet section initial byte unknown value (ignored)");
654     psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
655     }
656     len ++;
657    
658     psiconv_progress(lev+2,off+len,
659     "Going to read the initial bytes (%02x expected)",0x01);
660     temp = psiconv_read_u8(buf,lev+2,off+len,&res);
661     if (res)
662     goto ERROR2;
663     if (temp != 0x01) {
664     psiconv_warn(lev+2,off+len,
665     "Worksheet section initial byte unknown value (ignored)");
666     psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
667     }
668     len ++;
669    
670     psiconv_progress(lev+2,off+len,
671     "Going to read the initial bytes (%02x expected)",0x02);
672     temp = psiconv_read_u8(buf,lev+2,off+len,&res);
673     if (res)
674     goto ERROR2;
675     if (temp != 0x02) {
676     psiconv_warn(lev+2,off+len,
677     "Worksheet section initial byte unknown value (ignored)");
678     psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp);
679     }
680     len ++;
681    
682     psiconv_progress(lev+2,off+len,"Going to read the default formats flag");
683     temp = psiconv_read_u8(buf,lev+2,off+len,&res);
684     if (res)
685     goto ERROR2;
686     len ++;
687    
688     if (temp & 0x01) {
689     if (!((*result)->paragraph = psiconv_basic_paragraph_layout()))
690     goto ERROR2;
691     psiconv_progress(lev+3,off+len,"Going to read the default paragraph codes");
692     if ((res = psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng,
693     (*result)->paragraph)))
694     goto ERROR2_1;
695     len += leng;
696     }
697    
698     if (temp & 0x02) {
699     psiconv_progress(lev+3,off+len,"Going to read the default character codes");
700     if (!((*result)->character = psiconv_basic_character_layout()))
701     goto ERROR2_1;
702     if ((res = psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng,
703     (*result)->character)))
704     goto ERROR2_2;
705     len += leng;
706     }
707    
708     if (temp & 0x04) {
709     /* TODO: default number format */
710     psiconv_read_u8(buf,lev+2,off+len,&res);
711     if (res)
712     goto ERROR2_3;
713     len ++;
714     psiconv_read_u8(buf,lev+2,off+len,&res);
715     if (res)
716     goto ERROR2_3;
717     len ++;
718     psiconv_read_u8(buf,lev+2,off+len,&res);
719     if (res)
720     goto ERROR2_3;
721     len ++;
722     }
723    
724     psiconv_progress(lev+2,off+len,
725     "Going to read the offset of the 1st ??? Section");
726     temp = psiconv_read_u32(buf,lev+2,off+len,&res);
727     if (res)
728     goto ERROR2;
729     psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
730     len += 4;
731    
732     psiconv_progress(lev+2,off+len,
733     "Going to read the offset of the 2nd ??? Section");
734     temp = psiconv_read_u32(buf,lev+2,off+len,&res);
735     if (res)
736     goto ERROR2;
737     psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
738     len += 4;
739    
740     psiconv_progress(lev+2,off+len,
741     "Going to read the offset of the Cells List");
742     cells_off = psiconv_read_u32(buf,lev+2,off+len,&res);
743     if (res)
744     goto ERROR2;
745     psiconv_debug(lev+2,off+len,"Offset: %04x",cells_off);
746     len += 4;
747    
748     psiconv_progress(lev+2,off+len,
749     "Going to read the offset of the Grid Section");
750     grid_off = psiconv_read_u32(buf,lev+2,off+len,&res);
751     if (res)
752     goto ERROR2;
753     psiconv_debug(lev+2,off+len,"Offset: %04x",grid_off);
754     len += 4;
755    
756     psiconv_progress(lev+2,off+len,
757     "Going to read the offset of the 3rd ??? Section");
758     temp = psiconv_read_u32(buf,lev+2,off+len,&res);
759     if (res)
760     goto ERROR2;
761     psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
762     len += 4;
763    
764     psiconv_progress(lev+2,off+len,"Going to read the cells list");
765     if ((res = psiconv_parse_sheet_cell_list(buf,lev+2,cells_off,NULL,
766     &(*result)->cells)))
767     goto ERROR2;
768    
769    
770     /* TODO: parse grid section */
771    
772     if (length)
773     *length = len;
774    
775     psiconv_progress(lev,off+len-1,
776     "End of sheet worksheet section (total length: %08x)", len);
777     return 0;
778    
779     ERROR2_3:
780     psiconv_free_numberformat((*result)->numberformat);
781     ERROR2_2:
782     psiconv_free_character_layout((*result)->character);
783     ERROR2_1:
784     psiconv_free_paragraph_layout((*result)->paragraph);
785     goto ERROR2;
786    
787     ERROR2:
788     free (*result);
789     ERROR1:
790     psiconv_warn(lev+1,off,"Reading of Sheet Worksheet Section failed");
791     if (length)
792     *length = 0;
793     if (!res)
794     return -PSICONV_E_NOMEM;
795     else
796     return res;
797     }
798    
799    

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