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

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

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