/[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 42 Revision 63
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.
20#include "config.h" 20#include "config.h"
21#include "compat.h" 21#include "compat.h"
22#include <stdlib.h> 22#include <stdlib.h>
23#include <string.h> 23#include <string.h>
24#include "data.h" 24#include "data.h"
25#include "list.h"
26#include "general.h"
27 25
28static psiconv_color clone_color(psiconv_color color); 26static psiconv_color clone_color(psiconv_color color);
29static psiconv_font clone_font(psiconv_font font); 27static psiconv_font clone_font(psiconv_font font);
30static psiconv_border clone_border(psiconv_border border); 28static psiconv_border clone_border(psiconv_border border);
31static psiconv_bullet clone_bullet(psiconv_bullet bullet); 29static psiconv_bullet clone_bullet(psiconv_bullet bullet);
37static void psiconv_free_clipart_section_aux(void * section); 35static void psiconv_free_clipart_section_aux(void * section);
38 36
39psiconv_character_layout psiconv_basic_character_layout(void) 37psiconv_character_layout psiconv_basic_character_layout(void)
40{ 38{
41 /* Make the structures static, to oblige IRIX */ 39 /* Make the structures static, to oblige IRIX */
42 static struct psiconv_color black = 40 static struct psiconv_color_s black =
43 { 41 {
44 0x00, /* red */ 42 0x00, /* red */
45 0x00, /* green */ 43 0x00, /* green */
46 0x00, /* blue */ 44 0x00, /* blue */
47 }; 45 };
48 static struct psiconv_color white = 46 static struct psiconv_color_s white =
49 { 47 {
50 0xff, /* red */ 48 0xff, /* red */
51 0xff, /* green */ 49 0xff, /* green */
52 0xff, /* blue */ 50 0xff, /* blue */
53 }; 51 };
54 static struct psiconv_font font = 52 static struct psiconv_font_s font =
55 { 53 {
56 "Times New Roman", /* name */ 54 "Times New Roman", /* name */
57 3 /* screenfont */ 55 3 /* screenfont */
58 }; 56 };
59 struct psiconv_character_layout cl = 57 struct psiconv_character_layout_s cl =
60 { 58 {
61 &black, /* color */ 59 &black, /* color */
62 &white, /* back_color */ 60 &white, /* back_color */
63 10.0, /* font_size */ 61 10.0, /* font_size */
64 psiconv_bool_false, /* italic */ 62 psiconv_bool_false, /* italic */
72 return psiconv_clone_character_layout(&cl); 70 return psiconv_clone_character_layout(&cl);
73} 71}
74 72
75psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) 73psiconv_paragraph_layout psiconv_basic_paragraph_layout(void)
76{ 74{
77 static struct psiconv_font font = 75 static struct psiconv_font_s font =
78 { 76 {
79 "Times New Roman", /* name */ 77 "Times New Roman", /* name */
80 2 /* screenfont */ 78 2 /* screenfont */
81 }; 79 };
82 static struct psiconv_color black = 80 static struct psiconv_color_s black =
83 { 81 {
84 0x00, /* red */ 82 0x00, /* red */
85 0x00, /* green */ 83 0x00, /* green */
86 0x00, /* blue */ 84 0x00, /* blue */
87 }; 85 };
88 static struct psiconv_color white = 86 static struct psiconv_color_s white =
89 { 87 {
90 0xff, /* red */ 88 0xff, /* red */
91 0xff, /* green */ 89 0xff, /* green */
92 0xff, /* blue */ 90 0xff, /* blue */
93 }; 91 };
94 static struct psiconv_border no_border = 92 static struct psiconv_border_s no_border =
95 { 93 {
96 psiconv_border_none, /* kind */ 94 psiconv_border_none, /* kind */
97 1, /* thickness */ 95 1, /* thickness */
98 &black /* color */ 96 &black /* color */
99 }; 97 };
100 static struct psiconv_bullet bullet = 98 static struct psiconv_bullet_s bullet =
101 { 99 {
102 psiconv_bool_false, /* on */ 100 psiconv_bool_false, /* on */
103 10.0, /* font_size */ 101 10.0, /* font_size */
104 0x95, /* character */ 102 0x95, /* character */
105 psiconv_bool_true, /* indent */ 103 psiconv_bool_true, /* indent */
106 &black, /* color */ 104 &black, /* color */
107 &font, /* font */ 105 &font, /* font */
108 }; 106 };
109 static struct psiconv_all_tabs tabs = 107 static struct psiconv_all_tabs_s tabs =
110 { 108 {
111 0.64, /* normal */ 109 0.64, /* normal */
112 NULL /* kind */ 110 NULL /* kind */
113 }; 111 };
114 struct psiconv_paragraph_layout pl = 112 struct psiconv_paragraph_layout_s pl =
115 { 113 {
116 &white, /* back_color */ 114 &white, /* back_color */
117 0.0, /* indent_left */ 115 0.0, /* indent_left */
118 0.0, /* indent_right */ 116 0.0, /* indent_right */
119 0.0, /* indent_first */ 117 0.0, /* indent_first */
135 &no_border, /* bottom_border */ 133 &no_border, /* bottom_border */
136 &tabs, /* tabs */ 134 &tabs, /* tabs */
137 }; 135 };
138 psiconv_paragraph_layout res; 136 psiconv_paragraph_layout res;
139 137
140 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;
141 res = psiconv_clone_paragraph_layout(&pl); 140 res = psiconv_clone_paragraph_layout(&pl);
142 psiconv_list_free(pl.tabs->extras); 141 psiconv_list_free(pl.tabs->extras);
143 return res; 142 return res;
144} 143}
145 144
146psiconv_color clone_color(psiconv_color color) 145psiconv_color clone_color(psiconv_color color)
147{ 146{
148 psiconv_color result; 147 psiconv_color result;
149 result = malloc(sizeof(*result)); 148 if (!(result = malloc(sizeof(*result))))
149 return NULL;
150 *result = *color; 150 *result = *color;
151 return result; 151 return result;
152} 152}
153 153
154psiconv_font clone_font(psiconv_font font) 154psiconv_font clone_font(psiconv_font font)
155{ 155{
156 psiconv_font result; 156 psiconv_font result;
157 result = malloc(sizeof(*result)); 157 if(!(result = malloc(sizeof(*result))))
158 goto ERROR1;
158 *result = *font; 159 *result = *font;
159 result->name = strdup(result->name); 160 if (!(result->name = strdup(result->name)))
161 goto ERROR2;
160 return result; 162 return result;
163ERROR2:
164 free(result);
165ERROR1:
166 return NULL;
161} 167}
162 168
163psiconv_border clone_border(psiconv_border border) 169psiconv_border clone_border(psiconv_border border)
164{ 170{
165 psiconv_border result; 171 psiconv_border result;
166 result = malloc(sizeof(*result)); 172 if (!(result = malloc(sizeof(*result))))
173 goto ERROR1;
167 *result = *border; 174 *result = *border;
168 result->color = clone_color(result->color); 175 if(!(result->color = clone_color(result->color)))
176 goto ERROR2;
169 return result; 177 return result;
178ERROR2:
179 free(result);
180ERROR1:
181 return NULL;
170} 182}
171 183
172psiconv_bullet clone_bullet(psiconv_bullet bullet) 184psiconv_bullet clone_bullet(psiconv_bullet bullet)
173{ 185{
174 psiconv_bullet result; 186 psiconv_bullet result;
175 result = malloc(sizeof(*result)); 187 if (!(result = malloc(sizeof(*result))))
188 goto ERROR1;
176 *result = *bullet; 189 *result = *bullet;
177 result->font = clone_font(result->font); 190 if (!(result->font = clone_font(result->font)))
191 goto ERROR2;
178 result->color = clone_color(result->color); 192 if (!(result->color = clone_color(result->color)))
193 goto ERROR3;
179 return result; 194 return result;
195ERROR3:
196 psiconv_free_font(result->font);
197ERROR2:
198 free(result);
199ERROR1:
200 return NULL;
180} 201}
181 202
182psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs) 203psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs)
183{ 204{
184 psiconv_all_tabs result; 205 psiconv_all_tabs result;
185 result = malloc(sizeof(*result)); 206 if (!(result = malloc(sizeof(*result))))
207 goto ERROR1;
186 *result = *all_tabs; 208 *result = *all_tabs;
187 result->extras = psiconv_list_clone(result->extras); 209 if (!(result->extras = psiconv_list_clone(result->extras)))
210 goto ERROR2;
188 return result; 211 return result;
212ERROR2:
213 free(result);
214ERROR1:
215 return NULL;
189} 216}
190 217
191psiconv_character_layout psiconv_clone_character_layout 218psiconv_character_layout psiconv_clone_character_layout
192 (psiconv_character_layout ls) 219 (psiconv_character_layout ls)
193{ 220{
194 psiconv_character_layout result; 221 psiconv_character_layout result;
195 222
196 result = malloc(sizeof(*result)); 223 if (!(result = malloc(sizeof(*result))))
224 goto ERROR1;
197 *result = *ls; 225 *result = *ls;
198 result->color = clone_color(result->color); 226 if (!(result->color = clone_color(result->color)))
227 goto ERROR2;
199 result->back_color = clone_color(result->back_color); 228 if (!(result->back_color = clone_color(result->back_color)))
229 goto ERROR3;
200 result->font = clone_font(result->font); 230 if (!(result->font = clone_font(result->font)))
231 goto ERROR4;
201 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;
202} 241}
203 242
204psiconv_paragraph_layout psiconv_clone_paragraph_layout 243psiconv_paragraph_layout psiconv_clone_paragraph_layout
205 (psiconv_paragraph_layout ls) 244 (psiconv_paragraph_layout ls)
206{ 245{
207 psiconv_paragraph_layout result; 246 psiconv_paragraph_layout result;
208 247
209 result = malloc(sizeof(*result)); 248 if (!(result = malloc(sizeof(*result))))
249 goto ERROR1;
210 *result = *ls; 250 *result = *ls;
211 result->back_color = clone_color(result->back_color); 251 if (!(result->back_color = clone_color(result->back_color)))
252 goto ERROR2;
212 result->bullet = clone_bullet(result->bullet); 253 if (!(result->bullet = clone_bullet(result->bullet)))
254 goto ERROR3;
213 result->left_border = clone_border(result->left_border); 255 if (!(result->left_border = clone_border(result->left_border)))
256 goto ERROR4;
214 result->right_border = clone_border(result->right_border); 257 if (!(result->right_border = clone_border(result->right_border)))
258 goto ERROR5;
215 result->top_border = clone_border(result->top_border); 259 if (!(result->top_border = clone_border(result->top_border)))
260 goto ERROR6;
216 result->bottom_border = clone_border(result->bottom_border); 261 if (!(result->bottom_border = clone_border(result->bottom_border)))
262 goto ERROR7;
217 result->tabs = clone_all_tabs(result->tabs); 263 if (!(result->tabs = clone_all_tabs(result->tabs)))
264 goto ERROR8;
218 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;
219} 282}
220 283
221psiconv_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)
222{ 285{
223 if (nr == 0) 286 if (nr == 0)

Legend:
Removed from v.42  
changed lines
  Added in v.63

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