/[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 94 Revision 240
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
27static psiconv_color clone_color(psiconv_color color); 32static psiconv_color clone_color(psiconv_color color);
28static psiconv_font clone_font(psiconv_font font); 33static psiconv_font clone_font(psiconv_font font);
29static psiconv_border clone_border(psiconv_border border); 34static psiconv_border clone_border(psiconv_border border);
30static psiconv_bullet clone_bullet(psiconv_bullet bullet); 35static psiconv_bullet clone_bullet(psiconv_bullet bullet);
32static void psiconv_free_style_aux(void *style); 37static void psiconv_free_style_aux(void *style);
33static void psiconv_free_in_line_layout_aux(void * layout); 38static void psiconv_free_in_line_layout_aux(void * layout);
34static void psiconv_free_paragraph_aux(void * paragraph); 39static void psiconv_free_paragraph_aux(void * paragraph);
35static void psiconv_free_paint_data_section_aux(void * section); 40static void psiconv_free_paint_data_section_aux(void * section);
36static void psiconv_free_clipart_section_aux(void * section); 41static void psiconv_free_clipart_section_aux(void * section);
42static void psiconv_free_formula_aux(void *data);
43static void psiconv_free_sheet_worksheet_aux (void *data);
44static void psiconv_free_sheet_variable_aux(void * variable);
45static void psiconv_free_sheet_cell_aux(void *cell);
46static void psiconv_free_sheet_line_aux(void *line);
47static void psiconv_free_sheet_worksheet_aux (void *data);
37 48
38static psiconv_word_styles_section psiconv_empty_word_styles_section(void); 49static psiconv_word_styles_section psiconv_empty_word_styles_section(void);
39static psiconv_text_and_layout psiconv_empty_text_and_layout(void); 50static psiconv_text_and_layout psiconv_empty_text_and_layout(void);
40static psiconv_texted_section psiconv_empty_texted_section(void); 51static psiconv_texted_section psiconv_empty_texted_section(void);
41static psiconv_page_header psiconv_empty_page_header(void); 52static psiconv_page_header psiconv_empty_page_header(void);
42static psiconv_page_layout_section psiconv_empty_page_layout_section(void); 53static psiconv_page_layout_section psiconv_empty_page_layout_section(void);
43static psiconv_word_status_section psiconv_empty_word_status_section(void); 54static psiconv_word_status_section psiconv_empty_word_status_section(void);
44static psiconv_word_f psiconv_empty_word_f(void); 55static psiconv_word_f psiconv_empty_word_f(void);
45static psiconv_sheet_status_section psiconv_empty_sheet_status_section(void); 56static psiconv_sheet_status_section psiconv_empty_sheet_status_section(void);
57static psiconv_formula_list psiconv_empty_formula_list(void);
58static psiconv_sheet_workbook_section
59 psiconv_empty_sheet_workbook_section(void);
46static psiconv_sheet_f psiconv_empty_sheet_f(void); 60static psiconv_sheet_f psiconv_empty_sheet_f(void);
47static psiconv_texted_f psiconv_empty_texted_f(void); 61static psiconv_texted_f psiconv_empty_texted_f(void);
48static psiconv_paint_data_section psiconv_empty_paint_data_section(void); 62static psiconv_paint_data_section psiconv_empty_paint_data_section(void);
49static psiconv_pictures psiconv_empty_pictures(void); 63static psiconv_pictures psiconv_empty_pictures(void);
50static psiconv_mbm_f psiconv_empty_mbm_f(void); 64static psiconv_mbm_f psiconv_empty_mbm_f(void);
69 { 83 {
70 0xff, /* red */ 84 0xff, /* red */
71 0xff, /* green */ 85 0xff, /* green */
72 0xff, /* blue */ 86 0xff, /* blue */
73 }; 87 };
88 static psiconv_ucs2 font_times[16] = { 'T','i','m','e','s',' ',
89 'N','e','w',' ',
90 'R','o','m','a','n',0 };
74 static struct psiconv_font_s font = 91 static struct psiconv_font_s font =
75 { 92 {
76 "Times New Roman", /* name */ 93 font_times, /* name */
77 3 /* screenfont */ 94 3 /* screenfont */
78 }; 95 };
79 struct psiconv_character_layout_s cl = 96 struct psiconv_character_layout_s cl =
80 { 97 {
81 &black, /* color */ 98 &black, /* color */
94 111
95/* Note: these defaults seem to be hard-coded somewhere outside the 112/* Note: these defaults seem to be hard-coded somewhere outside the
96 files themself. */ 113 files themself. */
97psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) 114psiconv_paragraph_layout psiconv_basic_paragraph_layout(void)
98{ 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
99 static struct psiconv_font_s font = 120 static struct psiconv_font_s font =
100 { 121 {
101 "Times New Roman", /* name */ 122 font_times, /* name */
102 2 /* screenfont */ 123 2 /* screenfont */
103 }; 124 };
104 static struct psiconv_color_s black = 125 static struct psiconv_color_s black =
105 { 126 {
106 0x00, /* red */ 127 0x00, /* red */
121 }; 142 };
122 static struct psiconv_bullet_s bullet = 143 static struct psiconv_bullet_s bullet =
123 { 144 {
124 psiconv_bool_false, /* on */ 145 psiconv_bool_false, /* on */
125 10.0, /* font_size */ 146 10.0, /* font_size */
126 0x95, /* character */ 147 0x201d, /* character */
127 psiconv_bool_true, /* indent */ 148 psiconv_bool_true, /* indent */
128 &black, /* color */ 149 &black, /* color */
129 &font, /* font */ 150 &font, /* font */
130 }; 151 };
131 static struct psiconv_all_tabs_s tabs = 152 static struct psiconv_all_tabs_s tabs =
147 0.0, /* space_below */ 168 0.0, /* space_below */
148 psiconv_bool_false, /* keep_together */ 169 psiconv_bool_false, /* keep_together */
149 psiconv_bool_false, /* keep_with_next */ 170 psiconv_bool_false, /* keep_with_next */
150 psiconv_bool_false, /* on_next_page */ 171 psiconv_bool_false, /* on_next_page */
151 psiconv_bool_false, /* no_widow_protection */ 172 psiconv_bool_false, /* no_widow_protection */
173 psiconv_bool_false, /* wrap_to_fit_cell */
152 0.0, /* left_margin */ 174 0.0, /* left_margin */
153 &bullet, /* bullet */ 175 &bullet, /* bullet */
154 &no_border, /* left_border */ 176 &no_border, /* left_border */
155 &no_border, /* right_border */ 177 &no_border, /* right_border */
156 &no_border, /* top_border */ 178 &no_border, /* top_border */
179{ 201{
180 psiconv_font result; 202 psiconv_font result;
181 if(!(result = malloc(sizeof(*result)))) 203 if(!(result = malloc(sizeof(*result))))
182 goto ERROR1; 204 goto ERROR1;
183 *result = *font; 205 *result = *font;
184 if (!(result->name = strdup(result->name))) 206 if (!(result->name = psiconv_unicode_strdup(result->name)))
185 goto ERROR2; 207 goto ERROR2;
186 return result; 208 return result;
187ERROR2: 209ERROR2:
188 free(result); 210 free(result);
189ERROR1: 211ERROR1:
311 return ss->normal; 333 return ss->normal;
312 else 334 else
313 return psiconv_list_get(ss->styles,0xff - nr); 335 return psiconv_list_get(ss->styles,0xff - nr);
314} 336}
315 337
338psiconv_formula psiconv_get_formula (psiconv_formula_list ss, int nr)
339{
340 return psiconv_list_get(ss,psiconv_list_length(ss)-nr-1);
341}
342
343/* TODO: What if a cell is both in a default row and a default column?!? */
344psiconv_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
365
316void psiconv_free_color (psiconv_color color) 366void psiconv_free_color (psiconv_color color)
317{ 367{
318 if (color) 368 if (color)
319 free(color); 369 free(color);
320} 370}
397 psiconv_free_style_aux(style); 447 psiconv_free_style_aux(style);
398 free(style); 448 free(style);
399 } 449 }
400} 450}
401 451
452void 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
402void psiconv_free_word_styles_section(psiconv_word_styles_section styles) 458void psiconv_free_word_styles_section(psiconv_word_styles_section styles)
403{ 459{
404 if (styles) { 460 if (styles) {
405 psiconv_free_word_style(styles->normal); 461 psiconv_free_word_style(styles->normal);
406 if (styles->styles) 462 psiconv_free_word_style_list(styles->styles);
407 psiconv_list_free_el(styles->styles,psiconv_free_style_aux); 463 free(styles);
408 } 464 }
409} 465}
410 466
411void psiconv_free_header_section(psiconv_header_section header) 467void psiconv_free_header_section(psiconv_header_section header)
412{ 468{
433 free(section->name); 489 free(section->name);
434 free(section); 490 free(section);
435 } 491 }
436} 492}
437 493
494void 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
503void psiconv_free_object_display_section(psiconv_object_display_section section)
504{
505 if (section)
506 free(section);
507}
508
509void 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
438void psiconv_free_in_line_layout_aux(void * layout) 520void psiconv_free_in_line_layout_aux(void * layout)
439{ 521{
440 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);
441} 525}
442 526
443void psiconv_free_in_line_layout(psiconv_in_line_layout layout) 527void psiconv_free_in_line_layout(psiconv_in_line_layout layout)
444{ 528{
445 if (layout) { 529 if (layout) {
542{ 626{
543 if (section) 627 if (section)
544 free(section); 628 free(section);
545} 629}
546 630
631void psiconv_free_sheet_numberformat(psiconv_sheet_numberformat numberformat)
632{
633 if (numberformat)
634 free(numberformat);
635}
636
637void psiconv_free_sheet_cell_layout(psiconv_sheet_cell_layout layout)
638{
639 psiconv_free_paragraph_layout(layout->paragraph);
640 psiconv_free_character_layout(layout->character);
641 psiconv_free_sheet_numberformat(layout->numberformat);
642}
643
644void psiconv_free_sheet_cell_aux(void *cell)
645{
646 psiconv_sheet_cell data = cell;
647
648 psiconv_free_sheet_cell_layout(data->layout);
649
650 if ((data->type == psiconv_cell_string) && (data->data.dat_string))
651 free(data->data.dat_string);
652}
653
654void psiconv_free_sheet_cell(psiconv_sheet_cell cell)
655{
656 if (cell) {
657 psiconv_free_sheet_cell_aux(cell);
658 free(cell);
659 }
660}
661
662void psiconv_free_sheet_cell_list(psiconv_sheet_cell_list list)
663{
664 if (list)
665 psiconv_list_free_el(list,psiconv_free_sheet_cell_aux);
666}
667
668void 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
675void 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
684void 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
690void psiconv_free_sheet_grid_break_list(psiconv_sheet_grid_break_list list)
691{
692 if (list)
693 psiconv_list_free(list);
694}
695
696void psiconv_free_sheet_grid_size(psiconv_sheet_grid_size s)
697{
698 if (s)
699 free(s);
700}
701
702void psiconv_free_sheet_grid_size_list(psiconv_sheet_grid_size_list list)
703{
704 if (list)
705 psiconv_list_free(list);
706}
707
708void 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
719void psiconv_free_sheet_worksheet_aux (void *data)
720{
721 psiconv_sheet_worksheet section = data;
722 psiconv_free_sheet_cell_layout(section->default_layout);
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);
727}
728
729void psiconv_free_sheet_worksheet(psiconv_sheet_worksheet sheet)
730{
731 if (sheet) {
732 psiconv_free_sheet_worksheet_aux(sheet);
733 free(sheet);
734 }
735}
736
737void psiconv_free_sheet_worksheet_list(psiconv_sheet_worksheet_list list)
738{
739 if (list)
740 psiconv_list_free_el(list,psiconv_free_sheet_worksheet_aux);
741}
742
743void psiconv_free_formula_aux(void *data)
744{
745 psiconv_formula formula;
746 formula = data;
747 if (formula->type == psiconv_formula_dat_string)
748 free(formula->data.dat_string);
749 else if ((formula->type != psiconv_formula_dat_int) &&
750 (formula->type != psiconv_formula_dat_var) &&
751 (formula->type != psiconv_formula_dat_float) &&
752 (formula->type != psiconv_formula_dat_cellref) &&
753 (formula->type != psiconv_formula_dat_cellblock) &&
754 (formula->type != psiconv_formula_dat_vcellblock) &&
755 (formula->type != psiconv_formula_mark_opsep) &&
756 (formula->type != psiconv_formula_mark_opend) &&
757 (formula->type != psiconv_formula_mark_eof) &&
758 (formula->type != psiconv_formula_unknown))
759 psiconv_free_formula_list(formula->data.fun_operands);
760}
761
762void psiconv_free_formula(psiconv_formula formula)
763{
764 if (formula) {
765 psiconv_free_formula_aux(formula);
766 free(formula);
767 }
768}
769
770void psiconv_free_formula_list(psiconv_formula_list list)
771{
772 if (list)
773 psiconv_list_free_el(list,psiconv_free_formula_aux);
774}
775
776void 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
785void psiconv_free_sheet_info_section(psiconv_sheet_info_section section)
786{
787 if (section) {
788 free(section);
789 }
790}
791
792void 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
801void 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
809void 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
815void psiconv_free_sheet_workbook_section(psiconv_sheet_workbook_section section)
816{
817 if (section) {
818 psiconv_free_formula_list(section->formulas);
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);
823 free(section);
824 }
825}
826
547void psiconv_free_sheet_f(psiconv_sheet_f file) 827void psiconv_free_sheet_f(psiconv_sheet_f file)
548{ 828{
549 if (file) { 829 if (file) {
550 psiconv_free_page_layout_section(file->page_sec); 830 psiconv_free_page_layout_section(file->page_sec);
551 psiconv_free_sheet_status_section(file->status_sec); 831 psiconv_free_sheet_status_section(file->status_sec);
832 psiconv_free_sheet_workbook_section(file->workbook_sec);
552 free(file); 833 free(file);
553 } 834 }
554} 835}
555 836
556void psiconv_free_texted_f(psiconv_texted_f file) 837void psiconv_free_texted_f(psiconv_texted_f file)
617} 898}
618 899
619void psiconv_free_clipart_section_aux(void *section) 900void psiconv_free_clipart_section_aux(void *section)
620{ 901{
621 if (section) 902 if (section)
622 free(((psiconv_clipart_section ) section)->picture); 903 psiconv_free_paint_data_section(((psiconv_clipart_section) section)->picture);
623} 904}
624 905
625void psiconv_free_clipart_section(psiconv_clipart_section section) 906void psiconv_free_clipart_section(psiconv_clipart_section section)
626{ 907{
627 if (section) { 908 if (section) {
680 const psiconv_font value2) 961 const psiconv_font value2)
681{ 962{
682 if (!value1 || !value2 || !value1->name || !value2->name) 963 if (!value1 || !value2 || !value1->name || !value2->name)
683 return 1; 964 return 1;
684 if ((value1->screenfont == value2->screenfont) && 965 if ((value1->screenfont == value2->screenfont) &&
685 !strcmp(value1->name,value2->name)) 966 !psiconv_unicode_strcmp(value1->name,value2->name))
686 return 0; 967 return 0;
687 else 968 else
688 return 1; 969 return 1;
689} 970}
690 971
953 result->cursor_row = result->cursor_column = 0; 1234 result->cursor_row = result->cursor_column = 0;
954 result->sheet_display_size = result->graph_display_size = 1000; 1235 result->sheet_display_size = result->graph_display_size = 1000;
955 return result; 1236 return result;
956} 1237}
957 1238
1239psiconv_formula_list psiconv_empty_formula_list(void)
1240{
1241 return psiconv_list_new(sizeof(struct psiconv_formula_s));
1242}
1243
1244psiconv_sheet_workbook_section psiconv_empty_sheet_workbook_section(void)
1245{
1246 psiconv_sheet_workbook_section result;
1247 if (!(result = malloc(sizeof(*result))))
1248 goto ERROR1;
1249 if (!(result->formulas = psiconv_empty_formula_list()))
1250 goto ERROR2;
1251 return result;
1252ERROR2:
1253 free(result);
1254ERROR1:
1255 return NULL;
1256}
1257
1258
958psiconv_sheet_f psiconv_empty_sheet_f(void) 1259psiconv_sheet_f psiconv_empty_sheet_f(void)
959{ 1260{
960 psiconv_sheet_f result; 1261 psiconv_sheet_f result;
961 if (!(result = malloc(sizeof(*result)))) 1262 if (!(result = malloc(sizeof(*result))))
962 goto ERROR1; 1263 goto ERROR1;
963 if (!(result->page_sec = psiconv_empty_page_layout_section())) 1264 if (!(result->page_sec = psiconv_empty_page_layout_section()))
964 goto ERROR2; 1265 goto ERROR2;
965 if (!(result->status_sec = psiconv_empty_sheet_status_section())) 1266 if (!(result->status_sec = psiconv_empty_sheet_status_section()))
966 goto ERROR3; 1267 goto ERROR3;
1268 if (!(result->workbook_sec = psiconv_empty_sheet_workbook_section()))
1269 goto ERROR4;
967 return result; 1270 return result;
1271ERROR4:
1272 psiconv_free_sheet_status_section(result->status_sec);
968ERROR3: 1273ERROR3:
969 psiconv_free_page_layout_section(result->page_sec); 1274 psiconv_free_page_layout_section(result->page_sec);
970ERROR2: 1275ERROR2:
971 free(result); 1276 free(result);
972ERROR1: 1277ERROR1:
1054psiconv_sketch_section psiconv_empty_sketch_section(void) 1359psiconv_sketch_section psiconv_empty_sketch_section(void)
1055{ 1360{
1056 psiconv_sketch_section result; 1361 psiconv_sketch_section result;
1057 if (!(result = malloc(sizeof(*result)))) 1362 if (!(result = malloc(sizeof(*result))))
1058 goto ERROR1; 1363 goto ERROR1;
1059 result->form_xsize = 320; 1364 result->displayed_xsize = 320;
1060 result->form_ysize = 200; 1365 result->displayed_ysize = 200;
1061 result->picture_x_offset = result->picture_y_offset = result->picture_xsize = 1366 result->picture_data_x_offset = result->picture_data_y_offset =
1062 result->picture_ysize = 0; 1367 result->form_xsize = result->form_ysize =
1368 result->displayed_size_x_offset = result->displayed_size_y_offset = 0;
1063 result->magnification_x = result->magnification_y = 1.0; 1369 result->magnification_x = result->magnification_y = 1.0;
1064 result->cut_left = result->cut_right = result->cut_top = 1370 result->cut_left = result->cut_right = result->cut_top =
1065 result->cut_bottom = 0.0; 1371 result->cut_bottom = 0.0;
1066 if (!(result->picture = psiconv_empty_paint_data_section())) 1372 if (!(result->picture = psiconv_empty_paint_data_section()))
1067 goto ERROR2; 1373 goto ERROR2;

Legend:
Removed from v.94  
changed lines
  Added in v.240

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