/[public]/psiconv/trunk/lib/psiconv/data.c
ViewVC logotype

Diff of /psiconv/trunk/lib/psiconv/data.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 78 Revision 97
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
26static psiconv_color clone_color(psiconv_color color); 27static psiconv_color clone_color(psiconv_color color);
27static psiconv_font clone_font(psiconv_font font); 28static psiconv_font clone_font(psiconv_font font);
28static psiconv_border clone_border(psiconv_border border); 29static psiconv_border clone_border(psiconv_border border);
29static psiconv_bullet clone_bullet(psiconv_bullet bullet); 30static psiconv_bullet clone_bullet(psiconv_bullet bullet);
31static void psiconv_free_style_aux(void *style); 32static void psiconv_free_style_aux(void *style);
32static void psiconv_free_in_line_layout_aux(void * layout); 33static void psiconv_free_in_line_layout_aux(void * layout);
33static void psiconv_free_paragraph_aux(void * paragraph); 34static void psiconv_free_paragraph_aux(void * paragraph);
34static void psiconv_free_paint_data_section_aux(void * section); 35static void psiconv_free_paint_data_section_aux(void * section);
35static void psiconv_free_clipart_section_aux(void * section); 36static void psiconv_free_clipart_section_aux(void * section);
37
38static psiconv_word_styles_section psiconv_empty_word_styles_section(void);
39static psiconv_text_and_layout psiconv_empty_text_and_layout(void);
40static psiconv_texted_section psiconv_empty_texted_section(void);
41static psiconv_page_header psiconv_empty_page_header(void);
42static psiconv_page_layout_section psiconv_empty_page_layout_section(void);
43static psiconv_word_status_section psiconv_empty_word_status_section(void);
44static psiconv_word_f psiconv_empty_word_f(void);
45static psiconv_sheet_status_section psiconv_empty_sheet_status_section(void);
46static psiconv_sheet_formula_list psiconv_empty_sheet_formula_list(void);
47static psiconv_sheet_workbook_section
48 psiconv_empty_sheet_workbook_section(void);
49static psiconv_sheet_f psiconv_empty_sheet_f(void);
50static psiconv_texted_f psiconv_empty_texted_f(void);
51static psiconv_paint_data_section psiconv_empty_paint_data_section(void);
52static psiconv_pictures psiconv_empty_pictures(void);
53static psiconv_mbm_f psiconv_empty_mbm_f(void);
54static psiconv_sketch_section psiconv_empty_sketch_section(void);
55static psiconv_sketch_f psiconv_empty_sketch_f(void);
56static psiconv_clipart_f psiconv_empty_clipart_f(void);
57static psiconv_cliparts psiconv_empty_cliparts(void);
58
36 59
37/* Note: these defaults seem to be hard-coded somewhere outside the 60/* Note: these defaults seem to be hard-coded somewhere outside the
38 files themself. */ 61 files themself. */
39psiconv_character_layout psiconv_basic_character_layout(void) 62psiconv_character_layout psiconv_basic_character_layout(void)
40{ 63{
516 psiconv_free_word_styles_section(file->styles_sec); 539 psiconv_free_word_styles_section(file->styles_sec);
517 free(file); 540 free(file);
518 } 541 }
519} 542}
520 543
544void psiconv_free_sheet_status_section(psiconv_sheet_status_section section)
545{
546 if (section)
547 free(section);
548}
549
550void psiconv_free_sheet_formula(psiconv_sheet_formula formula)
551{
552 if (formula)
553 free(formula);
554}
555
556void psiconv_free_sheet_formula_list(psiconv_sheet_formula_list list)
557{
558 if (list)
559 psiconv_list_free(list);
560}
561
562void psiconv_free_sheet_workbook_section(psiconv_sheet_workbook_section section)
563{
564 if (section) {
565 psiconv_free_sheet_formula_list(section->formulas);
566 free(section);
567 }
568}
569
570void psiconv_free_sheet_f(psiconv_sheet_f file)
571{
572 if (file) {
573 psiconv_free_page_layout_section(file->page_sec);
574 psiconv_free_sheet_status_section(file->status_sec);
575 psiconv_free_sheet_workbook_section(file->workbook_sec);
576 free(file);
577 }
578}
579
521void psiconv_free_texted_f(psiconv_texted_f file) 580void psiconv_free_texted_f(psiconv_texted_f file)
522{ 581{
523 if (file) { 582 if (file) {
524 psiconv_free_page_layout_section(file->page_sec); 583 psiconv_free_page_layout_section(file->page_sec);
525 psiconv_free_texted_section(file->texted_sec); 584 psiconv_free_texted_section(file->texted_sec);
620 psiconv_free_mbm_f((psiconv_mbm_f) file->file); 679 psiconv_free_mbm_f((psiconv_mbm_f) file->file);
621 else if (file->type == psiconv_sketch_file) 680 else if (file->type == psiconv_sketch_file)
622 psiconv_free_sketch_f((psiconv_sketch_f) file->file); 681 psiconv_free_sketch_f((psiconv_sketch_f) file->file);
623 else if (file->type == psiconv_clipart_file) 682 else if (file->type == psiconv_clipart_file)
624 psiconv_free_clipart_f((psiconv_clipart_f) file->file); 683 psiconv_free_clipart_f((psiconv_clipart_f) file->file);
684 else if (file->type == psiconv_sheet_file)
685 psiconv_free_sheet_f((psiconv_sheet_f) file->file);
625 free(file); 686 free(file);
626 } 687 }
627} 688}
628 689
629int psiconv_compare_color(const psiconv_color value1, 690int psiconv_compare_color(const psiconv_color value1,
758 !psiconv_compare_font(value1->font,value2->font)) 819 !psiconv_compare_font(value1->font,value2->font))
759 return 0; 820 return 0;
760 else 821 else
761 return 1; 822 return 1;
762} 823}
824
825
826
827psiconv_word_styles_section psiconv_empty_word_styles_section(void)
828{
829 psiconv_word_styles_section result;
830 if (!(result = malloc(sizeof(*result))))
831 goto ERROR1;
832 if (!(result->styles = psiconv_list_new(sizeof(struct psiconv_word_style_s))))
833 goto ERROR2;
834 if (!(result->normal = malloc(sizeof(struct psiconv_word_style_s))))
835 goto ERROR3;
836 if (!(result->normal->character = psiconv_basic_character_layout()))
837 goto ERROR4;
838 if (!(result->normal->paragraph = psiconv_basic_paragraph_layout()))
839 goto ERROR5;
840 result->normal->hotkey = 'N';
841 result->normal->name = NULL;
842 result->normal->built_in = psiconv_bool_true;
843 result->normal->outline_level = 0;
844 return result;
845ERROR5:
846 psiconv_free_character_layout(result->normal->character);
847ERROR4:
848 free(result->normal);
849ERROR3:
850 psiconv_list_free(result->styles);
851ERROR2:
852 free(result);
853ERROR1:
854 return NULL;
855}
856
857psiconv_text_and_layout psiconv_empty_text_and_layout(void)
858{
859 return psiconv_list_new(sizeof(struct psiconv_paragraph_s));
860}
861
862psiconv_texted_section psiconv_empty_texted_section(void)
863{
864 psiconv_texted_section result;
865 if (!(result = malloc(sizeof(*result))))
866 goto ERROR1;
867 if (!(result->paragraphs = psiconv_empty_text_and_layout()))
868 goto ERROR2;
869 return result;
870ERROR2:
871 free(result);
872ERROR1:
873 return NULL;
874}
875
876psiconv_page_header psiconv_empty_page_header(void)
877{
878 psiconv_page_header result;
879 if (!(result = malloc(sizeof(*result))))
880 goto ERROR1;
881 result->on_first_page = psiconv_bool_true;
882 if (!(result->base_paragraph_layout = psiconv_basic_paragraph_layout()))
883 goto ERROR2;
884 if (!(result->base_character_layout = psiconv_basic_character_layout()))
885 goto ERROR3;
886 if (!(result->text = psiconv_empty_texted_section()))
887 goto ERROR4;
888 return result;
889ERROR4:
890 psiconv_free_character_layout(result->base_character_layout);
891ERROR3:
892 psiconv_free_paragraph_layout(result->base_paragraph_layout);
893ERROR2:
894 free(result);
895ERROR1:
896 return NULL;
897}
898
899psiconv_page_layout_section psiconv_empty_page_layout_section(void)
900{
901 psiconv_page_layout_section result;
902 if (!(result = malloc(sizeof(*result))))
903 goto ERROR1;
904 result->first_page_nr = 1;
905 result->header_dist = result->footer_dist = 1.27;
906 result->left_margin = result->right_margin = 3.175;
907 result->top_margin = result->bottom_margin = 2.54;
908 result->page_width = 21.0;
909 result->page_height = 29.7;
910 result->landscape = psiconv_bool_false;
911 if (!(result->header = psiconv_empty_page_header()))
912 goto ERROR2;
913 if (!(result->footer = psiconv_empty_page_header()))
914 goto ERROR3;
915 return result;
916ERROR3:
917 psiconv_free_page_header(result->header);
918ERROR2:
919 free(result);
920ERROR1:
921 return NULL;
922}
923
924psiconv_word_status_section psiconv_empty_word_status_section(void)
925{
926 psiconv_word_status_section result;
927 if (!(result = malloc(sizeof(*result))))
928 return NULL;
929 result->show_tabs = result->show_spaces = result->show_paragraph_ends =
930 result->show_hard_minus = result->show_hard_space =
931 result->fit_lines_to_screen = psiconv_bool_false;
932 result->show_full_pictures = result->show_full_graphs =
933 result->show_top_toolbar = result->show_side_toolbar =
934 psiconv_bool_true;
935 result->cursor_position = 0;
936 result->display_size = 1000;
937 return result;
938}
939
940psiconv_word_f psiconv_empty_word_f(void)
941{
942 psiconv_word_f result;
943 if (!(result = malloc(sizeof(*result))))
944 goto ERROR1;
945 if (!(result->page_sec = psiconv_empty_page_layout_section()))
946 goto ERROR2;
947 if (!(result->paragraphs = psiconv_empty_text_and_layout()))
948 goto ERROR3;
949 if (!(result->status_sec = psiconv_empty_word_status_section()))
950 goto ERROR4;
951 if (!(result->styles_sec = psiconv_empty_word_styles_section()))
952 goto ERROR5;
953 return result;
954ERROR5:
955 psiconv_free_word_status_section(result->status_sec);
956ERROR4:
957 psiconv_free_text_and_layout(result->paragraphs);
958ERROR3:
959 psiconv_free_page_layout_section(result->page_sec);
960ERROR2:
961 free(result);
962ERROR1:
963 return NULL;
964}
965
966psiconv_sheet_status_section psiconv_empty_sheet_status_section(void)
967{
968 psiconv_sheet_status_section result;
969 if (!(result = malloc(sizeof(*result))))
970 return NULL;
971 result->show_horizontal_scrollbar = result->show_vertical_scrollbar =
972 psiconv_triple_auto;
973 result->show_graph = psiconv_bool_false;
974 result->show_top_sheet_toolbar = result->show_side_sheet_toolbar =
975 result->show_top_graph_toolbar = result->show_side_graph_toolbar =
976 psiconv_bool_true;
977 result->cursor_row = result->cursor_column = 0;
978 result->sheet_display_size = result->graph_display_size = 1000;
979 return result;
980}
981
982psiconv_sheet_formula_list psiconv_empty_sheet_formula_list(void)
983{
984 return psiconv_list_new(sizeof(struct psiconv_sheet_formula_s));
985}
986
987psiconv_sheet_workbook_section psiconv_empty_sheet_workbook_section(void)
988{
989 psiconv_sheet_workbook_section result;
990 if (!(result = malloc(sizeof(*result))))
991 goto ERROR1;
992 if (!(result->formulas = psiconv_empty_sheet_formula_list()))
993 goto ERROR2;
994 return result;
995ERROR2:
996 free(result);
997ERROR1:
998 return NULL;
999}
1000
1001
1002psiconv_sheet_f psiconv_empty_sheet_f(void)
1003{
1004 psiconv_sheet_f result;
1005 if (!(result = malloc(sizeof(*result))))
1006 goto ERROR1;
1007 if (!(result->page_sec = psiconv_empty_page_layout_section()))
1008 goto ERROR2;
1009 if (!(result->status_sec = psiconv_empty_sheet_status_section()))
1010 goto ERROR3;
1011 if (!(result->workbook_sec = psiconv_empty_sheet_workbook_section()))
1012 goto ERROR4;
1013 return result;
1014ERROR4:
1015 psiconv_free_sheet_status_section(result->status_sec);
1016ERROR3:
1017 psiconv_free_page_layout_section(result->page_sec);
1018ERROR2:
1019 free(result);
1020ERROR1:
1021 return NULL;
1022}
1023
1024psiconv_texted_f psiconv_empty_texted_f(void)
1025{
1026 psiconv_texted_f result;
1027 if (!(result = malloc(sizeof(*result))))
1028 goto ERROR1;
1029 if (!(result->page_sec = psiconv_empty_page_layout_section()))
1030 goto ERROR2;
1031 if (!(result->texted_sec = psiconv_empty_texted_section()))
1032 goto ERROR3;
1033 return result;
1034ERROR3:
1035 psiconv_free_page_layout_section(result->page_sec);
1036ERROR2:
1037 free(result);
1038ERROR1:
1039 return NULL;
1040}
1041
1042psiconv_paint_data_section psiconv_empty_paint_data_section(void)
1043{
1044 psiconv_paint_data_section result;
1045 if (!(result = malloc(sizeof(*result))))
1046 goto ERROR1;
1047 /* Is this correct? */
1048 result->xsize = result->ysize = result->pic_xsize = result->pic_ysize = 0;
1049 /* Probably forbidden... */
1050 if (!(result->red = malloc(0)))
1051 goto ERROR2;
1052 if (!(result->green = malloc(0)))
1053 goto ERROR3;
1054 if (!(result->blue = malloc(0)))
1055 goto ERROR4;
1056 return result;
1057ERROR4:
1058 free(result->green);
1059ERROR3:
1060 free(result->red);
1061ERROR2:
1062 free(result);
1063ERROR1:
1064 return NULL;
1065}
1066
1067
1068psiconv_pictures psiconv_empty_pictures(void)
1069{
1070 psiconv_pictures result;
1071 psiconv_paint_data_section pds;
1072 if (!(result = psiconv_list_new(sizeof(struct psiconv_paint_data_section_s))))
1073 goto ERROR1;
1074 if (!(pds = psiconv_empty_paint_data_section()))
1075 goto ERROR2;
1076 if (psiconv_list_add(result,pds))
1077 goto ERROR3;
1078 free(pds);
1079 return result;
1080ERROR3:
1081 psiconv_free_paint_data_section(pds);
1082ERROR2:
1083 psiconv_list_free(result);
1084ERROR1:
1085 return NULL;
1086}
1087
1088psiconv_mbm_f psiconv_empty_mbm_f(void)
1089{
1090 psiconv_mbm_f result;
1091 if (!(result = malloc(sizeof(*result))))
1092 goto ERROR1;
1093 if (!(result->sections = psiconv_empty_pictures()))
1094 goto ERROR2;
1095 return result;
1096ERROR2:
1097 free(result);
1098ERROR1:
1099 return NULL;
1100}
1101
1102psiconv_sketch_section psiconv_empty_sketch_section(void)
1103{
1104 psiconv_sketch_section result;
1105 if (!(result = malloc(sizeof(*result))))
1106 goto ERROR1;
1107 result->form_xsize = 320;
1108 result->form_ysize = 200;
1109 result->picture_x_offset = result->picture_y_offset = result->picture_xsize =
1110 result->picture_ysize = 0;
1111 result->magnification_x = result->magnification_y = 1.0;
1112 result->cut_left = result->cut_right = result->cut_top =
1113 result->cut_bottom = 0.0;
1114 if (!(result->picture = psiconv_empty_paint_data_section()))
1115 goto ERROR2;
1116 return result;
1117ERROR2:
1118 free(result);
1119ERROR1:
1120 return NULL;
1121}
1122
1123psiconv_sketch_f psiconv_empty_sketch_f(void)
1124{
1125 psiconv_sketch_f result;
1126 if (!(result = malloc(sizeof(*result))))
1127 goto ERROR1;
1128 if (!(result->sketch_sec = psiconv_empty_sketch_section()))
1129 goto ERROR2;
1130 return result;
1131ERROR2:
1132 free(result);
1133ERROR1:
1134 return NULL;
1135}
1136
1137psiconv_cliparts psiconv_empty_cliparts(void)
1138{
1139 /* Is this correct? */
1140 return psiconv_list_new(sizeof(struct psiconv_clipart_section_s));
1141}
1142
1143psiconv_clipart_f psiconv_empty_clipart_f(void)
1144{
1145 psiconv_clipart_f result;
1146 if (!(result = malloc(sizeof(*result))))
1147 goto ERROR1;
1148 if (!(result->sections = psiconv_empty_cliparts()))
1149 goto ERROR2;
1150 return result;
1151ERROR2:
1152 free(result);
1153ERROR1:
1154 return NULL;
1155}
1156
1157psiconv_file psiconv_empty_file(psiconv_file_type_t type)
1158{
1159 psiconv_file result;
1160 if (!(result = malloc(sizeof(*result))))
1161 return NULL;
1162 result->type = type;
1163 if (type == psiconv_word_file) {
1164 if (!(result->file = psiconv_empty_word_f()))
1165 goto ERROR;
1166 } else if (type == psiconv_sheet_file) {
1167 if (!(result->file = psiconv_empty_sheet_f()))
1168 goto ERROR;
1169 } else if (type == psiconv_texted_file) {
1170 if (!(result->file = psiconv_empty_texted_f()))
1171 goto ERROR;
1172 } else if (type == psiconv_mbm_file) {
1173 if (!(result->file = psiconv_empty_mbm_f()))
1174 goto ERROR;
1175 } else if (type == psiconv_sketch_file) {
1176 if (!(result->file = psiconv_empty_sketch_f()))
1177 goto ERROR;
1178 } else if (type == psiconv_clipart_file) {
1179 if (!(result->file = psiconv_empty_clipart_f()))
1180 goto ERROR;
1181 } else
1182 goto ERROR;
1183 return result;
1184ERROR:
1185 free(result);
1186 return NULL;
1187}

Legend:
Removed from v.78  
changed lines
  Added in v.97

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