1 |
/* |
2 |
data.c - Part of psiconv, a PSION 5 file formats converter |
3 |
Copyright (c) 1999, 2000 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 |
|
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 |
static void psiconv_free_clipart_section_aux(void * section); |
37 |
static void psiconv_free_formula_aux(void *data); |
38 |
static void psiconv_free_sheet_worksheet_aux (void *data); |
39 |
static void psiconv_free_sheet_variable_aux(void * variable); |
40 |
|
41 |
static psiconv_word_styles_section psiconv_empty_word_styles_section(void); |
42 |
static psiconv_text_and_layout psiconv_empty_text_and_layout(void); |
43 |
static psiconv_texted_section psiconv_empty_texted_section(void); |
44 |
static psiconv_page_header psiconv_empty_page_header(void); |
45 |
static psiconv_page_layout_section psiconv_empty_page_layout_section(void); |
46 |
static psiconv_word_status_section psiconv_empty_word_status_section(void); |
47 |
static psiconv_word_f psiconv_empty_word_f(void); |
48 |
static psiconv_sheet_status_section psiconv_empty_sheet_status_section(void); |
49 |
static psiconv_formula_list psiconv_empty_formula_list(void); |
50 |
static psiconv_sheet_workbook_section |
51 |
psiconv_empty_sheet_workbook_section(void); |
52 |
static psiconv_sheet_f psiconv_empty_sheet_f(void); |
53 |
static psiconv_texted_f psiconv_empty_texted_f(void); |
54 |
static psiconv_paint_data_section psiconv_empty_paint_data_section(void); |
55 |
static psiconv_pictures psiconv_empty_pictures(void); |
56 |
static psiconv_mbm_f psiconv_empty_mbm_f(void); |
57 |
static psiconv_sketch_section psiconv_empty_sketch_section(void); |
58 |
static psiconv_sketch_f psiconv_empty_sketch_f(void); |
59 |
static psiconv_clipart_f psiconv_empty_clipart_f(void); |
60 |
static psiconv_cliparts psiconv_empty_cliparts(void); |
61 |
|
62 |
|
63 |
/* Note: these defaults seem to be hard-coded somewhere outside the |
64 |
files themself. */ |
65 |
psiconv_character_layout psiconv_basic_character_layout(void) |
66 |
{ |
67 |
/* Make the structures static, to oblige IRIX */ |
68 |
static struct psiconv_color_s black = |
69 |
{ |
70 |
0x00, /* red */ |
71 |
0x00, /* green */ |
72 |
0x00, /* blue */ |
73 |
}; |
74 |
static struct psiconv_color_s white = |
75 |
{ |
76 |
0xff, /* red */ |
77 |
0xff, /* green */ |
78 |
0xff, /* blue */ |
79 |
}; |
80 |
static struct psiconv_font_s font = |
81 |
{ |
82 |
"Times New Roman", /* name */ |
83 |
3 /* screenfont */ |
84 |
}; |
85 |
struct psiconv_character_layout_s cl = |
86 |
{ |
87 |
&black, /* color */ |
88 |
&white, /* back_color */ |
89 |
10.0, /* font_size */ |
90 |
psiconv_bool_false, /* italic */ |
91 |
psiconv_bool_false, /* bold */ |
92 |
psiconv_normalscript, /* super_sub */ |
93 |
psiconv_bool_false, /* underline */ |
94 |
psiconv_bool_false, /* strikethrough */ |
95 |
&font, /* font */ |
96 |
}; |
97 |
|
98 |
return psiconv_clone_character_layout(&cl); |
99 |
} |
100 |
|
101 |
/* Note: these defaults seem to be hard-coded somewhere outside the |
102 |
files themself. */ |
103 |
psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) |
104 |
{ |
105 |
static struct psiconv_font_s font = |
106 |
{ |
107 |
"Times New Roman", /* name */ |
108 |
2 /* screenfont */ |
109 |
}; |
110 |
static struct psiconv_color_s black = |
111 |
{ |
112 |
0x00, /* red */ |
113 |
0x00, /* green */ |
114 |
0x00, /* blue */ |
115 |
}; |
116 |
static struct psiconv_color_s white = |
117 |
{ |
118 |
0xff, /* red */ |
119 |
0xff, /* green */ |
120 |
0xff, /* blue */ |
121 |
}; |
122 |
static struct psiconv_border_s no_border = |
123 |
{ |
124 |
psiconv_border_none, /* kind */ |
125 |
1, /* thickness */ |
126 |
&black /* color */ |
127 |
}; |
128 |
static struct psiconv_bullet_s bullet = |
129 |
{ |
130 |
psiconv_bool_false, /* on */ |
131 |
10.0, /* font_size */ |
132 |
0x95, /* character */ |
133 |
psiconv_bool_true, /* indent */ |
134 |
&black, /* color */ |
135 |
&font, /* font */ |
136 |
}; |
137 |
static struct psiconv_all_tabs_s tabs = |
138 |
{ |
139 |
0.64, /* normal */ |
140 |
NULL /* kind */ |
141 |
}; |
142 |
struct psiconv_paragraph_layout_s pl = |
143 |
{ |
144 |
&white, /* back_color */ |
145 |
0.0, /* indent_left */ |
146 |
0.0, /* indent_right */ |
147 |
0.0, /* indent_first */ |
148 |
psiconv_justify_left, /* justify_hor */ |
149 |
psiconv_justify_middle,/* justify_ver */ |
150 |
10.0, /* linespacing */ |
151 |
psiconv_bool_false, /* linespacing_exact */ |
152 |
0.0, /* space_above */ |
153 |
0.0, /* space_below */ |
154 |
psiconv_bool_false, /* keep_together */ |
155 |
psiconv_bool_false, /* keep_with_next */ |
156 |
psiconv_bool_false, /* on_next_page */ |
157 |
psiconv_bool_false, /* no_widow_protection */ |
158 |
psiconv_bool_false, /* wrap_to_fit_cell */ |
159 |
0.0, /* left_margin */ |
160 |
&bullet, /* bullet */ |
161 |
&no_border, /* left_border */ |
162 |
&no_border, /* right_border */ |
163 |
&no_border, /* top_border */ |
164 |
&no_border, /* bottom_border */ |
165 |
&tabs, /* tabs */ |
166 |
}; |
167 |
psiconv_paragraph_layout res; |
168 |
|
169 |
if (!(pl.tabs->extras = psiconv_list_new(sizeof(struct psiconv_tab_s)))) |
170 |
return NULL; |
171 |
res = psiconv_clone_paragraph_layout(&pl); |
172 |
psiconv_list_free(pl.tabs->extras); |
173 |
return res; |
174 |
} |
175 |
|
176 |
psiconv_color clone_color(psiconv_color color) |
177 |
{ |
178 |
psiconv_color result; |
179 |
if (!(result = malloc(sizeof(*result)))) |
180 |
return NULL; |
181 |
*result = *color; |
182 |
return result; |
183 |
} |
184 |
|
185 |
psiconv_font clone_font(psiconv_font font) |
186 |
{ |
187 |
psiconv_font result; |
188 |
if(!(result = malloc(sizeof(*result)))) |
189 |
goto ERROR1; |
190 |
*result = *font; |
191 |
if (!(result->name = strdup(result->name))) |
192 |
goto ERROR2; |
193 |
return result; |
194 |
ERROR2: |
195 |
free(result); |
196 |
ERROR1: |
197 |
return NULL; |
198 |
} |
199 |
|
200 |
psiconv_border clone_border(psiconv_border border) |
201 |
{ |
202 |
psiconv_border result; |
203 |
if (!(result = malloc(sizeof(*result)))) |
204 |
goto ERROR1; |
205 |
*result = *border; |
206 |
if(!(result->color = clone_color(result->color))) |
207 |
goto ERROR2; |
208 |
return result; |
209 |
ERROR2: |
210 |
free(result); |
211 |
ERROR1: |
212 |
return NULL; |
213 |
} |
214 |
|
215 |
psiconv_bullet clone_bullet(psiconv_bullet bullet) |
216 |
{ |
217 |
psiconv_bullet result; |
218 |
if (!(result = malloc(sizeof(*result)))) |
219 |
goto ERROR1; |
220 |
*result = *bullet; |
221 |
if (!(result->font = clone_font(result->font))) |
222 |
goto ERROR2; |
223 |
if (!(result->color = clone_color(result->color))) |
224 |
goto ERROR3; |
225 |
return result; |
226 |
ERROR3: |
227 |
psiconv_free_font(result->font); |
228 |
ERROR2: |
229 |
free(result); |
230 |
ERROR1: |
231 |
return NULL; |
232 |
} |
233 |
|
234 |
psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs) |
235 |
{ |
236 |
psiconv_all_tabs result; |
237 |
if (!(result = malloc(sizeof(*result)))) |
238 |
goto ERROR1; |
239 |
*result = *all_tabs; |
240 |
if (!(result->extras = psiconv_list_clone(result->extras))) |
241 |
goto ERROR2; |
242 |
return result; |
243 |
ERROR2: |
244 |
free(result); |
245 |
ERROR1: |
246 |
return NULL; |
247 |
} |
248 |
|
249 |
psiconv_character_layout psiconv_clone_character_layout |
250 |
(psiconv_character_layout ls) |
251 |
{ |
252 |
psiconv_character_layout result; |
253 |
|
254 |
if (!(result = malloc(sizeof(*result)))) |
255 |
goto ERROR1; |
256 |
*result = *ls; |
257 |
if (!(result->color = clone_color(result->color))) |
258 |
goto ERROR2; |
259 |
if (!(result->back_color = clone_color(result->back_color))) |
260 |
goto ERROR3; |
261 |
if (!(result->font = clone_font(result->font))) |
262 |
goto ERROR4; |
263 |
return result; |
264 |
ERROR4: |
265 |
psiconv_free_color(result->back_color); |
266 |
ERROR3: |
267 |
psiconv_free_color(result->color); |
268 |
ERROR2: |
269 |
free(result); |
270 |
ERROR1: |
271 |
return NULL; |
272 |
} |
273 |
|
274 |
psiconv_paragraph_layout psiconv_clone_paragraph_layout |
275 |
(psiconv_paragraph_layout ls) |
276 |
{ |
277 |
psiconv_paragraph_layout result; |
278 |
|
279 |
if (!(result = malloc(sizeof(*result)))) |
280 |
goto ERROR1; |
281 |
*result = *ls; |
282 |
if (!(result->back_color = clone_color(result->back_color))) |
283 |
goto ERROR2; |
284 |
if (!(result->bullet = clone_bullet(result->bullet))) |
285 |
goto ERROR3; |
286 |
if (!(result->left_border = clone_border(result->left_border))) |
287 |
goto ERROR4; |
288 |
if (!(result->right_border = clone_border(result->right_border))) |
289 |
goto ERROR5; |
290 |
if (!(result->top_border = clone_border(result->top_border))) |
291 |
goto ERROR6; |
292 |
if (!(result->bottom_border = clone_border(result->bottom_border))) |
293 |
goto ERROR7; |
294 |
if (!(result->tabs = clone_all_tabs(result->tabs))) |
295 |
goto ERROR8; |
296 |
return result; |
297 |
ERROR8: |
298 |
psiconv_free_border(result->bottom_border); |
299 |
ERROR7: |
300 |
psiconv_free_border(result->top_border); |
301 |
ERROR6: |
302 |
psiconv_free_border(result->right_border); |
303 |
ERROR5: |
304 |
psiconv_free_border(result->left_border); |
305 |
ERROR4: |
306 |
psiconv_free_bullet(result->bullet); |
307 |
ERROR3: |
308 |
psiconv_free_color(result->back_color); |
309 |
ERROR2: |
310 |
free(result); |
311 |
ERROR1: |
312 |
return NULL; |
313 |
} |
314 |
|
315 |
psiconv_word_style psiconv_get_style (psiconv_word_styles_section ss, int nr) |
316 |
{ |
317 |
if (nr == 0) |
318 |
return ss->normal; |
319 |
else |
320 |
return psiconv_list_get(ss->styles,0xff - nr); |
321 |
} |
322 |
|
323 |
psiconv_formula psiconv_get_formula (psiconv_formula_list ss, int nr) |
324 |
{ |
325 |
return psiconv_list_get(ss,psiconv_list_length(ss)-nr-1); |
326 |
} |
327 |
|
328 |
/* TODO: What if a cell is both in a default row and a default column?!? */ |
329 |
psiconv_sheet_cell_layout psiconv_get_default_layout |
330 |
(psiconv_sheet_line_list row_defaults, |
331 |
psiconv_sheet_line_list col_defaults, |
332 |
psiconv_sheet_cell_layout cell_default, |
333 |
int row,int col) |
334 |
{ |
335 |
int i; |
336 |
psiconv_sheet_line line; |
337 |
for (i = 0;i < psiconv_list_length(row_defaults);i++) { |
338 |
line = psiconv_list_get(row_defaults,i); |
339 |
if (line->position == row) |
340 |
return line->layout; |
341 |
} |
342 |
for (i = 0;i < psiconv_list_length(col_defaults);i++) { |
343 |
line = psiconv_list_get(col_defaults,i); |
344 |
if (line->position == col) |
345 |
return line->layout; |
346 |
} |
347 |
return cell_default; |
348 |
} |
349 |
|
350 |
|
351 |
void psiconv_free_color (psiconv_color color) |
352 |
{ |
353 |
if (color) |
354 |
free(color); |
355 |
} |
356 |
|
357 |
void psiconv_free_border(psiconv_border border) |
358 |
{ |
359 |
if (border) { |
360 |
psiconv_free_color(border->color); |
361 |
free(border); |
362 |
} |
363 |
} |
364 |
|
365 |
void psiconv_free_font(psiconv_font font) |
366 |
{ |
367 |
if (font) { |
368 |
if (font->name) |
369 |
free(font->name); |
370 |
free(font); |
371 |
} |
372 |
} |
373 |
|
374 |
void psiconv_free_bullet(psiconv_bullet bullet) |
375 |
{ |
376 |
if (bullet) { |
377 |
psiconv_free_color(bullet->color); |
378 |
psiconv_free_font(bullet->font); |
379 |
free(bullet); |
380 |
} |
381 |
} |
382 |
|
383 |
void psiconv_free_character_layout(psiconv_character_layout layout) |
384 |
{ |
385 |
if (layout) { |
386 |
psiconv_free_color(layout->color); |
387 |
psiconv_free_color(layout->back_color); |
388 |
psiconv_free_font(layout->font); |
389 |
free(layout); |
390 |
} |
391 |
} |
392 |
|
393 |
void psiconv_free_tab(psiconv_tab tab) |
394 |
{ |
395 |
if (tab) |
396 |
free(tab); |
397 |
} |
398 |
|
399 |
void psiconv_free_tabs(psiconv_all_tabs tabs) |
400 |
{ |
401 |
if (tabs) { |
402 |
psiconv_list_free(tabs->extras); |
403 |
free(tabs); |
404 |
} |
405 |
} |
406 |
|
407 |
void psiconv_free_paragraph_layout(psiconv_paragraph_layout layout) |
408 |
{ |
409 |
if (layout) { |
410 |
psiconv_free_color(layout->back_color); |
411 |
psiconv_free_bullet(layout->bullet); |
412 |
psiconv_free_border(layout->left_border); |
413 |
psiconv_free_border(layout->right_border); |
414 |
psiconv_free_border(layout->top_border); |
415 |
psiconv_free_border(layout->bottom_border); |
416 |
psiconv_free_tabs(layout->tabs); |
417 |
free(layout); |
418 |
} |
419 |
} |
420 |
|
421 |
void psiconv_free_style_aux(void *style) |
422 |
{ |
423 |
if(((psiconv_word_style) style)->name) |
424 |
free(((psiconv_word_style) style)->name); |
425 |
psiconv_free_character_layout(((psiconv_word_style) style)->character); |
426 |
psiconv_free_paragraph_layout(((psiconv_word_style) style)->paragraph); |
427 |
} |
428 |
|
429 |
void psiconv_free_word_style(psiconv_word_style style) |
430 |
{ |
431 |
if (style) { |
432 |
psiconv_free_style_aux(style); |
433 |
free(style); |
434 |
} |
435 |
} |
436 |
|
437 |
void psiconv_free_word_styles_section(psiconv_word_styles_section styles) |
438 |
{ |
439 |
if (styles) { |
440 |
psiconv_free_word_style(styles->normal); |
441 |
if (styles->styles) |
442 |
psiconv_list_free_el(styles->styles,psiconv_free_style_aux); |
443 |
} |
444 |
} |
445 |
|
446 |
void psiconv_free_header_section(psiconv_header_section header) |
447 |
{ |
448 |
if (header) |
449 |
free(header); |
450 |
} |
451 |
|
452 |
void psiconv_free_section_table_entry(psiconv_section_table_entry entry) |
453 |
{ |
454 |
if (entry) |
455 |
free(entry); |
456 |
} |
457 |
|
458 |
void psiconv_free_section_table_section(psiconv_section_table_section section) |
459 |
{ |
460 |
if (section) |
461 |
psiconv_list_free(section); |
462 |
} |
463 |
|
464 |
void psiconv_free_application_id_section(psiconv_application_id_section section) |
465 |
{ |
466 |
if (section) { |
467 |
if (section->name) |
468 |
free(section->name); |
469 |
free(section); |
470 |
} |
471 |
} |
472 |
|
473 |
void psiconv_free_in_line_layout_aux(void * layout) |
474 |
{ |
475 |
psiconv_free_character_layout(((psiconv_in_line_layout) layout)->layout); |
476 |
} |
477 |
|
478 |
void psiconv_free_in_line_layout(psiconv_in_line_layout layout) |
479 |
{ |
480 |
if (layout) { |
481 |
psiconv_free_in_line_layout_aux(layout); |
482 |
free(layout); |
483 |
} |
484 |
} |
485 |
|
486 |
void psiconv_free_in_line_layouts(psiconv_in_line_layouts layouts) |
487 |
{ |
488 |
if (layouts) |
489 |
psiconv_list_free_el(layouts,&psiconv_free_in_line_layout_aux); |
490 |
} |
491 |
|
492 |
void psiconv_free_replacement(psiconv_replacement replacement) |
493 |
{ |
494 |
if (replacement) |
495 |
free(replacement); |
496 |
} |
497 |
|
498 |
void psiconv_free_replacements(psiconv_replacements replacements) |
499 |
{ |
500 |
if (replacements) |
501 |
psiconv_list_free(replacements); |
502 |
} |
503 |
|
504 |
void psiconv_free_paragraph_aux(void * paragraph) |
505 |
{ |
506 |
if(((psiconv_paragraph) paragraph)->text) |
507 |
free(((psiconv_paragraph) paragraph)->text); |
508 |
psiconv_free_character_layout(((psiconv_paragraph) paragraph) |
509 |
->base_character); |
510 |
psiconv_free_paragraph_layout(((psiconv_paragraph) paragraph) |
511 |
->base_paragraph); |
512 |
psiconv_free_in_line_layouts(((psiconv_paragraph) paragraph) |
513 |
->in_lines); |
514 |
psiconv_free_replacements(((psiconv_paragraph) paragraph) |
515 |
->replacements); |
516 |
} |
517 |
|
518 |
void psiconv_free_paragraph(psiconv_paragraph paragraph) |
519 |
{ |
520 |
if (paragraph) { |
521 |
psiconv_free_paragraph_aux(paragraph); |
522 |
free(paragraph); |
523 |
} |
524 |
} |
525 |
|
526 |
void psiconv_free_text_and_layout(psiconv_text_and_layout text) |
527 |
{ |
528 |
if (text) |
529 |
psiconv_list_free_el(text,&psiconv_free_paragraph_aux); |
530 |
} |
531 |
|
532 |
void psiconv_free_texted_section(psiconv_texted_section section) |
533 |
{ |
534 |
if (section) { |
535 |
psiconv_free_text_and_layout(section->paragraphs); |
536 |
free(section); |
537 |
} |
538 |
} |
539 |
|
540 |
void psiconv_free_page_header(psiconv_page_header header) |
541 |
{ |
542 |
if (header) { |
543 |
psiconv_free_character_layout(header->base_character_layout); |
544 |
psiconv_free_paragraph_layout(header->base_paragraph_layout); |
545 |
psiconv_free_texted_section(header->text); |
546 |
free(header); |
547 |
} |
548 |
} |
549 |
|
550 |
void psiconv_free_page_layout_section(psiconv_page_layout_section section) |
551 |
{ |
552 |
if (section) { |
553 |
psiconv_free_page_header(section->header); |
554 |
psiconv_free_page_header(section->footer); |
555 |
free(section); |
556 |
} |
557 |
} |
558 |
|
559 |
void psiconv_free_word_status_section(psiconv_word_status_section section) |
560 |
{ |
561 |
if (section) |
562 |
free(section); |
563 |
} |
564 |
|
565 |
void psiconv_free_word_f(psiconv_word_f file) |
566 |
{ |
567 |
if (file) { |
568 |
psiconv_free_page_layout_section(file->page_sec); |
569 |
psiconv_free_text_and_layout(file->paragraphs); |
570 |
psiconv_free_word_status_section(file->status_sec); |
571 |
psiconv_free_word_styles_section(file->styles_sec); |
572 |
free(file); |
573 |
} |
574 |
} |
575 |
|
576 |
void psiconv_free_sheet_status_section(psiconv_sheet_status_section section) |
577 |
{ |
578 |
if (section) |
579 |
free(section); |
580 |
} |
581 |
|
582 |
void psiconv_free_sheet_numberformat(psiconv_sheet_numberformat numberformat) |
583 |
{ |
584 |
if (numberformat) |
585 |
free(numberformat); |
586 |
} |
587 |
|
588 |
void psiconv_free_sheet_cell_layout(psiconv_sheet_cell_layout layout) |
589 |
{ |
590 |
psiconv_free_paragraph_layout(layout->paragraph); |
591 |
psiconv_free_character_layout(layout->character); |
592 |
psiconv_free_sheet_numberformat(layout->numberformat); |
593 |
} |
594 |
|
595 |
void psiconv_free_sheet_cell_aux(void *cell) |
596 |
{ |
597 |
psiconv_sheet_cell data = cell; |
598 |
|
599 |
psiconv_free_sheet_cell_layout(data->layout); |
600 |
|
601 |
if ((data->type == psiconv_cell_string) && (data->data.dat_string)) |
602 |
free(data->data.dat_string); |
603 |
} |
604 |
|
605 |
void psiconv_free_sheet_cell(psiconv_sheet_cell cell) |
606 |
{ |
607 |
if (cell) { |
608 |
psiconv_free_sheet_cell_aux(cell); |
609 |
free(cell); |
610 |
} |
611 |
} |
612 |
|
613 |
void psiconv_free_sheet_cell_list(psiconv_sheet_cell_list list) |
614 |
{ |
615 |
if (list) |
616 |
psiconv_list_free_el(list,psiconv_free_sheet_cell_aux); |
617 |
} |
618 |
|
619 |
void psiconv_free_sheet_line_aux(void *line) |
620 |
{ |
621 |
psiconv_sheet_line data = line; |
622 |
|
623 |
psiconv_free_sheet_cell_layout(data->layout); |
624 |
} |
625 |
|
626 |
void psiconv_free_sheet_line(psiconv_sheet_line line) |
627 |
{ |
628 |
if (line) { |
629 |
psiconv_free_sheet_line_aux(line); |
630 |
free(line); |
631 |
} |
632 |
} |
633 |
|
634 |
|
635 |
void psiconv_free_sheet_line_list(psiconv_sheet_line_list list) |
636 |
{ |
637 |
if (list) |
638 |
psiconv_list_free_el(list,psiconv_free_sheet_line_aux); |
639 |
} |
640 |
|
641 |
void psiconv_free_sheet_grid_break_list(psiconv_sheet_grid_break_list list) |
642 |
{ |
643 |
if (list) |
644 |
psiconv_list_free(list); |
645 |
} |
646 |
|
647 |
void psiconv_free_sheet_grid_size(psiconv_sheet_grid_size s) |
648 |
{ |
649 |
if (s) |
650 |
free(s); |
651 |
} |
652 |
|
653 |
void psiconv_free_sheet_grid_size_list(psiconv_sheet_grid_size_list list) |
654 |
{ |
655 |
if (list) |
656 |
psiconv_list_free(list); |
657 |
} |
658 |
|
659 |
void psiconv_free_sheet_grid_section(psiconv_sheet_grid_section sec) |
660 |
{ |
661 |
if (sec) { |
662 |
psiconv_free_sheet_grid_size_list(sec->row_heights); |
663 |
psiconv_free_sheet_grid_size_list(sec->column_heights); |
664 |
psiconv_free_sheet_grid_break_list(sec->row_page_breaks); |
665 |
psiconv_free_sheet_grid_break_list(sec->column_page_breaks); |
666 |
free(sec); |
667 |
} |
668 |
} |
669 |
|
670 |
void psiconv_free_sheet_worksheet_aux (void *data) |
671 |
{ |
672 |
psiconv_sheet_worksheet section = data; |
673 |
psiconv_free_sheet_cell_layout(section->default_layout); |
674 |
psiconv_free_sheet_cell_list(section->cells); |
675 |
psiconv_free_sheet_line_list(section->row_default_layouts); |
676 |
psiconv_free_sheet_line_list(section->col_default_layouts); |
677 |
psiconv_free_sheet_grid_section(section->grid); |
678 |
} |
679 |
|
680 |
void psiconv_free_sheet_worksheet(psiconv_sheet_worksheet sheet) |
681 |
{ |
682 |
if (sheet) { |
683 |
psiconv_free_sheet_worksheet_aux(sheet); |
684 |
free(sheet); |
685 |
} |
686 |
} |
687 |
|
688 |
void psiconv_free_sheet_worksheet_list(psiconv_sheet_worksheet_list list) |
689 |
{ |
690 |
if (list) |
691 |
psiconv_list_free_el(list,psiconv_free_sheet_worksheet_aux); |
692 |
} |
693 |
|
694 |
void psiconv_free_formula_aux(void *data) |
695 |
{ |
696 |
psiconv_formula formula; |
697 |
formula = data; |
698 |
if (formula->type == psiconv_formula_dat_string) |
699 |
free(formula->data.dat_string); |
700 |
else if ((formula->type != psiconv_formula_dat_int) && |
701 |
(formula->type != psiconv_formula_dat_var) && |
702 |
(formula->type != psiconv_formula_dat_float) && |
703 |
(formula->type != psiconv_formula_dat_cellref) && |
704 |
(formula->type != psiconv_formula_dat_cellblock) && |
705 |
(formula->type != psiconv_formula_dat_vcellblock) && |
706 |
(formula->type != psiconv_formula_mark_opsep) && |
707 |
(formula->type != psiconv_formula_mark_opend) && |
708 |
(formula->type != psiconv_formula_mark_eof) && |
709 |
(formula->type != psiconv_formula_unknown)) |
710 |
psiconv_free_formula_list(formula->data.fun_operands); |
711 |
} |
712 |
|
713 |
void psiconv_free_formula(psiconv_formula formula) |
714 |
{ |
715 |
if (formula) { |
716 |
psiconv_free_formula_aux(formula); |
717 |
free(formula); |
718 |
} |
719 |
} |
720 |
|
721 |
void psiconv_free_formula_list(psiconv_formula_list list) |
722 |
{ |
723 |
if (list) |
724 |
psiconv_list_free_el(list,psiconv_free_formula_aux); |
725 |
} |
726 |
|
727 |
void psiconv_free_sheet_name_section(psiconv_sheet_name_section section) |
728 |
{ |
729 |
if (section) { |
730 |
if(section->name) |
731 |
free(section->name); |
732 |
free(section); |
733 |
} |
734 |
} |
735 |
|
736 |
void psiconv_free_sheet_info_section(psiconv_sheet_info_section section) |
737 |
{ |
738 |
if (section) { |
739 |
free(section); |
740 |
} |
741 |
} |
742 |
|
743 |
void psiconv_free_sheet_variable_aux(void * variable) |
744 |
{ |
745 |
psiconv_sheet_variable var = variable; |
746 |
if (var->name) |
747 |
free(var->name); |
748 |
if (var->type == psiconv_var_string) |
749 |
free(var->data.dat_string); |
750 |
} |
751 |
|
752 |
void psiconv_free_sheet_variable(psiconv_sheet_variable var) |
753 |
{ |
754 |
if (var) { |
755 |
psiconv_free_sheet_variable_aux(var); |
756 |
free(var); |
757 |
} |
758 |
} |
759 |
|
760 |
void psiconv_free_sheet_variable_list(psiconv_sheet_variable_list list) |
761 |
{ |
762 |
if (list) |
763 |
psiconv_list_free_el(list,psiconv_free_sheet_variable_aux); |
764 |
} |
765 |
|
766 |
void psiconv_free_sheet_workbook_section(psiconv_sheet_workbook_section section) |
767 |
{ |
768 |
if (section) { |
769 |
psiconv_free_formula_list(section->formulas); |
770 |
psiconv_free_sheet_worksheet_list(section->worksheets); |
771 |
psiconv_free_sheet_name_section(section->name); |
772 |
psiconv_free_sheet_info_section(section->info); |
773 |
psiconv_free_sheet_variable_list(section->variables); |
774 |
free(section); |
775 |
} |
776 |
} |
777 |
|
778 |
void psiconv_free_sheet_f(psiconv_sheet_f file) |
779 |
{ |
780 |
if (file) { |
781 |
psiconv_free_page_layout_section(file->page_sec); |
782 |
psiconv_free_sheet_status_section(file->status_sec); |
783 |
psiconv_free_sheet_workbook_section(file->workbook_sec); |
784 |
free(file); |
785 |
} |
786 |
} |
787 |
|
788 |
void psiconv_free_texted_f(psiconv_texted_f file) |
789 |
{ |
790 |
if (file) { |
791 |
psiconv_free_page_layout_section(file->page_sec); |
792 |
psiconv_free_texted_section(file->texted_sec); |
793 |
free(file); |
794 |
} |
795 |
} |
796 |
|
797 |
void psiconv_free_paint_data_section_aux(void * section) |
798 |
{ |
799 |
if (((psiconv_paint_data_section) section)->red) |
800 |
free(((psiconv_paint_data_section)section) -> red); |
801 |
if (((psiconv_paint_data_section) section)->green) |
802 |
free(((psiconv_paint_data_section)section) -> green); |
803 |
if (((psiconv_paint_data_section) section)->blue) |
804 |
free(((psiconv_paint_data_section)section) -> blue); |
805 |
} |
806 |
|
807 |
void psiconv_free_paint_data_section(psiconv_paint_data_section section) |
808 |
{ |
809 |
if (section) { |
810 |
psiconv_free_paint_data_section_aux(section); |
811 |
free(section); |
812 |
} |
813 |
} |
814 |
|
815 |
void psiconv_free_pictures(psiconv_pictures section) |
816 |
{ |
817 |
if (section) |
818 |
psiconv_list_free_el(section,&psiconv_free_paint_data_section_aux); |
819 |
} |
820 |
|
821 |
void psiconv_free_jumptable_section (psiconv_jumptable_section section) |
822 |
{ |
823 |
if (section) |
824 |
psiconv_list_free(section); |
825 |
} |
826 |
|
827 |
void psiconv_free_mbm_f(psiconv_mbm_f file) |
828 |
{ |
829 |
if (file) { |
830 |
psiconv_free_pictures(file->sections); |
831 |
free(file); |
832 |
} |
833 |
} |
834 |
|
835 |
void psiconv_free_sketch_section(psiconv_sketch_section sec) |
836 |
{ |
837 |
if (sec) { |
838 |
psiconv_free_paint_data_section(sec->picture); |
839 |
free(sec); |
840 |
} |
841 |
} |
842 |
|
843 |
void psiconv_free_sketch_f(psiconv_sketch_f file) |
844 |
{ |
845 |
if (file) { |
846 |
psiconv_free_sketch_section(file->sketch_sec); |
847 |
free(file); |
848 |
} |
849 |
} |
850 |
|
851 |
void psiconv_free_clipart_section_aux(void *section) |
852 |
{ |
853 |
if (section) |
854 |
free(((psiconv_clipart_section ) section)->picture); |
855 |
} |
856 |
|
857 |
void psiconv_free_clipart_section(psiconv_clipart_section section) |
858 |
{ |
859 |
if (section) { |
860 |
psiconv_free_clipart_section_aux(section); |
861 |
free(section); |
862 |
} |
863 |
} |
864 |
|
865 |
void psiconv_free_cliparts(psiconv_cliparts section) |
866 |
{ |
867 |
if (section) |
868 |
psiconv_list_free_el(section,&psiconv_free_clipart_section_aux); |
869 |
} |
870 |
|
871 |
void psiconv_free_clipart_f(psiconv_clipart_f file) |
872 |
{ |
873 |
if (file) { |
874 |
psiconv_free_cliparts(file->sections); |
875 |
free(file); |
876 |
} |
877 |
} |
878 |
|
879 |
void psiconv_free_file(psiconv_file file) |
880 |
{ |
881 |
if (file) { |
882 |
if (file->type == psiconv_word_file) |
883 |
psiconv_free_word_f((psiconv_word_f) file->file); |
884 |
else if (file->type == psiconv_texted_file) |
885 |
psiconv_free_texted_f((psiconv_texted_f) file->file); |
886 |
else if (file->type == psiconv_mbm_file) |
887 |
psiconv_free_mbm_f((psiconv_mbm_f) file->file); |
888 |
else if (file->type == psiconv_sketch_file) |
889 |
psiconv_free_sketch_f((psiconv_sketch_f) file->file); |
890 |
else if (file->type == psiconv_clipart_file) |
891 |
psiconv_free_clipart_f((psiconv_clipart_f) file->file); |
892 |
else if (file->type == psiconv_sheet_file) |
893 |
psiconv_free_sheet_f((psiconv_sheet_f) file->file); |
894 |
free(file); |
895 |
} |
896 |
} |
897 |
|
898 |
int psiconv_compare_color(const psiconv_color value1, |
899 |
const psiconv_color value2) |
900 |
{ |
901 |
if (!value1 || !value2) |
902 |
return 1; |
903 |
if ((value1->red == value2->red) && |
904 |
(value1->green == value2->green) && |
905 |
(value1->blue == value2->blue)) |
906 |
return 0; |
907 |
else |
908 |
return 1; |
909 |
} |
910 |
|
911 |
int psiconv_compare_font(const psiconv_font value1, |
912 |
const psiconv_font value2) |
913 |
{ |
914 |
if (!value1 || !value2 || !value1->name || !value2->name) |
915 |
return 1; |
916 |
if ((value1->screenfont == value2->screenfont) && |
917 |
!strcmp(value1->name,value2->name)) |
918 |
return 0; |
919 |
else |
920 |
return 1; |
921 |
} |
922 |
|
923 |
int psiconv_compare_border(const psiconv_border value1, |
924 |
const psiconv_border value2) |
925 |
{ |
926 |
if (!value1 || !value2) |
927 |
return 1; |
928 |
if ((value1->kind == value2->kind) && |
929 |
(value1->thickness == value2->thickness) && |
930 |
!psiconv_compare_color(value1->color,value2->color)) |
931 |
return 0; |
932 |
else |
933 |
return 1; |
934 |
} |
935 |
|
936 |
int psiconv_compare_bullet(const psiconv_bullet value1, |
937 |
const psiconv_bullet value2) |
938 |
{ |
939 |
if (!value1 || !value2) |
940 |
return 1; |
941 |
if ((value1->on == value2->on) && |
942 |
(value1->font_size == value2->font_size) && |
943 |
(value1->character == value2->character) && |
944 |
(value1->indent == value2->indent) && |
945 |
!psiconv_compare_color(value1->color,value2->color) && |
946 |
!psiconv_compare_font(value1->font,value2->font)) |
947 |
return 0; |
948 |
else |
949 |
return 1; |
950 |
} |
951 |
|
952 |
int psiconv_compare_tab(const psiconv_tab value1, const psiconv_tab value2) |
953 |
{ |
954 |
if (!value1 || !value2) |
955 |
return 1; |
956 |
if ((value1->location == value2->location) && |
957 |
(value1->kind == value2->kind)) |
958 |
return 0; |
959 |
else |
960 |
return 1; |
961 |
} |
962 |
|
963 |
int psiconv_compare_all_tabs(const psiconv_all_tabs value1, |
964 |
const psiconv_all_tabs value2) |
965 |
{ |
966 |
int i; |
967 |
|
968 |
if (!value1 || !value2 || !value1->extras || !value2->extras) |
969 |
return 1; |
970 |
|
971 |
if ((value1->normal != value2->normal) || |
972 |
psiconv_list_length(value1->extras) != |
973 |
psiconv_list_length(value2->extras)) |
974 |
return 1; |
975 |
for (i = 0; i < psiconv_list_length(value1->extras); i++) |
976 |
if (psiconv_compare_tab(psiconv_list_get(value1->extras,i), |
977 |
psiconv_list_get(value2->extras,i))) |
978 |
|
979 |
return 1; |
980 |
return 0; |
981 |
} |
982 |
|
983 |
int psiconv_compare_paragraph_layout(const psiconv_paragraph_layout value1, |
984 |
const psiconv_paragraph_layout value2) |
985 |
{ |
986 |
if (!value1 || !value2) |
987 |
return 1; |
988 |
if ((value1->indent_left == value2->indent_left) && |
989 |
(value1->indent_right == value2->indent_right) && |
990 |
(value1->indent_first == value2->indent_first) && |
991 |
(value1->justify_hor == value2->justify_hor) && |
992 |
(value1->justify_ver == value2->justify_ver) && |
993 |
(value1->linespacing == value2->linespacing) && |
994 |
(value1->space_above == value2->space_above) && |
995 |
(value1->space_below == value2->space_below) && |
996 |
(value1->keep_together == value2->keep_together) && |
997 |
(value1->keep_with_next == value2->keep_with_next) && |
998 |
(value1->on_next_page == value2->on_next_page) && |
999 |
(value1->no_widow_protection == value2->no_widow_protection) && |
1000 |
(value1->border_distance == value2->border_distance) && |
1001 |
!psiconv_compare_color(value1->back_color,value2->back_color) && |
1002 |
!psiconv_compare_bullet(value1->bullet,value2->bullet) && |
1003 |
!psiconv_compare_border(value1->left_border,value2->left_border) && |
1004 |
!psiconv_compare_border(value1->right_border,value2->right_border) && |
1005 |
!psiconv_compare_border(value1->top_border,value2->top_border) && |
1006 |
!psiconv_compare_border(value1->bottom_border,value2->bottom_border) && |
1007 |
!psiconv_compare_all_tabs(value1->tabs,value2->tabs)) |
1008 |
return 0; |
1009 |
else |
1010 |
return 1; |
1011 |
} |
1012 |
|
1013 |
|
1014 |
int psiconv_compare_character_layout(const psiconv_character_layout value1, |
1015 |
const psiconv_character_layout value2) |
1016 |
{ |
1017 |
if (!value1 || !value2) |
1018 |
return 1; |
1019 |
if ((value1->font_size == value2->font_size) && |
1020 |
(value1->italic == value2->italic) && |
1021 |
(value1->bold == value2->bold) && |
1022 |
(value1->super_sub == value2->super_sub) && |
1023 |
(value1->underline == value2->underline) && |
1024 |
(value1->strikethrough == value2->strikethrough) && |
1025 |
!psiconv_compare_color(value1->color,value2->color) && |
1026 |
!psiconv_compare_color(value1->back_color,value2->back_color) && |
1027 |
!psiconv_compare_font(value1->font,value2->font)) |
1028 |
return 0; |
1029 |
else |
1030 |
return 1; |
1031 |
} |
1032 |
|
1033 |
|
1034 |
|
1035 |
psiconv_word_styles_section psiconv_empty_word_styles_section(void) |
1036 |
{ |
1037 |
psiconv_word_styles_section result; |
1038 |
if (!(result = malloc(sizeof(*result)))) |
1039 |
goto ERROR1; |
1040 |
if (!(result->styles = psiconv_list_new(sizeof(struct psiconv_word_style_s)))) |
1041 |
goto ERROR2; |
1042 |
if (!(result->normal = malloc(sizeof(struct psiconv_word_style_s)))) |
1043 |
goto ERROR3; |
1044 |
if (!(result->normal->character = psiconv_basic_character_layout())) |
1045 |
goto ERROR4; |
1046 |
if (!(result->normal->paragraph = psiconv_basic_paragraph_layout())) |
1047 |
goto ERROR5; |
1048 |
result->normal->hotkey = 'N'; |
1049 |
result->normal->name = NULL; |
1050 |
result->normal->built_in = psiconv_bool_true; |
1051 |
result->normal->outline_level = 0; |
1052 |
return result; |
1053 |
ERROR5: |
1054 |
psiconv_free_character_layout(result->normal->character); |
1055 |
ERROR4: |
1056 |
free(result->normal); |
1057 |
ERROR3: |
1058 |
psiconv_list_free(result->styles); |
1059 |
ERROR2: |
1060 |
free(result); |
1061 |
ERROR1: |
1062 |
return NULL; |
1063 |
} |
1064 |
|
1065 |
psiconv_text_and_layout psiconv_empty_text_and_layout(void) |
1066 |
{ |
1067 |
return psiconv_list_new(sizeof(struct psiconv_paragraph_s)); |
1068 |
} |
1069 |
|
1070 |
psiconv_texted_section psiconv_empty_texted_section(void) |
1071 |
{ |
1072 |
psiconv_texted_section result; |
1073 |
if (!(result = malloc(sizeof(*result)))) |
1074 |
goto ERROR1; |
1075 |
if (!(result->paragraphs = psiconv_empty_text_and_layout())) |
1076 |
goto ERROR2; |
1077 |
return result; |
1078 |
ERROR2: |
1079 |
free(result); |
1080 |
ERROR1: |
1081 |
return NULL; |
1082 |
} |
1083 |
|
1084 |
psiconv_page_header psiconv_empty_page_header(void) |
1085 |
{ |
1086 |
psiconv_page_header result; |
1087 |
if (!(result = malloc(sizeof(*result)))) |
1088 |
goto ERROR1; |
1089 |
result->on_first_page = psiconv_bool_true; |
1090 |
if (!(result->base_paragraph_layout = psiconv_basic_paragraph_layout())) |
1091 |
goto ERROR2; |
1092 |
if (!(result->base_character_layout = psiconv_basic_character_layout())) |
1093 |
goto ERROR3; |
1094 |
if (!(result->text = psiconv_empty_texted_section())) |
1095 |
goto ERROR4; |
1096 |
return result; |
1097 |
ERROR4: |
1098 |
psiconv_free_character_layout(result->base_character_layout); |
1099 |
ERROR3: |
1100 |
psiconv_free_paragraph_layout(result->base_paragraph_layout); |
1101 |
ERROR2: |
1102 |
free(result); |
1103 |
ERROR1: |
1104 |
return NULL; |
1105 |
} |
1106 |
|
1107 |
psiconv_page_layout_section psiconv_empty_page_layout_section(void) |
1108 |
{ |
1109 |
psiconv_page_layout_section result; |
1110 |
if (!(result = malloc(sizeof(*result)))) |
1111 |
goto ERROR1; |
1112 |
result->first_page_nr = 1; |
1113 |
result->header_dist = result->footer_dist = 1.27; |
1114 |
result->left_margin = result->right_margin = 3.175; |
1115 |
result->top_margin = result->bottom_margin = 2.54; |
1116 |
result->page_width = 21.0; |
1117 |
result->page_height = 29.7; |
1118 |
result->landscape = psiconv_bool_false; |
1119 |
if (!(result->header = psiconv_empty_page_header())) |
1120 |
goto ERROR2; |
1121 |
if (!(result->footer = psiconv_empty_page_header())) |
1122 |
goto ERROR3; |
1123 |
return result; |
1124 |
ERROR3: |
1125 |
psiconv_free_page_header(result->header); |
1126 |
ERROR2: |
1127 |
free(result); |
1128 |
ERROR1: |
1129 |
return NULL; |
1130 |
} |
1131 |
|
1132 |
psiconv_word_status_section psiconv_empty_word_status_section(void) |
1133 |
{ |
1134 |
psiconv_word_status_section result; |
1135 |
if (!(result = malloc(sizeof(*result)))) |
1136 |
return NULL; |
1137 |
result->show_tabs = result->show_spaces = result->show_paragraph_ends = |
1138 |
result->show_hard_minus = result->show_hard_space = |
1139 |
result->fit_lines_to_screen = psiconv_bool_false; |
1140 |
result->show_full_pictures = result->show_full_graphs = |
1141 |
result->show_top_toolbar = result->show_side_toolbar = |
1142 |
psiconv_bool_true; |
1143 |
result->cursor_position = 0; |
1144 |
result->display_size = 1000; |
1145 |
return result; |
1146 |
} |
1147 |
|
1148 |
psiconv_word_f psiconv_empty_word_f(void) |
1149 |
{ |
1150 |
psiconv_word_f result; |
1151 |
if (!(result = malloc(sizeof(*result)))) |
1152 |
goto ERROR1; |
1153 |
if (!(result->page_sec = psiconv_empty_page_layout_section())) |
1154 |
goto ERROR2; |
1155 |
if (!(result->paragraphs = psiconv_empty_text_and_layout())) |
1156 |
goto ERROR3; |
1157 |
if (!(result->status_sec = psiconv_empty_word_status_section())) |
1158 |
goto ERROR4; |
1159 |
if (!(result->styles_sec = psiconv_empty_word_styles_section())) |
1160 |
goto ERROR5; |
1161 |
return result; |
1162 |
ERROR5: |
1163 |
psiconv_free_word_status_section(result->status_sec); |
1164 |
ERROR4: |
1165 |
psiconv_free_text_and_layout(result->paragraphs); |
1166 |
ERROR3: |
1167 |
psiconv_free_page_layout_section(result->page_sec); |
1168 |
ERROR2: |
1169 |
free(result); |
1170 |
ERROR1: |
1171 |
return NULL; |
1172 |
} |
1173 |
|
1174 |
psiconv_sheet_status_section psiconv_empty_sheet_status_section(void) |
1175 |
{ |
1176 |
psiconv_sheet_status_section result; |
1177 |
if (!(result = malloc(sizeof(*result)))) |
1178 |
return NULL; |
1179 |
result->show_horizontal_scrollbar = result->show_vertical_scrollbar = |
1180 |
psiconv_triple_auto; |
1181 |
result->show_graph = psiconv_bool_false; |
1182 |
result->show_top_sheet_toolbar = result->show_side_sheet_toolbar = |
1183 |
result->show_top_graph_toolbar = result->show_side_graph_toolbar = |
1184 |
psiconv_bool_true; |
1185 |
result->cursor_row = result->cursor_column = 0; |
1186 |
result->sheet_display_size = result->graph_display_size = 1000; |
1187 |
return result; |
1188 |
} |
1189 |
|
1190 |
psiconv_formula_list psiconv_empty_formula_list(void) |
1191 |
{ |
1192 |
return psiconv_list_new(sizeof(struct psiconv_formula_s)); |
1193 |
} |
1194 |
|
1195 |
psiconv_sheet_workbook_section psiconv_empty_sheet_workbook_section(void) |
1196 |
{ |
1197 |
psiconv_sheet_workbook_section result; |
1198 |
if (!(result = malloc(sizeof(*result)))) |
1199 |
goto ERROR1; |
1200 |
if (!(result->formulas = psiconv_empty_formula_list())) |
1201 |
goto ERROR2; |
1202 |
return result; |
1203 |
ERROR2: |
1204 |
free(result); |
1205 |
ERROR1: |
1206 |
return NULL; |
1207 |
} |
1208 |
|
1209 |
|
1210 |
psiconv_sheet_f psiconv_empty_sheet_f(void) |
1211 |
{ |
1212 |
psiconv_sheet_f result; |
1213 |
if (!(result = malloc(sizeof(*result)))) |
1214 |
goto ERROR1; |
1215 |
if (!(result->page_sec = psiconv_empty_page_layout_section())) |
1216 |
goto ERROR2; |
1217 |
if (!(result->status_sec = psiconv_empty_sheet_status_section())) |
1218 |
goto ERROR3; |
1219 |
if (!(result->workbook_sec = psiconv_empty_sheet_workbook_section())) |
1220 |
goto ERROR4; |
1221 |
return result; |
1222 |
ERROR4: |
1223 |
psiconv_free_sheet_status_section(result->status_sec); |
1224 |
ERROR3: |
1225 |
psiconv_free_page_layout_section(result->page_sec); |
1226 |
ERROR2: |
1227 |
free(result); |
1228 |
ERROR1: |
1229 |
return NULL; |
1230 |
} |
1231 |
|
1232 |
psiconv_texted_f psiconv_empty_texted_f(void) |
1233 |
{ |
1234 |
psiconv_texted_f result; |
1235 |
if (!(result = malloc(sizeof(*result)))) |
1236 |
goto ERROR1; |
1237 |
if (!(result->page_sec = psiconv_empty_page_layout_section())) |
1238 |
goto ERROR2; |
1239 |
if (!(result->texted_sec = psiconv_empty_texted_section())) |
1240 |
goto ERROR3; |
1241 |
return result; |
1242 |
ERROR3: |
1243 |
psiconv_free_page_layout_section(result->page_sec); |
1244 |
ERROR2: |
1245 |
free(result); |
1246 |
ERROR1: |
1247 |
return NULL; |
1248 |
} |
1249 |
|
1250 |
psiconv_paint_data_section psiconv_empty_paint_data_section(void) |
1251 |
{ |
1252 |
psiconv_paint_data_section result; |
1253 |
if (!(result = malloc(sizeof(*result)))) |
1254 |
goto ERROR1; |
1255 |
/* Is this correct? */ |
1256 |
result->xsize = result->ysize = result->pic_xsize = result->pic_ysize = 0; |
1257 |
/* Probably forbidden... */ |
1258 |
if (!(result->red = malloc(0))) |
1259 |
goto ERROR2; |
1260 |
if (!(result->green = malloc(0))) |
1261 |
goto ERROR3; |
1262 |
if (!(result->blue = malloc(0))) |
1263 |
goto ERROR4; |
1264 |
return result; |
1265 |
ERROR4: |
1266 |
free(result->green); |
1267 |
ERROR3: |
1268 |
free(result->red); |
1269 |
ERROR2: |
1270 |
free(result); |
1271 |
ERROR1: |
1272 |
return NULL; |
1273 |
} |
1274 |
|
1275 |
|
1276 |
psiconv_pictures psiconv_empty_pictures(void) |
1277 |
{ |
1278 |
psiconv_pictures result; |
1279 |
psiconv_paint_data_section pds; |
1280 |
if (!(result = psiconv_list_new(sizeof(struct psiconv_paint_data_section_s)))) |
1281 |
goto ERROR1; |
1282 |
if (!(pds = psiconv_empty_paint_data_section())) |
1283 |
goto ERROR2; |
1284 |
if (psiconv_list_add(result,pds)) |
1285 |
goto ERROR3; |
1286 |
free(pds); |
1287 |
return result; |
1288 |
ERROR3: |
1289 |
psiconv_free_paint_data_section(pds); |
1290 |
ERROR2: |
1291 |
psiconv_list_free(result); |
1292 |
ERROR1: |
1293 |
return NULL; |
1294 |
} |
1295 |
|
1296 |
psiconv_mbm_f psiconv_empty_mbm_f(void) |
1297 |
{ |
1298 |
psiconv_mbm_f result; |
1299 |
if (!(result = malloc(sizeof(*result)))) |
1300 |
goto ERROR1; |
1301 |
if (!(result->sections = psiconv_empty_pictures())) |
1302 |
goto ERROR2; |
1303 |
return result; |
1304 |
ERROR2: |
1305 |
free(result); |
1306 |
ERROR1: |
1307 |
return NULL; |
1308 |
} |
1309 |
|
1310 |
psiconv_sketch_section psiconv_empty_sketch_section(void) |
1311 |
{ |
1312 |
psiconv_sketch_section result; |
1313 |
if (!(result = malloc(sizeof(*result)))) |
1314 |
goto ERROR1; |
1315 |
result->form_xsize = 320; |
1316 |
result->form_ysize = 200; |
1317 |
result->picture_x_offset = result->picture_y_offset = result->picture_xsize = |
1318 |
result->picture_ysize = 0; |
1319 |
result->magnification_x = result->magnification_y = 1.0; |
1320 |
result->cut_left = result->cut_right = result->cut_top = |
1321 |
result->cut_bottom = 0.0; |
1322 |
if (!(result->picture = psiconv_empty_paint_data_section())) |
1323 |
goto ERROR2; |
1324 |
return result; |
1325 |
ERROR2: |
1326 |
free(result); |
1327 |
ERROR1: |
1328 |
return NULL; |
1329 |
} |
1330 |
|
1331 |
psiconv_sketch_f psiconv_empty_sketch_f(void) |
1332 |
{ |
1333 |
psiconv_sketch_f result; |
1334 |
if (!(result = malloc(sizeof(*result)))) |
1335 |
goto ERROR1; |
1336 |
if (!(result->sketch_sec = psiconv_empty_sketch_section())) |
1337 |
goto ERROR2; |
1338 |
return result; |
1339 |
ERROR2: |
1340 |
free(result); |
1341 |
ERROR1: |
1342 |
return NULL; |
1343 |
} |
1344 |
|
1345 |
psiconv_cliparts psiconv_empty_cliparts(void) |
1346 |
{ |
1347 |
/* Is this correct? */ |
1348 |
return psiconv_list_new(sizeof(struct psiconv_clipart_section_s)); |
1349 |
} |
1350 |
|
1351 |
psiconv_clipart_f psiconv_empty_clipart_f(void) |
1352 |
{ |
1353 |
psiconv_clipart_f result; |
1354 |
if (!(result = malloc(sizeof(*result)))) |
1355 |
goto ERROR1; |
1356 |
if (!(result->sections = psiconv_empty_cliparts())) |
1357 |
goto ERROR2; |
1358 |
return result; |
1359 |
ERROR2: |
1360 |
free(result); |
1361 |
ERROR1: |
1362 |
return NULL; |
1363 |
} |
1364 |
|
1365 |
psiconv_file psiconv_empty_file(psiconv_file_type_t type) |
1366 |
{ |
1367 |
psiconv_file result; |
1368 |
if (!(result = malloc(sizeof(*result)))) |
1369 |
return NULL; |
1370 |
result->type = type; |
1371 |
if (type == psiconv_word_file) { |
1372 |
if (!(result->file = psiconv_empty_word_f())) |
1373 |
goto ERROR; |
1374 |
} else if (type == psiconv_sheet_file) { |
1375 |
if (!(result->file = psiconv_empty_sheet_f())) |
1376 |
goto ERROR; |
1377 |
} else if (type == psiconv_texted_file) { |
1378 |
if (!(result->file = psiconv_empty_texted_f())) |
1379 |
goto ERROR; |
1380 |
} else if (type == psiconv_mbm_file) { |
1381 |
if (!(result->file = psiconv_empty_mbm_f())) |
1382 |
goto ERROR; |
1383 |
} else if (type == psiconv_sketch_file) { |
1384 |
if (!(result->file = psiconv_empty_sketch_f())) |
1385 |
goto ERROR; |
1386 |
} else if (type == psiconv_clipart_file) { |
1387 |
if (!(result->file = psiconv_empty_clipart_f())) |
1388 |
goto ERROR; |
1389 |
} else |
1390 |
goto ERROR; |
1391 |
return result; |
1392 |
ERROR: |
1393 |
free(result); |
1394 |
return NULL; |
1395 |
} |