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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.130  
changed lines
  Added in v.270

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