/[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 66 Revision 95
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/ 18*/
19 19
20#include "config.h" 20#include "config.h"
21#include "compat.h"
22
21#include <stdlib.h> 23#include <stdlib.h>
22 24
23#include "parse.h" 25#include "parse.h"
24#include "parse_routines.h" 26#include "parse_routines.h"
25#include "data.h"
26 27
27psiconv_file_type_t psiconv_file_type(psiconv_buffer buf,int *length, 28psiconv_file_type_t psiconv_file_type(psiconv_buffer buf,int *length,
28 psiconv_header_section *result) 29 psiconv_header_section *result)
29{ 30{
30 psiconv_header_section header; 31 psiconv_header_section header;
70 res = psiconv_parse_sketch_file(buf,lev+2,leng, 71 res = psiconv_parse_sketch_file(buf,lev+2,leng,
71 (psiconv_sketch_f *)(&((*result)->file))); 72 (psiconv_sketch_f *)(&((*result)->file)));
72 else if ((*result)->type == psiconv_clipart_file) 73 else if ((*result)->type == psiconv_clipart_file)
73 res = psiconv_parse_clipart_file(buf,lev+2,leng, 74 res = psiconv_parse_clipart_file(buf,lev+2,leng,
74 (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)));
75 else { 79 else {
76 psiconv_warn(lev+1,off,"Can't parse this file yet!"); 80 psiconv_warn(lev+1,off,"Can't parse this file yet!");
77 (*result)->file = NULL; 81 (*result)->file = NULL;
78 } 82 }
79 if (res) 83 if (res)
644 648
645 psiconv_free_application_id_section(appl_id); 649 psiconv_free_application_id_section(appl_id);
646 psiconv_free_section_table_section(table); 650 psiconv_free_section_table_section(table);
647 651
648 psiconv_progress(lev+1,off,"End of word file"); 652 psiconv_progress(lev+1,off,"End of word file");
649 return res; 653 return 0;
650 654
651 655
652ERROR8: 656ERROR8:
653 psiconv_free_text_and_layout((*result)->paragraphs); 657 psiconv_free_text_and_layout((*result)->paragraphs);
654ERROR7: 658ERROR7:
668 if (res == 0) 672 if (res == 0)
669 return -PSICONV_E_NOMEM; 673 return -PSICONV_E_NOMEM;
670 else 674 else
671 return res; 675 return res;
672} 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_u32 workbook_sec = 0;
690 psiconv_section_table_entry entry;
691 psiconv_u32 sto;
692 int i;
693
694 psiconv_progress(lev+1,off,"Going to read a sheet file");
695 if (!(*result = malloc(sizeof(**result))))
696 goto ERROR1;
697
698 psiconv_progress(lev+2,off,
699 "Going to read the offset of the section table section");
700 sto = psiconv_read_u32(buf,lev+2,off,&res);
701 if (res)
702 goto ERROR2;
703 psiconv_debug(lev+2,off,"Offset: %08x",sto);
704
705 psiconv_progress(lev+2,sto,
706 "Going to read the section table section");
707 if ((res = psiconv_parse_section_table_section(buf,lev+2,sto, NULL,&table)))
708 goto ERROR2;
709
710 for (i = 0; i < psiconv_list_length(table); i ++) {
711 psiconv_progress(lev+2,sto, "Going to read entry %d",i);
712 if (!(entry = psiconv_list_get(table,i)))
713 goto ERROR3;
714 if (entry->id == PSICONV_ID_APPL_ID_SECTION) {
715 applid_sec = entry->offset;
716 psiconv_debug(lev+3,sto,
717 "Found the Application ID section at %08x",applid_sec);
718 } else if (entry->id == PSICONV_ID_PAGE_LAYOUT_SECTION) {
719 page_sec = entry->offset;
720 psiconv_debug(lev+3,sto,
721 "Found the Page Layout section at %08x",page_sec);
722 } else if (entry->id == PSICONV_ID_PASSWORD_SECTION) {
723 pwd_sec = entry->offset;
724 psiconv_debug(lev+3,sto,
725 "Found the Password section at %08x",pwd_sec);
726 psiconv_warn(lev+3,sto,
727 "Password section found - can't read encrypted data");
728 res = -PSICONV_E_PARSE;
729 goto ERROR3;
730 } else if (entry->id == PSICONV_ID_SHEET_WORKBOOK_SECTION) {
731 workbook_sec = entry->offset;
732 psiconv_debug(lev+3,sto,
733 "Found the Sheet Workbook section at %08x",workbook_sec);
734 } else if (entry->id == PSICONV_ID_SHEET_STATUS_SECTION) {
735 status_sec = entry->offset;
736 psiconv_debug(lev+3,sto,
737 "Found the Sheet Status section at %08x",status_sec);
738 } else {
739 psiconv_warn(lev+3,sto,
740 "Found unknown section in the Section Table (ignoring)");
741 psiconv_debug(lev+3,sto,
742 "Section ID %08x, offset %08x",entry->id,entry->offset);
743 }
744 }
745
746
747 psiconv_progress(lev+2,sto,
748 "Looking for the Status section");
749 if (!status_sec) {
750 psiconv_warn(lev+2,sto, "Status section not found in the section table");
751 res = -PSICONV_E_PARSE;
752 goto ERROR3;
753 } else {
754 psiconv_debug(lev+2,sto, "Status section at offset %08x",status_sec);
755 if ((res = psiconv_parse_sheet_status_section(buf,lev+2,status_sec,NULL,
756 &((*result)->status_sec))))
757 goto ERROR3;
758 }
759
760 psiconv_progress(lev+2,sto, "Looking for the Application ID section");
761 if (! applid_sec) {
762 psiconv_warn(lev+2,sto,
763 "Application ID section not found in the section table");
764 res = -PSICONV_E_PARSE;
765 goto ERROR4;
766 } else {
767 psiconv_debug(lev+2,sto,
768 "Application ID section at offset %08x",applid_sec);
769 if ((res = psiconv_parse_application_id_section(buf,lev+2,applid_sec,NULL,
770 &appl_id)))
771 goto ERROR4;
772 }
773 if ((appl_id->id != PSICONV_ID_SHEET) ||
774 strcmp(appl_id->name,"Sheet.app")) {
775 psiconv_warn(lev+2,applid_sec,
776 "Application ID section contains unexpected data");
777 psiconv_debug(lev+2,applid_sec,"ID: %08x expected, %08x found",
778 PSICONV_ID_SHEET,appl_id->id);
779 if (!(temp_str = psiconv_make_printable(appl_id->name)))
780 goto ERROR5;
781 psiconv_debug(lev+2,applid_sec,"Name: `%s' expected, `%s' found",
782 "Sheet.app",temp_str);
783 free(temp_str);
784 res = -PSICONV_E_PARSE;
785 goto ERROR5;
786 }
787
788 psiconv_progress(lev+2,sto,
789 "Looking for the Page layout section");
790 if (! page_sec) {
791 psiconv_warn(lev+2,sto,
792 "Page layout section not found in the section table");
793 res = -PSICONV_E_PARSE;
794 goto ERROR5;
795 } else {
796 psiconv_debug(lev+2,sto,
797 "Page layout section at offset %08x",page_sec);
798 if ((res = psiconv_parse_page_layout_section(buf,lev+2,page_sec,NULL,
799 &(*result)->page_sec)))
800 goto ERROR5;
801 }
802
803 psiconv_progress(lev+2,sto,
804 "Looking for the Sheet Workbook section");
805 if (! workbook_sec) {
806 psiconv_warn(lev+2,sto,
807 "Sheet workbook section not found in the section table");
808 res = -PSICONV_E_PARSE;
809 goto ERROR6;
810 } else {
811 psiconv_debug(lev+2,sto,
812 "Sheet workbook section at offset %08x",page_sec);
813 if ((res = psiconv_parse_sheet_workbook_section(buf,lev+2,workbook_sec,NULL,
814 &(*result)->workbook_sec)))
815 goto ERROR6;
816 }
817
818 psiconv_free_application_id_section(appl_id);
819 psiconv_free_section_table_section(table);
820
821 psiconv_progress(lev+1,off,"End of Sheet file");
822 return 0;
823
824ERROR6:
825 psiconv_free_page_layout_section((*result)->page_sec);
826ERROR5:
827 psiconv_free_application_id_section(appl_id);
828ERROR4:
829 psiconv_free_sheet_status_section((*result)->status_sec);
830ERROR3:
831 psiconv_free_section_table_section(table);
832ERROR2:
833 free(*result);
834ERROR1:
835 psiconv_warn(lev+1,off,"Reading of Sheet File failed");
836 if (res == 0)
837 return -PSICONV_E_NOMEM;
838 else
839 return res;
840}

Legend:
Removed from v.66  
changed lines
  Added in v.95

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