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