… | |
… | |
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 | |
|
|
38 | static psiconv_word_styles_section psiconv_empty_word_styles_section(void); |
|
|
39 | static psiconv_text_and_layout psiconv_empty_text_and_layout(void); |
|
|
40 | static psiconv_texted_section psiconv_empty_texted_section(void); |
|
|
41 | static psiconv_page_header psiconv_empty_page_header(void); |
|
|
42 | static psiconv_page_layout_section psiconv_empty_page_layout_section(void); |
|
|
43 | static psiconv_word_status_section psiconv_empty_word_status_section(void); |
|
|
44 | static psiconv_word_f psiconv_empty_word_f(void); |
|
|
45 | static psiconv_texted_f psiconv_empty_texted_f(void); |
|
|
46 | static psiconv_paint_data_section psiconv_empty_paint_data_section(void); |
|
|
47 | static psiconv_pictures psiconv_empty_pictures(void); |
|
|
48 | static psiconv_mbm_f psiconv_empty_mbm_f(void); |
|
|
49 | static psiconv_sketch_section psiconv_empty_sketch_section(void); |
|
|
50 | static psiconv_sketch_f psiconv_empty_sketch_f(void); |
|
|
51 | static psiconv_clipart_f psiconv_empty_clipart_f(void); |
|
|
52 | static psiconv_cliparts psiconv_empty_cliparts(void); |
|
|
53 | |
36 | |
54 | |
37 | /* Note: these defaults seem to be hard-coded somewhere outside the |
55 | /* Note: these defaults seem to be hard-coded somewhere outside the |
38 | files themself. */ |
56 | files themself. */ |
39 | psiconv_character_layout psiconv_basic_character_layout(void) |
57 | psiconv_character_layout psiconv_basic_character_layout(void) |
40 | { |
58 | { |
… | |
… | |
758 | !psiconv_compare_font(value1->font,value2->font)) |
776 | !psiconv_compare_font(value1->font,value2->font)) |
759 | return 0; |
777 | return 0; |
760 | else |
778 | else |
761 | return 1; |
779 | return 1; |
762 | } |
780 | } |
|
|
781 | |
|
|
782 | |
|
|
783 | |
|
|
784 | psiconv_word_styles_section psiconv_empty_word_styles_section(void) |
|
|
785 | { |
|
|
786 | psiconv_word_styles_section result; |
|
|
787 | if (!(result = malloc(sizeof(*result)))) |
|
|
788 | goto ERROR1; |
|
|
789 | if (!(result->styles = psiconv_list_new(sizeof(struct psiconv_word_style_s)))) |
|
|
790 | goto ERROR2; |
|
|
791 | if (!(result->normal = malloc(sizeof(struct psiconv_word_style_s)))) |
|
|
792 | goto ERROR3; |
|
|
793 | if (!(result->normal->character = psiconv_basic_character_layout())) |
|
|
794 | goto ERROR4; |
|
|
795 | if (!(result->normal->paragraph = psiconv_basic_paragraph_layout())) |
|
|
796 | goto ERROR5; |
|
|
797 | result->normal->hotkey = 'N'; |
|
|
798 | result->normal->name = NULL; |
|
|
799 | result->normal->built_in = psiconv_bool_true; |
|
|
800 | result->normal->outline_level = 0; |
|
|
801 | return result; |
|
|
802 | ERROR5: |
|
|
803 | psiconv_free_character_layout(result->normal->character); |
|
|
804 | ERROR4: |
|
|
805 | free(result->normal); |
|
|
806 | ERROR3: |
|
|
807 | psiconv_list_free(result->styles); |
|
|
808 | ERROR2: |
|
|
809 | free(result); |
|
|
810 | ERROR1: |
|
|
811 | return NULL; |
|
|
812 | } |
|
|
813 | |
|
|
814 | psiconv_text_and_layout psiconv_empty_text_and_layout(void) |
|
|
815 | { |
|
|
816 | return psiconv_list_new(sizeof(struct psiconv_paragraph_s)); |
|
|
817 | } |
|
|
818 | |
|
|
819 | psiconv_texted_section psiconv_empty_texted_section(void) |
|
|
820 | { |
|
|
821 | psiconv_texted_section result; |
|
|
822 | if (!(result = malloc(sizeof(*result)))) |
|
|
823 | goto ERROR1; |
|
|
824 | if (!(result->paragraphs = psiconv_empty_text_and_layout())) |
|
|
825 | goto ERROR2; |
|
|
826 | return result; |
|
|
827 | ERROR2: |
|
|
828 | free(result); |
|
|
829 | ERROR1: |
|
|
830 | return NULL; |
|
|
831 | } |
|
|
832 | |
|
|
833 | psiconv_page_header psiconv_empty_page_header(void) |
|
|
834 | { |
|
|
835 | psiconv_page_header result; |
|
|
836 | if (!(result = malloc(sizeof(*result)))) |
|
|
837 | goto ERROR1; |
|
|
838 | result->on_first_page = psiconv_bool_true; |
|
|
839 | if (!(result->base_paragraph_layout = psiconv_basic_paragraph_layout())) |
|
|
840 | goto ERROR2; |
|
|
841 | if (!(result->base_character_layout = psiconv_basic_character_layout())) |
|
|
842 | goto ERROR3; |
|
|
843 | if (!(result->text = psiconv_empty_texted_section())) |
|
|
844 | goto ERROR4; |
|
|
845 | return result; |
|
|
846 | ERROR4: |
|
|
847 | psiconv_free_character_layout(result->base_character_layout); |
|
|
848 | ERROR3: |
|
|
849 | psiconv_free_paragraph_layout(result->base_paragraph_layout); |
|
|
850 | ERROR2: |
|
|
851 | free(result); |
|
|
852 | ERROR1: |
|
|
853 | return NULL; |
|
|
854 | } |
|
|
855 | |
|
|
856 | psiconv_page_layout_section psiconv_empty_page_layout_section(void) |
|
|
857 | { |
|
|
858 | psiconv_page_layout_section result; |
|
|
859 | if (!(result = malloc(sizeof(*result)))) |
|
|
860 | goto ERROR1; |
|
|
861 | result->first_page_nr = 1; |
|
|
862 | result->header_dist = result->footer_dist = 1.27; |
|
|
863 | result->left_margin = result->right_margin = 3.175; |
|
|
864 | result->top_margin = result->bottom_margin = 2.54; |
|
|
865 | result->page_width = 21.0; |
|
|
866 | result->page_height = 29.7; |
|
|
867 | result->landscape = psiconv_bool_false; |
|
|
868 | if (!(result->header = psiconv_empty_page_header())) |
|
|
869 | goto ERROR2; |
|
|
870 | if (!(result->footer = psiconv_empty_page_header())) |
|
|
871 | goto ERROR3; |
|
|
872 | return result; |
|
|
873 | ERROR3: |
|
|
874 | psiconv_free_page_header(result->header); |
|
|
875 | ERROR2: |
|
|
876 | free(result); |
|
|
877 | ERROR1: |
|
|
878 | return NULL; |
|
|
879 | } |
|
|
880 | |
|
|
881 | psiconv_word_status_section psiconv_empty_word_status_section(void) |
|
|
882 | { |
|
|
883 | psiconv_word_status_section result; |
|
|
884 | if (!(result = malloc(sizeof(*result)))) |
|
|
885 | return NULL; |
|
|
886 | result->show_tabs = result->show_spaces = result->show_paragraph_ends = |
|
|
887 | result->show_hard_minus = result->show_hard_space = |
|
|
888 | result->fit_lines_to_screen = psiconv_bool_false; |
|
|
889 | result->show_full_pictures = result->show_full_graphs = |
|
|
890 | result->show_top_toolbar = result->show_side_toolbar = |
|
|
891 | psiconv_bool_true; |
|
|
892 | result->cursor_position = 0; |
|
|
893 | result->display_size = 1000; |
|
|
894 | return result; |
|
|
895 | } |
|
|
896 | |
|
|
897 | psiconv_word_f psiconv_empty_word_f(void) |
|
|
898 | { |
|
|
899 | psiconv_word_f result; |
|
|
900 | if (!(result = malloc(sizeof(*result)))) |
|
|
901 | goto ERROR1; |
|
|
902 | if (!(result->page_sec = psiconv_empty_page_layout_section())) |
|
|
903 | goto ERROR2; |
|
|
904 | if (!(result->paragraphs = psiconv_empty_text_and_layout())) |
|
|
905 | goto ERROR3; |
|
|
906 | if (!(result->status_sec = psiconv_empty_word_status_section())) |
|
|
907 | goto ERROR4; |
|
|
908 | if (!(result->styles_sec = psiconv_empty_word_styles_section())) |
|
|
909 | goto ERROR5; |
|
|
910 | return result; |
|
|
911 | ERROR5: |
|
|
912 | psiconv_free_word_status_section(result->status_sec); |
|
|
913 | ERROR4: |
|
|
914 | psiconv_free_text_and_layout(result->paragraphs); |
|
|
915 | ERROR3: |
|
|
916 | psiconv_free_page_layout_section(result->page_sec); |
|
|
917 | ERROR2: |
|
|
918 | free(result); |
|
|
919 | ERROR1: |
|
|
920 | return NULL; |
|
|
921 | } |
|
|
922 | |
|
|
923 | psiconv_texted_f psiconv_empty_texted_f(void) |
|
|
924 | { |
|
|
925 | psiconv_texted_f result; |
|
|
926 | if (!(result = malloc(sizeof(*result)))) |
|
|
927 | goto ERROR1; |
|
|
928 | if (!(result->page_sec = psiconv_empty_page_layout_section())) |
|
|
929 | goto ERROR2; |
|
|
930 | if (!(result->texted_sec = psiconv_empty_texted_section())) |
|
|
931 | goto ERROR3; |
|
|
932 | return result; |
|
|
933 | ERROR3: |
|
|
934 | psiconv_free_page_layout_section(result->page_sec); |
|
|
935 | ERROR2: |
|
|
936 | free(result); |
|
|
937 | ERROR1: |
|
|
938 | return NULL; |
|
|
939 | } |
|
|
940 | |
|
|
941 | psiconv_paint_data_section psiconv_empty_paint_data_section(void) |
|
|
942 | { |
|
|
943 | psiconv_paint_data_section result; |
|
|
944 | if (!(result = malloc(sizeof(*result)))) |
|
|
945 | goto ERROR1; |
|
|
946 | /* Is this correct? */ |
|
|
947 | result->xsize = result->ysize = result->pic_xsize = result->pic_ysize = 0; |
|
|
948 | /* Probably forbidden... */ |
|
|
949 | if (!(result->red = malloc(0))) |
|
|
950 | goto ERROR2; |
|
|
951 | if (!(result->green = malloc(0))) |
|
|
952 | goto ERROR3; |
|
|
953 | if (!(result->blue = malloc(0))) |
|
|
954 | goto ERROR4; |
|
|
955 | return result; |
|
|
956 | ERROR4: |
|
|
957 | free(result->green); |
|
|
958 | ERROR3: |
|
|
959 | free(result->red); |
|
|
960 | ERROR2: |
|
|
961 | free(result); |
|
|
962 | ERROR1: |
|
|
963 | return NULL; |
|
|
964 | } |
|
|
965 | |
|
|
966 | |
|
|
967 | psiconv_pictures psiconv_empty_pictures(void) |
|
|
968 | { |
|
|
969 | psiconv_pictures result; |
|
|
970 | psiconv_paint_data_section pds; |
|
|
971 | if (!(result = psiconv_list_new(sizeof(struct psiconv_paint_data_section_s)))) |
|
|
972 | goto ERROR1; |
|
|
973 | if (!(pds = psiconv_empty_paint_data_section())) |
|
|
974 | goto ERROR2; |
|
|
975 | if (psiconv_list_add(result,pds)) |
|
|
976 | goto ERROR3; |
|
|
977 | free(pds); |
|
|
978 | return result; |
|
|
979 | ERROR3: |
|
|
980 | psiconv_free_paint_data_section(pds); |
|
|
981 | ERROR2: |
|
|
982 | psiconv_list_free(result); |
|
|
983 | ERROR1: |
|
|
984 | return NULL; |
|
|
985 | } |
|
|
986 | |
|
|
987 | psiconv_mbm_f psiconv_empty_mbm_f(void) |
|
|
988 | { |
|
|
989 | psiconv_mbm_f result; |
|
|
990 | if (!(result = malloc(sizeof(*result)))) |
|
|
991 | goto ERROR1; |
|
|
992 | if (!(result->sections = psiconv_empty_pictures())) |
|
|
993 | goto ERROR2; |
|
|
994 | return result; |
|
|
995 | ERROR2: |
|
|
996 | free(result); |
|
|
997 | ERROR1: |
|
|
998 | return NULL; |
|
|
999 | } |
|
|
1000 | |
|
|
1001 | psiconv_sketch_section psiconv_empty_sketch_section(void) |
|
|
1002 | { |
|
|
1003 | psiconv_sketch_section result; |
|
|
1004 | if (!(result = malloc(sizeof(*result)))) |
|
|
1005 | goto ERROR1; |
|
|
1006 | result->form_xsize = 320; |
|
|
1007 | result->form_ysize = 200; |
|
|
1008 | result->picture_x_offset = result->picture_y_offset = result->picture_xsize = |
|
|
1009 | result->picture_ysize = 0; |
|
|
1010 | result->magnification_x = result->magnification_y = 1.0; |
|
|
1011 | result->cut_left = result->cut_right = result->cut_top = |
|
|
1012 | result->cut_bottom = 0.0; |
|
|
1013 | if (!(result->picture = psiconv_empty_paint_data_section())) |
|
|
1014 | goto ERROR2; |
|
|
1015 | return result; |
|
|
1016 | ERROR2: |
|
|
1017 | free(result); |
|
|
1018 | ERROR1: |
|
|
1019 | return NULL; |
|
|
1020 | } |
|
|
1021 | |
|
|
1022 | psiconv_sketch_f psiconv_empty_sketch_f(void) |
|
|
1023 | { |
|
|
1024 | psiconv_sketch_f result; |
|
|
1025 | if (!(result = malloc(sizeof(*result)))) |
|
|
1026 | goto ERROR1; |
|
|
1027 | if (!(result->sketch_sec = psiconv_empty_sketch_section())) |
|
|
1028 | goto ERROR2; |
|
|
1029 | return result; |
|
|
1030 | ERROR2: |
|
|
1031 | free(result); |
|
|
1032 | ERROR1: |
|
|
1033 | return NULL; |
|
|
1034 | } |
|
|
1035 | |
|
|
1036 | psiconv_cliparts psiconv_empty_cliparts(void) |
|
|
1037 | { |
|
|
1038 | /* Is this correct? */ |
|
|
1039 | return psiconv_list_new(sizeof(struct psiconv_clipart_section_s)); |
|
|
1040 | } |
|
|
1041 | |
|
|
1042 | psiconv_clipart_f psiconv_empty_clipart_f(void) |
|
|
1043 | { |
|
|
1044 | psiconv_clipart_f result; |
|
|
1045 | if (!(result = malloc(sizeof(*result)))) |
|
|
1046 | goto ERROR1; |
|
|
1047 | if (!(result->sections = psiconv_empty_cliparts())) |
|
|
1048 | goto ERROR2; |
|
|
1049 | return result; |
|
|
1050 | ERROR2: |
|
|
1051 | free(result); |
|
|
1052 | ERROR1: |
|
|
1053 | return NULL; |
|
|
1054 | } |
|
|
1055 | |
|
|
1056 | psiconv_file psiconv_empty_file(psiconv_file_type_t type) |
|
|
1057 | { |
|
|
1058 | psiconv_file result; |
|
|
1059 | if (!(result = malloc(sizeof(*result)))) |
|
|
1060 | return NULL; |
|
|
1061 | result->type = type; |
|
|
1062 | if (type == psiconv_word_file) { |
|
|
1063 | if (!(result->file = psiconv_empty_word_f())) |
|
|
1064 | goto ERROR; |
|
|
1065 | } else if (type == psiconv_texted_file) { |
|
|
1066 | if (!(result->file = psiconv_empty_texted_f())) |
|
|
1067 | goto ERROR; |
|
|
1068 | } else if (type == psiconv_mbm_file) { |
|
|
1069 | if (!(result->file = psiconv_empty_mbm_f())) |
|
|
1070 | goto ERROR; |
|
|
1071 | } else if (type == psiconv_sketch_file) { |
|
|
1072 | if (!(result->file = psiconv_empty_sketch_f())) |
|
|
1073 | goto ERROR; |
|
|
1074 | } else if (type == psiconv_clipart_file) { |
|
|
1075 | if (!(result->file = psiconv_empty_clipart_f())) |
|
|
1076 | goto ERROR; |
|
|
1077 | } else |
|
|
1078 | goto ERROR; |
|
|
1079 | return result; |
|
|
1080 | ERROR: |
|
|
1081 | free(result); |
|
|
1082 | return NULL; |
|
|
1083 | } |