/[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 99 - (show annotations)
Tue Jan 30 21:37:19 2001 UTC (19 years, 6 months ago) by frodo
File MIME type: text/plain
File size: 34011 byte(s)
(Frodo) Most formula work is completed

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

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