/[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 41 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.
21#include "compat.h" 21#include "compat.h"
22#include <stdlib.h> 22#include <stdlib.h>
23#include <string.h> 23#include <string.h>
24#include "data.h" 24#include "data.h"
25#include "list.h" 25#include "list.h"
26#include "general.h"
27 26
28static psiconv_color clone_color(psiconv_color color); 27static psiconv_color clone_color(psiconv_color color);
29static psiconv_font clone_font(psiconv_font font); 28static psiconv_font clone_font(psiconv_font font);
30static psiconv_border clone_border(psiconv_border border); 29static psiconv_border clone_border(psiconv_border border);
31static psiconv_bullet clone_bullet(psiconv_bullet bullet); 30static psiconv_bullet clone_bullet(psiconv_bullet bullet);
32static psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs); 31static psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs);
33static void psiconv_free_style_aux(void *style); 32static void psiconv_free_style_aux(void *style);
34static void psiconv_free_in_line_layout_aux(void * layout); 33static void psiconv_free_in_line_layout_aux(void * layout);
35static void psiconv_free_paragraph_aux(void * paragraph); 34static void psiconv_free_paragraph_aux(void * paragraph);
36static void psiconv_free_paint_data_section_aux(void * section); 35static void psiconv_free_paint_data_section_aux(void * section);
37static void psiconv_free_clipart_section_aux(psiconv_clipart_section section); 36static void psiconv_free_clipart_section_aux(void * section);
38 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. */
39psiconv_character_layout psiconv_basic_character_layout(void) 59psiconv_character_layout psiconv_basic_character_layout(void)
40{ 60{
41 /* Make the structures static, to oblige IRIX */ 61 /* Make the structures static, to oblige IRIX */
42 static struct psiconv_color black = 62 static struct psiconv_color_s black =
43 { 63 {
44 0x00, /* red */ 64 0x00, /* red */
45 0x00, /* green */ 65 0x00, /* green */
46 0x00, /* blue */ 66 0x00, /* blue */
47 }; 67 };
48 static struct psiconv_color white = 68 static struct psiconv_color_s white =
49 { 69 {
50 0xff, /* red */ 70 0xff, /* red */
51 0xff, /* green */ 71 0xff, /* green */
52 0xff, /* blue */ 72 0xff, /* blue */
53 }; 73 };
54 static struct psiconv_font font = 74 static struct psiconv_font_s font =
55 { 75 {
56 "Times New Roman", /* name */ 76 "Times New Roman", /* name */
57 3 /* screenfont */ 77 3 /* screenfont */
58 }; 78 };
59 struct psiconv_character_layout cl = 79 struct psiconv_character_layout_s cl =
60 { 80 {
61 &black, /* color */ 81 &black, /* color */
62 &white, /* back_color */ 82 &white, /* back_color */
63 10.0, /* font_size */ 83 10.0, /* font_size */
64 psiconv_bool_false, /* italic */ 84 psiconv_bool_false, /* italic */
65 psiconv_bool_false, /* bold */ 85 psiconv_bool_false, /* bold */
66 psiconv_normalscript, /* super_sub */ 86 psiconv_normalscript, /* super_sub */
67 psiconv_bool_false, /* underline */ 87 psiconv_bool_false, /* underline */
68 psiconv_bool_false, /* strike_out */ 88 psiconv_bool_false, /* strikethrough */
69 &font, /* font */ 89 &font, /* font */
70 }; 90 };
71 91
72 return psiconv_clone_character_layout(&cl); 92 return psiconv_clone_character_layout(&cl);
73} 93}
74 94
95/* Note: these defaults seem to be hard-coded somewhere outside the
96 files themself. */
75psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) 97psiconv_paragraph_layout psiconv_basic_paragraph_layout(void)
76{ 98{
77 static struct psiconv_font font = 99 static struct psiconv_font_s font =
78 { 100 {
79 "Times New Roman", /* name */ 101 "Times New Roman", /* name */
80 2 /* screenfont */ 102 2 /* screenfont */
81 }; 103 };
82 static struct psiconv_color black = 104 static struct psiconv_color_s black =
83 { 105 {
84 0x00, /* red */ 106 0x00, /* red */
85 0x00, /* green */ 107 0x00, /* green */
86 0x00, /* blue */ 108 0x00, /* blue */
87 }; 109 };
88 static struct psiconv_color white = 110 static struct psiconv_color_s white =
89 { 111 {
90 0xff, /* red */ 112 0xff, /* red */
91 0xff, /* green */ 113 0xff, /* green */
92 0xff, /* blue */ 114 0xff, /* blue */
93 }; 115 };
94 static struct psiconv_border no_border = 116 static struct psiconv_border_s no_border =
95 { 117 {
96 psiconv_border_none, /* kind */ 118 psiconv_border_none, /* kind */
97 1, /* thickness */ 119 1, /* thickness */
98 &black /* color */ 120 &black /* color */
99 }; 121 };
100 static struct psiconv_bullet bullet = 122 static struct psiconv_bullet_s bullet =
101 { 123 {
102 psiconv_bool_false, /* on */ 124 psiconv_bool_false, /* on */
103 10.0, /* font_size */ 125 10.0, /* font_size */
104 0x95, /* character */ 126 0x95, /* character */
105 psiconv_bool_true, /* indent */ 127 psiconv_bool_true, /* indent */
106 &black, /* color */ 128 &black, /* color */
107 &font, /* font */ 129 &font, /* font */
108 }; 130 };
109 static struct psiconv_all_tabs tabs = 131 static struct psiconv_all_tabs_s tabs =
110 { 132 {
111 0.64, /* normal */ 133 0.64, /* normal */
112 NULL /* kind */ 134 NULL /* kind */
113 }; 135 };
114 struct psiconv_paragraph_layout pl = 136 struct psiconv_paragraph_layout_s pl =
115 { 137 {
116 &white, /* back_color */ 138 &white, /* back_color */
117 0.0, /* indent_left */ 139 0.0, /* indent_left */
118 0.0, /* indent_right */ 140 0.0, /* indent_right */
119 0.0, /* indent_first */ 141 0.0, /* indent_first */
120 psiconv_justify_left, /* justify_hor */ 142 psiconv_justify_left, /* justify_hor */
121 psiconv_justify_middle,/* justify_ver */ 143 psiconv_justify_middle,/* justify_ver */
122 0.0, /* interline */ 144 10.0, /* linespacing */
123 psiconv_bool_false, /* interline_exact */ 145 psiconv_bool_false, /* linespacing_exact */
124 0.0, /* top_space */ 146 0.0, /* space_above */
125 0.0, /* bottom_space */ 147 0.0, /* space_below */
126 psiconv_bool_false, /* on_one_page */
127 psiconv_bool_false, /* together_with */ 148 psiconv_bool_false, /* keep_together */
149 psiconv_bool_false, /* keep_with_next */
128 psiconv_bool_false, /* on_next_page */ 150 psiconv_bool_false, /* on_next_page */
129 psiconv_bool_false, /* no_widow_protection */ 151 psiconv_bool_false, /* no_widow_protection */
130 0.0, /* left_margin */ 152 0.0, /* left_margin */
131 &bullet, /* bullet */ 153 &bullet, /* bullet */
132 &no_border, /* left_border */ 154 &no_border, /* left_border */
135 &no_border, /* bottom_border */ 157 &no_border, /* bottom_border */
136 &tabs, /* tabs */ 158 &tabs, /* tabs */
137 }; 159 };
138 psiconv_paragraph_layout res; 160 psiconv_paragraph_layout res;
139 161
140 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;
141 res = psiconv_clone_paragraph_layout(&pl); 164 res = psiconv_clone_paragraph_layout(&pl);
142 psiconv_list_free(pl.tabs->extras); 165 psiconv_list_free(pl.tabs->extras);
143 return res; 166 return res;
144} 167}
145 168
146psiconv_color clone_color(psiconv_color color) 169psiconv_color clone_color(psiconv_color color)
147{ 170{
148 psiconv_color result; 171 psiconv_color result;
149 result = malloc(sizeof(*result)); 172 if (!(result = malloc(sizeof(*result))))
173 return NULL;
150 *result = *color; 174 *result = *color;
151 return result; 175 return result;
152} 176}
153 177
154psiconv_font clone_font(psiconv_font font) 178psiconv_font clone_font(psiconv_font font)
155{ 179{
156 psiconv_font result; 180 psiconv_font result;
157 result = malloc(sizeof(*result)); 181 if(!(result = malloc(sizeof(*result))))
182 goto ERROR1;
158 *result = *font; 183 *result = *font;
159 result->name = strdup(result->name); 184 if (!(result->name = strdup(result->name)))
185 goto ERROR2;
160 return result; 186 return result;
187ERROR2:
188 free(result);
189ERROR1:
190 return NULL;
161} 191}
162 192
163psiconv_border clone_border(psiconv_border border) 193psiconv_border clone_border(psiconv_border border)
164{ 194{
165 psiconv_border result; 195 psiconv_border result;
166 result = malloc(sizeof(*result)); 196 if (!(result = malloc(sizeof(*result))))
197 goto ERROR1;
167 *result = *border; 198 *result = *border;
168 result->color = clone_color(result->color); 199 if(!(result->color = clone_color(result->color)))
200 goto ERROR2;
169 return result; 201 return result;
202ERROR2:
203 free(result);
204ERROR1:
205 return NULL;
170} 206}
171 207
172psiconv_bullet clone_bullet(psiconv_bullet bullet) 208psiconv_bullet clone_bullet(psiconv_bullet bullet)
173{ 209{
174 psiconv_bullet result; 210 psiconv_bullet result;
175 result = malloc(sizeof(*result)); 211 if (!(result = malloc(sizeof(*result))))
212 goto ERROR1;
176 *result = *bullet; 213 *result = *bullet;
177 result->font = clone_font(result->font); 214 if (!(result->font = clone_font(result->font)))
215 goto ERROR2;
178 result->color = clone_color(result->color); 216 if (!(result->color = clone_color(result->color)))
217 goto ERROR3;
179 return result; 218 return result;
219ERROR3:
220 psiconv_free_font(result->font);
221ERROR2:
222 free(result);
223ERROR1:
224 return NULL;
180} 225}
181 226
182psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs) 227psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs)
183{ 228{
184 psiconv_all_tabs result; 229 psiconv_all_tabs result;
185 result = malloc(sizeof(*result)); 230 if (!(result = malloc(sizeof(*result))))
231 goto ERROR1;
186 *result = *all_tabs; 232 *result = *all_tabs;
187 result->extras = psiconv_list_clone(result->extras); 233 if (!(result->extras = psiconv_list_clone(result->extras)))
234 goto ERROR2;
188 return result; 235 return result;
236ERROR2:
237 free(result);
238ERROR1:
239 return NULL;
189} 240}
190 241
191psiconv_character_layout psiconv_clone_character_layout 242psiconv_character_layout psiconv_clone_character_layout
192 (psiconv_character_layout ls) 243 (psiconv_character_layout ls)
193{ 244{
194 psiconv_character_layout result; 245 psiconv_character_layout result;
195 246
196 result = malloc(sizeof(*result)); 247 if (!(result = malloc(sizeof(*result))))
248 goto ERROR1;
197 *result = *ls; 249 *result = *ls;
198 result->color = clone_color(result->color); 250 if (!(result->color = clone_color(result->color)))
251 goto ERROR2;
199 result->back_color = clone_color(result->back_color); 252 if (!(result->back_color = clone_color(result->back_color)))
253 goto ERROR3;
200 result->font = clone_font(result->font); 254 if (!(result->font = clone_font(result->font)))
255 goto ERROR4;
201 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;
202} 265}
203 266
204psiconv_paragraph_layout psiconv_clone_paragraph_layout 267psiconv_paragraph_layout psiconv_clone_paragraph_layout
205 (psiconv_paragraph_layout ls) 268 (psiconv_paragraph_layout ls)
206{ 269{
207 psiconv_paragraph_layout result; 270 psiconv_paragraph_layout result;
208 271
209 result = malloc(sizeof(*result)); 272 if (!(result = malloc(sizeof(*result))))
273 goto ERROR1;
210 *result = *ls; 274 *result = *ls;
211 result->back_color = clone_color(result->back_color); 275 if (!(result->back_color = clone_color(result->back_color)))
276 goto ERROR2;
212 result->bullet = clone_bullet(result->bullet); 277 if (!(result->bullet = clone_bullet(result->bullet)))
278 goto ERROR3;
213 result->left_border = clone_border(result->left_border); 279 if (!(result->left_border = clone_border(result->left_border)))
280 goto ERROR4;
214 result->right_border = clone_border(result->right_border); 281 if (!(result->right_border = clone_border(result->right_border)))
282 goto ERROR5;
215 result->top_border = clone_border(result->top_border); 283 if (!(result->top_border = clone_border(result->top_border)))
284 goto ERROR6;
216 result->bottom_border = clone_border(result->bottom_border); 285 if (!(result->bottom_border = clone_border(result->bottom_border)))
286 goto ERROR7;
217 result->tabs = clone_all_tabs(result->tabs); 287 if (!(result->tabs = clone_all_tabs(result->tabs)))
288 goto ERROR8;
218 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;
219} 306}
220 307
221psiconv_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)
222{ 309{
223 if (nr == 0) 310 if (nr == 0)
449 psiconv_free_word_styles_section(file->styles_sec); 536 psiconv_free_word_styles_section(file->styles_sec);
450 free(file); 537 free(file);
451 } 538 }
452} 539}
453 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
454void psiconv_free_texted_f(psiconv_texted_f file) 556void psiconv_free_texted_f(psiconv_texted_f file)
455{ 557{
456 if (file) { 558 if (file) {
457 psiconv_free_page_layout_section(file->page_sec); 559 psiconv_free_page_layout_section(file->page_sec);
458 psiconv_free_texted_section(file->texted_sec); 560 psiconv_free_texted_section(file->texted_sec);
482{ 584{
483 if (section) 585 if (section)
484 psiconv_list_free_el(section,&psiconv_free_paint_data_section_aux); 586 psiconv_list_free_el(section,&psiconv_free_paint_data_section_aux);
485} 587}
486 588
487void psiconv_free_mbm_jumptable_section (psiconv_mbm_jumptable_section section) 589void psiconv_free_jumptable_section (psiconv_jumptable_section section)
488{ 590{
489 if (section) 591 if (section)
490 psiconv_list_free(section); 592 psiconv_list_free(section);
491} 593}
492 594
512 psiconv_free_sketch_section(file->sketch_sec); 614 psiconv_free_sketch_section(file->sketch_sec);
513 free(file); 615 free(file);
514 } 616 }
515} 617}
516 618
517void psiconv_free_clipart_section_aux(psiconv_clipart_section section) 619void psiconv_free_clipart_section_aux(void *section)
518{ 620{
519 if (section) 621 if (section)
520 free(section->picture); 622 free(((psiconv_clipart_section ) section)->picture);
521} 623}
522 624
523void psiconv_free_clipart_section(psiconv_clipart_section section) 625void psiconv_free_clipart_section(psiconv_clipart_section section)
524{ 626{
525 if (section) { 627 if (section) {
552 else if (file->type == psiconv_mbm_file) 654 else if (file->type == psiconv_mbm_file)
553 psiconv_free_mbm_f((psiconv_mbm_f) file->file); 655 psiconv_free_mbm_f((psiconv_mbm_f) file->file);
554 else if (file->type == psiconv_sketch_file) 656 else if (file->type == psiconv_sketch_file)
555 psiconv_free_sketch_f((psiconv_sketch_f) file->file); 657 psiconv_free_sketch_f((psiconv_sketch_f) file->file);
556 else if (file->type == psiconv_clipart_file) 658 else if (file->type == psiconv_clipart_file)
557 psiconv_free_sketch_f((psiconv_clipart_f) file->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);
558 free(file); 662 free(file);
559 } 663 }
560} 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.41  
changed lines
  Added in v.94

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