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

Legend:
Removed from v.21  
changed lines
  Added in v.88

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