… | |
… | |
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 | |
|
|
295 | static 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 | |
|
|
320 | static 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; |
|
|
353 | ERROR: |
|
|
354 | if (length) |
|
|
355 | *length = 0; |
|
|
356 | return res; |
|
|
357 | } |
|
|
358 | |
|
|
359 | static 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; |
|
|
382 | ERROR: |
|
|
383 | if (length) |
|
|
384 | *length = 0; |
|
|
385 | return res; |
|
|
386 | } |
|
|
387 | |
294 | int psiconv_parse_formula(const psiconv_buffer buf, int lev, |
388 | int 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; |
… | |
… | |
362 | psiconv_debug(lev+3,off+len,"Value: %08x",formula->data.dat_int); |
456 | psiconv_debug(lev+3,off+len,"Value: %08x",formula->data.dat_int); |
363 | len += 4; |
457 | len += 4; |
364 | if ((res = psiconv_list_add(formula_stack,formula))) |
458 | if ((res = psiconv_list_add(formula_stack,formula))) |
365 | goto ERROR8; |
459 | goto ERROR8; |
366 | formula->type = psiconv_formula_unknown; |
460 | formula->type = psiconv_formula_unknown; |
|
|
461 | } else if (formula_elements[marker].formula_type == |
|
|
462 | psiconv_formula_dat_float) { |
|
|
463 | psiconv_progress(lev+3,off+len,"Next item: a float"); |
|
|
464 | formula->data.dat_float = psiconv_read_float(buf,lev+2,off+len,&leng, |
|
|
465 | &res); |
|
|
466 | if (res) |
|
|
467 | goto ERROR8; |
|
|
468 | formula->type = formula_elements[marker].formula_type; |
|
|
469 | psiconv_debug(lev+3,off+len,"Value: %f",formula->data.dat_float); |
|
|
470 | len += leng; |
|
|
471 | if ((res = psiconv_list_add(formula_stack,formula))) |
|
|
472 | goto ERROR8; |
|
|
473 | formula->type = psiconv_formula_unknown; |
|
|
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; |
367 | } else if ((formula_elements[marker].formula_type == |
496 | } else if ((formula_elements[marker].formula_type == |
368 | psiconv_formula_dat_float) || |
|
|
369 | (formula_elements[marker].formula_type == |
|
|
370 | psiconv_formula_dat_var) || |
497 | psiconv_formula_dat_var) || |
371 | (formula_elements[marker].formula_type == |
498 | (formula_elements[marker].formula_type == |
372 | psiconv_formula_dat_string) || |
499 | psiconv_formula_dat_string) || |
373 | (formula_elements[marker].formula_type == |
|
|
374 | psiconv_formula_dat_cellref) || |
|
|
375 | (formula_elements[marker].formula_type == |
|
|
376 | psiconv_formula_dat_cellblock) || |
|
|
377 | (formula_elements[marker].formula_type == |
500 | (formula_elements[marker].formula_type == |
378 | psiconv_formula_dat_vcellblock) || |
501 | psiconv_formula_dat_vcellblock) || |
379 | (formula_elements[marker].formula_type == |
502 | (formula_elements[marker].formula_type == |
380 | psiconv_formula_mark_opsep) || |
503 | psiconv_formula_mark_opsep) || |
381 | (formula_elements[marker].formula_type == |
504 | (formula_elements[marker].formula_type == |