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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 95 - (show annotations)
Wed Jan 17 12:04:12 2001 UTC (23 years, 2 months ago) by frodo
File MIME type: text/plain
File size: 9155 byte(s)
(Frodo) A little more sheet work. Added a Sheet Workbook section, though
        nothing is really put into it yet.

1 /*
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 psiconv_warn(lev+1,off,"Reading of Sjeet Status Section failed");
177 if (length)
178 *length = 0;
179 if (!res)
180 return -PSICONV_E_NOMEM;
181 else
182 return res;
183 }
184
185 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 psiconv_u32 temp;
191 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 "Going to read the offset of the 2nd ??? Section");
219 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
220 if (res)
221 goto ERROR2;
222 psiconv_debug(lev+2,off+len,"Offset: %04x",temp);
223 len += 4;
224
225 psiconv_progress(lev+2,off+len,
226 "Going to read the offset of the 3rd ??? Section");
227 temp = psiconv_read_u32(buf,lev+2,off+len,&res);
228 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 if (length)
242 *length = len;
243
244 psiconv_progress(lev,off+len-1,
245 "End of sheet workbook section (total length: %08x)", len);
246 return 0;
247
248 ERROR2:
249 free (*result);
250 ERROR1:
251 psiconv_warn(lev+1,off,"Reading of Sheet Workbook Section failed");
252 if (length)
253 *length = 0;
254 if (!res)
255 return -PSICONV_E_NOMEM;
256 else
257 return res;
258 }

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