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

Legend:
Removed from v.142  
changed lines
  Added in v.196

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