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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2 Revision 69
1/* 1/*
2 data.c - Part of psiconv, a PSION 5 file formats converter 2 data.c - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 1999 Frodo Looijaard <frodol@dds.nl> 3 Copyright (c) 1999, 2000 Frodo Looijaard <frodol@dds.nl>
4 4
5 This program is free software; you can redistribute it and/or modify 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 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 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/ 18*/
19 19
20#include "config.h" 20#include "config.h"
21#include "compat.h"
21#include <stdlib.h> 22#include <stdlib.h>
22#include <string.h> 23#include <string.h>
23#include "data.h" 24#include "data.h"
24#include "list.h"
25#include "general.h"
26 25
27static psiconv_color clone_color(psiconv_color color); 26static psiconv_color clone_color(psiconv_color color);
28static psiconv_font clone_font(psiconv_font font); 27static psiconv_font clone_font(psiconv_font font);
29static psiconv_border clone_border(psiconv_border border); 28static psiconv_border clone_border(psiconv_border border);
30static psiconv_bullet clone_bullet(psiconv_bullet bullet); 29static psiconv_bullet clone_bullet(psiconv_bullet bullet);
31static psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs); 30static psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs);
32static void psiconv_free_style_aux(void *style); 31static void psiconv_free_style_aux(void *style);
33static void psiconv_free_in_line_layout_aux(void * layout); 32static void psiconv_free_in_line_layout_aux(void * layout);
34static void psiconv_free_paragraph_aux(void * paragraph); 33static void psiconv_free_paragraph_aux(void * paragraph);
34static void psiconv_free_paint_data_section_aux(void * section);
35static void psiconv_free_clipart_section_aux(void * section);
35 36
37/* Note: these defaults seem to be hard-coded somewhere outside the
38 files themself. */
36psiconv_character_layout psiconv_basic_character_layout(void) 39psiconv_character_layout psiconv_basic_character_layout(void)
37{ 40{
41 /* Make the structures static, to oblige IRIX */
38 struct psiconv_color black = 42 static struct psiconv_color_s black =
39 { 43 {
40 0x00, /* red */ 44 0x00, /* red */
41 0x00, /* green */ 45 0x00, /* green */
42 0x00, /* blue */ 46 0x00, /* blue */
43 }; 47 };
44 struct psiconv_color white = 48 static struct psiconv_color_s white =
45 { 49 {
46 0xff, /* red */ 50 0xff, /* red */
47 0xff, /* green */ 51 0xff, /* green */
48 0xff, /* blue */ 52 0xff, /* blue */
49 }; 53 };
54 static struct psiconv_font_s font =
55 {
56 "Times New Roman", /* name */
57 3 /* screenfont */
58 };
50 struct psiconv_character_layout cl = 59 struct psiconv_character_layout_s cl =
51 { 60 {
52 &black, /* color */ 61 &black, /* color */
53 &white, /* back_color */ 62 &white, /* back_color */
54 10.0, /* font_size */ 63 10.0, /* font_size */
55 psiconv_bool_false, /* italic */ 64 psiconv_bool_false, /* italic */
56 psiconv_bool_false, /* bold */ 65 psiconv_bool_false, /* bold */
57 psiconv_normalscript, /* super_sub */ 66 psiconv_normalscript, /* super_sub */
58 psiconv_bool_false, /* underline */ 67 psiconv_bool_false, /* underline */
59 psiconv_bool_false, /* strike_out */ 68 psiconv_bool_false, /* strikethrough */
60 NULL, /* font */ 69 &font, /* font */
61 }; 70 };
62 71
63 cl.color = malloc(sizeof(*cl.color));
64 cl.color->red = 0x00;
65 cl.color->green = 0x00;
66 cl.color->blue = 0x00;
67 cl.back_color = malloc(sizeof(*cl.color));
68 cl.back_color->red = 0xff;
69 cl.back_color->green = 0xff;
70 cl.back_color->blue = 0xff;
71 cl.font = malloc(sizeof(*cl.font));
72 cl.font->name = strdup("Times New Roman");
73 cl.font->screenfont = 3;
74 return psiconv_clone_character_layout(&cl); 72 return psiconv_clone_character_layout(&cl);
75} 73}
76 74
75/* Note: these defaults seem to be hard-coded somewhere outside the
76 files themself. */
77psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) 77psiconv_paragraph_layout psiconv_basic_paragraph_layout(void)
78{ 78{
79 char base_font[] = "Times New Roman";
80
81 struct psiconv_font font = 79 static struct psiconv_font_s font =
82 { 80 {
83 base_font, /* name */ 81 "Times New Roman", /* name */
84 2 /* screenfont */ 82 2 /* screenfont */
85 }; 83 };
86 struct psiconv_color black = 84 static struct psiconv_color_s black =
87 { 85 {
88 0x00, /* red */ 86 0x00, /* red */
89 0x00, /* green */ 87 0x00, /* green */
90 0x00, /* blue */ 88 0x00, /* blue */
91 }; 89 };
92 struct psiconv_color white = 90 static struct psiconv_color_s white =
93 { 91 {
94 0xff, /* red */ 92 0xff, /* red */
95 0xff, /* green */ 93 0xff, /* green */
96 0xff, /* blue */ 94 0xff, /* blue */
97 }; 95 };
98 struct psiconv_border no_border = 96 static struct psiconv_border_s no_border =
99 { 97 {
100 psiconv_border_none, /* kind */ 98 psiconv_border_none, /* kind */
101 1, /* thickness */ 99 1, /* thickness */
102 &black /* color */ 100 &black /* color */
103 }; 101 };
104 struct psiconv_bullet bullet = 102 static struct psiconv_bullet_s bullet =
105 { 103 {
106 psiconv_bool_false, /* on */ 104 psiconv_bool_false, /* on */
107 10.0, /* font_size */ 105 10.0, /* font_size */
108 0x95, /* character */ 106 0x95, /* character */
109 psiconv_bool_true, /* indent */ 107 psiconv_bool_true, /* indent */
110 &black, /* color */ 108 &black, /* color */
111 &font, /* font */ 109 &font, /* font */
112 }; 110 };
113 struct psiconv_all_tabs tabs = 111 static struct psiconv_all_tabs_s tabs =
114 { 112 {
115 0.64, /* normal */ 113 0.64, /* normal */
116 NULL /* kind */ 114 NULL /* kind */
117 }; 115 };
118 struct psiconv_paragraph_layout pl = 116 struct psiconv_paragraph_layout_s pl =
119 { 117 {
120 &white, /* back_color */ 118 &white, /* back_color */
121 0.0, /* indent_left */ 119 0.0, /* indent_left */
122 0.0, /* indent_right */ 120 0.0, /* indent_right */
123 0.0, /* indent_first */ 121 0.0, /* indent_first */
124 psiconv_justify_left, /* justify_hor */ 122 psiconv_justify_left, /* justify_hor */
125 psiconv_justify_middle,/* justify_ver */ 123 psiconv_justify_middle,/* justify_ver */
126 0.0, /* interline */ 124 10.0, /* linespacing */
127 psiconv_bool_false, /* interline_exact */ 125 psiconv_bool_false, /* linespacing_exact */
128 0.0, /* top_space */ 126 0.0, /* space_above */
129 0.0, /* bottom_space */ 127 0.0, /* space_below */
130 psiconv_bool_false, /* on_one_page */
131 psiconv_bool_false, /* together_with */ 128 psiconv_bool_false, /* keep_together */
129 psiconv_bool_false, /* keep_with_next */
132 psiconv_bool_false, /* on_next_page */ 130 psiconv_bool_false, /* on_next_page */
133 psiconv_bool_false, /* no_widow_protection */ 131 psiconv_bool_false, /* no_widow_protection */
134 0.0, /* left_margin */ 132 0.0, /* left_margin */
135 &bullet, /* bullet */ 133 &bullet, /* bullet */
136 &no_border, /* left_border */ 134 &no_border, /* left_border */
139 &no_border, /* bottom_border */ 137 &no_border, /* bottom_border */
140 &tabs, /* tabs */ 138 &tabs, /* tabs */
141 }; 139 };
142 psiconv_paragraph_layout res; 140 psiconv_paragraph_layout res;
143 141
144 pl.tabs->extras = psiconv_list_new(sizeof(struct psiconv_tab)); 142 if (!(pl.tabs->extras = psiconv_list_new(sizeof(struct psiconv_tab_s))))
143 return NULL;
145 res = psiconv_clone_paragraph_layout(&pl); 144 res = psiconv_clone_paragraph_layout(&pl);
146 psiconv_list_free(pl.tabs->extras); 145 psiconv_list_free(pl.tabs->extras);
147 return res; 146 return res;
148} 147}
149 148
150psiconv_color clone_color(psiconv_color color) 149psiconv_color clone_color(psiconv_color color)
151{ 150{
152 psiconv_color result; 151 psiconv_color result;
153 result = malloc(sizeof(*result)); 152 if (!(result = malloc(sizeof(*result))))
153 return NULL;
154 *result = *color; 154 *result = *color;
155 return result; 155 return result;
156} 156}
157 157
158psiconv_font clone_font(psiconv_font font) 158psiconv_font clone_font(psiconv_font font)
159{ 159{
160 psiconv_font result; 160 psiconv_font result;
161 result = malloc(sizeof(*result)); 161 if(!(result = malloc(sizeof(*result))))
162 goto ERROR1;
162 *result = *font; 163 *result = *font;
163 result->name = strdup(result->name); 164 if (!(result->name = strdup(result->name)))
165 goto ERROR2;
164 return result; 166 return result;
167ERROR2:
168 free(result);
169ERROR1:
170 return NULL;
165} 171}
166 172
167psiconv_border clone_border(psiconv_border border) 173psiconv_border clone_border(psiconv_border border)
168{ 174{
169 psiconv_border result; 175 psiconv_border result;
170 result = malloc(sizeof(*result)); 176 if (!(result = malloc(sizeof(*result))))
177 goto ERROR1;
171 *result = *border; 178 *result = *border;
172 result->color = clone_color(result->color); 179 if(!(result->color = clone_color(result->color)))
180 goto ERROR2;
173 return result; 181 return result;
182ERROR2:
183 free(result);
184ERROR1:
185 return NULL;
174} 186}
175 187
176psiconv_bullet clone_bullet(psiconv_bullet bullet) 188psiconv_bullet clone_bullet(psiconv_bullet bullet)
177{ 189{
178 psiconv_bullet result; 190 psiconv_bullet result;
179 result = malloc(sizeof(*result)); 191 if (!(result = malloc(sizeof(*result))))
192 goto ERROR1;
180 *result = *bullet; 193 *result = *bullet;
181 result->font = clone_font(result->font); 194 if (!(result->font = clone_font(result->font)))
195 goto ERROR2;
182 result->color = clone_color(result->color); 196 if (!(result->color = clone_color(result->color)))
197 goto ERROR3;
183 return result; 198 return result;
199ERROR3:
200 psiconv_free_font(result->font);
201ERROR2:
202 free(result);
203ERROR1:
204 return NULL;
184} 205}
185 206
186psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs) 207psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs)
187{ 208{
188 psiconv_all_tabs result; 209 psiconv_all_tabs result;
189 result = malloc(sizeof(*result)); 210 if (!(result = malloc(sizeof(*result))))
211 goto ERROR1;
190 *result = *all_tabs; 212 *result = *all_tabs;
191 result->extras = psiconv_list_clone(result->extras); 213 if (!(result->extras = psiconv_list_clone(result->extras)))
214 goto ERROR2;
192 return result; 215 return result;
216ERROR2:
217 free(result);
218ERROR1:
219 return NULL;
193} 220}
194 221
195psiconv_character_layout psiconv_clone_character_layout 222psiconv_character_layout psiconv_clone_character_layout
196 (psiconv_character_layout ls) 223 (psiconv_character_layout ls)
197{ 224{
198 psiconv_character_layout result; 225 psiconv_character_layout result;
199 226
200 result = malloc(sizeof(*result)); 227 if (!(result = malloc(sizeof(*result))))
228 goto ERROR1;
201 *result = *ls; 229 *result = *ls;
202 result->color = clone_color(result->color); 230 if (!(result->color = clone_color(result->color)))
231 goto ERROR2;
203 result->back_color = clone_color(result->back_color); 232 if (!(result->back_color = clone_color(result->back_color)))
233 goto ERROR3;
204 result->font = clone_font(result->font); 234 if (!(result->font = clone_font(result->font)))
235 goto ERROR4;
205 return result; 236 return result;
237ERROR4:
238 psiconv_free_color(result->back_color);
239ERROR3:
240 psiconv_free_color(result->color);
241ERROR2:
242 free(result);
243ERROR1:
244 return NULL;
206} 245}
207 246
208psiconv_paragraph_layout psiconv_clone_paragraph_layout 247psiconv_paragraph_layout psiconv_clone_paragraph_layout
209 (psiconv_paragraph_layout ls) 248 (psiconv_paragraph_layout ls)
210{ 249{
211 psiconv_paragraph_layout result; 250 psiconv_paragraph_layout result;
212 251
213 result = malloc(sizeof(*result)); 252 if (!(result = malloc(sizeof(*result))))
253 goto ERROR1;
214 *result = *ls; 254 *result = *ls;
215 result->back_color = clone_color(result->back_color); 255 if (!(result->back_color = clone_color(result->back_color)))
256 goto ERROR2;
216 result->bullet = clone_bullet(result->bullet); 257 if (!(result->bullet = clone_bullet(result->bullet)))
258 goto ERROR3;
217 result->left_border = clone_border(result->left_border); 259 if (!(result->left_border = clone_border(result->left_border)))
260 goto ERROR4;
218 result->right_border = clone_border(result->right_border); 261 if (!(result->right_border = clone_border(result->right_border)))
262 goto ERROR5;
219 result->top_border = clone_border(result->top_border); 263 if (!(result->top_border = clone_border(result->top_border)))
264 goto ERROR6;
220 result->bottom_border = clone_border(result->bottom_border); 265 if (!(result->bottom_border = clone_border(result->bottom_border)))
266 goto ERROR7;
221 result->tabs = clone_all_tabs(result->tabs); 267 if (!(result->tabs = clone_all_tabs(result->tabs)))
268 goto ERROR8;
222 return result; 269 return result;
270ERROR8:
271 psiconv_free_border(result->bottom_border);
272ERROR7:
273 psiconv_free_border(result->top_border);
274ERROR6:
275 psiconv_free_border(result->right_border);
276ERROR5:
277 psiconv_free_border(result->left_border);
278ERROR4:
279 psiconv_free_bullet(result->bullet);
280ERROR3:
281 psiconv_free_color(result->back_color);
282ERROR2:
283 free(result);
284ERROR1:
285 return NULL;
223} 286}
224 287
225psiconv_word_style psiconv_get_style (psiconv_word_styles_section ss, int nr) 288psiconv_word_style psiconv_get_style (psiconv_word_styles_section ss, int nr)
226{ 289{
227 if (nr == 0) 290 if (nr == 0)
453 psiconv_free_word_styles_section(file->styles_sec); 516 psiconv_free_word_styles_section(file->styles_sec);
454 free(file); 517 free(file);
455 } 518 }
456} 519}
457 520
521void psiconv_free_texted_f(psiconv_texted_f file)
522{
523 if (file) {
524 psiconv_free_page_layout_section(file->page_sec);
525 psiconv_free_texted_section(file->texted_sec);
526 free(file);
527 }
528}
529
530void psiconv_free_paint_data_section_aux(void * section)
531{
532 if (((psiconv_paint_data_section) section)->red)
533 free(((psiconv_paint_data_section)section) -> red);
534 if (((psiconv_paint_data_section) section)->green)
535 free(((psiconv_paint_data_section)section) -> green);
536 if (((psiconv_paint_data_section) section)->blue)
537 free(((psiconv_paint_data_section)section) -> blue);
538}
539
540void psiconv_free_paint_data_section(psiconv_paint_data_section section)
541{
542 if (section) {
543 psiconv_free_paint_data_section_aux(section);
544 free(section);
545 }
546}
547
548void psiconv_free_pictures(psiconv_pictures section)
549{
550 if (section)
551 psiconv_list_free_el(section,&psiconv_free_paint_data_section_aux);
552}
553
554void psiconv_free_jumptable_section (psiconv_jumptable_section section)
555{
556 if (section)
557 psiconv_list_free(section);
558}
559
560void psiconv_free_mbm_f(psiconv_mbm_f file)
561{
562 if (file) {
563 psiconv_free_pictures(file->sections);
564 free(file);
565 }
566}
567
568void psiconv_free_sketch_section(psiconv_sketch_section sec)
569{
570 if (sec) {
571 psiconv_free_paint_data_section(sec->picture);
572 free(sec);
573 }
574}
575
576void psiconv_free_sketch_f(psiconv_sketch_f file)
577{
578 if (file) {
579 psiconv_free_sketch_section(file->sketch_sec);
580 free(file);
581 }
582}
583
584void psiconv_free_clipart_section_aux(void *section)
585{
586 if (section)
587 free(((psiconv_clipart_section ) section)->picture);
588}
589
590void psiconv_free_clipart_section(psiconv_clipart_section section)
591{
592 if (section) {
593 psiconv_free_clipart_section_aux(section);
594 free(section);
595 }
596}
597
598void psiconv_free_cliparts(psiconv_cliparts section)
599{
600 if (section)
601 psiconv_list_free_el(section,&psiconv_free_clipart_section_aux);
602}
603
604void psiconv_free_clipart_f(psiconv_clipart_f file)
605{
606 if (file) {
607 psiconv_free_cliparts(file->sections);
608 free(file);
609 }
610}
611
458void psiconv_free_file(psiconv_file file) 612void psiconv_free_file(psiconv_file file)
459{ 613{
460 if (file) { 614 if (file) {
461 if (file->type == psiconv_word_file) 615 if (file->type == psiconv_word_file)
462 psiconv_free_word_f((psiconv_word_f) file->file); 616 psiconv_free_word_f((psiconv_word_f) file->file);
617 else if (file->type == psiconv_texted_file)
618 psiconv_free_texted_f((psiconv_texted_f) file->file);
619 else if (file->type == psiconv_mbm_file)
620 psiconv_free_mbm_f((psiconv_mbm_f) file->file);
621 else if (file->type == psiconv_sketch_file)
622 psiconv_free_sketch_f((psiconv_sketch_f) file->file);
623 else if (file->type == psiconv_clipart_file)
624 psiconv_free_clipart_f((psiconv_clipart_f) file->file);
463 free(file); 625 free(file);
464 } 626 }
465} 627}

Legend:
Removed from v.2  
changed lines
  Added in v.69

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