/[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 125 - (show annotations)
Tue Jul 10 22:38:49 2001 UTC (22 years, 8 months ago) by frodo
File MIME type: text/plain
File size: 35706 byte(s)
(Frodo) New function psiconv_get_function

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

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