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-2004 Frodo Looijaard <frodol@dds.nl> |
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 | |
|
|
28 | #ifdef DMALLOC |
|
|
29 | #include <dmalloc.h> |
|
|
30 | #endif |
26 | |
31 | |
27 | static psiconv_color clone_color(psiconv_color color); |
32 | static psiconv_color clone_color(psiconv_color color); |
28 | static psiconv_font clone_font(psiconv_font font); |
33 | static psiconv_font clone_font(psiconv_font font); |
29 | static psiconv_border clone_border(psiconv_border border); |
34 | static psiconv_border clone_border(psiconv_border border); |
30 | static psiconv_bullet clone_bullet(psiconv_bullet bullet); |
35 | static psiconv_bullet clone_bullet(psiconv_bullet bullet); |
… | |
… | |
33 | static void psiconv_free_in_line_layout_aux(void * layout); |
38 | static void psiconv_free_in_line_layout_aux(void * layout); |
34 | static void psiconv_free_paragraph_aux(void * paragraph); |
39 | static void psiconv_free_paragraph_aux(void * paragraph); |
35 | static void psiconv_free_paint_data_section_aux(void * section); |
40 | static void psiconv_free_paint_data_section_aux(void * section); |
36 | static void psiconv_free_clipart_section_aux(void * section); |
41 | static void psiconv_free_clipart_section_aux(void * section); |
37 | static void psiconv_free_formula_aux(void *data); |
42 | static void psiconv_free_formula_aux(void *data); |
|
|
43 | static void psiconv_free_sheet_worksheet_aux (void *data); |
|
|
44 | static void psiconv_free_sheet_variable_aux(void * variable); |
|
|
45 | static void psiconv_free_sheet_cell_aux(void *cell); |
|
|
46 | static void psiconv_free_sheet_line_aux(void *line); |
38 | static void psiconv_free_sheet_worksheet_aux (void *data); |
47 | static void psiconv_free_sheet_worksheet_aux (void *data); |
39 | |
48 | |
40 | static psiconv_word_styles_section psiconv_empty_word_styles_section(void); |
49 | static psiconv_word_styles_section psiconv_empty_word_styles_section(void); |
41 | static psiconv_text_and_layout psiconv_empty_text_and_layout(void); |
50 | static psiconv_text_and_layout psiconv_empty_text_and_layout(void); |
42 | static psiconv_texted_section psiconv_empty_texted_section(void); |
51 | static psiconv_texted_section psiconv_empty_texted_section(void); |
… | |
… | |
74 | { |
83 | { |
75 | 0xff, /* red */ |
84 | 0xff, /* red */ |
76 | 0xff, /* green */ |
85 | 0xff, /* green */ |
77 | 0xff, /* blue */ |
86 | 0xff, /* blue */ |
78 | }; |
87 | }; |
|
|
88 | static psiconv_ucs2 font_times[16] = { 'T','i','m','e','s',' ', |
|
|
89 | 'N','e','w',' ', |
|
|
90 | 'R','o','m','a','n',0 }; |
79 | static struct psiconv_font_s font = |
91 | static struct psiconv_font_s font = |
80 | { |
92 | { |
81 | "Times New Roman", /* name */ |
93 | font_times, /* name */ |
82 | 3 /* screenfont */ |
94 | 3 /* screenfont */ |
83 | }; |
95 | }; |
84 | struct psiconv_character_layout_s cl = |
96 | struct psiconv_character_layout_s cl = |
85 | { |
97 | { |
86 | &black, /* color */ |
98 | &black, /* color */ |
… | |
… | |
99 | |
111 | |
100 | /* Note: these defaults seem to be hard-coded somewhere outside the |
112 | /* Note: these defaults seem to be hard-coded somewhere outside the |
101 | files themself. */ |
113 | files themself. */ |
102 | psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) |
114 | psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) |
103 | { |
115 | { |
|
|
116 | static psiconv_ucs2 font_times[16] = { 'T','i','m','e','s',' ', |
|
|
117 | 'N','e','w',' ', |
|
|
118 | 'R','o','m','a','n',0 }; |
|
|
119 | |
104 | static struct psiconv_font_s font = |
120 | static struct psiconv_font_s font = |
105 | { |
121 | { |
106 | "Times New Roman", /* name */ |
122 | font_times, /* name */ |
107 | 2 /* screenfont */ |
123 | 2 /* screenfont */ |
108 | }; |
124 | }; |
109 | static struct psiconv_color_s black = |
125 | static struct psiconv_color_s black = |
110 | { |
126 | { |
111 | 0x00, /* red */ |
127 | 0x00, /* red */ |
… | |
… | |
126 | }; |
142 | }; |
127 | static struct psiconv_bullet_s bullet = |
143 | static struct psiconv_bullet_s bullet = |
128 | { |
144 | { |
129 | psiconv_bool_false, /* on */ |
145 | psiconv_bool_false, /* on */ |
130 | 10.0, /* font_size */ |
146 | 10.0, /* font_size */ |
131 | 0x95, /* character */ |
147 | 0x201d, /* character */ |
132 | psiconv_bool_true, /* indent */ |
148 | psiconv_bool_true, /* indent */ |
133 | &black, /* color */ |
149 | &black, /* color */ |
134 | &font, /* font */ |
150 | &font, /* font */ |
135 | }; |
151 | }; |
136 | static struct psiconv_all_tabs_s tabs = |
152 | static struct psiconv_all_tabs_s tabs = |
… | |
… | |
185 | { |
201 | { |
186 | psiconv_font result; |
202 | psiconv_font result; |
187 | if(!(result = malloc(sizeof(*result)))) |
203 | if(!(result = malloc(sizeof(*result)))) |
188 | goto ERROR1; |
204 | goto ERROR1; |
189 | *result = *font; |
205 | *result = *font; |
190 | if (!(result->name = strdup(result->name))) |
206 | if (!(result->name = psiconv_unicode_strdup(result->name))) |
191 | goto ERROR2; |
207 | goto ERROR2; |
192 | return result; |
208 | return result; |
193 | ERROR2: |
209 | ERROR2: |
194 | free(result); |
210 | free(result); |
195 | ERROR1: |
211 | ERROR1: |
… | |
… | |
322 | psiconv_formula psiconv_get_formula (psiconv_formula_list ss, int nr) |
338 | psiconv_formula psiconv_get_formula (psiconv_formula_list ss, int nr) |
323 | { |
339 | { |
324 | return psiconv_list_get(ss,psiconv_list_length(ss)-nr-1); |
340 | return psiconv_list_get(ss,psiconv_list_length(ss)-nr-1); |
325 | } |
341 | } |
326 | |
342 | |
|
|
343 | /* TODO: What if a cell is both in a default row and a default column?!? */ |
|
|
344 | psiconv_sheet_cell_layout psiconv_get_default_layout |
|
|
345 | (psiconv_sheet_line_list row_defaults, |
|
|
346 | psiconv_sheet_line_list col_defaults, |
|
|
347 | psiconv_sheet_cell_layout cell_default, |
|
|
348 | int row,int col) |
|
|
349 | { |
|
|
350 | int i; |
|
|
351 | psiconv_sheet_line line; |
|
|
352 | for (i = 0;i < psiconv_list_length(row_defaults);i++) { |
|
|
353 | line = psiconv_list_get(row_defaults,i); |
|
|
354 | if (line->position == row) |
|
|
355 | return line->layout; |
|
|
356 | } |
|
|
357 | for (i = 0;i < psiconv_list_length(col_defaults);i++) { |
|
|
358 | line = psiconv_list_get(col_defaults,i); |
|
|
359 | if (line->position == col) |
|
|
360 | return line->layout; |
|
|
361 | } |
|
|
362 | return cell_default; |
|
|
363 | } |
|
|
364 | |
327 | |
365 | |
328 | void psiconv_free_color (psiconv_color color) |
366 | void psiconv_free_color (psiconv_color color) |
329 | { |
367 | { |
330 | if (color) |
368 | if (color) |
331 | free(color); |
369 | free(color); |
… | |
… | |
409 | psiconv_free_style_aux(style); |
447 | psiconv_free_style_aux(style); |
410 | free(style); |
448 | free(style); |
411 | } |
449 | } |
412 | } |
450 | } |
413 | |
451 | |
|
|
452 | void psiconv_free_word_style_list(psiconv_word_style_list style_list) |
|
|
453 | { |
|
|
454 | if (style_list) |
|
|
455 | psiconv_list_free_el(style_list,psiconv_free_style_aux); |
|
|
456 | } |
|
|
457 | |
414 | void psiconv_free_word_styles_section(psiconv_word_styles_section styles) |
458 | void psiconv_free_word_styles_section(psiconv_word_styles_section styles) |
415 | { |
459 | { |
416 | if (styles) { |
460 | if (styles) { |
417 | psiconv_free_word_style(styles->normal); |
461 | psiconv_free_word_style(styles->normal); |
418 | if (styles->styles) |
462 | psiconv_free_word_style_list(styles->styles); |
419 | psiconv_list_free_el(styles->styles,psiconv_free_style_aux); |
463 | free(styles); |
420 | } |
464 | } |
421 | } |
465 | } |
422 | |
466 | |
423 | void psiconv_free_header_section(psiconv_header_section header) |
467 | void psiconv_free_header_section(psiconv_header_section header) |
424 | { |
468 | { |
… | |
… | |
445 | free(section->name); |
489 | free(section->name); |
446 | free(section); |
490 | free(section); |
447 | } |
491 | } |
448 | } |
492 | } |
449 | |
493 | |
|
|
494 | void psiconv_free_object_icon_section(psiconv_object_icon_section section) |
|
|
495 | { |
|
|
496 | if (section) { |
|
|
497 | if (section->icon_name) |
|
|
498 | free(section->icon_name); |
|
|
499 | free(section); |
|
|
500 | } |
|
|
501 | } |
|
|
502 | |
|
|
503 | void psiconv_free_object_display_section(psiconv_object_display_section section) |
|
|
504 | { |
|
|
505 | if (section) |
|
|
506 | free(section); |
|
|
507 | } |
|
|
508 | |
|
|
509 | void psiconv_free_embedded_object_section |
|
|
510 | (psiconv_embedded_object_section object) |
|
|
511 | { |
|
|
512 | if (object) { |
|
|
513 | psiconv_free_object_icon_section(object->icon); |
|
|
514 | psiconv_free_object_display_section(object->display); |
|
|
515 | psiconv_free_file(object->object); |
|
|
516 | free(object); |
|
|
517 | } |
|
|
518 | } |
|
|
519 | |
450 | void psiconv_free_in_line_layout_aux(void * layout) |
520 | void psiconv_free_in_line_layout_aux(void * layout) |
451 | { |
521 | { |
452 | psiconv_free_character_layout(((psiconv_in_line_layout) layout)->layout); |
522 | psiconv_free_character_layout(((psiconv_in_line_layout) layout)->layout); |
|
|
523 | psiconv_free_embedded_object_section |
|
|
524 | (((psiconv_in_line_layout) layout)->object); |
453 | } |
525 | } |
454 | |
526 | |
455 | void psiconv_free_in_line_layout(psiconv_in_line_layout layout) |
527 | void psiconv_free_in_line_layout(psiconv_in_line_layout layout) |
456 | { |
528 | { |
457 | if (layout) { |
529 | if (layout) { |
… | |
… | |
591 | { |
663 | { |
592 | if (list) |
664 | if (list) |
593 | psiconv_list_free_el(list,psiconv_free_sheet_cell_aux); |
665 | psiconv_list_free_el(list,psiconv_free_sheet_cell_aux); |
594 | } |
666 | } |
595 | |
667 | |
|
|
668 | void psiconv_free_sheet_line_aux(void *line) |
|
|
669 | { |
|
|
670 | psiconv_sheet_line data = line; |
|
|
671 | |
|
|
672 | psiconv_free_sheet_cell_layout(data->layout); |
|
|
673 | } |
|
|
674 | |
|
|
675 | void psiconv_free_sheet_line(psiconv_sheet_line line) |
|
|
676 | { |
|
|
677 | if (line) { |
|
|
678 | psiconv_free_sheet_line_aux(line); |
|
|
679 | free(line); |
|
|
680 | } |
|
|
681 | } |
|
|
682 | |
|
|
683 | |
|
|
684 | void psiconv_free_sheet_line_list(psiconv_sheet_line_list list) |
|
|
685 | { |
|
|
686 | if (list) |
|
|
687 | psiconv_list_free_el(list,psiconv_free_sheet_line_aux); |
|
|
688 | } |
|
|
689 | |
|
|
690 | void psiconv_free_sheet_grid_break_list(psiconv_sheet_grid_break_list list) |
|
|
691 | { |
|
|
692 | if (list) |
|
|
693 | psiconv_list_free(list); |
|
|
694 | } |
|
|
695 | |
|
|
696 | void psiconv_free_sheet_grid_size(psiconv_sheet_grid_size s) |
|
|
697 | { |
|
|
698 | if (s) |
|
|
699 | free(s); |
|
|
700 | } |
|
|
701 | |
|
|
702 | void psiconv_free_sheet_grid_size_list(psiconv_sheet_grid_size_list list) |
|
|
703 | { |
|
|
704 | if (list) |
|
|
705 | psiconv_list_free(list); |
|
|
706 | } |
|
|
707 | |
|
|
708 | void psiconv_free_sheet_grid_section(psiconv_sheet_grid_section sec) |
|
|
709 | { |
|
|
710 | if (sec) { |
|
|
711 | psiconv_free_sheet_grid_size_list(sec->row_heights); |
|
|
712 | psiconv_free_sheet_grid_size_list(sec->column_heights); |
|
|
713 | psiconv_free_sheet_grid_break_list(sec->row_page_breaks); |
|
|
714 | psiconv_free_sheet_grid_break_list(sec->column_page_breaks); |
|
|
715 | free(sec); |
|
|
716 | } |
|
|
717 | } |
|
|
718 | |
596 | void psiconv_free_sheet_worksheet_aux (void *data) |
719 | void psiconv_free_sheet_worksheet_aux (void *data) |
597 | { |
720 | { |
598 | psiconv_sheet_worksheet section = data; |
721 | psiconv_sheet_worksheet section = data; |
599 | psiconv_free_sheet_cell_layout(section->default_layout); |
722 | psiconv_free_sheet_cell_layout(section->default_layout); |
600 | psiconv_free_sheet_cell_list(section->cells); |
723 | psiconv_free_sheet_cell_list(section->cells); |
|
|
724 | psiconv_free_sheet_line_list(section->row_default_layouts); |
|
|
725 | psiconv_free_sheet_line_list(section->col_default_layouts); |
|
|
726 | psiconv_free_sheet_grid_section(section->grid); |
601 | } |
727 | } |
602 | |
728 | |
603 | void psiconv_free_sheet_worksheet(psiconv_sheet_worksheet sheet) |
729 | void psiconv_free_sheet_worksheet(psiconv_sheet_worksheet sheet) |
604 | { |
730 | { |
605 | if (sheet) { |
731 | if (sheet) { |
… | |
… | |
645 | { |
771 | { |
646 | if (list) |
772 | if (list) |
647 | psiconv_list_free_el(list,psiconv_free_formula_aux); |
773 | psiconv_list_free_el(list,psiconv_free_formula_aux); |
648 | } |
774 | } |
649 | |
775 | |
|
|
776 | void psiconv_free_sheet_name_section(psiconv_sheet_name_section section) |
|
|
777 | { |
|
|
778 | if (section) { |
|
|
779 | if(section->name) |
|
|
780 | free(section->name); |
|
|
781 | free(section); |
|
|
782 | } |
|
|
783 | } |
|
|
784 | |
|
|
785 | void psiconv_free_sheet_info_section(psiconv_sheet_info_section section) |
|
|
786 | { |
|
|
787 | if (section) { |
|
|
788 | free(section); |
|
|
789 | } |
|
|
790 | } |
|
|
791 | |
|
|
792 | void psiconv_free_sheet_variable_aux(void * variable) |
|
|
793 | { |
|
|
794 | psiconv_sheet_variable var = variable; |
|
|
795 | if (var->name) |
|
|
796 | free(var->name); |
|
|
797 | if (var->type == psiconv_var_string) |
|
|
798 | free(var->data.dat_string); |
|
|
799 | } |
|
|
800 | |
|
|
801 | void psiconv_free_sheet_variable(psiconv_sheet_variable var) |
|
|
802 | { |
|
|
803 | if (var) { |
|
|
804 | psiconv_free_sheet_variable_aux(var); |
|
|
805 | free(var); |
|
|
806 | } |
|
|
807 | } |
|
|
808 | |
|
|
809 | void psiconv_free_sheet_variable_list(psiconv_sheet_variable_list list) |
|
|
810 | { |
|
|
811 | if (list) |
|
|
812 | psiconv_list_free_el(list,psiconv_free_sheet_variable_aux); |
|
|
813 | } |
|
|
814 | |
650 | void psiconv_free_sheet_workbook_section(psiconv_sheet_workbook_section section) |
815 | void psiconv_free_sheet_workbook_section(psiconv_sheet_workbook_section section) |
651 | { |
816 | { |
652 | if (section) { |
817 | if (section) { |
653 | psiconv_free_formula_list(section->formulas); |
818 | psiconv_free_formula_list(section->formulas); |
654 | psiconv_free_sheet_worksheet_list(section->worksheets); |
819 | psiconv_free_sheet_worksheet_list(section->worksheets); |
|
|
820 | psiconv_free_sheet_name_section(section->name); |
|
|
821 | psiconv_free_sheet_info_section(section->info); |
|
|
822 | psiconv_free_sheet_variable_list(section->variables); |
655 | free(section); |
823 | free(section); |
656 | } |
824 | } |
657 | } |
825 | } |
658 | |
826 | |
659 | void psiconv_free_sheet_f(psiconv_sheet_f file) |
827 | void psiconv_free_sheet_f(psiconv_sheet_f file) |
… | |
… | |
730 | } |
898 | } |
731 | |
899 | |
732 | void psiconv_free_clipart_section_aux(void *section) |
900 | void psiconv_free_clipart_section_aux(void *section) |
733 | { |
901 | { |
734 | if (section) |
902 | if (section) |
735 | free(((psiconv_clipart_section ) section)->picture); |
903 | psiconv_free_paint_data_section(((psiconv_clipart_section) section)->picture); |
736 | } |
904 | } |
737 | |
905 | |
738 | void psiconv_free_clipart_section(psiconv_clipart_section section) |
906 | void psiconv_free_clipart_section(psiconv_clipart_section section) |
739 | { |
907 | { |
740 | if (section) { |
908 | if (section) { |
… | |
… | |
793 | const psiconv_font value2) |
961 | const psiconv_font value2) |
794 | { |
962 | { |
795 | if (!value1 || !value2 || !value1->name || !value2->name) |
963 | if (!value1 || !value2 || !value1->name || !value2->name) |
796 | return 1; |
964 | return 1; |
797 | if ((value1->screenfont == value2->screenfont) && |
965 | if ((value1->screenfont == value2->screenfont) && |
798 | !strcmp(value1->name,value2->name)) |
966 | !psiconv_unicode_strcmp(value1->name,value2->name)) |
799 | return 0; |
967 | return 0; |
800 | else |
968 | else |
801 | return 1; |
969 | return 1; |
802 | } |
970 | } |
803 | |
971 | |
… | |
… | |
1191 | psiconv_sketch_section psiconv_empty_sketch_section(void) |
1359 | psiconv_sketch_section psiconv_empty_sketch_section(void) |
1192 | { |
1360 | { |
1193 | psiconv_sketch_section result; |
1361 | psiconv_sketch_section result; |
1194 | if (!(result = malloc(sizeof(*result)))) |
1362 | if (!(result = malloc(sizeof(*result)))) |
1195 | goto ERROR1; |
1363 | goto ERROR1; |
1196 | result->form_xsize = 320; |
1364 | result->displayed_xsize = 320; |
1197 | result->form_ysize = 200; |
1365 | result->displayed_ysize = 200; |
1198 | result->picture_x_offset = result->picture_y_offset = result->picture_xsize = |
1366 | result->picture_data_x_offset = result->picture_data_y_offset = |
1199 | result->picture_ysize = 0; |
1367 | result->form_xsize = result->form_ysize = |
|
|
1368 | result->displayed_size_x_offset = result->displayed_size_y_offset = 0; |
1200 | result->magnification_x = result->magnification_y = 1.0; |
1369 | result->magnification_x = result->magnification_y = 1.0; |
1201 | result->cut_left = result->cut_right = result->cut_top = |
1370 | result->cut_left = result->cut_right = result->cut_top = |
1202 | result->cut_bottom = 0.0; |
1371 | result->cut_bottom = 0.0; |
1203 | if (!(result->picture = psiconv_empty_paint_data_section())) |
1372 | if (!(result->picture = psiconv_empty_paint_data_section())) |
1204 | goto ERROR2; |
1373 | goto ERROR2; |