/[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 104 - (show annotations)
Wed Jan 31 00:57:17 2001 UTC (23 years, 2 months ago) by frodo
File MIME type: text/plain
File size: 34064 byte(s)
(Frodo) Applied Decsi's patch for wraps

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

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