/[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 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);
34static void psiconv_free_paint_data_section_aux(void * section);
35static void psiconv_free_clipart_section_aux(void * section);
35 36
36psiconv_character_layout psiconv_basic_character_layout(void) 37psiconv_character_layout psiconv_basic_character_layout(void)
37{ 38{
39 /* Make the structures static, to oblige IRIX */
38 struct psiconv_color black = 40 static struct psiconv_color_s black =
39 { 41 {
40 0x00, /* red */ 42 0x00, /* red */
41 0x00, /* green */ 43 0x00, /* green */
42 0x00, /* blue */ 44 0x00, /* blue */
43 }; 45 };
44 struct psiconv_color white = 46 static struct psiconv_color_s white =
45 { 47 {
46 0xff, /* red */ 48 0xff, /* red */
47 0xff, /* green */ 49 0xff, /* green */
48 0xff, /* blue */ 50 0xff, /* blue */
49 }; 51 };
52 static struct psiconv_font_s font =
53 {
54 "Times New Roman", /* name */
55 3 /* screenfont */
56 };
50 struct psiconv_character_layout cl = 57 struct psiconv_character_layout_s cl =
51 { 58 {
52 &black, /* color */ 59 &black, /* color */
53 &white, /* back_color */ 60 &white, /* back_color */
54 10.0, /* font_size */ 61 10.0, /* font_size */
55 psiconv_bool_false, /* italic */ 62 psiconv_bool_false, /* italic */
56 psiconv_bool_false, /* bold */ 63 psiconv_bool_false, /* bold */
57 psiconv_normalscript, /* super_sub */ 64 psiconv_normalscript, /* super_sub */
58 psiconv_bool_false, /* underline */ 65 psiconv_bool_false, /* underline */
59 psiconv_bool_false, /* strike_out */ 66 psiconv_bool_false, /* strike_out */
60 NULL, /* font */ 67 &font, /* font */
61 }; 68 };
62 69
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); 70 return psiconv_clone_character_layout(&cl);
75} 71}
76 72
77psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) 73psiconv_paragraph_layout psiconv_basic_paragraph_layout(void)
78{ 74{
79 char base_font[] = "Times New Roman";
80
81 struct psiconv_font font = 75 static struct psiconv_font_s font =
82 { 76 {
83 base_font, /* name */ 77 "Times New Roman", /* name */
84 2 /* screenfont */ 78 2 /* screenfont */
85 }; 79 };
86 struct psiconv_color black = 80 static struct psiconv_color_s black =
87 { 81 {
88 0x00, /* red */ 82 0x00, /* red */
89 0x00, /* green */ 83 0x00, /* green */
90 0x00, /* blue */ 84 0x00, /* blue */
91 }; 85 };
92 struct psiconv_color white = 86 static struct psiconv_color_s white =
93 { 87 {
94 0xff, /* red */ 88 0xff, /* red */
95 0xff, /* green */ 89 0xff, /* green */
96 0xff, /* blue */ 90 0xff, /* blue */
97 }; 91 };
98 struct psiconv_border no_border = 92 static struct psiconv_border_s no_border =
99 { 93 {
100 psiconv_border_none, /* kind */ 94 psiconv_border_none, /* kind */
101 1, /* thickness */ 95 1, /* thickness */
102 &black /* color */ 96 &black /* color */
103 }; 97 };
104 struct psiconv_bullet bullet = 98 static struct psiconv_bullet_s bullet =
105 { 99 {
106 psiconv_bool_false, /* on */ 100 psiconv_bool_false, /* on */
107 10.0, /* font_size */ 101 10.0, /* font_size */
108 0x95, /* character */ 102 0x95, /* character */
109 psiconv_bool_true, /* indent */ 103 psiconv_bool_true, /* indent */
110 &black, /* color */ 104 &black, /* color */
111 &font, /* font */ 105 &font, /* font */
112 }; 106 };
113 struct psiconv_all_tabs tabs = 107 static struct psiconv_all_tabs_s tabs =
114 { 108 {
115 0.64, /* normal */ 109 0.64, /* normal */
116 NULL /* kind */ 110 NULL /* kind */
117 }; 111 };
118 struct psiconv_paragraph_layout pl = 112 struct psiconv_paragraph_layout_s pl =
119 { 113 {
120 &white, /* back_color */ 114 &white, /* back_color */
121 0.0, /* indent_left */ 115 0.0, /* indent_left */
122 0.0, /* indent_right */ 116 0.0, /* indent_right */
123 0.0, /* indent_first */ 117 0.0, /* indent_first */
139 &no_border, /* bottom_border */ 133 &no_border, /* bottom_border */
140 &tabs, /* tabs */ 134 &tabs, /* tabs */
141 }; 135 };
142 psiconv_paragraph_layout res; 136 psiconv_paragraph_layout res;
143 137
144 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;
145 res = psiconv_clone_paragraph_layout(&pl); 140 res = psiconv_clone_paragraph_layout(&pl);
146 psiconv_list_free(pl.tabs->extras); 141 psiconv_list_free(pl.tabs->extras);
147 return res; 142 return res;
148} 143}
149 144
150psiconv_color clone_color(psiconv_color color) 145psiconv_color clone_color(psiconv_color color)
151{ 146{
152 psiconv_color result; 147 psiconv_color result;
153 result = malloc(sizeof(*result)); 148 if (!(result = malloc(sizeof(*result))))
149 return NULL;
154 *result = *color; 150 *result = *color;
155 return result; 151 return result;
156} 152}
157 153
158psiconv_font clone_font(psiconv_font font) 154psiconv_font clone_font(psiconv_font font)
159{ 155{
160 psiconv_font result; 156 psiconv_font result;
161 result = malloc(sizeof(*result)); 157 if(!(result = malloc(sizeof(*result))))
158 goto ERROR1;
162 *result = *font; 159 *result = *font;
163 result->name = strdup(result->name); 160 if (!(result->name = strdup(result->name)))
161 goto ERROR2;
164 return result; 162 return result;
163ERROR2:
164 free(result);
165ERROR1:
166 return NULL;
165} 167}
166 168
167psiconv_border clone_border(psiconv_border border) 169psiconv_border clone_border(psiconv_border border)
168{ 170{
169 psiconv_border result; 171 psiconv_border result;
170 result = malloc(sizeof(*result)); 172 if (!(result = malloc(sizeof(*result))))
173 goto ERROR1;
171 *result = *border; 174 *result = *border;
172 result->color = clone_color(result->color); 175 if(!(result->color = clone_color(result->color)))
176 goto ERROR2;
173 return result; 177 return result;
178ERROR2:
179 free(result);
180ERROR1:
181 return NULL;
174} 182}
175 183
176psiconv_bullet clone_bullet(psiconv_bullet bullet) 184psiconv_bullet clone_bullet(psiconv_bullet bullet)
177{ 185{
178 psiconv_bullet result; 186 psiconv_bullet result;
179 result = malloc(sizeof(*result)); 187 if (!(result = malloc(sizeof(*result))))
188 goto ERROR1;
180 *result = *bullet; 189 *result = *bullet;
181 result->font = clone_font(result->font); 190 if (!(result->font = clone_font(result->font)))
191 goto ERROR2;
182 result->color = clone_color(result->color); 192 if (!(result->color = clone_color(result->color)))
193 goto ERROR3;
183 return result; 194 return result;
195ERROR3:
196 psiconv_free_font(result->font);
197ERROR2:
198 free(result);
199ERROR1:
200 return NULL;
184} 201}
185 202
186psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs) 203psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs)
187{ 204{
188 psiconv_all_tabs result; 205 psiconv_all_tabs result;
189 result = malloc(sizeof(*result)); 206 if (!(result = malloc(sizeof(*result))))
207 goto ERROR1;
190 *result = *all_tabs; 208 *result = *all_tabs;
191 result->extras = psiconv_list_clone(result->extras); 209 if (!(result->extras = psiconv_list_clone(result->extras)))
210 goto ERROR2;
192 return result; 211 return result;
212ERROR2:
213 free(result);
214ERROR1:
215 return NULL;
193} 216}
194 217
195psiconv_character_layout psiconv_clone_character_layout 218psiconv_character_layout psiconv_clone_character_layout
196 (psiconv_character_layout ls) 219 (psiconv_character_layout ls)
197{ 220{
198 psiconv_character_layout result; 221 psiconv_character_layout result;
199 222
200 result = malloc(sizeof(*result)); 223 if (!(result = malloc(sizeof(*result))))
224 goto ERROR1;
201 *result = *ls; 225 *result = *ls;
202 result->color = clone_color(result->color); 226 if (!(result->color = clone_color(result->color)))
227 goto ERROR2;
203 result->back_color = clone_color(result->back_color); 228 if (!(result->back_color = clone_color(result->back_color)))
229 goto ERROR3;
204 result->font = clone_font(result->font); 230 if (!(result->font = clone_font(result->font)))
231 goto ERROR4;
205 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;
206} 241}
207 242
208psiconv_paragraph_layout psiconv_clone_paragraph_layout 243psiconv_paragraph_layout psiconv_clone_paragraph_layout
209 (psiconv_paragraph_layout ls) 244 (psiconv_paragraph_layout ls)
210{ 245{
211 psiconv_paragraph_layout result; 246 psiconv_paragraph_layout result;
212 247
213 result = malloc(sizeof(*result)); 248 if (!(result = malloc(sizeof(*result))))
249 goto ERROR1;
214 *result = *ls; 250 *result = *ls;
215 result->back_color = clone_color(result->back_color); 251 if (!(result->back_color = clone_color(result->back_color)))
252 goto ERROR2;
216 result->bullet = clone_bullet(result->bullet); 253 if (!(result->bullet = clone_bullet(result->bullet)))
254 goto ERROR3;
217 result->left_border = clone_border(result->left_border); 255 if (!(result->left_border = clone_border(result->left_border)))
256 goto ERROR4;
218 result->right_border = clone_border(result->right_border); 257 if (!(result->right_border = clone_border(result->right_border)))
258 goto ERROR5;
219 result->top_border = clone_border(result->top_border); 259 if (!(result->top_border = clone_border(result->top_border)))
260 goto ERROR6;
220 result->bottom_border = clone_border(result->bottom_border); 261 if (!(result->bottom_border = clone_border(result->bottom_border)))
262 goto ERROR7;
221 result->tabs = clone_all_tabs(result->tabs); 263 if (!(result->tabs = clone_all_tabs(result->tabs)))
264 goto ERROR8;
222 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;
223} 282}
224 283
225psiconv_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)
226{ 285{
227 if (nr == 0) 286 if (nr == 0)
453 psiconv_free_word_styles_section(file->styles_sec); 512 psiconv_free_word_styles_section(file->styles_sec);
454 free(file); 513 free(file);
455 } 514 }
456} 515}
457 516
517void psiconv_free_texted_f(psiconv_texted_f file)
518{
519 if (file) {
520 psiconv_free_page_layout_section(file->page_sec);
521 psiconv_free_texted_section(file->texted_sec);
522 free(file);
523 }
524}
525
526void psiconv_free_paint_data_section_aux(void * section)
527{
528 if (((psiconv_paint_data_section) section)->red)
529 free(((psiconv_paint_data_section)section) -> red);
530 if (((psiconv_paint_data_section) section)->green)
531 free(((psiconv_paint_data_section)section) -> green);
532 if (((psiconv_paint_data_section) section)->blue)
533 free(((psiconv_paint_data_section)section) -> blue);
534}
535
536void psiconv_free_paint_data_section(psiconv_paint_data_section section)
537{
538 if (section) {
539 psiconv_free_paint_data_section_aux(section);
540 free(section);
541 }
542}
543
544void psiconv_free_pictures(psiconv_pictures section)
545{
546 if (section)
547 psiconv_list_free_el(section,&psiconv_free_paint_data_section_aux);
548}
549
550void psiconv_free_jumptable_section (psiconv_jumptable_section section)
551{
552 if (section)
553 psiconv_list_free(section);
554}
555
556void psiconv_free_mbm_f(psiconv_mbm_f file)
557{
558 if (file) {
559 psiconv_free_pictures(file->sections);
560 free(file);
561 }
562}
563
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)
581{
582 if (section)
583 free(((psiconv_clipart_section ) section)->picture);
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}
607
458void psiconv_free_file(psiconv_file file) 608void psiconv_free_file(psiconv_file file)
459{ 609{
460 if (file) { 610 if (file) {
461 if (file->type == psiconv_word_file) 611 if (file->type == psiconv_word_file)
462 psiconv_free_word_f((psiconv_word_f) file->file); 612 psiconv_free_word_f((psiconv_word_f) file->file);
613 else if (file->type == psiconv_texted_file)
614 psiconv_free_texted_f((psiconv_texted_f) file->file);
615 else if (file->type == psiconv_mbm_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);
463 free(file); 621 free(file);
464 } 622 }
465} 623}

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

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