/[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 111 Revision 208
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);
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);
37static void psiconv_free_formula_aux(void *data); 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);
38static void psiconv_free_sheet_worksheet_aux (void *data); 47static void psiconv_free_sheet_worksheet_aux (void *data);
39 48
40static psiconv_word_styles_section psiconv_empty_word_styles_section(void); 49static psiconv_word_styles_section psiconv_empty_word_styles_section(void);
41static psiconv_text_and_layout psiconv_empty_text_and_layout(void); 50static psiconv_text_and_layout psiconv_empty_text_and_layout(void);
42static psiconv_texted_section psiconv_empty_texted_section(void); 51static 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. */
102psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) 114psiconv_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;
193ERROR2: 209ERROR2:
194 free(result); 210 free(result);
195ERROR1: 211ERROR1:
317 return ss->normal; 333 return ss->normal;
318 else 334 else
319 return psiconv_list_get(ss->styles,0xff - nr); 335 return psiconv_list_get(ss->styles,0xff - nr);
320} 336}
321 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
322void psiconv_free_color (psiconv_color color) 366void psiconv_free_color (psiconv_color color)
323{ 367{
324 if (color) 368 if (color)
325 free(color); 369 free(color);
326} 370}
409{ 453{
410 if (styles) { 454 if (styles) {
411 psiconv_free_word_style(styles->normal); 455 psiconv_free_word_style(styles->normal);
412 if (styles->styles) 456 if (styles->styles)
413 psiconv_list_free_el(styles->styles,psiconv_free_style_aux); 457 psiconv_list_free_el(styles->styles,psiconv_free_style_aux);
458 free(styles);
414 } 459 }
415} 460}
416 461
417void psiconv_free_header_section(psiconv_header_section header) 462void psiconv_free_header_section(psiconv_header_section header)
418{ 463{
439 free(section->name); 484 free(section->name);
440 free(section); 485 free(section);
441 } 486 }
442} 487}
443 488
489void psiconv_free_object_icon_section(psiconv_object_icon_section section)
490{
491 if (section) {
492 if (section->icon_name)
493 free(section->icon_name);
494 free(section);
495 }
496}
497
498void psiconv_free_object_display_section(psiconv_object_display_section section)
499{
500 if (section)
501 free(section);
502}
503
504void psiconv_free_embedded_object_section
505 (psiconv_embedded_object_section object)
506{
507 if (object) {
508 psiconv_free_object_icon_section(object->icon);
509 psiconv_free_object_display_section(object->display);
510 psiconv_free_file(object->object);
511 free(object);
512 }
513}
514
444void psiconv_free_in_line_layout_aux(void * layout) 515void psiconv_free_in_line_layout_aux(void * layout)
445{ 516{
446 psiconv_free_character_layout(((psiconv_in_line_layout) layout)->layout); 517 psiconv_free_character_layout(((psiconv_in_line_layout) layout)->layout);
518 psiconv_free_embedded_object_section
519 (((psiconv_in_line_layout) layout)->object);
447} 520}
448 521
449void psiconv_free_in_line_layout(psiconv_in_line_layout layout) 522void psiconv_free_in_line_layout(psiconv_in_line_layout layout)
450{ 523{
451 if (layout) { 524 if (layout) {
561 psiconv_free_paragraph_layout(layout->paragraph); 634 psiconv_free_paragraph_layout(layout->paragraph);
562 psiconv_free_character_layout(layout->character); 635 psiconv_free_character_layout(layout->character);
563 psiconv_free_sheet_numberformat(layout->numberformat); 636 psiconv_free_sheet_numberformat(layout->numberformat);
564} 637}
565 638
639void psiconv_free_sheet_cell_aux(void *cell)
640{
641 psiconv_sheet_cell data = cell;
642
643 psiconv_free_sheet_cell_layout(data->layout);
644
645 if ((data->type == psiconv_cell_string) && (data->data.dat_string))
646 free(data->data.dat_string);
647}
648
566void psiconv_free_sheet_cell(psiconv_sheet_cell cell) 649void psiconv_free_sheet_cell(psiconv_sheet_cell cell)
567{ 650{
568 if (cell) { 651 if (cell) {
569 psiconv_free_sheet_cell_layout(cell->layout); 652 psiconv_free_sheet_cell_aux(cell);
570
571 if ((cell->type == psiconv_cell_string) && (cell->data.dat_string))
572 free(cell->data.dat_string);
573 free(cell); 653 free(cell);
574 } 654 }
575}
576
577void psiconv_free_sheet_cell_aux(void *data)
578{
579 psiconv_sheet_cell cell;
580 cell = data;
581 psiconv_free_sheet_cell(cell);
582} 655}
583 656
584void psiconv_free_sheet_cell_list(psiconv_sheet_cell_list list) 657void psiconv_free_sheet_cell_list(psiconv_sheet_cell_list list)
585{ 658{
586 if (list) 659 if (list)
587 psiconv_list_free_el(list,psiconv_free_sheet_cell_aux); 660 psiconv_list_free_el(list,psiconv_free_sheet_cell_aux);
661}
662
663void psiconv_free_sheet_line_aux(void *line)
664{
665 psiconv_sheet_line data = line;
666
667 psiconv_free_sheet_cell_layout(data->layout);
668}
669
670void psiconv_free_sheet_line(psiconv_sheet_line line)
671{
672 if (line) {
673 psiconv_free_sheet_line_aux(line);
674 free(line);
675 }
676}
677
678
679void psiconv_free_sheet_line_list(psiconv_sheet_line_list list)
680{
681 if (list)
682 psiconv_list_free_el(list,psiconv_free_sheet_line_aux);
683}
684
685void psiconv_free_sheet_grid_break_list(psiconv_sheet_grid_break_list list)
686{
687 if (list)
688 psiconv_list_free(list);
689}
690
691void psiconv_free_sheet_grid_size(psiconv_sheet_grid_size s)
692{
693 if (s)
694 free(s);
695}
696
697void psiconv_free_sheet_grid_size_list(psiconv_sheet_grid_size_list list)
698{
699 if (list)
700 psiconv_list_free(list);
701}
702
703void psiconv_free_sheet_grid_section(psiconv_sheet_grid_section sec)
704{
705 if (sec) {
706 psiconv_free_sheet_grid_size_list(sec->row_heights);
707 psiconv_free_sheet_grid_size_list(sec->column_heights);
708 psiconv_free_sheet_grid_break_list(sec->row_page_breaks);
709 psiconv_free_sheet_grid_break_list(sec->column_page_breaks);
710 free(sec);
711 }
588} 712}
589 713
590void psiconv_free_sheet_worksheet_aux (void *data) 714void psiconv_free_sheet_worksheet_aux (void *data)
591{ 715{
592 psiconv_sheet_worksheet section = data; 716 psiconv_sheet_worksheet section = data;
593 psiconv_free_sheet_cell_layout(section->default_layout); 717 psiconv_free_sheet_cell_layout(section->default_layout);
594 psiconv_free_sheet_cell_list(section->cells); 718 psiconv_free_sheet_cell_list(section->cells);
719 psiconv_free_sheet_line_list(section->row_default_layouts);
720 psiconv_free_sheet_line_list(section->col_default_layouts);
721 psiconv_free_sheet_grid_section(section->grid);
595} 722}
596 723
597void psiconv_free_sheet_worksheet(psiconv_sheet_worksheet sheet) 724void psiconv_free_sheet_worksheet(psiconv_sheet_worksheet sheet)
598{ 725{
599 if (sheet) { 726 if (sheet) {
639{ 766{
640 if (list) 767 if (list)
641 psiconv_list_free_el(list,psiconv_free_formula_aux); 768 psiconv_list_free_el(list,psiconv_free_formula_aux);
642} 769}
643 770
771void psiconv_free_sheet_name_section(psiconv_sheet_name_section section)
772{
773 if (section) {
774 if(section->name)
775 free(section->name);
776 free(section);
777 }
778}
779
780void psiconv_free_sheet_info_section(psiconv_sheet_info_section section)
781{
782 if (section) {
783 free(section);
784 }
785}
786
787void psiconv_free_sheet_variable_aux(void * variable)
788{
789 psiconv_sheet_variable var = variable;
790 if (var->name)
791 free(var->name);
792 if (var->type == psiconv_var_string)
793 free(var->data.dat_string);
794}
795
796void psiconv_free_sheet_variable(psiconv_sheet_variable var)
797{
798 if (var) {
799 psiconv_free_sheet_variable_aux(var);
800 free(var);
801 }
802}
803
804void psiconv_free_sheet_variable_list(psiconv_sheet_variable_list list)
805{
806 if (list)
807 psiconv_list_free_el(list,psiconv_free_sheet_variable_aux);
808}
809
644void psiconv_free_sheet_workbook_section(psiconv_sheet_workbook_section section) 810void psiconv_free_sheet_workbook_section(psiconv_sheet_workbook_section section)
645{ 811{
646 if (section) { 812 if (section) {
647 psiconv_free_formula_list(section->formulas); 813 psiconv_free_formula_list(section->formulas);
648 psiconv_free_sheet_worksheet_list(section->worksheets); 814 psiconv_free_sheet_worksheet_list(section->worksheets);
815 psiconv_free_sheet_name_section(section->name);
816 psiconv_free_sheet_info_section(section->info);
817 psiconv_free_sheet_variable_list(section->variables);
649 free(section); 818 free(section);
650 } 819 }
651} 820}
652 821
653void psiconv_free_sheet_f(psiconv_sheet_f file) 822void psiconv_free_sheet_f(psiconv_sheet_f file)
724} 893}
725 894
726void psiconv_free_clipart_section_aux(void *section) 895void psiconv_free_clipart_section_aux(void *section)
727{ 896{
728 if (section) 897 if (section)
729 free(((psiconv_clipart_section ) section)->picture); 898 psiconv_free_paint_data_section(((psiconv_clipart_section) section)->picture);
730} 899}
731 900
732void psiconv_free_clipart_section(psiconv_clipart_section section) 901void psiconv_free_clipart_section(psiconv_clipart_section section)
733{ 902{
734 if (section) { 903 if (section) {
787 const psiconv_font value2) 956 const psiconv_font value2)
788{ 957{
789 if (!value1 || !value2 || !value1->name || !value2->name) 958 if (!value1 || !value2 || !value1->name || !value2->name)
790 return 1; 959 return 1;
791 if ((value1->screenfont == value2->screenfont) && 960 if ((value1->screenfont == value2->screenfont) &&
792 !strcmp(value1->name,value2->name)) 961 !psiconv_unicode_strcmp(value1->name,value2->name))
793 return 0; 962 return 0;
794 else 963 else
795 return 1; 964 return 1;
796} 965}
797 966
1185psiconv_sketch_section psiconv_empty_sketch_section(void) 1354psiconv_sketch_section psiconv_empty_sketch_section(void)
1186{ 1355{
1187 psiconv_sketch_section result; 1356 psiconv_sketch_section result;
1188 if (!(result = malloc(sizeof(*result)))) 1357 if (!(result = malloc(sizeof(*result))))
1189 goto ERROR1; 1358 goto ERROR1;
1190 result->form_xsize = 320; 1359 result->displayed_xsize = 320;
1191 result->form_ysize = 200; 1360 result->displayed_ysize = 200;
1192 result->picture_x_offset = result->picture_y_offset = result->picture_xsize = 1361 result->picture_data_x_offset = result->picture_data_y_offset =
1193 result->picture_ysize = 0; 1362 result->form_xsize = result->form_ysize =
1363 result->displayed_size_x_offset = result->displayed_size_y_offset = 0;
1194 result->magnification_x = result->magnification_y = 1.0; 1364 result->magnification_x = result->magnification_y = 1.0;
1195 result->cut_left = result->cut_right = result->cut_top = 1365 result->cut_left = result->cut_right = result->cut_top =
1196 result->cut_bottom = 0.0; 1366 result->cut_bottom = 0.0;
1197 if (!(result->picture = psiconv_empty_paint_data_section())) 1367 if (!(result->picture = psiconv_empty_paint_data_section()))
1198 goto ERROR2; 1368 goto ERROR2;

Legend:
Removed from v.111  
changed lines
  Added in v.208

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