/[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 42 Revision 78
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 Frodo Looijaard <frodol@dds.nl> 3 Copyright (c) 1999, 2000 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.
20#include "config.h" 20#include "config.h"
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"
26#include "general.h"
27 25
28static psiconv_color clone_color(psiconv_color color); 26static psiconv_color clone_color(psiconv_color color);
29static psiconv_font clone_font(psiconv_font font); 27static psiconv_font clone_font(psiconv_font font);
30static psiconv_border clone_border(psiconv_border border); 28static psiconv_border clone_border(psiconv_border border);
31static psiconv_bullet clone_bullet(psiconv_bullet bullet); 29static psiconv_bullet clone_bullet(psiconv_bullet bullet);
34static void psiconv_free_in_line_layout_aux(void * layout); 32static void psiconv_free_in_line_layout_aux(void * layout);
35static void psiconv_free_paragraph_aux(void * paragraph); 33static void psiconv_free_paragraph_aux(void * paragraph);
36static void psiconv_free_paint_data_section_aux(void * section); 34static void psiconv_free_paint_data_section_aux(void * section);
37static void psiconv_free_clipart_section_aux(void * section); 35static void psiconv_free_clipart_section_aux(void * section);
38 36
37/* Note: these defaults seem to be hard-coded somewhere outside the
38 files themself. */
39psiconv_character_layout psiconv_basic_character_layout(void) 39psiconv_character_layout psiconv_basic_character_layout(void)
40{ 40{
41 /* Make the structures static, to oblige IRIX */ 41 /* Make the structures static, to oblige IRIX */
42 static struct psiconv_color black = 42 static struct psiconv_color_s black =
43 { 43 {
44 0x00, /* red */ 44 0x00, /* red */
45 0x00, /* green */ 45 0x00, /* green */
46 0x00, /* blue */ 46 0x00, /* blue */
47 }; 47 };
48 static struct psiconv_color white = 48 static struct psiconv_color_s white =
49 { 49 {
50 0xff, /* red */ 50 0xff, /* red */
51 0xff, /* green */ 51 0xff, /* green */
52 0xff, /* blue */ 52 0xff, /* blue */
53 }; 53 };
54 static struct psiconv_font font = 54 static struct psiconv_font_s font =
55 { 55 {
56 "Times New Roman", /* name */ 56 "Times New Roman", /* name */
57 3 /* screenfont */ 57 3 /* screenfont */
58 }; 58 };
59 struct psiconv_character_layout cl = 59 struct psiconv_character_layout_s cl =
60 { 60 {
61 &black, /* color */ 61 &black, /* color */
62 &white, /* back_color */ 62 &white, /* back_color */
63 10.0, /* font_size */ 63 10.0, /* font_size */
64 psiconv_bool_false, /* italic */ 64 psiconv_bool_false, /* italic */
65 psiconv_bool_false, /* bold */ 65 psiconv_bool_false, /* bold */
66 psiconv_normalscript, /* super_sub */ 66 psiconv_normalscript, /* super_sub */
67 psiconv_bool_false, /* underline */ 67 psiconv_bool_false, /* underline */
68 psiconv_bool_false, /* strike_out */ 68 psiconv_bool_false, /* strikethrough */
69 &font, /* font */ 69 &font, /* font */
70 }; 70 };
71 71
72 return psiconv_clone_character_layout(&cl); 72 return psiconv_clone_character_layout(&cl);
73} 73}
74 74
75/* Note: these defaults seem to be hard-coded somewhere outside the
76 files themself. */
75psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) 77psiconv_paragraph_layout psiconv_basic_paragraph_layout(void)
76{ 78{
77 static struct psiconv_font font = 79 static struct psiconv_font_s font =
78 { 80 {
79 "Times New Roman", /* name */ 81 "Times New Roman", /* name */
80 2 /* screenfont */ 82 2 /* screenfont */
81 }; 83 };
82 static struct psiconv_color black = 84 static struct psiconv_color_s black =
83 { 85 {
84 0x00, /* red */ 86 0x00, /* red */
85 0x00, /* green */ 87 0x00, /* green */
86 0x00, /* blue */ 88 0x00, /* blue */
87 }; 89 };
88 static struct psiconv_color white = 90 static struct psiconv_color_s white =
89 { 91 {
90 0xff, /* red */ 92 0xff, /* red */
91 0xff, /* green */ 93 0xff, /* green */
92 0xff, /* blue */ 94 0xff, /* blue */
93 }; 95 };
94 static struct psiconv_border no_border = 96 static struct psiconv_border_s no_border =
95 { 97 {
96 psiconv_border_none, /* kind */ 98 psiconv_border_none, /* kind */
97 1, /* thickness */ 99 1, /* thickness */
98 &black /* color */ 100 &black /* color */
99 }; 101 };
100 static struct psiconv_bullet bullet = 102 static struct psiconv_bullet_s bullet =
101 { 103 {
102 psiconv_bool_false, /* on */ 104 psiconv_bool_false, /* on */
103 10.0, /* font_size */ 105 10.0, /* font_size */
104 0x95, /* character */ 106 0x95, /* character */
105 psiconv_bool_true, /* indent */ 107 psiconv_bool_true, /* indent */
106 &black, /* color */ 108 &black, /* color */
107 &font, /* font */ 109 &font, /* font */
108 }; 110 };
109 static struct psiconv_all_tabs tabs = 111 static struct psiconv_all_tabs_s tabs =
110 { 112 {
111 0.64, /* normal */ 113 0.64, /* normal */
112 NULL /* kind */ 114 NULL /* kind */
113 }; 115 };
114 struct psiconv_paragraph_layout pl = 116 struct psiconv_paragraph_layout_s pl =
115 { 117 {
116 &white, /* back_color */ 118 &white, /* back_color */
117 0.0, /* indent_left */ 119 0.0, /* indent_left */
118 0.0, /* indent_right */ 120 0.0, /* indent_right */
119 0.0, /* indent_first */ 121 0.0, /* indent_first */
120 psiconv_justify_left, /* justify_hor */ 122 psiconv_justify_left, /* justify_hor */
121 psiconv_justify_middle,/* justify_ver */ 123 psiconv_justify_middle,/* justify_ver */
122 0.0, /* interline */ 124 10.0, /* linespacing */
123 psiconv_bool_false, /* interline_exact */ 125 psiconv_bool_false, /* linespacing_exact */
124 0.0, /* top_space */ 126 0.0, /* space_above */
125 0.0, /* bottom_space */ 127 0.0, /* space_below */
126 psiconv_bool_false, /* on_one_page */
127 psiconv_bool_false, /* together_with */ 128 psiconv_bool_false, /* keep_together */
129 psiconv_bool_false, /* keep_with_next */
128 psiconv_bool_false, /* on_next_page */ 130 psiconv_bool_false, /* on_next_page */
129 psiconv_bool_false, /* no_widow_protection */ 131 psiconv_bool_false, /* no_widow_protection */
130 0.0, /* left_margin */ 132 0.0, /* left_margin */
131 &bullet, /* bullet */ 133 &bullet, /* bullet */
132 &no_border, /* left_border */ 134 &no_border, /* left_border */
135 &no_border, /* bottom_border */ 137 &no_border, /* bottom_border */
136 &tabs, /* tabs */ 138 &tabs, /* tabs */
137 }; 139 };
138 psiconv_paragraph_layout res; 140 psiconv_paragraph_layout res;
139 141
140 pl.tabs->extras = psiconv_list_new(sizeof(struct psiconv_tab)); 142 if (!(pl.tabs->extras = psiconv_list_new(sizeof(struct psiconv_tab_s))))
143 return NULL;
141 res = psiconv_clone_paragraph_layout(&pl); 144 res = psiconv_clone_paragraph_layout(&pl);
142 psiconv_list_free(pl.tabs->extras); 145 psiconv_list_free(pl.tabs->extras);
143 return res; 146 return res;
144} 147}
145 148
146psiconv_color clone_color(psiconv_color color) 149psiconv_color clone_color(psiconv_color color)
147{ 150{
148 psiconv_color result; 151 psiconv_color result;
149 result = malloc(sizeof(*result)); 152 if (!(result = malloc(sizeof(*result))))
153 return NULL;
150 *result = *color; 154 *result = *color;
151 return result; 155 return result;
152} 156}
153 157
154psiconv_font clone_font(psiconv_font font) 158psiconv_font clone_font(psiconv_font font)
155{ 159{
156 psiconv_font result; 160 psiconv_font result;
157 result = malloc(sizeof(*result)); 161 if(!(result = malloc(sizeof(*result))))
162 goto ERROR1;
158 *result = *font; 163 *result = *font;
159 result->name = strdup(result->name); 164 if (!(result->name = strdup(result->name)))
165 goto ERROR2;
160 return result; 166 return result;
167ERROR2:
168 free(result);
169ERROR1:
170 return NULL;
161} 171}
162 172
163psiconv_border clone_border(psiconv_border border) 173psiconv_border clone_border(psiconv_border border)
164{ 174{
165 psiconv_border result; 175 psiconv_border result;
166 result = malloc(sizeof(*result)); 176 if (!(result = malloc(sizeof(*result))))
177 goto ERROR1;
167 *result = *border; 178 *result = *border;
168 result->color = clone_color(result->color); 179 if(!(result->color = clone_color(result->color)))
180 goto ERROR2;
169 return result; 181 return result;
182ERROR2:
183 free(result);
184ERROR1:
185 return NULL;
170} 186}
171 187
172psiconv_bullet clone_bullet(psiconv_bullet bullet) 188psiconv_bullet clone_bullet(psiconv_bullet bullet)
173{ 189{
174 psiconv_bullet result; 190 psiconv_bullet result;
175 result = malloc(sizeof(*result)); 191 if (!(result = malloc(sizeof(*result))))
192 goto ERROR1;
176 *result = *bullet; 193 *result = *bullet;
177 result->font = clone_font(result->font); 194 if (!(result->font = clone_font(result->font)))
195 goto ERROR2;
178 result->color = clone_color(result->color); 196 if (!(result->color = clone_color(result->color)))
197 goto ERROR3;
179 return result; 198 return result;
199ERROR3:
200 psiconv_free_font(result->font);
201ERROR2:
202 free(result);
203ERROR1:
204 return NULL;
180} 205}
181 206
182psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs) 207psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs)
183{ 208{
184 psiconv_all_tabs result; 209 psiconv_all_tabs result;
185 result = malloc(sizeof(*result)); 210 if (!(result = malloc(sizeof(*result))))
211 goto ERROR1;
186 *result = *all_tabs; 212 *result = *all_tabs;
187 result->extras = psiconv_list_clone(result->extras); 213 if (!(result->extras = psiconv_list_clone(result->extras)))
214 goto ERROR2;
188 return result; 215 return result;
216ERROR2:
217 free(result);
218ERROR1:
219 return NULL;
189} 220}
190 221
191psiconv_character_layout psiconv_clone_character_layout 222psiconv_character_layout psiconv_clone_character_layout
192 (psiconv_character_layout ls) 223 (psiconv_character_layout ls)
193{ 224{
194 psiconv_character_layout result; 225 psiconv_character_layout result;
195 226
196 result = malloc(sizeof(*result)); 227 if (!(result = malloc(sizeof(*result))))
228 goto ERROR1;
197 *result = *ls; 229 *result = *ls;
198 result->color = clone_color(result->color); 230 if (!(result->color = clone_color(result->color)))
231 goto ERROR2;
199 result->back_color = clone_color(result->back_color); 232 if (!(result->back_color = clone_color(result->back_color)))
233 goto ERROR3;
200 result->font = clone_font(result->font); 234 if (!(result->font = clone_font(result->font)))
235 goto ERROR4;
201 return result; 236 return result;
237ERROR4:
238 psiconv_free_color(result->back_color);
239ERROR3:
240 psiconv_free_color(result->color);
241ERROR2:
242 free(result);
243ERROR1:
244 return NULL;
202} 245}
203 246
204psiconv_paragraph_layout psiconv_clone_paragraph_layout 247psiconv_paragraph_layout psiconv_clone_paragraph_layout
205 (psiconv_paragraph_layout ls) 248 (psiconv_paragraph_layout ls)
206{ 249{
207 psiconv_paragraph_layout result; 250 psiconv_paragraph_layout result;
208 251
209 result = malloc(sizeof(*result)); 252 if (!(result = malloc(sizeof(*result))))
253 goto ERROR1;
210 *result = *ls; 254 *result = *ls;
211 result->back_color = clone_color(result->back_color); 255 if (!(result->back_color = clone_color(result->back_color)))
256 goto ERROR2;
212 result->bullet = clone_bullet(result->bullet); 257 if (!(result->bullet = clone_bullet(result->bullet)))
258 goto ERROR3;
213 result->left_border = clone_border(result->left_border); 259 if (!(result->left_border = clone_border(result->left_border)))
260 goto ERROR4;
214 result->right_border = clone_border(result->right_border); 261 if (!(result->right_border = clone_border(result->right_border)))
262 goto ERROR5;
215 result->top_border = clone_border(result->top_border); 263 if (!(result->top_border = clone_border(result->top_border)))
264 goto ERROR6;
216 result->bottom_border = clone_border(result->bottom_border); 265 if (!(result->bottom_border = clone_border(result->bottom_border)))
266 goto ERROR7;
217 result->tabs = clone_all_tabs(result->tabs); 267 if (!(result->tabs = clone_all_tabs(result->tabs)))
268 goto ERROR8;
218 return result; 269 return result;
270ERROR8:
271 psiconv_free_border(result->bottom_border);
272ERROR7:
273 psiconv_free_border(result->top_border);
274ERROR6:
275 psiconv_free_border(result->right_border);
276ERROR5:
277 psiconv_free_border(result->left_border);
278ERROR4:
279 psiconv_free_bullet(result->bullet);
280ERROR3:
281 psiconv_free_color(result->back_color);
282ERROR2:
283 free(result);
284ERROR1:
285 return NULL;
219} 286}
220 287
221psiconv_word_style psiconv_get_style (psiconv_word_styles_section ss, int nr) 288psiconv_word_style psiconv_get_style (psiconv_word_styles_section ss, int nr)
222{ 289{
223 if (nr == 0) 290 if (nr == 0)
556 else if (file->type == psiconv_clipart_file) 623 else if (file->type == psiconv_clipart_file)
557 psiconv_free_clipart_f((psiconv_clipart_f) file->file); 624 psiconv_free_clipart_f((psiconv_clipart_f) file->file);
558 free(file); 625 free(file);
559 } 626 }
560} 627}
628
629int psiconv_compare_color(const psiconv_color value1,
630 const psiconv_color value2)
631{
632 if (!value1 || !value2)
633 return 1;
634 if ((value1->red == value2->red) &&
635 (value1->green == value2->green) &&
636 (value1->blue == value2->blue))
637 return 0;
638 else
639 return 1;
640}
641
642int psiconv_compare_font(const psiconv_font value1,
643 const psiconv_font value2)
644{
645 if (!value1 || !value2 || !value1->name || !value2->name)
646 return 1;
647 if ((value1->screenfont == value2->screenfont) &&
648 !strcmp(value1->name,value2->name))
649 return 0;
650 else
651 return 1;
652}
653
654int psiconv_compare_border(const psiconv_border value1,
655 const psiconv_border value2)
656{
657 if (!value1 || !value2)
658 return 1;
659 if ((value1->kind == value2->kind) &&
660 (value1->thickness == value2->thickness) &&
661 !psiconv_compare_color(value1->color,value2->color))
662 return 0;
663 else
664 return 1;
665}
666
667int psiconv_compare_bullet(const psiconv_bullet value1,
668 const psiconv_bullet value2)
669{
670 if (!value1 || !value2)
671 return 1;
672 if ((value1->on == value2->on) &&
673 (value1->font_size == value2->font_size) &&
674 (value1->character == value2->character) &&
675 (value1->indent == value2->indent) &&
676 !psiconv_compare_color(value1->color,value2->color) &&
677 !psiconv_compare_font(value1->font,value2->font))
678 return 0;
679 else
680 return 1;
681}
682
683int psiconv_compare_tab(const psiconv_tab value1, const psiconv_tab value2)
684{
685 if (!value1 || !value2)
686 return 1;
687 if ((value1->location == value2->location) &&
688 (value1->kind == value2->kind))
689 return 0;
690 else
691 return 1;
692}
693
694int psiconv_compare_all_tabs(const psiconv_all_tabs value1,
695 const psiconv_all_tabs value2)
696{
697 int i;
698
699 if (!value1 || !value2 || !value1->extras || !value2->extras)
700 return 1;
701
702 if ((value1->normal != value2->normal) ||
703 psiconv_list_length(value1->extras) !=
704 psiconv_list_length(value2->extras))
705 return 1;
706 for (i = 0; i < psiconv_list_length(value1->extras); i++)
707 if (psiconv_compare_tab(psiconv_list_get(value1->extras,i),
708 psiconv_list_get(value2->extras,i)))
709
710 return 1;
711 return 0;
712}
713
714int psiconv_compare_paragraph_layout(const psiconv_paragraph_layout value1,
715 const psiconv_paragraph_layout value2)
716{
717 if (!value1 || !value2)
718 return 1;
719 if ((value1->indent_left == value2->indent_left) &&
720 (value1->indent_right == value2->indent_right) &&
721 (value1->indent_first == value2->indent_first) &&
722 (value1->justify_hor == value2->justify_hor) &&
723 (value1->justify_ver == value2->justify_ver) &&
724 (value1->linespacing == value2->linespacing) &&
725 (value1->space_above == value2->space_above) &&
726 (value1->space_below == value2->space_below) &&
727 (value1->keep_together == value2->keep_together) &&
728 (value1->keep_with_next == value2->keep_with_next) &&
729 (value1->on_next_page == value2->on_next_page) &&
730 (value1->no_widow_protection == value2->no_widow_protection) &&
731 (value1->border_distance == value2->border_distance) &&
732 !psiconv_compare_color(value1->back_color,value2->back_color) &&
733 !psiconv_compare_bullet(value1->bullet,value2->bullet) &&
734 !psiconv_compare_border(value1->left_border,value2->left_border) &&
735 !psiconv_compare_border(value1->right_border,value2->right_border) &&
736 !psiconv_compare_border(value1->top_border,value2->top_border) &&
737 !psiconv_compare_border(value1->bottom_border,value2->bottom_border) &&
738 !psiconv_compare_all_tabs(value1->tabs,value2->tabs))
739 return 0;
740 else
741 return 1;
742}
743
744
745int psiconv_compare_character_layout(const psiconv_character_layout value1,
746 const psiconv_character_layout value2)
747{
748 if (!value1 || !value2)
749 return 1;
750 if ((value1->font_size == value2->font_size) &&
751 (value1->italic == value2->italic) &&
752 (value1->bold == value2->bold) &&
753 (value1->super_sub == value2->super_sub) &&
754 (value1->underline == value2->underline) &&
755 (value1->strikethrough == value2->strikethrough) &&
756 !psiconv_compare_color(value1->color,value2->color) &&
757 !psiconv_compare_color(value1->back_color,value2->back_color) &&
758 !psiconv_compare_font(value1->font,value2->font))
759 return 0;
760 else
761 return 1;
762}

Legend:
Removed from v.42  
changed lines
  Added in v.78

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