/[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 97 Revision 241
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#include "error.h"
28
29#ifdef DMALLOC
30#include <dmalloc.h>
31#endif
26 32
27static psiconv_color clone_color(psiconv_color color); 33static psiconv_color clone_color(psiconv_color color);
28static psiconv_font clone_font(psiconv_font font); 34static psiconv_font clone_font(psiconv_font font);
29static psiconv_border clone_border(psiconv_border border); 35static psiconv_border clone_border(psiconv_border border);
30static psiconv_bullet clone_bullet(psiconv_bullet bullet); 36static psiconv_bullet clone_bullet(psiconv_bullet bullet);
32static void psiconv_free_style_aux(void *style); 38static void psiconv_free_style_aux(void *style);
33static void psiconv_free_in_line_layout_aux(void * layout); 39static void psiconv_free_in_line_layout_aux(void * layout);
34static void psiconv_free_paragraph_aux(void * paragraph); 40static void psiconv_free_paragraph_aux(void * paragraph);
35static void psiconv_free_paint_data_section_aux(void * section); 41static void psiconv_free_paint_data_section_aux(void * section);
36static 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);
37 49
38static psiconv_word_styles_section psiconv_empty_word_styles_section(void); 50static psiconv_word_styles_section psiconv_empty_word_styles_section(void);
39static psiconv_text_and_layout psiconv_empty_text_and_layout(void); 51static psiconv_text_and_layout psiconv_empty_text_and_layout(void);
40static psiconv_texted_section psiconv_empty_texted_section(void); 52static psiconv_texted_section psiconv_empty_texted_section(void);
41static psiconv_page_header psiconv_empty_page_header(void); 53static psiconv_page_header psiconv_empty_page_header(void);
42static psiconv_page_layout_section psiconv_empty_page_layout_section(void); 54static psiconv_page_layout_section psiconv_empty_page_layout_section(void);
43static psiconv_word_status_section psiconv_empty_word_status_section(void); 55static psiconv_word_status_section psiconv_empty_word_status_section(void);
44static psiconv_word_f psiconv_empty_word_f(void); 56static psiconv_word_f psiconv_empty_word_f(void);
45static psiconv_sheet_status_section psiconv_empty_sheet_status_section(void); 57static psiconv_sheet_status_section psiconv_empty_sheet_status_section(void);
46static psiconv_sheet_formula_list psiconv_empty_sheet_formula_list(void); 58static psiconv_formula_list psiconv_empty_formula_list(void);
47static psiconv_sheet_workbook_section 59static psiconv_sheet_workbook_section
48 psiconv_empty_sheet_workbook_section(void); 60 psiconv_empty_sheet_workbook_section(void);
49static psiconv_sheet_f psiconv_empty_sheet_f(void); 61static psiconv_sheet_f psiconv_empty_sheet_f(void);
50static psiconv_texted_f psiconv_empty_texted_f(void); 62static psiconv_texted_f psiconv_empty_texted_f(void);
51static psiconv_paint_data_section psiconv_empty_paint_data_section(void); 63static psiconv_paint_data_section psiconv_empty_paint_data_section(void);
72 { 84 {
73 0xff, /* red */ 85 0xff, /* red */
74 0xff, /* green */ 86 0xff, /* green */
75 0xff, /* blue */ 87 0xff, /* blue */
76 }; 88 };
89 static psiconv_ucs2 font_times[16] = { 'T','i','m','e','s',' ',
90 'N','e','w',' ',
91 'R','o','m','a','n',0 };
77 static struct psiconv_font_s font = 92 static struct psiconv_font_s font =
78 { 93 {
79 "Times New Roman", /* name */ 94 font_times, /* name */
80 3 /* screenfont */ 95 3 /* screenfont */
81 }; 96 };
82 struct psiconv_character_layout_s cl = 97 struct psiconv_character_layout_s cl =
83 { 98 {
84 &black, /* color */ 99 &black, /* color */
97 112
98/* Note: these defaults seem to be hard-coded somewhere outside the 113/* Note: these defaults seem to be hard-coded somewhere outside the
99 files themself. */ 114 files themself. */
100psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) 115psiconv_paragraph_layout psiconv_basic_paragraph_layout(void)
101{ 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
102 static struct psiconv_font_s font = 121 static struct psiconv_font_s font =
103 { 122 {
104 "Times New Roman", /* name */ 123 font_times, /* name */
105 2 /* screenfont */ 124 2 /* screenfont */
106 }; 125 };
107 static struct psiconv_color_s black = 126 static struct psiconv_color_s black =
108 { 127 {
109 0x00, /* red */ 128 0x00, /* red */
124 }; 143 };
125 static struct psiconv_bullet_s bullet = 144 static struct psiconv_bullet_s bullet =
126 { 145 {
127 psiconv_bool_false, /* on */ 146 psiconv_bool_false, /* on */
128 10.0, /* font_size */ 147 10.0, /* font_size */
129 0x95, /* character */ 148 0x201d, /* character */
130 psiconv_bool_true, /* indent */ 149 psiconv_bool_true, /* indent */
131 &black, /* color */ 150 &black, /* color */
132 &font, /* font */ 151 &font, /* font */
133 }; 152 };
134 static struct psiconv_all_tabs_s tabs = 153 static struct psiconv_all_tabs_s tabs =
150 0.0, /* space_below */ 169 0.0, /* space_below */
151 psiconv_bool_false, /* keep_together */ 170 psiconv_bool_false, /* keep_together */
152 psiconv_bool_false, /* keep_with_next */ 171 psiconv_bool_false, /* keep_with_next */
153 psiconv_bool_false, /* on_next_page */ 172 psiconv_bool_false, /* on_next_page */
154 psiconv_bool_false, /* no_widow_protection */ 173 psiconv_bool_false, /* no_widow_protection */
174 psiconv_bool_false, /* wrap_to_fit_cell */
155 0.0, /* left_margin */ 175 0.0, /* left_margin */
156 &bullet, /* bullet */ 176 &bullet, /* bullet */
157 &no_border, /* left_border */ 177 &no_border, /* left_border */
158 &no_border, /* right_border */ 178 &no_border, /* right_border */
159 &no_border, /* top_border */ 179 &no_border, /* top_border */
182{ 202{
183 psiconv_font result; 203 psiconv_font result;
184 if(!(result = malloc(sizeof(*result)))) 204 if(!(result = malloc(sizeof(*result))))
185 goto ERROR1; 205 goto ERROR1;
186 *result = *font; 206 *result = *font;
187 if (!(result->name = strdup(result->name))) 207 if (!(result->name = psiconv_unicode_strdup(result->name)))
188 goto ERROR2; 208 goto ERROR2;
189 return result; 209 return result;
190ERROR2: 210ERROR2:
191 free(result); 211 free(result);
192ERROR1: 212ERROR1:
314 return ss->normal; 334 return ss->normal;
315 else 335 else
316 return psiconv_list_get(ss->styles,0xff - nr); 336 return psiconv_list_get(ss->styles,0xff - nr);
317} 337}
318 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
319void psiconv_free_color (psiconv_color color) 394void psiconv_free_color (psiconv_color color)
320{ 395{
321 if (color) 396 if (color)
322 free(color); 397 free(color);
323} 398}
400 psiconv_free_style_aux(style); 475 psiconv_free_style_aux(style);
401 free(style); 476 free(style);
402 } 477 }
403} 478}
404 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
405void psiconv_free_word_styles_section(psiconv_word_styles_section styles) 486void psiconv_free_word_styles_section(psiconv_word_styles_section styles)
406{ 487{
407 if (styles) { 488 if (styles) {
408 psiconv_free_word_style(styles->normal); 489 psiconv_free_word_style(styles->normal);
409 if (styles->styles) 490 psiconv_free_word_style_list(styles->styles);
410 psiconv_list_free_el(styles->styles,psiconv_free_style_aux); 491 free(styles);
411 } 492 }
412} 493}
413 494
414void psiconv_free_header_section(psiconv_header_section header) 495void psiconv_free_header_section(psiconv_header_section header)
415{ 496{
436 free(section->name); 517 free(section->name);
437 free(section); 518 free(section);
438 } 519 }
439} 520}
440 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
441void psiconv_free_in_line_layout_aux(void * layout) 548void psiconv_free_in_line_layout_aux(void * layout)
442{ 549{
443 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);
444} 553}
445 554
446void psiconv_free_in_line_layout(psiconv_in_line_layout layout) 555void psiconv_free_in_line_layout(psiconv_in_line_layout layout)
447{ 556{
448 if (layout) { 557 if (layout) {
545{ 654{
546 if (section) 655 if (section)
547 free(section); 656 free(section);
548} 657}
549 658
550void psiconv_free_sheet_formula(psiconv_sheet_formula formula) 659void psiconv_free_sheet_numberformat(psiconv_sheet_numberformat numberformat)
551{ 660{
552 if (formula) 661 if (numberformat)
553 free(formula); 662 free(numberformat);
554} 663}
555 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
556void psiconv_free_sheet_formula_list(psiconv_sheet_formula_list list) 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)
557{ 719{
558 if (list) 720 if (list)
559 psiconv_list_free(list); 721 psiconv_list_free(list);
560} 722}
561 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
562void psiconv_free_sheet_workbook_section(psiconv_sheet_workbook_section section) 843void psiconv_free_sheet_workbook_section(psiconv_sheet_workbook_section section)
563{ 844{
564 if (section) { 845 if (section) {
565 psiconv_free_sheet_formula_list(section->formulas); 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);
566 free(section); 851 free(section);
567 } 852 }
568} 853}
569 854
570void psiconv_free_sheet_f(psiconv_sheet_f file) 855void psiconv_free_sheet_f(psiconv_sheet_f file)
641} 926}
642 927
643void psiconv_free_clipart_section_aux(void *section) 928void psiconv_free_clipart_section_aux(void *section)
644{ 929{
645 if (section) 930 if (section)
646 free(((psiconv_clipart_section ) section)->picture); 931 psiconv_free_paint_data_section(((psiconv_clipart_section) section)->picture);
647} 932}
648 933
649void psiconv_free_clipart_section(psiconv_clipart_section section) 934void psiconv_free_clipart_section(psiconv_clipart_section section)
650{ 935{
651 if (section) { 936 if (section) {
704 const psiconv_font value2) 989 const psiconv_font value2)
705{ 990{
706 if (!value1 || !value2 || !value1->name || !value2->name) 991 if (!value1 || !value2 || !value1->name || !value2->name)
707 return 1; 992 return 1;
708 if ((value1->screenfont == value2->screenfont) && 993 if ((value1->screenfont == value2->screenfont) &&
709 !strcmp(value1->name,value2->name)) 994 !psiconv_unicode_strcmp(value1->name,value2->name))
710 return 0; 995 return 0;
711 else 996 else
712 return 1; 997 return 1;
713} 998}
714 999
977 result->cursor_row = result->cursor_column = 0; 1262 result->cursor_row = result->cursor_column = 0;
978 result->sheet_display_size = result->graph_display_size = 1000; 1263 result->sheet_display_size = result->graph_display_size = 1000;
979 return result; 1264 return result;
980} 1265}
981 1266
982psiconv_sheet_formula_list psiconv_empty_sheet_formula_list(void) 1267psiconv_formula_list psiconv_empty_formula_list(void)
983{ 1268{
984 return psiconv_list_new(sizeof(struct psiconv_sheet_formula_s)); 1269 return psiconv_list_new(sizeof(struct psiconv_formula_s));
985} 1270}
986 1271
987psiconv_sheet_workbook_section psiconv_empty_sheet_workbook_section(void) 1272psiconv_sheet_workbook_section psiconv_empty_sheet_workbook_section(void)
988{ 1273{
989 psiconv_sheet_workbook_section result; 1274 psiconv_sheet_workbook_section result;
990 if (!(result = malloc(sizeof(*result)))) 1275 if (!(result = malloc(sizeof(*result))))
991 goto ERROR1; 1276 goto ERROR1;
992 if (!(result->formulas = psiconv_empty_sheet_formula_list())) 1277 if (!(result->formulas = psiconv_empty_formula_list()))
993 goto ERROR2; 1278 goto ERROR2;
994 return result; 1279 return result;
995ERROR2: 1280ERROR2:
996 free(result); 1281 free(result);
997ERROR1: 1282ERROR1:
1102psiconv_sketch_section psiconv_empty_sketch_section(void) 1387psiconv_sketch_section psiconv_empty_sketch_section(void)
1103{ 1388{
1104 psiconv_sketch_section result; 1389 psiconv_sketch_section result;
1105 if (!(result = malloc(sizeof(*result)))) 1390 if (!(result = malloc(sizeof(*result))))
1106 goto ERROR1; 1391 goto ERROR1;
1107 result->form_xsize = 320; 1392 result->displayed_xsize = 320;
1108 result->form_ysize = 200; 1393 result->displayed_ysize = 200;
1109 result->picture_x_offset = result->picture_y_offset = result->picture_xsize = 1394 result->picture_data_x_offset = result->picture_data_y_offset =
1110 result->picture_ysize = 0; 1395 result->form_xsize = result->form_ysize =
1396 result->displayed_size_x_offset = result->displayed_size_y_offset = 0;
1111 result->magnification_x = result->magnification_y = 1.0; 1397 result->magnification_x = result->magnification_y = 1.0;
1112 result->cut_left = result->cut_right = result->cut_top = 1398 result->cut_left = result->cut_right = result->cut_top =
1113 result->cut_bottom = 0.0; 1399 result->cut_bottom = 0.0;
1114 if (!(result->picture = psiconv_empty_paint_data_section())) 1400 if (!(result->picture = psiconv_empty_paint_data_section()))
1115 goto ERROR2; 1401 goto ERROR2;

Legend:
Removed from v.97  
changed lines
  Added in v.241

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