1 |
/* |
2 |
data.c - Part of psiconv, a PSION 5 file formats converter |
3 |
Copyright (c) 1999, 2000 Frodo Looijaard <frodol@dds.nl> |
4 |
|
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 |
7 |
the Free Software Foundation; either version 2 of the License, or |
8 |
(at your option) any later version. |
9 |
|
10 |
This program is distributed in the hope that it will be useful, |
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
GNU General Public License for more details. |
14 |
|
15 |
You should have received a copy of the GNU General Public License |
16 |
along with this program; if not, write to the Free Software |
17 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
18 |
*/ |
19 |
|
20 |
#include "config.h" |
21 |
#include "compat.h" |
22 |
#include <stdlib.h> |
23 |
#include <string.h> |
24 |
#include "data.h" |
25 |
#include "list.h" |
26 |
|
27 |
static psiconv_color clone_color(psiconv_color color); |
28 |
static psiconv_font clone_font(psiconv_font font); |
29 |
static psiconv_border clone_border(psiconv_border border); |
30 |
static psiconv_bullet clone_bullet(psiconv_bullet bullet); |
31 |
static psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs); |
32 |
static void psiconv_free_style_aux(void *style); |
33 |
static void psiconv_free_in_line_layout_aux(void * layout); |
34 |
static void psiconv_free_paragraph_aux(void * paragraph); |
35 |
static void psiconv_free_paint_data_section_aux(void * section); |
36 |
static void psiconv_free_clipart_section_aux(void * section); |
37 |
|
38 |
static psiconv_word_styles_section psiconv_empty_word_styles_section(void); |
39 |
static psiconv_text_and_layout psiconv_empty_text_and_layout(void); |
40 |
static psiconv_texted_section psiconv_empty_texted_section(void); |
41 |
static psiconv_page_header psiconv_empty_page_header(void); |
42 |
static psiconv_page_layout_section psiconv_empty_page_layout_section(void); |
43 |
static psiconv_word_status_section psiconv_empty_word_status_section(void); |
44 |
static psiconv_word_f psiconv_empty_word_f(void); |
45 |
static psiconv_sheet_status_section psiconv_empty_sheet_status_section(void); |
46 |
static psiconv_sheet_workbook_section |
47 |
psiconv_empty_sheet_workbook_section(void); |
48 |
static psiconv_sheet_f psiconv_empty_sheet_f(void); |
49 |
static psiconv_texted_f psiconv_empty_texted_f(void); |
50 |
static psiconv_paint_data_section psiconv_empty_paint_data_section(void); |
51 |
static psiconv_pictures psiconv_empty_pictures(void); |
52 |
static psiconv_mbm_f psiconv_empty_mbm_f(void); |
53 |
static psiconv_sketch_section psiconv_empty_sketch_section(void); |
54 |
static psiconv_sketch_f psiconv_empty_sketch_f(void); |
55 |
static psiconv_clipart_f psiconv_empty_clipart_f(void); |
56 |
static psiconv_cliparts psiconv_empty_cliparts(void); |
57 |
|
58 |
|
59 |
/* Note: these defaults seem to be hard-coded somewhere outside the |
60 |
files themself. */ |
61 |
psiconv_character_layout psiconv_basic_character_layout(void) |
62 |
{ |
63 |
/* Make the structures static, to oblige IRIX */ |
64 |
static struct psiconv_color_s black = |
65 |
{ |
66 |
0x00, /* red */ |
67 |
0x00, /* green */ |
68 |
0x00, /* blue */ |
69 |
}; |
70 |
static struct psiconv_color_s white = |
71 |
{ |
72 |
0xff, /* red */ |
73 |
0xff, /* green */ |
74 |
0xff, /* blue */ |
75 |
}; |
76 |
static struct psiconv_font_s font = |
77 |
{ |
78 |
"Times New Roman", /* name */ |
79 |
3 /* screenfont */ |
80 |
}; |
81 |
struct psiconv_character_layout_s cl = |
82 |
{ |
83 |
&black, /* color */ |
84 |
&white, /* back_color */ |
85 |
10.0, /* font_size */ |
86 |
psiconv_bool_false, /* italic */ |
87 |
psiconv_bool_false, /* bold */ |
88 |
psiconv_normalscript, /* super_sub */ |
89 |
psiconv_bool_false, /* underline */ |
90 |
psiconv_bool_false, /* strikethrough */ |
91 |
&font, /* font */ |
92 |
}; |
93 |
|
94 |
return psiconv_clone_character_layout(&cl); |
95 |
} |
96 |
|
97 |
/* Note: these defaults seem to be hard-coded somewhere outside the |
98 |
files themself. */ |
99 |
psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) |
100 |
{ |
101 |
static struct psiconv_font_s font = |
102 |
{ |
103 |
"Times New Roman", /* name */ |
104 |
2 /* screenfont */ |
105 |
}; |
106 |
static struct psiconv_color_s black = |
107 |
{ |
108 |
0x00, /* red */ |
109 |
0x00, /* green */ |
110 |
0x00, /* blue */ |
111 |
}; |
112 |
static struct psiconv_color_s white = |
113 |
{ |
114 |
0xff, /* red */ |
115 |
0xff, /* green */ |
116 |
0xff, /* blue */ |
117 |
}; |
118 |
static struct psiconv_border_s no_border = |
119 |
{ |
120 |
psiconv_border_none, /* kind */ |
121 |
1, /* thickness */ |
122 |
&black /* color */ |
123 |
}; |
124 |
static struct psiconv_bullet_s bullet = |
125 |
{ |
126 |
psiconv_bool_false, /* on */ |
127 |
10.0, /* font_size */ |
128 |
0x95, /* character */ |
129 |
psiconv_bool_true, /* indent */ |
130 |
&black, /* color */ |
131 |
&font, /* font */ |
132 |
}; |
133 |
static struct psiconv_all_tabs_s tabs = |
134 |
{ |
135 |
0.64, /* normal */ |
136 |
NULL /* kind */ |
137 |
}; |
138 |
struct psiconv_paragraph_layout_s pl = |
139 |
{ |
140 |
&white, /* back_color */ |
141 |
0.0, /* indent_left */ |
142 |
0.0, /* indent_right */ |
143 |
0.0, /* indent_first */ |
144 |
psiconv_justify_left, /* justify_hor */ |
145 |
psiconv_justify_middle,/* justify_ver */ |
146 |
10.0, /* linespacing */ |
147 |
psiconv_bool_false, /* linespacing_exact */ |
148 |
0.0, /* space_above */ |
149 |
0.0, /* space_below */ |
150 |
psiconv_bool_false, /* keep_together */ |
151 |
psiconv_bool_false, /* keep_with_next */ |
152 |
psiconv_bool_false, /* on_next_page */ |
153 |
psiconv_bool_false, /* no_widow_protection */ |
154 |
0.0, /* left_margin */ |
155 |
&bullet, /* bullet */ |
156 |
&no_border, /* left_border */ |
157 |
&no_border, /* right_border */ |
158 |
&no_border, /* top_border */ |
159 |
&no_border, /* bottom_border */ |
160 |
&tabs, /* tabs */ |
161 |
}; |
162 |
psiconv_paragraph_layout res; |
163 |
|
164 |
if (!(pl.tabs->extras = psiconv_list_new(sizeof(struct psiconv_tab_s)))) |
165 |
return NULL; |
166 |
res = psiconv_clone_paragraph_layout(&pl); |
167 |
psiconv_list_free(pl.tabs->extras); |
168 |
return res; |
169 |
} |
170 |
|
171 |
psiconv_color clone_color(psiconv_color color) |
172 |
{ |
173 |
psiconv_color result; |
174 |
if (!(result = malloc(sizeof(*result)))) |
175 |
return NULL; |
176 |
*result = *color; |
177 |
return result; |
178 |
} |
179 |
|
180 |
psiconv_font clone_font(psiconv_font font) |
181 |
{ |
182 |
psiconv_font result; |
183 |
if(!(result = malloc(sizeof(*result)))) |
184 |
goto ERROR1; |
185 |
*result = *font; |
186 |
if (!(result->name = strdup(result->name))) |
187 |
goto ERROR2; |
188 |
return result; |
189 |
ERROR2: |
190 |
free(result); |
191 |
ERROR1: |
192 |
return NULL; |
193 |
} |
194 |
|
195 |
psiconv_border clone_border(psiconv_border border) |
196 |
{ |
197 |
psiconv_border result; |
198 |
if (!(result = malloc(sizeof(*result)))) |
199 |
goto ERROR1; |
200 |
*result = *border; |
201 |
if(!(result->color = clone_color(result->color))) |
202 |
goto ERROR2; |
203 |
return result; |
204 |
ERROR2: |
205 |
free(result); |
206 |
ERROR1: |
207 |
return NULL; |
208 |
} |
209 |
|
210 |
psiconv_bullet clone_bullet(psiconv_bullet bullet) |
211 |
{ |
212 |
psiconv_bullet result; |
213 |
if (!(result = malloc(sizeof(*result)))) |
214 |
goto ERROR1; |
215 |
*result = *bullet; |
216 |
if (!(result->font = clone_font(result->font))) |
217 |
goto ERROR2; |
218 |
if (!(result->color = clone_color(result->color))) |
219 |
goto ERROR3; |
220 |
return result; |
221 |
ERROR3: |
222 |
psiconv_free_font(result->font); |
223 |
ERROR2: |
224 |
free(result); |
225 |
ERROR1: |
226 |
return NULL; |
227 |
} |
228 |
|
229 |
psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs) |
230 |
{ |
231 |
psiconv_all_tabs result; |
232 |
if (!(result = malloc(sizeof(*result)))) |
233 |
goto ERROR1; |
234 |
*result = *all_tabs; |
235 |
if (!(result->extras = psiconv_list_clone(result->extras))) |
236 |
goto ERROR2; |
237 |
return result; |
238 |
ERROR2: |
239 |
free(result); |
240 |
ERROR1: |
241 |
return NULL; |
242 |
} |
243 |
|
244 |
psiconv_character_layout psiconv_clone_character_layout |
245 |
(psiconv_character_layout ls) |
246 |
{ |
247 |
psiconv_character_layout result; |
248 |
|
249 |
if (!(result = malloc(sizeof(*result)))) |
250 |
goto ERROR1; |
251 |
*result = *ls; |
252 |
if (!(result->color = clone_color(result->color))) |
253 |
goto ERROR2; |
254 |
if (!(result->back_color = clone_color(result->back_color))) |
255 |
goto ERROR3; |
256 |
if (!(result->font = clone_font(result->font))) |
257 |
goto ERROR4; |
258 |
return result; |
259 |
ERROR4: |
260 |
psiconv_free_color(result->back_color); |
261 |
ERROR3: |
262 |
psiconv_free_color(result->color); |
263 |
ERROR2: |
264 |
free(result); |
265 |
ERROR1: |
266 |
return NULL; |
267 |
} |
268 |
|
269 |
psiconv_paragraph_layout psiconv_clone_paragraph_layout |
270 |
(psiconv_paragraph_layout ls) |
271 |
{ |
272 |
psiconv_paragraph_layout result; |
273 |
|
274 |
if (!(result = malloc(sizeof(*result)))) |
275 |
goto ERROR1; |
276 |
*result = *ls; |
277 |
if (!(result->back_color = clone_color(result->back_color))) |
278 |
goto ERROR2; |
279 |
if (!(result->bullet = clone_bullet(result->bullet))) |
280 |
goto ERROR3; |
281 |
if (!(result->left_border = clone_border(result->left_border))) |
282 |
goto ERROR4; |
283 |
if (!(result->right_border = clone_border(result->right_border))) |
284 |
goto ERROR5; |
285 |
if (!(result->top_border = clone_border(result->top_border))) |
286 |
goto ERROR6; |
287 |
if (!(result->bottom_border = clone_border(result->bottom_border))) |
288 |
goto ERROR7; |
289 |
if (!(result->tabs = clone_all_tabs(result->tabs))) |
290 |
goto ERROR8; |
291 |
return result; |
292 |
ERROR8: |
293 |
psiconv_free_border(result->bottom_border); |
294 |
ERROR7: |
295 |
psiconv_free_border(result->top_border); |
296 |
ERROR6: |
297 |
psiconv_free_border(result->right_border); |
298 |
ERROR5: |
299 |
psiconv_free_border(result->left_border); |
300 |
ERROR4: |
301 |
psiconv_free_bullet(result->bullet); |
302 |
ERROR3: |
303 |
psiconv_free_color(result->back_color); |
304 |
ERROR2: |
305 |
free(result); |
306 |
ERROR1: |
307 |
return NULL; |
308 |
} |
309 |
|
310 |
psiconv_word_style psiconv_get_style (psiconv_word_styles_section ss, int nr) |
311 |
{ |
312 |
if (nr == 0) |
313 |
return ss->normal; |
314 |
else |
315 |
return psiconv_list_get(ss->styles,0xff - nr); |
316 |
} |
317 |
|
318 |
void psiconv_free_color (psiconv_color color) |
319 |
{ |
320 |
if (color) |
321 |
free(color); |
322 |
} |
323 |
|
324 |
void psiconv_free_border(psiconv_border border) |
325 |
{ |
326 |
if (border) { |
327 |
psiconv_free_color(border->color); |
328 |
free(border); |
329 |
} |
330 |
} |
331 |
|
332 |
void psiconv_free_font(psiconv_font font) |
333 |
{ |
334 |
if (font) { |
335 |
if (font->name) |
336 |
free(font->name); |
337 |
free(font); |
338 |
} |
339 |
} |
340 |
|
341 |
void psiconv_free_bullet(psiconv_bullet bullet) |
342 |
{ |
343 |
if (bullet) { |
344 |
psiconv_free_color(bullet->color); |
345 |
psiconv_free_font(bullet->font); |
346 |
free(bullet); |
347 |
} |
348 |
} |
349 |
|
350 |
void psiconv_free_character_layout(psiconv_character_layout layout) |
351 |
{ |
352 |
if (layout) { |
353 |
psiconv_free_color(layout->color); |
354 |
psiconv_free_color(layout->back_color); |
355 |
psiconv_free_font(layout->font); |
356 |
free(layout); |
357 |
} |
358 |
} |
359 |
|
360 |
void psiconv_free_tab(psiconv_tab tab) |
361 |
{ |
362 |
if (tab) |
363 |
free(tab); |
364 |
} |
365 |
|
366 |
void psiconv_free_tabs(psiconv_all_tabs tabs) |
367 |
{ |
368 |
if (tabs) { |
369 |
psiconv_list_free(tabs->extras); |
370 |
free(tabs); |
371 |
} |
372 |
} |
373 |
|
374 |
void psiconv_free_paragraph_layout(psiconv_paragraph_layout layout) |
375 |
{ |
376 |
if (layout) { |
377 |
psiconv_free_color(layout->back_color); |
378 |
psiconv_free_bullet(layout->bullet); |
379 |
psiconv_free_border(layout->left_border); |
380 |
psiconv_free_border(layout->right_border); |
381 |
psiconv_free_border(layout->top_border); |
382 |
psiconv_free_border(layout->bottom_border); |
383 |
psiconv_free_tabs(layout->tabs); |
384 |
free(layout); |
385 |
} |
386 |
} |
387 |
|
388 |
void psiconv_free_style_aux(void *style) |
389 |
{ |
390 |
if(((psiconv_word_style) style)->name) |
391 |
free(((psiconv_word_style) style)->name); |
392 |
psiconv_free_character_layout(((psiconv_word_style) style)->character); |
393 |
psiconv_free_paragraph_layout(((psiconv_word_style) style)->paragraph); |
394 |
} |
395 |
|
396 |
void psiconv_free_word_style(psiconv_word_style style) |
397 |
{ |
398 |
if (style) { |
399 |
psiconv_free_style_aux(style); |
400 |
free(style); |
401 |
} |
402 |
} |
403 |
|
404 |
void psiconv_free_word_styles_section(psiconv_word_styles_section styles) |
405 |
{ |
406 |
if (styles) { |
407 |
psiconv_free_word_style(styles->normal); |
408 |
if (styles->styles) |
409 |
psiconv_list_free_el(styles->styles,psiconv_free_style_aux); |
410 |
} |
411 |
} |
412 |
|
413 |
void psiconv_free_header_section(psiconv_header_section header) |
414 |
{ |
415 |
if (header) |
416 |
free(header); |
417 |
} |
418 |
|
419 |
void psiconv_free_section_table_entry(psiconv_section_table_entry entry) |
420 |
{ |
421 |
if (entry) |
422 |
free(entry); |
423 |
} |
424 |
|
425 |
void psiconv_free_section_table_section(psiconv_section_table_section section) |
426 |
{ |
427 |
if (section) |
428 |
psiconv_list_free(section); |
429 |
} |
430 |
|
431 |
void psiconv_free_application_id_section(psiconv_application_id_section section) |
432 |
{ |
433 |
if (section) { |
434 |
if (section->name) |
435 |
free(section->name); |
436 |
free(section); |
437 |
} |
438 |
} |
439 |
|
440 |
void psiconv_free_in_line_layout_aux(void * layout) |
441 |
{ |
442 |
psiconv_free_character_layout(((psiconv_in_line_layout) layout)->layout); |
443 |
} |
444 |
|
445 |
void psiconv_free_in_line_layout(psiconv_in_line_layout layout) |
446 |
{ |
447 |
if (layout) { |
448 |
psiconv_free_in_line_layout_aux(layout); |
449 |
free(layout); |
450 |
} |
451 |
} |
452 |
|
453 |
void psiconv_free_in_line_layouts(psiconv_in_line_layouts layouts) |
454 |
{ |
455 |
if (layouts) |
456 |
psiconv_list_free_el(layouts,&psiconv_free_in_line_layout_aux); |
457 |
} |
458 |
|
459 |
void psiconv_free_replacement(psiconv_replacement replacement) |
460 |
{ |
461 |
if (replacement) |
462 |
free(replacement); |
463 |
} |
464 |
|
465 |
void psiconv_free_replacements(psiconv_replacements replacements) |
466 |
{ |
467 |
if (replacements) |
468 |
psiconv_list_free(replacements); |
469 |
} |
470 |
|
471 |
void psiconv_free_paragraph_aux(void * paragraph) |
472 |
{ |
473 |
if(((psiconv_paragraph) paragraph)->text) |
474 |
free(((psiconv_paragraph) paragraph)->text); |
475 |
psiconv_free_character_layout(((psiconv_paragraph) paragraph) |
476 |
->base_character); |
477 |
psiconv_free_paragraph_layout(((psiconv_paragraph) paragraph) |
478 |
->base_paragraph); |
479 |
psiconv_free_in_line_layouts(((psiconv_paragraph) paragraph) |
480 |
->in_lines); |
481 |
psiconv_free_replacements(((psiconv_paragraph) paragraph) |
482 |
->replacements); |
483 |
} |
484 |
|
485 |
void psiconv_free_paragraph(psiconv_paragraph paragraph) |
486 |
{ |
487 |
if (paragraph) { |
488 |
psiconv_free_paragraph_aux(paragraph); |
489 |
free(paragraph); |
490 |
} |
491 |
} |
492 |
|
493 |
void psiconv_free_text_and_layout(psiconv_text_and_layout text) |
494 |
{ |
495 |
if (text) |
496 |
psiconv_list_free_el(text,&psiconv_free_paragraph_aux); |
497 |
} |
498 |
|
499 |
void psiconv_free_texted_section(psiconv_texted_section section) |
500 |
{ |
501 |
if (section) { |
502 |
psiconv_free_text_and_layout(section->paragraphs); |
503 |
free(section); |
504 |
} |
505 |
} |
506 |
|
507 |
void psiconv_free_page_header(psiconv_page_header header) |
508 |
{ |
509 |
if (header) { |
510 |
psiconv_free_character_layout(header->base_character_layout); |
511 |
psiconv_free_paragraph_layout(header->base_paragraph_layout); |
512 |
psiconv_free_texted_section(header->text); |
513 |
free(header); |
514 |
} |
515 |
} |
516 |
|
517 |
void psiconv_free_page_layout_section(psiconv_page_layout_section section) |
518 |
{ |
519 |
if (section) { |
520 |
psiconv_free_page_header(section->header); |
521 |
psiconv_free_page_header(section->footer); |
522 |
free(section); |
523 |
} |
524 |
} |
525 |
|
526 |
void psiconv_free_word_status_section(psiconv_word_status_section section) |
527 |
{ |
528 |
if (section) |
529 |
free(section); |
530 |
} |
531 |
|
532 |
void psiconv_free_word_f(psiconv_word_f file) |
533 |
{ |
534 |
if (file) { |
535 |
psiconv_free_page_layout_section(file->page_sec); |
536 |
psiconv_free_text_and_layout(file->paragraphs); |
537 |
psiconv_free_word_status_section(file->status_sec); |
538 |
psiconv_free_word_styles_section(file->styles_sec); |
539 |
free(file); |
540 |
} |
541 |
} |
542 |
|
543 |
void psiconv_free_sheet_status_section(psiconv_sheet_status_section section) |
544 |
{ |
545 |
if (section) |
546 |
free(section); |
547 |
} |
548 |
|
549 |
void psiconv_free_sheet_workbook_section(psiconv_sheet_workbook_section section) |
550 |
{ |
551 |
if (section) |
552 |
free(section); |
553 |
} |
554 |
|
555 |
void psiconv_free_sheet_f(psiconv_sheet_f file) |
556 |
{ |
557 |
if (file) { |
558 |
psiconv_free_page_layout_section(file->page_sec); |
559 |
psiconv_free_sheet_status_section(file->status_sec); |
560 |
psiconv_free_sheet_workbook_section(file->workbook_sec); |
561 |
free(file); |
562 |
} |
563 |
} |
564 |
|
565 |
void psiconv_free_texted_f(psiconv_texted_f file) |
566 |
{ |
567 |
if (file) { |
568 |
psiconv_free_page_layout_section(file->page_sec); |
569 |
psiconv_free_texted_section(file->texted_sec); |
570 |
free(file); |
571 |
} |
572 |
} |
573 |
|
574 |
void psiconv_free_paint_data_section_aux(void * section) |
575 |
{ |
576 |
if (((psiconv_paint_data_section) section)->red) |
577 |
free(((psiconv_paint_data_section)section) -> red); |
578 |
if (((psiconv_paint_data_section) section)->green) |
579 |
free(((psiconv_paint_data_section)section) -> green); |
580 |
if (((psiconv_paint_data_section) section)->blue) |
581 |
free(((psiconv_paint_data_section)section) -> blue); |
582 |
} |
583 |
|
584 |
void psiconv_free_paint_data_section(psiconv_paint_data_section section) |
585 |
{ |
586 |
if (section) { |
587 |
psiconv_free_paint_data_section_aux(section); |
588 |
free(section); |
589 |
} |
590 |
} |
591 |
|
592 |
void psiconv_free_pictures(psiconv_pictures section) |
593 |
{ |
594 |
if (section) |
595 |
psiconv_list_free_el(section,&psiconv_free_paint_data_section_aux); |
596 |
} |
597 |
|
598 |
void psiconv_free_jumptable_section (psiconv_jumptable_section section) |
599 |
{ |
600 |
if (section) |
601 |
psiconv_list_free(section); |
602 |
} |
603 |
|
604 |
void psiconv_free_mbm_f(psiconv_mbm_f file) |
605 |
{ |
606 |
if (file) { |
607 |
psiconv_free_pictures(file->sections); |
608 |
free(file); |
609 |
} |
610 |
} |
611 |
|
612 |
void psiconv_free_sketch_section(psiconv_sketch_section sec) |
613 |
{ |
614 |
if (sec) { |
615 |
psiconv_free_paint_data_section(sec->picture); |
616 |
free(sec); |
617 |
} |
618 |
} |
619 |
|
620 |
void psiconv_free_sketch_f(psiconv_sketch_f file) |
621 |
{ |
622 |
if (file) { |
623 |
psiconv_free_sketch_section(file->sketch_sec); |
624 |
free(file); |
625 |
} |
626 |
} |
627 |
|
628 |
void psiconv_free_clipart_section_aux(void *section) |
629 |
{ |
630 |
if (section) |
631 |
free(((psiconv_clipart_section ) section)->picture); |
632 |
} |
633 |
|
634 |
void psiconv_free_clipart_section(psiconv_clipart_section section) |
635 |
{ |
636 |
if (section) { |
637 |
psiconv_free_clipart_section_aux(section); |
638 |
free(section); |
639 |
} |
640 |
} |
641 |
|
642 |
void psiconv_free_cliparts(psiconv_cliparts section) |
643 |
{ |
644 |
if (section) |
645 |
psiconv_list_free_el(section,&psiconv_free_clipart_section_aux); |
646 |
} |
647 |
|
648 |
void psiconv_free_clipart_f(psiconv_clipart_f file) |
649 |
{ |
650 |
if (file) { |
651 |
psiconv_free_cliparts(file->sections); |
652 |
free(file); |
653 |
} |
654 |
} |
655 |
|
656 |
void psiconv_free_file(psiconv_file file) |
657 |
{ |
658 |
if (file) { |
659 |
if (file->type == psiconv_word_file) |
660 |
psiconv_free_word_f((psiconv_word_f) file->file); |
661 |
else if (file->type == psiconv_texted_file) |
662 |
psiconv_free_texted_f((psiconv_texted_f) file->file); |
663 |
else if (file->type == psiconv_mbm_file) |
664 |
psiconv_free_mbm_f((psiconv_mbm_f) file->file); |
665 |
else if (file->type == psiconv_sketch_file) |
666 |
psiconv_free_sketch_f((psiconv_sketch_f) file->file); |
667 |
else if (file->type == psiconv_clipart_file) |
668 |
psiconv_free_clipart_f((psiconv_clipart_f) file->file); |
669 |
else if (file->type == psiconv_sheet_file) |
670 |
psiconv_free_sheet_f((psiconv_sheet_f) file->file); |
671 |
free(file); |
672 |
} |
673 |
} |
674 |
|
675 |
int psiconv_compare_color(const psiconv_color value1, |
676 |
const psiconv_color value2) |
677 |
{ |
678 |
if (!value1 || !value2) |
679 |
return 1; |
680 |
if ((value1->red == value2->red) && |
681 |
(value1->green == value2->green) && |
682 |
(value1->blue == value2->blue)) |
683 |
return 0; |
684 |
else |
685 |
return 1; |
686 |
} |
687 |
|
688 |
int psiconv_compare_font(const psiconv_font value1, |
689 |
const psiconv_font value2) |
690 |
{ |
691 |
if (!value1 || !value2 || !value1->name || !value2->name) |
692 |
return 1; |
693 |
if ((value1->screenfont == value2->screenfont) && |
694 |
!strcmp(value1->name,value2->name)) |
695 |
return 0; |
696 |
else |
697 |
return 1; |
698 |
} |
699 |
|
700 |
int psiconv_compare_border(const psiconv_border value1, |
701 |
const psiconv_border value2) |
702 |
{ |
703 |
if (!value1 || !value2) |
704 |
return 1; |
705 |
if ((value1->kind == value2->kind) && |
706 |
(value1->thickness == value2->thickness) && |
707 |
!psiconv_compare_color(value1->color,value2->color)) |
708 |
return 0; |
709 |
else |
710 |
return 1; |
711 |
} |
712 |
|
713 |
int psiconv_compare_bullet(const psiconv_bullet value1, |
714 |
const psiconv_bullet value2) |
715 |
{ |
716 |
if (!value1 || !value2) |
717 |
return 1; |
718 |
if ((value1->on == value2->on) && |
719 |
(value1->font_size == value2->font_size) && |
720 |
(value1->character == value2->character) && |
721 |
(value1->indent == value2->indent) && |
722 |
!psiconv_compare_color(value1->color,value2->color) && |
723 |
!psiconv_compare_font(value1->font,value2->font)) |
724 |
return 0; |
725 |
else |
726 |
return 1; |
727 |
} |
728 |
|
729 |
int psiconv_compare_tab(const psiconv_tab value1, const psiconv_tab value2) |
730 |
{ |
731 |
if (!value1 || !value2) |
732 |
return 1; |
733 |
if ((value1->location == value2->location) && |
734 |
(value1->kind == value2->kind)) |
735 |
return 0; |
736 |
else |
737 |
return 1; |
738 |
} |
739 |
|
740 |
int psiconv_compare_all_tabs(const psiconv_all_tabs value1, |
741 |
const psiconv_all_tabs value2) |
742 |
{ |
743 |
int i; |
744 |
|
745 |
if (!value1 || !value2 || !value1->extras || !value2->extras) |
746 |
return 1; |
747 |
|
748 |
if ((value1->normal != value2->normal) || |
749 |
psiconv_list_length(value1->extras) != |
750 |
psiconv_list_length(value2->extras)) |
751 |
return 1; |
752 |
for (i = 0; i < psiconv_list_length(value1->extras); i++) |
753 |
if (psiconv_compare_tab(psiconv_list_get(value1->extras,i), |
754 |
psiconv_list_get(value2->extras,i))) |
755 |
|
756 |
return 1; |
757 |
return 0; |
758 |
} |
759 |
|
760 |
int psiconv_compare_paragraph_layout(const psiconv_paragraph_layout value1, |
761 |
const psiconv_paragraph_layout value2) |
762 |
{ |
763 |
if (!value1 || !value2) |
764 |
return 1; |
765 |
if ((value1->indent_left == value2->indent_left) && |
766 |
(value1->indent_right == value2->indent_right) && |
767 |
(value1->indent_first == value2->indent_first) && |
768 |
(value1->justify_hor == value2->justify_hor) && |
769 |
(value1->justify_ver == value2->justify_ver) && |
770 |
(value1->linespacing == value2->linespacing) && |
771 |
(value1->space_above == value2->space_above) && |
772 |
(value1->space_below == value2->space_below) && |
773 |
(value1->keep_together == value2->keep_together) && |
774 |
(value1->keep_with_next == value2->keep_with_next) && |
775 |
(value1->on_next_page == value2->on_next_page) && |
776 |
(value1->no_widow_protection == value2->no_widow_protection) && |
777 |
(value1->border_distance == value2->border_distance) && |
778 |
!psiconv_compare_color(value1->back_color,value2->back_color) && |
779 |
!psiconv_compare_bullet(value1->bullet,value2->bullet) && |
780 |
!psiconv_compare_border(value1->left_border,value2->left_border) && |
781 |
!psiconv_compare_border(value1->right_border,value2->right_border) && |
782 |
!psiconv_compare_border(value1->top_border,value2->top_border) && |
783 |
!psiconv_compare_border(value1->bottom_border,value2->bottom_border) && |
784 |
!psiconv_compare_all_tabs(value1->tabs,value2->tabs)) |
785 |
return 0; |
786 |
else |
787 |
return 1; |
788 |
} |
789 |
|
790 |
|
791 |
int psiconv_compare_character_layout(const psiconv_character_layout value1, |
792 |
const psiconv_character_layout value2) |
793 |
{ |
794 |
if (!value1 || !value2) |
795 |
return 1; |
796 |
if ((value1->font_size == value2->font_size) && |
797 |
(value1->italic == value2->italic) && |
798 |
(value1->bold == value2->bold) && |
799 |
(value1->super_sub == value2->super_sub) && |
800 |
(value1->underline == value2->underline) && |
801 |
(value1->strikethrough == value2->strikethrough) && |
802 |
!psiconv_compare_color(value1->color,value2->color) && |
803 |
!psiconv_compare_color(value1->back_color,value2->back_color) && |
804 |
!psiconv_compare_font(value1->font,value2->font)) |
805 |
return 0; |
806 |
else |
807 |
return 1; |
808 |
} |
809 |
|
810 |
|
811 |
|
812 |
psiconv_word_styles_section psiconv_empty_word_styles_section(void) |
813 |
{ |
814 |
psiconv_word_styles_section result; |
815 |
if (!(result = malloc(sizeof(*result)))) |
816 |
goto ERROR1; |
817 |
if (!(result->styles = psiconv_list_new(sizeof(struct psiconv_word_style_s)))) |
818 |
goto ERROR2; |
819 |
if (!(result->normal = malloc(sizeof(struct psiconv_word_style_s)))) |
820 |
goto ERROR3; |
821 |
if (!(result->normal->character = psiconv_basic_character_layout())) |
822 |
goto ERROR4; |
823 |
if (!(result->normal->paragraph = psiconv_basic_paragraph_layout())) |
824 |
goto ERROR5; |
825 |
result->normal->hotkey = 'N'; |
826 |
result->normal->name = NULL; |
827 |
result->normal->built_in = psiconv_bool_true; |
828 |
result->normal->outline_level = 0; |
829 |
return result; |
830 |
ERROR5: |
831 |
psiconv_free_character_layout(result->normal->character); |
832 |
ERROR4: |
833 |
free(result->normal); |
834 |
ERROR3: |
835 |
psiconv_list_free(result->styles); |
836 |
ERROR2: |
837 |
free(result); |
838 |
ERROR1: |
839 |
return NULL; |
840 |
} |
841 |
|
842 |
psiconv_text_and_layout psiconv_empty_text_and_layout(void) |
843 |
{ |
844 |
return psiconv_list_new(sizeof(struct psiconv_paragraph_s)); |
845 |
} |
846 |
|
847 |
psiconv_texted_section psiconv_empty_texted_section(void) |
848 |
{ |
849 |
psiconv_texted_section result; |
850 |
if (!(result = malloc(sizeof(*result)))) |
851 |
goto ERROR1; |
852 |
if (!(result->paragraphs = psiconv_empty_text_and_layout())) |
853 |
goto ERROR2; |
854 |
return result; |
855 |
ERROR2: |
856 |
free(result); |
857 |
ERROR1: |
858 |
return NULL; |
859 |
} |
860 |
|
861 |
psiconv_page_header psiconv_empty_page_header(void) |
862 |
{ |
863 |
psiconv_page_header result; |
864 |
if (!(result = malloc(sizeof(*result)))) |
865 |
goto ERROR1; |
866 |
result->on_first_page = psiconv_bool_true; |
867 |
if (!(result->base_paragraph_layout = psiconv_basic_paragraph_layout())) |
868 |
goto ERROR2; |
869 |
if (!(result->base_character_layout = psiconv_basic_character_layout())) |
870 |
goto ERROR3; |
871 |
if (!(result->text = psiconv_empty_texted_section())) |
872 |
goto ERROR4; |
873 |
return result; |
874 |
ERROR4: |
875 |
psiconv_free_character_layout(result->base_character_layout); |
876 |
ERROR3: |
877 |
psiconv_free_paragraph_layout(result->base_paragraph_layout); |
878 |
ERROR2: |
879 |
free(result); |
880 |
ERROR1: |
881 |
return NULL; |
882 |
} |
883 |
|
884 |
psiconv_page_layout_section psiconv_empty_page_layout_section(void) |
885 |
{ |
886 |
psiconv_page_layout_section result; |
887 |
if (!(result = malloc(sizeof(*result)))) |
888 |
goto ERROR1; |
889 |
result->first_page_nr = 1; |
890 |
result->header_dist = result->footer_dist = 1.27; |
891 |
result->left_margin = result->right_margin = 3.175; |
892 |
result->top_margin = result->bottom_margin = 2.54; |
893 |
result->page_width = 21.0; |
894 |
result->page_height = 29.7; |
895 |
result->landscape = psiconv_bool_false; |
896 |
if (!(result->header = psiconv_empty_page_header())) |
897 |
goto ERROR2; |
898 |
if (!(result->footer = psiconv_empty_page_header())) |
899 |
goto ERROR3; |
900 |
return result; |
901 |
ERROR3: |
902 |
psiconv_free_page_header(result->header); |
903 |
ERROR2: |
904 |
free(result); |
905 |
ERROR1: |
906 |
return NULL; |
907 |
} |
908 |
|
909 |
psiconv_word_status_section psiconv_empty_word_status_section(void) |
910 |
{ |
911 |
psiconv_word_status_section result; |
912 |
if (!(result = malloc(sizeof(*result)))) |
913 |
return NULL; |
914 |
result->show_tabs = result->show_spaces = result->show_paragraph_ends = |
915 |
result->show_hard_minus = result->show_hard_space = |
916 |
result->fit_lines_to_screen = psiconv_bool_false; |
917 |
result->show_full_pictures = result->show_full_graphs = |
918 |
result->show_top_toolbar = result->show_side_toolbar = |
919 |
psiconv_bool_true; |
920 |
result->cursor_position = 0; |
921 |
result->display_size = 1000; |
922 |
return result; |
923 |
} |
924 |
|
925 |
psiconv_word_f psiconv_empty_word_f(void) |
926 |
{ |
927 |
psiconv_word_f result; |
928 |
if (!(result = malloc(sizeof(*result)))) |
929 |
goto ERROR1; |
930 |
if (!(result->page_sec = psiconv_empty_page_layout_section())) |
931 |
goto ERROR2; |
932 |
if (!(result->paragraphs = psiconv_empty_text_and_layout())) |
933 |
goto ERROR3; |
934 |
if (!(result->status_sec = psiconv_empty_word_status_section())) |
935 |
goto ERROR4; |
936 |
if (!(result->styles_sec = psiconv_empty_word_styles_section())) |
937 |
goto ERROR5; |
938 |
return result; |
939 |
ERROR5: |
940 |
psiconv_free_word_status_section(result->status_sec); |
941 |
ERROR4: |
942 |
psiconv_free_text_and_layout(result->paragraphs); |
943 |
ERROR3: |
944 |
psiconv_free_page_layout_section(result->page_sec); |
945 |
ERROR2: |
946 |
free(result); |
947 |
ERROR1: |
948 |
return NULL; |
949 |
} |
950 |
|
951 |
psiconv_sheet_status_section psiconv_empty_sheet_status_section(void) |
952 |
{ |
953 |
psiconv_sheet_status_section result; |
954 |
if (!(result = malloc(sizeof(*result)))) |
955 |
return NULL; |
956 |
result->show_horizontal_scrollbar = result->show_vertical_scrollbar = |
957 |
psiconv_triple_auto; |
958 |
result->show_graph = psiconv_bool_false; |
959 |
result->show_top_sheet_toolbar = result->show_side_sheet_toolbar = |
960 |
result->show_top_graph_toolbar = result->show_side_graph_toolbar = |
961 |
psiconv_bool_true; |
962 |
result->cursor_row = result->cursor_column = 0; |
963 |
result->sheet_display_size = result->graph_display_size = 1000; |
964 |
return result; |
965 |
} |
966 |
|
967 |
psiconv_sheet_workbook_section psiconv_empty_sheet_workbook_section(void) |
968 |
{ |
969 |
psiconv_sheet_workbook_section result; |
970 |
if (!(result = malloc(sizeof(*result)))) |
971 |
return NULL; |
972 |
return result; |
973 |
} |
974 |
|
975 |
psiconv_sheet_f psiconv_empty_sheet_f(void) |
976 |
{ |
977 |
psiconv_sheet_f result; |
978 |
if (!(result = malloc(sizeof(*result)))) |
979 |
goto ERROR1; |
980 |
if (!(result->page_sec = psiconv_empty_page_layout_section())) |
981 |
goto ERROR2; |
982 |
if (!(result->status_sec = psiconv_empty_sheet_status_section())) |
983 |
goto ERROR3; |
984 |
if (!(result->workbook_sec = psiconv_empty_sheet_workbook_section())) |
985 |
goto ERROR4; |
986 |
return result; |
987 |
ERROR4: |
988 |
psiconv_free_sheet_status_section(result->status_sec); |
989 |
ERROR3: |
990 |
psiconv_free_page_layout_section(result->page_sec); |
991 |
ERROR2: |
992 |
free(result); |
993 |
ERROR1: |
994 |
return NULL; |
995 |
} |
996 |
|
997 |
psiconv_texted_f psiconv_empty_texted_f(void) |
998 |
{ |
999 |
psiconv_texted_f result; |
1000 |
if (!(result = malloc(sizeof(*result)))) |
1001 |
goto ERROR1; |
1002 |
if (!(result->page_sec = psiconv_empty_page_layout_section())) |
1003 |
goto ERROR2; |
1004 |
if (!(result->texted_sec = psiconv_empty_texted_section())) |
1005 |
goto ERROR3; |
1006 |
return result; |
1007 |
ERROR3: |
1008 |
psiconv_free_page_layout_section(result->page_sec); |
1009 |
ERROR2: |
1010 |
free(result); |
1011 |
ERROR1: |
1012 |
return NULL; |
1013 |
} |
1014 |
|
1015 |
psiconv_paint_data_section psiconv_empty_paint_data_section(void) |
1016 |
{ |
1017 |
psiconv_paint_data_section result; |
1018 |
if (!(result = malloc(sizeof(*result)))) |
1019 |
goto ERROR1; |
1020 |
/* Is this correct? */ |
1021 |
result->xsize = result->ysize = result->pic_xsize = result->pic_ysize = 0; |
1022 |
/* Probably forbidden... */ |
1023 |
if (!(result->red = malloc(0))) |
1024 |
goto ERROR2; |
1025 |
if (!(result->green = malloc(0))) |
1026 |
goto ERROR3; |
1027 |
if (!(result->blue = malloc(0))) |
1028 |
goto ERROR4; |
1029 |
return result; |
1030 |
ERROR4: |
1031 |
free(result->green); |
1032 |
ERROR3: |
1033 |
free(result->red); |
1034 |
ERROR2: |
1035 |
free(result); |
1036 |
ERROR1: |
1037 |
return NULL; |
1038 |
} |
1039 |
|
1040 |
|
1041 |
psiconv_pictures psiconv_empty_pictures(void) |
1042 |
{ |
1043 |
psiconv_pictures result; |
1044 |
psiconv_paint_data_section pds; |
1045 |
if (!(result = psiconv_list_new(sizeof(struct psiconv_paint_data_section_s)))) |
1046 |
goto ERROR1; |
1047 |
if (!(pds = psiconv_empty_paint_data_section())) |
1048 |
goto ERROR2; |
1049 |
if (psiconv_list_add(result,pds)) |
1050 |
goto ERROR3; |
1051 |
free(pds); |
1052 |
return result; |
1053 |
ERROR3: |
1054 |
psiconv_free_paint_data_section(pds); |
1055 |
ERROR2: |
1056 |
psiconv_list_free(result); |
1057 |
ERROR1: |
1058 |
return NULL; |
1059 |
} |
1060 |
|
1061 |
psiconv_mbm_f psiconv_empty_mbm_f(void) |
1062 |
{ |
1063 |
psiconv_mbm_f result; |
1064 |
if (!(result = malloc(sizeof(*result)))) |
1065 |
goto ERROR1; |
1066 |
if (!(result->sections = psiconv_empty_pictures())) |
1067 |
goto ERROR2; |
1068 |
return result; |
1069 |
ERROR2: |
1070 |
free(result); |
1071 |
ERROR1: |
1072 |
return NULL; |
1073 |
} |
1074 |
|
1075 |
psiconv_sketch_section psiconv_empty_sketch_section(void) |
1076 |
{ |
1077 |
psiconv_sketch_section result; |
1078 |
if (!(result = malloc(sizeof(*result)))) |
1079 |
goto ERROR1; |
1080 |
result->form_xsize = 320; |
1081 |
result->form_ysize = 200; |
1082 |
result->picture_x_offset = result->picture_y_offset = result->picture_xsize = |
1083 |
result->picture_ysize = 0; |
1084 |
result->magnification_x = result->magnification_y = 1.0; |
1085 |
result->cut_left = result->cut_right = result->cut_top = |
1086 |
result->cut_bottom = 0.0; |
1087 |
if (!(result->picture = psiconv_empty_paint_data_section())) |
1088 |
goto ERROR2; |
1089 |
return result; |
1090 |
ERROR2: |
1091 |
free(result); |
1092 |
ERROR1: |
1093 |
return NULL; |
1094 |
} |
1095 |
|
1096 |
psiconv_sketch_f psiconv_empty_sketch_f(void) |
1097 |
{ |
1098 |
psiconv_sketch_f result; |
1099 |
if (!(result = malloc(sizeof(*result)))) |
1100 |
goto ERROR1; |
1101 |
if (!(result->sketch_sec = psiconv_empty_sketch_section())) |
1102 |
goto ERROR2; |
1103 |
return result; |
1104 |
ERROR2: |
1105 |
free(result); |
1106 |
ERROR1: |
1107 |
return NULL; |
1108 |
} |
1109 |
|
1110 |
psiconv_cliparts psiconv_empty_cliparts(void) |
1111 |
{ |
1112 |
/* Is this correct? */ |
1113 |
return psiconv_list_new(sizeof(struct psiconv_clipart_section_s)); |
1114 |
} |
1115 |
|
1116 |
psiconv_clipart_f psiconv_empty_clipart_f(void) |
1117 |
{ |
1118 |
psiconv_clipart_f result; |
1119 |
if (!(result = malloc(sizeof(*result)))) |
1120 |
goto ERROR1; |
1121 |
if (!(result->sections = psiconv_empty_cliparts())) |
1122 |
goto ERROR2; |
1123 |
return result; |
1124 |
ERROR2: |
1125 |
free(result); |
1126 |
ERROR1: |
1127 |
return NULL; |
1128 |
} |
1129 |
|
1130 |
psiconv_file psiconv_empty_file(psiconv_file_type_t type) |
1131 |
{ |
1132 |
psiconv_file result; |
1133 |
if (!(result = malloc(sizeof(*result)))) |
1134 |
return NULL; |
1135 |
result->type = type; |
1136 |
if (type == psiconv_word_file) { |
1137 |
if (!(result->file = psiconv_empty_word_f())) |
1138 |
goto ERROR; |
1139 |
} else if (type == psiconv_sheet_file) { |
1140 |
if (!(result->file = psiconv_empty_sheet_f())) |
1141 |
goto ERROR; |
1142 |
} else if (type == psiconv_texted_file) { |
1143 |
if (!(result->file = psiconv_empty_texted_f())) |
1144 |
goto ERROR; |
1145 |
} else if (type == psiconv_mbm_file) { |
1146 |
if (!(result->file = psiconv_empty_mbm_f())) |
1147 |
goto ERROR; |
1148 |
} else if (type == psiconv_sketch_file) { |
1149 |
if (!(result->file = psiconv_empty_sketch_f())) |
1150 |
goto ERROR; |
1151 |
} else if (type == psiconv_clipart_file) { |
1152 |
if (!(result->file = psiconv_empty_clipart_f())) |
1153 |
goto ERROR; |
1154 |
} else |
1155 |
goto ERROR; |
1156 |
return result; |
1157 |
ERROR: |
1158 |
free(result); |
1159 |
return NULL; |
1160 |
} |