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

Legend:
Removed from v.20  
changed lines
  Added in v.110

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