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

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

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