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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 56 - (hide annotations)
Sun Dec 10 15:44:40 2000 UTC (23 years, 3 months ago) by frodo
File MIME type: text/plain
File size: 15382 byte(s)
(Frodo) Changed all struct definition to make them C++ compatible

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

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