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

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

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