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 |
121 |
static psiconv_sheet_cell_layout psiconv_basic_cell_layout(void) |
29 |
|
|
{ |
30 |
|
|
psiconv_sheet_cell_layout result; |
31 |
|
|
if (!(result = malloc(sizeof(*result)))) |
32 |
|
|
goto ERROR1; |
33 |
|
|
if (!(result->character = psiconv_basic_character_layout())) |
34 |
|
|
goto ERROR2; |
35 |
|
|
if (!(result->paragraph = psiconv_basic_paragraph_layout())) |
36 |
|
|
goto ERROR3; |
37 |
|
|
if (!(result->numberformat = malloc(sizeof(*result->numberformat)))) |
38 |
|
|
goto ERROR4; |
39 |
|
|
result->numberformat->code = psiconv_numberformat_general; |
40 |
|
|
result->numberformat->decimal = 2; |
41 |
|
|
return result; |
42 |
|
|
ERROR4: |
43 |
|
|
psiconv_free_paragraph_layout(result->paragraph); |
44 |
|
|
ERROR3: |
45 |
|
|
psiconv_free_character_layout(result->character); |
46 |
|
|
ERROR2: |
47 |
|
|
free(result); |
48 |
|
|
ERROR1: |
49 |
|
|
return NULL; |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
static psiconv_sheet_cell_layout psiconv_clone_cell_layout |
53 |
|
|
(psiconv_sheet_cell_layout original) |
54 |
|
|
{ |
55 |
|
|
psiconv_sheet_cell_layout result; |
56 |
|
|
if (!(result = malloc(sizeof(*result)))) |
57 |
|
|
goto ERROR1; |
58 |
|
|
if (!(result->character = |
59 |
|
|
psiconv_clone_character_layout(original->character))) |
60 |
|
|
goto ERROR2; |
61 |
|
|
if (!(result->paragraph = |
62 |
|
|
psiconv_clone_paragraph_layout(original->paragraph))) |
63 |
|
|
goto ERROR3; |
64 |
|
|
if (!(result->numberformat = malloc(sizeof(*result->numberformat)))) |
65 |
|
|
goto ERROR4; |
66 |
|
|
result->numberformat->code = original->numberformat->code; |
67 |
|
|
result->numberformat->decimal = original->numberformat->decimal; |
68 |
|
|
return result; |
69 |
|
|
ERROR4: |
70 |
|
|
psiconv_free_paragraph_layout(result->paragraph); |
71 |
|
|
ERROR3: |
72 |
|
|
psiconv_free_character_layout(result->character); |
73 |
|
|
ERROR2: |
74 |
|
|
free(result); |
75 |
|
|
ERROR1: |
76 |
|
|
return NULL; |
77 |
|
|
} |
78 |
|
|
|
79 |
frodo |
129 |
static psiconv_sheet_cell_reference_t |
80 |
|
|
psiconv_read_var_cellref (const psiconv_buffer buf, int lev, |
81 |
|
|
psiconv_u32 off, int *length, |
82 |
|
|
int *status) |
83 |
|
|
{ |
84 |
|
|
int len=0; |
85 |
|
|
int res; |
86 |
|
|
psiconv_sheet_cell_reference_t result; |
87 |
|
|
psiconv_u32 temp; |
88 |
|
|
|
89 |
|
|
psiconv_progress(lev+1,off+len,"Going to read a sheet cell reference"); |
90 |
|
|
psiconv_progress(lev+2,off+len, |
91 |
|
|
"Going to read the initial byte (%02x expected)",0x00); |
92 |
|
|
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
93 |
|
|
if (res) |
94 |
|
|
goto ERROR1; |
95 |
|
|
if (temp != 0x00) { |
96 |
|
|
psiconv_warn(lev+2,off+len, |
97 |
|
|
"Sheet cell reference initial byte unknown value (ignored)"); |
98 |
|
|
psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
99 |
|
|
} |
100 |
|
|
len ++; |
101 |
|
|
|
102 |
|
|
temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
103 |
|
|
if (res) |
104 |
|
|
goto ERROR1; |
105 |
|
|
if (temp & 0xffff0000) { |
106 |
|
|
psiconv_warn(lev+2,off+len, |
107 |
|
|
"Sheet cell row reference to unknown row (reset)"); |
108 |
|
|
} |
109 |
|
|
result.row.offset = temp; |
110 |
|
|
result.row.absolute = psiconv_bool_true; |
111 |
|
|
len += 4; |
112 |
|
|
|
113 |
|
|
temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
114 |
|
|
if (res) |
115 |
|
|
goto ERROR1; |
116 |
|
|
if (temp & 0xffff0000) { |
117 |
|
|
psiconv_warn(lev+2,off+len, |
118 |
|
|
"Sheet cell column reference to unknown row (reset)"); |
119 |
|
|
} |
120 |
|
|
result.column.offset = temp; |
121 |
|
|
result.column.absolute = psiconv_bool_true; |
122 |
|
|
len += 4; |
123 |
|
|
|
124 |
|
|
if (length) |
125 |
|
|
*length = len; |
126 |
|
|
|
127 |
|
|
psiconv_progress(lev,off+len-1, |
128 |
|
|
"End of sheet column reference (total length: %08x)", len); |
129 |
|
|
return result; |
130 |
|
|
ERROR1: |
131 |
|
|
psiconv_warn(lev+1,off,"Reading of Sheet Column Reference failed"); |
132 |
|
|
if (length) |
133 |
|
|
*length = 0; |
134 |
|
|
if (status) |
135 |
|
|
*status = res?res:-PSICONV_E_NOMEM; |
136 |
|
|
return result; |
137 |
|
|
} |
138 |
|
|
|
139 |
|
|
static psiconv_sheet_cell_block_t |
140 |
|
|
psiconv_read_var_cellblock (const psiconv_buffer buf, int lev, |
141 |
|
|
psiconv_u32 off, int *length, |
142 |
|
|
int *status) |
143 |
|
|
{ |
144 |
|
|
int len=0; |
145 |
|
|
int res; |
146 |
|
|
psiconv_sheet_cell_block_t result; |
147 |
|
|
psiconv_u32 temp; |
148 |
|
|
|
149 |
|
|
psiconv_progress(lev+1,off+len,"Going to read a sheet cell block reference"); |
150 |
|
|
psiconv_progress(lev+2,off+len, |
151 |
|
|
"Going to read the initial byte (%02x expected)",0x00); |
152 |
|
|
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
153 |
|
|
if (res) |
154 |
|
|
goto ERROR1; |
155 |
|
|
if (temp != 0x00) { |
156 |
|
|
psiconv_warn(lev+2,off+len, |
157 |
|
|
"Sheet cell reference initial byte unknown value (ignored)"); |
158 |
|
|
psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
159 |
|
|
} |
160 |
|
|
len ++; |
161 |
|
|
|
162 |
|
|
temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
163 |
|
|
if (res) |
164 |
|
|
goto ERROR1; |
165 |
|
|
if (temp & 0xffff0000) { |
166 |
|
|
psiconv_warn(lev+2,off+len, |
167 |
|
|
"Sheet block initial row reference to unknown row (reset)"); |
168 |
|
|
} |
169 |
|
|
result.first.row.offset = temp; |
170 |
|
|
result.first.row.absolute = psiconv_bool_true; |
171 |
|
|
len += 4; |
172 |
|
|
|
173 |
|
|
temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
174 |
|
|
if (res) |
175 |
|
|
goto ERROR1; |
176 |
|
|
if (temp & 0xffff0000) { |
177 |
|
|
psiconv_warn(lev+2,off+len, |
178 |
|
|
"Sheet block initial column reference to unknown row (reset)"); |
179 |
|
|
} |
180 |
|
|
result.first.column.offset = temp; |
181 |
|
|
result.first.column.absolute = psiconv_bool_true; |
182 |
|
|
len += 4; |
183 |
|
|
|
184 |
|
|
temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
185 |
|
|
if (res) |
186 |
|
|
goto ERROR1; |
187 |
|
|
if (temp & 0xffff0000) { |
188 |
|
|
psiconv_warn(lev+2,off+len, |
189 |
|
|
"Sheet block final row reference to unknown row (reset)"); |
190 |
|
|
} |
191 |
|
|
result.last.row.offset = temp; |
192 |
|
|
result.last.row.absolute = psiconv_bool_true; |
193 |
|
|
len += 4; |
194 |
|
|
|
195 |
|
|
temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
196 |
|
|
if (res) |
197 |
|
|
goto ERROR1; |
198 |
|
|
if (temp & 0xffff0000) { |
199 |
|
|
psiconv_warn(lev+2,off+len, |
200 |
|
|
"Sheet block final column reference to unknown row (reset)"); |
201 |
|
|
} |
202 |
|
|
result.last.column.offset = temp; |
203 |
|
|
result.last.column.absolute = psiconv_bool_true; |
204 |
|
|
len += 4; |
205 |
|
|
|
206 |
|
|
if (length) |
207 |
|
|
*length = len; |
208 |
|
|
|
209 |
|
|
psiconv_progress(lev,off+len-1, |
210 |
|
|
"End of sheet cell block reference (total length: %08x)", |
211 |
|
|
len); |
212 |
|
|
return result; |
213 |
|
|
ERROR1: |
214 |
|
|
psiconv_warn(lev+1,off,"Reading of Sheet Cell Block Reference failed"); |
215 |
|
|
if (length) |
216 |
|
|
*length = 0; |
217 |
|
|
if (status) |
218 |
|
|
*status = res?res:-PSICONV_E_NOMEM; |
219 |
|
|
return result; |
220 |
|
|
} |
221 |
|
|
|
222 |
frodo |
111 |
int psiconv_parse_sheet_numberformat(const psiconv_buffer buf, int lev, |
223 |
|
|
psiconv_u32 off, int *length, |
224 |
frodo |
121 |
psiconv_sheet_numberformat result) |
225 |
frodo |
111 |
{ |
226 |
|
|
int res=0; |
227 |
|
|
int len=0; |
228 |
|
|
psiconv_u8 temp; |
229 |
|
|
|
230 |
|
|
psiconv_progress(lev+1,off,"Going to read a sheet numberformat"); |
231 |
|
|
|
232 |
|
|
psiconv_progress(lev+2,off+len, |
233 |
|
|
"Going to read the initial byte (%02x expected)",0x02); |
234 |
|
|
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
235 |
|
|
if (res) |
236 |
frodo |
121 |
goto ERROR1; |
237 |
frodo |
111 |
if (temp != 0x02) { |
238 |
|
|
psiconv_warn(lev+2,off+len, |
239 |
|
|
"Sheet numberformat initial byte unknown value (ignored)"); |
240 |
|
|
psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
241 |
|
|
} |
242 |
|
|
len ++; |
243 |
|
|
|
244 |
|
|
psiconv_progress(lev+2,off+len, "Going to read the code byte"); |
245 |
|
|
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
246 |
|
|
if (res) |
247 |
frodo |
121 |
goto ERROR1; |
248 |
frodo |
111 |
psiconv_debug(lev+2,off+len,"Code: %02x",temp); |
249 |
|
|
if (temp == 0x00) |
250 |
frodo |
121 |
result->code = psiconv_numberformat_general; |
251 |
frodo |
111 |
else if (temp == 0x02) |
252 |
frodo |
121 |
result->code = psiconv_numberformat_fixeddecimal; |
253 |
frodo |
111 |
else if (temp == 0x04) |
254 |
frodo |
121 |
result->code = psiconv_numberformat_scientific; |
255 |
frodo |
111 |
else if (temp == 0x06) |
256 |
frodo |
121 |
result->code = psiconv_numberformat_currency; |
257 |
frodo |
111 |
else if (temp == 0x08) |
258 |
frodo |
121 |
result->code = psiconv_numberformat_percent; |
259 |
frodo |
111 |
else if (temp == 0x0A) |
260 |
frodo |
121 |
result->code = psiconv_numberformat_triads; |
261 |
frodo |
111 |
else if (temp == 0x0C) |
262 |
frodo |
121 |
result->code = psiconv_numberformat_boolean; |
263 |
frodo |
111 |
else if (temp == 0x0E) |
264 |
frodo |
121 |
result->code = psiconv_numberformat_text; |
265 |
frodo |
111 |
else if (temp == 0x10) |
266 |
frodo |
122 |
result->code = psiconv_numberformat_date_dmm; |
267 |
frodo |
111 |
else if (temp == 0x12) |
268 |
frodo |
122 |
result->code = psiconv_numberformat_date_mmd; |
269 |
frodo |
111 |
else if (temp == 0x14) |
270 |
frodo |
121 |
result->code = psiconv_numberformat_date_ddmmyy; |
271 |
frodo |
111 |
else if (temp == 0x16) |
272 |
frodo |
121 |
result->code = psiconv_numberformat_date_mmddyy; |
273 |
frodo |
111 |
else if (temp == 0x18) |
274 |
frodo |
121 |
result->code = psiconv_numberformat_date_yymmdd; |
275 |
frodo |
111 |
else if (temp == 0x1A) |
276 |
frodo |
122 |
result->code = psiconv_numberformat_date_dmmm; |
277 |
frodo |
111 |
else if (temp == 0x1C) |
278 |
frodo |
122 |
result->code = psiconv_numberformat_date_dmmmyy; |
279 |
|
|
else if (temp == 0x1E) |
280 |
frodo |
121 |
result->code = psiconv_numberformat_date_ddmmmyy; |
281 |
frodo |
111 |
else if (temp == 0x20) |
282 |
frodo |
121 |
result->code = psiconv_numberformat_date_mmm; |
283 |
frodo |
111 |
else if (temp == 0x22) |
284 |
frodo |
121 |
result->code = psiconv_numberformat_date_monthname; |
285 |
frodo |
111 |
else if (temp == 0x24) |
286 |
frodo |
121 |
result->code = psiconv_numberformat_date_mmmyy; |
287 |
frodo |
111 |
else if (temp == 0x26) |
288 |
frodo |
121 |
result->code = psiconv_numberformat_date_monthnameyy; |
289 |
frodo |
111 |
else if (temp == 0x28) |
290 |
frodo |
122 |
result->code = psiconv_numberformat_date_monthnamedyyyy; |
291 |
frodo |
111 |
else if (temp == 0x2A) |
292 |
frodo |
121 |
result->code = psiconv_numberformat_datetime_ddmmyyyyhhii; |
293 |
frodo |
111 |
else if (temp == 0x2C) |
294 |
frodo |
121 |
result->code = psiconv_numberformat_datetime_ddmmyyyyHHii; |
295 |
frodo |
111 |
else if (temp == 0x2E) |
296 |
frodo |
121 |
result->code = psiconv_numberformat_datetime_mmddyyyyhhii; |
297 |
frodo |
111 |
else if (temp == 0x30) |
298 |
frodo |
121 |
result->code = psiconv_numberformat_datetime_mmddyyyyHHii; |
299 |
frodo |
111 |
else if (temp == 0x32) |
300 |
frodo |
121 |
result->code = psiconv_numberformat_datetime_yyyymmddhhii; |
301 |
frodo |
111 |
else if (temp == 0x34) |
302 |
frodo |
121 |
result->code = psiconv_numberformat_datetime_yyyymmddHHii; |
303 |
frodo |
111 |
else if (temp == 0x36) |
304 |
frodo |
121 |
result->code = psiconv_numberformat_time_hhii; |
305 |
frodo |
111 |
else if (temp == 0x38) |
306 |
frodo |
121 |
result->code = psiconv_numberformat_time_hhiiss; |
307 |
frodo |
111 |
else if (temp == 0x3A) |
308 |
frodo |
121 |
result->code = psiconv_numberformat_time_HHii; |
309 |
frodo |
111 |
else if (temp == 0x3C) |
310 |
frodo |
121 |
result->code = psiconv_numberformat_time_HHiiss; |
311 |
frodo |
111 |
else { |
312 |
|
|
psiconv_warn(lev+2,off+len,"Unknown number format (assumed general)"); |
313 |
frodo |
121 |
result->code = psiconv_numberformat_general; |
314 |
frodo |
111 |
} |
315 |
|
|
len ++; |
316 |
|
|
|
317 |
|
|
psiconv_progress(lev+2,off+len, "Going to read the number of decimals"); |
318 |
frodo |
122 |
result->decimal = psiconv_read_u8(buf,lev+2,off+len,&res) >> 1; |
319 |
frodo |
111 |
if (res) |
320 |
frodo |
121 |
goto ERROR1; |
321 |
|
|
psiconv_debug(lev+2,off+len,"Decimals: %d",result->decimal); |
322 |
frodo |
111 |
len ++; |
323 |
|
|
|
324 |
|
|
if (length) |
325 |
|
|
*length = len; |
326 |
|
|
|
327 |
|
|
psiconv_progress(lev,off+len-1, |
328 |
|
|
"End of sheet number format (total length: %08x)", len); |
329 |
|
|
return 0; |
330 |
|
|
|
331 |
|
|
ERROR1: |
332 |
|
|
psiconv_warn(lev+1,off,"Reading of Sheet Number Format failed"); |
333 |
|
|
if (length) |
334 |
|
|
*length = 0; |
335 |
|
|
if (!res) |
336 |
|
|
return -PSICONV_E_NOMEM; |
337 |
|
|
else |
338 |
|
|
return res; |
339 |
|
|
} |
340 |
|
|
|
341 |
frodo |
94 |
int psiconv_parse_sheet_status_section(const psiconv_buffer buf, int lev, |
342 |
|
|
psiconv_u32 off, int *length, |
343 |
|
|
psiconv_sheet_status_section *result) |
344 |
|
|
{ |
345 |
|
|
int res=0; |
346 |
|
|
int len=0; |
347 |
|
|
psiconv_u32 temp; |
348 |
|
|
int leng; |
349 |
|
|
|
350 |
|
|
psiconv_progress(lev+1,off,"Going to read the sheet status section"); |
351 |
|
|
if (!(*result = malloc(sizeof(**result)))) |
352 |
|
|
goto ERROR1; |
353 |
|
|
|
354 |
|
|
psiconv_progress(lev+2,off+len, |
355 |
|
|
"Going to read the initial byte (%02x expected)",0x02); |
356 |
|
|
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
357 |
|
|
if (res) |
358 |
|
|
goto ERROR2; |
359 |
|
|
if (temp != 0x02) { |
360 |
|
|
psiconv_warn(lev+2,off+len, |
361 |
|
|
"Sheet status section initial byte unknown value (ignored)"); |
362 |
|
|
psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
363 |
|
|
} |
364 |
|
|
len ++; |
365 |
|
|
|
366 |
|
|
psiconv_progress(lev+2,off+len, |
367 |
|
|
"Going to read the cursor row"); |
368 |
|
|
(*result)->cursor_row = psiconv_read_u32(buf,lev+2,off + len,&res); |
369 |
|
|
if (res) |
370 |
|
|
goto ERROR2; |
371 |
|
|
psiconv_debug(lev+2,off+len,"Cursor row: %08x", |
372 |
|
|
(*result)->cursor_row); |
373 |
|
|
len += 0x04; |
374 |
|
|
|
375 |
|
|
psiconv_progress(lev+2,off+len, |
376 |
|
|
"Going to read the cursor column"); |
377 |
|
|
(*result)->cursor_column = psiconv_read_u32(buf,lev+2,off + len,&res); |
378 |
|
|
if (res) |
379 |
|
|
goto ERROR2; |
380 |
|
|
psiconv_debug(lev+2,off+len,"Cursor column: %08x", |
381 |
|
|
(*result)->cursor_column); |
382 |
|
|
len += 0x04; |
383 |
|
|
|
384 |
|
|
psiconv_progress(lev+2,off+len,"Going to read initially display graph"); |
385 |
|
|
if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng, |
386 |
|
|
&(*result)->show_graph))) |
387 |
|
|
goto ERROR2; |
388 |
|
|
len += leng; |
389 |
|
|
|
390 |
|
|
psiconv_progress(lev+2,off+len, |
391 |
|
|
"Going to read the toolbar status byte"); |
392 |
|
|
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
393 |
|
|
if (res) |
394 |
|
|
goto ERROR2; |
395 |
|
|
|
396 |
|
|
(*result)->show_side_sheet_toolbar = temp&0x01 ? psiconv_bool_true : |
397 |
|
|
psiconv_bool_false; |
398 |
|
|
psiconv_debug(lev+2,off+len,"Show side sheet toolbar: %02x", |
399 |
|
|
(*result)->show_side_sheet_toolbar); |
400 |
|
|
(*result)->show_top_sheet_toolbar = temp&0x02 ? psiconv_bool_true : |
401 |
|
|
psiconv_bool_false; |
402 |
|
|
psiconv_debug(lev+2,off+len,"Show top sheet toolbar: %02x", |
403 |
|
|
(*result)->show_top_sheet_toolbar); |
404 |
|
|
(*result)->show_side_graph_toolbar = temp&0x04 ? psiconv_bool_true : |
405 |
|
|
psiconv_bool_false; |
406 |
|
|
psiconv_debug(lev+2,off+len,"Show side graph toolbar: %02x", |
407 |
|
|
(*result)->show_side_graph_toolbar); |
408 |
|
|
(*result)->show_top_graph_toolbar = temp&0x08 ? psiconv_bool_true : |
409 |
|
|
psiconv_bool_false; |
410 |
|
|
psiconv_debug(lev+2,off+len,"Show top graph toolbar: %02x", |
411 |
|
|
(*result)->show_top_graph_toolbar); |
412 |
|
|
if (temp & 0xf0) { |
413 |
|
|
psiconv_warn(lev+2,off+len,"Sheet status section toolbar byte " |
414 |
|
|
"flags contains unknown flags (ignored)"); |
415 |
|
|
psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0xf0); |
416 |
|
|
} |
417 |
|
|
len ++; |
418 |
|
|
|
419 |
|
|
psiconv_progress(lev+2,off+len, |
420 |
|
|
"Going to read the scrollbar status byte"); |
421 |
|
|
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
422 |
|
|
if (res) |
423 |
|
|
goto ERROR2; |
424 |
|
|
if ((temp & 0x03) == 0x03) { |
425 |
|
|
psiconv_warn(lev+2,off+len,"Sheet status section scrollbar byte " |
426 |
|
|
"flags contains unknown flags (ignored)"); |
427 |
|
|
psiconv_debug(lev+2,off+len,"Unknown flag: %02x",temp & 0x03); |
428 |
|
|
} |
429 |
|
|
(*result)->show_horizontal_scrollbar = (temp&0x03) == 1? psiconv_triple_off : |
430 |
|
|
(temp&0x03) == 2? psiconv_triple_auto: |
431 |
|
|
psiconv_triple_on; |
432 |
|
|
psiconv_debug(lev+2,off+len,"Show horizontal scrollbar: %02x", |
433 |
|
|
(*result)->show_horizontal_scrollbar); |
434 |
|
|
if ((temp & 0x0c) == 0x0c) { |
435 |
|
|
psiconv_warn(lev+2,off+len,"Sheet status section scrollbar byte " |
436 |
|
|
"flags contains unknown flags (ignored)"); |
437 |
|
|
psiconv_debug(lev+2,off+len,"Unknown flag: %02x",temp & 0x0c); |
438 |
|
|
} |
439 |
|
|
(*result)->show_vertical_scrollbar = (temp&0x0c) ==0x04? psiconv_triple_off: |
440 |
|
|
(temp&0x0c) ==0x08? psiconv_triple_auto: |
441 |
|
|
psiconv_triple_on; |
442 |
|
|
psiconv_debug(lev+2,off+len,"Show vertical scrollbar: %02x", |
443 |
|
|
(*result)->show_vertical_scrollbar); |
444 |
|
|
if (temp & 0xf0) { |
445 |
|
|
psiconv_warn(lev+2,off+len,"Sheet status section scrollbar byte " |
446 |
|
|
"flags contains unknown flags (ignored)"); |
447 |
|
|
psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp & 0xf0); |
448 |
|
|
} |
449 |
|
|
len ++; |
450 |
|
|
|
451 |
|
|
psiconv_progress(lev+2,off+len, |
452 |
|
|
"Going to read an unknown byte (%02x expected)",0x00); |
453 |
|
|
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
454 |
|
|
if (res) |
455 |
|
|
goto ERROR2; |
456 |
|
|
if (temp != 0x00) { |
457 |
|
|
psiconv_warn(lev+2,off+len, |
458 |
|
|
"Sheet status section unknown byte unknown value (ignored)"); |
459 |
frodo |
129 |
psiconv_debug(lev+2,off+len,"Unknown byte: %02x",temp); |
460 |
frodo |
94 |
} |
461 |
|
|
len ++; |
462 |
|
|
|
463 |
|
|
psiconv_progress(lev+2,off+len,"Going to read sheet display size"); |
464 |
|
|
(*result)->sheet_display_size = psiconv_read_u32(buf,lev+2,off + len,&res); |
465 |
|
|
if (res) |
466 |
|
|
goto ERROR2; |
467 |
|
|
psiconv_debug(lev+2,off+len,"Sheet display size: %08x", |
468 |
|
|
(*result)->sheet_display_size); |
469 |
|
|
len += 0x04; |
470 |
|
|
|
471 |
|
|
psiconv_progress(lev+2,off+len,"Going to read graph display size"); |
472 |
|
|
(*result)->graph_display_size = psiconv_read_u32(buf,lev+2,off + len,&res); |
473 |
|
|
if (res) |
474 |
|
|
goto ERROR2; |
475 |
|
|
psiconv_debug(lev+2,off+len,"Graph display size: %08x", |
476 |
|
|
(*result)->graph_display_size); |
477 |
|
|
len += 0x04; |
478 |
|
|
|
479 |
|
|
if (length) |
480 |
|
|
*length = len; |
481 |
|
|
|
482 |
|
|
psiconv_progress(lev,off+len-1, |
483 |
|
|
"End of sheet status section (total length: %08x)", len); |
484 |
|
|
return 0; |
485 |
|
|
|
486 |
|
|
ERROR2: |
487 |
|
|
free (*result); |
488 |
|
|
ERROR1: |
489 |
frodo |
110 |
psiconv_warn(lev+1,off,"Reading of Sheet Status Section failed"); |
490 |
frodo |
94 |
if (length) |
491 |
|
|
*length = 0; |
492 |
|
|
if (!res) |
493 |
|
|
return -PSICONV_E_NOMEM; |
494 |
|
|
else |
495 |
|
|
return res; |
496 |
|
|
} |
497 |
|
|
|
498 |
frodo |
95 |
int psiconv_parse_sheet_workbook_section(const psiconv_buffer buf, int lev, |
499 |
|
|
psiconv_u32 off, int *length, |
500 |
|
|
psiconv_sheet_workbook_section *result) |
501 |
|
|
{ |
502 |
frodo |
129 |
int res=0,with_name; |
503 |
|
|
psiconv_u32 temp,formulas_off,worksheets_off,info_off,var_off,name_off=0; |
504 |
frodo |
95 |
int len=0; |
505 |
|
|
|
506 |
|
|
psiconv_progress(lev+1,off,"Going to read the sheet workbook section"); |
507 |
|
|
if (!(*result = malloc(sizeof(**result)))) |
508 |
|
|
goto ERROR1; |
509 |
|
|
|
510 |
|
|
psiconv_progress(lev+2,off+len, |
511 |
frodo |
130 |
"Going to read the initial byte (%02x or %02x expected)", |
512 |
frodo |
129 |
0x02,0x04); |
513 |
frodo |
95 |
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
514 |
|
|
if (res) |
515 |
|
|
goto ERROR2; |
516 |
frodo |
129 |
if ((temp != 0x04) && temp !=0x02) { |
517 |
frodo |
95 |
psiconv_warn(lev+2,off+len, |
518 |
|
|
"Sheet workbook section initial byte unknown value (ignored)"); |
519 |
|
|
psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
520 |
|
|
} |
521 |
frodo |
129 |
with_name = temp ==0x04; |
522 |
frodo |
95 |
len ++; |
523 |
|
|
|
524 |
|
|
psiconv_progress(lev+2,off+len, |
525 |
frodo |
129 |
"Going to read the offset of the sheet info Section"); |
526 |
|
|
info_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
527 |
frodo |
95 |
if (res) |
528 |
|
|
goto ERROR2; |
529 |
frodo |
129 |
psiconv_debug(lev+2,off+len,"Offset: %04x",info_off); |
530 |
frodo |
95 |
len += 4; |
531 |
|
|
|
532 |
|
|
psiconv_progress(lev+2,off+len, |
533 |
frodo |
97 |
"Going to read the offset of the Formulas List"); |
534 |
|
|
formulas_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
535 |
frodo |
95 |
if (res) |
536 |
|
|
goto ERROR2; |
537 |
frodo |
97 |
psiconv_debug(lev+2,off+len,"Offset: %04x",formulas_off); |
538 |
frodo |
95 |
len += 4; |
539 |
|
|
|
540 |
|
|
psiconv_progress(lev+2,off+len, |
541 |
frodo |
111 |
"Going to read the offset of the Worksheet List"); |
542 |
frodo |
110 |
worksheets_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
543 |
frodo |
95 |
if (res) |
544 |
|
|
goto ERROR2; |
545 |
frodo |
111 |
psiconv_debug(lev+2,off+len,"Offset: %04x",worksheets_off); |
546 |
frodo |
95 |
len += 4; |
547 |
|
|
|
548 |
|
|
psiconv_progress(lev+2,off+len, |
549 |
frodo |
129 |
"Going to read the offset of the Variable List"); |
550 |
|
|
var_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
551 |
frodo |
95 |
if (res) |
552 |
|
|
goto ERROR2; |
553 |
frodo |
129 |
psiconv_debug(lev+2,off+len,"Offset: %04x",var_off); |
554 |
frodo |
95 |
len += 4; |
555 |
|
|
|
556 |
frodo |
129 |
if (with_name) { |
557 |
|
|
psiconv_progress(lev+2,off+len, |
558 |
|
|
"Going to read the offset of the Name Section"); |
559 |
|
|
name_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
560 |
|
|
if (res) |
561 |
|
|
goto ERROR2; |
562 |
|
|
psiconv_debug(lev+2,off+len,"Offset: %04x",name_off); |
563 |
|
|
len += 4; |
564 |
|
|
} |
565 |
|
|
|
566 |
|
|
|
567 |
|
|
psiconv_progress(lev+2,off+len,"Going to read the info section"); |
568 |
|
|
if ((res = psiconv_parse_sheet_info_section(buf,lev+2,info_off,NULL, |
569 |
|
|
&(*result)->info))) |
570 |
|
|
goto ERROR2; |
571 |
|
|
|
572 |
|
|
psiconv_progress(lev+2,off+len,"Going to read the variables list"); |
573 |
|
|
if ((res = psiconv_parse_sheet_variable_list(buf,lev+2,var_off,NULL, |
574 |
|
|
&(*result)->variables))) |
575 |
|
|
goto ERROR3; |
576 |
|
|
|
577 |
frodo |
97 |
psiconv_progress(lev+2,off+len,"Going to read the formulas list"); |
578 |
frodo |
129 |
if ((res = psiconv_parse_sheet_formula_list(buf,lev+2,formulas_off,NULL, |
579 |
frodo |
98 |
&(*result)->formulas))) |
580 |
frodo |
129 |
goto ERROR4; |
581 |
frodo |
97 |
|
582 |
frodo |
111 |
psiconv_progress(lev+2,off+len,"Going to read the worksheet list"); |
583 |
|
|
if ((res = psiconv_parse_sheet_worksheet_list(buf,lev+2,worksheets_off, |
584 |
|
|
NULL,&(*result)->worksheets))) |
585 |
frodo |
129 |
goto ERROR5; |
586 |
frodo |
97 |
|
587 |
frodo |
129 |
if (with_name) { |
588 |
|
|
psiconv_progress(lev+2,off+len,"Going to read the name section"); |
589 |
|
|
if ((res = psiconv_parse_sheet_name_section(buf,lev+2,name_off,NULL, |
590 |
|
|
&(*result)->name))) |
591 |
|
|
goto ERROR6; |
592 |
|
|
} else |
593 |
|
|
(*result)->name = NULL; |
594 |
frodo |
110 |
|
595 |
frodo |
95 |
if (length) |
596 |
|
|
*length = len; |
597 |
|
|
|
598 |
|
|
psiconv_progress(lev,off+len-1, |
599 |
|
|
"End of sheet workbook section (total length: %08x)", len); |
600 |
|
|
return 0; |
601 |
|
|
|
602 |
frodo |
129 |
ERROR6: |
603 |
|
|
psiconv_free_sheet_worksheet_list((*result)->worksheets); |
604 |
|
|
ERROR5: |
605 |
|
|
psiconv_free_formula_list((*result)->formulas); |
606 |
|
|
ERROR4: |
607 |
|
|
psiconv_free_sheet_variable_list((*result)->variables); |
608 |
|
|
ERROR3: |
609 |
|
|
psiconv_free_sheet_info_section((*result)->info); |
610 |
frodo |
95 |
ERROR2: |
611 |
|
|
free (*result); |
612 |
|
|
ERROR1: |
613 |
|
|
psiconv_warn(lev+1,off,"Reading of Sheet Workbook Section failed"); |
614 |
|
|
if (length) |
615 |
|
|
*length = 0; |
616 |
|
|
if (!res) |
617 |
|
|
return -PSICONV_E_NOMEM; |
618 |
|
|
else |
619 |
|
|
return res; |
620 |
|
|
} |
621 |
frodo |
97 |
|
622 |
frodo |
129 |
int psiconv_parse_sheet_name_section(const psiconv_buffer buf, int lev, |
623 |
|
|
psiconv_u32 off, int *length, |
624 |
|
|
psiconv_sheet_name_section *result) |
625 |
|
|
{ |
626 |
|
|
int res=0; |
627 |
|
|
psiconv_u32 temp; |
628 |
|
|
int len=0,leng; |
629 |
|
|
|
630 |
|
|
psiconv_progress(lev+1,off,"Going to read the sheet name section"); |
631 |
|
|
if (!(*result = malloc(sizeof(**result)))) |
632 |
|
|
goto ERROR1; |
633 |
|
|
|
634 |
|
|
psiconv_progress(lev+2,off+len, |
635 |
|
|
"Going to read the initial byte (%02x expected)",0x02); |
636 |
|
|
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
637 |
|
|
if (res) |
638 |
|
|
goto ERROR2; |
639 |
|
|
if (temp != 0x02) { |
640 |
|
|
psiconv_warn(lev+2,off+len, |
641 |
|
|
"Sheet name section initial byte unknown value (ignored)"); |
642 |
|
|
psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
643 |
|
|
} |
644 |
|
|
len ++; |
645 |
|
|
|
646 |
|
|
psiconv_progress(lev+2,off+len, "Going to read the sheet name"); |
647 |
|
|
(*result)->name = psiconv_read_string(buf,lev+2,off+len,&leng,&res); |
648 |
|
|
if (res) |
649 |
|
|
goto ERROR2; |
650 |
|
|
len += leng; |
651 |
|
|
|
652 |
|
|
if (length) |
653 |
|
|
*length = len; |
654 |
|
|
|
655 |
|
|
psiconv_progress(lev,off+len-1, |
656 |
|
|
"End of sheet name section (total length: %08x)", len); |
657 |
|
|
return 0; |
658 |
|
|
|
659 |
|
|
ERROR2: |
660 |
|
|
free(*result); |
661 |
|
|
ERROR1: |
662 |
|
|
psiconv_warn(lev+1,off,"Reading of Sheet Name Section failed"); |
663 |
|
|
if (length) |
664 |
|
|
*length = 0; |
665 |
|
|
if (!res) |
666 |
|
|
return -PSICONV_E_NOMEM; |
667 |
|
|
else |
668 |
|
|
return res; |
669 |
|
|
} |
670 |
|
|
|
671 |
|
|
int psiconv_parse_sheet_info_section(const psiconv_buffer buf, int lev, |
672 |
|
|
psiconv_u32 off, int *length, |
673 |
|
|
psiconv_sheet_info_section *result) |
674 |
|
|
{ |
675 |
|
|
int res=0; |
676 |
|
|
psiconv_u32 temp; |
677 |
|
|
int len=0; |
678 |
|
|
|
679 |
|
|
psiconv_progress(lev+1,off,"Going to read the sheet info section"); |
680 |
|
|
if (!(*result = malloc(sizeof(**result)))) |
681 |
|
|
goto ERROR1; |
682 |
|
|
|
683 |
|
|
psiconv_progress(lev+2,off+len, |
684 |
|
|
"Going to read the initial byte (%02x expected)",0x02); |
685 |
|
|
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
686 |
|
|
if (res) |
687 |
|
|
goto ERROR2; |
688 |
|
|
if (temp != 0x02) { |
689 |
|
|
psiconv_warn(lev+2,off+len, |
690 |
|
|
"Sheet info section initial byte unknown value (ignored)"); |
691 |
|
|
psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
692 |
|
|
} |
693 |
|
|
len ++; |
694 |
|
|
|
695 |
|
|
psiconv_progress(lev+2,off+len, "Going to read the flags byte"); |
696 |
|
|
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
697 |
|
|
if (res) |
698 |
|
|
goto ERROR2; |
699 |
|
|
(*result)->auto_recalc = temp & 0x01 ? psiconv_bool_true:psiconv_bool_false; |
700 |
|
|
psiconv_debug(lev+2,off+len,"Auto recalculation: %02x", |
701 |
|
|
(*result)->auto_recalc); |
702 |
|
|
if ((temp & 0xfe) != 0x02) { |
703 |
|
|
psiconv_warn(lev+2,off+len,"Sheet Info Section flags byte " |
704 |
|
|
"contains unknown flags (ignored)"); |
705 |
|
|
psiconv_debug(lev+2,off+len,"Unknown flags: %02x",temp &0xfe); |
706 |
|
|
} |
707 |
|
|
|
708 |
|
|
len ++; |
709 |
|
|
|
710 |
|
|
|
711 |
|
|
if (length) |
712 |
|
|
*length = len; |
713 |
|
|
|
714 |
|
|
psiconv_progress(lev,off+len-1, |
715 |
|
|
"End of sheet info section (total length: %08x)", len); |
716 |
|
|
return 0; |
717 |
|
|
|
718 |
|
|
ERROR2: |
719 |
|
|
free(*result); |
720 |
|
|
ERROR1: |
721 |
|
|
psiconv_warn(lev+1,off,"Reading of Sheet Name Section failed"); |
722 |
|
|
if (length) |
723 |
|
|
*length = 0; |
724 |
|
|
if (!res) |
725 |
|
|
return -PSICONV_E_NOMEM; |
726 |
|
|
else |
727 |
|
|
return res; |
728 |
|
|
} |
729 |
|
|
|
730 |
|
|
int psiconv_parse_sheet_formula_list(const psiconv_buffer buf, int lev, |
731 |
frodo |
98 |
psiconv_u32 off, int *length, |
732 |
|
|
psiconv_formula_list *result) |
733 |
frodo |
97 |
{ |
734 |
|
|
int res=0; |
735 |
|
|
int len=0; |
736 |
|
|
psiconv_u32 temp; |
737 |
frodo |
98 |
psiconv_formula formula; |
738 |
frodo |
97 |
psiconv_u32 listlen,i; |
739 |
|
|
int leng; |
740 |
|
|
|
741 |
frodo |
129 |
psiconv_progress(lev+1,off,"Going to read the sheet formula list"); |
742 |
frodo |
98 |
if (!(*result = psiconv_list_new(sizeof(struct psiconv_formula_s)))) |
743 |
frodo |
97 |
goto ERROR1; |
744 |
|
|
|
745 |
|
|
psiconv_progress(lev+2,off+len, |
746 |
|
|
"Going to read the initial byte (%02x expected)",0x02); |
747 |
|
|
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
748 |
|
|
if (res) |
749 |
|
|
goto ERROR2; |
750 |
|
|
if (temp != 0x02) { |
751 |
|
|
psiconv_warn(lev+2,off+len, |
752 |
frodo |
129 |
"Sheet formula list initial byte unknown value (ignored)"); |
753 |
frodo |
97 |
psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
754 |
|
|
} |
755 |
|
|
len ++; |
756 |
|
|
|
757 |
|
|
psiconv_progress(lev+2,off+len, |
758 |
|
|
"Going to read the number of formulas"); |
759 |
|
|
listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
760 |
|
|
if (res) |
761 |
|
|
goto ERROR2; |
762 |
|
|
psiconv_debug(lev+2,off+len,"Number of formulas: %d",listlen); |
763 |
|
|
len += leng; |
764 |
|
|
|
765 |
|
|
psiconv_progress(lev+2,off+len,"Going to read all formulas"); |
766 |
|
|
for (i = 0; i < listlen; i++) { |
767 |
|
|
psiconv_progress(lev+3,off+len,"Going to read formula %d",i); |
768 |
frodo |
98 |
if ((res = psiconv_parse_formula(buf,lev+3,off+len,&leng,&formula))) |
769 |
frodo |
97 |
goto ERROR2; |
770 |
|
|
if ((res = psiconv_list_add(*result,formula))) |
771 |
|
|
goto ERROR3; |
772 |
|
|
len += leng; |
773 |
|
|
} |
774 |
|
|
|
775 |
|
|
if (length) |
776 |
|
|
*length = len; |
777 |
|
|
|
778 |
|
|
psiconv_progress(lev,off+len-1, |
779 |
frodo |
129 |
"End of sheet formula list (total length: %08x)", len); |
780 |
frodo |
97 |
return 0; |
781 |
|
|
|
782 |
|
|
ERROR3: |
783 |
frodo |
98 |
psiconv_free_formula(formula); |
784 |
frodo |
97 |
ERROR2: |
785 |
|
|
psiconv_list_free(*result); |
786 |
|
|
ERROR1: |
787 |
frodo |
129 |
psiconv_warn(lev+1,off,"Reading of Sheet Formula list failed"); |
788 |
frodo |
97 |
if (length) |
789 |
|
|
*length = 0; |
790 |
|
|
if (!res) |
791 |
|
|
return -PSICONV_E_NOMEM; |
792 |
|
|
else |
793 |
|
|
return res; |
794 |
|
|
} |
795 |
frodo |
110 |
|
796 |
|
|
int psiconv_parse_sheet_cell(const psiconv_buffer buf, int lev, |
797 |
frodo |
121 |
psiconv_u32 off, int *length, |
798 |
|
|
psiconv_sheet_cell *result, |
799 |
frodo |
128 |
const psiconv_sheet_cell_layout default_layout, |
800 |
|
|
const psiconv_sheet_line_list row_default_layouts, |
801 |
|
|
const psiconv_sheet_line_list col_default_layouts) |
802 |
frodo |
110 |
{ |
803 |
|
|
int res=0; |
804 |
|
|
int len=0; |
805 |
|
|
psiconv_u32 temp; |
806 |
|
|
psiconv_bool_t has_layout; |
807 |
|
|
int leng; |
808 |
|
|
|
809 |
|
|
psiconv_progress(lev+1,off,"Going to read a sheet cell structure"); |
810 |
|
|
if (!(*result = malloc(sizeof(**result)))) |
811 |
|
|
goto ERROR1; |
812 |
|
|
|
813 |
frodo |
111 |
(*result)->layout = NULL; |
814 |
|
|
(*result)->type = psiconv_cell_blank; |
815 |
|
|
|
816 |
frodo |
110 |
psiconv_progress(lev+2,off+len,"Going to read the cell position"); |
817 |
|
|
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
818 |
|
|
if (res) |
819 |
|
|
goto ERROR2; |
820 |
|
|
len ++; |
821 |
|
|
temp += psiconv_read_u8(buf,lev+2,off+len,&res) << 8; |
822 |
|
|
if (res) |
823 |
|
|
goto ERROR2; |
824 |
|
|
len ++; |
825 |
|
|
temp += psiconv_read_u8(buf,lev+2,off+len,&res) << 16; |
826 |
|
|
if (res) |
827 |
|
|
goto ERROR2; |
828 |
|
|
len ++; |
829 |
|
|
(*result)->column = (temp >> 2) & 0xFF; |
830 |
|
|
(*result)->row = (temp >> 10) & 0x3FFF; |
831 |
|
|
psiconv_debug(lev+2,off+len,"Cell position is col:%02x row:%04x", |
832 |
|
|
(*result)->column,(*result)->row); |
833 |
frodo |
111 |
if (temp & 0x03) { |
834 |
|
|
psiconv_warn(lev+2,off+len,"Unknown flags in cell position (ignored)"); |
835 |
|
|
psiconv_debug(lev+2,off+len,"Flags: %02x",temp & 0x03); |
836 |
|
|
} |
837 |
frodo |
110 |
|
838 |
|
|
psiconv_progress(lev+2,off+len,"Going to read the cell type"); |
839 |
|
|
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
840 |
|
|
if (res) |
841 |
|
|
goto ERROR2; |
842 |
|
|
len ++; |
843 |
|
|
(*result)->type = (temp >> 5) & 0x07; |
844 |
|
|
(*result)->calculated = (temp & 0x08)?psiconv_bool_true:psiconv_bool_false; |
845 |
|
|
has_layout = (temp & 0x10)?psiconv_bool_true:psiconv_bool_false; |
846 |
|
|
|
847 |
|
|
psiconv_progress(lev+2,off+len,"Going to read the cell value"); |
848 |
|
|
if ((*result)->type == psiconv_cell_blank) { |
849 |
|
|
psiconv_debug(lev+2,off+len,"Cell type is blank: no value given."); |
850 |
|
|
} else if ((*result)->type == psiconv_cell_int) { |
851 |
|
|
psiconv_progress(lev+2,off+len,"Going to read an integer"); |
852 |
|
|
(*result)->data.dat_int = psiconv_read_u32(buf,lev+2,off+len,&res); |
853 |
|
|
if (res) |
854 |
|
|
goto ERROR2; |
855 |
|
|
len += 4; |
856 |
|
|
psiconv_debug(lev+2,off+len,"Cell contents: %ld",(*result)->data.dat_int); |
857 |
|
|
|
858 |
|
|
} else if ((*result)->type == psiconv_cell_bool) { |
859 |
|
|
psiconv_progress(lev+2,off+len,"Going to read a boolean"); |
860 |
frodo |
111 |
if ((res = psiconv_parse_bool(buf,lev+2,off+len,&leng, |
861 |
|
|
&(*result)->data.dat_bool))) |
862 |
frodo |
110 |
goto ERROR2; |
863 |
|
|
psiconv_debug(lev+2,off+len,"Cell contents: %01x",temp); |
864 |
|
|
(*result)->data.dat_bool = temp?psiconv_bool_true:psiconv_bool_false; |
865 |
frodo |
111 |
len += leng; |
866 |
frodo |
110 |
} else if ((*result)->type == psiconv_cell_error) { |
867 |
|
|
psiconv_progress(lev+2,off+len,"Going to read the error code"); |
868 |
frodo |
111 |
temp = psiconv_read_u16(buf,lev+2,off+len,&res); |
869 |
|
|
if (res) |
870 |
|
|
goto ERROR2; |
871 |
|
|
if (temp == 0) |
872 |
|
|
(*result)->data.dat_error = psiconv_sheet_error_none; |
873 |
|
|
else if (temp == 1) |
874 |
|
|
(*result)->data.dat_error = psiconv_sheet_error_null; |
875 |
|
|
else if (temp == 2) |
876 |
|
|
(*result)->data.dat_error = psiconv_sheet_error_divzero; |
877 |
|
|
else if (temp == 3) |
878 |
|
|
(*result)->data.dat_error = psiconv_sheet_error_value; |
879 |
|
|
else if (temp == 4) |
880 |
|
|
(*result)->data.dat_error = psiconv_sheet_error_reference; |
881 |
|
|
else if (temp == 5) |
882 |
|
|
(*result)->data.dat_error = psiconv_sheet_error_name; |
883 |
|
|
else if (temp == 6) |
884 |
|
|
(*result)->data.dat_error = psiconv_sheet_error_number; |
885 |
|
|
else if (temp == 7) |
886 |
|
|
(*result)->data.dat_error = psiconv_sheet_error_notavail; |
887 |
|
|
else { |
888 |
|
|
psiconv_warn(lev+2,off+len,"Unknown error code (default assumed)"); |
889 |
|
|
psiconv_debug(lev+2,off+len,"Error code: %04x",temp); |
890 |
|
|
(*result)->data.dat_error = psiconv_sheet_error_none; |
891 |
|
|
} |
892 |
frodo |
110 |
psiconv_debug(lev+2,off+len,"Cell contents: %04x", |
893 |
frodo |
111 |
(*result)->data.dat_error); |
894 |
|
|
len += 2; |
895 |
frodo |
110 |
} else if ((*result)->type == psiconv_cell_float) { |
896 |
|
|
psiconv_progress(lev+2,off+len,"Going to read a float"); |
897 |
|
|
(*result)->data.dat_float = |
898 |
|
|
psiconv_read_float(buf,lev+2,off+len,&leng,&res); |
899 |
frodo |
111 |
if (res) |
900 |
|
|
goto ERROR2; |
901 |
frodo |
110 |
psiconv_debug(lev+2,off+len,"Cell contents: %f",(*result)->data.dat_float); |
902 |
frodo |
111 |
len += leng; |
903 |
frodo |
110 |
} else if ((*result)->type == psiconv_cell_string) { |
904 |
|
|
psiconv_progress(lev+2,off+len,"Going to read a string"); |
905 |
|
|
(*result)->data.dat_string = |
906 |
frodo |
111 |
psiconv_read_string(buf,lev+2,off+len,&leng,&res); |
907 |
|
|
if (res) |
908 |
|
|
goto ERROR2; |
909 |
frodo |
110 |
psiconv_debug(lev+2,off+len,"Cell contents: `%s'", |
910 |
|
|
(*result)->data.dat_string); |
911 |
frodo |
111 |
len += leng; |
912 |
frodo |
110 |
} else { |
913 |
|
|
psiconv_warn(lev+2,off+len,"Unknown Sheet Cell type: %02x",(*result)->type); |
914 |
frodo |
111 |
res = PSICONV_E_PARSE; |
915 |
|
|
goto ERROR2; |
916 |
frodo |
110 |
} |
917 |
|
|
|
918 |
frodo |
128 |
if (!((*result)->layout = psiconv_clone_cell_layout( |
919 |
|
|
psiconv_get_default_layout(row_default_layouts, |
920 |
|
|
col_default_layouts, |
921 |
|
|
default_layout, |
922 |
|
|
(*result)->row, |
923 |
|
|
(*result)->column)))) |
924 |
frodo |
121 |
goto ERROR2; |
925 |
frodo |
110 |
if (has_layout) { |
926 |
frodo |
111 |
if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len, |
927 |
frodo |
121 |
&leng,(*result)->layout))) |
928 |
frodo |
110 |
goto ERROR2; |
929 |
frodo |
111 |
len += leng; |
930 |
frodo |
110 |
} |
931 |
|
|
|
932 |
|
|
if ((*result)->calculated) { |
933 |
|
|
psiconv_progress(lev+2,off+len,"Going to read the cell formula reference"); |
934 |
|
|
temp = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
935 |
|
|
if (res) |
936 |
|
|
goto ERROR2; |
937 |
|
|
psiconv_debug(lev+2,off+len,"Cell formula reference: %d",temp); |
938 |
|
|
len += leng; |
939 |
frodo |
111 |
(*result)->ref_formula = temp; |
940 |
frodo |
110 |
} |
941 |
|
|
|
942 |
|
|
if (length) |
943 |
|
|
*length = len; |
944 |
|
|
|
945 |
|
|
psiconv_progress(lev,off+len-1, |
946 |
|
|
"End of sheet cell structure (total length: %08x)", len); |
947 |
|
|
return 0; |
948 |
|
|
|
949 |
|
|
ERROR2: |
950 |
|
|
psiconv_free_sheet_cell(*result); |
951 |
|
|
ERROR1: |
952 |
|
|
psiconv_warn(lev+1,off,"Reading of Sheet Cell Structure failed"); |
953 |
|
|
if (length) |
954 |
|
|
*length = 0; |
955 |
|
|
if (!res) |
956 |
|
|
return -PSICONV_E_NOMEM; |
957 |
|
|
else |
958 |
|
|
return res; |
959 |
|
|
} |
960 |
|
|
|
961 |
|
|
int psiconv_parse_sheet_cell_list(const psiconv_buffer buf, int lev, |
962 |
frodo |
128 |
psiconv_u32 off, int *length, |
963 |
|
|
psiconv_sheet_cell_list *result, |
964 |
|
|
const psiconv_sheet_cell_layout default_layout, |
965 |
|
|
const psiconv_sheet_line_list row_default_layouts, |
966 |
|
|
const psiconv_sheet_line_list col_default_layouts) |
967 |
frodo |
110 |
{ |
968 |
|
|
int res=0; |
969 |
|
|
int len=0; |
970 |
|
|
psiconv_u32 temp; |
971 |
|
|
psiconv_sheet_cell cell; |
972 |
|
|
psiconv_u32 listlen,i; |
973 |
|
|
int leng; |
974 |
|
|
|
975 |
frodo |
111 |
psiconv_progress(lev+1,off,"Going to read the sheet cell list"); |
976 |
frodo |
110 |
if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_cell_s)))) |
977 |
|
|
goto ERROR1; |
978 |
|
|
|
979 |
|
|
psiconv_progress(lev+2,off+len, |
980 |
|
|
"Going to read the initial byte (%02x expected)",0x02); |
981 |
|
|
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
982 |
|
|
if (res) |
983 |
|
|
goto ERROR2; |
984 |
|
|
if (temp != 0x02) { |
985 |
|
|
psiconv_warn(lev+2,off+len, |
986 |
|
|
"Sheet cell list initial byte unknown value (ignored)"); |
987 |
|
|
psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
988 |
|
|
} |
989 |
|
|
len ++; |
990 |
|
|
|
991 |
|
|
psiconv_progress(lev+2,off+len, |
992 |
|
|
"Going to read the initial byte (%02x expected)",0x00); |
993 |
|
|
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
994 |
|
|
if (res) |
995 |
|
|
goto ERROR2; |
996 |
|
|
if (temp != 0x00) { |
997 |
|
|
psiconv_warn(lev+2,off+len, |
998 |
|
|
"Sheet cell list initial byte unknown value (ignored)"); |
999 |
|
|
psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
1000 |
|
|
} |
1001 |
|
|
len ++; |
1002 |
|
|
|
1003 |
|
|
psiconv_progress(lev+2,off+len, |
1004 |
|
|
"Going to read the number of defined cells"); |
1005 |
|
|
listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
1006 |
|
|
if (res) |
1007 |
|
|
goto ERROR2; |
1008 |
|
|
psiconv_debug(lev+2,off+len,"Number of defined cells: %d",listlen); |
1009 |
|
|
len += leng; |
1010 |
|
|
|
1011 |
|
|
psiconv_progress(lev+2,off+len,"Going to read all cells"); |
1012 |
|
|
for (i = 0; i < listlen; i++) { |
1013 |
|
|
psiconv_progress(lev+3,off+len,"Going to read cell %d",i); |
1014 |
frodo |
121 |
if ((res = psiconv_parse_sheet_cell(buf,lev+3,off+len,&leng,&cell, |
1015 |
frodo |
128 |
default_layout,row_default_layouts, |
1016 |
|
|
col_default_layouts))) |
1017 |
frodo |
110 |
goto ERROR2; |
1018 |
|
|
if ((res = psiconv_list_add(*result,cell))) |
1019 |
|
|
goto ERROR3; |
1020 |
frodo |
120 |
free(cell); |
1021 |
frodo |
110 |
len += leng; |
1022 |
|
|
} |
1023 |
|
|
|
1024 |
|
|
if (length) |
1025 |
|
|
*length = len; |
1026 |
|
|
|
1027 |
|
|
psiconv_progress(lev,off+len-1, |
1028 |
|
|
"End of sheet cell list (total length: %08x)", len); |
1029 |
|
|
return 0; |
1030 |
|
|
|
1031 |
|
|
ERROR3: |
1032 |
|
|
psiconv_free_sheet_cell(cell); |
1033 |
|
|
ERROR2: |
1034 |
|
|
psiconv_free_sheet_cell_list(*result); |
1035 |
|
|
ERROR1: |
1036 |
|
|
psiconv_warn(lev+1,off,"Reading of Sheet Cells List failed"); |
1037 |
|
|
if (length) |
1038 |
|
|
*length = 0; |
1039 |
|
|
if (!res) |
1040 |
|
|
return -PSICONV_E_NOMEM; |
1041 |
|
|
else |
1042 |
|
|
return res; |
1043 |
|
|
} |
1044 |
|
|
|
1045 |
|
|
|
1046 |
frodo |
111 |
int psiconv_parse_sheet_worksheet_list( const psiconv_buffer buf, int lev, |
1047 |
|
|
psiconv_u32 off, int *length, |
1048 |
|
|
psiconv_sheet_worksheet_list *result) |
1049 |
frodo |
110 |
{ |
1050 |
frodo |
111 |
psiconv_sheet_worksheet worksheet; |
1051 |
frodo |
110 |
int res=0; |
1052 |
|
|
int len=0; |
1053 |
frodo |
111 |
psiconv_u8 temp; |
1054 |
|
|
psiconv_u32 offset; |
1055 |
|
|
int leng,i,nr; |
1056 |
frodo |
110 |
|
1057 |
frodo |
111 |
psiconv_progress(lev+1,off,"Going to read the worksheet list"); |
1058 |
|
|
if (!(*result = psiconv_list_new(sizeof(*worksheet)))) |
1059 |
|
|
goto ERROR1; |
1060 |
|
|
|
1061 |
frodo |
110 |
psiconv_progress(lev+2,off+len, |
1062 |
|
|
"Going to read the initial bytes (%02x expected)",0x02); |
1063 |
|
|
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1064 |
|
|
if (res) |
1065 |
frodo |
111 |
goto ERROR2; |
1066 |
|
|
if (temp != 0x02) { |
1067 |
frodo |
110 |
psiconv_warn(lev+2,off+len, |
1068 |
frodo |
111 |
"Sheet worksheet list initial byte unknown value (ignored)"); |
1069 |
frodo |
110 |
psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
1070 |
|
|
} |
1071 |
|
|
len ++; |
1072 |
|
|
|
1073 |
frodo |
111 |
psiconv_progress(lev+2,off+len,"Going to read the list length"); |
1074 |
|
|
nr = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
1075 |
frodo |
110 |
if (res) |
1076 |
frodo |
111 |
goto ERROR2; |
1077 |
|
|
psiconv_debug(lev+2,off+len,"Length: %02x",nr); |
1078 |
|
|
len += leng; |
1079 |
frodo |
110 |
|
1080 |
frodo |
111 |
psiconv_progress(lev+2,off+len,"Going to read the list"); |
1081 |
|
|
for (i=0 ; i < nr; i++) { |
1082 |
|
|
psiconv_progress(lev+3,off+len,"Going to read element %d",i); |
1083 |
|
|
psiconv_progress(lev+4,off+len, |
1084 |
|
|
"Going to read the initial byte (%02x expected)",0x00); |
1085 |
|
|
temp = psiconv_read_u8(buf,lev+4,off+len,&res); |
1086 |
|
|
if (res) |
1087 |
|
|
goto ERROR2; |
1088 |
|
|
if (temp != 0x00) { |
1089 |
|
|
psiconv_warn(lev+4,off+len, |
1090 |
|
|
"Sheet worksheet element initial byte unknown value (ignored)"); |
1091 |
|
|
psiconv_debug(lev+4,off+len,"Initial byte: %02x",temp); |
1092 |
|
|
} |
1093 |
|
|
len ++; |
1094 |
|
|
|
1095 |
|
|
psiconv_progress(lev+4,off+len,"Going to read the worksheet offset"); |
1096 |
|
|
offset = psiconv_read_u32(buf,lev+2,off+len,&res); |
1097 |
|
|
if (res) |
1098 |
|
|
goto ERROR2; |
1099 |
|
|
psiconv_debug(lev+4,off+len,"Offset: %08x",offset); |
1100 |
|
|
len += 4; |
1101 |
|
|
|
1102 |
|
|
if ((res = psiconv_parse_sheet_worksheet(buf,lev+4,offset,NULL, |
1103 |
|
|
&worksheet))) |
1104 |
|
|
goto ERROR2; |
1105 |
|
|
if ((res = psiconv_list_add(*result,worksheet))) |
1106 |
|
|
goto ERROR3; |
1107 |
frodo |
120 |
free(worksheet); |
1108 |
frodo |
110 |
} |
1109 |
|
|
|
1110 |
frodo |
111 |
if (length) |
1111 |
|
|
*length = len; |
1112 |
frodo |
110 |
|
1113 |
frodo |
111 |
psiconv_progress(lev,off+len-1, |
1114 |
|
|
"End of worksheet list (total length: %08x)", len); |
1115 |
frodo |
110 |
|
1116 |
frodo |
111 |
return 0; |
1117 |
|
|
|
1118 |
|
|
ERROR3: |
1119 |
|
|
psiconv_free_sheet_worksheet(worksheet); |
1120 |
|
|
ERROR2: |
1121 |
|
|
psiconv_free_sheet_worksheet_list(*result); |
1122 |
|
|
ERROR1: |
1123 |
|
|
psiconv_warn(lev+1,off,"Reading of worksheet list failed"); |
1124 |
|
|
if (length) |
1125 |
|
|
*length = 0; |
1126 |
|
|
if (!res) |
1127 |
|
|
return -PSICONV_E_NOMEM; |
1128 |
|
|
else |
1129 |
|
|
return res; |
1130 |
|
|
} |
1131 |
|
|
|
1132 |
|
|
int psiconv_parse_sheet_cell_layout(const psiconv_buffer buf, int lev, |
1133 |
|
|
psiconv_u32 off, int *length, |
1134 |
frodo |
121 |
psiconv_sheet_cell_layout result) |
1135 |
frodo |
111 |
|
1136 |
|
|
{ |
1137 |
|
|
int res=0; |
1138 |
|
|
int len=0; |
1139 |
|
|
int leng; |
1140 |
|
|
psiconv_u8 temp; |
1141 |
|
|
|
1142 |
|
|
psiconv_progress(lev+1,off,"Going to read a sheet cell layout"); |
1143 |
frodo |
110 |
|
1144 |
|
|
psiconv_progress(lev+2,off+len, |
1145 |
frodo |
111 |
"Going to read the first byte (%02x expected)",0x02); |
1146 |
frodo |
110 |
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1147 |
|
|
if (res) |
1148 |
frodo |
121 |
goto ERROR1; |
1149 |
frodo |
110 |
if (temp != 0x02) { |
1150 |
|
|
psiconv_warn(lev+2,off+len, |
1151 |
|
|
"Worksheet section initial byte unknown value (ignored)"); |
1152 |
|
|
psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
1153 |
|
|
} |
1154 |
|
|
len ++; |
1155 |
|
|
|
1156 |
|
|
psiconv_progress(lev+2,off+len,"Going to read the default formats flag"); |
1157 |
|
|
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1158 |
|
|
if (res) |
1159 |
frodo |
121 |
goto ERROR1; |
1160 |
frodo |
110 |
len ++; |
1161 |
|
|
|
1162 |
|
|
if (temp & 0x01) { |
1163 |
|
|
psiconv_progress(lev+3,off+len,"Going to read the default paragraph codes"); |
1164 |
|
|
if ((res = psiconv_parse_paragraph_layout_list(buf,lev+3,off+len,&leng, |
1165 |
frodo |
121 |
result->paragraph))) |
1166 |
|
|
goto ERROR1; |
1167 |
frodo |
110 |
len += leng; |
1168 |
|
|
} |
1169 |
|
|
|
1170 |
|
|
if (temp & 0x02) { |
1171 |
|
|
psiconv_progress(lev+3,off+len,"Going to read the default character codes"); |
1172 |
|
|
if ((res = psiconv_parse_character_layout_list(buf,lev+3,off+len,&leng, |
1173 |
frodo |
121 |
result->character))) |
1174 |
|
|
goto ERROR1; |
1175 |
frodo |
110 |
len += leng; |
1176 |
|
|
} |
1177 |
|
|
|
1178 |
|
|
if (temp & 0x04) { |
1179 |
frodo |
111 |
psiconv_progress(lev+3,off+len, "Going to read the default number format"); |
1180 |
|
|
psiconv_parse_sheet_numberformat(buf,lev+3,off+len,&leng, |
1181 |
frodo |
121 |
result->numberformat); |
1182 |
frodo |
111 |
len += leng; |
1183 |
frodo |
110 |
} |
1184 |
frodo |
111 |
|
1185 |
|
|
if (length) |
1186 |
|
|
*length = len; |
1187 |
|
|
|
1188 |
|
|
psiconv_progress(lev,off+len-1, |
1189 |
|
|
"End of sheet cell layout (total length: %08x)", len); |
1190 |
|
|
|
1191 |
|
|
return 0; |
1192 |
|
|
|
1193 |
|
|
ERROR1: |
1194 |
|
|
psiconv_warn(lev+1,off,"Reading of sheet cell layout failed"); |
1195 |
|
|
if (length) |
1196 |
|
|
*length = 0; |
1197 |
|
|
if (!res) |
1198 |
|
|
return -PSICONV_E_NOMEM; |
1199 |
|
|
else |
1200 |
|
|
return res; |
1201 |
|
|
} |
1202 |
frodo |
110 |
|
1203 |
frodo |
111 |
|
1204 |
|
|
int psiconv_parse_sheet_worksheet(const psiconv_buffer buf, int lev, |
1205 |
|
|
psiconv_u32 off, int *length, |
1206 |
|
|
psiconv_sheet_worksheet *result) |
1207 |
|
|
{ |
1208 |
|
|
int res=0; |
1209 |
frodo |
128 |
psiconv_u32 temp,cells_off,grid_off,rows_off,cols_off; |
1210 |
frodo |
111 |
int len=0; |
1211 |
|
|
int leng; |
1212 |
|
|
|
1213 |
|
|
psiconv_progress(lev+1,off,"Going to read the sheet worksheet section"); |
1214 |
|
|
if (!(*result = malloc(sizeof(**result)))) |
1215 |
|
|
goto ERROR1; |
1216 |
|
|
|
1217 |
frodo |
110 |
psiconv_progress(lev+2,off+len, |
1218 |
frodo |
111 |
"Going to read the initial bytes (%02x expected)",0x04); |
1219 |
|
|
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1220 |
|
|
if (res) |
1221 |
|
|
goto ERROR2; |
1222 |
|
|
if (temp != 0x04) { |
1223 |
|
|
psiconv_warn(lev+2,off+len, |
1224 |
|
|
"Worksheet section initial byte unknown value (ignored)"); |
1225 |
|
|
psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
1226 |
|
|
} |
1227 |
|
|
len ++; |
1228 |
|
|
|
1229 |
|
|
psiconv_progress(lev+2,off+len, "Going to read the flags byte"); |
1230 |
|
|
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1231 |
|
|
if (res) |
1232 |
|
|
goto ERROR2; |
1233 |
|
|
psiconv_debug(lev+2,off+len,"Flags byte: %02x",temp); |
1234 |
|
|
(*result)->show_zeros = (temp & 0x01)?psiconv_bool_true:psiconv_bool_false; |
1235 |
|
|
if (temp & 0xfe) { |
1236 |
|
|
psiconv_warn(lev+2,off+len, |
1237 |
|
|
"Worksheet section flags byte unknown bits (ignored)"); |
1238 |
|
|
} |
1239 |
|
|
len ++; |
1240 |
|
|
|
1241 |
|
|
psiconv_progress(lev+2,off+len,"Going to read the default cell layout"); |
1242 |
frodo |
121 |
if (!((*result)->default_layout = psiconv_basic_cell_layout())) |
1243 |
|
|
goto ERROR2; |
1244 |
frodo |
111 |
if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len,&leng, |
1245 |
frodo |
121 |
(*result)->default_layout))) |
1246 |
|
|
goto ERROR3; |
1247 |
frodo |
111 |
len += leng; |
1248 |
|
|
|
1249 |
|
|
psiconv_progress(lev+2,off+len, |
1250 |
frodo |
128 |
"Going to read the offset of the row defaults Section"); |
1251 |
|
|
rows_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
1252 |
frodo |
110 |
if (res) |
1253 |
frodo |
111 |
goto ERROR3; |
1254 |
frodo |
128 |
psiconv_debug(lev+2,off+len,"Offset: %04x",rows_off); |
1255 |
frodo |
110 |
len += 4; |
1256 |
|
|
|
1257 |
|
|
psiconv_progress(lev+2,off+len, |
1258 |
frodo |
128 |
"Going to read the offset of the column defaults Section"); |
1259 |
|
|
cols_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
1260 |
frodo |
110 |
if (res) |
1261 |
frodo |
111 |
goto ERROR3; |
1262 |
frodo |
128 |
psiconv_debug(lev+2,off+len,"Offset: %04x",cols_off); |
1263 |
frodo |
110 |
len += 4; |
1264 |
|
|
|
1265 |
|
|
psiconv_progress(lev+2,off+len, |
1266 |
|
|
"Going to read the offset of the Cells List"); |
1267 |
|
|
cells_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
1268 |
|
|
if (res) |
1269 |
frodo |
111 |
goto ERROR3; |
1270 |
frodo |
110 |
psiconv_debug(lev+2,off+len,"Offset: %04x",cells_off); |
1271 |
|
|
len += 4; |
1272 |
|
|
|
1273 |
|
|
psiconv_progress(lev+2,off+len, |
1274 |
|
|
"Going to read the offset of the Grid Section"); |
1275 |
|
|
grid_off = psiconv_read_u32(buf,lev+2,off+len,&res); |
1276 |
|
|
if (res) |
1277 |
frodo |
111 |
goto ERROR3; |
1278 |
frodo |
110 |
psiconv_debug(lev+2,off+len,"Offset: %04x",grid_off); |
1279 |
|
|
len += 4; |
1280 |
|
|
|
1281 |
|
|
psiconv_progress(lev+2,off+len, |
1282 |
|
|
"Going to read the offset of the 3rd ??? Section"); |
1283 |
|
|
temp = psiconv_read_u32(buf,lev+2,off+len,&res); |
1284 |
|
|
if (res) |
1285 |
frodo |
111 |
goto ERROR3; |
1286 |
frodo |
110 |
psiconv_debug(lev+2,off+len,"Offset: %04x",temp); |
1287 |
|
|
len += 4; |
1288 |
|
|
|
1289 |
frodo |
128 |
psiconv_progress(lev+2,off+len,"Going to read the row defaults"); |
1290 |
|
|
if ((res = psiconv_parse_sheet_line_list(buf,lev+2,rows_off,NULL, |
1291 |
|
|
&(*result)->row_default_layouts, |
1292 |
|
|
(*result)->default_layout))) |
1293 |
|
|
goto ERROR3; |
1294 |
|
|
|
1295 |
|
|
psiconv_progress(lev+2,off+len,"Going to read the column defaults"); |
1296 |
|
|
if ((res = psiconv_parse_sheet_line_list(buf,lev+2,cols_off,NULL, |
1297 |
|
|
&(*result)->col_default_layouts, |
1298 |
|
|
(*result)->default_layout))) |
1299 |
|
|
goto ERROR4; |
1300 |
|
|
|
1301 |
frodo |
110 |
psiconv_progress(lev+2,off+len,"Going to read the cells list"); |
1302 |
|
|
if ((res = psiconv_parse_sheet_cell_list(buf,lev+2,cells_off,NULL, |
1303 |
frodo |
121 |
&(*result)->cells, |
1304 |
frodo |
128 |
(*result)->default_layout, |
1305 |
|
|
(*result)->row_default_layouts, |
1306 |
|
|
(*result)->col_default_layouts))) |
1307 |
|
|
goto ERROR5; |
1308 |
frodo |
110 |
|
1309 |
|
|
|
1310 |
|
|
/* TODO: parse grid section */ |
1311 |
|
|
|
1312 |
|
|
if (length) |
1313 |
|
|
*length = len; |
1314 |
|
|
|
1315 |
|
|
psiconv_progress(lev,off+len-1, |
1316 |
|
|
"End of sheet worksheet section (total length: %08x)", len); |
1317 |
|
|
return 0; |
1318 |
|
|
|
1319 |
frodo |
128 |
ERROR5: |
1320 |
|
|
psiconv_free_sheet_line_list((*result)->col_default_layouts); |
1321 |
|
|
ERROR4: |
1322 |
|
|
psiconv_free_sheet_line_list((*result)->row_default_layouts); |
1323 |
frodo |
111 |
ERROR3: |
1324 |
|
|
psiconv_free_sheet_cell_layout((*result)->default_layout); |
1325 |
frodo |
110 |
ERROR2: |
1326 |
|
|
free (*result); |
1327 |
|
|
ERROR1: |
1328 |
|
|
psiconv_warn(lev+1,off,"Reading of Sheet Worksheet Section failed"); |
1329 |
|
|
if (length) |
1330 |
|
|
*length = 0; |
1331 |
|
|
if (!res) |
1332 |
|
|
return -PSICONV_E_NOMEM; |
1333 |
|
|
else |
1334 |
|
|
return res; |
1335 |
|
|
} |
1336 |
|
|
|
1337 |
frodo |
128 |
int psiconv_parse_sheet_line(const psiconv_buffer buf, int lev, |
1338 |
|
|
psiconv_u32 off, int *length, |
1339 |
|
|
psiconv_sheet_line *result, |
1340 |
|
|
const psiconv_sheet_cell_layout default_layout) |
1341 |
|
|
{ |
1342 |
|
|
int res=0; |
1343 |
|
|
int len=0; |
1344 |
|
|
int leng; |
1345 |
frodo |
110 |
|
1346 |
frodo |
128 |
|
1347 |
|
|
psiconv_progress(lev+1,off,"Going to read a sheet line"); |
1348 |
|
|
if (!(*result = malloc(sizeof(**result)))) |
1349 |
|
|
goto ERROR1; |
1350 |
|
|
|
1351 |
|
|
psiconv_progress(lev+2,off+len,"Going to read the line number"); |
1352 |
|
|
(*result)->position = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
1353 |
|
|
if (res) |
1354 |
|
|
goto ERROR2; |
1355 |
|
|
psiconv_debug(lev+2,off+len,"Line number: %d\n",(*result)->position); |
1356 |
|
|
len += leng; |
1357 |
|
|
|
1358 |
|
|
if (!((*result)->layout = psiconv_clone_cell_layout(default_layout))) |
1359 |
|
|
goto ERROR2; |
1360 |
|
|
if ((res = psiconv_parse_sheet_cell_layout(buf,lev+2,off+len, |
1361 |
|
|
&leng,(*result)->layout))) |
1362 |
|
|
goto ERROR3; |
1363 |
|
|
len += leng; |
1364 |
|
|
|
1365 |
|
|
if (length) |
1366 |
|
|
*length = len; |
1367 |
|
|
|
1368 |
|
|
psiconv_progress(lev,off+len-1, |
1369 |
|
|
"End of the sheet line (total length: %08x)", len); |
1370 |
|
|
return 0; |
1371 |
|
|
|
1372 |
|
|
ERROR3: |
1373 |
|
|
psiconv_free_sheet_cell_layout((*result)->layout); |
1374 |
|
|
ERROR2: |
1375 |
|
|
free (*result); |
1376 |
|
|
ERROR1: |
1377 |
|
|
psiconv_warn(lev+1,off,"Reading of the sheet line failed"); |
1378 |
|
|
if (length) |
1379 |
|
|
*length = 0; |
1380 |
|
|
if (!res) |
1381 |
|
|
return -PSICONV_E_NOMEM; |
1382 |
|
|
else |
1383 |
|
|
return res; |
1384 |
|
|
} |
1385 |
|
|
|
1386 |
|
|
|
1387 |
|
|
int psiconv_parse_sheet_line_list(const psiconv_buffer buf, int lev, |
1388 |
|
|
psiconv_u32 off, int *length, |
1389 |
|
|
psiconv_sheet_line_list *result, |
1390 |
|
|
const psiconv_sheet_cell_layout default_layout) |
1391 |
|
|
{ |
1392 |
|
|
int res=0; |
1393 |
|
|
int len=0; |
1394 |
|
|
psiconv_u32 temp; |
1395 |
|
|
psiconv_sheet_line line; |
1396 |
|
|
psiconv_u32 listlen,i; |
1397 |
|
|
int leng; |
1398 |
|
|
|
1399 |
|
|
psiconv_progress(lev+1,off,"Going to read the sheet line list"); |
1400 |
|
|
if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_line_s)))) |
1401 |
|
|
goto ERROR1; |
1402 |
|
|
|
1403 |
|
|
psiconv_progress(lev+2,off+len, |
1404 |
|
|
"Going to read the initial byte (%02x expected)",0x02); |
1405 |
|
|
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1406 |
|
|
if (res) |
1407 |
|
|
goto ERROR2; |
1408 |
|
|
if (temp != 0x02) { |
1409 |
|
|
psiconv_warn(lev+2,off+len, |
1410 |
|
|
"Sheet line list initial byte unknown value (ignored)"); |
1411 |
|
|
psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
1412 |
|
|
} |
1413 |
|
|
len ++; |
1414 |
|
|
|
1415 |
|
|
psiconv_progress(lev+2,off+len, |
1416 |
|
|
"Going to read the number of defined lines"); |
1417 |
|
|
listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
1418 |
|
|
if (res) |
1419 |
|
|
goto ERROR2; |
1420 |
|
|
psiconv_debug(lev+2,off+len,"Number of defined lines: %d",listlen); |
1421 |
|
|
len += leng; |
1422 |
|
|
|
1423 |
|
|
psiconv_progress(lev+2,off+len,"Going to read all lines"); |
1424 |
|
|
for (i = 0; i < listlen; i++) { |
1425 |
|
|
psiconv_progress(lev+3,off+len,"Going to read line %d",i); |
1426 |
|
|
if ((res = psiconv_parse_sheet_line(buf,lev+3,off+len,&leng,&line, |
1427 |
|
|
default_layout))) |
1428 |
|
|
goto ERROR2; |
1429 |
|
|
if ((res = psiconv_list_add(*result,line))) |
1430 |
|
|
goto ERROR3; |
1431 |
|
|
free(line); |
1432 |
|
|
len += leng; |
1433 |
|
|
} |
1434 |
|
|
|
1435 |
|
|
if (length) |
1436 |
|
|
*length = len; |
1437 |
|
|
|
1438 |
|
|
psiconv_progress(lev,off+len-1, |
1439 |
|
|
"End of sheet line list (total length: %08x)", len); |
1440 |
|
|
return 0; |
1441 |
|
|
|
1442 |
|
|
ERROR3: |
1443 |
|
|
psiconv_free_sheet_line(line); |
1444 |
|
|
ERROR2: |
1445 |
|
|
psiconv_free_sheet_line_list(*result); |
1446 |
|
|
ERROR1: |
1447 |
|
|
psiconv_warn(lev+1,off,"Reading of Sheet Line List failed"); |
1448 |
|
|
if (length) |
1449 |
|
|
*length = 0; |
1450 |
|
|
if (!res) |
1451 |
|
|
return -PSICONV_E_NOMEM; |
1452 |
|
|
else |
1453 |
|
|
return res; |
1454 |
|
|
} |
1455 |
|
|
|
1456 |
frodo |
129 |
int psiconv_parse_sheet_variable(const psiconv_buffer buf, int lev, |
1457 |
|
|
psiconv_u32 off, int *length, |
1458 |
|
|
psiconv_sheet_variable *result) |
1459 |
|
|
{ |
1460 |
|
|
int res=0; |
1461 |
|
|
int len=0; |
1462 |
|
|
psiconv_u32 marker; |
1463 |
|
|
int leng; |
1464 |
|
|
|
1465 |
|
|
psiconv_progress(lev+1,off,"Going to read a sheet variable"); |
1466 |
|
|
if (!(*result = malloc(sizeof(**result)))) |
1467 |
|
|
goto ERROR1; |
1468 |
|
|
|
1469 |
|
|
psiconv_progress(lev+2,off+len, "Going to read the variable name"); |
1470 |
|
|
(*result)->name = psiconv_read_string(buf,lev+2,off+len,&leng,&res); |
1471 |
|
|
if (res) |
1472 |
|
|
goto ERROR2; |
1473 |
|
|
len += leng; |
1474 |
|
|
|
1475 |
|
|
psiconv_progress(lev+2,off+len,"Going to read the type marker"); |
1476 |
|
|
marker = psiconv_read_u8(buf,lev+2,off+len,&res); |
1477 |
|
|
if (res) |
1478 |
|
|
goto ERROR3; |
1479 |
|
|
psiconv_debug(lev+2,off+len,"Marker: %02x",marker); |
1480 |
|
|
len ++; |
1481 |
|
|
|
1482 |
|
|
if (marker == 0x00) { |
1483 |
|
|
(*result)->type = psiconv_var_int; |
1484 |
|
|
psiconv_progress(lev+2,off+len,"Going to read a signed integer"); |
1485 |
|
|
(*result)->data.dat_int = psiconv_read_sint(buf,lev+2,off+len,&leng,&res); |
1486 |
|
|
if (res) |
1487 |
|
|
goto ERROR3; |
1488 |
|
|
psiconv_debug(lev+2,off+len,"Value: %d",(*result)->data.dat_int); |
1489 |
|
|
len += leng; |
1490 |
|
|
} else if (marker == 0x01) { |
1491 |
|
|
(*result)->type = psiconv_var_float; |
1492 |
|
|
psiconv_progress(lev+2,off+len,"Going to read a floating point number"); |
1493 |
|
|
(*result)->data.dat_float = psiconv_read_float(buf,lev+2,off+len,&leng, |
1494 |
|
|
&res); |
1495 |
|
|
if (res) |
1496 |
|
|
goto ERROR3; |
1497 |
|
|
psiconv_debug(lev+2,off+len,"Value: %f",(*result)->data.dat_float); |
1498 |
|
|
len += leng; |
1499 |
|
|
} else if (marker == 0x02) { |
1500 |
|
|
(*result)->type = psiconv_var_string; |
1501 |
|
|
psiconv_progress(lev+2,off+len,"Going to read a string"); |
1502 |
|
|
(*result)->data.dat_string = psiconv_read_string(buf,lev+2,off+len,&leng, |
1503 |
|
|
&res); |
1504 |
|
|
if (res) |
1505 |
|
|
goto ERROR3; |
1506 |
|
|
len += leng; |
1507 |
|
|
} else if (marker == 0x03) { |
1508 |
|
|
(*result)->type = psiconv_var_cellref; |
1509 |
|
|
psiconv_progress(lev+2,off+len,"Going to read a cell reference"); |
1510 |
|
|
(*result)->data.dat_cellref = psiconv_read_var_cellref(buf,lev+2,off+len, |
1511 |
|
|
&leng, &res); |
1512 |
|
|
if (res) |
1513 |
|
|
goto ERROR3; |
1514 |
|
|
len += leng; |
1515 |
|
|
} else if (marker == 0x04) { |
1516 |
|
|
(*result)->type = psiconv_var_cellblock; |
1517 |
|
|
psiconv_progress(lev+2,off+len,"Going to read a cell block reference"); |
1518 |
|
|
(*result)->data.dat_cellblock = psiconv_read_var_cellblock(buf,lev+2, |
1519 |
|
|
off+len, |
1520 |
|
|
&leng, &res); |
1521 |
|
|
if (res) |
1522 |
|
|
goto ERROR3; |
1523 |
|
|
len += leng; |
1524 |
|
|
} else { |
1525 |
|
|
psiconv_warn(lev+2,off+len,"Sheet variable unknown type marker"); |
1526 |
|
|
res = -PSICONV_E_PARSE; |
1527 |
|
|
goto ERROR3; |
1528 |
|
|
} |
1529 |
|
|
|
1530 |
|
|
psiconv_progress(lev+2,off+len,"Going to read the variable number"); |
1531 |
|
|
(*result)->number = psiconv_read_u32(buf,lev+2,off+len,&res); |
1532 |
|
|
if (res) |
1533 |
|
|
goto ERROR4; |
1534 |
|
|
psiconv_debug(lev+2,off+len,"Number: %08x",(*result)->number); |
1535 |
|
|
len += 4; |
1536 |
|
|
|
1537 |
|
|
if (length) |
1538 |
|
|
*length = len; |
1539 |
|
|
|
1540 |
|
|
psiconv_progress(lev,off+len-1, |
1541 |
|
|
"End of sheet variable (total length: %08x)", len); |
1542 |
|
|
return 0; |
1543 |
|
|
|
1544 |
|
|
ERROR4: |
1545 |
|
|
if ((*result)->type == psiconv_var_string) |
1546 |
|
|
free((*result)->data.dat_string); |
1547 |
|
|
ERROR3: |
1548 |
|
|
free((*result)->name); |
1549 |
|
|
ERROR2: |
1550 |
|
|
free (*result); |
1551 |
|
|
ERROR1: |
1552 |
|
|
psiconv_warn(lev+1,off,"Reading of Sheet Variable failed"); |
1553 |
|
|
if (length) |
1554 |
|
|
*length = 0; |
1555 |
|
|
if (!res) |
1556 |
|
|
return -PSICONV_E_NOMEM; |
1557 |
|
|
else |
1558 |
|
|
return res; |
1559 |
|
|
} |
1560 |
|
|
|
1561 |
|
|
|
1562 |
|
|
int psiconv_parse_sheet_variable_list(const psiconv_buffer buf, int lev, |
1563 |
|
|
psiconv_u32 off, int *length, |
1564 |
|
|
psiconv_sheet_variable_list *result) |
1565 |
|
|
{ |
1566 |
|
|
int res=0; |
1567 |
|
|
int len=0; |
1568 |
|
|
psiconv_u32 temp; |
1569 |
|
|
psiconv_sheet_variable variable; |
1570 |
|
|
psiconv_u32 listlen,i; |
1571 |
|
|
int leng; |
1572 |
|
|
|
1573 |
|
|
psiconv_progress(lev+1,off,"Going to read the sheet variable list"); |
1574 |
|
|
if (!(*result = psiconv_list_new(sizeof(struct psiconv_sheet_variable_s)))) |
1575 |
|
|
goto ERROR1; |
1576 |
|
|
|
1577 |
|
|
psiconv_progress(lev+2,off+len, |
1578 |
|
|
"Going to read the initial byte (%02x expected)",0x02); |
1579 |
|
|
temp = psiconv_read_u8(buf,lev+2,off+len,&res); |
1580 |
|
|
if (res) |
1581 |
|
|
goto ERROR2; |
1582 |
|
|
if (temp != 0x02) { |
1583 |
|
|
psiconv_warn(lev+2,off+len, |
1584 |
|
|
"Sheet variable list initial byte unknown value (ignored)"); |
1585 |
|
|
psiconv_debug(lev+2,off+len,"Initial byte: %02x",temp); |
1586 |
|
|
} |
1587 |
|
|
len ++; |
1588 |
|
|
|
1589 |
|
|
psiconv_progress(lev+2,off+len, |
1590 |
|
|
"Going to read the number of variables"); |
1591 |
|
|
listlen = psiconv_read_X(buf,lev+2,off+len,&leng,&res); |
1592 |
|
|
if (res) |
1593 |
|
|
goto ERROR2; |
1594 |
|
|
psiconv_debug(lev+2,off+len,"Number of variables: %d",listlen); |
1595 |
|
|
len += leng; |
1596 |
|
|
|
1597 |
|
|
psiconv_progress(lev+2,off+len,"Going to read all variables"); |
1598 |
|
|
for (i = 0; i < listlen; i++) { |
1599 |
|
|
psiconv_progress(lev+3,off+len,"Going to read variable %d",i); |
1600 |
|
|
if ((res = psiconv_parse_sheet_variable(buf,lev+3,off+len,&leng,&variable))) |
1601 |
|
|
goto ERROR2; |
1602 |
|
|
if ((res = psiconv_list_add(*result,variable))) |
1603 |
|
|
goto ERROR3; |
1604 |
|
|
len += leng; |
1605 |
|
|
} |
1606 |
|
|
|
1607 |
|
|
if (length) |
1608 |
|
|
*length = len; |
1609 |
|
|
|
1610 |
|
|
psiconv_progress(lev,off+len-1, |
1611 |
|
|
"End of sheet variabels list (total length: %08x)", len); |
1612 |
|
|
return 0; |
1613 |
|
|
|
1614 |
|
|
ERROR3: |
1615 |
|
|
psiconv_free_sheet_variable(variable); |
1616 |
|
|
ERROR2: |
1617 |
|
|
psiconv_list_free(*result); |
1618 |
|
|
ERROR1: |
1619 |
|
|
psiconv_warn(lev+1,off,"Reading of Sheet Variable list failed"); |
1620 |
|
|
if (length) |
1621 |
|
|
*length = 0; |
1622 |
|
|
if (!res) |
1623 |
|
|
return -PSICONV_E_NOMEM; |
1624 |
|
|
else |
1625 |
|
|
return res; |
1626 |
|
|
} |