/[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 21 - (show annotations)
Wed Oct 27 15:30:34 1999 UTC (20 years, 3 months ago) by frodo
File MIME type: text/plain
File size: 14230 byte(s)
(Frodo) Added getopt_long support for systems without it, as well as a minor
        typo.

1 /*
2 data.c - Part of psiconv, a PSION 5 file formats converter
3 Copyright (c) 1999 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 #include "general.h"
27
28 static psiconv_color clone_color(psiconv_color color);
29 static psiconv_font clone_font(psiconv_font font);
30 static psiconv_border clone_border(psiconv_border border);
31 static psiconv_bullet clone_bullet(psiconv_bullet bullet);
32 static psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs);
33 static void psiconv_free_style_aux(void *style);
34 static void psiconv_free_in_line_layout_aux(void * layout);
35 static void psiconv_free_paragraph_aux(void * paragraph);
36 static void psiconv_free_paint_data_section_aux(void * section);
37
38 psiconv_character_layout psiconv_basic_character_layout(void)
39 {
40 /* Make the structures static, to oblige IRIX */
41 static struct psiconv_color black =
42 {
43 0x00, /* red */
44 0x00, /* green */
45 0x00, /* blue */
46 };
47 static struct psiconv_color white =
48 {
49 0xff, /* red */
50 0xff, /* green */
51 0xff, /* blue */
52 };
53 static struct psiconv_font font =
54 {
55 "Times New Roman", /* name */
56 3 /* screenfont */
57 };
58 struct psiconv_character_layout cl =
59 {
60 &black, /* color */
61 &white, /* back_color */
62 10.0, /* font_size */
63 psiconv_bool_false, /* italic */
64 psiconv_bool_false, /* bold */
65 psiconv_normalscript, /* super_sub */
66 psiconv_bool_false, /* underline */
67 psiconv_bool_false, /* strike_out */
68 font, /* font */
69 };
70
71 return psiconv_clone_character_layout(&cl);
72 }
73
74 psiconv_paragraph_layout psiconv_basic_paragraph_layout(void)
75 {
76 static struct psiconv_font font =
77 {
78 "Times New Roman", /* name */
79 2 /* screenfont */
80 };
81 static struct psiconv_color black =
82 {
83 0x00, /* red */
84 0x00, /* green */
85 0x00, /* blue */
86 };
87 static struct psiconv_color white =
88 {
89 0xff, /* red */
90 0xff, /* green */
91 0xff, /* blue */
92 };
93 static struct psiconv_border no_border =
94 {
95 psiconv_border_none, /* kind */
96 1, /* thickness */
97 &black /* color */
98 };
99 static struct psiconv_bullet bullet =
100 {
101 psiconv_bool_false, /* on */
102 10.0, /* font_size */
103 0x95, /* character */
104 psiconv_bool_true, /* indent */
105 &black, /* color */
106 &font, /* font */
107 };
108 static struct psiconv_all_tabs tabs =
109 {
110 0.64, /* normal */
111 NULL /* kind */
112 };
113 struct psiconv_paragraph_layout pl =
114 {
115 &white, /* back_color */
116 0.0, /* indent_left */
117 0.0, /* indent_right */
118 0.0, /* indent_first */
119 psiconv_justify_left, /* justify_hor */
120 psiconv_justify_middle,/* justify_ver */
121 0.0, /* interline */
122 psiconv_bool_false, /* interline_exact */
123 0.0, /* top_space */
124 0.0, /* bottom_space */
125 psiconv_bool_false, /* on_one_page */
126 psiconv_bool_false, /* together_with */
127 psiconv_bool_false, /* on_next_page */
128 psiconv_bool_false, /* no_widow_protection */
129 0.0, /* left_margin */
130 &bullet, /* bullet */
131 &no_border, /* left_border */
132 &no_border, /* right_border */
133 &no_border, /* top_border */
134 &no_border, /* bottom_border */
135 &tabs, /* tabs */
136 };
137 psiconv_paragraph_layout res;
138
139 pl.tabs->extras = psiconv_list_new(sizeof(struct psiconv_tab));
140 res = psiconv_clone_paragraph_layout(&pl);
141 psiconv_list_free(pl.tabs->extras);
142 return res;
143 }
144
145 psiconv_color clone_color(psiconv_color color)
146 {
147 psiconv_color result;
148 result = malloc(sizeof(*result));
149 *result = *color;
150 return result;
151 }
152
153 psiconv_font clone_font(psiconv_font font)
154 {
155 psiconv_font result;
156 result = malloc(sizeof(*result));
157 *result = *font;
158 result->name = strdup(result->name);
159 return result;
160 }
161
162 psiconv_border clone_border(psiconv_border border)
163 {
164 psiconv_border result;
165 result = malloc(sizeof(*result));
166 *result = *border;
167 result->color = clone_color(result->color);
168 return result;
169 }
170
171 psiconv_bullet clone_bullet(psiconv_bullet bullet)
172 {
173 psiconv_bullet result;
174 result = malloc(sizeof(*result));
175 *result = *bullet;
176 result->font = clone_font(result->font);
177 result->color = clone_color(result->color);
178 return result;
179 }
180
181 psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs)
182 {
183 psiconv_all_tabs result;
184 result = malloc(sizeof(*result));
185 *result = *all_tabs;
186 result->extras = psiconv_list_clone(result->extras);
187 return result;
188 }
189
190 psiconv_character_layout psiconv_clone_character_layout
191 (psiconv_character_layout ls)
192 {
193 psiconv_character_layout result;
194
195 result = malloc(sizeof(*result));
196 *result = *ls;
197 result->color = clone_color(result->color);
198 result->back_color = clone_color(result->back_color);
199 result->font = clone_font(result->font);
200 return result;
201 }
202
203 psiconv_paragraph_layout psiconv_clone_paragraph_layout
204 (psiconv_paragraph_layout ls)
205 {
206 psiconv_paragraph_layout result;
207
208 result = malloc(sizeof(*result));
209 *result = *ls;
210 result->back_color = clone_color(result->back_color);
211 result->bullet = clone_bullet(result->bullet);
212 result->left_border = clone_border(result->left_border);
213 result->right_border = clone_border(result->right_border);
214 result->top_border = clone_border(result->top_border);
215 result->bottom_border = clone_border(result->bottom_border);
216 result->tabs = clone_all_tabs(result->tabs);
217 return result;
218 }
219
220 psiconv_word_style psiconv_get_style (psiconv_word_styles_section ss, int nr)
221 {
222 if (nr == 0)
223 return ss->normal;
224 else
225 return psiconv_list_get(ss->styles,0xff - nr);
226 }
227
228 void psiconv_free_color (psiconv_color color)
229 {
230 if (color)
231 free(color);
232 }
233
234 void psiconv_free_border(psiconv_border border)
235 {
236 if (border) {
237 psiconv_free_color(border->color);
238 free(border);
239 }
240 }
241
242 void psiconv_free_font(psiconv_font font)
243 {
244 if (font) {
245 if (font->name)
246 free(font->name);
247 free(font);
248 }
249 }
250
251 void psiconv_free_bullet(psiconv_bullet bullet)
252 {
253 if (bullet) {
254 psiconv_free_color(bullet->color);
255 psiconv_free_font(bullet->font);
256 free(bullet);
257 }
258 }
259
260 void psiconv_free_character_layout(psiconv_character_layout layout)
261 {
262 if (layout) {
263 psiconv_free_color(layout->color);
264 psiconv_free_color(layout->back_color);
265 psiconv_free_font(layout->font);
266 free(layout);
267 }
268 }
269
270 void psiconv_free_tab(psiconv_tab tab)
271 {
272 if (tab)
273 free(tab);
274 }
275
276 void psiconv_free_tabs(psiconv_all_tabs tabs)
277 {
278 if (tabs) {
279 psiconv_list_free(tabs->extras);
280 free(tabs);
281 }
282 }
283
284 void psiconv_free_paragraph_layout(psiconv_paragraph_layout layout)
285 {
286 if (layout) {
287 psiconv_free_color(layout->back_color);
288 psiconv_free_bullet(layout->bullet);
289 psiconv_free_border(layout->left_border);
290 psiconv_free_border(layout->right_border);
291 psiconv_free_border(layout->top_border);
292 psiconv_free_border(layout->bottom_border);
293 psiconv_free_tabs(layout->tabs);
294 free(layout);
295 }
296 }
297
298 void psiconv_free_style_aux(void *style)
299 {
300 if(((psiconv_word_style) style)->name)
301 free(((psiconv_word_style) style)->name);
302 psiconv_free_character_layout(((psiconv_word_style) style)->character);
303 psiconv_free_paragraph_layout(((psiconv_word_style) style)->paragraph);
304 }
305
306 void psiconv_free_word_style(psiconv_word_style style)
307 {
308 if (style) {
309 psiconv_free_style_aux(style);
310 free(style);
311 }
312 }
313
314 void psiconv_free_word_styles_section(psiconv_word_styles_section styles)
315 {
316 if (styles) {
317 psiconv_free_word_style(styles->normal);
318 if (styles->styles)
319 psiconv_list_free_el(styles->styles,psiconv_free_style_aux);
320 }
321 }
322
323 void psiconv_free_header_section(psiconv_header_section header)
324 {
325 if (header)
326 free(header);
327 }
328
329 void psiconv_free_section_table_entry(psiconv_section_table_entry entry)
330 {
331 if (entry)
332 free(entry);
333 }
334
335 void psiconv_free_section_table_section(psiconv_section_table_section section)
336 {
337 if (section)
338 psiconv_list_free(section);
339 }
340
341 void psiconv_free_application_id_section(psiconv_application_id_section section)
342 {
343 if (section) {
344 if (section->name)
345 free(section->name);
346 free(section);
347 }
348 }
349
350 void psiconv_free_in_line_layout_aux(void * layout)
351 {
352 psiconv_free_character_layout(((psiconv_in_line_layout) layout)->layout);
353 }
354
355 void psiconv_free_in_line_layout(psiconv_in_line_layout layout)
356 {
357 if (layout) {
358 psiconv_free_in_line_layout_aux(layout);
359 free(layout);
360 }
361 }
362
363 void psiconv_free_in_line_layouts(psiconv_in_line_layouts layouts)
364 {
365 if (layouts)
366 psiconv_list_free_el(layouts,&psiconv_free_in_line_layout_aux);
367 }
368
369 void psiconv_free_replacement(psiconv_replacement replacement)
370 {
371 if (replacement)
372 free(replacement);
373 }
374
375 void psiconv_free_replacements(psiconv_replacements replacements)
376 {
377 if (replacements)
378 psiconv_list_free(replacements);
379 }
380
381 void psiconv_free_paragraph_aux(void * paragraph)
382 {
383 if(((psiconv_paragraph) paragraph)->text)
384 free(((psiconv_paragraph) paragraph)->text);
385 psiconv_free_character_layout(((psiconv_paragraph) paragraph)
386 ->base_character);
387 psiconv_free_paragraph_layout(((psiconv_paragraph) paragraph)
388 ->base_paragraph);
389 psiconv_free_in_line_layouts(((psiconv_paragraph) paragraph)
390 ->in_lines);
391 psiconv_free_replacements(((psiconv_paragraph) paragraph)
392 ->replacements);
393 }
394
395 void psiconv_free_paragraph(psiconv_paragraph paragraph)
396 {
397 if (paragraph) {
398 psiconv_free_paragraph_aux(paragraph);
399 free(paragraph);
400 }
401 }
402
403 void psiconv_free_text_and_layout(psiconv_text_and_layout text)
404 {
405 if (text)
406 psiconv_list_free_el(text,&psiconv_free_paragraph_aux);
407 }
408
409 void psiconv_free_texted_section(psiconv_texted_section section)
410 {
411 if (section) {
412 psiconv_free_text_and_layout(section->paragraphs);
413 free(section);
414 }
415 }
416
417 void psiconv_free_page_header(psiconv_page_header header)
418 {
419 if (header) {
420 psiconv_free_character_layout(header->base_character_layout);
421 psiconv_free_paragraph_layout(header->base_paragraph_layout);
422 psiconv_free_texted_section(header->text);
423 free(header);
424 }
425 }
426
427 void psiconv_free_page_layout_section(psiconv_page_layout_section section)
428 {
429 if (section) {
430 psiconv_free_page_header(section->header);
431 psiconv_free_page_header(section->footer);
432 free(section);
433 }
434 }
435
436 void psiconv_free_word_status_section(psiconv_word_status_section section)
437 {
438 if (section)
439 free(section);
440 }
441
442 void psiconv_free_word_f(psiconv_word_f file)
443 {
444 if (file) {
445 psiconv_free_page_layout_section(file->page_sec);
446 psiconv_free_text_and_layout(file->paragraphs);
447 psiconv_free_word_status_section(file->status_sec);
448 psiconv_free_word_styles_section(file->styles_sec);
449 free(file);
450 }
451 }
452
453 void psiconv_free_texted_f(psiconv_texted_f file)
454 {
455 if (file) {
456 psiconv_free_page_layout_section(file->page_sec);
457 psiconv_free_texted_section(file->texted_sec);
458 free(file);
459 }
460 }
461
462 void psiconv_free_paint_data_section_aux(void * section)
463 {
464 if (((psiconv_paint_data_section) section)->red)
465 free(((psiconv_paint_data_section)section) -> red);
466 if (((psiconv_paint_data_section) section)->green)
467 free(((psiconv_paint_data_section)section) -> green);
468 if (((psiconv_paint_data_section) section)->blue)
469 free(((psiconv_paint_data_section)section) -> blue);
470 }
471
472 void psiconv_free_paint_data_section(psiconv_paint_data_section section)
473 {
474 if (section) {
475 psiconv_free_paint_data_section_aux(section);
476 free(section);
477 }
478 }
479
480 void psiconv_free_pictures(psiconv_pictures section)
481 {
482 if (section)
483 psiconv_list_free_el(section,&psiconv_free_paint_data_section_aux);
484 }
485
486 void psiconv_free_mbm_jumptable_section (psiconv_mbm_jumptable_section section)
487 {
488 if (section)
489 psiconv_list_free(section);
490 }
491
492 void psiconv_free_mbm_f(psiconv_mbm_f file)
493 {
494 if (file) {
495 psiconv_free_pictures(file->sections);
496 free(file);
497 }
498 }
499
500 void psiconv_free_file(psiconv_file file)
501 {
502 if (file) {
503 if (file->type == psiconv_word_file)
504 psiconv_free_word_f((psiconv_word_f) file->file);
505 else if (file->type == psiconv_texted_file)
506 psiconv_free_texted_f((psiconv_texted_f) file->file);
507 else if (file->type == psiconv_mbm_file)
508 psiconv_free_mbm_f((psiconv_mbm_f) file->file);
509 free(file);
510 }
511 }

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