/[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 41 - (show annotations)
Fri Dec 3 00:59:12 1999 UTC (24 years, 4 months ago) by frodo
File MIME type: text/plain
File size: 15371 byte(s)
(Frodo) Some base work for ClipArt files

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 static void psiconv_free_clipart_section_aux(psiconv_clipart_section section);
38
39 psiconv_character_layout psiconv_basic_character_layout(void)
40 {
41 /* Make the structures static, to oblige IRIX */
42 static struct psiconv_color black =
43 {
44 0x00, /* red */
45 0x00, /* green */
46 0x00, /* blue */
47 };
48 static struct psiconv_color white =
49 {
50 0xff, /* red */
51 0xff, /* green */
52 0xff, /* blue */
53 };
54 static struct psiconv_font font =
55 {
56 "Times New Roman", /* name */
57 3 /* screenfont */
58 };
59 struct psiconv_character_layout cl =
60 {
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 &font, /* font */
70 };
71
72 return psiconv_clone_character_layout(&cl);
73 }
74
75 psiconv_paragraph_layout psiconv_basic_paragraph_layout(void)
76 {
77 static struct psiconv_font font =
78 {
79 "Times New Roman", /* name */
80 2 /* screenfont */
81 };
82 static struct psiconv_color black =
83 {
84 0x00, /* red */
85 0x00, /* green */
86 0x00, /* blue */
87 };
88 static struct psiconv_color white =
89 {
90 0xff, /* red */
91 0xff, /* green */
92 0xff, /* blue */
93 };
94 static struct psiconv_border no_border =
95 {
96 psiconv_border_none, /* kind */
97 1, /* thickness */
98 &black /* color */
99 };
100 static struct psiconv_bullet bullet =
101 {
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 static struct psiconv_all_tabs tabs =
110 {
111 0.64, /* normal */
112 NULL /* kind */
113 };
114 struct psiconv_paragraph_layout pl =
115 {
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 pl.tabs->extras = psiconv_list_new(sizeof(struct psiconv_tab));
141 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 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 void psiconv_free_mbm_jumptable_section (psiconv_mbm_jumptable_section section)
488 {
489 if (section)
490 psiconv_list_free(section);
491 }
492
493 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 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 void psiconv_free_clipart_section_aux(psiconv_clipart_section section)
518 {
519 if (section)
520 free(section->picture);
521 }
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 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 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 else if (file->type == psiconv_sketch_file)
555 psiconv_free_sketch_f((psiconv_sketch_f) file->file);
556 else if (file->type == psiconv_clipart_file)
557 psiconv_free_sketch_f((psiconv_clipart_f) file->file);
558 free(file);
559 }
560 }

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