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 | |
28 | static psiconv_color clone_color(psiconv_color color); |
26 | static psiconv_color clone_color(psiconv_color color); |
29 | static psiconv_font clone_font(psiconv_font font); |
27 | static psiconv_font clone_font(psiconv_font font); |
30 | static psiconv_border clone_border(psiconv_border border); |
28 | static psiconv_border clone_border(psiconv_border border); |
31 | static psiconv_bullet clone_bullet(psiconv_bullet bullet); |
29 | static psiconv_bullet clone_bullet(psiconv_bullet bullet); |
32 | static psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs); |
30 | static psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs); |
33 | static void psiconv_free_style_aux(void *style); |
31 | static void psiconv_free_style_aux(void *style); |
34 | static void psiconv_free_in_line_layout_aux(void * layout); |
32 | static void psiconv_free_in_line_layout_aux(void * layout); |
35 | static void psiconv_free_paragraph_aux(void * paragraph); |
33 | static void psiconv_free_paragraph_aux(void * paragraph); |
36 | static void psiconv_free_paint_data_section_aux(void * section); |
34 | static void psiconv_free_paint_data_section_aux(void * section); |
|
|
35 | static void psiconv_free_clipart_section_aux(void * section); |
37 | |
36 | |
38 | psiconv_character_layout psiconv_basic_character_layout(void) |
37 | psiconv_character_layout psiconv_basic_character_layout(void) |
39 | { |
38 | { |
40 | /* Make the structures static, to oblige IRIX */ |
39 | /* Make the structures static, to oblige IRIX */ |
41 | static struct psiconv_color black = |
40 | static struct psiconv_color_s black = |
42 | { |
41 | { |
43 | 0x00, /* red */ |
42 | 0x00, /* red */ |
44 | 0x00, /* green */ |
43 | 0x00, /* green */ |
45 | 0x00, /* blue */ |
44 | 0x00, /* blue */ |
46 | }; |
45 | }; |
47 | static struct psiconv_color white = |
46 | static struct psiconv_color_s white = |
48 | { |
47 | { |
49 | 0xff, /* red */ |
48 | 0xff, /* red */ |
50 | 0xff, /* green */ |
49 | 0xff, /* green */ |
51 | 0xff, /* blue */ |
50 | 0xff, /* blue */ |
52 | }; |
51 | }; |
53 | static struct psiconv_font font = |
52 | static struct psiconv_font_s font = |
54 | { |
53 | { |
55 | "Times New Roman", /* name */ |
54 | "Times New Roman", /* name */ |
56 | 3 /* screenfont */ |
55 | 3 /* screenfont */ |
57 | }; |
56 | }; |
58 | struct psiconv_character_layout cl = |
57 | struct psiconv_character_layout_s cl = |
59 | { |
58 | { |
60 | &black, /* color */ |
59 | &black, /* color */ |
61 | &white, /* back_color */ |
60 | &white, /* back_color */ |
62 | 10.0, /* font_size */ |
61 | 10.0, /* font_size */ |
63 | psiconv_bool_false, /* italic */ |
62 | psiconv_bool_false, /* italic */ |
64 | psiconv_bool_false, /* bold */ |
63 | psiconv_bool_false, /* bold */ |
65 | psiconv_normalscript, /* super_sub */ |
64 | psiconv_normalscript, /* super_sub */ |
66 | psiconv_bool_false, /* underline */ |
65 | psiconv_bool_false, /* underline */ |
67 | psiconv_bool_false, /* strike_out */ |
66 | psiconv_bool_false, /* strikethrough */ |
68 | font, /* font */ |
67 | &font, /* font */ |
69 | }; |
68 | }; |
70 | |
69 | |
71 | return psiconv_clone_character_layout(&cl); |
70 | return psiconv_clone_character_layout(&cl); |
72 | } |
71 | } |
73 | |
72 | |
74 | psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) |
73 | psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) |
75 | { |
74 | { |
76 | static struct psiconv_font font = |
75 | static struct psiconv_font_s font = |
77 | { |
76 | { |
78 | "Times New Roman", /* name */ |
77 | "Times New Roman", /* name */ |
79 | 2 /* screenfont */ |
78 | 2 /* screenfont */ |
80 | }; |
79 | }; |
81 | static struct psiconv_color black = |
80 | static struct psiconv_color_s black = |
82 | { |
81 | { |
83 | 0x00, /* red */ |
82 | 0x00, /* red */ |
84 | 0x00, /* green */ |
83 | 0x00, /* green */ |
85 | 0x00, /* blue */ |
84 | 0x00, /* blue */ |
86 | }; |
85 | }; |
87 | static struct psiconv_color white = |
86 | static struct psiconv_color_s white = |
88 | { |
87 | { |
89 | 0xff, /* red */ |
88 | 0xff, /* red */ |
90 | 0xff, /* green */ |
89 | 0xff, /* green */ |
91 | 0xff, /* blue */ |
90 | 0xff, /* blue */ |
92 | }; |
91 | }; |
93 | static struct psiconv_border no_border = |
92 | static struct psiconv_border_s no_border = |
94 | { |
93 | { |
95 | psiconv_border_none, /* kind */ |
94 | psiconv_border_none, /* kind */ |
96 | 1, /* thickness */ |
95 | 1, /* thickness */ |
97 | &black /* color */ |
96 | &black /* color */ |
98 | }; |
97 | }; |
99 | static struct psiconv_bullet bullet = |
98 | static struct psiconv_bullet_s bullet = |
100 | { |
99 | { |
101 | psiconv_bool_false, /* on */ |
100 | psiconv_bool_false, /* on */ |
102 | 10.0, /* font_size */ |
101 | 10.0, /* font_size */ |
103 | 0x95, /* character */ |
102 | 0x95, /* character */ |
104 | psiconv_bool_true, /* indent */ |
103 | psiconv_bool_true, /* indent */ |
105 | &black, /* color */ |
104 | &black, /* color */ |
106 | &font, /* font */ |
105 | &font, /* font */ |
107 | }; |
106 | }; |
108 | static struct psiconv_all_tabs tabs = |
107 | static struct psiconv_all_tabs_s tabs = |
109 | { |
108 | { |
110 | 0.64, /* normal */ |
109 | 0.64, /* normal */ |
111 | NULL /* kind */ |
110 | NULL /* kind */ |
112 | }; |
111 | }; |
113 | struct psiconv_paragraph_layout pl = |
112 | struct psiconv_paragraph_layout_s pl = |
114 | { |
113 | { |
115 | &white, /* back_color */ |
114 | &white, /* back_color */ |
116 | 0.0, /* indent_left */ |
115 | 0.0, /* indent_left */ |
117 | 0.0, /* indent_right */ |
116 | 0.0, /* indent_right */ |
118 | 0.0, /* indent_first */ |
117 | 0.0, /* indent_first */ |
119 | psiconv_justify_left, /* justify_hor */ |
118 | psiconv_justify_left, /* justify_hor */ |
120 | psiconv_justify_middle,/* justify_ver */ |
119 | psiconv_justify_middle,/* justify_ver */ |
121 | 0.0, /* interline */ |
120 | 0.0, /* linespacing */ |
122 | psiconv_bool_false, /* interline_exact */ |
121 | psiconv_bool_false, /* linespacing_exact */ |
123 | 0.0, /* top_space */ |
122 | 0.0, /* space_above */ |
124 | 0.0, /* bottom_space */ |
123 | 0.0, /* space_below */ |
125 | psiconv_bool_false, /* on_one_page */ |
|
|
126 | psiconv_bool_false, /* together_with */ |
124 | psiconv_bool_false, /* keep_together */ |
|
|
125 | psiconv_bool_false, /* keep_with_next */ |
127 | psiconv_bool_false, /* on_next_page */ |
126 | psiconv_bool_false, /* on_next_page */ |
128 | psiconv_bool_false, /* no_widow_protection */ |
127 | psiconv_bool_false, /* no_widow_protection */ |
129 | 0.0, /* left_margin */ |
128 | 0.0, /* left_margin */ |
130 | &bullet, /* bullet */ |
129 | &bullet, /* bullet */ |
131 | &no_border, /* left_border */ |
130 | &no_border, /* left_border */ |
… | |
… | |
134 | &no_border, /* bottom_border */ |
133 | &no_border, /* bottom_border */ |
135 | &tabs, /* tabs */ |
134 | &tabs, /* tabs */ |
136 | }; |
135 | }; |
137 | psiconv_paragraph_layout res; |
136 | psiconv_paragraph_layout res; |
138 | |
137 | |
139 | pl.tabs->extras = psiconv_list_new(sizeof(struct psiconv_tab)); |
138 | if (!(pl.tabs->extras = psiconv_list_new(sizeof(struct psiconv_tab_s)))) |
|
|
139 | return NULL; |
140 | res = psiconv_clone_paragraph_layout(&pl); |
140 | res = psiconv_clone_paragraph_layout(&pl); |
141 | psiconv_list_free(pl.tabs->extras); |
141 | psiconv_list_free(pl.tabs->extras); |
142 | return res; |
142 | return res; |
143 | } |
143 | } |
144 | |
144 | |
145 | psiconv_color clone_color(psiconv_color color) |
145 | psiconv_color clone_color(psiconv_color color) |
146 | { |
146 | { |
147 | psiconv_color result; |
147 | psiconv_color result; |
148 | result = malloc(sizeof(*result)); |
148 | if (!(result = malloc(sizeof(*result)))) |
|
|
149 | return NULL; |
149 | *result = *color; |
150 | *result = *color; |
150 | return result; |
151 | return result; |
151 | } |
152 | } |
152 | |
153 | |
153 | psiconv_font clone_font(psiconv_font font) |
154 | psiconv_font clone_font(psiconv_font font) |
154 | { |
155 | { |
155 | psiconv_font result; |
156 | psiconv_font result; |
156 | result = malloc(sizeof(*result)); |
157 | if(!(result = malloc(sizeof(*result)))) |
|
|
158 | goto ERROR1; |
157 | *result = *font; |
159 | *result = *font; |
158 | result->name = strdup(result->name); |
160 | if (!(result->name = strdup(result->name))) |
|
|
161 | goto ERROR2; |
159 | return result; |
162 | return result; |
|
|
163 | ERROR2: |
|
|
164 | free(result); |
|
|
165 | ERROR1: |
|
|
166 | return NULL; |
160 | } |
167 | } |
161 | |
168 | |
162 | psiconv_border clone_border(psiconv_border border) |
169 | psiconv_border clone_border(psiconv_border border) |
163 | { |
170 | { |
164 | psiconv_border result; |
171 | psiconv_border result; |
165 | result = malloc(sizeof(*result)); |
172 | if (!(result = malloc(sizeof(*result)))) |
|
|
173 | goto ERROR1; |
166 | *result = *border; |
174 | *result = *border; |
167 | result->color = clone_color(result->color); |
175 | if(!(result->color = clone_color(result->color))) |
|
|
176 | goto ERROR2; |
168 | return result; |
177 | return result; |
|
|
178 | ERROR2: |
|
|
179 | free(result); |
|
|
180 | ERROR1: |
|
|
181 | return NULL; |
169 | } |
182 | } |
170 | |
183 | |
171 | psiconv_bullet clone_bullet(psiconv_bullet bullet) |
184 | psiconv_bullet clone_bullet(psiconv_bullet bullet) |
172 | { |
185 | { |
173 | psiconv_bullet result; |
186 | psiconv_bullet result; |
174 | result = malloc(sizeof(*result)); |
187 | if (!(result = malloc(sizeof(*result)))) |
|
|
188 | goto ERROR1; |
175 | *result = *bullet; |
189 | *result = *bullet; |
176 | result->font = clone_font(result->font); |
190 | if (!(result->font = clone_font(result->font))) |
|
|
191 | goto ERROR2; |
177 | result->color = clone_color(result->color); |
192 | if (!(result->color = clone_color(result->color))) |
|
|
193 | goto ERROR3; |
178 | return result; |
194 | return result; |
|
|
195 | ERROR3: |
|
|
196 | psiconv_free_font(result->font); |
|
|
197 | ERROR2: |
|
|
198 | free(result); |
|
|
199 | ERROR1: |
|
|
200 | return NULL; |
179 | } |
201 | } |
180 | |
202 | |
181 | psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs) |
203 | psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs) |
182 | { |
204 | { |
183 | psiconv_all_tabs result; |
205 | psiconv_all_tabs result; |
184 | result = malloc(sizeof(*result)); |
206 | if (!(result = malloc(sizeof(*result)))) |
|
|
207 | goto ERROR1; |
185 | *result = *all_tabs; |
208 | *result = *all_tabs; |
186 | result->extras = psiconv_list_clone(result->extras); |
209 | if (!(result->extras = psiconv_list_clone(result->extras))) |
|
|
210 | goto ERROR2; |
187 | return result; |
211 | return result; |
|
|
212 | ERROR2: |
|
|
213 | free(result); |
|
|
214 | ERROR1: |
|
|
215 | return NULL; |
188 | } |
216 | } |
189 | |
217 | |
190 | psiconv_character_layout psiconv_clone_character_layout |
218 | psiconv_character_layout psiconv_clone_character_layout |
191 | (psiconv_character_layout ls) |
219 | (psiconv_character_layout ls) |
192 | { |
220 | { |
193 | psiconv_character_layout result; |
221 | psiconv_character_layout result; |
194 | |
222 | |
195 | result = malloc(sizeof(*result)); |
223 | if (!(result = malloc(sizeof(*result)))) |
|
|
224 | goto ERROR1; |
196 | *result = *ls; |
225 | *result = *ls; |
197 | result->color = clone_color(result->color); |
226 | if (!(result->color = clone_color(result->color))) |
|
|
227 | goto ERROR2; |
198 | result->back_color = clone_color(result->back_color); |
228 | if (!(result->back_color = clone_color(result->back_color))) |
|
|
229 | goto ERROR3; |
199 | result->font = clone_font(result->font); |
230 | if (!(result->font = clone_font(result->font))) |
|
|
231 | goto ERROR4; |
200 | return result; |
232 | return result; |
|
|
233 | ERROR4: |
|
|
234 | psiconv_free_color(result->back_color); |
|
|
235 | ERROR3: |
|
|
236 | psiconv_free_color(result->color); |
|
|
237 | ERROR2: |
|
|
238 | free(result); |
|
|
239 | ERROR1: |
|
|
240 | return NULL; |
201 | } |
241 | } |
202 | |
242 | |
203 | psiconv_paragraph_layout psiconv_clone_paragraph_layout |
243 | psiconv_paragraph_layout psiconv_clone_paragraph_layout |
204 | (psiconv_paragraph_layout ls) |
244 | (psiconv_paragraph_layout ls) |
205 | { |
245 | { |
206 | psiconv_paragraph_layout result; |
246 | psiconv_paragraph_layout result; |
207 | |
247 | |
208 | result = malloc(sizeof(*result)); |
248 | if (!(result = malloc(sizeof(*result)))) |
|
|
249 | goto ERROR1; |
209 | *result = *ls; |
250 | *result = *ls; |
210 | result->back_color = clone_color(result->back_color); |
251 | if (!(result->back_color = clone_color(result->back_color))) |
|
|
252 | goto ERROR2; |
211 | result->bullet = clone_bullet(result->bullet); |
253 | if (!(result->bullet = clone_bullet(result->bullet))) |
|
|
254 | goto ERROR3; |
212 | result->left_border = clone_border(result->left_border); |
255 | if (!(result->left_border = clone_border(result->left_border))) |
|
|
256 | goto ERROR4; |
213 | result->right_border = clone_border(result->right_border); |
257 | if (!(result->right_border = clone_border(result->right_border))) |
|
|
258 | goto ERROR5; |
214 | result->top_border = clone_border(result->top_border); |
259 | if (!(result->top_border = clone_border(result->top_border))) |
|
|
260 | goto ERROR6; |
215 | result->bottom_border = clone_border(result->bottom_border); |
261 | if (!(result->bottom_border = clone_border(result->bottom_border))) |
|
|
262 | goto ERROR7; |
216 | result->tabs = clone_all_tabs(result->tabs); |
263 | if (!(result->tabs = clone_all_tabs(result->tabs))) |
|
|
264 | goto ERROR8; |
217 | return result; |
265 | return result; |
|
|
266 | ERROR8: |
|
|
267 | psiconv_free_border(result->bottom_border); |
|
|
268 | ERROR7: |
|
|
269 | psiconv_free_border(result->top_border); |
|
|
270 | ERROR6: |
|
|
271 | psiconv_free_border(result->right_border); |
|
|
272 | ERROR5: |
|
|
273 | psiconv_free_border(result->left_border); |
|
|
274 | ERROR4: |
|
|
275 | psiconv_free_bullet(result->bullet); |
|
|
276 | ERROR3: |
|
|
277 | psiconv_free_color(result->back_color); |
|
|
278 | ERROR2: |
|
|
279 | free(result); |
|
|
280 | ERROR1: |
|
|
281 | return NULL; |
218 | } |
282 | } |
219 | |
283 | |
220 | psiconv_word_style psiconv_get_style (psiconv_word_styles_section ss, int nr) |
284 | psiconv_word_style psiconv_get_style (psiconv_word_styles_section ss, int nr) |
221 | { |
285 | { |
222 | if (nr == 0) |
286 | if (nr == 0) |
… | |
… | |
481 | { |
545 | { |
482 | if (section) |
546 | if (section) |
483 | psiconv_list_free_el(section,&psiconv_free_paint_data_section_aux); |
547 | psiconv_list_free_el(section,&psiconv_free_paint_data_section_aux); |
484 | } |
548 | } |
485 | |
549 | |
486 | void psiconv_free_mbm_jumptable_section (psiconv_mbm_jumptable_section section) |
550 | void psiconv_free_jumptable_section (psiconv_jumptable_section section) |
487 | { |
551 | { |
488 | if (section) |
552 | if (section) |
489 | psiconv_list_free(section); |
553 | psiconv_list_free(section); |
490 | } |
554 | } |
491 | |
555 | |
492 | void psiconv_free_mbm_f(psiconv_mbm_f file) |
556 | void psiconv_free_mbm_f(psiconv_mbm_f file) |
493 | { |
557 | { |
494 | if (file) { |
558 | if (file) { |
495 | psiconv_free_pictures(file->sections); |
559 | psiconv_free_pictures(file->sections); |
|
|
560 | free(file); |
|
|
561 | } |
|
|
562 | } |
|
|
563 | |
|
|
564 | void psiconv_free_sketch_section(psiconv_sketch_section sec) |
|
|
565 | { |
|
|
566 | if (sec) { |
|
|
567 | psiconv_free_paint_data_section(sec->picture); |
|
|
568 | free(sec); |
|
|
569 | } |
|
|
570 | } |
|
|
571 | |
|
|
572 | void psiconv_free_sketch_f(psiconv_sketch_f file) |
|
|
573 | { |
|
|
574 | if (file) { |
|
|
575 | psiconv_free_sketch_section(file->sketch_sec); |
|
|
576 | free(file); |
|
|
577 | } |
|
|
578 | } |
|
|
579 | |
|
|
580 | void psiconv_free_clipart_section_aux(void *section) |
|
|
581 | { |
|
|
582 | if (section) |
|
|
583 | free(((psiconv_clipart_section ) section)->picture); |
|
|
584 | } |
|
|
585 | |
|
|
586 | void psiconv_free_clipart_section(psiconv_clipart_section section) |
|
|
587 | { |
|
|
588 | if (section) { |
|
|
589 | psiconv_free_clipart_section_aux(section); |
|
|
590 | free(section); |
|
|
591 | } |
|
|
592 | } |
|
|
593 | |
|
|
594 | void psiconv_free_cliparts(psiconv_cliparts section) |
|
|
595 | { |
|
|
596 | if (section) |
|
|
597 | psiconv_list_free_el(section,&psiconv_free_clipart_section_aux); |
|
|
598 | } |
|
|
599 | |
|
|
600 | void psiconv_free_clipart_f(psiconv_clipart_f file) |
|
|
601 | { |
|
|
602 | if (file) { |
|
|
603 | psiconv_free_cliparts(file->sections); |
496 | free(file); |
604 | free(file); |
497 | } |
605 | } |
498 | } |
606 | } |
499 | |
607 | |
500 | void psiconv_free_file(psiconv_file file) |
608 | void psiconv_free_file(psiconv_file file) |
… | |
… | |
504 | psiconv_free_word_f((psiconv_word_f) file->file); |
612 | psiconv_free_word_f((psiconv_word_f) file->file); |
505 | else if (file->type == psiconv_texted_file) |
613 | else if (file->type == psiconv_texted_file) |
506 | psiconv_free_texted_f((psiconv_texted_f) file->file); |
614 | psiconv_free_texted_f((psiconv_texted_f) file->file); |
507 | else if (file->type == psiconv_mbm_file) |
615 | else if (file->type == psiconv_mbm_file) |
508 | psiconv_free_mbm_f((psiconv_mbm_f) file->file); |
616 | psiconv_free_mbm_f((psiconv_mbm_f) file->file); |
|
|
617 | else if (file->type == psiconv_sketch_file) |
|
|
618 | psiconv_free_sketch_f((psiconv_sketch_f) file->file); |
|
|
619 | else if (file->type == psiconv_clipart_file) |
|
|
620 | psiconv_free_clipart_f((psiconv_clipart_f) file->file); |
509 | free(file); |
621 | free(file); |
510 | } |
622 | } |
511 | } |
623 | } |