/[public]/psiconv/trunk/lib/psiconv/data.c
ViewVC logotype

Contents of /psiconv/trunk/lib/psiconv/data.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 121 - (show annotations)
Sun Jul 1 13:14:19 2001 UTC (18 years, 6 months ago) by frodo
File MIME type: text/plain
File size: 35570 byte(s)
(Frodo) Default cell layout will now be used

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

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