1 | /* |
1 | /* |
2 | data.c - Part of psiconv, a PSION 5 file formats converter |
2 | data.c - Part of psiconv, a PSION 5 file formats converter |
3 | Copyright (c) 1999 Frodo Looijaard <frodol@dds.nl> |
3 | Copyright (c) 1999, 2000 Frodo Looijaard <frodol@dds.nl> |
4 | |
4 | |
5 | This program is free software; you can redistribute it and/or modify |
5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
8 | (at your option) any later version. |
… | |
… | |
20 | #include "config.h" |
20 | #include "config.h" |
21 | #include "compat.h" |
21 | #include "compat.h" |
22 | #include <stdlib.h> |
22 | #include <stdlib.h> |
23 | #include <string.h> |
23 | #include <string.h> |
24 | #include "data.h" |
24 | #include "data.h" |
|
|
25 | #include "list.h" |
25 | |
26 | |
26 | static psiconv_color clone_color(psiconv_color color); |
27 | static psiconv_color clone_color(psiconv_color color); |
27 | static psiconv_font clone_font(psiconv_font font); |
28 | static psiconv_font clone_font(psiconv_font font); |
28 | static psiconv_border clone_border(psiconv_border border); |
29 | static psiconv_border clone_border(psiconv_border border); |
29 | static psiconv_bullet clone_bullet(psiconv_bullet bullet); |
30 | static psiconv_bullet clone_bullet(psiconv_bullet bullet); |
… | |
… | |
31 | static void psiconv_free_style_aux(void *style); |
32 | static void psiconv_free_style_aux(void *style); |
32 | static void psiconv_free_in_line_layout_aux(void * layout); |
33 | static void psiconv_free_in_line_layout_aux(void * layout); |
33 | static void psiconv_free_paragraph_aux(void * paragraph); |
34 | static void psiconv_free_paragraph_aux(void * paragraph); |
34 | static void psiconv_free_paint_data_section_aux(void * section); |
35 | static void psiconv_free_paint_data_section_aux(void * section); |
35 | static void psiconv_free_clipart_section_aux(void * section); |
36 | static void psiconv_free_clipart_section_aux(void * section); |
|
|
37 | static void psiconv_free_formula_aux(void *data); |
|
|
38 | static void psiconv_free_sheet_worksheet_aux (void *data); |
36 | |
39 | |
|
|
40 | static psiconv_word_styles_section psiconv_empty_word_styles_section(void); |
|
|
41 | static psiconv_text_and_layout psiconv_empty_text_and_layout(void); |
|
|
42 | static psiconv_texted_section psiconv_empty_texted_section(void); |
|
|
43 | static psiconv_page_header psiconv_empty_page_header(void); |
|
|
44 | static psiconv_page_layout_section psiconv_empty_page_layout_section(void); |
|
|
45 | static psiconv_word_status_section psiconv_empty_word_status_section(void); |
|
|
46 | static psiconv_word_f psiconv_empty_word_f(void); |
|
|
47 | static psiconv_sheet_status_section psiconv_empty_sheet_status_section(void); |
|
|
48 | static psiconv_formula_list psiconv_empty_formula_list(void); |
|
|
49 | static psiconv_sheet_workbook_section |
|
|
50 | psiconv_empty_sheet_workbook_section(void); |
|
|
51 | static psiconv_sheet_f psiconv_empty_sheet_f(void); |
|
|
52 | static psiconv_texted_f psiconv_empty_texted_f(void); |
|
|
53 | static psiconv_paint_data_section psiconv_empty_paint_data_section(void); |
|
|
54 | static psiconv_pictures psiconv_empty_pictures(void); |
|
|
55 | static psiconv_mbm_f psiconv_empty_mbm_f(void); |
|
|
56 | static psiconv_sketch_section psiconv_empty_sketch_section(void); |
|
|
57 | static psiconv_sketch_f psiconv_empty_sketch_f(void); |
|
|
58 | static psiconv_clipart_f psiconv_empty_clipart_f(void); |
|
|
59 | static psiconv_cliparts psiconv_empty_cliparts(void); |
|
|
60 | |
|
|
61 | |
|
|
62 | /* Note: these defaults seem to be hard-coded somewhere outside the |
|
|
63 | files themself. */ |
37 | psiconv_character_layout psiconv_basic_character_layout(void) |
64 | psiconv_character_layout psiconv_basic_character_layout(void) |
38 | { |
65 | { |
39 | /* Make the structures static, to oblige IRIX */ |
66 | /* Make the structures static, to oblige IRIX */ |
40 | static struct psiconv_color_s black = |
67 | static struct psiconv_color_s black = |
41 | { |
68 | { |
… | |
… | |
61 | 10.0, /* font_size */ |
88 | 10.0, /* font_size */ |
62 | psiconv_bool_false, /* italic */ |
89 | psiconv_bool_false, /* italic */ |
63 | psiconv_bool_false, /* bold */ |
90 | psiconv_bool_false, /* bold */ |
64 | psiconv_normalscript, /* super_sub */ |
91 | psiconv_normalscript, /* super_sub */ |
65 | psiconv_bool_false, /* underline */ |
92 | psiconv_bool_false, /* underline */ |
66 | psiconv_bool_false, /* strike_out */ |
93 | psiconv_bool_false, /* strikethrough */ |
67 | &font, /* font */ |
94 | &font, /* font */ |
68 | }; |
95 | }; |
69 | |
96 | |
70 | return psiconv_clone_character_layout(&cl); |
97 | return psiconv_clone_character_layout(&cl); |
71 | } |
98 | } |
72 | |
99 | |
|
|
100 | /* Note: these defaults seem to be hard-coded somewhere outside the |
|
|
101 | files themself. */ |
73 | psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) |
102 | psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) |
74 | { |
103 | { |
75 | static struct psiconv_font_s font = |
104 | static struct psiconv_font_s font = |
76 | { |
105 | { |
77 | "Times New Roman", /* name */ |
106 | "Times New Roman", /* name */ |
… | |
… | |
115 | 0.0, /* indent_left */ |
144 | 0.0, /* indent_left */ |
116 | 0.0, /* indent_right */ |
145 | 0.0, /* indent_right */ |
117 | 0.0, /* indent_first */ |
146 | 0.0, /* indent_first */ |
118 | psiconv_justify_left, /* justify_hor */ |
147 | psiconv_justify_left, /* justify_hor */ |
119 | psiconv_justify_middle,/* justify_ver */ |
148 | psiconv_justify_middle,/* justify_ver */ |
120 | 0.0, /* interline */ |
149 | 10.0, /* linespacing */ |
121 | psiconv_bool_false, /* interline_exact */ |
150 | psiconv_bool_false, /* linespacing_exact */ |
122 | 0.0, /* top_space */ |
151 | 0.0, /* space_above */ |
123 | 0.0, /* bottom_space */ |
152 | 0.0, /* space_below */ |
124 | psiconv_bool_false, /* on_one_page */ |
|
|
125 | psiconv_bool_false, /* together_with */ |
153 | psiconv_bool_false, /* keep_together */ |
|
|
154 | psiconv_bool_false, /* keep_with_next */ |
126 | psiconv_bool_false, /* on_next_page */ |
155 | psiconv_bool_false, /* on_next_page */ |
127 | psiconv_bool_false, /* no_widow_protection */ |
156 | psiconv_bool_false, /* no_widow_protection */ |
|
|
157 | psiconv_bool_false, /* wrap_to_fit_cell */ |
128 | 0.0, /* left_margin */ |
158 | 0.0, /* left_margin */ |
129 | &bullet, /* bullet */ |
159 | &bullet, /* bullet */ |
130 | &no_border, /* left_border */ |
160 | &no_border, /* left_border */ |
131 | &no_border, /* right_border */ |
161 | &no_border, /* right_border */ |
132 | &no_border, /* top_border */ |
162 | &no_border, /* top_border */ |
… | |
… | |
512 | psiconv_free_word_styles_section(file->styles_sec); |
542 | psiconv_free_word_styles_section(file->styles_sec); |
513 | free(file); |
543 | free(file); |
514 | } |
544 | } |
515 | } |
545 | } |
516 | |
546 | |
|
|
547 | void psiconv_free_sheet_status_section(psiconv_sheet_status_section section) |
|
|
548 | { |
|
|
549 | if (section) |
|
|
550 | free(section); |
|
|
551 | } |
|
|
552 | |
|
|
553 | void psiconv_free_sheet_numberformat(psiconv_sheet_numberformat numberformat) |
|
|
554 | { |
|
|
555 | if (numberformat) |
|
|
556 | free(numberformat); |
|
|
557 | } |
|
|
558 | |
|
|
559 | void psiconv_free_sheet_cell_layout(psiconv_sheet_cell_layout layout) |
|
|
560 | { |
|
|
561 | psiconv_free_paragraph_layout(layout->paragraph); |
|
|
562 | psiconv_free_character_layout(layout->character); |
|
|
563 | psiconv_free_sheet_numberformat(layout->numberformat); |
|
|
564 | } |
|
|
565 | |
|
|
566 | void psiconv_free_sheet_cell_aux(void *cell) |
|
|
567 | { |
|
|
568 | psiconv_sheet_cell data = cell; |
|
|
569 | |
|
|
570 | psiconv_free_sheet_cell_layout(data->layout); |
|
|
571 | |
|
|
572 | if ((data->type == psiconv_cell_string) && (data->data.dat_string)) |
|
|
573 | free(data->data.dat_string); |
|
|
574 | } |
|
|
575 | |
|
|
576 | void psiconv_free_sheet_cell(psiconv_sheet_cell cell) |
|
|
577 | { |
|
|
578 | if (cell) { |
|
|
579 | psiconv_free_sheet_cell_aux(cell); |
|
|
580 | free(cell); |
|
|
581 | } |
|
|
582 | } |
|
|
583 | |
|
|
584 | void psiconv_free_sheet_cell_list(psiconv_sheet_cell_list list) |
|
|
585 | { |
|
|
586 | if (list) |
|
|
587 | psiconv_list_free_el(list,psiconv_free_sheet_cell_aux); |
|
|
588 | } |
|
|
589 | |
|
|
590 | void psiconv_free_sheet_worksheet_aux (void *data) |
|
|
591 | { |
|
|
592 | psiconv_sheet_worksheet section = data; |
|
|
593 | psiconv_free_sheet_cell_layout(section->default_layout); |
|
|
594 | psiconv_free_sheet_cell_list(section->cells); |
|
|
595 | } |
|
|
596 | |
|
|
597 | void psiconv_free_sheet_worksheet(psiconv_sheet_worksheet sheet) |
|
|
598 | { |
|
|
599 | if (sheet) { |
|
|
600 | psiconv_free_sheet_worksheet_aux(sheet); |
|
|
601 | free(sheet); |
|
|
602 | } |
|
|
603 | } |
|
|
604 | |
|
|
605 | void psiconv_free_sheet_worksheet_list(psiconv_sheet_worksheet_list list) |
|
|
606 | { |
|
|
607 | if (list) |
|
|
608 | psiconv_list_free_el(list,psiconv_free_sheet_worksheet_aux); |
|
|
609 | } |
|
|
610 | |
|
|
611 | void psiconv_free_formula_aux(void *data) |
|
|
612 | { |
|
|
613 | psiconv_formula formula; |
|
|
614 | formula = data; |
|
|
615 | if (formula->type == psiconv_formula_dat_string) |
|
|
616 | free(formula->data.dat_string); |
|
|
617 | else if ((formula->type != psiconv_formula_dat_int) && |
|
|
618 | (formula->type != psiconv_formula_dat_var) && |
|
|
619 | (formula->type != psiconv_formula_dat_float) && |
|
|
620 | (formula->type != psiconv_formula_dat_cellref) && |
|
|
621 | (formula->type != psiconv_formula_dat_cellblock) && |
|
|
622 | (formula->type != psiconv_formula_dat_vcellblock) && |
|
|
623 | (formula->type != psiconv_formula_mark_opsep) && |
|
|
624 | (formula->type != psiconv_formula_mark_opend) && |
|
|
625 | (formula->type != psiconv_formula_mark_eof) && |
|
|
626 | (formula->type != psiconv_formula_unknown)) |
|
|
627 | psiconv_free_formula_list(formula->data.fun_operands); |
|
|
628 | } |
|
|
629 | |
|
|
630 | void psiconv_free_formula(psiconv_formula formula) |
|
|
631 | { |
|
|
632 | if (formula) { |
|
|
633 | psiconv_free_formula_aux(formula); |
|
|
634 | free(formula); |
|
|
635 | } |
|
|
636 | } |
|
|
637 | |
|
|
638 | void psiconv_free_formula_list(psiconv_formula_list list) |
|
|
639 | { |
|
|
640 | if (list) |
|
|
641 | psiconv_list_free_el(list,psiconv_free_formula_aux); |
|
|
642 | } |
|
|
643 | |
|
|
644 | void psiconv_free_sheet_workbook_section(psiconv_sheet_workbook_section section) |
|
|
645 | { |
|
|
646 | if (section) { |
|
|
647 | psiconv_free_formula_list(section->formulas); |
|
|
648 | psiconv_free_sheet_worksheet_list(section->worksheets); |
|
|
649 | free(section); |
|
|
650 | } |
|
|
651 | } |
|
|
652 | |
|
|
653 | void psiconv_free_sheet_f(psiconv_sheet_f file) |
|
|
654 | { |
|
|
655 | if (file) { |
|
|
656 | psiconv_free_page_layout_section(file->page_sec); |
|
|
657 | psiconv_free_sheet_status_section(file->status_sec); |
|
|
658 | psiconv_free_sheet_workbook_section(file->workbook_sec); |
|
|
659 | free(file); |
|
|
660 | } |
|
|
661 | } |
|
|
662 | |
517 | void psiconv_free_texted_f(psiconv_texted_f file) |
663 | void psiconv_free_texted_f(psiconv_texted_f file) |
518 | { |
664 | { |
519 | if (file) { |
665 | if (file) { |
520 | psiconv_free_page_layout_section(file->page_sec); |
666 | psiconv_free_page_layout_section(file->page_sec); |
521 | psiconv_free_texted_section(file->texted_sec); |
667 | psiconv_free_texted_section(file->texted_sec); |
… | |
… | |
616 | psiconv_free_mbm_f((psiconv_mbm_f) file->file); |
762 | psiconv_free_mbm_f((psiconv_mbm_f) file->file); |
617 | else if (file->type == psiconv_sketch_file) |
763 | else if (file->type == psiconv_sketch_file) |
618 | psiconv_free_sketch_f((psiconv_sketch_f) file->file); |
764 | psiconv_free_sketch_f((psiconv_sketch_f) file->file); |
619 | else if (file->type == psiconv_clipart_file) |
765 | else if (file->type == psiconv_clipart_file) |
620 | psiconv_free_clipart_f((psiconv_clipart_f) file->file); |
766 | psiconv_free_clipart_f((psiconv_clipart_f) file->file); |
|
|
767 | else if (file->type == psiconv_sheet_file) |
|
|
768 | psiconv_free_sheet_f((psiconv_sheet_f) file->file); |
621 | free(file); |
769 | free(file); |
622 | } |
770 | } |
623 | } |
771 | } |
|
|
772 | |
|
|
773 | int psiconv_compare_color(const psiconv_color value1, |
|
|
774 | const psiconv_color value2) |
|
|
775 | { |
|
|
776 | if (!value1 || !value2) |
|
|
777 | return 1; |
|
|
778 | if ((value1->red == value2->red) && |
|
|
779 | (value1->green == value2->green) && |
|
|
780 | (value1->blue == value2->blue)) |
|
|
781 | return 0; |
|
|
782 | else |
|
|
783 | return 1; |
|
|
784 | } |
|
|
785 | |
|
|
786 | int psiconv_compare_font(const psiconv_font value1, |
|
|
787 | const psiconv_font value2) |
|
|
788 | { |
|
|
789 | if (!value1 || !value2 || !value1->name || !value2->name) |
|
|
790 | return 1; |
|
|
791 | if ((value1->screenfont == value2->screenfont) && |
|
|
792 | !strcmp(value1->name,value2->name)) |
|
|
793 | return 0; |
|
|
794 | else |
|
|
795 | return 1; |
|
|
796 | } |
|
|
797 | |
|
|
798 | int psiconv_compare_border(const psiconv_border value1, |
|
|
799 | const psiconv_border value2) |
|
|
800 | { |
|
|
801 | if (!value1 || !value2) |
|
|
802 | return 1; |
|
|
803 | if ((value1->kind == value2->kind) && |
|
|
804 | (value1->thickness == value2->thickness) && |
|
|
805 | !psiconv_compare_color(value1->color,value2->color)) |
|
|
806 | return 0; |
|
|
807 | else |
|
|
808 | return 1; |
|
|
809 | } |
|
|
810 | |
|
|
811 | int psiconv_compare_bullet(const psiconv_bullet value1, |
|
|
812 | const psiconv_bullet value2) |
|
|
813 | { |
|
|
814 | if (!value1 || !value2) |
|
|
815 | return 1; |
|
|
816 | if ((value1->on == value2->on) && |
|
|
817 | (value1->font_size == value2->font_size) && |
|
|
818 | (value1->character == value2->character) && |
|
|
819 | (value1->indent == value2->indent) && |
|
|
820 | !psiconv_compare_color(value1->color,value2->color) && |
|
|
821 | !psiconv_compare_font(value1->font,value2->font)) |
|
|
822 | return 0; |
|
|
823 | else |
|
|
824 | return 1; |
|
|
825 | } |
|
|
826 | |
|
|
827 | int psiconv_compare_tab(const psiconv_tab value1, const psiconv_tab value2) |
|
|
828 | { |
|
|
829 | if (!value1 || !value2) |
|
|
830 | return 1; |
|
|
831 | if ((value1->location == value2->location) && |
|
|
832 | (value1->kind == value2->kind)) |
|
|
833 | return 0; |
|
|
834 | else |
|
|
835 | return 1; |
|
|
836 | } |
|
|
837 | |
|
|
838 | int psiconv_compare_all_tabs(const psiconv_all_tabs value1, |
|
|
839 | const psiconv_all_tabs value2) |
|
|
840 | { |
|
|
841 | int i; |
|
|
842 | |
|
|
843 | if (!value1 || !value2 || !value1->extras || !value2->extras) |
|
|
844 | return 1; |
|
|
845 | |
|
|
846 | if ((value1->normal != value2->normal) || |
|
|
847 | psiconv_list_length(value1->extras) != |
|
|
848 | psiconv_list_length(value2->extras)) |
|
|
849 | return 1; |
|
|
850 | for (i = 0; i < psiconv_list_length(value1->extras); i++) |
|
|
851 | if (psiconv_compare_tab(psiconv_list_get(value1->extras,i), |
|
|
852 | psiconv_list_get(value2->extras,i))) |
|
|
853 | |
|
|
854 | return 1; |
|
|
855 | return 0; |
|
|
856 | } |
|
|
857 | |
|
|
858 | int psiconv_compare_paragraph_layout(const psiconv_paragraph_layout value1, |
|
|
859 | const psiconv_paragraph_layout value2) |
|
|
860 | { |
|
|
861 | if (!value1 || !value2) |
|
|
862 | return 1; |
|
|
863 | if ((value1->indent_left == value2->indent_left) && |
|
|
864 | (value1->indent_right == value2->indent_right) && |
|
|
865 | (value1->indent_first == value2->indent_first) && |
|
|
866 | (value1->justify_hor == value2->justify_hor) && |
|
|
867 | (value1->justify_ver == value2->justify_ver) && |
|
|
868 | (value1->linespacing == value2->linespacing) && |
|
|
869 | (value1->space_above == value2->space_above) && |
|
|
870 | (value1->space_below == value2->space_below) && |
|
|
871 | (value1->keep_together == value2->keep_together) && |
|
|
872 | (value1->keep_with_next == value2->keep_with_next) && |
|
|
873 | (value1->on_next_page == value2->on_next_page) && |
|
|
874 | (value1->no_widow_protection == value2->no_widow_protection) && |
|
|
875 | (value1->border_distance == value2->border_distance) && |
|
|
876 | !psiconv_compare_color(value1->back_color,value2->back_color) && |
|
|
877 | !psiconv_compare_bullet(value1->bullet,value2->bullet) && |
|
|
878 | !psiconv_compare_border(value1->left_border,value2->left_border) && |
|
|
879 | !psiconv_compare_border(value1->right_border,value2->right_border) && |
|
|
880 | !psiconv_compare_border(value1->top_border,value2->top_border) && |
|
|
881 | !psiconv_compare_border(value1->bottom_border,value2->bottom_border) && |
|
|
882 | !psiconv_compare_all_tabs(value1->tabs,value2->tabs)) |
|
|
883 | return 0; |
|
|
884 | else |
|
|
885 | return 1; |
|
|
886 | } |
|
|
887 | |
|
|
888 | |
|
|
889 | int psiconv_compare_character_layout(const psiconv_character_layout value1, |
|
|
890 | const psiconv_character_layout value2) |
|
|
891 | { |
|
|
892 | if (!value1 || !value2) |
|
|
893 | return 1; |
|
|
894 | if ((value1->font_size == value2->font_size) && |
|
|
895 | (value1->italic == value2->italic) && |
|
|
896 | (value1->bold == value2->bold) && |
|
|
897 | (value1->super_sub == value2->super_sub) && |
|
|
898 | (value1->underline == value2->underline) && |
|
|
899 | (value1->strikethrough == value2->strikethrough) && |
|
|
900 | !psiconv_compare_color(value1->color,value2->color) && |
|
|
901 | !psiconv_compare_color(value1->back_color,value2->back_color) && |
|
|
902 | !psiconv_compare_font(value1->font,value2->font)) |
|
|
903 | return 0; |
|
|
904 | else |
|
|
905 | return 1; |
|
|
906 | } |
|
|
907 | |
|
|
908 | |
|
|
909 | |
|
|
910 | psiconv_word_styles_section psiconv_empty_word_styles_section(void) |
|
|
911 | { |
|
|
912 | psiconv_word_styles_section result; |
|
|
913 | if (!(result = malloc(sizeof(*result)))) |
|
|
914 | goto ERROR1; |
|
|
915 | if (!(result->styles = psiconv_list_new(sizeof(struct psiconv_word_style_s)))) |
|
|
916 | goto ERROR2; |
|
|
917 | if (!(result->normal = malloc(sizeof(struct psiconv_word_style_s)))) |
|
|
918 | goto ERROR3; |
|
|
919 | if (!(result->normal->character = psiconv_basic_character_layout())) |
|
|
920 | goto ERROR4; |
|
|
921 | if (!(result->normal->paragraph = psiconv_basic_paragraph_layout())) |
|
|
922 | goto ERROR5; |
|
|
923 | result->normal->hotkey = 'N'; |
|
|
924 | result->normal->name = NULL; |
|
|
925 | result->normal->built_in = psiconv_bool_true; |
|
|
926 | result->normal->outline_level = 0; |
|
|
927 | return result; |
|
|
928 | ERROR5: |
|
|
929 | psiconv_free_character_layout(result->normal->character); |
|
|
930 | ERROR4: |
|
|
931 | free(result->normal); |
|
|
932 | ERROR3: |
|
|
933 | psiconv_list_free(result->styles); |
|
|
934 | ERROR2: |
|
|
935 | free(result); |
|
|
936 | ERROR1: |
|
|
937 | return NULL; |
|
|
938 | } |
|
|
939 | |
|
|
940 | psiconv_text_and_layout psiconv_empty_text_and_layout(void) |
|
|
941 | { |
|
|
942 | return psiconv_list_new(sizeof(struct psiconv_paragraph_s)); |
|
|
943 | } |
|
|
944 | |
|
|
945 | psiconv_texted_section psiconv_empty_texted_section(void) |
|
|
946 | { |
|
|
947 | psiconv_texted_section result; |
|
|
948 | if (!(result = malloc(sizeof(*result)))) |
|
|
949 | goto ERROR1; |
|
|
950 | if (!(result->paragraphs = psiconv_empty_text_and_layout())) |
|
|
951 | goto ERROR2; |
|
|
952 | return result; |
|
|
953 | ERROR2: |
|
|
954 | free(result); |
|
|
955 | ERROR1: |
|
|
956 | return NULL; |
|
|
957 | } |
|
|
958 | |
|
|
959 | psiconv_page_header psiconv_empty_page_header(void) |
|
|
960 | { |
|
|
961 | psiconv_page_header result; |
|
|
962 | if (!(result = malloc(sizeof(*result)))) |
|
|
963 | goto ERROR1; |
|
|
964 | result->on_first_page = psiconv_bool_true; |
|
|
965 | if (!(result->base_paragraph_layout = psiconv_basic_paragraph_layout())) |
|
|
966 | goto ERROR2; |
|
|
967 | if (!(result->base_character_layout = psiconv_basic_character_layout())) |
|
|
968 | goto ERROR3; |
|
|
969 | if (!(result->text = psiconv_empty_texted_section())) |
|
|
970 | goto ERROR4; |
|
|
971 | return result; |
|
|
972 | ERROR4: |
|
|
973 | psiconv_free_character_layout(result->base_character_layout); |
|
|
974 | ERROR3: |
|
|
975 | psiconv_free_paragraph_layout(result->base_paragraph_layout); |
|
|
976 | ERROR2: |
|
|
977 | free(result); |
|
|
978 | ERROR1: |
|
|
979 | return NULL; |
|
|
980 | } |
|
|
981 | |
|
|
982 | psiconv_page_layout_section psiconv_empty_page_layout_section(void) |
|
|
983 | { |
|
|
984 | psiconv_page_layout_section result; |
|
|
985 | if (!(result = malloc(sizeof(*result)))) |
|
|
986 | goto ERROR1; |
|
|
987 | result->first_page_nr = 1; |
|
|
988 | result->header_dist = result->footer_dist = 1.27; |
|
|
989 | result->left_margin = result->right_margin = 3.175; |
|
|
990 | result->top_margin = result->bottom_margin = 2.54; |
|
|
991 | result->page_width = 21.0; |
|
|
992 | result->page_height = 29.7; |
|
|
993 | result->landscape = psiconv_bool_false; |
|
|
994 | if (!(result->header = psiconv_empty_page_header())) |
|
|
995 | goto ERROR2; |
|
|
996 | if (!(result->footer = psiconv_empty_page_header())) |
|
|
997 | goto ERROR3; |
|
|
998 | return result; |
|
|
999 | ERROR3: |
|
|
1000 | psiconv_free_page_header(result->header); |
|
|
1001 | ERROR2: |
|
|
1002 | free(result); |
|
|
1003 | ERROR1: |
|
|
1004 | return NULL; |
|
|
1005 | } |
|
|
1006 | |
|
|
1007 | psiconv_word_status_section psiconv_empty_word_status_section(void) |
|
|
1008 | { |
|
|
1009 | psiconv_word_status_section result; |
|
|
1010 | if (!(result = malloc(sizeof(*result)))) |
|
|
1011 | return NULL; |
|
|
1012 | result->show_tabs = result->show_spaces = result->show_paragraph_ends = |
|
|
1013 | result->show_hard_minus = result->show_hard_space = |
|
|
1014 | result->fit_lines_to_screen = psiconv_bool_false; |
|
|
1015 | result->show_full_pictures = result->show_full_graphs = |
|
|
1016 | result->show_top_toolbar = result->show_side_toolbar = |
|
|
1017 | psiconv_bool_true; |
|
|
1018 | result->cursor_position = 0; |
|
|
1019 | result->display_size = 1000; |
|
|
1020 | return result; |
|
|
1021 | } |
|
|
1022 | |
|
|
1023 | psiconv_word_f psiconv_empty_word_f(void) |
|
|
1024 | { |
|
|
1025 | psiconv_word_f result; |
|
|
1026 | if (!(result = malloc(sizeof(*result)))) |
|
|
1027 | goto ERROR1; |
|
|
1028 | if (!(result->page_sec = psiconv_empty_page_layout_section())) |
|
|
1029 | goto ERROR2; |
|
|
1030 | if (!(result->paragraphs = psiconv_empty_text_and_layout())) |
|
|
1031 | goto ERROR3; |
|
|
1032 | if (!(result->status_sec = psiconv_empty_word_status_section())) |
|
|
1033 | goto ERROR4; |
|
|
1034 | if (!(result->styles_sec = psiconv_empty_word_styles_section())) |
|
|
1035 | goto ERROR5; |
|
|
1036 | return result; |
|
|
1037 | ERROR5: |
|
|
1038 | psiconv_free_word_status_section(result->status_sec); |
|
|
1039 | ERROR4: |
|
|
1040 | psiconv_free_text_and_layout(result->paragraphs); |
|
|
1041 | ERROR3: |
|
|
1042 | psiconv_free_page_layout_section(result->page_sec); |
|
|
1043 | ERROR2: |
|
|
1044 | free(result); |
|
|
1045 | ERROR1: |
|
|
1046 | return NULL; |
|
|
1047 | } |
|
|
1048 | |
|
|
1049 | psiconv_sheet_status_section psiconv_empty_sheet_status_section(void) |
|
|
1050 | { |
|
|
1051 | psiconv_sheet_status_section result; |
|
|
1052 | if (!(result = malloc(sizeof(*result)))) |
|
|
1053 | return NULL; |
|
|
1054 | result->show_horizontal_scrollbar = result->show_vertical_scrollbar = |
|
|
1055 | psiconv_triple_auto; |
|
|
1056 | result->show_graph = psiconv_bool_false; |
|
|
1057 | result->show_top_sheet_toolbar = result->show_side_sheet_toolbar = |
|
|
1058 | result->show_top_graph_toolbar = result->show_side_graph_toolbar = |
|
|
1059 | psiconv_bool_true; |
|
|
1060 | result->cursor_row = result->cursor_column = 0; |
|
|
1061 | result->sheet_display_size = result->graph_display_size = 1000; |
|
|
1062 | return result; |
|
|
1063 | } |
|
|
1064 | |
|
|
1065 | psiconv_formula_list psiconv_empty_formula_list(void) |
|
|
1066 | { |
|
|
1067 | return psiconv_list_new(sizeof(struct psiconv_formula_s)); |
|
|
1068 | } |
|
|
1069 | |
|
|
1070 | psiconv_sheet_workbook_section psiconv_empty_sheet_workbook_section(void) |
|
|
1071 | { |
|
|
1072 | psiconv_sheet_workbook_section result; |
|
|
1073 | if (!(result = malloc(sizeof(*result)))) |
|
|
1074 | goto ERROR1; |
|
|
1075 | if (!(result->formulas = psiconv_empty_formula_list())) |
|
|
1076 | goto ERROR2; |
|
|
1077 | return result; |
|
|
1078 | ERROR2: |
|
|
1079 | free(result); |
|
|
1080 | ERROR1: |
|
|
1081 | return NULL; |
|
|
1082 | } |
|
|
1083 | |
|
|
1084 | |
|
|
1085 | psiconv_sheet_f psiconv_empty_sheet_f(void) |
|
|
1086 | { |
|
|
1087 | psiconv_sheet_f result; |
|
|
1088 | if (!(result = malloc(sizeof(*result)))) |
|
|
1089 | goto ERROR1; |
|
|
1090 | if (!(result->page_sec = psiconv_empty_page_layout_section())) |
|
|
1091 | goto ERROR2; |
|
|
1092 | if (!(result->status_sec = psiconv_empty_sheet_status_section())) |
|
|
1093 | goto ERROR3; |
|
|
1094 | if (!(result->workbook_sec = psiconv_empty_sheet_workbook_section())) |
|
|
1095 | goto ERROR4; |
|
|
1096 | return result; |
|
|
1097 | ERROR4: |
|
|
1098 | psiconv_free_sheet_status_section(result->status_sec); |
|
|
1099 | ERROR3: |
|
|
1100 | psiconv_free_page_layout_section(result->page_sec); |
|
|
1101 | ERROR2: |
|
|
1102 | free(result); |
|
|
1103 | ERROR1: |
|
|
1104 | return NULL; |
|
|
1105 | } |
|
|
1106 | |
|
|
1107 | psiconv_texted_f psiconv_empty_texted_f(void) |
|
|
1108 | { |
|
|
1109 | psiconv_texted_f result; |
|
|
1110 | if (!(result = malloc(sizeof(*result)))) |
|
|
1111 | goto ERROR1; |
|
|
1112 | if (!(result->page_sec = psiconv_empty_page_layout_section())) |
|
|
1113 | goto ERROR2; |
|
|
1114 | if (!(result->texted_sec = psiconv_empty_texted_section())) |
|
|
1115 | goto ERROR3; |
|
|
1116 | return result; |
|
|
1117 | ERROR3: |
|
|
1118 | psiconv_free_page_layout_section(result->page_sec); |
|
|
1119 | ERROR2: |
|
|
1120 | free(result); |
|
|
1121 | ERROR1: |
|
|
1122 | return NULL; |
|
|
1123 | } |
|
|
1124 | |
|
|
1125 | psiconv_paint_data_section psiconv_empty_paint_data_section(void) |
|
|
1126 | { |
|
|
1127 | psiconv_paint_data_section result; |
|
|
1128 | if (!(result = malloc(sizeof(*result)))) |
|
|
1129 | goto ERROR1; |
|
|
1130 | /* Is this correct? */ |
|
|
1131 | result->xsize = result->ysize = result->pic_xsize = result->pic_ysize = 0; |
|
|
1132 | /* Probably forbidden... */ |
|
|
1133 | if (!(result->red = malloc(0))) |
|
|
1134 | goto ERROR2; |
|
|
1135 | if (!(result->green = malloc(0))) |
|
|
1136 | goto ERROR3; |
|
|
1137 | if (!(result->blue = malloc(0))) |
|
|
1138 | goto ERROR4; |
|
|
1139 | return result; |
|
|
1140 | ERROR4: |
|
|
1141 | free(result->green); |
|
|
1142 | ERROR3: |
|
|
1143 | free(result->red); |
|
|
1144 | ERROR2: |
|
|
1145 | free(result); |
|
|
1146 | ERROR1: |
|
|
1147 | return NULL; |
|
|
1148 | } |
|
|
1149 | |
|
|
1150 | |
|
|
1151 | psiconv_pictures psiconv_empty_pictures(void) |
|
|
1152 | { |
|
|
1153 | psiconv_pictures result; |
|
|
1154 | psiconv_paint_data_section pds; |
|
|
1155 | if (!(result = psiconv_list_new(sizeof(struct psiconv_paint_data_section_s)))) |
|
|
1156 | goto ERROR1; |
|
|
1157 | if (!(pds = psiconv_empty_paint_data_section())) |
|
|
1158 | goto ERROR2; |
|
|
1159 | if (psiconv_list_add(result,pds)) |
|
|
1160 | goto ERROR3; |
|
|
1161 | free(pds); |
|
|
1162 | return result; |
|
|
1163 | ERROR3: |
|
|
1164 | psiconv_free_paint_data_section(pds); |
|
|
1165 | ERROR2: |
|
|
1166 | psiconv_list_free(result); |
|
|
1167 | ERROR1: |
|
|
1168 | return NULL; |
|
|
1169 | } |
|
|
1170 | |
|
|
1171 | psiconv_mbm_f psiconv_empty_mbm_f(void) |
|
|
1172 | { |
|
|
1173 | psiconv_mbm_f result; |
|
|
1174 | if (!(result = malloc(sizeof(*result)))) |
|
|
1175 | goto ERROR1; |
|
|
1176 | if (!(result->sections = psiconv_empty_pictures())) |
|
|
1177 | goto ERROR2; |
|
|
1178 | return result; |
|
|
1179 | ERROR2: |
|
|
1180 | free(result); |
|
|
1181 | ERROR1: |
|
|
1182 | return NULL; |
|
|
1183 | } |
|
|
1184 | |
|
|
1185 | psiconv_sketch_section psiconv_empty_sketch_section(void) |
|
|
1186 | { |
|
|
1187 | psiconv_sketch_section result; |
|
|
1188 | if (!(result = malloc(sizeof(*result)))) |
|
|
1189 | goto ERROR1; |
|
|
1190 | result->form_xsize = 320; |
|
|
1191 | result->form_ysize = 200; |
|
|
1192 | result->picture_x_offset = result->picture_y_offset = result->picture_xsize = |
|
|
1193 | result->picture_ysize = 0; |
|
|
1194 | result->magnification_x = result->magnification_y = 1.0; |
|
|
1195 | result->cut_left = result->cut_right = result->cut_top = |
|
|
1196 | result->cut_bottom = 0.0; |
|
|
1197 | if (!(result->picture = psiconv_empty_paint_data_section())) |
|
|
1198 | goto ERROR2; |
|
|
1199 | return result; |
|
|
1200 | ERROR2: |
|
|
1201 | free(result); |
|
|
1202 | ERROR1: |
|
|
1203 | return NULL; |
|
|
1204 | } |
|
|
1205 | |
|
|
1206 | psiconv_sketch_f psiconv_empty_sketch_f(void) |
|
|
1207 | { |
|
|
1208 | psiconv_sketch_f result; |
|
|
1209 | if (!(result = malloc(sizeof(*result)))) |
|
|
1210 | goto ERROR1; |
|
|
1211 | if (!(result->sketch_sec = psiconv_empty_sketch_section())) |
|
|
1212 | goto ERROR2; |
|
|
1213 | return result; |
|
|
1214 | ERROR2: |
|
|
1215 | free(result); |
|
|
1216 | ERROR1: |
|
|
1217 | return NULL; |
|
|
1218 | } |
|
|
1219 | |
|
|
1220 | psiconv_cliparts psiconv_empty_cliparts(void) |
|
|
1221 | { |
|
|
1222 | /* Is this correct? */ |
|
|
1223 | return psiconv_list_new(sizeof(struct psiconv_clipart_section_s)); |
|
|
1224 | } |
|
|
1225 | |
|
|
1226 | psiconv_clipart_f psiconv_empty_clipart_f(void) |
|
|
1227 | { |
|
|
1228 | psiconv_clipart_f result; |
|
|
1229 | if (!(result = malloc(sizeof(*result)))) |
|
|
1230 | goto ERROR1; |
|
|
1231 | if (!(result->sections = psiconv_empty_cliparts())) |
|
|
1232 | goto ERROR2; |
|
|
1233 | return result; |
|
|
1234 | ERROR2: |
|
|
1235 | free(result); |
|
|
1236 | ERROR1: |
|
|
1237 | return NULL; |
|
|
1238 | } |
|
|
1239 | |
|
|
1240 | psiconv_file psiconv_empty_file(psiconv_file_type_t type) |
|
|
1241 | { |
|
|
1242 | psiconv_file result; |
|
|
1243 | if (!(result = malloc(sizeof(*result)))) |
|
|
1244 | return NULL; |
|
|
1245 | result->type = type; |
|
|
1246 | if (type == psiconv_word_file) { |
|
|
1247 | if (!(result->file = psiconv_empty_word_f())) |
|
|
1248 | goto ERROR; |
|
|
1249 | } else if (type == psiconv_sheet_file) { |
|
|
1250 | if (!(result->file = psiconv_empty_sheet_f())) |
|
|
1251 | goto ERROR; |
|
|
1252 | } else if (type == psiconv_texted_file) { |
|
|
1253 | if (!(result->file = psiconv_empty_texted_f())) |
|
|
1254 | goto ERROR; |
|
|
1255 | } else if (type == psiconv_mbm_file) { |
|
|
1256 | if (!(result->file = psiconv_empty_mbm_f())) |
|
|
1257 | goto ERROR; |
|
|
1258 | } else if (type == psiconv_sketch_file) { |
|
|
1259 | if (!(result->file = psiconv_empty_sketch_f())) |
|
|
1260 | goto ERROR; |
|
|
1261 | } else if (type == psiconv_clipart_file) { |
|
|
1262 | if (!(result->file = psiconv_empty_clipart_f())) |
|
|
1263 | goto ERROR; |
|
|
1264 | } else |
|
|
1265 | goto ERROR; |
|
|
1266 | return result; |
|
|
1267 | ERROR: |
|
|
1268 | free(result); |
|
|
1269 | return NULL; |
|
|
1270 | } |