… | |
… | |
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); |
37 | static void psiconv_free_clipart_section_aux(psiconv_clipart_section section); |
35 | static void psiconv_free_clipart_section_aux(void * section); |
38 | |
36 | |
39 | psiconv_character_layout psiconv_basic_character_layout(void) |
37 | psiconv_character_layout psiconv_basic_character_layout(void) |
40 | { |
38 | { |
41 | /* Make the structures static, to oblige IRIX */ |
39 | /* Make the structures static, to oblige IRIX */ |
42 | static struct psiconv_color black = |
40 | static struct psiconv_color_s black = |
43 | { |
41 | { |
44 | 0x00, /* red */ |
42 | 0x00, /* red */ |
45 | 0x00, /* green */ |
43 | 0x00, /* green */ |
46 | 0x00, /* blue */ |
44 | 0x00, /* blue */ |
47 | }; |
45 | }; |
48 | static struct psiconv_color white = |
46 | static struct psiconv_color_s white = |
49 | { |
47 | { |
50 | 0xff, /* red */ |
48 | 0xff, /* red */ |
51 | 0xff, /* green */ |
49 | 0xff, /* green */ |
52 | 0xff, /* blue */ |
50 | 0xff, /* blue */ |
53 | }; |
51 | }; |
54 | static struct psiconv_font font = |
52 | static struct psiconv_font_s font = |
55 | { |
53 | { |
56 | "Times New Roman", /* name */ |
54 | "Times New Roman", /* name */ |
57 | 3 /* screenfont */ |
55 | 3 /* screenfont */ |
58 | }; |
56 | }; |
59 | struct psiconv_character_layout cl = |
57 | struct psiconv_character_layout_s cl = |
60 | { |
58 | { |
61 | &black, /* color */ |
59 | &black, /* color */ |
62 | &white, /* back_color */ |
60 | &white, /* back_color */ |
63 | 10.0, /* font_size */ |
61 | 10.0, /* font_size */ |
64 | psiconv_bool_false, /* italic */ |
62 | psiconv_bool_false, /* italic */ |
… | |
… | |
72 | return psiconv_clone_character_layout(&cl); |
70 | return psiconv_clone_character_layout(&cl); |
73 | } |
71 | } |
74 | |
72 | |
75 | psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) |
73 | psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) |
76 | { |
74 | { |
77 | static struct psiconv_font font = |
75 | static struct psiconv_font_s font = |
78 | { |
76 | { |
79 | "Times New Roman", /* name */ |
77 | "Times New Roman", /* name */ |
80 | 2 /* screenfont */ |
78 | 2 /* screenfont */ |
81 | }; |
79 | }; |
82 | static struct psiconv_color black = |
80 | static struct psiconv_color_s black = |
83 | { |
81 | { |
84 | 0x00, /* red */ |
82 | 0x00, /* red */ |
85 | 0x00, /* green */ |
83 | 0x00, /* green */ |
86 | 0x00, /* blue */ |
84 | 0x00, /* blue */ |
87 | }; |
85 | }; |
88 | static struct psiconv_color white = |
86 | static struct psiconv_color_s white = |
89 | { |
87 | { |
90 | 0xff, /* red */ |
88 | 0xff, /* red */ |
91 | 0xff, /* green */ |
89 | 0xff, /* green */ |
92 | 0xff, /* blue */ |
90 | 0xff, /* blue */ |
93 | }; |
91 | }; |
94 | static struct psiconv_border no_border = |
92 | static struct psiconv_border_s no_border = |
95 | { |
93 | { |
96 | psiconv_border_none, /* kind */ |
94 | psiconv_border_none, /* kind */ |
97 | 1, /* thickness */ |
95 | 1, /* thickness */ |
98 | &black /* color */ |
96 | &black /* color */ |
99 | }; |
97 | }; |
100 | static struct psiconv_bullet bullet = |
98 | static struct psiconv_bullet_s bullet = |
101 | { |
99 | { |
102 | psiconv_bool_false, /* on */ |
100 | psiconv_bool_false, /* on */ |
103 | 10.0, /* font_size */ |
101 | 10.0, /* font_size */ |
104 | 0x95, /* character */ |
102 | 0x95, /* character */ |
105 | psiconv_bool_true, /* indent */ |
103 | psiconv_bool_true, /* indent */ |
106 | &black, /* color */ |
104 | &black, /* color */ |
107 | &font, /* font */ |
105 | &font, /* font */ |
108 | }; |
106 | }; |
109 | static struct psiconv_all_tabs tabs = |
107 | static struct psiconv_all_tabs_s tabs = |
110 | { |
108 | { |
111 | 0.64, /* normal */ |
109 | 0.64, /* normal */ |
112 | NULL /* kind */ |
110 | NULL /* kind */ |
113 | }; |
111 | }; |
114 | struct psiconv_paragraph_layout pl = |
112 | struct psiconv_paragraph_layout_s pl = |
115 | { |
113 | { |
116 | &white, /* back_color */ |
114 | &white, /* back_color */ |
117 | 0.0, /* indent_left */ |
115 | 0.0, /* indent_left */ |
118 | 0.0, /* indent_right */ |
116 | 0.0, /* indent_right */ |
119 | 0.0, /* indent_first */ |
117 | 0.0, /* indent_first */ |
… | |
… | |
135 | &no_border, /* bottom_border */ |
133 | &no_border, /* bottom_border */ |
136 | &tabs, /* tabs */ |
134 | &tabs, /* tabs */ |
137 | }; |
135 | }; |
138 | psiconv_paragraph_layout res; |
136 | psiconv_paragraph_layout res; |
139 | |
137 | |
140 | 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; |
141 | res = psiconv_clone_paragraph_layout(&pl); |
140 | res = psiconv_clone_paragraph_layout(&pl); |
142 | psiconv_list_free(pl.tabs->extras); |
141 | psiconv_list_free(pl.tabs->extras); |
143 | return res; |
142 | return res; |
144 | } |
143 | } |
145 | |
144 | |
146 | psiconv_color clone_color(psiconv_color color) |
145 | psiconv_color clone_color(psiconv_color color) |
147 | { |
146 | { |
148 | psiconv_color result; |
147 | psiconv_color result; |
149 | result = malloc(sizeof(*result)); |
148 | if (!(result = malloc(sizeof(*result)))) |
|
|
149 | return NULL; |
150 | *result = *color; |
150 | *result = *color; |
151 | return result; |
151 | return result; |
152 | } |
152 | } |
153 | |
153 | |
154 | psiconv_font clone_font(psiconv_font font) |
154 | psiconv_font clone_font(psiconv_font font) |
155 | { |
155 | { |
156 | psiconv_font result; |
156 | psiconv_font result; |
157 | result = malloc(sizeof(*result)); |
157 | if(!(result = malloc(sizeof(*result)))) |
|
|
158 | goto ERROR1; |
158 | *result = *font; |
159 | *result = *font; |
159 | result->name = strdup(result->name); |
160 | if (!(result->name = strdup(result->name))) |
|
|
161 | goto ERROR2; |
160 | return result; |
162 | return result; |
|
|
163 | ERROR2: |
|
|
164 | free(result); |
|
|
165 | ERROR1: |
|
|
166 | return NULL; |
161 | } |
167 | } |
162 | |
168 | |
163 | psiconv_border clone_border(psiconv_border border) |
169 | psiconv_border clone_border(psiconv_border border) |
164 | { |
170 | { |
165 | psiconv_border result; |
171 | psiconv_border result; |
166 | result = malloc(sizeof(*result)); |
172 | if (!(result = malloc(sizeof(*result)))) |
|
|
173 | goto ERROR1; |
167 | *result = *border; |
174 | *result = *border; |
168 | result->color = clone_color(result->color); |
175 | if(!(result->color = clone_color(result->color))) |
|
|
176 | goto ERROR2; |
169 | return result; |
177 | return result; |
|
|
178 | ERROR2: |
|
|
179 | free(result); |
|
|
180 | ERROR1: |
|
|
181 | return NULL; |
170 | } |
182 | } |
171 | |
183 | |
172 | psiconv_bullet clone_bullet(psiconv_bullet bullet) |
184 | psiconv_bullet clone_bullet(psiconv_bullet bullet) |
173 | { |
185 | { |
174 | psiconv_bullet result; |
186 | psiconv_bullet result; |
175 | result = malloc(sizeof(*result)); |
187 | if (!(result = malloc(sizeof(*result)))) |
|
|
188 | goto ERROR1; |
176 | *result = *bullet; |
189 | *result = *bullet; |
177 | result->font = clone_font(result->font); |
190 | if (!(result->font = clone_font(result->font))) |
|
|
191 | goto ERROR2; |
178 | result->color = clone_color(result->color); |
192 | if (!(result->color = clone_color(result->color))) |
|
|
193 | goto ERROR3; |
179 | return result; |
194 | return result; |
|
|
195 | ERROR3: |
|
|
196 | psiconv_free_font(result->font); |
|
|
197 | ERROR2: |
|
|
198 | free(result); |
|
|
199 | ERROR1: |
|
|
200 | return NULL; |
180 | } |
201 | } |
181 | |
202 | |
182 | psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs) |
203 | psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs) |
183 | { |
204 | { |
184 | psiconv_all_tabs result; |
205 | psiconv_all_tabs result; |
185 | result = malloc(sizeof(*result)); |
206 | if (!(result = malloc(sizeof(*result)))) |
|
|
207 | goto ERROR1; |
186 | *result = *all_tabs; |
208 | *result = *all_tabs; |
187 | result->extras = psiconv_list_clone(result->extras); |
209 | if (!(result->extras = psiconv_list_clone(result->extras))) |
|
|
210 | goto ERROR2; |
188 | return result; |
211 | return result; |
|
|
212 | ERROR2: |
|
|
213 | free(result); |
|
|
214 | ERROR1: |
|
|
215 | return NULL; |
189 | } |
216 | } |
190 | |
217 | |
191 | psiconv_character_layout psiconv_clone_character_layout |
218 | psiconv_character_layout psiconv_clone_character_layout |
192 | (psiconv_character_layout ls) |
219 | (psiconv_character_layout ls) |
193 | { |
220 | { |
194 | psiconv_character_layout result; |
221 | psiconv_character_layout result; |
195 | |
222 | |
196 | result = malloc(sizeof(*result)); |
223 | if (!(result = malloc(sizeof(*result)))) |
|
|
224 | goto ERROR1; |
197 | *result = *ls; |
225 | *result = *ls; |
198 | result->color = clone_color(result->color); |
226 | if (!(result->color = clone_color(result->color))) |
|
|
227 | goto ERROR2; |
199 | result->back_color = clone_color(result->back_color); |
228 | if (!(result->back_color = clone_color(result->back_color))) |
|
|
229 | goto ERROR3; |
200 | result->font = clone_font(result->font); |
230 | if (!(result->font = clone_font(result->font))) |
|
|
231 | goto ERROR4; |
201 | 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; |
202 | } |
241 | } |
203 | |
242 | |
204 | psiconv_paragraph_layout psiconv_clone_paragraph_layout |
243 | psiconv_paragraph_layout psiconv_clone_paragraph_layout |
205 | (psiconv_paragraph_layout ls) |
244 | (psiconv_paragraph_layout ls) |
206 | { |
245 | { |
207 | psiconv_paragraph_layout result; |
246 | psiconv_paragraph_layout result; |
208 | |
247 | |
209 | result = malloc(sizeof(*result)); |
248 | if (!(result = malloc(sizeof(*result)))) |
|
|
249 | goto ERROR1; |
210 | *result = *ls; |
250 | *result = *ls; |
211 | result->back_color = clone_color(result->back_color); |
251 | if (!(result->back_color = clone_color(result->back_color))) |
|
|
252 | goto ERROR2; |
212 | result->bullet = clone_bullet(result->bullet); |
253 | if (!(result->bullet = clone_bullet(result->bullet))) |
|
|
254 | goto ERROR3; |
213 | result->left_border = clone_border(result->left_border); |
255 | if (!(result->left_border = clone_border(result->left_border))) |
|
|
256 | goto ERROR4; |
214 | result->right_border = clone_border(result->right_border); |
257 | if (!(result->right_border = clone_border(result->right_border))) |
|
|
258 | goto ERROR5; |
215 | result->top_border = clone_border(result->top_border); |
259 | if (!(result->top_border = clone_border(result->top_border))) |
|
|
260 | goto ERROR6; |
216 | result->bottom_border = clone_border(result->bottom_border); |
261 | if (!(result->bottom_border = clone_border(result->bottom_border))) |
|
|
262 | goto ERROR7; |
217 | result->tabs = clone_all_tabs(result->tabs); |
263 | if (!(result->tabs = clone_all_tabs(result->tabs))) |
|
|
264 | goto ERROR8; |
218 | 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; |
219 | } |
282 | } |
220 | |
283 | |
221 | 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) |
222 | { |
285 | { |
223 | if (nr == 0) |
286 | if (nr == 0) |
… | |
… | |
482 | { |
545 | { |
483 | if (section) |
546 | if (section) |
484 | psiconv_list_free_el(section,&psiconv_free_paint_data_section_aux); |
547 | psiconv_list_free_el(section,&psiconv_free_paint_data_section_aux); |
485 | } |
548 | } |
486 | |
549 | |
487 | void psiconv_free_mbm_jumptable_section (psiconv_mbm_jumptable_section section) |
550 | void psiconv_free_jumptable_section (psiconv_jumptable_section section) |
488 | { |
551 | { |
489 | if (section) |
552 | if (section) |
490 | psiconv_list_free(section); |
553 | psiconv_list_free(section); |
491 | } |
554 | } |
492 | |
555 | |
… | |
… | |
512 | psiconv_free_sketch_section(file->sketch_sec); |
575 | psiconv_free_sketch_section(file->sketch_sec); |
513 | free(file); |
576 | free(file); |
514 | } |
577 | } |
515 | } |
578 | } |
516 | |
579 | |
517 | void psiconv_free_clipart_section_aux(psiconv_clipart_section section) |
580 | void psiconv_free_clipart_section_aux(void *section) |
518 | { |
581 | { |
519 | if (section) |
582 | if (section) |
520 | free(section->picture); |
583 | free(((psiconv_clipart_section ) section)->picture); |
521 | } |
584 | } |
522 | |
585 | |
523 | void psiconv_free_clipart_section(psiconv_clipart_section section) |
586 | void psiconv_free_clipart_section(psiconv_clipart_section section) |
524 | { |
587 | { |
525 | if (section) { |
588 | if (section) { |
… | |
… | |
552 | else if (file->type == psiconv_mbm_file) |
615 | else if (file->type == psiconv_mbm_file) |
553 | psiconv_free_mbm_f((psiconv_mbm_f) file->file); |
616 | psiconv_free_mbm_f((psiconv_mbm_f) file->file); |
554 | else if (file->type == psiconv_sketch_file) |
617 | else if (file->type == psiconv_sketch_file) |
555 | psiconv_free_sketch_f((psiconv_sketch_f) file->file); |
618 | psiconv_free_sketch_f((psiconv_sketch_f) file->file); |
556 | else if (file->type == psiconv_clipart_file) |
619 | else if (file->type == psiconv_clipart_file) |
557 | psiconv_free_sketch_f((psiconv_clipart_f) file->file); |
620 | psiconv_free_clipart_f((psiconv_clipart_f) file->file); |
558 | free(file); |
621 | free(file); |
559 | } |
622 | } |
560 | } |
623 | } |