/[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 125
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);
38static void psiconv_free_sheet_worksheet_aux (void *data);
39
40static psiconv_word_styles_section psiconv_empty_word_styles_section(void);
41static psiconv_text_and_layout psiconv_empty_text_and_layout(void);
42static psiconv_texted_section psiconv_empty_texted_section(void);
43static psiconv_page_header psiconv_empty_page_header(void);
44static psiconv_page_layout_section psiconv_empty_page_layout_section(void);
45static psiconv_word_status_section psiconv_empty_word_status_section(void);
46static psiconv_word_f psiconv_empty_word_f(void);
47static psiconv_sheet_status_section psiconv_empty_sheet_status_section(void);
48static psiconv_formula_list psiconv_empty_formula_list(void);
49static psiconv_sheet_workbook_section
50 psiconv_empty_sheet_workbook_section(void);
51static psiconv_sheet_f psiconv_empty_sheet_f(void);
52static psiconv_texted_f psiconv_empty_texted_f(void);
53static psiconv_paint_data_section psiconv_empty_paint_data_section(void);
54static psiconv_pictures psiconv_empty_pictures(void);
55static psiconv_mbm_f psiconv_empty_mbm_f(void);
56static psiconv_sketch_section psiconv_empty_sketch_section(void);
57static psiconv_sketch_f psiconv_empty_sketch_f(void);
58static psiconv_clipart_f psiconv_empty_clipart_f(void);
59static psiconv_cliparts psiconv_empty_cliparts(void);
60
36 61
37/* Note: these defaults seem to be hard-coded somewhere outside the 62/* Note: these defaults seem to be hard-coded somewhere outside the
38 files themself. */ 63 files themself. */
39psiconv_character_layout psiconv_basic_character_layout(void) 64psiconv_character_layout psiconv_basic_character_layout(void)
40{ 65{
127 0.0, /* space_below */ 152 0.0, /* space_below */
128 psiconv_bool_false, /* keep_together */ 153 psiconv_bool_false, /* keep_together */
129 psiconv_bool_false, /* keep_with_next */ 154 psiconv_bool_false, /* keep_with_next */
130 psiconv_bool_false, /* on_next_page */ 155 psiconv_bool_false, /* on_next_page */
131 psiconv_bool_false, /* no_widow_protection */ 156 psiconv_bool_false, /* no_widow_protection */
157 psiconv_bool_false, /* wrap_to_fit_cell */
132 0.0, /* left_margin */ 158 0.0, /* left_margin */
133 &bullet, /* bullet */ 159 &bullet, /* bullet */
134 &no_border, /* left_border */ 160 &no_border, /* left_border */
135 &no_border, /* right_border */ 161 &no_border, /* right_border */
136 &no_border, /* top_border */ 162 &no_border, /* top_border */
291 return ss->normal; 317 return ss->normal;
292 else 318 else
293 return psiconv_list_get(ss->styles,0xff - nr); 319 return psiconv_list_get(ss->styles,0xff - nr);
294} 320}
295 321
322psiconv_formula psiconv_get_formula (psiconv_formula_list ss, int nr)
323{
324 return psiconv_list_get(ss,psiconv_list_length(ss)-nr-1);
325}
326
327
296void psiconv_free_color (psiconv_color color) 328void psiconv_free_color (psiconv_color color)
297{ 329{
298 if (color) 330 if (color)
299 free(color); 331 free(color);
300} 332}
512 if (file) { 544 if (file) {
513 psiconv_free_page_layout_section(file->page_sec); 545 psiconv_free_page_layout_section(file->page_sec);
514 psiconv_free_text_and_layout(file->paragraphs); 546 psiconv_free_text_and_layout(file->paragraphs);
515 psiconv_free_word_status_section(file->status_sec); 547 psiconv_free_word_status_section(file->status_sec);
516 psiconv_free_word_styles_section(file->styles_sec); 548 psiconv_free_word_styles_section(file->styles_sec);
549 free(file);
550 }
551}
552
553void psiconv_free_sheet_status_section(psiconv_sheet_status_section section)
554{
555 if (section)
556 free(section);
557}
558
559void psiconv_free_sheet_numberformat(psiconv_sheet_numberformat numberformat)
560{
561 if (numberformat)
562 free(numberformat);
563}
564
565void psiconv_free_sheet_cell_layout(psiconv_sheet_cell_layout layout)
566{
567 psiconv_free_paragraph_layout(layout->paragraph);
568 psiconv_free_character_layout(layout->character);
569 psiconv_free_sheet_numberformat(layout->numberformat);
570}
571
572void psiconv_free_sheet_cell_aux(void *cell)
573{
574 psiconv_sheet_cell data = cell;
575
576 psiconv_free_sheet_cell_layout(data->layout);
577
578 if ((data->type == psiconv_cell_string) && (data->data.dat_string))
579 free(data->data.dat_string);
580}
581
582void psiconv_free_sheet_cell(psiconv_sheet_cell cell)
583{
584 if (cell) {
585 psiconv_free_sheet_cell_aux(cell);
586 free(cell);
587 }
588}
589
590void psiconv_free_sheet_cell_list(psiconv_sheet_cell_list list)
591{
592 if (list)
593 psiconv_list_free_el(list,psiconv_free_sheet_cell_aux);
594}
595
596void psiconv_free_sheet_worksheet_aux (void *data)
597{
598 psiconv_sheet_worksheet section = data;
599 psiconv_free_sheet_cell_layout(section->default_layout);
600 psiconv_free_sheet_cell_list(section->cells);
601}
602
603void psiconv_free_sheet_worksheet(psiconv_sheet_worksheet sheet)
604{
605 if (sheet) {
606 psiconv_free_sheet_worksheet_aux(sheet);
607 free(sheet);
608 }
609}
610
611void psiconv_free_sheet_worksheet_list(psiconv_sheet_worksheet_list list)
612{
613 if (list)
614 psiconv_list_free_el(list,psiconv_free_sheet_worksheet_aux);
615}
616
617void psiconv_free_formula_aux(void *data)
618{
619 psiconv_formula formula;
620 formula = data;
621 if (formula->type == psiconv_formula_dat_string)
622 free(formula->data.dat_string);
623 else if ((formula->type != psiconv_formula_dat_int) &&
624 (formula->type != psiconv_formula_dat_var) &&
625 (formula->type != psiconv_formula_dat_float) &&
626 (formula->type != psiconv_formula_dat_cellref) &&
627 (formula->type != psiconv_formula_dat_cellblock) &&
628 (formula->type != psiconv_formula_dat_vcellblock) &&
629 (formula->type != psiconv_formula_mark_opsep) &&
630 (formula->type != psiconv_formula_mark_opend) &&
631 (formula->type != psiconv_formula_mark_eof) &&
632 (formula->type != psiconv_formula_unknown))
633 psiconv_free_formula_list(formula->data.fun_operands);
634}
635
636void psiconv_free_formula(psiconv_formula formula)
637{
638 if (formula) {
639 psiconv_free_formula_aux(formula);
640 free(formula);
641 }
642}
643
644void psiconv_free_formula_list(psiconv_formula_list list)
645{
646 if (list)
647 psiconv_list_free_el(list,psiconv_free_formula_aux);
648}
649
650void psiconv_free_sheet_workbook_section(psiconv_sheet_workbook_section section)
651{
652 if (section) {
653 psiconv_free_formula_list(section->formulas);
654 psiconv_free_sheet_worksheet_list(section->worksheets);
655 free(section);
656 }
657}
658
659void psiconv_free_sheet_f(psiconv_sheet_f file)
660{
661 if (file) {
662 psiconv_free_page_layout_section(file->page_sec);
663 psiconv_free_sheet_status_section(file->status_sec);
664 psiconv_free_sheet_workbook_section(file->workbook_sec);
517 free(file); 665 free(file);
518 } 666 }
519} 667}
520 668
521void psiconv_free_texted_f(psiconv_texted_f file) 669void psiconv_free_texted_f(psiconv_texted_f file)
620 psiconv_free_mbm_f((psiconv_mbm_f) file->file); 768 psiconv_free_mbm_f((psiconv_mbm_f) file->file);
621 else if (file->type == psiconv_sketch_file) 769 else if (file->type == psiconv_sketch_file)
622 psiconv_free_sketch_f((psiconv_sketch_f) file->file); 770 psiconv_free_sketch_f((psiconv_sketch_f) file->file);
623 else if (file->type == psiconv_clipart_file) 771 else if (file->type == psiconv_clipart_file)
624 psiconv_free_clipart_f((psiconv_clipart_f) file->file); 772 psiconv_free_clipart_f((psiconv_clipart_f) file->file);
773 else if (file->type == psiconv_sheet_file)
774 psiconv_free_sheet_f((psiconv_sheet_f) file->file);
625 free(file); 775 free(file);
626 } 776 }
627} 777}
628 778
629int psiconv_compare_color(const psiconv_color value1, 779int psiconv_compare_color(const psiconv_color value1,
758 !psiconv_compare_font(value1->font,value2->font)) 908 !psiconv_compare_font(value1->font,value2->font))
759 return 0; 909 return 0;
760 else 910 else
761 return 1; 911 return 1;
762} 912}
913
914
915
916psiconv_word_styles_section psiconv_empty_word_styles_section(void)
917{
918 psiconv_word_styles_section result;
919 if (!(result = malloc(sizeof(*result))))
920 goto ERROR1;
921 if (!(result->styles = psiconv_list_new(sizeof(struct psiconv_word_style_s))))
922 goto ERROR2;
923 if (!(result->normal = malloc(sizeof(struct psiconv_word_style_s))))
924 goto ERROR3;
925 if (!(result->normal->character = psiconv_basic_character_layout()))
926 goto ERROR4;
927 if (!(result->normal->paragraph = psiconv_basic_paragraph_layout()))
928 goto ERROR5;
929 result->normal->hotkey = 'N';
930 result->normal->name = NULL;
931 result->normal->built_in = psiconv_bool_true;
932 result->normal->outline_level = 0;
933 return result;
934ERROR5:
935 psiconv_free_character_layout(result->normal->character);
936ERROR4:
937 free(result->normal);
938ERROR3:
939 psiconv_list_free(result->styles);
940ERROR2:
941 free(result);
942ERROR1:
943 return NULL;
944}
945
946psiconv_text_and_layout psiconv_empty_text_and_layout(void)
947{
948 return psiconv_list_new(sizeof(struct psiconv_paragraph_s));
949}
950
951psiconv_texted_section psiconv_empty_texted_section(void)
952{
953 psiconv_texted_section result;
954 if (!(result = malloc(sizeof(*result))))
955 goto ERROR1;
956 if (!(result->paragraphs = psiconv_empty_text_and_layout()))
957 goto ERROR2;
958 return result;
959ERROR2:
960 free(result);
961ERROR1:
962 return NULL;
963}
964
965psiconv_page_header psiconv_empty_page_header(void)
966{
967 psiconv_page_header result;
968 if (!(result = malloc(sizeof(*result))))
969 goto ERROR1;
970 result->on_first_page = psiconv_bool_true;
971 if (!(result->base_paragraph_layout = psiconv_basic_paragraph_layout()))
972 goto ERROR2;
973 if (!(result->base_character_layout = psiconv_basic_character_layout()))
974 goto ERROR3;
975 if (!(result->text = psiconv_empty_texted_section()))
976 goto ERROR4;
977 return result;
978ERROR4:
979 psiconv_free_character_layout(result->base_character_layout);
980ERROR3:
981 psiconv_free_paragraph_layout(result->base_paragraph_layout);
982ERROR2:
983 free(result);
984ERROR1:
985 return NULL;
986}
987
988psiconv_page_layout_section psiconv_empty_page_layout_section(void)
989{
990 psiconv_page_layout_section result;
991 if (!(result = malloc(sizeof(*result))))
992 goto ERROR1;
993 result->first_page_nr = 1;
994 result->header_dist = result->footer_dist = 1.27;
995 result->left_margin = result->right_margin = 3.175;
996 result->top_margin = result->bottom_margin = 2.54;
997 result->page_width = 21.0;
998 result->page_height = 29.7;
999 result->landscape = psiconv_bool_false;
1000 if (!(result->header = psiconv_empty_page_header()))
1001 goto ERROR2;
1002 if (!(result->footer = psiconv_empty_page_header()))
1003 goto ERROR3;
1004 return result;
1005ERROR3:
1006 psiconv_free_page_header(result->header);
1007ERROR2:
1008 free(result);
1009ERROR1:
1010 return NULL;
1011}
1012
1013psiconv_word_status_section psiconv_empty_word_status_section(void)
1014{
1015 psiconv_word_status_section result;
1016 if (!(result = malloc(sizeof(*result))))
1017 return NULL;
1018 result->show_tabs = result->show_spaces = result->show_paragraph_ends =
1019 result->show_hard_minus = result->show_hard_space =
1020 result->fit_lines_to_screen = psiconv_bool_false;
1021 result->show_full_pictures = result->show_full_graphs =
1022 result->show_top_toolbar = result->show_side_toolbar =
1023 psiconv_bool_true;
1024 result->cursor_position = 0;
1025 result->display_size = 1000;
1026 return result;
1027}
1028
1029psiconv_word_f psiconv_empty_word_f(void)
1030{
1031 psiconv_word_f result;
1032 if (!(result = malloc(sizeof(*result))))
1033 goto ERROR1;
1034 if (!(result->page_sec = psiconv_empty_page_layout_section()))
1035 goto ERROR2;
1036 if (!(result->paragraphs = psiconv_empty_text_and_layout()))
1037 goto ERROR3;
1038 if (!(result->status_sec = psiconv_empty_word_status_section()))
1039 goto ERROR4;
1040 if (!(result->styles_sec = psiconv_empty_word_styles_section()))
1041 goto ERROR5;
1042 return result;
1043ERROR5:
1044 psiconv_free_word_status_section(result->status_sec);
1045ERROR4:
1046 psiconv_free_text_and_layout(result->paragraphs);
1047ERROR3:
1048 psiconv_free_page_layout_section(result->page_sec);
1049ERROR2:
1050 free(result);
1051ERROR1:
1052 return NULL;
1053}
1054
1055psiconv_sheet_status_section psiconv_empty_sheet_status_section(void)
1056{
1057 psiconv_sheet_status_section result;
1058 if (!(result = malloc(sizeof(*result))))
1059 return NULL;
1060 result->show_horizontal_scrollbar = result->show_vertical_scrollbar =
1061 psiconv_triple_auto;
1062 result->show_graph = psiconv_bool_false;
1063 result->show_top_sheet_toolbar = result->show_side_sheet_toolbar =
1064 result->show_top_graph_toolbar = result->show_side_graph_toolbar =
1065 psiconv_bool_true;
1066 result->cursor_row = result->cursor_column = 0;
1067 result->sheet_display_size = result->graph_display_size = 1000;
1068 return result;
1069}
1070
1071psiconv_formula_list psiconv_empty_formula_list(void)
1072{
1073 return psiconv_list_new(sizeof(struct psiconv_formula_s));
1074}
1075
1076psiconv_sheet_workbook_section psiconv_empty_sheet_workbook_section(void)
1077{
1078 psiconv_sheet_workbook_section result;
1079 if (!(result = malloc(sizeof(*result))))
1080 goto ERROR1;
1081 if (!(result->formulas = psiconv_empty_formula_list()))
1082 goto ERROR2;
1083 return result;
1084ERROR2:
1085 free(result);
1086ERROR1:
1087 return NULL;
1088}
1089
1090
1091psiconv_sheet_f psiconv_empty_sheet_f(void)
1092{
1093 psiconv_sheet_f result;
1094 if (!(result = malloc(sizeof(*result))))
1095 goto ERROR1;
1096 if (!(result->page_sec = psiconv_empty_page_layout_section()))
1097 goto ERROR2;
1098 if (!(result->status_sec = psiconv_empty_sheet_status_section()))
1099 goto ERROR3;
1100 if (!(result->workbook_sec = psiconv_empty_sheet_workbook_section()))
1101 goto ERROR4;
1102 return result;
1103ERROR4:
1104 psiconv_free_sheet_status_section(result->status_sec);
1105ERROR3:
1106 psiconv_free_page_layout_section(result->page_sec);
1107ERROR2:
1108 free(result);
1109ERROR1:
1110 return NULL;
1111}
1112
1113psiconv_texted_f psiconv_empty_texted_f(void)
1114{
1115 psiconv_texted_f result;
1116 if (!(result = malloc(sizeof(*result))))
1117 goto ERROR1;
1118 if (!(result->page_sec = psiconv_empty_page_layout_section()))
1119 goto ERROR2;
1120 if (!(result->texted_sec = psiconv_empty_texted_section()))
1121 goto ERROR3;
1122 return result;
1123ERROR3:
1124 psiconv_free_page_layout_section(result->page_sec);
1125ERROR2:
1126 free(result);
1127ERROR1:
1128 return NULL;
1129}
1130
1131psiconv_paint_data_section psiconv_empty_paint_data_section(void)
1132{
1133 psiconv_paint_data_section result;
1134 if (!(result = malloc(sizeof(*result))))
1135 goto ERROR1;
1136 /* Is this correct? */
1137 result->xsize = result->ysize = result->pic_xsize = result->pic_ysize = 0;
1138 /* Probably forbidden... */
1139 if (!(result->red = malloc(0)))
1140 goto ERROR2;
1141 if (!(result->green = malloc(0)))
1142 goto ERROR3;
1143 if (!(result->blue = malloc(0)))
1144 goto ERROR4;
1145 return result;
1146ERROR4:
1147 free(result->green);
1148ERROR3:
1149 free(result->red);
1150ERROR2:
1151 free(result);
1152ERROR1:
1153 return NULL;
1154}
1155
1156
1157psiconv_pictures psiconv_empty_pictures(void)
1158{
1159 psiconv_pictures result;
1160 psiconv_paint_data_section pds;
1161 if (!(result = psiconv_list_new(sizeof(struct psiconv_paint_data_section_s))))
1162 goto ERROR1;
1163 if (!(pds = psiconv_empty_paint_data_section()))
1164 goto ERROR2;
1165 if (psiconv_list_add(result,pds))
1166 goto ERROR3;
1167 free(pds);
1168 return result;
1169ERROR3:
1170 psiconv_free_paint_data_section(pds);
1171ERROR2:
1172 psiconv_list_free(result);
1173ERROR1:
1174 return NULL;
1175}
1176
1177psiconv_mbm_f psiconv_empty_mbm_f(void)
1178{
1179 psiconv_mbm_f result;
1180 if (!(result = malloc(sizeof(*result))))
1181 goto ERROR1;
1182 if (!(result->sections = psiconv_empty_pictures()))
1183 goto ERROR2;
1184 return result;
1185ERROR2:
1186 free(result);
1187ERROR1:
1188 return NULL;
1189}
1190
1191psiconv_sketch_section psiconv_empty_sketch_section(void)
1192{
1193 psiconv_sketch_section result;
1194 if (!(result = malloc(sizeof(*result))))
1195 goto ERROR1;
1196 result->form_xsize = 320;
1197 result->form_ysize = 200;
1198 result->picture_x_offset = result->picture_y_offset = result->picture_xsize =
1199 result->picture_ysize = 0;
1200 result->magnification_x = result->magnification_y = 1.0;
1201 result->cut_left = result->cut_right = result->cut_top =
1202 result->cut_bottom = 0.0;
1203 if (!(result->picture = psiconv_empty_paint_data_section()))
1204 goto ERROR2;
1205 return result;
1206ERROR2:
1207 free(result);
1208ERROR1:
1209 return NULL;
1210}
1211
1212psiconv_sketch_f psiconv_empty_sketch_f(void)
1213{
1214 psiconv_sketch_f result;
1215 if (!(result = malloc(sizeof(*result))))
1216 goto ERROR1;
1217 if (!(result->sketch_sec = psiconv_empty_sketch_section()))
1218 goto ERROR2;
1219 return result;
1220ERROR2:
1221 free(result);
1222ERROR1:
1223 return NULL;
1224}
1225
1226psiconv_cliparts psiconv_empty_cliparts(void)
1227{
1228 /* Is this correct? */
1229 return psiconv_list_new(sizeof(struct psiconv_clipart_section_s));
1230}
1231
1232psiconv_clipart_f psiconv_empty_clipart_f(void)
1233{
1234 psiconv_clipart_f result;
1235 if (!(result = malloc(sizeof(*result))))
1236 goto ERROR1;
1237 if (!(result->sections = psiconv_empty_cliparts()))
1238 goto ERROR2;
1239 return result;
1240ERROR2:
1241 free(result);
1242ERROR1:
1243 return NULL;
1244}
1245
1246psiconv_file psiconv_empty_file(psiconv_file_type_t type)
1247{
1248 psiconv_file result;
1249 if (!(result = malloc(sizeof(*result))))
1250 return NULL;
1251 result->type = type;
1252 if (type == psiconv_word_file) {
1253 if (!(result->file = psiconv_empty_word_f()))
1254 goto ERROR;
1255 } else if (type == psiconv_sheet_file) {
1256 if (!(result->file = psiconv_empty_sheet_f()))
1257 goto ERROR;
1258 } else if (type == psiconv_texted_file) {
1259 if (!(result->file = psiconv_empty_texted_f()))
1260 goto ERROR;
1261 } else if (type == psiconv_mbm_file) {
1262 if (!(result->file = psiconv_empty_mbm_f()))
1263 goto ERROR;
1264 } else if (type == psiconv_sketch_file) {
1265 if (!(result->file = psiconv_empty_sketch_f()))
1266 goto ERROR;
1267 } else if (type == psiconv_clipart_file) {
1268 if (!(result->file = psiconv_empty_clipart_f()))
1269 goto ERROR;
1270 } else
1271 goto ERROR;
1272 return result;
1273ERROR:
1274 free(result);
1275 return NULL;
1276}

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

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