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

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

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