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

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

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

Revision 71 Revision 163
19 19
20#include "config.h" 20#include "config.h"
21#include "compat.h" 21#include "compat.h"
22 22
23#include <stdlib.h> 23#include <stdlib.h>
24#include <string.h>
24 25
25#include "parse.h" 26#include "parse.h"
26#include "parse_routines.h" 27#include "parse_routines.h"
28
29#ifdef DMALLOC
30#include <dmalloc.h>
31#endif
32
27 33
28psiconv_file_type_t psiconv_file_type(psiconv_buffer buf,int *length, 34psiconv_file_type_t psiconv_file_type(psiconv_buffer buf,int *length,
29 psiconv_header_section *result) 35 psiconv_header_section *result)
30{ 36{
31 psiconv_header_section header; 37 psiconv_header_section header;
71 res = psiconv_parse_sketch_file(buf,lev+2,leng, 77 res = psiconv_parse_sketch_file(buf,lev+2,leng,
72 (psiconv_sketch_f *)(&((*result)->file))); 78 (psiconv_sketch_f *)(&((*result)->file)));
73 else if ((*result)->type == psiconv_clipart_file) 79 else if ((*result)->type == psiconv_clipart_file)
74 res = psiconv_parse_clipart_file(buf,lev+2,leng, 80 res = psiconv_parse_clipart_file(buf,lev+2,leng,
75 (psiconv_clipart_f *)(&((*result)->file))); 81 (psiconv_clipart_f *)(&((*result)->file)));
82 else if ((*result)->type == psiconv_sheet_file)
83 res = psiconv_parse_sheet_file(buf,lev+2,leng,
84 (psiconv_sheet_f *)(&((*result)->file)));
76 else { 85 else {
77 psiconv_warn(lev+1,off,"Can't parse this file yet!"); 86 psiconv_warn(lev+1,off,"Can't parse this file yet!");
78 (*result)->file = NULL; 87 (*result)->file = NULL;
79 } 88 }
80 if (res) 89 if (res)
293 psiconv_warn(lev+2,sto, 302 psiconv_warn(lev+2,sto,
294 "Sketch section not found in the section table"); 303 "Sketch section not found in the section table");
295 } else { 304 } else {
296 psiconv_debug(lev+2,sto, 305 psiconv_debug(lev+2,sto,
297 "Sketch section at offset %08x",applid_sec); 306 "Sketch section at offset %08x",applid_sec);
298 if ((res = psiconv_parse_sketch_section(buf,lev+2,sketch_sec,NULL,0, 307 if ((res = psiconv_parse_sketch_section(buf,lev+2,sketch_sec,NULL,
299 &(*result)->sketch_sec))) 308 &(*result)->sketch_sec)))
300 goto ERROR4; 309 goto ERROR4;
301 } 310 }
302 311
303 psiconv_free_application_id_section(appl_id); 312 psiconv_free_application_id_section(appl_id);
669 if (res == 0) 678 if (res == 0)
670 return -PSICONV_E_NOMEM; 679 return -PSICONV_E_NOMEM;
671 else 680 else
672 return res; 681 return res;
673} 682}
683
684int psiconv_parse_sheet_file(const psiconv_buffer buf,int lev, psiconv_u32 off,
685 psiconv_sheet_f *result)
686{
687 int res=0;
688 psiconv_section_table_section table;
689 psiconv_application_id_section appl_id;
690 char *temp_str;
691 psiconv_u32 pwd_sec = 0;
692 psiconv_u32 status_sec = 0;
693 psiconv_u32 page_sec = 0;
694 psiconv_u32 applid_sec = 0;
695 psiconv_u32 workbook_sec = 0;
696 psiconv_section_table_entry entry;
697 psiconv_u32 sto;
698 int i;
699
700 psiconv_progress(lev+1,off,"Going to read a sheet file");
701 if (!(*result = malloc(sizeof(**result))))
702 goto ERROR1;
703
704 psiconv_progress(lev+2,off,
705 "Going to read the offset of the section table section");
706 sto = psiconv_read_u32(buf,lev+2,off,&res);
707 if (res)
708 goto ERROR2;
709 psiconv_debug(lev+2,off,"Offset: %08x",sto);
710
711 psiconv_progress(lev+2,sto,
712 "Going to read the section table section");
713 if ((res = psiconv_parse_section_table_section(buf,lev+2,sto, NULL,&table)))
714 goto ERROR2;
715
716 for (i = 0; i < psiconv_list_length(table); i ++) {
717 psiconv_progress(lev+2,sto, "Going to read entry %d",i);
718 if (!(entry = psiconv_list_get(table,i)))
719 goto ERROR3;
720 if (entry->id == PSICONV_ID_APPL_ID_SECTION) {
721 applid_sec = entry->offset;
722 psiconv_debug(lev+3,sto,
723 "Found the Application ID section at %08x",applid_sec);
724 } else if (entry->id == PSICONV_ID_PAGE_LAYOUT_SECTION) {
725 page_sec = entry->offset;
726 psiconv_debug(lev+3,sto,
727 "Found the Page Layout section at %08x",page_sec);
728 } else if (entry->id == PSICONV_ID_PASSWORD_SECTION) {
729 pwd_sec = entry->offset;
730 psiconv_debug(lev+3,sto,
731 "Found the Password section at %08x",pwd_sec);
732 psiconv_warn(lev+3,sto,
733 "Password section found - can't read encrypted data");
734 res = -PSICONV_E_PARSE;
735 goto ERROR3;
736 } else if (entry->id == PSICONV_ID_SHEET_WORKBOOK_SECTION) {
737 workbook_sec = entry->offset;
738 psiconv_debug(lev+3,sto,
739 "Found the Sheet Workbook section at %08x",workbook_sec);
740 } else if (entry->id == PSICONV_ID_SHEET_STATUS_SECTION) {
741 status_sec = entry->offset;
742 psiconv_debug(lev+3,sto,
743 "Found the Sheet Status section at %08x",status_sec);
744 } else {
745 psiconv_warn(lev+3,sto,
746 "Found unknown section in the Section Table (ignoring)");
747 psiconv_debug(lev+3,sto,
748 "Section ID %08x, offset %08x",entry->id,entry->offset);
749 }
750 }
751
752
753 psiconv_progress(lev+2,sto,
754 "Looking for the Status section");
755 if (!status_sec) {
756 psiconv_warn(lev+2,sto, "Status section not found in the section table");
757 res = -PSICONV_E_PARSE;
758 goto ERROR3;
759 } else {
760 psiconv_debug(lev+2,sto, "Status section at offset %08x",status_sec);
761 if ((res = psiconv_parse_sheet_status_section(buf,lev+2,status_sec,NULL,
762 &((*result)->status_sec))))
763 goto ERROR3;
764 }
765
766 psiconv_progress(lev+2,sto, "Looking for the Application ID section");
767 if (! applid_sec) {
768 psiconv_warn(lev+2,sto,
769 "Application ID section not found in the section table");
770 res = -PSICONV_E_PARSE;
771 goto ERROR4;
772 } else {
773 psiconv_debug(lev+2,sto,
774 "Application ID section at offset %08x",applid_sec);
775 if ((res = psiconv_parse_application_id_section(buf,lev+2,applid_sec,NULL,
776 &appl_id)))
777 goto ERROR4;
778 }
779 if ((appl_id->id != PSICONV_ID_SHEET) ||
780 strcmp(appl_id->name,"Sheet.app")) {
781 psiconv_warn(lev+2,applid_sec,
782 "Application ID section contains unexpected data");
783 psiconv_debug(lev+2,applid_sec,"ID: %08x expected, %08x found",
784 PSICONV_ID_SHEET,appl_id->id);
785 if (!(temp_str = psiconv_make_printable(appl_id->name)))
786 goto ERROR5;
787 psiconv_debug(lev+2,applid_sec,"Name: `%s' expected, `%s' found",
788 "Sheet.app",temp_str);
789 free(temp_str);
790 res = -PSICONV_E_PARSE;
791 goto ERROR5;
792 }
793
794 psiconv_progress(lev+2,sto,
795 "Looking for the Page layout section");
796 if (! page_sec) {
797 psiconv_warn(lev+2,sto,
798 "Page layout section not found in the section table");
799 res = -PSICONV_E_PARSE;
800 goto ERROR5;
801 } else {
802 psiconv_debug(lev+2,sto,
803 "Page layout section at offset %08x",page_sec);
804 if ((res = psiconv_parse_page_layout_section(buf,lev+2,page_sec,NULL,
805 &(*result)->page_sec)))
806 goto ERROR5;
807 }
808
809 psiconv_progress(lev+2,sto,
810 "Looking for the Sheet Workbook section");
811 if (! workbook_sec) {
812 psiconv_warn(lev+2,sto,
813 "Sheet workbook section not found in the section table");
814 res = -PSICONV_E_PARSE;
815 goto ERROR6;
816 } else {
817 psiconv_debug(lev+2,sto,
818 "Sheet workbook section at offset %08x",page_sec);
819 if ((res = psiconv_parse_sheet_workbook_section(buf,lev+2,workbook_sec,NULL,
820 &(*result)->workbook_sec)))
821 goto ERROR6;
822 }
823
824 psiconv_free_application_id_section(appl_id);
825 psiconv_free_section_table_section(table);
826
827 psiconv_progress(lev+1,off,"End of Sheet file");
828 return 0;
829
830ERROR6:
831 psiconv_free_page_layout_section((*result)->page_sec);
832ERROR5:
833 psiconv_free_application_id_section(appl_id);
834ERROR4:
835 psiconv_free_sheet_status_section((*result)->status_sec);
836ERROR3:
837 psiconv_free_section_table_section(table);
838ERROR2:
839 free(*result);
840ERROR1:
841 psiconv_warn(lev+1,off,"Reading of Sheet File failed");
842 if (res == 0)
843 return -PSICONV_E_NOMEM;
844 else
845 return res;
846}

Legend:
Removed from v.71  
changed lines
  Added in v.163

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