/[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 94 - (show annotations)
Wed Jan 17 00:05:08 2001 UTC (23 years, 2 months ago) by frodo
File MIME type: text/plain
File size: 31848 byte(s)
(Frodo) Start of Sheet support: base types defined, page and status section
        parsed, supporting definitions in data.c

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

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