/[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 12 Revision 104
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.
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/ 18*/
19 19
20#include "config.h" 20#include "config.h"
21#include "compat.h"
21#include <stdlib.h> 22#include <stdlib.h>
22#include <string.h> 23#include <string.h>
23#include "data.h" 24#include "data.h"
24#include "list.h" 25#include "list.h"
25#include "general.h"
26 26
27static psiconv_color clone_color(psiconv_color color); 27static psiconv_color clone_color(psiconv_color color);
28static psiconv_font clone_font(psiconv_font font); 28static psiconv_font clone_font(psiconv_font font);
29static psiconv_border clone_border(psiconv_border border); 29static psiconv_border clone_border(psiconv_border border);
30static psiconv_bullet clone_bullet(psiconv_bullet bullet); 30static psiconv_bullet clone_bullet(psiconv_bullet bullet);
31static psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs); 31static psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs);
32static void psiconv_free_style_aux(void *style); 32static void psiconv_free_style_aux(void *style);
33static void psiconv_free_in_line_layout_aux(void * layout); 33static void psiconv_free_in_line_layout_aux(void * layout);
34static void psiconv_free_paragraph_aux(void * paragraph); 34static void psiconv_free_paragraph_aux(void * paragraph);
35static 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);
36 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. */
37psiconv_character_layout psiconv_basic_character_layout(void) 63psiconv_character_layout psiconv_basic_character_layout(void)
38{ 64{
65 /* Make the structures static, to oblige IRIX */
39 struct psiconv_color black = 66 static struct psiconv_color_s black =
40 { 67 {
41 0x00, /* red */ 68 0x00, /* red */
42 0x00, /* green */ 69 0x00, /* green */
43 0x00, /* blue */ 70 0x00, /* blue */
44 }; 71 };
45 struct psiconv_color white = 72 static struct psiconv_color_s white =
46 { 73 {
47 0xff, /* red */ 74 0xff, /* red */
48 0xff, /* green */ 75 0xff, /* green */
49 0xff, /* blue */ 76 0xff, /* blue */
50 }; 77 };
78 static struct psiconv_font_s font =
79 {
80 "Times New Roman", /* name */
81 3 /* screenfont */
82 };
51 struct psiconv_character_layout cl = 83 struct psiconv_character_layout_s cl =
52 { 84 {
53 &black, /* color */ 85 &black, /* color */
54 &white, /* back_color */ 86 &white, /* back_color */
55 10.0, /* font_size */ 87 10.0, /* font_size */
56 psiconv_bool_false, /* italic */ 88 psiconv_bool_false, /* italic */
57 psiconv_bool_false, /* bold */ 89 psiconv_bool_false, /* bold */
58 psiconv_normalscript, /* super_sub */ 90 psiconv_normalscript, /* super_sub */
59 psiconv_bool_false, /* underline */ 91 psiconv_bool_false, /* underline */
60 psiconv_bool_false, /* strike_out */ 92 psiconv_bool_false, /* strikethrough */
61 NULL, /* font */ 93 &font, /* font */
62 }; 94 };
63 95
64 cl.color = malloc(sizeof(*cl.color));
65 cl.color->red = 0x00;
66 cl.color->green = 0x00;
67 cl.color->blue = 0x00;
68 cl.back_color = malloc(sizeof(*cl.color));
69 cl.back_color->red = 0xff;
70 cl.back_color->green = 0xff;
71 cl.back_color->blue = 0xff;
72 cl.font = malloc(sizeof(*cl.font));
73 cl.font->name = strdup("Times New Roman");
74 cl.font->screenfont = 3;
75 return psiconv_clone_character_layout(&cl); 96 return psiconv_clone_character_layout(&cl);
76} 97}
77 98
99/* Note: these defaults seem to be hard-coded somewhere outside the
100 files themself. */
78psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) 101psiconv_paragraph_layout psiconv_basic_paragraph_layout(void)
79{ 102{
80 char base_font[] = "Times New Roman";
81
82 struct psiconv_font font = 103 static struct psiconv_font_s font =
83 { 104 {
84 base_font, /* name */ 105 "Times New Roman", /* name */
85 2 /* screenfont */ 106 2 /* screenfont */
86 }; 107 };
87 struct psiconv_color black = 108 static struct psiconv_color_s black =
88 { 109 {
89 0x00, /* red */ 110 0x00, /* red */
90 0x00, /* green */ 111 0x00, /* green */
91 0x00, /* blue */ 112 0x00, /* blue */
92 }; 113 };
93 struct psiconv_color white = 114 static struct psiconv_color_s white =
94 { 115 {
95 0xff, /* red */ 116 0xff, /* red */
96 0xff, /* green */ 117 0xff, /* green */
97 0xff, /* blue */ 118 0xff, /* blue */
98 }; 119 };
99 struct psiconv_border no_border = 120 static struct psiconv_border_s no_border =
100 { 121 {
101 psiconv_border_none, /* kind */ 122 psiconv_border_none, /* kind */
102 1, /* thickness */ 123 1, /* thickness */
103 &black /* color */ 124 &black /* color */
104 }; 125 };
105 struct psiconv_bullet bullet = 126 static struct psiconv_bullet_s bullet =
106 { 127 {
107 psiconv_bool_false, /* on */ 128 psiconv_bool_false, /* on */
108 10.0, /* font_size */ 129 10.0, /* font_size */
109 0x95, /* character */ 130 0x95, /* character */
110 psiconv_bool_true, /* indent */ 131 psiconv_bool_true, /* indent */
111 &black, /* color */ 132 &black, /* color */
112 &font, /* font */ 133 &font, /* font */
113 }; 134 };
114 struct psiconv_all_tabs tabs = 135 static struct psiconv_all_tabs_s tabs =
115 { 136 {
116 0.64, /* normal */ 137 0.64, /* normal */
117 NULL /* kind */ 138 NULL /* kind */
118 }; 139 };
119 struct psiconv_paragraph_layout pl = 140 struct psiconv_paragraph_layout_s pl =
120 { 141 {
121 &white, /* back_color */ 142 &white, /* back_color */
122 0.0, /* indent_left */ 143 0.0, /* indent_left */
123 0.0, /* indent_right */ 144 0.0, /* indent_right */
124 0.0, /* indent_first */ 145 0.0, /* indent_first */
125 psiconv_justify_left, /* justify_hor */ 146 psiconv_justify_left, /* justify_hor */
126 psiconv_justify_middle,/* justify_ver */ 147 psiconv_justify_middle,/* justify_ver */
127 0.0, /* interline */ 148 10.0, /* linespacing */
128 psiconv_bool_false, /* interline_exact */ 149 psiconv_bool_false, /* linespacing_exact */
129 0.0, /* top_space */ 150 0.0, /* space_above */
130 0.0, /* bottom_space */ 151 0.0, /* space_below */
131 psiconv_bool_false, /* on_one_page */
132 psiconv_bool_false, /* together_with */ 152 psiconv_bool_false, /* keep_together */
153 psiconv_bool_false, /* keep_with_next */
133 psiconv_bool_false, /* on_next_page */ 154 psiconv_bool_false, /* on_next_page */
134 psiconv_bool_false, /* no_widow_protection */ 155 psiconv_bool_false, /* no_widow_protection */
156 psiconv_bool_false, /* wrap_to_fit_cell */
135 0.0, /* left_margin */ 157 0.0, /* left_margin */
136 &bullet, /* bullet */ 158 &bullet, /* bullet */
137 &no_border, /* left_border */ 159 &no_border, /* left_border */
138 &no_border, /* right_border */ 160 &no_border, /* right_border */
139 &no_border, /* top_border */ 161 &no_border, /* top_border */
140 &no_border, /* bottom_border */ 162 &no_border, /* bottom_border */
141 &tabs, /* tabs */ 163 &tabs, /* tabs */
142 }; 164 };
143 psiconv_paragraph_layout res; 165 psiconv_paragraph_layout res;
144 166
145 pl.tabs->extras = psiconv_list_new(sizeof(struct psiconv_tab)); 167 if (!(pl.tabs->extras = psiconv_list_new(sizeof(struct psiconv_tab_s))))
168 return NULL;
146 res = psiconv_clone_paragraph_layout(&pl); 169 res = psiconv_clone_paragraph_layout(&pl);
147 psiconv_list_free(pl.tabs->extras); 170 psiconv_list_free(pl.tabs->extras);
148 return res; 171 return res;
149} 172}
150 173
151psiconv_color clone_color(psiconv_color color) 174psiconv_color clone_color(psiconv_color color)
152{ 175{
153 psiconv_color result; 176 psiconv_color result;
154 result = malloc(sizeof(*result)); 177 if (!(result = malloc(sizeof(*result))))
178 return NULL;
155 *result = *color; 179 *result = *color;
156 return result; 180 return result;
157} 181}
158 182
159psiconv_font clone_font(psiconv_font font) 183psiconv_font clone_font(psiconv_font font)
160{ 184{
161 psiconv_font result; 185 psiconv_font result;
162 result = malloc(sizeof(*result)); 186 if(!(result = malloc(sizeof(*result))))
187 goto ERROR1;
163 *result = *font; 188 *result = *font;
164 result->name = strdup(result->name); 189 if (!(result->name = strdup(result->name)))
190 goto ERROR2;
165 return result; 191 return result;
192ERROR2:
193 free(result);
194ERROR1:
195 return NULL;
166} 196}
167 197
168psiconv_border clone_border(psiconv_border border) 198psiconv_border clone_border(psiconv_border border)
169{ 199{
170 psiconv_border result; 200 psiconv_border result;
171 result = malloc(sizeof(*result)); 201 if (!(result = malloc(sizeof(*result))))
202 goto ERROR1;
172 *result = *border; 203 *result = *border;
173 result->color = clone_color(result->color); 204 if(!(result->color = clone_color(result->color)))
205 goto ERROR2;
174 return result; 206 return result;
207ERROR2:
208 free(result);
209ERROR1:
210 return NULL;
175} 211}
176 212
177psiconv_bullet clone_bullet(psiconv_bullet bullet) 213psiconv_bullet clone_bullet(psiconv_bullet bullet)
178{ 214{
179 psiconv_bullet result; 215 psiconv_bullet result;
180 result = malloc(sizeof(*result)); 216 if (!(result = malloc(sizeof(*result))))
217 goto ERROR1;
181 *result = *bullet; 218 *result = *bullet;
182 result->font = clone_font(result->font); 219 if (!(result->font = clone_font(result->font)))
220 goto ERROR2;
183 result->color = clone_color(result->color); 221 if (!(result->color = clone_color(result->color)))
222 goto ERROR3;
184 return result; 223 return result;
224ERROR3:
225 psiconv_free_font(result->font);
226ERROR2:
227 free(result);
228ERROR1:
229 return NULL;
185} 230}
186 231
187psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs) 232psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs)
188{ 233{
189 psiconv_all_tabs result; 234 psiconv_all_tabs result;
190 result = malloc(sizeof(*result)); 235 if (!(result = malloc(sizeof(*result))))
236 goto ERROR1;
191 *result = *all_tabs; 237 *result = *all_tabs;
192 result->extras = psiconv_list_clone(result->extras); 238 if (!(result->extras = psiconv_list_clone(result->extras)))
239 goto ERROR2;
193 return result; 240 return result;
241ERROR2:
242 free(result);
243ERROR1:
244 return NULL;
194} 245}
195 246
196psiconv_character_layout psiconv_clone_character_layout 247psiconv_character_layout psiconv_clone_character_layout
197 (psiconv_character_layout ls) 248 (psiconv_character_layout ls)
198{ 249{
199 psiconv_character_layout result; 250 psiconv_character_layout result;
200 251
201 result = malloc(sizeof(*result)); 252 if (!(result = malloc(sizeof(*result))))
253 goto ERROR1;
202 *result = *ls; 254 *result = *ls;
203 result->color = clone_color(result->color); 255 if (!(result->color = clone_color(result->color)))
256 goto ERROR2;
204 result->back_color = clone_color(result->back_color); 257 if (!(result->back_color = clone_color(result->back_color)))
258 goto ERROR3;
205 result->font = clone_font(result->font); 259 if (!(result->font = clone_font(result->font)))
260 goto ERROR4;
206 return result; 261 return result;
262ERROR4:
263 psiconv_free_color(result->back_color);
264ERROR3:
265 psiconv_free_color(result->color);
266ERROR2:
267 free(result);
268ERROR1:
269 return NULL;
207} 270}
208 271
209psiconv_paragraph_layout psiconv_clone_paragraph_layout 272psiconv_paragraph_layout psiconv_clone_paragraph_layout
210 (psiconv_paragraph_layout ls) 273 (psiconv_paragraph_layout ls)
211{ 274{
212 psiconv_paragraph_layout result; 275 psiconv_paragraph_layout result;
213 276
214 result = malloc(sizeof(*result)); 277 if (!(result = malloc(sizeof(*result))))
278 goto ERROR1;
215 *result = *ls; 279 *result = *ls;
216 result->back_color = clone_color(result->back_color); 280 if (!(result->back_color = clone_color(result->back_color)))
281 goto ERROR2;
217 result->bullet = clone_bullet(result->bullet); 282 if (!(result->bullet = clone_bullet(result->bullet)))
283 goto ERROR3;
218 result->left_border = clone_border(result->left_border); 284 if (!(result->left_border = clone_border(result->left_border)))
285 goto ERROR4;
219 result->right_border = clone_border(result->right_border); 286 if (!(result->right_border = clone_border(result->right_border)))
287 goto ERROR5;
220 result->top_border = clone_border(result->top_border); 288 if (!(result->top_border = clone_border(result->top_border)))
289 goto ERROR6;
221 result->bottom_border = clone_border(result->bottom_border); 290 if (!(result->bottom_border = clone_border(result->bottom_border)))
291 goto ERROR7;
222 result->tabs = clone_all_tabs(result->tabs); 292 if (!(result->tabs = clone_all_tabs(result->tabs)))
293 goto ERROR8;
223 return result; 294 return result;
295ERROR8:
296 psiconv_free_border(result->bottom_border);
297ERROR7:
298 psiconv_free_border(result->top_border);
299ERROR6:
300 psiconv_free_border(result->right_border);
301ERROR5:
302 psiconv_free_border(result->left_border);
303ERROR4:
304 psiconv_free_bullet(result->bullet);
305ERROR3:
306 psiconv_free_color(result->back_color);
307ERROR2:
308 free(result);
309ERROR1:
310 return NULL;
224} 311}
225 312
226psiconv_word_style psiconv_get_style (psiconv_word_styles_section ss, int nr) 313psiconv_word_style psiconv_get_style (psiconv_word_styles_section ss, int nr)
227{ 314{
228 if (nr == 0) 315 if (nr == 0)
454 psiconv_free_word_styles_section(file->styles_sec); 541 psiconv_free_word_styles_section(file->styles_sec);
455 free(file); 542 free(file);
456 } 543 }
457} 544}
458 545
546void psiconv_free_sheet_status_section(psiconv_sheet_status_section section)
547{
548 if (section)
549 free(section);
550}
551
552void psiconv_free_formula_aux(void *data)
553{
554 psiconv_formula formula;
555 formula = data;
556 if (formula->type == psiconv_formula_dat_string)
557 free(formula->data.dat_string);
558 else if ((formula->type != psiconv_formula_dat_int) &&
559 (formula->type != psiconv_formula_dat_var) &&
560 (formula->type != psiconv_formula_dat_float) &&
561 (formula->type != psiconv_formula_dat_cellref) &&
562 (formula->type != psiconv_formula_dat_cellblock) &&
563 (formula->type != psiconv_formula_dat_vcellblock) &&
564 (formula->type != psiconv_formula_mark_opsep) &&
565 (formula->type != psiconv_formula_mark_opend) &&
566 (formula->type != psiconv_formula_mark_eof) &&
567 (formula->type != psiconv_formula_unknown))
568 psiconv_free_formula_list(formula->data.fun_operands);
569}
570
571void psiconv_free_formula(psiconv_formula formula)
572{
573 if (formula) {
574 psiconv_free_formula_aux(formula);
575 free(formula);
576 }
577}
578
579void psiconv_free_formula_list(psiconv_formula_list list)
580{
581 if (list)
582 psiconv_list_free_el(list,psiconv_free_formula_aux);
583}
584
585void psiconv_free_sheet_workbook_section(psiconv_sheet_workbook_section section)
586{
587 if (section) {
588 psiconv_free_formula_list(section->formulas);
589 free(section);
590 }
591}
592
593void psiconv_free_sheet_f(psiconv_sheet_f file)
594{
595 if (file) {
596 psiconv_free_page_layout_section(file->page_sec);
597 psiconv_free_sheet_status_section(file->status_sec);
598 psiconv_free_sheet_workbook_section(file->workbook_sec);
599 free(file);
600 }
601}
602
459void psiconv_free_texted_f(psiconv_texted_f file) 603void psiconv_free_texted_f(psiconv_texted_f file)
460{ 604{
461 if (file) { 605 if (file) {
462 psiconv_free_page_layout_section(file->page_sec); 606 psiconv_free_page_layout_section(file->page_sec);
463 psiconv_free_texted_section(file->texted_sec); 607 psiconv_free_texted_section(file->texted_sec);
487{ 631{
488 if (section) 632 if (section)
489 psiconv_list_free_el(section,&psiconv_free_paint_data_section_aux); 633 psiconv_list_free_el(section,&psiconv_free_paint_data_section_aux);
490} 634}
491 635
636void psiconv_free_jumptable_section (psiconv_jumptable_section section)
637{
638 if (section)
639 psiconv_list_free(section);
640}
641
492void psiconv_free_mbm_f(psiconv_mbm_f file) 642void psiconv_free_mbm_f(psiconv_mbm_f file)
493{ 643{
494 if (file) { 644 if (file) {
495 psiconv_free_pictures(file->sections); 645 psiconv_free_pictures(file->sections);
496 free(file); 646 free(file);
497 } 647 }
498} 648}
499 649
500void psiconv_free_mbm_jumptable_section (psiconv_mbm_jumptable_section section) 650void psiconv_free_sketch_section(psiconv_sketch_section sec)
651{
652 if (sec) {
653 psiconv_free_paint_data_section(sec->picture);
654 free(sec);
655 }
656}
657
658void psiconv_free_sketch_f(psiconv_sketch_f file)
659{
660 if (file) {
661 psiconv_free_sketch_section(file->sketch_sec);
662 free(file);
663 }
664}
665
666void psiconv_free_clipart_section_aux(void *section)
501{ 667{
502 if (section) 668 if (section)
503 psiconv_list_free(section); 669 free(((psiconv_clipart_section ) section)->picture);
504} 670}
671
672void psiconv_free_clipart_section(psiconv_clipart_section section)
673{
674 if (section) {
675 psiconv_free_clipart_section_aux(section);
676 free(section);
677 }
678}
679
680void psiconv_free_cliparts(psiconv_cliparts section)
681{
682 if (section)
683 psiconv_list_free_el(section,&psiconv_free_clipart_section_aux);
684}
685
686void psiconv_free_clipart_f(psiconv_clipart_f file)
687{
688 if (file) {
689 psiconv_free_cliparts(file->sections);
690 free(file);
691 }
692}
505 693
506void psiconv_free_file(psiconv_file file) 694void psiconv_free_file(psiconv_file file)
507{ 695{
508 if (file) { 696 if (file) {
509 if (file->type == psiconv_word_file) 697 if (file->type == psiconv_word_file)
510 psiconv_free_word_f((psiconv_word_f) file->file); 698 psiconv_free_word_f((psiconv_word_f) file->file);
511 else if (file->type == psiconv_texted_file) 699 else if (file->type == psiconv_texted_file)
512 psiconv_free_texted_f((psiconv_texted_f) file->file); 700 psiconv_free_texted_f((psiconv_texted_f) file->file);
513 else if (file->type == psiconv_mbm_file) 701 else if (file->type == psiconv_mbm_file)
514 psiconv_free_mbm_f((psiconv_mbm_f) file->file); 702 psiconv_free_mbm_f((psiconv_mbm_f) file->file);
703 else if (file->type == psiconv_sketch_file)
704 psiconv_free_sketch_f((psiconv_sketch_f) file->file);
705 else if (file->type == psiconv_clipart_file)
706 psiconv_free_clipart_f((psiconv_clipart_f) file->file);
707 else if (file->type == psiconv_sheet_file)
708 psiconv_free_sheet_f((psiconv_sheet_f) file->file);
515 free(file); 709 free(file);
516 } 710 }
517} 711}
712
713int psiconv_compare_color(const psiconv_color value1,
714 const psiconv_color value2)
715{
716 if (!value1 || !value2)
717 return 1;
718 if ((value1->red == value2->red) &&
719 (value1->green == value2->green) &&
720 (value1->blue == value2->blue))
721 return 0;
722 else
723 return 1;
724}
725
726int psiconv_compare_font(const psiconv_font value1,
727 const psiconv_font value2)
728{
729 if (!value1 || !value2 || !value1->name || !value2->name)
730 return 1;
731 if ((value1->screenfont == value2->screenfont) &&
732 !strcmp(value1->name,value2->name))
733 return 0;
734 else
735 return 1;
736}
737
738int psiconv_compare_border(const psiconv_border value1,
739 const psiconv_border value2)
740{
741 if (!value1 || !value2)
742 return 1;
743 if ((value1->kind == value2->kind) &&
744 (value1->thickness == value2->thickness) &&
745 !psiconv_compare_color(value1->color,value2->color))
746 return 0;
747 else
748 return 1;
749}
750
751int psiconv_compare_bullet(const psiconv_bullet value1,
752 const psiconv_bullet value2)
753{
754 if (!value1 || !value2)
755 return 1;
756 if ((value1->on == value2->on) &&
757 (value1->font_size == value2->font_size) &&
758 (value1->character == value2->character) &&
759 (value1->indent == value2->indent) &&
760 !psiconv_compare_color(value1->color,value2->color) &&
761 !psiconv_compare_font(value1->font,value2->font))
762 return 0;
763 else
764 return 1;
765}
766
767int psiconv_compare_tab(const psiconv_tab value1, const psiconv_tab value2)
768{
769 if (!value1 || !value2)
770 return 1;
771 if ((value1->location == value2->location) &&
772 (value1->kind == value2->kind))
773 return 0;
774 else
775 return 1;
776}
777
778int psiconv_compare_all_tabs(const psiconv_all_tabs value1,
779 const psiconv_all_tabs value2)
780{
781 int i;
782
783 if (!value1 || !value2 || !value1->extras || !value2->extras)
784 return 1;
785
786 if ((value1->normal != value2->normal) ||
787 psiconv_list_length(value1->extras) !=
788 psiconv_list_length(value2->extras))
789 return 1;
790 for (i = 0; i < psiconv_list_length(value1->extras); i++)
791 if (psiconv_compare_tab(psiconv_list_get(value1->extras,i),
792 psiconv_list_get(value2->extras,i)))
793
794 return 1;
795 return 0;
796}
797
798int psiconv_compare_paragraph_layout(const psiconv_paragraph_layout value1,
799 const psiconv_paragraph_layout value2)
800{
801 if (!value1 || !value2)
802 return 1;
803 if ((value1->indent_left == value2->indent_left) &&
804 (value1->indent_right == value2->indent_right) &&
805 (value1->indent_first == value2->indent_first) &&
806 (value1->justify_hor == value2->justify_hor) &&
807 (value1->justify_ver == value2->justify_ver) &&
808 (value1->linespacing == value2->linespacing) &&
809 (value1->space_above == value2->space_above) &&
810 (value1->space_below == value2->space_below) &&
811 (value1->keep_together == value2->keep_together) &&
812 (value1->keep_with_next == value2->keep_with_next) &&
813 (value1->on_next_page == value2->on_next_page) &&
814 (value1->no_widow_protection == value2->no_widow_protection) &&
815 (value1->border_distance == value2->border_distance) &&
816 !psiconv_compare_color(value1->back_color,value2->back_color) &&
817 !psiconv_compare_bullet(value1->bullet,value2->bullet) &&
818 !psiconv_compare_border(value1->left_border,value2->left_border) &&
819 !psiconv_compare_border(value1->right_border,value2->right_border) &&
820 !psiconv_compare_border(value1->top_border,value2->top_border) &&
821 !psiconv_compare_border(value1->bottom_border,value2->bottom_border) &&
822 !psiconv_compare_all_tabs(value1->tabs,value2->tabs))
823 return 0;
824 else
825 return 1;
826}
827
828
829int psiconv_compare_character_layout(const psiconv_character_layout value1,
830 const psiconv_character_layout value2)
831{
832 if (!value1 || !value2)
833 return 1;
834 if ((value1->font_size == value2->font_size) &&
835 (value1->italic == value2->italic) &&
836 (value1->bold == value2->bold) &&
837 (value1->super_sub == value2->super_sub) &&
838 (value1->underline == value2->underline) &&
839 (value1->strikethrough == value2->strikethrough) &&
840 !psiconv_compare_color(value1->color,value2->color) &&
841 !psiconv_compare_color(value1->back_color,value2->back_color) &&
842 !psiconv_compare_font(value1->font,value2->font))
843 return 0;
844 else
845 return 1;
846}
847
848
849
850psiconv_word_styles_section psiconv_empty_word_styles_section(void)
851{
852 psiconv_word_styles_section result;
853 if (!(result = malloc(sizeof(*result))))
854 goto ERROR1;
855 if (!(result->styles = psiconv_list_new(sizeof(struct psiconv_word_style_s))))
856 goto ERROR2;
857 if (!(result->normal = malloc(sizeof(struct psiconv_word_style_s))))
858 goto ERROR3;
859 if (!(result->normal->character = psiconv_basic_character_layout()))
860 goto ERROR4;
861 if (!(result->normal->paragraph = psiconv_basic_paragraph_layout()))
862 goto ERROR5;
863 result->normal->hotkey = 'N';
864 result->normal->name = NULL;
865 result->normal->built_in = psiconv_bool_true;
866 result->normal->outline_level = 0;
867 return result;
868ERROR5:
869 psiconv_free_character_layout(result->normal->character);
870ERROR4:
871 free(result->normal);
872ERROR3:
873 psiconv_list_free(result->styles);
874ERROR2:
875 free(result);
876ERROR1:
877 return NULL;
878}
879
880psiconv_text_and_layout psiconv_empty_text_and_layout(void)
881{
882 return psiconv_list_new(sizeof(struct psiconv_paragraph_s));
883}
884
885psiconv_texted_section psiconv_empty_texted_section(void)
886{
887 psiconv_texted_section result;
888 if (!(result = malloc(sizeof(*result))))
889 goto ERROR1;
890 if (!(result->paragraphs = psiconv_empty_text_and_layout()))
891 goto ERROR2;
892 return result;
893ERROR2:
894 free(result);
895ERROR1:
896 return NULL;
897}
898
899psiconv_page_header psiconv_empty_page_header(void)
900{
901 psiconv_page_header result;
902 if (!(result = malloc(sizeof(*result))))
903 goto ERROR1;
904 result->on_first_page = psiconv_bool_true;
905 if (!(result->base_paragraph_layout = psiconv_basic_paragraph_layout()))
906 goto ERROR2;
907 if (!(result->base_character_layout = psiconv_basic_character_layout()))
908 goto ERROR3;
909 if (!(result->text = psiconv_empty_texted_section()))
910 goto ERROR4;
911 return result;
912ERROR4:
913 psiconv_free_character_layout(result->base_character_layout);
914ERROR3:
915 psiconv_free_paragraph_layout(result->base_paragraph_layout);
916ERROR2:
917 free(result);
918ERROR1:
919 return NULL;
920}
921
922psiconv_page_layout_section psiconv_empty_page_layout_section(void)
923{
924 psiconv_page_layout_section result;
925 if (!(result = malloc(sizeof(*result))))
926 goto ERROR1;
927 result->first_page_nr = 1;
928 result->header_dist = result->footer_dist = 1.27;
929 result->left_margin = result->right_margin = 3.175;
930 result->top_margin = result->bottom_margin = 2.54;
931 result->page_width = 21.0;
932 result->page_height = 29.7;
933 result->landscape = psiconv_bool_false;
934 if (!(result->header = psiconv_empty_page_header()))
935 goto ERROR2;
936 if (!(result->footer = psiconv_empty_page_header()))
937 goto ERROR3;
938 return result;
939ERROR3:
940 psiconv_free_page_header(result->header);
941ERROR2:
942 free(result);
943ERROR1:
944 return NULL;
945}
946
947psiconv_word_status_section psiconv_empty_word_status_section(void)
948{
949 psiconv_word_status_section result;
950 if (!(result = malloc(sizeof(*result))))
951 return NULL;
952 result->show_tabs = result->show_spaces = result->show_paragraph_ends =
953 result->show_hard_minus = result->show_hard_space =
954 result->fit_lines_to_screen = psiconv_bool_false;
955 result->show_full_pictures = result->show_full_graphs =
956 result->show_top_toolbar = result->show_side_toolbar =
957 psiconv_bool_true;
958 result->cursor_position = 0;
959 result->display_size = 1000;
960 return result;
961}
962
963psiconv_word_f psiconv_empty_word_f(void)
964{
965 psiconv_word_f result;
966 if (!(result = malloc(sizeof(*result))))
967 goto ERROR1;
968 if (!(result->page_sec = psiconv_empty_page_layout_section()))
969 goto ERROR2;
970 if (!(result->paragraphs = psiconv_empty_text_and_layout()))
971 goto ERROR3;
972 if (!(result->status_sec = psiconv_empty_word_status_section()))
973 goto ERROR4;
974 if (!(result->styles_sec = psiconv_empty_word_styles_section()))
975 goto ERROR5;
976 return result;
977ERROR5:
978 psiconv_free_word_status_section(result->status_sec);
979ERROR4:
980 psiconv_free_text_and_layout(result->paragraphs);
981ERROR3:
982 psiconv_free_page_layout_section(result->page_sec);
983ERROR2:
984 free(result);
985ERROR1:
986 return NULL;
987}
988
989psiconv_sheet_status_section psiconv_empty_sheet_status_section(void)
990{
991 psiconv_sheet_status_section result;
992 if (!(result = malloc(sizeof(*result))))
993 return NULL;
994 result->show_horizontal_scrollbar = result->show_vertical_scrollbar =
995 psiconv_triple_auto;
996 result->show_graph = psiconv_bool_false;
997 result->show_top_sheet_toolbar = result->show_side_sheet_toolbar =
998 result->show_top_graph_toolbar = result->show_side_graph_toolbar =
999 psiconv_bool_true;
1000 result->cursor_row = result->cursor_column = 0;
1001 result->sheet_display_size = result->graph_display_size = 1000;
1002 return result;
1003}
1004
1005psiconv_formula_list psiconv_empty_formula_list(void)
1006{
1007 return psiconv_list_new(sizeof(struct psiconv_formula_s));
1008}
1009
1010psiconv_sheet_workbook_section psiconv_empty_sheet_workbook_section(void)
1011{
1012 psiconv_sheet_workbook_section result;
1013 if (!(result = malloc(sizeof(*result))))
1014 goto ERROR1;
1015 if (!(result->formulas = psiconv_empty_formula_list()))
1016 goto ERROR2;
1017 return result;
1018ERROR2:
1019 free(result);
1020ERROR1:
1021 return NULL;
1022}
1023
1024
1025psiconv_sheet_f psiconv_empty_sheet_f(void)
1026{
1027 psiconv_sheet_f result;
1028 if (!(result = malloc(sizeof(*result))))
1029 goto ERROR1;
1030 if (!(result->page_sec = psiconv_empty_page_layout_section()))
1031 goto ERROR2;
1032 if (!(result->status_sec = psiconv_empty_sheet_status_section()))
1033 goto ERROR3;
1034 if (!(result->workbook_sec = psiconv_empty_sheet_workbook_section()))
1035 goto ERROR4;
1036 return result;
1037ERROR4:
1038 psiconv_free_sheet_status_section(result->status_sec);
1039ERROR3:
1040 psiconv_free_page_layout_section(result->page_sec);
1041ERROR2:
1042 free(result);
1043ERROR1:
1044 return NULL;
1045}
1046
1047psiconv_texted_f psiconv_empty_texted_f(void)
1048{
1049 psiconv_texted_f result;
1050 if (!(result = malloc(sizeof(*result))))
1051 goto ERROR1;
1052 if (!(result->page_sec = psiconv_empty_page_layout_section()))
1053 goto ERROR2;
1054 if (!(result->texted_sec = psiconv_empty_texted_section()))
1055 goto ERROR3;
1056 return result;
1057ERROR3:
1058 psiconv_free_page_layout_section(result->page_sec);
1059ERROR2:
1060 free(result);
1061ERROR1:
1062 return NULL;
1063}
1064
1065psiconv_paint_data_section psiconv_empty_paint_data_section(void)
1066{
1067 psiconv_paint_data_section result;
1068 if (!(result = malloc(sizeof(*result))))
1069 goto ERROR1;
1070 /* Is this correct? */
1071 result->xsize = result->ysize = result->pic_xsize = result->pic_ysize = 0;
1072 /* Probably forbidden... */
1073 if (!(result->red = malloc(0)))
1074 goto ERROR2;
1075 if (!(result->green = malloc(0)))
1076 goto ERROR3;
1077 if (!(result->blue = malloc(0)))
1078 goto ERROR4;
1079 return result;
1080ERROR4:
1081 free(result->green);
1082ERROR3:
1083 free(result->red);
1084ERROR2:
1085 free(result);
1086ERROR1:
1087 return NULL;
1088}
1089
1090
1091psiconv_pictures psiconv_empty_pictures(void)
1092{
1093 psiconv_pictures result;
1094 psiconv_paint_data_section pds;
1095 if (!(result = psiconv_list_new(sizeof(struct psiconv_paint_data_section_s))))
1096 goto ERROR1;
1097 if (!(pds = psiconv_empty_paint_data_section()))
1098 goto ERROR2;
1099 if (psiconv_list_add(result,pds))
1100 goto ERROR3;
1101 free(pds);
1102 return result;
1103ERROR3:
1104 psiconv_free_paint_data_section(pds);
1105ERROR2:
1106 psiconv_list_free(result);
1107ERROR1:
1108 return NULL;
1109}
1110
1111psiconv_mbm_f psiconv_empty_mbm_f(void)
1112{
1113 psiconv_mbm_f result;
1114 if (!(result = malloc(sizeof(*result))))
1115 goto ERROR1;
1116 if (!(result->sections = psiconv_empty_pictures()))
1117 goto ERROR2;
1118 return result;
1119ERROR2:
1120 free(result);
1121ERROR1:
1122 return NULL;
1123}
1124
1125psiconv_sketch_section psiconv_empty_sketch_section(void)
1126{
1127 psiconv_sketch_section result;
1128 if (!(result = malloc(sizeof(*result))))
1129 goto ERROR1;
1130 result->form_xsize = 320;
1131 result->form_ysize = 200;
1132 result->picture_x_offset = result->picture_y_offset = result->picture_xsize =
1133 result->picture_ysize = 0;
1134 result->magnification_x = result->magnification_y = 1.0;
1135 result->cut_left = result->cut_right = result->cut_top =
1136 result->cut_bottom = 0.0;
1137 if (!(result->picture = psiconv_empty_paint_data_section()))
1138 goto ERROR2;
1139 return result;
1140ERROR2:
1141 free(result);
1142ERROR1:
1143 return NULL;
1144}
1145
1146psiconv_sketch_f psiconv_empty_sketch_f(void)
1147{
1148 psiconv_sketch_f result;
1149 if (!(result = malloc(sizeof(*result))))
1150 goto ERROR1;
1151 if (!(result->sketch_sec = psiconv_empty_sketch_section()))
1152 goto ERROR2;
1153 return result;
1154ERROR2:
1155 free(result);
1156ERROR1:
1157 return NULL;
1158}
1159
1160psiconv_cliparts psiconv_empty_cliparts(void)
1161{
1162 /* Is this correct? */
1163 return psiconv_list_new(sizeof(struct psiconv_clipart_section_s));
1164}
1165
1166psiconv_clipart_f psiconv_empty_clipart_f(void)
1167{
1168 psiconv_clipart_f result;
1169 if (!(result = malloc(sizeof(*result))))
1170 goto ERROR1;
1171 if (!(result->sections = psiconv_empty_cliparts()))
1172 goto ERROR2;
1173 return result;
1174ERROR2:
1175 free(result);
1176ERROR1:
1177 return NULL;
1178}
1179
1180psiconv_file psiconv_empty_file(psiconv_file_type_t type)
1181{
1182 psiconv_file result;
1183 if (!(result = malloc(sizeof(*result))))
1184 return NULL;
1185 result->type = type;
1186 if (type == psiconv_word_file) {
1187 if (!(result->file = psiconv_empty_word_f()))
1188 goto ERROR;
1189 } else if (type == psiconv_sheet_file) {
1190 if (!(result->file = psiconv_empty_sheet_f()))
1191 goto ERROR;
1192 } else if (type == psiconv_texted_file) {
1193 if (!(result->file = psiconv_empty_texted_f()))
1194 goto ERROR;
1195 } else if (type == psiconv_mbm_file) {
1196 if (!(result->file = psiconv_empty_mbm_f()))
1197 goto ERROR;
1198 } else if (type == psiconv_sketch_file) {
1199 if (!(result->file = psiconv_empty_sketch_f()))
1200 goto ERROR;
1201 } else if (type == psiconv_clipart_file) {
1202 if (!(result->file = psiconv_empty_clipart_f()))
1203 goto ERROR;
1204 } else
1205 goto ERROR;
1206 return result;
1207ERROR:
1208 free(result);
1209 return NULL;
1210}

Legend:
Removed from v.12  
changed lines
  Added in v.104

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