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

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

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

Revision 101 Revision 102
289 {psiconv_formula_unknown,0,"*UNKNOWN*"}, 289 {psiconv_formula_unknown,0,"*UNKNOWN*"},
290 {psiconv_formula_unknown,0,"*UNKNOWN*"}, 290 {psiconv_formula_unknown,0,"*UNKNOWN*"},
291 {psiconv_formula_unknown,0,"*UNKNOWN*"}, 291 {psiconv_formula_unknown,0,"*UNKNOWN*"},
292 {psiconv_formula_unknown,0,"*UNKNOWN*"}}; 292 {psiconv_formula_unknown,0,"*UNKNOWN*"}};
293 293
294
295static int psiconv_parse_sheet_ref(const psiconv_buffer buf,int lev,
296 psiconv_u32 off, int *length,
297 psiconv_sheet_ref_t *result)
298{
299 int res;
300 psiconv_u16 temp;
301
302 psiconv_progress(lev+1,off,"Going to read a sheet ref");
303 psiconv_progress(lev+2,off,"Going to read the offset encoding");
304 temp = psiconv_read_u16(buf,lev+2,off,&res);
305 if (res) {
306 if (length)
307 *length = 0;
308 return res;
309 }
310 psiconv_debug(lev+2,off,"Encoded word: %04x",temp);
311 result->absolute = (temp & 0x4000)?psiconv_bool_true:psiconv_bool_false;
312 result->offset = (temp & 0x3fff) * ((temp & 0x8000)?-1:1);
313 psiconv_debug(lev+2,off,"Reference: %s offset %d",
314 result->absolute?"absolute":"relative",result->offset);
315 if (length)
316 *length = 2;
317 return 0;
318}
319
320static int psiconv_parse_sheet_cell_reference(const psiconv_buffer buf,int lev,
321 psiconv_u32 off, int *length,
322 psiconv_sheet_cell_reference_t *result)
323{
324 int len = 0;
325 int leng,res;
326 psiconv_u8 temp;
327
328 psiconv_progress(lev+1,off+len,"Going to read a sheet cell reference");
329 psiconv_progress(lev+2,off+len,"Going to read the row reference");
330 if ((res = psiconv_parse_sheet_ref(buf,lev+2,off+len,&leng,&result->row)))
331 goto ERROR;
332 len += leng;
333 psiconv_progress(lev+2,off+len,"Going to read the column reference");
334 if ((res = psiconv_parse_sheet_ref(buf,lev+2,off+len,&leng,&result->column)))
335 goto ERROR;
336 len += leng;
337
338 psiconv_progress(lev+2,off+len,
339 "Going to read the trailing byte (%02x expected)",0);
340 temp = psiconv_read_u8(buf,lev+2,off+len,&res);
341 if (res)
342 goto ERROR;
343 if (temp != 0) {
344 psiconv_warn(lev+2,off+len,"Unknown byte in cell reference (ignored");
345 psiconv_debug(lev+2,off+len,"Trailing byte: %02x",temp);
346 }
347 len ++;
348 psiconv_progress(lev,off+len-1,
349 "End of cell reference (total length: %08x)", len);
350 if (length)
351 *length = len;
352 return 0;
353ERROR:
354 if (length)
355 *length = 0;
356 return res;
357}
358
359static int psiconv_parse_sheet_cell_block(const psiconv_buffer buf,int lev,
360 psiconv_u32 off, int *length,
361 psiconv_sheet_cell_block_t *result)
362{
363 int len = 0;
364 int leng,res;
365
366 psiconv_progress(lev+1,off+len,"Going to read a sheet cell block");
367 psiconv_progress(lev+2,off+len,"Going to read the first cell");
368 if ((res = psiconv_parse_sheet_cell_reference(buf,lev+2,off+len,&leng,
369 &result->first)))
370 goto ERROR;
371 len += leng;
372 psiconv_progress(lev+2,off+len,"Going to read the last cell");
373 if ((res = psiconv_parse_sheet_cell_reference(buf,lev+2,off+len,&leng,
374 &result->last)))
375 goto ERROR;
376 len += leng;
377 psiconv_progress(lev,off+len-1,
378 "End of cell block (total length: %08x)", len);
379 if (length)
380 *length = len;
381 return 0;
382ERROR:
383 if (length)
384 *length = 0;
385 return res;
386}
387
294int psiconv_parse_formula(const psiconv_buffer buf, int lev, 388int psiconv_parse_formula(const psiconv_buffer buf, int lev,
295 psiconv_u32 off, int *length, 389 psiconv_u32 off, int *length,
296 psiconv_formula *result) 390 psiconv_formula *result)
297{ 391{
298 int res=0; 392 int res=0;
375 psiconv_debug(lev+3,off+len,"Value: %f",formula->data.dat_float); 469 psiconv_debug(lev+3,off+len,"Value: %f",formula->data.dat_float);
376 len += leng; 470 len += leng;
377 if ((res = psiconv_list_add(formula_stack,formula))) 471 if ((res = psiconv_list_add(formula_stack,formula)))
378 goto ERROR8; 472 goto ERROR8;
379 formula->type = psiconv_formula_unknown; 473 formula->type = psiconv_formula_unknown;
380 474 } else if (formula_elements[marker].formula_type ==
475 psiconv_formula_dat_cellref) {
476 psiconv_progress(lev+3,off+len,"Next item: a cell reference");
477 if ((res = psiconv_parse_sheet_cell_reference(buf,lev+2,off+len,&leng,
478 &formula->data.dat_cellref)))
479 goto ERROR8;
480 formula->type = formula_elements[marker].formula_type;
481 len += leng;
482 if ((res = psiconv_list_add(formula_stack,formula)))
483 goto ERROR8;
484 formula->type = psiconv_formula_unknown;
485 } else if (formula_elements[marker].formula_type ==
486 psiconv_formula_dat_cellblock) {
487 psiconv_progress(lev+3,off+len,"Next item: a cell block");
488 if ((res = psiconv_parse_sheet_cell_block(buf,lev+2,off+len,&leng,
489 &formula->data.dat_cellblock)))
490 goto ERROR8;
491 formula->type = formula_elements[marker].formula_type;
492 len += leng;
493 if ((res = psiconv_list_add(formula_stack,formula)))
494 goto ERROR8;
495 formula->type = psiconv_formula_unknown;
381 } else if ((formula_elements[marker].formula_type == 496 } else if ((formula_elements[marker].formula_type ==
382 psiconv_formula_dat_var) || 497 psiconv_formula_dat_var) ||
383 (formula_elements[marker].formula_type == 498 (formula_elements[marker].formula_type ==
384 psiconv_formula_dat_string) || 499 psiconv_formula_dat_string) ||
385 (formula_elements[marker].formula_type ==
386 psiconv_formula_dat_cellref) ||
387 (formula_elements[marker].formula_type ==
388 psiconv_formula_dat_cellblock) ||
389 (formula_elements[marker].formula_type == 500 (formula_elements[marker].formula_type ==
390 psiconv_formula_dat_vcellblock) || 501 psiconv_formula_dat_vcellblock) ||
391 (formula_elements[marker].formula_type == 502 (formula_elements[marker].formula_type ==
392 psiconv_formula_mark_opsep) || 503 psiconv_formula_mark_opsep) ||
393 (formula_elements[marker].formula_type == 504 (formula_elements[marker].formula_type ==

Legend:
Removed from v.101  
changed lines
  Added in v.102

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