/[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 94
71 res = psiconv_parse_sketch_file(buf,lev+2,leng, 71 res = psiconv_parse_sketch_file(buf,lev+2,leng,
72 (psiconv_sketch_f *)(&((*result)->file))); 72 (psiconv_sketch_f *)(&((*result)->file)));
73 else if ((*result)->type == psiconv_clipart_file) 73 else if ((*result)->type == psiconv_clipart_file)
74 res = psiconv_parse_clipart_file(buf,lev+2,leng, 74 res = psiconv_parse_clipart_file(buf,lev+2,leng,
75 (psiconv_clipart_f *)(&((*result)->file))); 75 (psiconv_clipart_f *)(&((*result)->file)));
76 else if ((*result)->type == psiconv_sheet_file)
77 res = psiconv_parse_sheet_file(buf,lev+2,leng,
78 (psiconv_sheet_f *)(&((*result)->file)));
76 else { 79 else {
77 psiconv_warn(lev+1,off,"Can't parse this file yet!"); 80 psiconv_warn(lev+1,off,"Can't parse this file yet!");
78 (*result)->file = NULL; 81 (*result)->file = NULL;
79 } 82 }
80 if (res) 83 if (res)
669 if (res == 0) 672 if (res == 0)
670 return -PSICONV_E_NOMEM; 673 return -PSICONV_E_NOMEM;
671 else 674 else
672 return res; 675 return res;
673} 676}
677
678int psiconv_parse_sheet_file(const psiconv_buffer buf,int lev, psiconv_u32 off,
679 psiconv_sheet_f *result)
680{
681 int res=0;
682 psiconv_section_table_section table;
683 psiconv_application_id_section appl_id;
684 char *temp_str;
685 psiconv_u32 pwd_sec = 0;
686 psiconv_u32 status_sec = 0;
687 psiconv_u32 page_sec = 0;
688 psiconv_u32 applid_sec = 0;
689 psiconv_section_table_entry entry;
690 psiconv_u32 sto;
691 int i;
692
693 psiconv_progress(lev+1,off,"Going to read a sheet file");
694 if (!(*result = malloc(sizeof(**result))))
695 goto ERROR1;
696
697 psiconv_progress(lev+2,off,
698 "Going to read the offset of the section table section");
699 sto = psiconv_read_u32(buf,lev+2,off,&res);
700 if (res)
701 goto ERROR2;
702 psiconv_debug(lev+2,off,"Offset: %08x",sto);
703
704 psiconv_progress(lev+2,sto,
705 "Going to read the section table section");
706 if ((res = psiconv_parse_section_table_section(buf,lev+2,sto, NULL,&table)))
707 goto ERROR2;
708
709 for (i = 0; i < psiconv_list_length(table); i ++) {
710 psiconv_progress(lev+2,sto, "Going to read entry %d",i);
711 if (!(entry = psiconv_list_get(table,i)))
712 goto ERROR3;
713 if (entry->id == PSICONV_ID_APPL_ID_SECTION) {
714 applid_sec = entry->offset;
715 psiconv_debug(lev+3,sto,
716 "Found the Application ID section at %08x",applid_sec);
717 } else if (entry->id == PSICONV_ID_PAGE_LAYOUT_SECTION) {
718 page_sec = entry->offset;
719 psiconv_debug(lev+3,sto,
720 "Found the Page Layout section at %08x",page_sec);
721 } else if (entry->id == PSICONV_ID_PASSWORD_SECTION) {
722 pwd_sec = entry->offset;
723 psiconv_debug(lev+3,sto,
724 "Found the Password section at %08x",pwd_sec);
725 psiconv_warn(lev+3,sto,
726 "Password section found - can't read encrypted data");
727 res = -PSICONV_E_PARSE;
728 goto ERROR3;
729 } else if (entry->id == PSICONV_ID_SHEET_STATUS_SECTION) {
730 status_sec = entry->offset;
731 psiconv_debug(lev+3,sto,
732 "Found the Sheet Status section at %08x",status_sec);
733 } else {
734 psiconv_warn(lev+3,sto,
735 "Found unknown section in the Section Table (ignoring)");
736 psiconv_debug(lev+3,sto,
737 "Section ID %08x, offset %08x",entry->id,entry->offset);
738 }
739 }
740
741
742 psiconv_progress(lev+2,sto,
743 "Looking for the Status section");
744 if (!status_sec) {
745 psiconv_warn(lev+2,sto, "Status section not found in the section table");
746 res = -PSICONV_E_PARSE;
747 goto ERROR3;
748 } else {
749 psiconv_debug(lev+2,sto, "Status section at offset %08x",status_sec);
750 if ((res = psiconv_parse_sheet_status_section(buf,lev+2,status_sec,NULL,
751 &((*result)->status_sec))))
752 goto ERROR3;
753 }
754
755 psiconv_progress(lev+2,sto, "Looking for the Application ID section");
756 if (! applid_sec) {
757 psiconv_warn(lev+2,sto,
758 "Application ID section not found in the section table");
759 res = -PSICONV_E_PARSE;
760 goto ERROR4;
761 } else {
762 psiconv_debug(lev+2,sto,
763 "Application ID section at offset %08x",applid_sec);
764 if ((res = psiconv_parse_application_id_section(buf,lev+2,applid_sec,NULL,
765 &appl_id)))
766 goto ERROR4;
767 }
768 if ((appl_id->id != PSICONV_ID_SHEET) ||
769 strcmp(appl_id->name,"Sheet.app")) {
770 psiconv_warn(lev+2,applid_sec,
771 "Application ID section contains unexpected data");
772 psiconv_debug(lev+2,applid_sec,"ID: %08x expected, %08x found",
773 PSICONV_ID_SHEET,appl_id->id);
774 if (!(temp_str = psiconv_make_printable(appl_id->name)))
775 goto ERROR5;
776 psiconv_debug(lev+2,applid_sec,"Name: `%s' expected, `%s' found",
777 "Word.app",temp_str);
778 free(temp_str);
779 res = -PSICONV_E_PARSE;
780 goto ERROR5;
781 }
782
783 psiconv_progress(lev+2,sto,
784 "Looking for the Page layout section");
785 if (! page_sec) {
786 psiconv_warn(lev+2,sto,
787 "Page layout section not found in the section table");
788 res = -PSICONV_E_PARSE;
789 goto ERROR5;
790 } else {
791 psiconv_debug(lev+2,sto,
792 "Page layout section at offset %08x",page_sec);
793 if ((res = psiconv_parse_page_layout_section(buf,lev+2,page_sec,NULL,
794 &(*result)->page_sec)))
795 goto ERROR5;
796 }
797
798 psiconv_free_application_id_section(appl_id);
799 psiconv_free_section_table_section(table);
800
801 psiconv_progress(lev+1,off,"End of Sheet file");
802 return 0;
803
804
805ERROR5:
806 psiconv_free_application_id_section(appl_id);
807ERROR4:
808 psiconv_free_sheet_status_section((*result)->status_sec);
809ERROR3:
810 psiconv_free_section_table_section(table);
811ERROR2:
812 free(*result);
813ERROR1:
814 psiconv_warn(lev+1,off,"Reading of Sheet File failed");
815 if (res == 0)
816 return -PSICONV_E_NOMEM;
817 else
818 return res;
819}

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

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