/[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 143 - (show annotations)
Tue Jan 29 18:47:26 2002 UTC (17 years, 9 months ago) by frodo
File MIME type: text/plain
File size: 38859 byte(s)
(Frodo) Two memory-leaks fixed

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

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