/[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 24 Revision 99
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);
32static psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs); 31static psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs);
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);
36static void psiconv_free_clipart_section_aux(void * section);
37static void psiconv_free_formula_aux(void *data);
37 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
60
61/* Note: these defaults seem to be hard-coded somewhere outside the
62 files themself. */
38psiconv_character_layout psiconv_basic_character_layout(void) 63psiconv_character_layout psiconv_basic_character_layout(void)
39{ 64{
40 /* Make the structures static, to oblige IRIX */ 65 /* Make the structures static, to oblige IRIX */
41 static struct psiconv_color black = 66 static struct psiconv_color_s black =
42 { 67 {
43 0x00, /* red */ 68 0x00, /* red */
44 0x00, /* green */ 69 0x00, /* green */
45 0x00, /* blue */ 70 0x00, /* blue */
46 }; 71 };
47 static struct psiconv_color white = 72 static struct psiconv_color_s white =
48 { 73 {
49 0xff, /* red */ 74 0xff, /* red */
50 0xff, /* green */ 75 0xff, /* green */
51 0xff, /* blue */ 76 0xff, /* blue */
52 }; 77 };
53 static struct psiconv_font font = 78 static struct psiconv_font_s font =
54 { 79 {
55 "Times New Roman", /* name */ 80 "Times New Roman", /* name */
56 3 /* screenfont */ 81 3 /* screenfont */
57 }; 82 };
58 struct psiconv_character_layout cl = 83 struct psiconv_character_layout_s cl =
59 { 84 {
60 &black, /* color */ 85 &black, /* color */
61 &white, /* back_color */ 86 &white, /* back_color */
62 10.0, /* font_size */ 87 10.0, /* font_size */
63 psiconv_bool_false, /* italic */ 88 psiconv_bool_false, /* italic */
64 psiconv_bool_false, /* bold */ 89 psiconv_bool_false, /* bold */
65 psiconv_normalscript, /* super_sub */ 90 psiconv_normalscript, /* super_sub */
66 psiconv_bool_false, /* underline */ 91 psiconv_bool_false, /* underline */
67 psiconv_bool_false, /* strike_out */ 92 psiconv_bool_false, /* strikethrough */
68 &font, /* font */ 93 &font, /* font */
69 }; 94 };
70 95
71 return psiconv_clone_character_layout(&cl); 96 return psiconv_clone_character_layout(&cl);
72} 97}
73 98
99/* Note: these defaults seem to be hard-coded somewhere outside the
100 files themself. */
74psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) 101psiconv_paragraph_layout psiconv_basic_paragraph_layout(void)
75{ 102{
76 static struct psiconv_font font = 103 static struct psiconv_font_s font =
77 { 104 {
78 "Times New Roman", /* name */ 105 "Times New Roman", /* name */
79 2 /* screenfont */ 106 2 /* screenfont */
80 }; 107 };
81 static struct psiconv_color black = 108 static struct psiconv_color_s black =
82 { 109 {
83 0x00, /* red */ 110 0x00, /* red */
84 0x00, /* green */ 111 0x00, /* green */
85 0x00, /* blue */ 112 0x00, /* blue */
86 }; 113 };
87 static struct psiconv_color white = 114 static struct psiconv_color_s white =
88 { 115 {
89 0xff, /* red */ 116 0xff, /* red */
90 0xff, /* green */ 117 0xff, /* green */
91 0xff, /* blue */ 118 0xff, /* blue */
92 }; 119 };
93 static struct psiconv_border no_border = 120 static struct psiconv_border_s no_border =
94 { 121 {
95 psiconv_border_none, /* kind */ 122 psiconv_border_none, /* kind */
96 1, /* thickness */ 123 1, /* thickness */
97 &black /* color */ 124 &black /* color */
98 }; 125 };
99 static struct psiconv_bullet bullet = 126 static struct psiconv_bullet_s bullet =
100 { 127 {
101 psiconv_bool_false, /* on */ 128 psiconv_bool_false, /* on */
102 10.0, /* font_size */ 129 10.0, /* font_size */
103 0x95, /* character */ 130 0x95, /* character */
104 psiconv_bool_true, /* indent */ 131 psiconv_bool_true, /* indent */
105 &black, /* color */ 132 &black, /* color */
106 &font, /* font */ 133 &font, /* font */
107 }; 134 };
108 static struct psiconv_all_tabs tabs = 135 static struct psiconv_all_tabs_s tabs =
109 { 136 {
110 0.64, /* normal */ 137 0.64, /* normal */
111 NULL /* kind */ 138 NULL /* kind */
112 }; 139 };
113 struct psiconv_paragraph_layout pl = 140 struct psiconv_paragraph_layout_s pl =
114 { 141 {
115 &white, /* back_color */ 142 &white, /* back_color */
116 0.0, /* indent_left */ 143 0.0, /* indent_left */
117 0.0, /* indent_right */ 144 0.0, /* indent_right */
118 0.0, /* indent_first */ 145 0.0, /* indent_first */
119 psiconv_justify_left, /* justify_hor */ 146 psiconv_justify_left, /* justify_hor */
120 psiconv_justify_middle,/* justify_ver */ 147 psiconv_justify_middle,/* justify_ver */
121 0.0, /* interline */ 148 10.0, /* linespacing */
122 psiconv_bool_false, /* interline_exact */ 149 psiconv_bool_false, /* linespacing_exact */
123 0.0, /* top_space */ 150 0.0, /* space_above */
124 0.0, /* bottom_space */ 151 0.0, /* space_below */
125 psiconv_bool_false, /* on_one_page */
126 psiconv_bool_false, /* together_with */ 152 psiconv_bool_false, /* keep_together */
153 psiconv_bool_false, /* keep_with_next */
127 psiconv_bool_false, /* on_next_page */ 154 psiconv_bool_false, /* on_next_page */
128 psiconv_bool_false, /* no_widow_protection */ 155 psiconv_bool_false, /* no_widow_protection */
129 0.0, /* left_margin */ 156 0.0, /* left_margin */
130 &bullet, /* bullet */ 157 &bullet, /* bullet */
131 &no_border, /* left_border */ 158 &no_border, /* left_border */
134 &no_border, /* bottom_border */ 161 &no_border, /* bottom_border */
135 &tabs, /* tabs */ 162 &tabs, /* tabs */
136 }; 163 };
137 psiconv_paragraph_layout res; 164 psiconv_paragraph_layout res;
138 165
139 pl.tabs->extras = psiconv_list_new(sizeof(struct psiconv_tab)); 166 if (!(pl.tabs->extras = psiconv_list_new(sizeof(struct psiconv_tab_s))))
167 return NULL;
140 res = psiconv_clone_paragraph_layout(&pl); 168 res = psiconv_clone_paragraph_layout(&pl);
141 psiconv_list_free(pl.tabs->extras); 169 psiconv_list_free(pl.tabs->extras);
142 return res; 170 return res;
143} 171}
144 172
145psiconv_color clone_color(psiconv_color color) 173psiconv_color clone_color(psiconv_color color)
146{ 174{
147 psiconv_color result; 175 psiconv_color result;
148 result = malloc(sizeof(*result)); 176 if (!(result = malloc(sizeof(*result))))
177 return NULL;
149 *result = *color; 178 *result = *color;
150 return result; 179 return result;
151} 180}
152 181
153psiconv_font clone_font(psiconv_font font) 182psiconv_font clone_font(psiconv_font font)
154{ 183{
155 psiconv_font result; 184 psiconv_font result;
156 result = malloc(sizeof(*result)); 185 if(!(result = malloc(sizeof(*result))))
186 goto ERROR1;
157 *result = *font; 187 *result = *font;
158 result->name = strdup(result->name); 188 if (!(result->name = strdup(result->name)))
189 goto ERROR2;
159 return result; 190 return result;
191ERROR2:
192 free(result);
193ERROR1:
194 return NULL;
160} 195}
161 196
162psiconv_border clone_border(psiconv_border border) 197psiconv_border clone_border(psiconv_border border)
163{ 198{
164 psiconv_border result; 199 psiconv_border result;
165 result = malloc(sizeof(*result)); 200 if (!(result = malloc(sizeof(*result))))
201 goto ERROR1;
166 *result = *border; 202 *result = *border;
167 result->color = clone_color(result->color); 203 if(!(result->color = clone_color(result->color)))
204 goto ERROR2;
168 return result; 205 return result;
206ERROR2:
207 free(result);
208ERROR1:
209 return NULL;
169} 210}
170 211
171psiconv_bullet clone_bullet(psiconv_bullet bullet) 212psiconv_bullet clone_bullet(psiconv_bullet bullet)
172{ 213{
173 psiconv_bullet result; 214 psiconv_bullet result;
174 result = malloc(sizeof(*result)); 215 if (!(result = malloc(sizeof(*result))))
216 goto ERROR1;
175 *result = *bullet; 217 *result = *bullet;
176 result->font = clone_font(result->font); 218 if (!(result->font = clone_font(result->font)))
219 goto ERROR2;
177 result->color = clone_color(result->color); 220 if (!(result->color = clone_color(result->color)))
221 goto ERROR3;
178 return result; 222 return result;
223ERROR3:
224 psiconv_free_font(result->font);
225ERROR2:
226 free(result);
227ERROR1:
228 return NULL;
179} 229}
180 230
181psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs) 231psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs)
182{ 232{
183 psiconv_all_tabs result; 233 psiconv_all_tabs result;
184 result = malloc(sizeof(*result)); 234 if (!(result = malloc(sizeof(*result))))
235 goto ERROR1;
185 *result = *all_tabs; 236 *result = *all_tabs;
186 result->extras = psiconv_list_clone(result->extras); 237 if (!(result->extras = psiconv_list_clone(result->extras)))
238 goto ERROR2;
187 return result; 239 return result;
240ERROR2:
241 free(result);
242ERROR1:
243 return NULL;
188} 244}
189 245
190psiconv_character_layout psiconv_clone_character_layout 246psiconv_character_layout psiconv_clone_character_layout
191 (psiconv_character_layout ls) 247 (psiconv_character_layout ls)
192{ 248{
193 psiconv_character_layout result; 249 psiconv_character_layout result;
194 250
195 result = malloc(sizeof(*result)); 251 if (!(result = malloc(sizeof(*result))))
252 goto ERROR1;
196 *result = *ls; 253 *result = *ls;
197 result->color = clone_color(result->color); 254 if (!(result->color = clone_color(result->color)))
255 goto ERROR2;
198 result->back_color = clone_color(result->back_color); 256 if (!(result->back_color = clone_color(result->back_color)))
257 goto ERROR3;
199 result->font = clone_font(result->font); 258 if (!(result->font = clone_font(result->font)))
259 goto ERROR4;
200 return result; 260 return result;
261ERROR4:
262 psiconv_free_color(result->back_color);
263ERROR3:
264 psiconv_free_color(result->color);
265ERROR2:
266 free(result);
267ERROR1:
268 return NULL;
201} 269}
202 270
203psiconv_paragraph_layout psiconv_clone_paragraph_layout 271psiconv_paragraph_layout psiconv_clone_paragraph_layout
204 (psiconv_paragraph_layout ls) 272 (psiconv_paragraph_layout ls)
205{ 273{
206 psiconv_paragraph_layout result; 274 psiconv_paragraph_layout result;
207 275
208 result = malloc(sizeof(*result)); 276 if (!(result = malloc(sizeof(*result))))
277 goto ERROR1;
209 *result = *ls; 278 *result = *ls;
210 result->back_color = clone_color(result->back_color); 279 if (!(result->back_color = clone_color(result->back_color)))
280 goto ERROR2;
211 result->bullet = clone_bullet(result->bullet); 281 if (!(result->bullet = clone_bullet(result->bullet)))
282 goto ERROR3;
212 result->left_border = clone_border(result->left_border); 283 if (!(result->left_border = clone_border(result->left_border)))
284 goto ERROR4;
213 result->right_border = clone_border(result->right_border); 285 if (!(result->right_border = clone_border(result->right_border)))
286 goto ERROR5;
214 result->top_border = clone_border(result->top_border); 287 if (!(result->top_border = clone_border(result->top_border)))
288 goto ERROR6;
215 result->bottom_border = clone_border(result->bottom_border); 289 if (!(result->bottom_border = clone_border(result->bottom_border)))
290 goto ERROR7;
216 result->tabs = clone_all_tabs(result->tabs); 291 if (!(result->tabs = clone_all_tabs(result->tabs)))
292 goto ERROR8;
217 return result; 293 return result;
294ERROR8:
295 psiconv_free_border(result->bottom_border);
296ERROR7:
297 psiconv_free_border(result->top_border);
298ERROR6:
299 psiconv_free_border(result->right_border);
300ERROR5:
301 psiconv_free_border(result->left_border);
302ERROR4:
303 psiconv_free_bullet(result->bullet);
304ERROR3:
305 psiconv_free_color(result->back_color);
306ERROR2:
307 free(result);
308ERROR1:
309 return NULL;
218} 310}
219 311
220psiconv_word_style psiconv_get_style (psiconv_word_styles_section ss, int nr) 312psiconv_word_style psiconv_get_style (psiconv_word_styles_section ss, int nr)
221{ 313{
222 if (nr == 0) 314 if (nr == 0)
448 psiconv_free_word_styles_section(file->styles_sec); 540 psiconv_free_word_styles_section(file->styles_sec);
449 free(file); 541 free(file);
450 } 542 }
451} 543}
452 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
453void psiconv_free_texted_f(psiconv_texted_f file) 602void psiconv_free_texted_f(psiconv_texted_f file)
454{ 603{
455 if (file) { 604 if (file) {
456 psiconv_free_page_layout_section(file->page_sec); 605 psiconv_free_page_layout_section(file->page_sec);
457 psiconv_free_texted_section(file->texted_sec); 606 psiconv_free_texted_section(file->texted_sec);
481{ 630{
482 if (section) 631 if (section)
483 psiconv_list_free_el(section,&psiconv_free_paint_data_section_aux); 632 psiconv_list_free_el(section,&psiconv_free_paint_data_section_aux);
484} 633}
485 634
486void psiconv_free_mbm_jumptable_section (psiconv_mbm_jumptable_section section) 635void psiconv_free_jumptable_section (psiconv_jumptable_section section)
487{ 636{
488 if (section) 637 if (section)
489 psiconv_list_free(section); 638 psiconv_list_free(section);
490} 639}
491 640
507 656
508void psiconv_free_sketch_f(psiconv_sketch_f file) 657void psiconv_free_sketch_f(psiconv_sketch_f file)
509{ 658{
510 if (file) { 659 if (file) {
511 psiconv_free_sketch_section(file->sketch_sec); 660 psiconv_free_sketch_section(file->sketch_sec);
661 free(file);
662 }
663}
664
665void psiconv_free_clipart_section_aux(void *section)
666{
667 if (section)
668 free(((psiconv_clipart_section ) section)->picture);
669}
670
671void psiconv_free_clipart_section(psiconv_clipart_section section)
672{
673 if (section) {
674 psiconv_free_clipart_section_aux(section);
675 free(section);
676 }
677}
678
679void psiconv_free_cliparts(psiconv_cliparts section)
680{
681 if (section)
682 psiconv_list_free_el(section,&psiconv_free_clipart_section_aux);
683}
684
685void psiconv_free_clipart_f(psiconv_clipart_f file)
686{
687 if (file) {
688 psiconv_free_cliparts(file->sections);
512 free(file); 689 free(file);
513 } 690 }
514} 691}
515 692
516void psiconv_free_file(psiconv_file file) 693void psiconv_free_file(psiconv_file file)
522 psiconv_free_texted_f((psiconv_texted_f) file->file); 699 psiconv_free_texted_f((psiconv_texted_f) file->file);
523 else if (file->type == psiconv_mbm_file) 700 else if (file->type == psiconv_mbm_file)
524 psiconv_free_mbm_f((psiconv_mbm_f) file->file); 701 psiconv_free_mbm_f((psiconv_mbm_f) file->file);
525 else if (file->type == psiconv_sketch_file) 702 else if (file->type == psiconv_sketch_file)
526 psiconv_free_sketch_f((psiconv_sketch_f) file->file); 703 psiconv_free_sketch_f((psiconv_sketch_f) file->file);
704 else if (file->type == psiconv_clipart_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);
527 free(file); 708 free(file);
528 } 709 }
529} 710}
711
712int psiconv_compare_color(const psiconv_color value1,
713 const psiconv_color value2)
714{
715 if (!value1 || !value2)
716 return 1;
717 if ((value1->red == value2->red) &&
718 (value1->green == value2->green) &&
719 (value1->blue == value2->blue))
720 return 0;
721 else
722 return 1;
723}
724
725int psiconv_compare_font(const psiconv_font value1,
726 const psiconv_font value2)
727{
728 if (!value1 || !value2 || !value1->name || !value2->name)
729 return 1;
730 if ((value1->screenfont == value2->screenfont) &&
731 !strcmp(value1->name,value2->name))
732 return 0;
733 else
734 return 1;
735}
736
737int psiconv_compare_border(const psiconv_border value1,
738 const psiconv_border value2)
739{
740 if (!value1 || !value2)
741 return 1;
742 if ((value1->kind == value2->kind) &&
743 (value1->thickness == value2->thickness) &&
744 !psiconv_compare_color(value1->color,value2->color))
745 return 0;
746 else
747 return 1;
748}
749
750int psiconv_compare_bullet(const psiconv_bullet value1,
751 const psiconv_bullet value2)
752{
753 if (!value1 || !value2)
754 return 1;
755 if ((value1->on == value2->on) &&
756 (value1->font_size == value2->font_size) &&
757 (value1->character == value2->character) &&
758 (value1->indent == value2->indent) &&
759 !psiconv_compare_color(value1->color,value2->color) &&
760 !psiconv_compare_font(value1->font,value2->font))
761 return 0;
762 else
763 return 1;
764}
765
766int psiconv_compare_tab(const psiconv_tab value1, const psiconv_tab value2)
767{
768 if (!value1 || !value2)
769 return 1;
770 if ((value1->location == value2->location) &&
771 (value1->kind == value2->kind))
772 return 0;
773 else
774 return 1;
775}
776
777int psiconv_compare_all_tabs(const psiconv_all_tabs value1,
778 const psiconv_all_tabs value2)
779{
780 int i;
781
782 if (!value1 || !value2 || !value1->extras || !value2->extras)
783 return 1;
784
785 if ((value1->normal != value2->normal) ||
786 psiconv_list_length(value1->extras) !=
787 psiconv_list_length(value2->extras))
788 return 1;
789 for (i = 0; i < psiconv_list_length(value1->extras); i++)
790 if (psiconv_compare_tab(psiconv_list_get(value1->extras,i),
791 psiconv_list_get(value2->extras,i)))
792
793 return 1;
794 return 0;
795}
796
797int psiconv_compare_paragraph_layout(const psiconv_paragraph_layout value1,
798 const psiconv_paragraph_layout value2)
799{
800 if (!value1 || !value2)
801 return 1;
802 if ((value1->indent_left == value2->indent_left) &&
803 (value1->indent_right == value2->indent_right) &&
804 (value1->indent_first == value2->indent_first) &&
805 (value1->justify_hor == value2->justify_hor) &&
806 (value1->justify_ver == value2->justify_ver) &&
807 (value1->linespacing == value2->linespacing) &&
808 (value1->space_above == value2->space_above) &&
809 (value1->space_below == value2->space_below) &&
810 (value1->keep_together == value2->keep_together) &&
811 (value1->keep_with_next == value2->keep_with_next) &&
812 (value1->on_next_page == value2->on_next_page) &&
813 (value1->no_widow_protection == value2->no_widow_protection) &&
814 (value1->border_distance == value2->border_distance) &&
815 !psiconv_compare_color(value1->back_color,value2->back_color) &&
816 !psiconv_compare_bullet(value1->bullet,value2->bullet) &&
817 !psiconv_compare_border(value1->left_border,value2->left_border) &&
818 !psiconv_compare_border(value1->right_border,value2->right_border) &&
819 !psiconv_compare_border(value1->top_border,value2->top_border) &&
820 !psiconv_compare_border(value1->bottom_border,value2->bottom_border) &&
821 !psiconv_compare_all_tabs(value1->tabs,value2->tabs))
822 return 0;
823 else
824 return 1;
825}
826
827
828int psiconv_compare_character_layout(const psiconv_character_layout value1,
829 const psiconv_character_layout value2)
830{
831 if (!value1 || !value2)
832 return 1;
833 if ((value1->font_size == value2->font_size) &&
834 (value1->italic == value2->italic) &&
835 (value1->bold == value2->bold) &&
836 (value1->super_sub == value2->super_sub) &&
837 (value1->underline == value2->underline) &&
838 (value1->strikethrough == value2->strikethrough) &&
839 !psiconv_compare_color(value1->color,value2->color) &&
840 !psiconv_compare_color(value1->back_color,value2->back_color) &&
841 !psiconv_compare_font(value1->font,value2->font))
842 return 0;
843 else
844 return 1;
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.24  
changed lines
  Added in v.99

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