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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 78 Revision 270
1/* 1/*
2 data.c - Part of psiconv, a PSION 5 file formats converter 2 data.c - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 1999, 2000 Frodo Looijaard <frodol@dds.nl> 3 Copyright (c) 1999-2005 Frodo Looijaard <frodo@frodo.looijaard.name>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
20#include "config.h" 20#include "config.h"
21#include "compat.h" 21#include "compat.h"
22#include <stdlib.h> 22#include <stdlib.h>
23#include <string.h> 23#include <string.h>
24#include "data.h" 24#include "data.h"
25#include "list.h"
26#include "unicode.h"
27#include "error.h"
28
29#ifdef DMALLOC
30#include <dmalloc.h>
31#endif
25 32
26static psiconv_color clone_color(psiconv_color color); 33static psiconv_color clone_color(psiconv_color color);
27static psiconv_font clone_font(psiconv_font font); 34static psiconv_font clone_font(psiconv_font font);
28static psiconv_border clone_border(psiconv_border border); 35static psiconv_border clone_border(psiconv_border border);
29static psiconv_bullet clone_bullet(psiconv_bullet bullet); 36static psiconv_bullet clone_bullet(psiconv_bullet bullet);
31static void psiconv_free_style_aux(void *style); 38static void psiconv_free_style_aux(void *style);
32static void psiconv_free_in_line_layout_aux(void * layout); 39static void psiconv_free_in_line_layout_aux(void * layout);
33static void psiconv_free_paragraph_aux(void * paragraph); 40static void psiconv_free_paragraph_aux(void * paragraph);
34static void psiconv_free_paint_data_section_aux(void * section); 41static void psiconv_free_paint_data_section_aux(void * section);
35static void psiconv_free_clipart_section_aux(void * section); 42static void psiconv_free_clipart_section_aux(void * section);
43static void psiconv_free_formula_aux(void *data);
44static void psiconv_free_sheet_worksheet_aux (void *data);
45static void psiconv_free_sheet_variable_aux(void * variable);
46static void psiconv_free_sheet_cell_aux(void *cell);
47static void psiconv_free_sheet_line_aux(void *line);
48static void psiconv_free_sheet_worksheet_aux (void *data);
49
50static psiconv_word_styles_section psiconv_empty_word_styles_section(void);
51static psiconv_text_and_layout psiconv_empty_text_and_layout(void);
52static psiconv_texted_section psiconv_empty_texted_section(void);
53static psiconv_page_header psiconv_empty_page_header(void);
54static psiconv_page_layout_section psiconv_empty_page_layout_section(void);
55static psiconv_word_status_section psiconv_empty_word_status_section(void);
56static psiconv_word_f psiconv_empty_word_f(void);
57static psiconv_sheet_status_section psiconv_empty_sheet_status_section(void);
58static psiconv_formula_list psiconv_empty_formula_list(void);
59static psiconv_sheet_workbook_section
60 psiconv_empty_sheet_workbook_section(void);
61static psiconv_sheet_f psiconv_empty_sheet_f(void);
62static psiconv_texted_f psiconv_empty_texted_f(void);
63static psiconv_paint_data_section psiconv_empty_paint_data_section(void);
64static psiconv_pictures psiconv_empty_pictures(void);
65static psiconv_mbm_f psiconv_empty_mbm_f(void);
66static psiconv_sketch_section psiconv_empty_sketch_section(void);
67static psiconv_sketch_f psiconv_empty_sketch_f(void);
68static psiconv_clipart_f psiconv_empty_clipart_f(void);
69static psiconv_cliparts psiconv_empty_cliparts(void);
70
36 71
37/* Note: these defaults seem to be hard-coded somewhere outside the 72/* Note: these defaults seem to be hard-coded somewhere outside the
38 files themself. */ 73 files themself. */
39psiconv_character_layout psiconv_basic_character_layout(void) 74psiconv_character_layout psiconv_basic_character_layout(void)
40{ 75{
49 { 84 {
50 0xff, /* red */ 85 0xff, /* red */
51 0xff, /* green */ 86 0xff, /* green */
52 0xff, /* blue */ 87 0xff, /* blue */
53 }; 88 };
89 static psiconv_ucs2 font_times[16] = { 'T','i','m','e','s',' ',
90 'N','e','w',' ',
91 'R','o','m','a','n',0 };
54 static struct psiconv_font_s font = 92 static struct psiconv_font_s font =
55 { 93 {
56 "Times New Roman", /* name */ 94 font_times, /* name */
57 3 /* screenfont */ 95 3 /* screenfont */
58 }; 96 };
59 struct psiconv_character_layout_s cl = 97 struct psiconv_character_layout_s cl =
60 { 98 {
61 &black, /* color */ 99 &black, /* color */
74 112
75/* Note: these defaults seem to be hard-coded somewhere outside the 113/* Note: these defaults seem to be hard-coded somewhere outside the
76 files themself. */ 114 files themself. */
77psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) 115psiconv_paragraph_layout psiconv_basic_paragraph_layout(void)
78{ 116{
117 static psiconv_ucs2 font_times[16] = { 'T','i','m','e','s',' ',
118 'N','e','w',' ',
119 'R','o','m','a','n',0 };
120
79 static struct psiconv_font_s font = 121 static struct psiconv_font_s font =
80 { 122 {
81 "Times New Roman", /* name */ 123 font_times, /* name */
82 2 /* screenfont */ 124 2 /* screenfont */
83 }; 125 };
84 static struct psiconv_color_s black = 126 static struct psiconv_color_s black =
85 { 127 {
86 0x00, /* red */ 128 0x00, /* red */
101 }; 143 };
102 static struct psiconv_bullet_s bullet = 144 static struct psiconv_bullet_s bullet =
103 { 145 {
104 psiconv_bool_false, /* on */ 146 psiconv_bool_false, /* on */
105 10.0, /* font_size */ 147 10.0, /* font_size */
106 0x95, /* character */ 148 0x201d, /* character */
107 psiconv_bool_true, /* indent */ 149 psiconv_bool_true, /* indent */
108 &black, /* color */ 150 &black, /* color */
109 &font, /* font */ 151 &font, /* font */
110 }; 152 };
111 static struct psiconv_all_tabs_s tabs = 153 static struct psiconv_all_tabs_s tabs =
127 0.0, /* space_below */ 169 0.0, /* space_below */
128 psiconv_bool_false, /* keep_together */ 170 psiconv_bool_false, /* keep_together */
129 psiconv_bool_false, /* keep_with_next */ 171 psiconv_bool_false, /* keep_with_next */
130 psiconv_bool_false, /* on_next_page */ 172 psiconv_bool_false, /* on_next_page */
131 psiconv_bool_false, /* no_widow_protection */ 173 psiconv_bool_false, /* no_widow_protection */
174 psiconv_bool_false, /* wrap_to_fit_cell */
132 0.0, /* left_margin */ 175 0.0, /* left_margin */
133 &bullet, /* bullet */ 176 &bullet, /* bullet */
134 &no_border, /* left_border */ 177 &no_border, /* left_border */
135 &no_border, /* right_border */ 178 &no_border, /* right_border */
136 &no_border, /* top_border */ 179 &no_border, /* top_border */
159{ 202{
160 psiconv_font result; 203 psiconv_font result;
161 if(!(result = malloc(sizeof(*result)))) 204 if(!(result = malloc(sizeof(*result))))
162 goto ERROR1; 205 goto ERROR1;
163 *result = *font; 206 *result = *font;
164 if (!(result->name = strdup(result->name))) 207 if (!(result->name = psiconv_unicode_strdup(result->name)))
165 goto ERROR2; 208 goto ERROR2;
166 return result; 209 return result;
167ERROR2: 210ERROR2:
168 free(result); 211 free(result);
169ERROR1: 212ERROR1:
291 return ss->normal; 334 return ss->normal;
292 else 335 else
293 return psiconv_list_get(ss->styles,0xff - nr); 336 return psiconv_list_get(ss->styles,0xff - nr);
294} 337}
295 338
339int psiconv_find_style(const psiconv_word_styles_section ss,
340 const psiconv_ucs2 *name,
341 int *nr)
342{
343 const psiconv_ucs2 value_normal[] = { 'N','o','r','m','a','l',0 };
344 psiconv_word_style style;
345 int i;
346
347 if (!nr)
348 return PSICONV_E_OTHER;
349 if(!psiconv_unicode_strcmp(value_normal,name)) {
350 *nr = 0;
351 return 0;
352 }
353 for (i = 0; i < psiconv_list_length(ss->styles);i++) {
354 if (!(style = psiconv_list_get(ss->styles,i)))
355 return PSICONV_E_NOMEM;
356 if (!psiconv_unicode_strcmp(style->name,name)) {
357 *nr = 0xff - i;
358 return 0;
359 }
360 }
361 *nr = 0;
362 return PSICONV_E_OTHER;
363}
364
365
366psiconv_formula psiconv_get_formula (psiconv_formula_list ss, int nr)
367{
368 return psiconv_list_get(ss,psiconv_list_length(ss)-nr-1);
369}
370
371/* TODO: What if a cell is both in a default row and a default column?!? */
372psiconv_sheet_cell_layout psiconv_get_default_layout
373 (psiconv_sheet_line_list row_defaults,
374 psiconv_sheet_line_list col_defaults,
375 psiconv_sheet_cell_layout cell_default,
376 int row,int col)
377{
378 int i;
379 psiconv_sheet_line line;
380 for (i = 0;i < psiconv_list_length(row_defaults);i++) {
381 line = psiconv_list_get(row_defaults,i);
382 if (line->position == row)
383 return line->layout;
384 }
385 for (i = 0;i < psiconv_list_length(col_defaults);i++) {
386 line = psiconv_list_get(col_defaults,i);
387 if (line->position == col)
388 return line->layout;
389 }
390 return cell_default;
391}
392
393
296void psiconv_free_color (psiconv_color color) 394void psiconv_free_color (psiconv_color color)
297{ 395{
298 if (color) 396 if (color)
299 free(color); 397 free(color);
300} 398}
377 psiconv_free_style_aux(style); 475 psiconv_free_style_aux(style);
378 free(style); 476 free(style);
379 } 477 }
380} 478}
381 479
480void psiconv_free_word_style_list(psiconv_word_style_list style_list)
481{
482 if (style_list)
483 psiconv_list_free_el(style_list,psiconv_free_style_aux);
484}
485
382void psiconv_free_word_styles_section(psiconv_word_styles_section styles) 486void psiconv_free_word_styles_section(psiconv_word_styles_section styles)
383{ 487{
384 if (styles) { 488 if (styles) {
385 psiconv_free_word_style(styles->normal); 489 psiconv_free_word_style(styles->normal);
386 if (styles->styles) 490 psiconv_free_word_style_list(styles->styles);
387 psiconv_list_free_el(styles->styles,psiconv_free_style_aux); 491 free(styles);
388 } 492 }
389} 493}
390 494
391void psiconv_free_header_section(psiconv_header_section header) 495void psiconv_free_header_section(psiconv_header_section header)
392{ 496{
413 free(section->name); 517 free(section->name);
414 free(section); 518 free(section);
415 } 519 }
416} 520}
417 521
522void psiconv_free_object_icon_section(psiconv_object_icon_section section)
523{
524 if (section) {
525 if (section->icon_name)
526 free(section->icon_name);
527 free(section);
528 }
529}
530
531void psiconv_free_object_display_section(psiconv_object_display_section section)
532{
533 if (section)
534 free(section);
535}
536
537void psiconv_free_embedded_object_section
538 (psiconv_embedded_object_section object)
539{
540 if (object) {
541 psiconv_free_object_icon_section(object->icon);
542 psiconv_free_object_display_section(object->display);
543 psiconv_free_file(object->object);
544 free(object);
545 }
546}
547
418void psiconv_free_in_line_layout_aux(void * layout) 548void psiconv_free_in_line_layout_aux(void * layout)
419{ 549{
420 psiconv_free_character_layout(((psiconv_in_line_layout) layout)->layout); 550 psiconv_free_character_layout(((psiconv_in_line_layout) layout)->layout);
551 psiconv_free_embedded_object_section
552 (((psiconv_in_line_layout) layout)->object);
421} 553}
422 554
423void psiconv_free_in_line_layout(psiconv_in_line_layout layout) 555void psiconv_free_in_line_layout(psiconv_in_line_layout layout)
424{ 556{
425 if (layout) { 557 if (layout) {
516 psiconv_free_word_styles_section(file->styles_sec); 648 psiconv_free_word_styles_section(file->styles_sec);
517 free(file); 649 free(file);
518 } 650 }
519} 651}
520 652
653void psiconv_free_sheet_status_section(psiconv_sheet_status_section section)
654{
655 if (section)
656 free(section);
657}
658
659void psiconv_free_sheet_numberformat(psiconv_sheet_numberformat numberformat)
660{
661 if (numberformat)
662 free(numberformat);
663}
664
665void psiconv_free_sheet_cell_layout(psiconv_sheet_cell_layout layout)
666{
667 psiconv_free_paragraph_layout(layout->paragraph);
668 psiconv_free_character_layout(layout->character);
669 psiconv_free_sheet_numberformat(layout->numberformat);
670}
671
672void psiconv_free_sheet_cell_aux(void *cell)
673{
674 psiconv_sheet_cell data = cell;
675
676 psiconv_free_sheet_cell_layout(data->layout);
677
678 if ((data->type == psiconv_cell_string) && (data->data.dat_string))
679 free(data->data.dat_string);
680}
681
682void psiconv_free_sheet_cell(psiconv_sheet_cell cell)
683{
684 if (cell) {
685 psiconv_free_sheet_cell_aux(cell);
686 free(cell);
687 }
688}
689
690void psiconv_free_sheet_cell_list(psiconv_sheet_cell_list list)
691{
692 if (list)
693 psiconv_list_free_el(list,psiconv_free_sheet_cell_aux);
694}
695
696void psiconv_free_sheet_line_aux(void *line)
697{
698 psiconv_sheet_line data = line;
699
700 psiconv_free_sheet_cell_layout(data->layout);
701}
702
703void psiconv_free_sheet_line(psiconv_sheet_line line)
704{
705 if (line) {
706 psiconv_free_sheet_line_aux(line);
707 free(line);
708 }
709}
710
711
712void psiconv_free_sheet_line_list(psiconv_sheet_line_list list)
713{
714 if (list)
715 psiconv_list_free_el(list,psiconv_free_sheet_line_aux);
716}
717
718void psiconv_free_sheet_grid_break_list(psiconv_sheet_grid_break_list list)
719{
720 if (list)
721 psiconv_list_free(list);
722}
723
724void psiconv_free_sheet_grid_size(psiconv_sheet_grid_size s)
725{
726 if (s)
727 free(s);
728}
729
730void psiconv_free_sheet_grid_size_list(psiconv_sheet_grid_size_list list)
731{
732 if (list)
733 psiconv_list_free(list);
734}
735
736void psiconv_free_sheet_grid_section(psiconv_sheet_grid_section sec)
737{
738 if (sec) {
739 psiconv_free_sheet_grid_size_list(sec->row_heights);
740 psiconv_free_sheet_grid_size_list(sec->column_heights);
741 psiconv_free_sheet_grid_break_list(sec->row_page_breaks);
742 psiconv_free_sheet_grid_break_list(sec->column_page_breaks);
743 free(sec);
744 }
745}
746
747void psiconv_free_sheet_worksheet_aux (void *data)
748{
749 psiconv_sheet_worksheet section = data;
750 psiconv_free_sheet_cell_layout(section->default_layout);
751 psiconv_free_sheet_cell_list(section->cells);
752 psiconv_free_sheet_line_list(section->row_default_layouts);
753 psiconv_free_sheet_line_list(section->col_default_layouts);
754 psiconv_free_sheet_grid_section(section->grid);
755}
756
757void psiconv_free_sheet_worksheet(psiconv_sheet_worksheet sheet)
758{
759 if (sheet) {
760 psiconv_free_sheet_worksheet_aux(sheet);
761 free(sheet);
762 }
763}
764
765void psiconv_free_sheet_worksheet_list(psiconv_sheet_worksheet_list list)
766{
767 if (list)
768 psiconv_list_free_el(list,psiconv_free_sheet_worksheet_aux);
769}
770
771void psiconv_free_formula_aux(void *data)
772{
773 psiconv_formula formula;
774 formula = data;
775 if (formula->type == psiconv_formula_dat_string)
776 free(formula->data.dat_string);
777 else if ((formula->type != psiconv_formula_dat_int) &&
778 (formula->type != psiconv_formula_dat_var) &&
779 (formula->type != psiconv_formula_dat_float) &&
780 (formula->type != psiconv_formula_dat_cellref) &&
781 (formula->type != psiconv_formula_dat_cellblock) &&
782 (formula->type != psiconv_formula_dat_vcellblock) &&
783 (formula->type != psiconv_formula_mark_opsep) &&
784 (formula->type != psiconv_formula_mark_opend) &&
785 (formula->type != psiconv_formula_mark_eof) &&
786 (formula->type != psiconv_formula_unknown))
787 psiconv_free_formula_list(formula->data.fun_operands);
788}
789
790void psiconv_free_formula(psiconv_formula formula)
791{
792 if (formula) {
793 psiconv_free_formula_aux(formula);
794 free(formula);
795 }
796}
797
798void psiconv_free_formula_list(psiconv_formula_list list)
799{
800 if (list)
801 psiconv_list_free_el(list,psiconv_free_formula_aux);
802}
803
804void psiconv_free_sheet_name_section(psiconv_sheet_name_section section)
805{
806 if (section) {
807 if(section->name)
808 free(section->name);
809 free(section);
810 }
811}
812
813void psiconv_free_sheet_info_section(psiconv_sheet_info_section section)
814{
815 if (section) {
816 free(section);
817 }
818}
819
820void psiconv_free_sheet_variable_aux(void * variable)
821{
822 psiconv_sheet_variable var = variable;
823 if (var->name)
824 free(var->name);
825 if (var->type == psiconv_var_string)
826 free(var->data.dat_string);
827}
828
829void psiconv_free_sheet_variable(psiconv_sheet_variable var)
830{
831 if (var) {
832 psiconv_free_sheet_variable_aux(var);
833 free(var);
834 }
835}
836
837void psiconv_free_sheet_variable_list(psiconv_sheet_variable_list list)
838{
839 if (list)
840 psiconv_list_free_el(list,psiconv_free_sheet_variable_aux);
841}
842
843void psiconv_free_sheet_workbook_section(psiconv_sheet_workbook_section section)
844{
845 if (section) {
846 psiconv_free_formula_list(section->formulas);
847 psiconv_free_sheet_worksheet_list(section->worksheets);
848 psiconv_free_sheet_name_section(section->name);
849 psiconv_free_sheet_info_section(section->info);
850 psiconv_free_sheet_variable_list(section->variables);
851 free(section);
852 }
853}
854
855void psiconv_free_sheet_f(psiconv_sheet_f file)
856{
857 if (file) {
858 psiconv_free_page_layout_section(file->page_sec);
859 psiconv_free_sheet_status_section(file->status_sec);
860 psiconv_free_sheet_workbook_section(file->workbook_sec);
861 free(file);
862 }
863}
864
521void psiconv_free_texted_f(psiconv_texted_f file) 865void psiconv_free_texted_f(psiconv_texted_f file)
522{ 866{
523 if (file) { 867 if (file) {
524 psiconv_free_page_layout_section(file->page_sec); 868 psiconv_free_page_layout_section(file->page_sec);
525 psiconv_free_texted_section(file->texted_sec); 869 psiconv_free_texted_section(file->texted_sec);
582} 926}
583 927
584void psiconv_free_clipart_section_aux(void *section) 928void psiconv_free_clipart_section_aux(void *section)
585{ 929{
586 if (section) 930 if (section)
587 free(((psiconv_clipart_section ) section)->picture); 931 psiconv_free_paint_data_section(((psiconv_clipart_section) section)->picture);
588} 932}
589 933
590void psiconv_free_clipart_section(psiconv_clipart_section section) 934void psiconv_free_clipart_section(psiconv_clipart_section section)
591{ 935{
592 if (section) { 936 if (section) {
620 psiconv_free_mbm_f((psiconv_mbm_f) file->file); 964 psiconv_free_mbm_f((psiconv_mbm_f) file->file);
621 else if (file->type == psiconv_sketch_file) 965 else if (file->type == psiconv_sketch_file)
622 psiconv_free_sketch_f((psiconv_sketch_f) file->file); 966 psiconv_free_sketch_f((psiconv_sketch_f) file->file);
623 else if (file->type == psiconv_clipart_file) 967 else if (file->type == psiconv_clipart_file)
624 psiconv_free_clipart_f((psiconv_clipart_f) file->file); 968 psiconv_free_clipart_f((psiconv_clipart_f) file->file);
969 else if (file->type == psiconv_sheet_file)
970 psiconv_free_sheet_f((psiconv_sheet_f) file->file);
625 free(file); 971 free(file);
626 } 972 }
627} 973}
628 974
629int psiconv_compare_color(const psiconv_color value1, 975int psiconv_compare_color(const psiconv_color value1,
643 const psiconv_font value2) 989 const psiconv_font value2)
644{ 990{
645 if (!value1 || !value2 || !value1->name || !value2->name) 991 if (!value1 || !value2 || !value1->name || !value2->name)
646 return 1; 992 return 1;
647 if ((value1->screenfont == value2->screenfont) && 993 if ((value1->screenfont == value2->screenfont) &&
648 !strcmp(value1->name,value2->name)) 994 !psiconv_unicode_strcmp(value1->name,value2->name))
649 return 0; 995 return 0;
650 else 996 else
651 return 1; 997 return 1;
652} 998}
653 999
758 !psiconv_compare_font(value1->font,value2->font)) 1104 !psiconv_compare_font(value1->font,value2->font))
759 return 0; 1105 return 0;
760 else 1106 else
761 return 1; 1107 return 1;
762} 1108}
1109
1110
1111
1112psiconv_word_styles_section psiconv_empty_word_styles_section(void)
1113{
1114 psiconv_word_styles_section result;
1115 if (!(result = malloc(sizeof(*result))))
1116 goto ERROR1;
1117 if (!(result->styles = psiconv_list_new(sizeof(struct psiconv_word_style_s))))
1118 goto ERROR2;
1119 if (!(result->normal = malloc(sizeof(struct psiconv_word_style_s))))
1120 goto ERROR3;
1121 if (!(result->normal->character = psiconv_basic_character_layout()))
1122 goto ERROR4;
1123 if (!(result->normal->paragraph = psiconv_basic_paragraph_layout()))
1124 goto ERROR5;
1125 result->normal->hotkey = 'N';
1126 result->normal->name = NULL;
1127 result->normal->built_in = psiconv_bool_true;
1128 result->normal->outline_level = 0;
1129 return result;
1130ERROR5:
1131 psiconv_free_character_layout(result->normal->character);
1132ERROR4:
1133 free(result->normal);
1134ERROR3:
1135 psiconv_list_free(result->styles);
1136ERROR2:
1137 free(result);
1138ERROR1:
1139 return NULL;
1140}
1141
1142psiconv_text_and_layout psiconv_empty_text_and_layout(void)
1143{
1144 return psiconv_list_new(sizeof(struct psiconv_paragraph_s));
1145}
1146
1147psiconv_texted_section psiconv_empty_texted_section(void)
1148{
1149 psiconv_texted_section result;
1150 if (!(result = malloc(sizeof(*result))))
1151 goto ERROR1;
1152 if (!(result->paragraphs = psiconv_empty_text_and_layout()))
1153 goto ERROR2;
1154 return result;
1155ERROR2:
1156 free(result);
1157ERROR1:
1158 return NULL;
1159}
1160
1161psiconv_page_header psiconv_empty_page_header(void)
1162{
1163 psiconv_page_header result;
1164 if (!(result = malloc(sizeof(*result))))
1165 goto ERROR1;
1166 result->on_first_page = psiconv_bool_true;
1167 if (!(result->base_paragraph_layout = psiconv_basic_paragraph_layout()))
1168 goto ERROR2;
1169 if (!(result->base_character_layout = psiconv_basic_character_layout()))
1170 goto ERROR3;
1171 if (!(result->text = psiconv_empty_texted_section()))
1172 goto ERROR4;
1173 return result;
1174ERROR4:
1175 psiconv_free_character_layout(result->base_character_layout);
1176ERROR3:
1177 psiconv_free_paragraph_layout(result->base_paragraph_layout);
1178ERROR2:
1179 free(result);
1180ERROR1:
1181 return NULL;
1182}
1183
1184psiconv_page_layout_section psiconv_empty_page_layout_section(void)
1185{
1186 psiconv_page_layout_section result;
1187 if (!(result = malloc(sizeof(*result))))
1188 goto ERROR1;
1189 result->first_page_nr = 1;
1190 result->header_dist = result->footer_dist = 1.27;
1191 result->left_margin = result->right_margin = 3.175;
1192 result->top_margin = result->bottom_margin = 2.54;
1193 result->page_width = 21.0;
1194 result->page_height = 29.7;
1195 result->landscape = psiconv_bool_false;
1196 if (!(result->header = psiconv_empty_page_header()))
1197 goto ERROR2;
1198 if (!(result->footer = psiconv_empty_page_header()))
1199 goto ERROR3;
1200 return result;
1201ERROR3:
1202 psiconv_free_page_header(result->header);
1203ERROR2:
1204 free(result);
1205ERROR1:
1206 return NULL;
1207}
1208
1209psiconv_word_status_section psiconv_empty_word_status_section(void)
1210{
1211 psiconv_word_status_section result;
1212 if (!(result = malloc(sizeof(*result))))
1213 return NULL;
1214 result->show_tabs = result->show_spaces = result->show_paragraph_ends =
1215 result->show_hard_minus = result->show_hard_space =
1216 result->fit_lines_to_screen = psiconv_bool_false;
1217 result->show_full_pictures = result->show_full_graphs =
1218 result->show_top_toolbar = result->show_side_toolbar =
1219 psiconv_bool_true;
1220 result->cursor_position = 0;
1221 result->display_size = 1000;
1222 return result;
1223}
1224
1225psiconv_word_f psiconv_empty_word_f(void)
1226{
1227 psiconv_word_f result;
1228 if (!(result = malloc(sizeof(*result))))
1229 goto ERROR1;
1230 if (!(result->page_sec = psiconv_empty_page_layout_section()))
1231 goto ERROR2;
1232 if (!(result->paragraphs = psiconv_empty_text_and_layout()))
1233 goto ERROR3;
1234 if (!(result->status_sec = psiconv_empty_word_status_section()))
1235 goto ERROR4;
1236 if (!(result->styles_sec = psiconv_empty_word_styles_section()))
1237 goto ERROR5;
1238 return result;
1239ERROR5:
1240 psiconv_free_word_status_section(result->status_sec);
1241ERROR4:
1242 psiconv_free_text_and_layout(result->paragraphs);
1243ERROR3:
1244 psiconv_free_page_layout_section(result->page_sec);
1245ERROR2:
1246 free(result);
1247ERROR1:
1248 return NULL;
1249}
1250
1251psiconv_sheet_status_section psiconv_empty_sheet_status_section(void)
1252{
1253 psiconv_sheet_status_section result;
1254 if (!(result = malloc(sizeof(*result))))
1255 return NULL;
1256 result->show_horizontal_scrollbar = result->show_vertical_scrollbar =
1257 psiconv_triple_auto;
1258 result->show_graph = psiconv_bool_false;
1259 result->show_top_sheet_toolbar = result->show_side_sheet_toolbar =
1260 result->show_top_graph_toolbar = result->show_side_graph_toolbar =
1261 psiconv_bool_true;
1262 result->cursor_row = result->cursor_column = 0;
1263 result->sheet_display_size = result->graph_display_size = 1000;
1264 return result;
1265}
1266
1267psiconv_formula_list psiconv_empty_formula_list(void)
1268{
1269 return psiconv_list_new(sizeof(struct psiconv_formula_s));
1270}
1271
1272psiconv_sheet_workbook_section psiconv_empty_sheet_workbook_section(void)
1273{
1274 psiconv_sheet_workbook_section result;
1275 if (!(result = malloc(sizeof(*result))))
1276 goto ERROR1;
1277 if (!(result->formulas = psiconv_empty_formula_list()))
1278 goto ERROR2;
1279 return result;
1280ERROR2:
1281 free(result);
1282ERROR1:
1283 return NULL;
1284}
1285
1286
1287psiconv_sheet_f psiconv_empty_sheet_f(void)
1288{
1289 psiconv_sheet_f result;
1290 if (!(result = malloc(sizeof(*result))))
1291 goto ERROR1;
1292 if (!(result->page_sec = psiconv_empty_page_layout_section()))
1293 goto ERROR2;
1294 if (!(result->status_sec = psiconv_empty_sheet_status_section()))
1295 goto ERROR3;
1296 if (!(result->workbook_sec = psiconv_empty_sheet_workbook_section()))
1297 goto ERROR4;
1298 return result;
1299ERROR4:
1300 psiconv_free_sheet_status_section(result->status_sec);
1301ERROR3:
1302 psiconv_free_page_layout_section(result->page_sec);
1303ERROR2:
1304 free(result);
1305ERROR1:
1306 return NULL;
1307}
1308
1309psiconv_texted_f psiconv_empty_texted_f(void)
1310{
1311 psiconv_texted_f result;
1312 if (!(result = malloc(sizeof(*result))))
1313 goto ERROR1;
1314 if (!(result->page_sec = psiconv_empty_page_layout_section()))
1315 goto ERROR2;
1316 if (!(result->texted_sec = psiconv_empty_texted_section()))
1317 goto ERROR3;
1318 return result;
1319ERROR3:
1320 psiconv_free_page_layout_section(result->page_sec);
1321ERROR2:
1322 free(result);
1323ERROR1:
1324 return NULL;
1325}
1326
1327psiconv_paint_data_section psiconv_empty_paint_data_section(void)
1328{
1329 psiconv_paint_data_section result;
1330 if (!(result = malloc(sizeof(*result))))
1331 goto ERROR1;
1332 /* Is this correct? */
1333 result->xsize = result->ysize = result->pic_xsize = result->pic_ysize = 0;
1334 /* Probably forbidden... */
1335 if (!(result->red = malloc(0)))
1336 goto ERROR2;
1337 if (!(result->green = malloc(0)))
1338 goto ERROR3;
1339 if (!(result->blue = malloc(0)))
1340 goto ERROR4;
1341 return result;
1342ERROR4:
1343 free(result->green);
1344ERROR3:
1345 free(result->red);
1346ERROR2:
1347 free(result);
1348ERROR1:
1349 return NULL;
1350}
1351
1352
1353psiconv_pictures psiconv_empty_pictures(void)
1354{
1355 psiconv_pictures result;
1356 psiconv_paint_data_section pds;
1357 if (!(result = psiconv_list_new(sizeof(struct psiconv_paint_data_section_s))))
1358 goto ERROR1;
1359 if (!(pds = psiconv_empty_paint_data_section()))
1360 goto ERROR2;
1361 if (psiconv_list_add(result,pds))
1362 goto ERROR3;
1363 free(pds);
1364 return result;
1365ERROR3:
1366 psiconv_free_paint_data_section(pds);
1367ERROR2:
1368 psiconv_list_free(result);
1369ERROR1:
1370 return NULL;
1371}
1372
1373psiconv_mbm_f psiconv_empty_mbm_f(void)
1374{
1375 psiconv_mbm_f result;
1376 if (!(result = malloc(sizeof(*result))))
1377 goto ERROR1;
1378 if (!(result->sections = psiconv_empty_pictures()))
1379 goto ERROR2;
1380 return result;
1381ERROR2:
1382 free(result);
1383ERROR1:
1384 return NULL;
1385}
1386
1387psiconv_sketch_section psiconv_empty_sketch_section(void)
1388{
1389 psiconv_sketch_section result;
1390 if (!(result = malloc(sizeof(*result))))
1391 goto ERROR1;
1392 result->displayed_xsize = 320;
1393 result->displayed_ysize = 200;
1394 result->picture_data_x_offset = result->picture_data_y_offset =
1395 result->form_xsize = result->form_ysize =
1396 result->displayed_size_x_offset = result->displayed_size_y_offset = 0;
1397 result->magnification_x = result->magnification_y = 1.0;
1398 result->cut_left = result->cut_right = result->cut_top =
1399 result->cut_bottom = 0.0;
1400 if (!(result->picture = psiconv_empty_paint_data_section()))
1401 goto ERROR2;
1402 return result;
1403ERROR2:
1404 free(result);
1405ERROR1:
1406 return NULL;
1407}
1408
1409psiconv_sketch_f psiconv_empty_sketch_f(void)
1410{
1411 psiconv_sketch_f result;
1412 if (!(result = malloc(sizeof(*result))))
1413 goto ERROR1;
1414 if (!(result->sketch_sec = psiconv_empty_sketch_section()))
1415 goto ERROR2;
1416 return result;
1417ERROR2:
1418 free(result);
1419ERROR1:
1420 return NULL;
1421}
1422
1423psiconv_cliparts psiconv_empty_cliparts(void)
1424{
1425 /* Is this correct? */
1426 return psiconv_list_new(sizeof(struct psiconv_clipart_section_s));
1427}
1428
1429psiconv_clipart_f psiconv_empty_clipart_f(void)
1430{
1431 psiconv_clipart_f result;
1432 if (!(result = malloc(sizeof(*result))))
1433 goto ERROR1;
1434 if (!(result->sections = psiconv_empty_cliparts()))
1435 goto ERROR2;
1436 return result;
1437ERROR2:
1438 free(result);
1439ERROR1:
1440 return NULL;
1441}
1442
1443psiconv_file psiconv_empty_file(psiconv_file_type_t type)
1444{
1445 psiconv_file result;
1446 if (!(result = malloc(sizeof(*result))))
1447 return NULL;
1448 result->type = type;
1449 if (type == psiconv_word_file) {
1450 if (!(result->file = psiconv_empty_word_f()))
1451 goto ERROR;
1452 } else if (type == psiconv_sheet_file) {
1453 if (!(result->file = psiconv_empty_sheet_f()))
1454 goto ERROR;
1455 } else if (type == psiconv_texted_file) {
1456 if (!(result->file = psiconv_empty_texted_f()))
1457 goto ERROR;
1458 } else if (type == psiconv_mbm_file) {
1459 if (!(result->file = psiconv_empty_mbm_f()))
1460 goto ERROR;
1461 } else if (type == psiconv_sketch_file) {
1462 if (!(result->file = psiconv_empty_sketch_f()))
1463 goto ERROR;
1464 } else if (type == psiconv_clipart_file) {
1465 if (!(result->file = psiconv_empty_clipart_f()))
1466 goto ERROR;
1467 } else
1468 goto ERROR;
1469 return result;
1470ERROR:
1471 free(result);
1472 return NULL;
1473}

Legend:
Removed from v.78  
changed lines
  Added in v.270

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