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. |
… | |
… | |
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" |
25 | #include "list.h" |
|
|
26 | #include "unicode.h" |
|
|
27 | #include "error.h" |
|
|
28 | |
|
|
29 | #ifdef DMALLOC |
|
|
30 | #include <dmalloc.h> |
|
|
31 | #endif |
26 | |
32 | |
27 | static psiconv_color clone_color(psiconv_color color); |
33 | static psiconv_color clone_color(psiconv_color color); |
28 | static psiconv_font clone_font(psiconv_font font); |
34 | static psiconv_font clone_font(psiconv_font font); |
29 | static psiconv_border clone_border(psiconv_border border); |
35 | static psiconv_border clone_border(psiconv_border border); |
30 | static psiconv_bullet clone_bullet(psiconv_bullet bullet); |
36 | static psiconv_bullet clone_bullet(psiconv_bullet bullet); |
… | |
… | |
33 | static void psiconv_free_in_line_layout_aux(void * layout); |
39 | static void psiconv_free_in_line_layout_aux(void * layout); |
34 | static void psiconv_free_paragraph_aux(void * paragraph); |
40 | static void psiconv_free_paragraph_aux(void * paragraph); |
35 | static void psiconv_free_paint_data_section_aux(void * section); |
41 | static void psiconv_free_paint_data_section_aux(void * section); |
36 | static void psiconv_free_clipart_section_aux(void * section); |
42 | static void psiconv_free_clipart_section_aux(void * section); |
37 | static void psiconv_free_formula_aux(void *data); |
43 | static void psiconv_free_formula_aux(void *data); |
|
|
44 | static void psiconv_free_sheet_worksheet_aux (void *data); |
|
|
45 | static void psiconv_free_sheet_variable_aux(void * variable); |
|
|
46 | static void psiconv_free_sheet_cell_aux(void *cell); |
|
|
47 | static void psiconv_free_sheet_line_aux(void *line); |
38 | static void psiconv_free_sheet_worksheet_aux (void *data); |
48 | static void psiconv_free_sheet_worksheet_aux (void *data); |
39 | |
49 | |
40 | static psiconv_word_styles_section psiconv_empty_word_styles_section(void); |
50 | static psiconv_word_styles_section psiconv_empty_word_styles_section(void); |
41 | static psiconv_text_and_layout psiconv_empty_text_and_layout(void); |
51 | static psiconv_text_and_layout psiconv_empty_text_and_layout(void); |
42 | static psiconv_texted_section psiconv_empty_texted_section(void); |
52 | static psiconv_texted_section psiconv_empty_texted_section(void); |
… | |
… | |
74 | { |
84 | { |
75 | 0xff, /* red */ |
85 | 0xff, /* red */ |
76 | 0xff, /* green */ |
86 | 0xff, /* green */ |
77 | 0xff, /* blue */ |
87 | 0xff, /* blue */ |
78 | }; |
88 | }; |
|
|
89 | static psiconv_ucs2 font_times[16] = { 'T','i','m','e','s',' ', |
|
|
90 | 'N','e','w',' ', |
|
|
91 | 'R','o','m','a','n',0 }; |
79 | static struct psiconv_font_s font = |
92 | static struct psiconv_font_s font = |
80 | { |
93 | { |
81 | "Times New Roman", /* name */ |
94 | font_times, /* name */ |
82 | 3 /* screenfont */ |
95 | 3 /* screenfont */ |
83 | }; |
96 | }; |
84 | struct psiconv_character_layout_s cl = |
97 | struct psiconv_character_layout_s cl = |
85 | { |
98 | { |
86 | &black, /* color */ |
99 | &black, /* color */ |
… | |
… | |
99 | |
112 | |
100 | /* Note: these defaults seem to be hard-coded somewhere outside the |
113 | /* Note: these defaults seem to be hard-coded somewhere outside the |
101 | files themself. */ |
114 | files themself. */ |
102 | psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) |
115 | psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) |
103 | { |
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 | |
104 | static struct psiconv_font_s font = |
121 | static struct psiconv_font_s font = |
105 | { |
122 | { |
106 | "Times New Roman", /* name */ |
123 | font_times, /* name */ |
107 | 2 /* screenfont */ |
124 | 2 /* screenfont */ |
108 | }; |
125 | }; |
109 | static struct psiconv_color_s black = |
126 | static struct psiconv_color_s black = |
110 | { |
127 | { |
111 | 0x00, /* red */ |
128 | 0x00, /* red */ |
… | |
… | |
126 | }; |
143 | }; |
127 | static struct psiconv_bullet_s bullet = |
144 | static struct psiconv_bullet_s bullet = |
128 | { |
145 | { |
129 | psiconv_bool_false, /* on */ |
146 | psiconv_bool_false, /* on */ |
130 | 10.0, /* font_size */ |
147 | 10.0, /* font_size */ |
131 | 0x95, /* character */ |
148 | 0x201d, /* character */ |
132 | psiconv_bool_true, /* indent */ |
149 | psiconv_bool_true, /* indent */ |
133 | &black, /* color */ |
150 | &black, /* color */ |
134 | &font, /* font */ |
151 | &font, /* font */ |
135 | }; |
152 | }; |
136 | static struct psiconv_all_tabs_s tabs = |
153 | static struct psiconv_all_tabs_s tabs = |
… | |
… | |
185 | { |
202 | { |
186 | psiconv_font result; |
203 | psiconv_font result; |
187 | if(!(result = malloc(sizeof(*result)))) |
204 | if(!(result = malloc(sizeof(*result)))) |
188 | goto ERROR1; |
205 | goto ERROR1; |
189 | *result = *font; |
206 | *result = *font; |
190 | if (!(result->name = strdup(result->name))) |
207 | if (!(result->name = psiconv_unicode_strdup(result->name))) |
191 | goto ERROR2; |
208 | goto ERROR2; |
192 | return result; |
209 | return result; |
193 | ERROR2: |
210 | ERROR2: |
194 | free(result); |
211 | free(result); |
195 | ERROR1: |
212 | ERROR1: |
… | |
… | |
317 | return ss->normal; |
334 | return ss->normal; |
318 | else |
335 | else |
319 | return psiconv_list_get(ss->styles,0xff - nr); |
336 | return psiconv_list_get(ss->styles,0xff - nr); |
320 | } |
337 | } |
321 | |
338 | |
|
|
339 | int 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 | |
322 | psiconv_formula psiconv_get_formula (psiconv_formula_list ss, int nr) |
366 | psiconv_formula psiconv_get_formula (psiconv_formula_list ss, int nr) |
323 | { |
367 | { |
324 | return psiconv_list_get(ss,psiconv_list_length(ss)-nr-1); |
368 | return psiconv_list_get(ss,psiconv_list_length(ss)-nr-1); |
325 | } |
369 | } |
326 | |
370 | |
… | |
… | |
431 | psiconv_free_style_aux(style); |
475 | psiconv_free_style_aux(style); |
432 | free(style); |
476 | free(style); |
433 | } |
477 | } |
434 | } |
478 | } |
435 | |
479 | |
|
|
480 | void 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 | |
436 | void psiconv_free_word_styles_section(psiconv_word_styles_section styles) |
486 | void psiconv_free_word_styles_section(psiconv_word_styles_section styles) |
437 | { |
487 | { |
438 | if (styles) { |
488 | if (styles) { |
439 | psiconv_free_word_style(styles->normal); |
489 | psiconv_free_word_style(styles->normal); |
440 | if (styles->styles) |
490 | psiconv_free_word_style_list(styles->styles); |
441 | psiconv_list_free_el(styles->styles,psiconv_free_style_aux); |
491 | free(styles); |
442 | } |
492 | } |
443 | } |
493 | } |
444 | |
494 | |
445 | void psiconv_free_header_section(psiconv_header_section header) |
495 | void psiconv_free_header_section(psiconv_header_section header) |
446 | { |
496 | { |
… | |
… | |
467 | free(section->name); |
517 | free(section->name); |
468 | free(section); |
518 | free(section); |
469 | } |
519 | } |
470 | } |
520 | } |
471 | |
521 | |
|
|
522 | void 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 | |
|
|
531 | void psiconv_free_object_display_section(psiconv_object_display_section section) |
|
|
532 | { |
|
|
533 | if (section) |
|
|
534 | free(section); |
|
|
535 | } |
|
|
536 | |
|
|
537 | void 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 | |
472 | void psiconv_free_in_line_layout_aux(void * layout) |
548 | void psiconv_free_in_line_layout_aux(void * layout) |
473 | { |
549 | { |
474 | 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); |
475 | } |
553 | } |
476 | |
554 | |
477 | void psiconv_free_in_line_layout(psiconv_in_line_layout layout) |
555 | void psiconv_free_in_line_layout(psiconv_in_line_layout layout) |
478 | { |
556 | { |
479 | if (layout) { |
557 | if (layout) { |
… | |
… | |
628 | psiconv_free_sheet_line_aux(line); |
706 | psiconv_free_sheet_line_aux(line); |
629 | free(line); |
707 | free(line); |
630 | } |
708 | } |
631 | } |
709 | } |
632 | |
710 | |
|
|
711 | |
633 | void psiconv_free_sheet_line_list(psiconv_sheet_line_list list) |
712 | void psiconv_free_sheet_line_list(psiconv_sheet_line_list list) |
634 | { |
713 | { |
635 | if (list) |
714 | if (list) |
636 | psiconv_list_free_el(list,psiconv_free_sheet_line_aux); |
715 | psiconv_list_free_el(list,psiconv_free_sheet_line_aux); |
|
|
716 | } |
|
|
717 | |
|
|
718 | void psiconv_free_sheet_grid_break_list(psiconv_sheet_grid_break_list list) |
|
|
719 | { |
|
|
720 | if (list) |
|
|
721 | psiconv_list_free(list); |
|
|
722 | } |
|
|
723 | |
|
|
724 | void psiconv_free_sheet_grid_size(psiconv_sheet_grid_size s) |
|
|
725 | { |
|
|
726 | if (s) |
|
|
727 | free(s); |
|
|
728 | } |
|
|
729 | |
|
|
730 | void psiconv_free_sheet_grid_size_list(psiconv_sheet_grid_size_list list) |
|
|
731 | { |
|
|
732 | if (list) |
|
|
733 | psiconv_list_free(list); |
|
|
734 | } |
|
|
735 | |
|
|
736 | void 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 | } |
637 | } |
745 | } |
638 | |
746 | |
639 | void psiconv_free_sheet_worksheet_aux (void *data) |
747 | void psiconv_free_sheet_worksheet_aux (void *data) |
640 | { |
748 | { |
641 | psiconv_sheet_worksheet section = data; |
749 | psiconv_sheet_worksheet section = data; |
642 | psiconv_free_sheet_cell_layout(section->default_layout); |
750 | psiconv_free_sheet_cell_layout(section->default_layout); |
643 | psiconv_free_sheet_cell_list(section->cells); |
751 | psiconv_free_sheet_cell_list(section->cells); |
644 | psiconv_free_sheet_line_list(section->row_default_layouts); |
752 | psiconv_free_sheet_line_list(section->row_default_layouts); |
645 | psiconv_free_sheet_line_list(section->col_default_layouts); |
753 | psiconv_free_sheet_line_list(section->col_default_layouts); |
|
|
754 | psiconv_free_sheet_grid_section(section->grid); |
646 | } |
755 | } |
647 | |
756 | |
648 | void psiconv_free_sheet_worksheet(psiconv_sheet_worksheet sheet) |
757 | void psiconv_free_sheet_worksheet(psiconv_sheet_worksheet sheet) |
649 | { |
758 | { |
650 | if (sheet) { |
759 | if (sheet) { |
… | |
… | |
690 | { |
799 | { |
691 | if (list) |
800 | if (list) |
692 | psiconv_list_free_el(list,psiconv_free_formula_aux); |
801 | psiconv_list_free_el(list,psiconv_free_formula_aux); |
693 | } |
802 | } |
694 | |
803 | |
|
|
804 | void 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 | |
|
|
813 | void psiconv_free_sheet_info_section(psiconv_sheet_info_section section) |
|
|
814 | { |
|
|
815 | if (section) { |
|
|
816 | free(section); |
|
|
817 | } |
|
|
818 | } |
|
|
819 | |
|
|
820 | void 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 | |
|
|
829 | void 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 | |
|
|
837 | void 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 | |
695 | void psiconv_free_sheet_workbook_section(psiconv_sheet_workbook_section section) |
843 | void psiconv_free_sheet_workbook_section(psiconv_sheet_workbook_section section) |
696 | { |
844 | { |
697 | if (section) { |
845 | if (section) { |
698 | psiconv_free_formula_list(section->formulas); |
846 | psiconv_free_formula_list(section->formulas); |
699 | psiconv_free_sheet_worksheet_list(section->worksheets); |
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); |
700 | free(section); |
851 | free(section); |
701 | } |
852 | } |
702 | } |
853 | } |
703 | |
854 | |
704 | void psiconv_free_sheet_f(psiconv_sheet_f file) |
855 | void psiconv_free_sheet_f(psiconv_sheet_f file) |
… | |
… | |
775 | } |
926 | } |
776 | |
927 | |
777 | void psiconv_free_clipart_section_aux(void *section) |
928 | void psiconv_free_clipart_section_aux(void *section) |
778 | { |
929 | { |
779 | if (section) |
930 | if (section) |
780 | free(((psiconv_clipart_section ) section)->picture); |
931 | psiconv_free_paint_data_section(((psiconv_clipart_section) section)->picture); |
781 | } |
932 | } |
782 | |
933 | |
783 | void psiconv_free_clipart_section(psiconv_clipart_section section) |
934 | void psiconv_free_clipart_section(psiconv_clipart_section section) |
784 | { |
935 | { |
785 | if (section) { |
936 | if (section) { |
… | |
… | |
838 | const psiconv_font value2) |
989 | const psiconv_font value2) |
839 | { |
990 | { |
840 | if (!value1 || !value2 || !value1->name || !value2->name) |
991 | if (!value1 || !value2 || !value1->name || !value2->name) |
841 | return 1; |
992 | return 1; |
842 | if ((value1->screenfont == value2->screenfont) && |
993 | if ((value1->screenfont == value2->screenfont) && |
843 | !strcmp(value1->name,value2->name)) |
994 | !psiconv_unicode_strcmp(value1->name,value2->name)) |
844 | return 0; |
995 | return 0; |
845 | else |
996 | else |
846 | return 1; |
997 | return 1; |
847 | } |
998 | } |
848 | |
999 | |
… | |
… | |
1236 | psiconv_sketch_section psiconv_empty_sketch_section(void) |
1387 | psiconv_sketch_section psiconv_empty_sketch_section(void) |
1237 | { |
1388 | { |
1238 | psiconv_sketch_section result; |
1389 | psiconv_sketch_section result; |
1239 | if (!(result = malloc(sizeof(*result)))) |
1390 | if (!(result = malloc(sizeof(*result)))) |
1240 | goto ERROR1; |
1391 | goto ERROR1; |
1241 | result->form_xsize = 320; |
1392 | result->displayed_xsize = 320; |
1242 | result->form_ysize = 200; |
1393 | result->displayed_ysize = 200; |
1243 | result->picture_x_offset = result->picture_y_offset = result->picture_xsize = |
1394 | result->picture_data_x_offset = result->picture_data_y_offset = |
1244 | result->picture_ysize = 0; |
1395 | result->form_xsize = result->form_ysize = |
|
|
1396 | result->displayed_size_x_offset = result->displayed_size_y_offset = 0; |
1245 | result->magnification_x = result->magnification_y = 1.0; |
1397 | result->magnification_x = result->magnification_y = 1.0; |
1246 | result->cut_left = result->cut_right = result->cut_top = |
1398 | result->cut_left = result->cut_right = result->cut_top = |
1247 | result->cut_bottom = 0.0; |
1399 | result->cut_bottom = 0.0; |
1248 | if (!(result->picture = psiconv_empty_paint_data_section())) |
1400 | if (!(result->picture = psiconv_empty_paint_data_section())) |
1249 | goto ERROR2; |
1401 | goto ERROR2; |