/[public]/psiconv/trunk/lib/psiconv/data.c
ViewVC logotype

Contents of /psiconv/trunk/lib/psiconv/data.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 97 - (show annotations)
Mon Jan 22 20:36:50 2001 UTC (23 years, 3 months ago) by frodo
File MIME type: text/plain
File size: 33118 byte(s)
(Frodo) Another small Sheet improvement: sheet formula list

1 /*
2 data.c - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 1999, 2000 Frodo Looijaard <frodol@dds.nl>
4
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
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include "config.h"
21 #include "compat.h"
22 #include <stdlib.h>
23 #include <string.h>
24 #include "data.h"
25 #include "list.h"
26
27 static psiconv_color clone_color(psiconv_color color);
28 static psiconv_font clone_font(psiconv_font font);
29 static psiconv_border clone_border(psiconv_border border);
30 static psiconv_bullet clone_bullet(psiconv_bullet bullet);
31 static psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs);
32 static void psiconv_free_style_aux(void *style);
33 static void psiconv_free_in_line_layout_aux(void * layout);
34 static void psiconv_free_paragraph_aux(void * paragraph);
35 static void psiconv_free_paint_data_section_aux(void * section);
36 static void psiconv_free_clipart_section_aux(void * section);
37
38 static psiconv_word_styles_section psiconv_empty_word_styles_section(void);
39 static psiconv_text_and_layout psiconv_empty_text_and_layout(void);
40 static psiconv_texted_section psiconv_empty_texted_section(void);
41 static psiconv_page_header psiconv_empty_page_header(void);
42 static psiconv_page_layout_section psiconv_empty_page_layout_section(void);
43 static psiconv_word_status_section psiconv_empty_word_status_section(void);
44 static psiconv_word_f psiconv_empty_word_f(void);
45 static psiconv_sheet_status_section psiconv_empty_sheet_status_section(void);
46 static psiconv_sheet_formula_list psiconv_empty_sheet_formula_list(void);
47 static psiconv_sheet_workbook_section
48 psiconv_empty_sheet_workbook_section(void);
49 static psiconv_sheet_f psiconv_empty_sheet_f(void);
50 static psiconv_texted_f psiconv_empty_texted_f(void);
51 static psiconv_paint_data_section psiconv_empty_paint_data_section(void);
52 static psiconv_pictures psiconv_empty_pictures(void);
53 static psiconv_mbm_f psiconv_empty_mbm_f(void);
54 static psiconv_sketch_section psiconv_empty_sketch_section(void);
55 static psiconv_sketch_f psiconv_empty_sketch_f(void);
56 static psiconv_clipart_f psiconv_empty_clipart_f(void);
57 static psiconv_cliparts psiconv_empty_cliparts(void);
58
59
60 /* Note: these defaults seem to be hard-coded somewhere outside the
61 files themself. */
62 psiconv_character_layout psiconv_basic_character_layout(void)
63 {
64 /* Make the structures static, to oblige IRIX */
65 static struct psiconv_color_s black =
66 {
67 0x00, /* red */
68 0x00, /* green */
69 0x00, /* blue */
70 };
71 static struct psiconv_color_s white =
72 {
73 0xff, /* red */
74 0xff, /* green */
75 0xff, /* blue */
76 };
77 static struct psiconv_font_s font =
78 {
79 "Times New Roman", /* name */
80 3 /* screenfont */
81 };
82 struct psiconv_character_layout_s cl =
83 {
84 &black, /* color */
85 &white, /* back_color */
86 10.0, /* font_size */
87 psiconv_bool_false, /* italic */
88 psiconv_bool_false, /* bold */
89 psiconv_normalscript, /* super_sub */
90 psiconv_bool_false, /* underline */
91 psiconv_bool_false, /* strikethrough */
92 &font, /* font */
93 };
94
95 return psiconv_clone_character_layout(&cl);
96 }
97
98 /* Note: these defaults seem to be hard-coded somewhere outside the
99 files themself. */
100 psiconv_paragraph_layout psiconv_basic_paragraph_layout(void)
101 {
102 static struct psiconv_font_s font =
103 {
104 "Times New Roman", /* name */
105 2 /* screenfont */
106 };
107 static struct psiconv_color_s black =
108 {
109 0x00, /* red */
110 0x00, /* green */
111 0x00, /* blue */
112 };
113 static struct psiconv_color_s white =
114 {
115 0xff, /* red */
116 0xff, /* green */
117 0xff, /* blue */
118 };
119 static struct psiconv_border_s no_border =
120 {
121 psiconv_border_none, /* kind */
122 1, /* thickness */
123 &black /* color */
124 };
125 static struct psiconv_bullet_s bullet =
126 {
127 psiconv_bool_false, /* on */
128 10.0, /* font_size */
129 0x95, /* character */
130 psiconv_bool_true, /* indent */
131 &black, /* color */
132 &font, /* font */
133 };
134 static struct psiconv_all_tabs_s tabs =
135 {
136 0.64, /* normal */
137 NULL /* kind */
138 };
139 struct psiconv_paragraph_layout_s pl =
140 {
141 &white, /* back_color */
142 0.0, /* indent_left */
143 0.0, /* indent_right */
144 0.0, /* indent_first */
145 psiconv_justify_left, /* justify_hor */
146 psiconv_justify_middle,/* justify_ver */
147 10.0, /* linespacing */
148 psiconv_bool_false, /* linespacing_exact */
149 0.0, /* space_above */
150 0.0, /* space_below */
151 psiconv_bool_false, /* keep_together */
152 psiconv_bool_false, /* keep_with_next */
153 psiconv_bool_false, /* on_next_page */
154 psiconv_bool_false, /* no_widow_protection */
155 0.0, /* left_margin */
156 &bullet, /* bullet */
157 &no_border, /* left_border */
158 &no_border, /* right_border */
159 &no_border, /* top_border */
160 &no_border, /* bottom_border */
161 &tabs, /* tabs */
162 };
163 psiconv_paragraph_layout res;
164
165 if (!(pl.tabs->extras = psiconv_list_new(sizeof(struct psiconv_tab_s))))
166 return NULL;
167 res = psiconv_clone_paragraph_layout(&pl);
168 psiconv_list_free(pl.tabs->extras);
169 return res;
170 }
171
172 psiconv_color clone_color(psiconv_color color)
173 {
174 psiconv_color result;
175 if (!(result = malloc(sizeof(*result))))
176 return NULL;
177 *result = *color;
178 return result;
179 }
180
181 psiconv_font clone_font(psiconv_font font)
182 {
183 psiconv_font result;
184 if(!(result = malloc(sizeof(*result))))
185 goto ERROR1;
186 *result = *font;
187 if (!(result->name = strdup(result->name)))
188 goto ERROR2;
189 return result;
190 ERROR2:
191 free(result);
192 ERROR1:
193 return NULL;
194 }
195
196 psiconv_border clone_border(psiconv_border border)
197 {
198 psiconv_border result;
199 if (!(result = malloc(sizeof(*result))))
200 goto ERROR1;
201 *result = *border;
202 if(!(result->color = clone_color(result->color)))
203 goto ERROR2;
204 return result;
205 ERROR2:
206 free(result);
207 ERROR1:
208 return NULL;
209 }
210
211 psiconv_bullet clone_bullet(psiconv_bullet bullet)
212 {
213 psiconv_bullet result;
214 if (!(result = malloc(sizeof(*result))))
215 goto ERROR1;
216 *result = *bullet;
217 if (!(result->font = clone_font(result->font)))
218 goto ERROR2;
219 if (!(result->color = clone_color(result->color)))
220 goto ERROR3;
221 return result;
222 ERROR3:
223 psiconv_free_font(result->font);
224 ERROR2:
225 free(result);
226 ERROR1:
227 return NULL;
228 }
229
230 psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs)
231 {
232 psiconv_all_tabs result;
233 if (!(result = malloc(sizeof(*result))))
234 goto ERROR1;
235 *result = *all_tabs;
236 if (!(result->extras = psiconv_list_clone(result->extras)))
237 goto ERROR2;
238 return result;
239 ERROR2:
240 free(result);
241 ERROR1:
242 return NULL;
243 }
244
245 psiconv_character_layout psiconv_clone_character_layout
246 (psiconv_character_layout ls)
247 {
248 psiconv_character_layout result;
249
250 if (!(result = malloc(sizeof(*result))))
251 goto ERROR1;
252 *result = *ls;
253 if (!(result->color = clone_color(result->color)))
254 goto ERROR2;
255 if (!(result->back_color = clone_color(result->back_color)))
256 goto ERROR3;
257 if (!(result->font = clone_font(result->font)))
258 goto ERROR4;
259 return result;
260 ERROR4:
261 psiconv_free_color(result->back_color);
262 ERROR3:
263 psiconv_free_color(result->color);
264 ERROR2:
265 free(result);
266 ERROR1:
267 return NULL;
268 }
269
270 psiconv_paragraph_layout psiconv_clone_paragraph_layout
271 (psiconv_paragraph_layout ls)
272 {
273 psiconv_paragraph_layout result;
274
275 if (!(result = malloc(sizeof(*result))))
276 goto ERROR1;
277 *result = *ls;
278 if (!(result->back_color = clone_color(result->back_color)))
279 goto ERROR2;
280 if (!(result->bullet = clone_bullet(result->bullet)))
281 goto ERROR3;
282 if (!(result->left_border = clone_border(result->left_border)))
283 goto ERROR4;
284 if (!(result->right_border = clone_border(result->right_border)))
285 goto ERROR5;
286 if (!(result->top_border = clone_border(result->top_border)))
287 goto ERROR6;
288 if (!(result->bottom_border = clone_border(result->bottom_border)))
289 goto ERROR7;
290 if (!(result->tabs = clone_all_tabs(result->tabs)))
291 goto ERROR8;
292 return result;
293 ERROR8:
294 psiconv_free_border(result->bottom_border);
295 ERROR7:
296 psiconv_free_border(result->top_border);
297 ERROR6:
298 psiconv_free_border(result->right_border);
299 ERROR5:
300 psiconv_free_border(result->left_border);
301 ERROR4:
302 psiconv_free_bullet(result->bullet);
303 ERROR3:
304 psiconv_free_color(result->back_color);
305 ERROR2:
306 free(result);
307 ERROR1:
308 return NULL;
309 }
310
311 psiconv_word_style psiconv_get_style (psiconv_word_styles_section ss, int nr)
312 {
313 if (nr == 0)
314 return ss->normal;
315 else
316 return psiconv_list_get(ss->styles,0xff - nr);
317 }
318
319 void psiconv_free_color (psiconv_color color)
320 {
321 if (color)
322 free(color);
323 }
324
325 void psiconv_free_border(psiconv_border border)
326 {
327 if (border) {
328 psiconv_free_color(border->color);
329 free(border);
330 }
331 }
332
333 void psiconv_free_font(psiconv_font font)
334 {
335 if (font) {
336 if (font->name)
337 free(font->name);
338 free(font);
339 }
340 }
341
342 void psiconv_free_bullet(psiconv_bullet bullet)
343 {
344 if (bullet) {
345 psiconv_free_color(bullet->color);
346 psiconv_free_font(bullet->font);
347 free(bullet);
348 }
349 }
350
351 void psiconv_free_character_layout(psiconv_character_layout layout)
352 {
353 if (layout) {
354 psiconv_free_color(layout->color);
355 psiconv_free_color(layout->back_color);
356 psiconv_free_font(layout->font);
357 free(layout);
358 }
359 }
360
361 void psiconv_free_tab(psiconv_tab tab)
362 {
363 if (tab)
364 free(tab);
365 }
366
367 void psiconv_free_tabs(psiconv_all_tabs tabs)
368 {
369 if (tabs) {
370 psiconv_list_free(tabs->extras);
371 free(tabs);
372 }
373 }
374
375 void psiconv_free_paragraph_layout(psiconv_paragraph_layout layout)
376 {
377 if (layout) {
378 psiconv_free_color(layout->back_color);
379 psiconv_free_bullet(layout->bullet);
380 psiconv_free_border(layout->left_border);
381 psiconv_free_border(layout->right_border);
382 psiconv_free_border(layout->top_border);
383 psiconv_free_border(layout->bottom_border);
384 psiconv_free_tabs(layout->tabs);
385 free(layout);
386 }
387 }
388
389 void psiconv_free_style_aux(void *style)
390 {
391 if(((psiconv_word_style) style)->name)
392 free(((psiconv_word_style) style)->name);
393 psiconv_free_character_layout(((psiconv_word_style) style)->character);
394 psiconv_free_paragraph_layout(((psiconv_word_style) style)->paragraph);
395 }
396
397 void psiconv_free_word_style(psiconv_word_style style)
398 {
399 if (style) {
400 psiconv_free_style_aux(style);
401 free(style);
402 }
403 }
404
405 void psiconv_free_word_styles_section(psiconv_word_styles_section styles)
406 {
407 if (styles) {
408 psiconv_free_word_style(styles->normal);
409 if (styles->styles)
410 psiconv_list_free_el(styles->styles,psiconv_free_style_aux);
411 }
412 }
413
414 void psiconv_free_header_section(psiconv_header_section header)
415 {
416 if (header)
417 free(header);
418 }
419
420 void psiconv_free_section_table_entry(psiconv_section_table_entry entry)
421 {
422 if (entry)
423 free(entry);
424 }
425
426 void psiconv_free_section_table_section(psiconv_section_table_section section)
427 {
428 if (section)
429 psiconv_list_free(section);
430 }
431
432 void psiconv_free_application_id_section(psiconv_application_id_section section)
433 {
434 if (section) {
435 if (section->name)
436 free(section->name);
437 free(section);
438 }
439 }
440
441 void psiconv_free_in_line_layout_aux(void * layout)
442 {
443 psiconv_free_character_layout(((psiconv_in_line_layout) layout)->layout);
444 }
445
446 void psiconv_free_in_line_layout(psiconv_in_line_layout layout)
447 {
448 if (layout) {
449 psiconv_free_in_line_layout_aux(layout);
450 free(layout);
451 }
452 }
453
454 void psiconv_free_in_line_layouts(psiconv_in_line_layouts layouts)
455 {
456 if (layouts)
457 psiconv_list_free_el(layouts,&psiconv_free_in_line_layout_aux);
458 }
459
460 void psiconv_free_replacement(psiconv_replacement replacement)
461 {
462 if (replacement)
463 free(replacement);
464 }
465
466 void psiconv_free_replacements(psiconv_replacements replacements)
467 {
468 if (replacements)
469 psiconv_list_free(replacements);
470 }
471
472 void psiconv_free_paragraph_aux(void * paragraph)
473 {
474 if(((psiconv_paragraph) paragraph)->text)
475 free(((psiconv_paragraph) paragraph)->text);
476 psiconv_free_character_layout(((psiconv_paragraph) paragraph)
477 ->base_character);
478 psiconv_free_paragraph_layout(((psiconv_paragraph) paragraph)
479 ->base_paragraph);
480 psiconv_free_in_line_layouts(((psiconv_paragraph) paragraph)
481 ->in_lines);
482 psiconv_free_replacements(((psiconv_paragraph) paragraph)
483 ->replacements);
484 }
485
486 void psiconv_free_paragraph(psiconv_paragraph paragraph)
487 {
488 if (paragraph) {
489 psiconv_free_paragraph_aux(paragraph);
490 free(paragraph);
491 }
492 }
493
494 void psiconv_free_text_and_layout(psiconv_text_and_layout text)
495 {
496 if (text)
497 psiconv_list_free_el(text,&psiconv_free_paragraph_aux);
498 }
499
500 void psiconv_free_texted_section(psiconv_texted_section section)
501 {
502 if (section) {
503 psiconv_free_text_and_layout(section->paragraphs);
504 free(section);
505 }
506 }
507
508 void psiconv_free_page_header(psiconv_page_header header)
509 {
510 if (header) {
511 psiconv_free_character_layout(header->base_character_layout);
512 psiconv_free_paragraph_layout(header->base_paragraph_layout);
513 psiconv_free_texted_section(header->text);
514 free(header);
515 }
516 }
517
518 void psiconv_free_page_layout_section(psiconv_page_layout_section section)
519 {
520 if (section) {
521 psiconv_free_page_header(section->header);
522 psiconv_free_page_header(section->footer);
523 free(section);
524 }
525 }
526
527 void psiconv_free_word_status_section(psiconv_word_status_section section)
528 {
529 if (section)
530 free(section);
531 }
532
533 void psiconv_free_word_f(psiconv_word_f file)
534 {
535 if (file) {
536 psiconv_free_page_layout_section(file->page_sec);
537 psiconv_free_text_and_layout(file->paragraphs);
538 psiconv_free_word_status_section(file->status_sec);
539 psiconv_free_word_styles_section(file->styles_sec);
540 free(file);
541 }
542 }
543
544 void psiconv_free_sheet_status_section(psiconv_sheet_status_section section)
545 {
546 if (section)
547 free(section);
548 }
549
550 void psiconv_free_sheet_formula(psiconv_sheet_formula formula)
551 {
552 if (formula)
553 free(formula);
554 }
555
556 void psiconv_free_sheet_formula_list(psiconv_sheet_formula_list list)
557 {
558 if (list)
559 psiconv_list_free(list);
560 }
561
562 void psiconv_free_sheet_workbook_section(psiconv_sheet_workbook_section section)
563 {
564 if (section) {
565 psiconv_free_sheet_formula_list(section->formulas);
566 free(section);
567 }
568 }
569
570 void psiconv_free_sheet_f(psiconv_sheet_f file)
571 {
572 if (file) {
573 psiconv_free_page_layout_section(file->page_sec);
574 psiconv_free_sheet_status_section(file->status_sec);
575 psiconv_free_sheet_workbook_section(file->workbook_sec);
576 free(file);
577 }
578 }
579
580 void psiconv_free_texted_f(psiconv_texted_f file)
581 {
582 if (file) {
583 psiconv_free_page_layout_section(file->page_sec);
584 psiconv_free_texted_section(file->texted_sec);
585 free(file);
586 }
587 }
588
589 void psiconv_free_paint_data_section_aux(void * section)
590 {
591 if (((psiconv_paint_data_section) section)->red)
592 free(((psiconv_paint_data_section)section) -> red);
593 if (((psiconv_paint_data_section) section)->green)
594 free(((psiconv_paint_data_section)section) -> green);
595 if (((psiconv_paint_data_section) section)->blue)
596 free(((psiconv_paint_data_section)section) -> blue);
597 }
598
599 void psiconv_free_paint_data_section(psiconv_paint_data_section section)
600 {
601 if (section) {
602 psiconv_free_paint_data_section_aux(section);
603 free(section);
604 }
605 }
606
607 void psiconv_free_pictures(psiconv_pictures section)
608 {
609 if (section)
610 psiconv_list_free_el(section,&psiconv_free_paint_data_section_aux);
611 }
612
613 void psiconv_free_jumptable_section (psiconv_jumptable_section section)
614 {
615 if (section)
616 psiconv_list_free(section);
617 }
618
619 void psiconv_free_mbm_f(psiconv_mbm_f file)
620 {
621 if (file) {
622 psiconv_free_pictures(file->sections);
623 free(file);
624 }
625 }
626
627 void psiconv_free_sketch_section(psiconv_sketch_section sec)
628 {
629 if (sec) {
630 psiconv_free_paint_data_section(sec->picture);
631 free(sec);
632 }
633 }
634
635 void psiconv_free_sketch_f(psiconv_sketch_f file)
636 {
637 if (file) {
638 psiconv_free_sketch_section(file->sketch_sec);
639 free(file);
640 }
641 }
642
643 void psiconv_free_clipart_section_aux(void *section)
644 {
645 if (section)
646 free(((psiconv_clipart_section ) section)->picture);
647 }
648
649 void psiconv_free_clipart_section(psiconv_clipart_section section)
650 {
651 if (section) {
652 psiconv_free_clipart_section_aux(section);
653 free(section);
654 }
655 }
656
657 void psiconv_free_cliparts(psiconv_cliparts section)
658 {
659 if (section)
660 psiconv_list_free_el(section,&psiconv_free_clipart_section_aux);
661 }
662
663 void psiconv_free_clipart_f(psiconv_clipart_f file)
664 {
665 if (file) {
666 psiconv_free_cliparts(file->sections);
667 free(file);
668 }
669 }
670
671 void psiconv_free_file(psiconv_file file)
672 {
673 if (file) {
674 if (file->type == psiconv_word_file)
675 psiconv_free_word_f((psiconv_word_f) file->file);
676 else if (file->type == psiconv_texted_file)
677 psiconv_free_texted_f((psiconv_texted_f) file->file);
678 else if (file->type == psiconv_mbm_file)
679 psiconv_free_mbm_f((psiconv_mbm_f) file->file);
680 else if (file->type == psiconv_sketch_file)
681 psiconv_free_sketch_f((psiconv_sketch_f) file->file);
682 else if (file->type == psiconv_clipart_file)
683 psiconv_free_clipart_f((psiconv_clipart_f) file->file);
684 else if (file->type == psiconv_sheet_file)
685 psiconv_free_sheet_f((psiconv_sheet_f) file->file);
686 free(file);
687 }
688 }
689
690 int psiconv_compare_color(const psiconv_color value1,
691 const psiconv_color value2)
692 {
693 if (!value1 || !value2)
694 return 1;
695 if ((value1->red == value2->red) &&
696 (value1->green == value2->green) &&
697 (value1->blue == value2->blue))
698 return 0;
699 else
700 return 1;
701 }
702
703 int psiconv_compare_font(const psiconv_font value1,
704 const psiconv_font value2)
705 {
706 if (!value1 || !value2 || !value1->name || !value2->name)
707 return 1;
708 if ((value1->screenfont == value2->screenfont) &&
709 !strcmp(value1->name,value2->name))
710 return 0;
711 else
712 return 1;
713 }
714
715 int psiconv_compare_border(const psiconv_border value1,
716 const psiconv_border value2)
717 {
718 if (!value1 || !value2)
719 return 1;
720 if ((value1->kind == value2->kind) &&
721 (value1->thickness == value2->thickness) &&
722 !psiconv_compare_color(value1->color,value2->color))
723 return 0;
724 else
725 return 1;
726 }
727
728 int psiconv_compare_bullet(const psiconv_bullet value1,
729 const psiconv_bullet value2)
730 {
731 if (!value1 || !value2)
732 return 1;
733 if ((value1->on == value2->on) &&
734 (value1->font_size == value2->font_size) &&
735 (value1->character == value2->character) &&
736 (value1->indent == value2->indent) &&
737 !psiconv_compare_color(value1->color,value2->color) &&
738 !psiconv_compare_font(value1->font,value2->font))
739 return 0;
740 else
741 return 1;
742 }
743
744 int psiconv_compare_tab(const psiconv_tab value1, const psiconv_tab value2)
745 {
746 if (!value1 || !value2)
747 return 1;
748 if ((value1->location == value2->location) &&
749 (value1->kind == value2->kind))
750 return 0;
751 else
752 return 1;
753 }
754
755 int psiconv_compare_all_tabs(const psiconv_all_tabs value1,
756 const psiconv_all_tabs value2)
757 {
758 int i;
759
760 if (!value1 || !value2 || !value1->extras || !value2->extras)
761 return 1;
762
763 if ((value1->normal != value2->normal) ||
764 psiconv_list_length(value1->extras) !=
765 psiconv_list_length(value2->extras))
766 return 1;
767 for (i = 0; i < psiconv_list_length(value1->extras); i++)
768 if (psiconv_compare_tab(psiconv_list_get(value1->extras,i),
769 psiconv_list_get(value2->extras,i)))
770
771 return 1;
772 return 0;
773 }
774
775 int psiconv_compare_paragraph_layout(const psiconv_paragraph_layout value1,
776 const psiconv_paragraph_layout value2)
777 {
778 if (!value1 || !value2)
779 return 1;
780 if ((value1->indent_left == value2->indent_left) &&
781 (value1->indent_right == value2->indent_right) &&
782 (value1->indent_first == value2->indent_first) &&
783 (value1->justify_hor == value2->justify_hor) &&
784 (value1->justify_ver == value2->justify_ver) &&
785 (value1->linespacing == value2->linespacing) &&
786 (value1->space_above == value2->space_above) &&
787 (value1->space_below == value2->space_below) &&
788 (value1->keep_together == value2->keep_together) &&
789 (value1->keep_with_next == value2->keep_with_next) &&
790 (value1->on_next_page == value2->on_next_page) &&
791 (value1->no_widow_protection == value2->no_widow_protection) &&
792 (value1->border_distance == value2->border_distance) &&
793 !psiconv_compare_color(value1->back_color,value2->back_color) &&
794 !psiconv_compare_bullet(value1->bullet,value2->bullet) &&
795 !psiconv_compare_border(value1->left_border,value2->left_border) &&
796 !psiconv_compare_border(value1->right_border,value2->right_border) &&
797 !psiconv_compare_border(value1->top_border,value2->top_border) &&
798 !psiconv_compare_border(value1->bottom_border,value2->bottom_border) &&
799 !psiconv_compare_all_tabs(value1->tabs,value2->tabs))
800 return 0;
801 else
802 return 1;
803 }
804
805
806 int psiconv_compare_character_layout(const psiconv_character_layout value1,
807 const psiconv_character_layout value2)
808 {
809 if (!value1 || !value2)
810 return 1;
811 if ((value1->font_size == value2->font_size) &&
812 (value1->italic == value2->italic) &&
813 (value1->bold == value2->bold) &&
814 (value1->super_sub == value2->super_sub) &&
815 (value1->underline == value2->underline) &&
816 (value1->strikethrough == value2->strikethrough) &&
817 !psiconv_compare_color(value1->color,value2->color) &&
818 !psiconv_compare_color(value1->back_color,value2->back_color) &&
819 !psiconv_compare_font(value1->font,value2->font))
820 return 0;
821 else
822 return 1;
823 }
824
825
826
827 psiconv_word_styles_section psiconv_empty_word_styles_section(void)
828 {
829 psiconv_word_styles_section result;
830 if (!(result = malloc(sizeof(*result))))
831 goto ERROR1;
832 if (!(result->styles = psiconv_list_new(sizeof(struct psiconv_word_style_s))))
833 goto ERROR2;
834 if (!(result->normal = malloc(sizeof(struct psiconv_word_style_s))))
835 goto ERROR3;
836 if (!(result->normal->character = psiconv_basic_character_layout()))
837 goto ERROR4;
838 if (!(result->normal->paragraph = psiconv_basic_paragraph_layout()))
839 goto ERROR5;
840 result->normal->hotkey = 'N';
841 result->normal->name = NULL;
842 result->normal->built_in = psiconv_bool_true;
843 result->normal->outline_level = 0;
844 return result;
845 ERROR5:
846 psiconv_free_character_layout(result->normal->character);
847 ERROR4:
848 free(result->normal);
849 ERROR3:
850 psiconv_list_free(result->styles);
851 ERROR2:
852 free(result);
853 ERROR1:
854 return NULL;
855 }
856
857 psiconv_text_and_layout psiconv_empty_text_and_layout(void)
858 {
859 return psiconv_list_new(sizeof(struct psiconv_paragraph_s));
860 }
861
862 psiconv_texted_section psiconv_empty_texted_section(void)
863 {
864 psiconv_texted_section result;
865 if (!(result = malloc(sizeof(*result))))
866 goto ERROR1;
867 if (!(result->paragraphs = psiconv_empty_text_and_layout()))
868 goto ERROR2;
869 return result;
870 ERROR2:
871 free(result);
872 ERROR1:
873 return NULL;
874 }
875
876 psiconv_page_header psiconv_empty_page_header(void)
877 {
878 psiconv_page_header result;
879 if (!(result = malloc(sizeof(*result))))
880 goto ERROR1;
881 result->on_first_page = psiconv_bool_true;
882 if (!(result->base_paragraph_layout = psiconv_basic_paragraph_layout()))
883 goto ERROR2;
884 if (!(result->base_character_layout = psiconv_basic_character_layout()))
885 goto ERROR3;
886 if (!(result->text = psiconv_empty_texted_section()))
887 goto ERROR4;
888 return result;
889 ERROR4:
890 psiconv_free_character_layout(result->base_character_layout);
891 ERROR3:
892 psiconv_free_paragraph_layout(result->base_paragraph_layout);
893 ERROR2:
894 free(result);
895 ERROR1:
896 return NULL;
897 }
898
899 psiconv_page_layout_section psiconv_empty_page_layout_section(void)
900 {
901 psiconv_page_layout_section result;
902 if (!(result = malloc(sizeof(*result))))
903 goto ERROR1;
904 result->first_page_nr = 1;
905 result->header_dist = result->footer_dist = 1.27;
906 result->left_margin = result->right_margin = 3.175;
907 result->top_margin = result->bottom_margin = 2.54;
908 result->page_width = 21.0;
909 result->page_height = 29.7;
910 result->landscape = psiconv_bool_false;
911 if (!(result->header = psiconv_empty_page_header()))
912 goto ERROR2;
913 if (!(result->footer = psiconv_empty_page_header()))
914 goto ERROR3;
915 return result;
916 ERROR3:
917 psiconv_free_page_header(result->header);
918 ERROR2:
919 free(result);
920 ERROR1:
921 return NULL;
922 }
923
924 psiconv_word_status_section psiconv_empty_word_status_section(void)
925 {
926 psiconv_word_status_section result;
927 if (!(result = malloc(sizeof(*result))))
928 return NULL;
929 result->show_tabs = result->show_spaces = result->show_paragraph_ends =
930 result->show_hard_minus = result->show_hard_space =
931 result->fit_lines_to_screen = psiconv_bool_false;
932 result->show_full_pictures = result->show_full_graphs =
933 result->show_top_toolbar = result->show_side_toolbar =
934 psiconv_bool_true;
935 result->cursor_position = 0;
936 result->display_size = 1000;
937 return result;
938 }
939
940 psiconv_word_f psiconv_empty_word_f(void)
941 {
942 psiconv_word_f result;
943 if (!(result = malloc(sizeof(*result))))
944 goto ERROR1;
945 if (!(result->page_sec = psiconv_empty_page_layout_section()))
946 goto ERROR2;
947 if (!(result->paragraphs = psiconv_empty_text_and_layout()))
948 goto ERROR3;
949 if (!(result->status_sec = psiconv_empty_word_status_section()))
950 goto ERROR4;
951 if (!(result->styles_sec = psiconv_empty_word_styles_section()))
952 goto ERROR5;
953 return result;
954 ERROR5:
955 psiconv_free_word_status_section(result->status_sec);
956 ERROR4:
957 psiconv_free_text_and_layout(result->paragraphs);
958 ERROR3:
959 psiconv_free_page_layout_section(result->page_sec);
960 ERROR2:
961 free(result);
962 ERROR1:
963 return NULL;
964 }
965
966 psiconv_sheet_status_section psiconv_empty_sheet_status_section(void)
967 {
968 psiconv_sheet_status_section result;
969 if (!(result = malloc(sizeof(*result))))
970 return NULL;
971 result->show_horizontal_scrollbar = result->show_vertical_scrollbar =
972 psiconv_triple_auto;
973 result->show_graph = psiconv_bool_false;
974 result->show_top_sheet_toolbar = result->show_side_sheet_toolbar =
975 result->show_top_graph_toolbar = result->show_side_graph_toolbar =
976 psiconv_bool_true;
977 result->cursor_row = result->cursor_column = 0;
978 result->sheet_display_size = result->graph_display_size = 1000;
979 return result;
980 }
981
982 psiconv_sheet_formula_list psiconv_empty_sheet_formula_list(void)
983 {
984 return psiconv_list_new(sizeof(struct psiconv_sheet_formula_s));
985 }
986
987 psiconv_sheet_workbook_section psiconv_empty_sheet_workbook_section(void)
988 {
989 psiconv_sheet_workbook_section result;
990 if (!(result = malloc(sizeof(*result))))
991 goto ERROR1;
992 if (!(result->formulas = psiconv_empty_sheet_formula_list()))
993 goto ERROR2;
994 return result;
995 ERROR2:
996 free(result);
997 ERROR1:
998 return NULL;
999 }
1000
1001
1002 psiconv_sheet_f psiconv_empty_sheet_f(void)
1003 {
1004 psiconv_sheet_f result;
1005 if (!(result = malloc(sizeof(*result))))
1006 goto ERROR1;
1007 if (!(result->page_sec = psiconv_empty_page_layout_section()))
1008 goto ERROR2;
1009 if (!(result->status_sec = psiconv_empty_sheet_status_section()))
1010 goto ERROR3;
1011 if (!(result->workbook_sec = psiconv_empty_sheet_workbook_section()))
1012 goto ERROR4;
1013 return result;
1014 ERROR4:
1015 psiconv_free_sheet_status_section(result->status_sec);
1016 ERROR3:
1017 psiconv_free_page_layout_section(result->page_sec);
1018 ERROR2:
1019 free(result);
1020 ERROR1:
1021 return NULL;
1022 }
1023
1024 psiconv_texted_f psiconv_empty_texted_f(void)
1025 {
1026 psiconv_texted_f result;
1027 if (!(result = malloc(sizeof(*result))))
1028 goto ERROR1;
1029 if (!(result->page_sec = psiconv_empty_page_layout_section()))
1030 goto ERROR2;
1031 if (!(result->texted_sec = psiconv_empty_texted_section()))
1032 goto ERROR3;
1033 return result;
1034 ERROR3:
1035 psiconv_free_page_layout_section(result->page_sec);
1036 ERROR2:
1037 free(result);
1038 ERROR1:
1039 return NULL;
1040 }
1041
1042 psiconv_paint_data_section psiconv_empty_paint_data_section(void)
1043 {
1044 psiconv_paint_data_section result;
1045 if (!(result = malloc(sizeof(*result))))
1046 goto ERROR1;
1047 /* Is this correct? */
1048 result->xsize = result->ysize = result->pic_xsize = result->pic_ysize = 0;
1049 /* Probably forbidden... */
1050 if (!(result->red = malloc(0)))
1051 goto ERROR2;
1052 if (!(result->green = malloc(0)))
1053 goto ERROR3;
1054 if (!(result->blue = malloc(0)))
1055 goto ERROR4;
1056 return result;
1057 ERROR4:
1058 free(result->green);
1059 ERROR3:
1060 free(result->red);
1061 ERROR2:
1062 free(result);
1063 ERROR1:
1064 return NULL;
1065 }
1066
1067
1068 psiconv_pictures psiconv_empty_pictures(void)
1069 {
1070 psiconv_pictures result;
1071 psiconv_paint_data_section pds;
1072 if (!(result = psiconv_list_new(sizeof(struct psiconv_paint_data_section_s))))
1073 goto ERROR1;
1074 if (!(pds = psiconv_empty_paint_data_section()))
1075 goto ERROR2;
1076 if (psiconv_list_add(result,pds))
1077 goto ERROR3;
1078 free(pds);
1079 return result;
1080 ERROR3:
1081 psiconv_free_paint_data_section(pds);
1082 ERROR2:
1083 psiconv_list_free(result);
1084 ERROR1:
1085 return NULL;
1086 }
1087
1088 psiconv_mbm_f psiconv_empty_mbm_f(void)
1089 {
1090 psiconv_mbm_f result;
1091 if (!(result = malloc(sizeof(*result))))
1092 goto ERROR1;
1093 if (!(result->sections = psiconv_empty_pictures()))
1094 goto ERROR2;
1095 return result;
1096 ERROR2:
1097 free(result);
1098 ERROR1:
1099 return NULL;
1100 }
1101
1102 psiconv_sketch_section psiconv_empty_sketch_section(void)
1103 {
1104 psiconv_sketch_section result;
1105 if (!(result = malloc(sizeof(*result))))
1106 goto ERROR1;
1107 result->form_xsize = 320;
1108 result->form_ysize = 200;
1109 result->picture_x_offset = result->picture_y_offset = result->picture_xsize =
1110 result->picture_ysize = 0;
1111 result->magnification_x = result->magnification_y = 1.0;
1112 result->cut_left = result->cut_right = result->cut_top =
1113 result->cut_bottom = 0.0;
1114 if (!(result->picture = psiconv_empty_paint_data_section()))
1115 goto ERROR2;
1116 return result;
1117 ERROR2:
1118 free(result);
1119 ERROR1:
1120 return NULL;
1121 }
1122
1123 psiconv_sketch_f psiconv_empty_sketch_f(void)
1124 {
1125 psiconv_sketch_f result;
1126 if (!(result = malloc(sizeof(*result))))
1127 goto ERROR1;
1128 if (!(result->sketch_sec = psiconv_empty_sketch_section()))
1129 goto ERROR2;
1130 return result;
1131 ERROR2:
1132 free(result);
1133 ERROR1:
1134 return NULL;
1135 }
1136
1137 psiconv_cliparts psiconv_empty_cliparts(void)
1138 {
1139 /* Is this correct? */
1140 return psiconv_list_new(sizeof(struct psiconv_clipart_section_s));
1141 }
1142
1143 psiconv_clipart_f psiconv_empty_clipart_f(void)
1144 {
1145 psiconv_clipart_f result;
1146 if (!(result = malloc(sizeof(*result))))
1147 goto ERROR1;
1148 if (!(result->sections = psiconv_empty_cliparts()))
1149 goto ERROR2;
1150 return result;
1151 ERROR2:
1152 free(result);
1153 ERROR1:
1154 return NULL;
1155 }
1156
1157 psiconv_file psiconv_empty_file(psiconv_file_type_t type)
1158 {
1159 psiconv_file result;
1160 if (!(result = malloc(sizeof(*result))))
1161 return NULL;
1162 result->type = type;
1163 if (type == psiconv_word_file) {
1164 if (!(result->file = psiconv_empty_word_f()))
1165 goto ERROR;
1166 } else if (type == psiconv_sheet_file) {
1167 if (!(result->file = psiconv_empty_sheet_f()))
1168 goto ERROR;
1169 } else if (type == psiconv_texted_file) {
1170 if (!(result->file = psiconv_empty_texted_f()))
1171 goto ERROR;
1172 } else if (type == psiconv_mbm_file) {
1173 if (!(result->file = psiconv_empty_mbm_f()))
1174 goto ERROR;
1175 } else if (type == psiconv_sketch_file) {
1176 if (!(result->file = psiconv_empty_sketch_f()))
1177 goto ERROR;
1178 } else if (type == psiconv_clipart_file) {
1179 if (!(result->file = psiconv_empty_clipart_f()))
1180 goto ERROR;
1181 } else
1182 goto ERROR;
1183 return result;
1184 ERROR:
1185 free(result);
1186 return NULL;
1187 }

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