/[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 110 - (hide annotations)
Sun Mar 4 22:10:45 2001 UTC (23 years, 1 month ago) by frodo
File MIME type: text/plain
File size: 35204 byte(s)
(Frodo) Thomas Decsi's major sheet patch

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

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