/[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 13 - (show annotations)
Mon Oct 11 18:19:09 1999 UTC (24 years, 5 months ago) by frodo
File MIME type: text/plain
File size: 14377 byte(s)
(Frodo) Current status images: Parsing kind of works, but the number of
        pixels does not match. What am I doing wrong?

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

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