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

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

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