/[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 42 Revision 125
1/* 1/*
2 data.c - Part of psiconv, a PSION 5 file formats converter 2 data.c - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 1999 Frodo Looijaard <frodol@dds.nl> 3 Copyright (c) 1999, 2000 Frodo Looijaard <frodol@dds.nl>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
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#include "list.h"
26#include "general.h"
27 26
28static psiconv_color clone_color(psiconv_color color); 27static psiconv_color clone_color(psiconv_color color);
29static psiconv_font clone_font(psiconv_font font); 28static psiconv_font clone_font(psiconv_font font);
30static psiconv_border clone_border(psiconv_border border); 29static psiconv_border clone_border(psiconv_border border);
31static psiconv_bullet clone_bullet(psiconv_bullet bullet); 30static psiconv_bullet clone_bullet(psiconv_bullet bullet);
33static void psiconv_free_style_aux(void *style); 32static void psiconv_free_style_aux(void *style);
34static void psiconv_free_in_line_layout_aux(void * layout); 33static void psiconv_free_in_line_layout_aux(void * layout);
35static void psiconv_free_paragraph_aux(void * paragraph); 34static void psiconv_free_paragraph_aux(void * paragraph);
36static void psiconv_free_paint_data_section_aux(void * section); 35static void psiconv_free_paint_data_section_aux(void * section);
37static 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);
38 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
61
62/* Note: these defaults seem to be hard-coded somewhere outside the
63 files themself. */
39psiconv_character_layout psiconv_basic_character_layout(void) 64psiconv_character_layout psiconv_basic_character_layout(void)
40{ 65{
41 /* Make the structures static, to oblige IRIX */ 66 /* Make the structures static, to oblige IRIX */
42 static struct psiconv_color black = 67 static struct psiconv_color_s black =
43 { 68 {
44 0x00, /* red */ 69 0x00, /* red */
45 0x00, /* green */ 70 0x00, /* green */
46 0x00, /* blue */ 71 0x00, /* blue */
47 }; 72 };
48 static struct psiconv_color white = 73 static struct psiconv_color_s white =
49 { 74 {
50 0xff, /* red */ 75 0xff, /* red */
51 0xff, /* green */ 76 0xff, /* green */
52 0xff, /* blue */ 77 0xff, /* blue */
53 }; 78 };
54 static struct psiconv_font font = 79 static struct psiconv_font_s font =
55 { 80 {
56 "Times New Roman", /* name */ 81 "Times New Roman", /* name */
57 3 /* screenfont */ 82 3 /* screenfont */
58 }; 83 };
59 struct psiconv_character_layout cl = 84 struct psiconv_character_layout_s cl =
60 { 85 {
61 &black, /* color */ 86 &black, /* color */
62 &white, /* back_color */ 87 &white, /* back_color */
63 10.0, /* font_size */ 88 10.0, /* font_size */
64 psiconv_bool_false, /* italic */ 89 psiconv_bool_false, /* italic */
65 psiconv_bool_false, /* bold */ 90 psiconv_bool_false, /* bold */
66 psiconv_normalscript, /* super_sub */ 91 psiconv_normalscript, /* super_sub */
67 psiconv_bool_false, /* underline */ 92 psiconv_bool_false, /* underline */
68 psiconv_bool_false, /* strike_out */ 93 psiconv_bool_false, /* strikethrough */
69 &font, /* font */ 94 &font, /* font */
70 }; 95 };
71 96
72 return psiconv_clone_character_layout(&cl); 97 return psiconv_clone_character_layout(&cl);
73} 98}
74 99
100/* Note: these defaults seem to be hard-coded somewhere outside the
101 files themself. */
75psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) 102psiconv_paragraph_layout psiconv_basic_paragraph_layout(void)
76{ 103{
77 static struct psiconv_font font = 104 static struct psiconv_font_s font =
78 { 105 {
79 "Times New Roman", /* name */ 106 "Times New Roman", /* name */
80 2 /* screenfont */ 107 2 /* screenfont */
81 }; 108 };
82 static struct psiconv_color black = 109 static struct psiconv_color_s black =
83 { 110 {
84 0x00, /* red */ 111 0x00, /* red */
85 0x00, /* green */ 112 0x00, /* green */
86 0x00, /* blue */ 113 0x00, /* blue */
87 }; 114 };
88 static struct psiconv_color white = 115 static struct psiconv_color_s white =
89 { 116 {
90 0xff, /* red */ 117 0xff, /* red */
91 0xff, /* green */ 118 0xff, /* green */
92 0xff, /* blue */ 119 0xff, /* blue */
93 }; 120 };
94 static struct psiconv_border no_border = 121 static struct psiconv_border_s no_border =
95 { 122 {
96 psiconv_border_none, /* kind */ 123 psiconv_border_none, /* kind */
97 1, /* thickness */ 124 1, /* thickness */
98 &black /* color */ 125 &black /* color */
99 }; 126 };
100 static struct psiconv_bullet bullet = 127 static struct psiconv_bullet_s bullet =
101 { 128 {
102 psiconv_bool_false, /* on */ 129 psiconv_bool_false, /* on */
103 10.0, /* font_size */ 130 10.0, /* font_size */
104 0x95, /* character */ 131 0x95, /* character */
105 psiconv_bool_true, /* indent */ 132 psiconv_bool_true, /* indent */
106 &black, /* color */ 133 &black, /* color */
107 &font, /* font */ 134 &font, /* font */
108 }; 135 };
109 static struct psiconv_all_tabs tabs = 136 static struct psiconv_all_tabs_s tabs =
110 { 137 {
111 0.64, /* normal */ 138 0.64, /* normal */
112 NULL /* kind */ 139 NULL /* kind */
113 }; 140 };
114 struct psiconv_paragraph_layout pl = 141 struct psiconv_paragraph_layout_s pl =
115 { 142 {
116 &white, /* back_color */ 143 &white, /* back_color */
117 0.0, /* indent_left */ 144 0.0, /* indent_left */
118 0.0, /* indent_right */ 145 0.0, /* indent_right */
119 0.0, /* indent_first */ 146 0.0, /* indent_first */
120 psiconv_justify_left, /* justify_hor */ 147 psiconv_justify_left, /* justify_hor */
121 psiconv_justify_middle,/* justify_ver */ 148 psiconv_justify_middle,/* justify_ver */
122 0.0, /* interline */ 149 10.0, /* linespacing */
123 psiconv_bool_false, /* interline_exact */ 150 psiconv_bool_false, /* linespacing_exact */
124 0.0, /* top_space */ 151 0.0, /* space_above */
125 0.0, /* bottom_space */ 152 0.0, /* space_below */
126 psiconv_bool_false, /* on_one_page */
127 psiconv_bool_false, /* together_with */ 153 psiconv_bool_false, /* keep_together */
154 psiconv_bool_false, /* keep_with_next */
128 psiconv_bool_false, /* on_next_page */ 155 psiconv_bool_false, /* on_next_page */
129 psiconv_bool_false, /* no_widow_protection */ 156 psiconv_bool_false, /* no_widow_protection */
157 psiconv_bool_false, /* wrap_to_fit_cell */
130 0.0, /* left_margin */ 158 0.0, /* left_margin */
131 &bullet, /* bullet */ 159 &bullet, /* bullet */
132 &no_border, /* left_border */ 160 &no_border, /* left_border */
133 &no_border, /* right_border */ 161 &no_border, /* right_border */
134 &no_border, /* top_border */ 162 &no_border, /* top_border */
135 &no_border, /* bottom_border */ 163 &no_border, /* bottom_border */
136 &tabs, /* tabs */ 164 &tabs, /* tabs */
137 }; 165 };
138 psiconv_paragraph_layout res; 166 psiconv_paragraph_layout res;
139 167
140 pl.tabs->extras = psiconv_list_new(sizeof(struct psiconv_tab)); 168 if (!(pl.tabs->extras = psiconv_list_new(sizeof(struct psiconv_tab_s))))
169 return NULL;
141 res = psiconv_clone_paragraph_layout(&pl); 170 res = psiconv_clone_paragraph_layout(&pl);
142 psiconv_list_free(pl.tabs->extras); 171 psiconv_list_free(pl.tabs->extras);
143 return res; 172 return res;
144} 173}
145 174
146psiconv_color clone_color(psiconv_color color) 175psiconv_color clone_color(psiconv_color color)
147{ 176{
148 psiconv_color result; 177 psiconv_color result;
149 result = malloc(sizeof(*result)); 178 if (!(result = malloc(sizeof(*result))))
179 return NULL;
150 *result = *color; 180 *result = *color;
151 return result; 181 return result;
152} 182}
153 183
154psiconv_font clone_font(psiconv_font font) 184psiconv_font clone_font(psiconv_font font)
155{ 185{
156 psiconv_font result; 186 psiconv_font result;
157 result = malloc(sizeof(*result)); 187 if(!(result = malloc(sizeof(*result))))
188 goto ERROR1;
158 *result = *font; 189 *result = *font;
159 result->name = strdup(result->name); 190 if (!(result->name = strdup(result->name)))
191 goto ERROR2;
160 return result; 192 return result;
193ERROR2:
194 free(result);
195ERROR1:
196 return NULL;
161} 197}
162 198
163psiconv_border clone_border(psiconv_border border) 199psiconv_border clone_border(psiconv_border border)
164{ 200{
165 psiconv_border result; 201 psiconv_border result;
166 result = malloc(sizeof(*result)); 202 if (!(result = malloc(sizeof(*result))))
203 goto ERROR1;
167 *result = *border; 204 *result = *border;
168 result->color = clone_color(result->color); 205 if(!(result->color = clone_color(result->color)))
206 goto ERROR2;
169 return result; 207 return result;
208ERROR2:
209 free(result);
210ERROR1:
211 return NULL;
170} 212}
171 213
172psiconv_bullet clone_bullet(psiconv_bullet bullet) 214psiconv_bullet clone_bullet(psiconv_bullet bullet)
173{ 215{
174 psiconv_bullet result; 216 psiconv_bullet result;
175 result = malloc(sizeof(*result)); 217 if (!(result = malloc(sizeof(*result))))
218 goto ERROR1;
176 *result = *bullet; 219 *result = *bullet;
177 result->font = clone_font(result->font); 220 if (!(result->font = clone_font(result->font)))
221 goto ERROR2;
178 result->color = clone_color(result->color); 222 if (!(result->color = clone_color(result->color)))
223 goto ERROR3;
179 return result; 224 return result;
225ERROR3:
226 psiconv_free_font(result->font);
227ERROR2:
228 free(result);
229ERROR1:
230 return NULL;
180} 231}
181 232
182psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs) 233psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs)
183{ 234{
184 psiconv_all_tabs result; 235 psiconv_all_tabs result;
185 result = malloc(sizeof(*result)); 236 if (!(result = malloc(sizeof(*result))))
237 goto ERROR1;
186 *result = *all_tabs; 238 *result = *all_tabs;
187 result->extras = psiconv_list_clone(result->extras); 239 if (!(result->extras = psiconv_list_clone(result->extras)))
240 goto ERROR2;
188 return result; 241 return result;
242ERROR2:
243 free(result);
244ERROR1:
245 return NULL;
189} 246}
190 247
191psiconv_character_layout psiconv_clone_character_layout 248psiconv_character_layout psiconv_clone_character_layout
192 (psiconv_character_layout ls) 249 (psiconv_character_layout ls)
193{ 250{
194 psiconv_character_layout result; 251 psiconv_character_layout result;
195 252
196 result = malloc(sizeof(*result)); 253 if (!(result = malloc(sizeof(*result))))
254 goto ERROR1;
197 *result = *ls; 255 *result = *ls;
198 result->color = clone_color(result->color); 256 if (!(result->color = clone_color(result->color)))
257 goto ERROR2;
199 result->back_color = clone_color(result->back_color); 258 if (!(result->back_color = clone_color(result->back_color)))
259 goto ERROR3;
200 result->font = clone_font(result->font); 260 if (!(result->font = clone_font(result->font)))
261 goto ERROR4;
201 return result; 262 return result;
263ERROR4:
264 psiconv_free_color(result->back_color);
265ERROR3:
266 psiconv_free_color(result->color);
267ERROR2:
268 free(result);
269ERROR1:
270 return NULL;
202} 271}
203 272
204psiconv_paragraph_layout psiconv_clone_paragraph_layout 273psiconv_paragraph_layout psiconv_clone_paragraph_layout
205 (psiconv_paragraph_layout ls) 274 (psiconv_paragraph_layout ls)
206{ 275{
207 psiconv_paragraph_layout result; 276 psiconv_paragraph_layout result;
208 277
209 result = malloc(sizeof(*result)); 278 if (!(result = malloc(sizeof(*result))))
279 goto ERROR1;
210 *result = *ls; 280 *result = *ls;
211 result->back_color = clone_color(result->back_color); 281 if (!(result->back_color = clone_color(result->back_color)))
282 goto ERROR2;
212 result->bullet = clone_bullet(result->bullet); 283 if (!(result->bullet = clone_bullet(result->bullet)))
284 goto ERROR3;
213 result->left_border = clone_border(result->left_border); 285 if (!(result->left_border = clone_border(result->left_border)))
286 goto ERROR4;
214 result->right_border = clone_border(result->right_border); 287 if (!(result->right_border = clone_border(result->right_border)))
288 goto ERROR5;
215 result->top_border = clone_border(result->top_border); 289 if (!(result->top_border = clone_border(result->top_border)))
290 goto ERROR6;
216 result->bottom_border = clone_border(result->bottom_border); 291 if (!(result->bottom_border = clone_border(result->bottom_border)))
292 goto ERROR7;
217 result->tabs = clone_all_tabs(result->tabs); 293 if (!(result->tabs = clone_all_tabs(result->tabs)))
294 goto ERROR8;
218 return result; 295 return result;
296ERROR8:
297 psiconv_free_border(result->bottom_border);
298ERROR7:
299 psiconv_free_border(result->top_border);
300ERROR6:
301 psiconv_free_border(result->right_border);
302ERROR5:
303 psiconv_free_border(result->left_border);
304ERROR4:
305 psiconv_free_bullet(result->bullet);
306ERROR3:
307 psiconv_free_color(result->back_color);
308ERROR2:
309 free(result);
310ERROR1:
311 return NULL;
219} 312}
220 313
221psiconv_word_style psiconv_get_style (psiconv_word_styles_section ss, int nr) 314psiconv_word_style psiconv_get_style (psiconv_word_styles_section ss, int nr)
222{ 315{
223 if (nr == 0) 316 if (nr == 0)
224 return ss->normal; 317 return ss->normal;
225 else 318 else
226 return psiconv_list_get(ss->styles,0xff - nr); 319 return psiconv_list_get(ss->styles,0xff - nr);
227} 320}
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
228 327
229void psiconv_free_color (psiconv_color color) 328void psiconv_free_color (psiconv_color color)
230{ 329{
231 if (color) 330 if (color)
232 free(color); 331 free(color);
445 if (file) { 544 if (file) {
446 psiconv_free_page_layout_section(file->page_sec); 545 psiconv_free_page_layout_section(file->page_sec);
447 psiconv_free_text_and_layout(file->paragraphs); 546 psiconv_free_text_and_layout(file->paragraphs);
448 psiconv_free_word_status_section(file->status_sec); 547 psiconv_free_word_status_section(file->status_sec);
449 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);
450 free(file); 665 free(file);
451 } 666 }
452} 667}
453 668
454void psiconv_free_texted_f(psiconv_texted_f file) 669void psiconv_free_texted_f(psiconv_texted_f file)
553 psiconv_free_mbm_f((psiconv_mbm_f) file->file); 768 psiconv_free_mbm_f((psiconv_mbm_f) file->file);
554 else if (file->type == psiconv_sketch_file) 769 else if (file->type == psiconv_sketch_file)
555 psiconv_free_sketch_f((psiconv_sketch_f) file->file); 770 psiconv_free_sketch_f((psiconv_sketch_f) file->file);
556 else if (file->type == psiconv_clipart_file) 771 else if (file->type == psiconv_clipart_file)
557 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);
558 free(file); 775 free(file);
559 } 776 }
560} 777}
778
779int psiconv_compare_color(const psiconv_color value1,
780 const psiconv_color value2)
781{
782 if (!value1 || !value2)
783 return 1;
784 if ((value1->red == value2->red) &&
785 (value1->green == value2->green) &&
786 (value1->blue == value2->blue))
787 return 0;
788 else
789 return 1;
790}
791
792int psiconv_compare_font(const psiconv_font value1,
793 const psiconv_font value2)
794{
795 if (!value1 || !value2 || !value1->name || !value2->name)
796 return 1;
797 if ((value1->screenfont == value2->screenfont) &&
798 !strcmp(value1->name,value2->name))
799 return 0;
800 else
801 return 1;
802}
803
804int psiconv_compare_border(const psiconv_border value1,
805 const psiconv_border value2)
806{
807 if (!value1 || !value2)
808 return 1;
809 if ((value1->kind == value2->kind) &&
810 (value1->thickness == value2->thickness) &&
811 !psiconv_compare_color(value1->color,value2->color))
812 return 0;
813 else
814 return 1;
815}
816
817int psiconv_compare_bullet(const psiconv_bullet value1,
818 const psiconv_bullet value2)
819{
820 if (!value1 || !value2)
821 return 1;
822 if ((value1->on == value2->on) &&
823 (value1->font_size == value2->font_size) &&
824 (value1->character == value2->character) &&
825 (value1->indent == value2->indent) &&
826 !psiconv_compare_color(value1->color,value2->color) &&
827 !psiconv_compare_font(value1->font,value2->font))
828 return 0;
829 else
830 return 1;
831}
832
833int psiconv_compare_tab(const psiconv_tab value1, const psiconv_tab value2)
834{
835 if (!value1 || !value2)
836 return 1;
837 if ((value1->location == value2->location) &&
838 (value1->kind == value2->kind))
839 return 0;
840 else
841 return 1;
842}
843
844int psiconv_compare_all_tabs(const psiconv_all_tabs value1,
845 const psiconv_all_tabs value2)
846{
847 int i;
848
849 if (!value1 || !value2 || !value1->extras || !value2->extras)
850 return 1;
851
852 if ((value1->normal != value2->normal) ||
853 psiconv_list_length(value1->extras) !=
854 psiconv_list_length(value2->extras))
855 return 1;
856 for (i = 0; i < psiconv_list_length(value1->extras); i++)
857 if (psiconv_compare_tab(psiconv_list_get(value1->extras,i),
858 psiconv_list_get(value2->extras,i)))
859
860 return 1;
861 return 0;
862}
863
864int psiconv_compare_paragraph_layout(const psiconv_paragraph_layout value1,
865 const psiconv_paragraph_layout value2)
866{
867 if (!value1 || !value2)
868 return 1;
869 if ((value1->indent_left == value2->indent_left) &&
870 (value1->indent_right == value2->indent_right) &&
871 (value1->indent_first == value2->indent_first) &&
872 (value1->justify_hor == value2->justify_hor) &&
873 (value1->justify_ver == value2->justify_ver) &&
874 (value1->linespacing == value2->linespacing) &&
875 (value1->space_above == value2->space_above) &&
876 (value1->space_below == value2->space_below) &&
877 (value1->keep_together == value2->keep_together) &&
878 (value1->keep_with_next == value2->keep_with_next) &&
879 (value1->on_next_page == value2->on_next_page) &&
880 (value1->no_widow_protection == value2->no_widow_protection) &&
881 (value1->border_distance == value2->border_distance) &&
882 !psiconv_compare_color(value1->back_color,value2->back_color) &&
883 !psiconv_compare_bullet(value1->bullet,value2->bullet) &&
884 !psiconv_compare_border(value1->left_border,value2->left_border) &&
885 !psiconv_compare_border(value1->right_border,value2->right_border) &&
886 !psiconv_compare_border(value1->top_border,value2->top_border) &&
887 !psiconv_compare_border(value1->bottom_border,value2->bottom_border) &&
888 !psiconv_compare_all_tabs(value1->tabs,value2->tabs))
889 return 0;
890 else
891 return 1;
892}
893
894
895int psiconv_compare_character_layout(const psiconv_character_layout value1,
896 const psiconv_character_layout value2)
897{
898 if (!value1 || !value2)
899 return 1;
900 if ((value1->font_size == value2->font_size) &&
901 (value1->italic == value2->italic) &&
902 (value1->bold == value2->bold) &&
903 (value1->super_sub == value2->super_sub) &&
904 (value1->underline == value2->underline) &&
905 (value1->strikethrough == value2->strikethrough) &&
906 !psiconv_compare_color(value1->color,value2->color) &&
907 !psiconv_compare_color(value1->back_color,value2->back_color) &&
908 !psiconv_compare_font(value1->font,value2->font))
909 return 0;
910 else
911 return 1;
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.42  
changed lines
  Added in v.125

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