/[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 12 Revision 62
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);
35static void psiconv_free_paint_data_section_aux(void * section); 34static void psiconv_free_paint_data_section_aux(void * section);
35static void psiconv_free_clipart_section_aux(void * section);
36 36
37psiconv_character_layout psiconv_basic_character_layout(void) 37psiconv_character_layout psiconv_basic_character_layout(void)
38{ 38{
39 /* Make the structures static, to oblige IRIX */
39 struct psiconv_color black = 40 static struct psiconv_color_s black =
40 { 41 {
41 0x00, /* red */ 42 0x00, /* red */
42 0x00, /* green */ 43 0x00, /* green */
43 0x00, /* blue */ 44 0x00, /* blue */
44 }; 45 };
45 struct psiconv_color white = 46 static struct psiconv_color_s white =
46 { 47 {
47 0xff, /* red */ 48 0xff, /* red */
48 0xff, /* green */ 49 0xff, /* green */
49 0xff, /* blue */ 50 0xff, /* blue */
50 }; 51 };
52 static struct psiconv_font_s font =
53 {
54 "Times New Roman", /* name */
55 3 /* screenfont */
56 };
51 struct psiconv_character_layout cl = 57 struct psiconv_character_layout_s cl =
52 { 58 {
53 &black, /* color */ 59 &black, /* color */
54 &white, /* back_color */ 60 &white, /* back_color */
55 10.0, /* font_size */ 61 10.0, /* font_size */
56 psiconv_bool_false, /* italic */ 62 psiconv_bool_false, /* italic */
57 psiconv_bool_false, /* bold */ 63 psiconv_bool_false, /* bold */
58 psiconv_normalscript, /* super_sub */ 64 psiconv_normalscript, /* super_sub */
59 psiconv_bool_false, /* underline */ 65 psiconv_bool_false, /* underline */
60 psiconv_bool_false, /* strike_out */ 66 psiconv_bool_false, /* strike_out */
61 NULL, /* font */ 67 &font, /* font */
62 }; 68 };
63 69
64 cl.color = malloc(sizeof(*cl.color));
65 cl.color->red = 0x00;
66 cl.color->green = 0x00;
67 cl.color->blue = 0x00;
68 cl.back_color = malloc(sizeof(*cl.color));
69 cl.back_color->red = 0xff;
70 cl.back_color->green = 0xff;
71 cl.back_color->blue = 0xff;
72 cl.font = malloc(sizeof(*cl.font));
73 cl.font->name = strdup("Times New Roman");
74 cl.font->screenfont = 3;
75 return psiconv_clone_character_layout(&cl); 70 return psiconv_clone_character_layout(&cl);
76} 71}
77 72
78psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) 73psiconv_paragraph_layout psiconv_basic_paragraph_layout(void)
79{ 74{
80 char base_font[] = "Times New Roman";
81
82 struct psiconv_font font = 75 static struct psiconv_font_s font =
83 { 76 {
84 base_font, /* name */ 77 "Times New Roman", /* name */
85 2 /* screenfont */ 78 2 /* screenfont */
86 }; 79 };
87 struct psiconv_color black = 80 static struct psiconv_color_s black =
88 { 81 {
89 0x00, /* red */ 82 0x00, /* red */
90 0x00, /* green */ 83 0x00, /* green */
91 0x00, /* blue */ 84 0x00, /* blue */
92 }; 85 };
93 struct psiconv_color white = 86 static struct psiconv_color_s white =
94 { 87 {
95 0xff, /* red */ 88 0xff, /* red */
96 0xff, /* green */ 89 0xff, /* green */
97 0xff, /* blue */ 90 0xff, /* blue */
98 }; 91 };
99 struct psiconv_border no_border = 92 static struct psiconv_border_s no_border =
100 { 93 {
101 psiconv_border_none, /* kind */ 94 psiconv_border_none, /* kind */
102 1, /* thickness */ 95 1, /* thickness */
103 &black /* color */ 96 &black /* color */
104 }; 97 };
105 struct psiconv_bullet bullet = 98 static struct psiconv_bullet_s bullet =
106 { 99 {
107 psiconv_bool_false, /* on */ 100 psiconv_bool_false, /* on */
108 10.0, /* font_size */ 101 10.0, /* font_size */
109 0x95, /* character */ 102 0x95, /* character */
110 psiconv_bool_true, /* indent */ 103 psiconv_bool_true, /* indent */
111 &black, /* color */ 104 &black, /* color */
112 &font, /* font */ 105 &font, /* font */
113 }; 106 };
114 struct psiconv_all_tabs tabs = 107 static struct psiconv_all_tabs_s tabs =
115 { 108 {
116 0.64, /* normal */ 109 0.64, /* normal */
117 NULL /* kind */ 110 NULL /* kind */
118 }; 111 };
119 struct psiconv_paragraph_layout pl = 112 struct psiconv_paragraph_layout_s pl =
120 { 113 {
121 &white, /* back_color */ 114 &white, /* back_color */
122 0.0, /* indent_left */ 115 0.0, /* indent_left */
123 0.0, /* indent_right */ 116 0.0, /* indent_right */
124 0.0, /* indent_first */ 117 0.0, /* indent_first */
140 &no_border, /* bottom_border */ 133 &no_border, /* bottom_border */
141 &tabs, /* tabs */ 134 &tabs, /* tabs */
142 }; 135 };
143 psiconv_paragraph_layout res; 136 psiconv_paragraph_layout res;
144 137
145 pl.tabs->extras = psiconv_list_new(sizeof(struct psiconv_tab)); 138 if (!(pl.tabs->extras = psiconv_list_new(sizeof(struct psiconv_tab_s))))
139 return NULL;
146 res = psiconv_clone_paragraph_layout(&pl); 140 res = psiconv_clone_paragraph_layout(&pl);
147 psiconv_list_free(pl.tabs->extras); 141 psiconv_list_free(pl.tabs->extras);
148 return res; 142 return res;
149} 143}
150 144
151psiconv_color clone_color(psiconv_color color) 145psiconv_color clone_color(psiconv_color color)
152{ 146{
153 psiconv_color result; 147 psiconv_color result;
154 result = malloc(sizeof(*result)); 148 if (!(result = malloc(sizeof(*result))))
149 return NULL;
155 *result = *color; 150 *result = *color;
156 return result; 151 return result;
157} 152}
158 153
159psiconv_font clone_font(psiconv_font font) 154psiconv_font clone_font(psiconv_font font)
160{ 155{
161 psiconv_font result; 156 psiconv_font result;
162 result = malloc(sizeof(*result)); 157 if(!(result = malloc(sizeof(*result))))
158 goto ERROR1;
163 *result = *font; 159 *result = *font;
164 result->name = strdup(result->name); 160 if (!(result->name = strdup(result->name)))
161 goto ERROR2;
165 return result; 162 return result;
163ERROR2:
164 free(result);
165ERROR1:
166 return NULL;
166} 167}
167 168
168psiconv_border clone_border(psiconv_border border) 169psiconv_border clone_border(psiconv_border border)
169{ 170{
170 psiconv_border result; 171 psiconv_border result;
171 result = malloc(sizeof(*result)); 172 if (!(result = malloc(sizeof(*result))))
173 goto ERROR1;
172 *result = *border; 174 *result = *border;
173 result->color = clone_color(result->color); 175 if(!(result->color = clone_color(result->color)))
176 goto ERROR2;
174 return result; 177 return result;
178ERROR2:
179 free(result);
180ERROR1:
181 return NULL;
175} 182}
176 183
177psiconv_bullet clone_bullet(psiconv_bullet bullet) 184psiconv_bullet clone_bullet(psiconv_bullet bullet)
178{ 185{
179 psiconv_bullet result; 186 psiconv_bullet result;
180 result = malloc(sizeof(*result)); 187 if (!(result = malloc(sizeof(*result))))
188 goto ERROR1;
181 *result = *bullet; 189 *result = *bullet;
182 result->font = clone_font(result->font); 190 if (!(result->font = clone_font(result->font)))
191 goto ERROR2;
183 result->color = clone_color(result->color); 192 if (!(result->color = clone_color(result->color)))
193 goto ERROR3;
184 return result; 194 return result;
195ERROR3:
196 psiconv_free_font(result->font);
197ERROR2:
198 free(result);
199ERROR1:
200 return NULL;
185} 201}
186 202
187psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs) 203psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs)
188{ 204{
189 psiconv_all_tabs result; 205 psiconv_all_tabs result;
190 result = malloc(sizeof(*result)); 206 if (!(result = malloc(sizeof(*result))))
207 goto ERROR1;
191 *result = *all_tabs; 208 *result = *all_tabs;
192 result->extras = psiconv_list_clone(result->extras); 209 if (!(result->extras = psiconv_list_clone(result->extras)))
210 goto ERROR2;
193 return result; 211 return result;
212ERROR2:
213 free(result);
214ERROR1:
215 return NULL;
194} 216}
195 217
196psiconv_character_layout psiconv_clone_character_layout 218psiconv_character_layout psiconv_clone_character_layout
197 (psiconv_character_layout ls) 219 (psiconv_character_layout ls)
198{ 220{
199 psiconv_character_layout result; 221 psiconv_character_layout result;
200 222
201 result = malloc(sizeof(*result)); 223 if (!(result = malloc(sizeof(*result))))
224 goto ERROR1;
202 *result = *ls; 225 *result = *ls;
203 result->color = clone_color(result->color); 226 if (!(result->color = clone_color(result->color)))
227 goto ERROR2;
204 result->back_color = clone_color(result->back_color); 228 if (!(result->back_color = clone_color(result->back_color)))
229 goto ERROR3;
205 result->font = clone_font(result->font); 230 if (!(result->font = clone_font(result->font)))
231 goto ERROR4;
206 return result; 232 return result;
233ERROR4:
234 psiconv_free_color(result->back_color);
235ERROR3:
236 psiconv_free_color(result->color);
237ERROR2:
238 free(result);
239ERROR1:
240 return NULL;
207} 241}
208 242
209psiconv_paragraph_layout psiconv_clone_paragraph_layout 243psiconv_paragraph_layout psiconv_clone_paragraph_layout
210 (psiconv_paragraph_layout ls) 244 (psiconv_paragraph_layout ls)
211{ 245{
212 psiconv_paragraph_layout result; 246 psiconv_paragraph_layout result;
213 247
214 result = malloc(sizeof(*result)); 248 if (!(result = malloc(sizeof(*result))))
249 goto ERROR1;
215 *result = *ls; 250 *result = *ls;
216 result->back_color = clone_color(result->back_color); 251 if (!(result->back_color = clone_color(result->back_color)))
252 goto ERROR2;
217 result->bullet = clone_bullet(result->bullet); 253 if (!(result->bullet = clone_bullet(result->bullet)))
254 goto ERROR3;
218 result->left_border = clone_border(result->left_border); 255 if (!(result->left_border = clone_border(result->left_border)))
256 goto ERROR4;
219 result->right_border = clone_border(result->right_border); 257 if (!(result->right_border = clone_border(result->right_border)))
258 goto ERROR5;
220 result->top_border = clone_border(result->top_border); 259 if (!(result->top_border = clone_border(result->top_border)))
260 goto ERROR6;
221 result->bottom_border = clone_border(result->bottom_border); 261 if (!(result->bottom_border = clone_border(result->bottom_border)))
262 goto ERROR7;
222 result->tabs = clone_all_tabs(result->tabs); 263 if (!(result->tabs = clone_all_tabs(result->tabs)))
264 goto ERROR8;
223 return result; 265 return result;
266ERROR8:
267 psiconv_free_border(result->bottom_border);
268ERROR7:
269 psiconv_free_border(result->top_border);
270ERROR6:
271 psiconv_free_border(result->right_border);
272ERROR5:
273 psiconv_free_border(result->left_border);
274ERROR4:
275 psiconv_free_bullet(result->bullet);
276ERROR3:
277 psiconv_free_color(result->back_color);
278ERROR2:
279 free(result);
280ERROR1:
281 return NULL;
224} 282}
225 283
226psiconv_word_style psiconv_get_style (psiconv_word_styles_section ss, int nr) 284psiconv_word_style psiconv_get_style (psiconv_word_styles_section ss, int nr)
227{ 285{
228 if (nr == 0) 286 if (nr == 0)
487{ 545{
488 if (section) 546 if (section)
489 psiconv_list_free_el(section,&psiconv_free_paint_data_section_aux); 547 psiconv_list_free_el(section,&psiconv_free_paint_data_section_aux);
490} 548}
491 549
550void psiconv_free_jumptable_section (psiconv_jumptable_section section)
551{
552 if (section)
553 psiconv_list_free(section);
554}
555
492void psiconv_free_mbm_f(psiconv_mbm_f file) 556void psiconv_free_mbm_f(psiconv_mbm_f file)
493{ 557{
494 if (file) { 558 if (file) {
495 psiconv_free_pictures(file->sections); 559 psiconv_free_pictures(file->sections);
496 free(file); 560 free(file);
497 } 561 }
498} 562}
499 563
500void psiconv_free_mbm_jumptable_section (psiconv_mbm_jumptable_section section) 564void psiconv_free_sketch_section(psiconv_sketch_section sec)
565{
566 if (sec) {
567 psiconv_free_paint_data_section(sec->picture);
568 free(sec);
569 }
570}
571
572void psiconv_free_sketch_f(psiconv_sketch_f file)
573{
574 if (file) {
575 psiconv_free_sketch_section(file->sketch_sec);
576 free(file);
577 }
578}
579
580void psiconv_free_clipart_section_aux(void *section)
501{ 581{
502 if (section) 582 if (section)
503 psiconv_list_free(section); 583 free(((psiconv_clipart_section ) section)->picture);
504} 584}
585
586void psiconv_free_clipart_section(psiconv_clipart_section section)
587{
588 if (section) {
589 psiconv_free_clipart_section_aux(section);
590 free(section);
591 }
592}
593
594void psiconv_free_cliparts(psiconv_cliparts section)
595{
596 if (section)
597 psiconv_list_free_el(section,&psiconv_free_clipart_section_aux);
598}
599
600void psiconv_free_clipart_f(psiconv_clipart_f file)
601{
602 if (file) {
603 psiconv_free_cliparts(file->sections);
604 free(file);
605 }
606}
505 607
506void psiconv_free_file(psiconv_file file) 608void psiconv_free_file(psiconv_file file)
507{ 609{
508 if (file) { 610 if (file) {
509 if (file->type == psiconv_word_file) 611 if (file->type == psiconv_word_file)
510 psiconv_free_word_f((psiconv_word_f) file->file); 612 psiconv_free_word_f((psiconv_word_f) file->file);
511 else if (file->type == psiconv_texted_file) 613 else if (file->type == psiconv_texted_file)
512 psiconv_free_texted_f((psiconv_texted_f) file->file); 614 psiconv_free_texted_f((psiconv_texted_f) file->file);
513 else if (file->type == psiconv_mbm_file) 615 else if (file->type == psiconv_mbm_file)
514 psiconv_free_mbm_f((psiconv_mbm_f) file->file); 616 psiconv_free_mbm_f((psiconv_mbm_f) file->file);
617 else if (file->type == psiconv_sketch_file)
618 psiconv_free_sketch_f((psiconv_sketch_f) file->file);
619 else if (file->type == psiconv_clipart_file)
620 psiconv_free_clipart_f((psiconv_clipart_f) file->file);
515 free(file); 621 free(file);
516 } 622 }
517} 623}

Legend:
Removed from v.12  
changed lines
  Added in v.62

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