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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 98 - (hide annotations)
Mon Jan 29 21:57:05 2001 UTC (23 years, 2 months ago) by frodo
File MIME type: text/plain
File size: 33120 byte(s)
(Frodo) Base formula work

1 frodo 2 /*
2     data.c - Part of psiconv, a PSION 5 file formats converter
3 frodo 63 Copyright (c) 1999, 2000 Frodo Looijaard <frodol@dds.nl>
4 frodo 2
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 frodo 20 #include "compat.h"
22 frodo 2 #include <stdlib.h>
23     #include <string.h>
24     #include "data.h"
25 frodo 87 #include "list.h"
26 frodo 2
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 frodo 12 static void psiconv_free_paint_data_section_aux(void * section);
36 frodo 42 static void psiconv_free_clipart_section_aux(void * section);
37 frodo 2
38 frodo 87 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 frodo 94 static psiconv_sheet_status_section psiconv_empty_sheet_status_section(void);
46 frodo 98 static psiconv_formula_list psiconv_empty_formula_list(void);
47 frodo 95 static psiconv_sheet_workbook_section
48     psiconv_empty_sheet_workbook_section(void);
49 frodo 94 static psiconv_sheet_f psiconv_empty_sheet_f(void);
50 frodo 87 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 frodo 69 /* Note: these defaults seem to be hard-coded somewhere outside the
61     files themself. */
62 frodo 2 psiconv_character_layout psiconv_basic_character_layout(void)
63     {
64 frodo 20 /* Make the structures static, to oblige IRIX */
65 frodo 56 static struct psiconv_color_s black =
66 frodo 2 {
67     0x00, /* red */
68     0x00, /* green */
69     0x00, /* blue */
70     };
71 frodo 56 static struct psiconv_color_s white =
72 frodo 2 {
73     0xff, /* red */
74     0xff, /* green */
75     0xff, /* blue */
76     };
77 frodo 56 static struct psiconv_font_s font =
78 frodo 20 {
79     "Times New Roman", /* name */
80     3 /* screenfont */
81     };
82 frodo 56 struct psiconv_character_layout_s cl =
83 frodo 2 {
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 frodo 67 psiconv_bool_false, /* strikethrough */
92 frodo 24 &font, /* font */
93 frodo 2 };
94    
95     return psiconv_clone_character_layout(&cl);
96     }
97    
98 frodo 69 /* Note: these defaults seem to be hard-coded somewhere outside the
99     files themself. */
100 frodo 2 psiconv_paragraph_layout psiconv_basic_paragraph_layout(void)
101     {
102 frodo 56 static struct psiconv_font_s font =
103 frodo 2 {
104 frodo 20 "Times New Roman", /* name */
105 frodo 2 2 /* screenfont */
106     };
107 frodo 56 static struct psiconv_color_s black =
108 frodo 2 {
109     0x00, /* red */
110     0x00, /* green */
111     0x00, /* blue */
112     };
113 frodo 56 static struct psiconv_color_s white =
114 frodo 2 {
115     0xff, /* red */
116     0xff, /* green */
117     0xff, /* blue */
118     };
119 frodo 56 static struct psiconv_border_s no_border =
120 frodo 2 {
121     psiconv_border_none, /* kind */
122     1, /* thickness */
123     &black /* color */
124     };
125 frodo 56 static struct psiconv_bullet_s bullet =
126 frodo 2 {
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 frodo 56 static struct psiconv_all_tabs_s tabs =
135 frodo 2 {
136     0.64, /* normal */
137     NULL /* kind */
138     };
139 frodo 56 struct psiconv_paragraph_layout_s pl =
140 frodo 2 {
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 frodo 69 10.0, /* linespacing */
148 frodo 67 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 frodo 2 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 frodo 62 if (!(pl.tabs->extras = psiconv_list_new(sizeof(struct psiconv_tab_s))))
166     return NULL;
167 frodo 2 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 frodo 62 if (!(result = malloc(sizeof(*result))))
176     return NULL;
177 frodo 2 *result = *color;
178     return result;
179     }
180    
181     psiconv_font clone_font(psiconv_font font)
182     {
183     psiconv_font result;
184 frodo 62 if(!(result = malloc(sizeof(*result))))
185     goto ERROR1;
186 frodo 2 *result = *font;
187 frodo 62 if (!(result->name = strdup(result->name)))
188     goto ERROR2;
189 frodo 2 return result;
190 frodo 62 ERROR2:
191     free(result);
192     ERROR1:
193     return NULL;
194 frodo 2 }
195    
196     psiconv_border clone_border(psiconv_border border)
197     {
198     psiconv_border result;
199 frodo 62 if (!(result = malloc(sizeof(*result))))
200     goto ERROR1;
201 frodo 2 *result = *border;
202 frodo 62 if(!(result->color = clone_color(result->color)))
203     goto ERROR2;
204 frodo 2 return result;
205 frodo 62 ERROR2:
206     free(result);
207     ERROR1:
208     return NULL;
209 frodo 2 }
210    
211     psiconv_bullet clone_bullet(psiconv_bullet bullet)
212     {
213     psiconv_bullet result;
214 frodo 62 if (!(result = malloc(sizeof(*result))))
215     goto ERROR1;
216 frodo 2 *result = *bullet;
217 frodo 62 if (!(result->font = clone_font(result->font)))
218     goto ERROR2;
219     if (!(result->color = clone_color(result->color)))
220     goto ERROR3;
221 frodo 2 return result;
222 frodo 62 ERROR3:
223     psiconv_free_font(result->font);
224     ERROR2:
225     free(result);
226     ERROR1:
227     return NULL;
228 frodo 2 }
229    
230     psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs)
231     {
232     psiconv_all_tabs result;
233 frodo 62 if (!(result = malloc(sizeof(*result))))
234     goto ERROR1;
235 frodo 2 *result = *all_tabs;
236 frodo 62 if (!(result->extras = psiconv_list_clone(result->extras)))
237     goto ERROR2;
238 frodo 2 return result;
239 frodo 62 ERROR2:
240     free(result);
241     ERROR1:
242     return NULL;
243 frodo 2 }
244    
245     psiconv_character_layout psiconv_clone_character_layout
246     (psiconv_character_layout ls)
247     {
248     psiconv_character_layout result;
249    
250 frodo 62 if (!(result = malloc(sizeof(*result))))
251     goto ERROR1;
252 frodo 2 *result = *ls;
253 frodo 62 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 frodo 2 return result;
260 frodo 62 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 frodo 2 }
269    
270     psiconv_paragraph_layout psiconv_clone_paragraph_layout
271     (psiconv_paragraph_layout ls)
272     {
273     psiconv_paragraph_layout result;
274    
275 frodo 62 if (!(result = malloc(sizeof(*result))))
276     goto ERROR1;
277 frodo 2 *result = *ls;
278 frodo 62 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 frodo 2 return result;
293 frodo 62 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 frodo 2 }
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 frodo 94 void psiconv_free_sheet_status_section(psiconv_sheet_status_section section)
545     {
546     if (section)
547     free(section);
548     }
549    
550 frodo 98 /* TODO: Free sublists, strings etc. depending on formula->type */
551     void psiconv_free_formula(psiconv_formula formula)
552 frodo 97 {
553 frodo 98 if (formula)
554 frodo 97 free(formula);
555     }
556    
557 frodo 98 void psiconv_free_formula_list(psiconv_formula_list list)
558 frodo 97 {
559     if (list)
560     psiconv_list_free(list);
561     }
562    
563 frodo 95 void psiconv_free_sheet_workbook_section(psiconv_sheet_workbook_section section)
564     {
565 frodo 97 if (section) {
566 frodo 98 psiconv_free_formula_list(section->formulas);
567 frodo 95 free(section);
568 frodo 97 }
569 frodo 95 }
570    
571 frodo 94 void psiconv_free_sheet_f(psiconv_sheet_f file)
572     {
573     if (file) {
574     psiconv_free_page_layout_section(file->page_sec);
575     psiconv_free_sheet_status_section(file->status_sec);
576 frodo 95 psiconv_free_sheet_workbook_section(file->workbook_sec);
577 frodo 94 free(file);
578     }
579     }
580    
581 frodo 12 void psiconv_free_texted_f(psiconv_texted_f file)
582     {
583     if (file) {
584     psiconv_free_page_layout_section(file->page_sec);
585     psiconv_free_texted_section(file->texted_sec);
586     free(file);
587     }
588     }
589    
590     void psiconv_free_paint_data_section_aux(void * section)
591     {
592     if (((psiconv_paint_data_section) section)->red)
593     free(((psiconv_paint_data_section)section) -> red);
594     if (((psiconv_paint_data_section) section)->green)
595     free(((psiconv_paint_data_section)section) -> green);
596     if (((psiconv_paint_data_section) section)->blue)
597     free(((psiconv_paint_data_section)section) -> blue);
598     }
599    
600     void psiconv_free_paint_data_section(psiconv_paint_data_section section)
601     {
602     if (section) {
603     psiconv_free_paint_data_section_aux(section);
604     free(section);
605     }
606     }
607    
608     void psiconv_free_pictures(psiconv_pictures section)
609     {
610     if (section)
611     psiconv_list_free_el(section,&psiconv_free_paint_data_section_aux);
612     }
613    
614 frodo 42 void psiconv_free_jumptable_section (psiconv_jumptable_section section)
615 frodo 13 {
616     if (section)
617     psiconv_list_free(section);
618     }
619    
620 frodo 12 void psiconv_free_mbm_f(psiconv_mbm_f file)
621     {
622     if (file) {
623     psiconv_free_pictures(file->sections);
624     free(file);
625     }
626     }
627    
628 frodo 24 void psiconv_free_sketch_section(psiconv_sketch_section sec)
629     {
630     if (sec) {
631     psiconv_free_paint_data_section(sec->picture);
632     free(sec);
633     }
634     }
635    
636     void psiconv_free_sketch_f(psiconv_sketch_f file)
637     {
638     if (file) {
639     psiconv_free_sketch_section(file->sketch_sec);
640     free(file);
641     }
642     }
643    
644 frodo 42 void psiconv_free_clipart_section_aux(void *section)
645 frodo 41 {
646     if (section)
647 frodo 42 free(((psiconv_clipart_section ) section)->picture);
648 frodo 41 }
649    
650     void psiconv_free_clipart_section(psiconv_clipart_section section)
651     {
652     if (section) {
653     psiconv_free_clipart_section_aux(section);
654     free(section);
655     }
656     }
657    
658     void psiconv_free_cliparts(psiconv_cliparts section)
659     {
660     if (section)
661     psiconv_list_free_el(section,&psiconv_free_clipart_section_aux);
662     }
663    
664     void psiconv_free_clipart_f(psiconv_clipart_f file)
665     {
666     if (file) {
667     psiconv_free_cliparts(file->sections);
668     free(file);
669     }
670     }
671    
672 frodo 2 void psiconv_free_file(psiconv_file file)
673     {
674     if (file) {
675     if (file->type == psiconv_word_file)
676     psiconv_free_word_f((psiconv_word_f) file->file);
677 frodo 12 else if (file->type == psiconv_texted_file)
678     psiconv_free_texted_f((psiconv_texted_f) file->file);
679     else if (file->type == psiconv_mbm_file)
680     psiconv_free_mbm_f((psiconv_mbm_f) file->file);
681 frodo 24 else if (file->type == psiconv_sketch_file)
682     psiconv_free_sketch_f((psiconv_sketch_f) file->file);
683 frodo 41 else if (file->type == psiconv_clipart_file)
684 frodo 42 psiconv_free_clipart_f((psiconv_clipart_f) file->file);
685 frodo 94 else if (file->type == psiconv_sheet_file)
686     psiconv_free_sheet_f((psiconv_sheet_f) file->file);
687 frodo 2 free(file);
688     }
689     }
690 frodo 78
691     int psiconv_compare_color(const psiconv_color value1,
692     const psiconv_color value2)
693     {
694     if (!value1 || !value2)
695     return 1;
696     if ((value1->red == value2->red) &&
697     (value1->green == value2->green) &&
698     (value1->blue == value2->blue))
699     return 0;
700     else
701     return 1;
702     }
703    
704     int psiconv_compare_font(const psiconv_font value1,
705     const psiconv_font value2)
706     {
707     if (!value1 || !value2 || !value1->name || !value2->name)
708     return 1;
709     if ((value1->screenfont == value2->screenfont) &&
710     !strcmp(value1->name,value2->name))
711     return 0;
712     else
713     return 1;
714     }
715    
716     int psiconv_compare_border(const psiconv_border value1,
717     const psiconv_border value2)
718     {
719     if (!value1 || !value2)
720     return 1;
721     if ((value1->kind == value2->kind) &&
722     (value1->thickness == value2->thickness) &&
723     !psiconv_compare_color(value1->color,value2->color))
724     return 0;
725     else
726     return 1;
727     }
728    
729     int psiconv_compare_bullet(const psiconv_bullet value1,
730     const psiconv_bullet value2)
731     {
732     if (!value1 || !value2)
733     return 1;
734     if ((value1->on == value2->on) &&
735     (value1->font_size == value2->font_size) &&
736     (value1->character == value2->character) &&
737     (value1->indent == value2->indent) &&
738     !psiconv_compare_color(value1->color,value2->color) &&
739     !psiconv_compare_font(value1->font,value2->font))
740     return 0;
741     else
742     return 1;
743     }
744    
745     int psiconv_compare_tab(const psiconv_tab value1, const psiconv_tab value2)
746     {
747     if (!value1 || !value2)
748     return 1;
749     if ((value1->location == value2->location) &&
750     (value1->kind == value2->kind))
751     return 0;
752     else
753     return 1;
754     }
755    
756     int psiconv_compare_all_tabs(const psiconv_all_tabs value1,
757     const psiconv_all_tabs value2)
758     {
759     int i;
760    
761     if (!value1 || !value2 || !value1->extras || !value2->extras)
762     return 1;
763    
764     if ((value1->normal != value2->normal) ||
765     psiconv_list_length(value1->extras) !=
766     psiconv_list_length(value2->extras))
767     return 1;
768     for (i = 0; i < psiconv_list_length(value1->extras); i++)
769     if (psiconv_compare_tab(psiconv_list_get(value1->extras,i),
770     psiconv_list_get(value2->extras,i)))
771    
772     return 1;
773     return 0;
774     }
775    
776     int psiconv_compare_paragraph_layout(const psiconv_paragraph_layout value1,
777     const psiconv_paragraph_layout value2)
778     {
779     if (!value1 || !value2)
780     return 1;
781     if ((value1->indent_left == value2->indent_left) &&
782     (value1->indent_right == value2->indent_right) &&
783     (value1->indent_first == value2->indent_first) &&
784     (value1->justify_hor == value2->justify_hor) &&
785     (value1->justify_ver == value2->justify_ver) &&
786     (value1->linespacing == value2->linespacing) &&
787     (value1->space_above == value2->space_above) &&
788     (value1->space_below == value2->space_below) &&
789     (value1->keep_together == value2->keep_together) &&
790     (value1->keep_with_next == value2->keep_with_next) &&
791     (value1->on_next_page == value2->on_next_page) &&
792     (value1->no_widow_protection == value2->no_widow_protection) &&
793     (value1->border_distance == value2->border_distance) &&
794     !psiconv_compare_color(value1->back_color,value2->back_color) &&
795     !psiconv_compare_bullet(value1->bullet,value2->bullet) &&
796     !psiconv_compare_border(value1->left_border,value2->left_border) &&
797     !psiconv_compare_border(value1->right_border,value2->right_border) &&
798     !psiconv_compare_border(value1->top_border,value2->top_border) &&
799     !psiconv_compare_border(value1->bottom_border,value2->bottom_border) &&
800     !psiconv_compare_all_tabs(value1->tabs,value2->tabs))
801     return 0;
802     else
803     return 1;
804     }
805    
806    
807     int psiconv_compare_character_layout(const psiconv_character_layout value1,
808     const psiconv_character_layout value2)
809     {
810     if (!value1 || !value2)
811     return 1;
812     if ((value1->font_size == value2->font_size) &&
813     (value1->italic == value2->italic) &&
814     (value1->bold == value2->bold) &&
815     (value1->super_sub == value2->super_sub) &&
816     (value1->underline == value2->underline) &&
817     (value1->strikethrough == value2->strikethrough) &&
818     !psiconv_compare_color(value1->color,value2->color) &&
819     !psiconv_compare_color(value1->back_color,value2->back_color) &&
820     !psiconv_compare_font(value1->font,value2->font))
821     return 0;
822     else
823     return 1;
824     }
825 frodo 87
826    
827    
828     psiconv_word_styles_section psiconv_empty_word_styles_section(void)
829     {
830     psiconv_word_styles_section result;
831     if (!(result = malloc(sizeof(*result))))
832     goto ERROR1;
833     if (!(result->styles = psiconv_list_new(sizeof(struct psiconv_word_style_s))))
834     goto ERROR2;
835     if (!(result->normal = malloc(sizeof(struct psiconv_word_style_s))))
836     goto ERROR3;
837     if (!(result->normal->character = psiconv_basic_character_layout()))
838     goto ERROR4;
839     if (!(result->normal->paragraph = psiconv_basic_paragraph_layout()))
840     goto ERROR5;
841     result->normal->hotkey = 'N';
842     result->normal->name = NULL;
843     result->normal->built_in = psiconv_bool_true;
844     result->normal->outline_level = 0;
845     return result;
846     ERROR5:
847     psiconv_free_character_layout(result->normal->character);
848     ERROR4:
849     free(result->normal);
850     ERROR3:
851     psiconv_list_free(result->styles);
852     ERROR2:
853     free(result);
854     ERROR1:
855     return NULL;
856     }
857    
858     psiconv_text_and_layout psiconv_empty_text_and_layout(void)
859     {
860     return psiconv_list_new(sizeof(struct psiconv_paragraph_s));
861     }
862    
863     psiconv_texted_section psiconv_empty_texted_section(void)
864     {
865     psiconv_texted_section result;
866     if (!(result = malloc(sizeof(*result))))
867     goto ERROR1;
868     if (!(result->paragraphs = psiconv_empty_text_and_layout()))
869     goto ERROR2;
870     return result;
871     ERROR2:
872     free(result);
873     ERROR1:
874     return NULL;
875     }
876    
877     psiconv_page_header psiconv_empty_page_header(void)
878     {
879     psiconv_page_header result;
880     if (!(result = malloc(sizeof(*result))))
881     goto ERROR1;
882     result->on_first_page = psiconv_bool_true;
883     if (!(result->base_paragraph_layout = psiconv_basic_paragraph_layout()))
884     goto ERROR2;
885     if (!(result->base_character_layout = psiconv_basic_character_layout()))
886     goto ERROR3;
887     if (!(result->text = psiconv_empty_texted_section()))
888     goto ERROR4;
889     return result;
890     ERROR4:
891     psiconv_free_character_layout(result->base_character_layout);
892     ERROR3:
893     psiconv_free_paragraph_layout(result->base_paragraph_layout);
894     ERROR2:
895     free(result);
896     ERROR1:
897     return NULL;
898     }
899    
900     psiconv_page_layout_section psiconv_empty_page_layout_section(void)
901     {
902     psiconv_page_layout_section result;
903     if (!(result = malloc(sizeof(*result))))
904     goto ERROR1;
905 frodo 88 result->first_page_nr = 1;
906 frodo 87 result->header_dist = result->footer_dist = 1.27;
907     result->left_margin = result->right_margin = 3.175;
908     result->top_margin = result->bottom_margin = 2.54;
909     result->page_width = 21.0;
910     result->page_height = 29.7;
911     result->landscape = psiconv_bool_false;
912     if (!(result->header = psiconv_empty_page_header()))
913     goto ERROR2;
914     if (!(result->footer = psiconv_empty_page_header()))
915     goto ERROR3;
916     return result;
917     ERROR3:
918     psiconv_free_page_header(result->header);
919     ERROR2:
920     free(result);
921     ERROR1:
922     return NULL;
923     }
924    
925     psiconv_word_status_section psiconv_empty_word_status_section(void)
926     {
927     psiconv_word_status_section result;
928     if (!(result = malloc(sizeof(*result))))
929     return NULL;
930     result->show_tabs = result->show_spaces = result->show_paragraph_ends =
931     result->show_hard_minus = result->show_hard_space =
932     result->fit_lines_to_screen = psiconv_bool_false;
933     result->show_full_pictures = result->show_full_graphs =
934     result->show_top_toolbar = result->show_side_toolbar =
935     psiconv_bool_true;
936     result->cursor_position = 0;
937     result->display_size = 1000;
938     return result;
939     }
940    
941     psiconv_word_f psiconv_empty_word_f(void)
942     {
943     psiconv_word_f result;
944     if (!(result = malloc(sizeof(*result))))
945     goto ERROR1;
946     if (!(result->page_sec = psiconv_empty_page_layout_section()))
947     goto ERROR2;
948     if (!(result->paragraphs = psiconv_empty_text_and_layout()))
949     goto ERROR3;
950     if (!(result->status_sec = psiconv_empty_word_status_section()))
951     goto ERROR4;
952     if (!(result->styles_sec = psiconv_empty_word_styles_section()))
953     goto ERROR5;
954     return result;
955     ERROR5:
956     psiconv_free_word_status_section(result->status_sec);
957     ERROR4:
958     psiconv_free_text_and_layout(result->paragraphs);
959     ERROR3:
960     psiconv_free_page_layout_section(result->page_sec);
961     ERROR2:
962     free(result);
963     ERROR1:
964     return NULL;
965     }
966    
967 frodo 94 psiconv_sheet_status_section psiconv_empty_sheet_status_section(void)
968     {
969     psiconv_sheet_status_section result;
970     if (!(result = malloc(sizeof(*result))))
971     return NULL;
972     result->show_horizontal_scrollbar = result->show_vertical_scrollbar =
973     psiconv_triple_auto;
974     result->show_graph = psiconv_bool_false;
975     result->show_top_sheet_toolbar = result->show_side_sheet_toolbar =
976     result->show_top_graph_toolbar = result->show_side_graph_toolbar =
977     psiconv_bool_true;
978     result->cursor_row = result->cursor_column = 0;
979     result->sheet_display_size = result->graph_display_size = 1000;
980     return result;
981     }
982    
983 frodo 98 psiconv_formula_list psiconv_empty_formula_list(void)
984 frodo 97 {
985 frodo 98 return psiconv_list_new(sizeof(struct psiconv_formula_s));
986 frodo 97 }
987    
988 frodo 95 psiconv_sheet_workbook_section psiconv_empty_sheet_workbook_section(void)
989     {
990     psiconv_sheet_workbook_section result;
991     if (!(result = malloc(sizeof(*result))))
992 frodo 97 goto ERROR1;
993 frodo 98 if (!(result->formulas = psiconv_empty_formula_list()))
994 frodo 97 goto ERROR2;
995 frodo 95 return result;
996 frodo 97 ERROR2:
997     free(result);
998     ERROR1:
999     return NULL;
1000 frodo 95 }
1001    
1002 frodo 97
1003 frodo 94 psiconv_sheet_f psiconv_empty_sheet_f(void)
1004     {
1005     psiconv_sheet_f result;
1006     if (!(result = malloc(sizeof(*result))))
1007     goto ERROR1;
1008     if (!(result->page_sec = psiconv_empty_page_layout_section()))
1009     goto ERROR2;
1010     if (!(result->status_sec = psiconv_empty_sheet_status_section()))
1011     goto ERROR3;
1012 frodo 95 if (!(result->workbook_sec = psiconv_empty_sheet_workbook_section()))
1013     goto ERROR4;
1014 frodo 94 return result;
1015 frodo 95 ERROR4:
1016     psiconv_free_sheet_status_section(result->status_sec);
1017 frodo 94 ERROR3:
1018     psiconv_free_page_layout_section(result->page_sec);
1019     ERROR2:
1020     free(result);
1021     ERROR1:
1022     return NULL;
1023     }
1024    
1025 frodo 87 psiconv_texted_f psiconv_empty_texted_f(void)
1026     {
1027     psiconv_texted_f result;
1028     if (!(result = malloc(sizeof(*result))))
1029     goto ERROR1;
1030     if (!(result->page_sec = psiconv_empty_page_layout_section()))
1031     goto ERROR2;
1032     if (!(result->texted_sec = psiconv_empty_texted_section()))
1033     goto ERROR3;
1034     return result;
1035     ERROR3:
1036     psiconv_free_page_layout_section(result->page_sec);
1037     ERROR2:
1038     free(result);
1039     ERROR1:
1040     return NULL;
1041     }
1042    
1043     psiconv_paint_data_section psiconv_empty_paint_data_section(void)
1044     {
1045     psiconv_paint_data_section result;
1046     if (!(result = malloc(sizeof(*result))))
1047     goto ERROR1;
1048     /* Is this correct? */
1049     result->xsize = result->ysize = result->pic_xsize = result->pic_ysize = 0;
1050     /* Probably forbidden... */
1051     if (!(result->red = malloc(0)))
1052     goto ERROR2;
1053     if (!(result->green = malloc(0)))
1054     goto ERROR3;
1055     if (!(result->blue = malloc(0)))
1056     goto ERROR4;
1057     return result;
1058     ERROR4:
1059     free(result->green);
1060     ERROR3:
1061     free(result->red);
1062     ERROR2:
1063     free(result);
1064     ERROR1:
1065     return NULL;
1066     }
1067    
1068    
1069     psiconv_pictures psiconv_empty_pictures(void)
1070     {
1071     psiconv_pictures result;
1072     psiconv_paint_data_section pds;
1073     if (!(result = psiconv_list_new(sizeof(struct psiconv_paint_data_section_s))))
1074     goto ERROR1;
1075     if (!(pds = psiconv_empty_paint_data_section()))
1076     goto ERROR2;
1077     if (psiconv_list_add(result,pds))
1078     goto ERROR3;
1079     free(pds);
1080     return result;
1081     ERROR3:
1082     psiconv_free_paint_data_section(pds);
1083     ERROR2:
1084     psiconv_list_free(result);
1085     ERROR1:
1086     return NULL;
1087     }
1088    
1089     psiconv_mbm_f psiconv_empty_mbm_f(void)
1090     {
1091     psiconv_mbm_f result;
1092     if (!(result = malloc(sizeof(*result))))
1093     goto ERROR1;
1094     if (!(result->sections = psiconv_empty_pictures()))
1095     goto ERROR2;
1096     return result;
1097     ERROR2:
1098     free(result);
1099     ERROR1:
1100     return NULL;
1101     }
1102    
1103     psiconv_sketch_section psiconv_empty_sketch_section(void)
1104     {
1105     psiconv_sketch_section result;
1106     if (!(result = malloc(sizeof(*result))))
1107     goto ERROR1;
1108     result->form_xsize = 320;
1109     result->form_ysize = 200;
1110     result->picture_x_offset = result->picture_y_offset = result->picture_xsize =
1111     result->picture_ysize = 0;
1112     result->magnification_x = result->magnification_y = 1.0;
1113     result->cut_left = result->cut_right = result->cut_top =
1114     result->cut_bottom = 0.0;
1115     if (!(result->picture = psiconv_empty_paint_data_section()))
1116     goto ERROR2;
1117     return result;
1118     ERROR2:
1119     free(result);
1120     ERROR1:
1121     return NULL;
1122     }
1123    
1124     psiconv_sketch_f psiconv_empty_sketch_f(void)
1125     {
1126     psiconv_sketch_f result;
1127     if (!(result = malloc(sizeof(*result))))
1128     goto ERROR1;
1129     if (!(result->sketch_sec = psiconv_empty_sketch_section()))
1130     goto ERROR2;
1131     return result;
1132     ERROR2:
1133     free(result);
1134     ERROR1:
1135     return NULL;
1136     }
1137    
1138     psiconv_cliparts psiconv_empty_cliparts(void)
1139     {
1140     /* Is this correct? */
1141     return psiconv_list_new(sizeof(struct psiconv_clipart_section_s));
1142     }
1143    
1144     psiconv_clipart_f psiconv_empty_clipart_f(void)
1145     {
1146     psiconv_clipart_f result;
1147     if (!(result = malloc(sizeof(*result))))
1148     goto ERROR1;
1149     if (!(result->sections = psiconv_empty_cliparts()))
1150     goto ERROR2;
1151     return result;
1152     ERROR2:
1153     free(result);
1154     ERROR1:
1155     return NULL;
1156     }
1157    
1158     psiconv_file psiconv_empty_file(psiconv_file_type_t type)
1159     {
1160     psiconv_file result;
1161     if (!(result = malloc(sizeof(*result))))
1162     return NULL;
1163     result->type = type;
1164     if (type == psiconv_word_file) {
1165     if (!(result->file = psiconv_empty_word_f()))
1166     goto ERROR;
1167 frodo 94 } else if (type == psiconv_sheet_file) {
1168     if (!(result->file = psiconv_empty_sheet_f()))
1169     goto ERROR;
1170 frodo 87 } else if (type == psiconv_texted_file) {
1171     if (!(result->file = psiconv_empty_texted_f()))
1172     goto ERROR;
1173     } else if (type == psiconv_mbm_file) {
1174     if (!(result->file = psiconv_empty_mbm_f()))
1175     goto ERROR;
1176     } else if (type == psiconv_sketch_file) {
1177     if (!(result->file = psiconv_empty_sketch_f()))
1178     goto ERROR;
1179     } else if (type == psiconv_clipart_file) {
1180     if (!(result->file = psiconv_empty_clipart_f()))
1181     goto ERROR;
1182     } else
1183     goto ERROR;
1184     return result;
1185     ERROR:
1186     free(result);
1187     return NULL;
1188     }

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