--- psiconv/trunk/lib/psiconv/data.c 1999/12/03 23:13:55 42 +++ psiconv/trunk/lib/psiconv/data.c 2001/07/01 13:14:19 121 @@ -1,6 +1,6 @@ /* data.c - Part of psiconv, a PSION 5 file formats converter - Copyright (c) 1999 Frodo Looijaard + Copyright (c) 1999, 2000 Frodo Looijaard This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,7 +23,6 @@ #include #include "data.h" #include "list.h" -#include "general.h" static psiconv_color clone_color(psiconv_color color); static psiconv_font clone_font(psiconv_font font); @@ -35,28 +34,54 @@ static void psiconv_free_paragraph_aux(void * paragraph); static void psiconv_free_paint_data_section_aux(void * section); static void psiconv_free_clipart_section_aux(void * section); +static void psiconv_free_formula_aux(void *data); +static void psiconv_free_sheet_worksheet_aux (void *data); +static psiconv_word_styles_section psiconv_empty_word_styles_section(void); +static psiconv_text_and_layout psiconv_empty_text_and_layout(void); +static psiconv_texted_section psiconv_empty_texted_section(void); +static psiconv_page_header psiconv_empty_page_header(void); +static psiconv_page_layout_section psiconv_empty_page_layout_section(void); +static psiconv_word_status_section psiconv_empty_word_status_section(void); +static psiconv_word_f psiconv_empty_word_f(void); +static psiconv_sheet_status_section psiconv_empty_sheet_status_section(void); +static psiconv_formula_list psiconv_empty_formula_list(void); +static psiconv_sheet_workbook_section + psiconv_empty_sheet_workbook_section(void); +static psiconv_sheet_f psiconv_empty_sheet_f(void); +static psiconv_texted_f psiconv_empty_texted_f(void); +static psiconv_paint_data_section psiconv_empty_paint_data_section(void); +static psiconv_pictures psiconv_empty_pictures(void); +static psiconv_mbm_f psiconv_empty_mbm_f(void); +static psiconv_sketch_section psiconv_empty_sketch_section(void); +static psiconv_sketch_f psiconv_empty_sketch_f(void); +static psiconv_clipart_f psiconv_empty_clipart_f(void); +static psiconv_cliparts psiconv_empty_cliparts(void); + + +/* Note: these defaults seem to be hard-coded somewhere outside the + files themself. */ psiconv_character_layout psiconv_basic_character_layout(void) { /* Make the structures static, to oblige IRIX */ - static struct psiconv_color black = + static struct psiconv_color_s black = { 0x00, /* red */ 0x00, /* green */ 0x00, /* blue */ }; - static struct psiconv_color white = + static struct psiconv_color_s white = { 0xff, /* red */ 0xff, /* green */ 0xff, /* blue */ }; - static struct psiconv_font font = + static struct psiconv_font_s font = { "Times New Roman", /* name */ 3 /* screenfont */ }; - struct psiconv_character_layout cl = + struct psiconv_character_layout_s cl = { &black, /* color */ &white, /* back_color */ @@ -65,39 +90,41 @@ psiconv_bool_false, /* bold */ psiconv_normalscript, /* super_sub */ psiconv_bool_false, /* underline */ - psiconv_bool_false, /* strike_out */ + psiconv_bool_false, /* strikethrough */ &font, /* font */ }; return psiconv_clone_character_layout(&cl); } +/* Note: these defaults seem to be hard-coded somewhere outside the + files themself. */ psiconv_paragraph_layout psiconv_basic_paragraph_layout(void) { - static struct psiconv_font font = + static struct psiconv_font_s font = { "Times New Roman", /* name */ 2 /* screenfont */ }; - static struct psiconv_color black = + static struct psiconv_color_s black = { 0x00, /* red */ 0x00, /* green */ 0x00, /* blue */ }; - static struct psiconv_color white = + static struct psiconv_color_s white = { 0xff, /* red */ 0xff, /* green */ 0xff, /* blue */ }; - static struct psiconv_border no_border = + static struct psiconv_border_s no_border = { psiconv_border_none, /* kind */ 1, /* thickness */ &black /* color */ }; - static struct psiconv_bullet bullet = + static struct psiconv_bullet_s bullet = { psiconv_bool_false, /* on */ 10.0, /* font_size */ @@ -106,12 +133,12 @@ &black, /* color */ &font, /* font */ }; - static struct psiconv_all_tabs tabs = + static struct psiconv_all_tabs_s tabs = { 0.64, /* normal */ NULL /* kind */ }; - struct psiconv_paragraph_layout pl = + struct psiconv_paragraph_layout_s pl = { &white, /* back_color */ 0.0, /* indent_left */ @@ -119,14 +146,15 @@ 0.0, /* indent_first */ psiconv_justify_left, /* justify_hor */ psiconv_justify_middle,/* justify_ver */ - 0.0, /* interline */ - psiconv_bool_false, /* interline_exact */ - 0.0, /* top_space */ - 0.0, /* bottom_space */ - psiconv_bool_false, /* on_one_page */ - psiconv_bool_false, /* together_with */ + 10.0, /* linespacing */ + psiconv_bool_false, /* linespacing_exact */ + 0.0, /* space_above */ + 0.0, /* space_below */ + psiconv_bool_false, /* keep_together */ + psiconv_bool_false, /* keep_with_next */ psiconv_bool_false, /* on_next_page */ psiconv_bool_false, /* no_widow_protection */ + psiconv_bool_false, /* wrap_to_fit_cell */ 0.0, /* left_margin */ &bullet, /* bullet */ &no_border, /* left_border */ @@ -137,7 +165,8 @@ }; psiconv_paragraph_layout res; - pl.tabs->extras = psiconv_list_new(sizeof(struct psiconv_tab)); + if (!(pl.tabs->extras = psiconv_list_new(sizeof(struct psiconv_tab_s)))) + return NULL; res = psiconv_clone_paragraph_layout(&pl); psiconv_list_free(pl.tabs->extras); return res; @@ -146,7 +175,8 @@ psiconv_color clone_color(psiconv_color color) { psiconv_color result; - result = malloc(sizeof(*result)); + if (!(result = malloc(sizeof(*result)))) + return NULL; *result = *color; return result; } @@ -154,38 +184,65 @@ psiconv_font clone_font(psiconv_font font) { psiconv_font result; - result = malloc(sizeof(*result)); + if(!(result = malloc(sizeof(*result)))) + goto ERROR1; *result = *font; - result->name = strdup(result->name); + if (!(result->name = strdup(result->name))) + goto ERROR2; return result; +ERROR2: + free(result); +ERROR1: + return NULL; } psiconv_border clone_border(psiconv_border border) { psiconv_border result; - result = malloc(sizeof(*result)); + if (!(result = malloc(sizeof(*result)))) + goto ERROR1; *result = *border; - result->color = clone_color(result->color); + if(!(result->color = clone_color(result->color))) + goto ERROR2; return result; +ERROR2: + free(result); +ERROR1: + return NULL; } psiconv_bullet clone_bullet(psiconv_bullet bullet) { psiconv_bullet result; - result = malloc(sizeof(*result)); + if (!(result = malloc(sizeof(*result)))) + goto ERROR1; *result = *bullet; - result->font = clone_font(result->font); - result->color = clone_color(result->color); + if (!(result->font = clone_font(result->font))) + goto ERROR2; + if (!(result->color = clone_color(result->color))) + goto ERROR3; return result; +ERROR3: + psiconv_free_font(result->font); +ERROR2: + free(result); +ERROR1: + return NULL; } psiconv_all_tabs clone_all_tabs(psiconv_all_tabs all_tabs) { psiconv_all_tabs result; - result = malloc(sizeof(*result)); + if (!(result = malloc(sizeof(*result)))) + goto ERROR1; *result = *all_tabs; - result->extras = psiconv_list_clone(result->extras); + if (!(result->extras = psiconv_list_clone(result->extras))) + goto ERROR2; return result; +ERROR2: + free(result); +ERROR1: + return NULL; } psiconv_character_layout psiconv_clone_character_layout @@ -193,12 +250,24 @@ { psiconv_character_layout result; - result = malloc(sizeof(*result)); + if (!(result = malloc(sizeof(*result)))) + goto ERROR1; *result = *ls; - result->color = clone_color(result->color); - result->back_color = clone_color(result->back_color); - result->font = clone_font(result->font); + if (!(result->color = clone_color(result->color))) + goto ERROR2; + if (!(result->back_color = clone_color(result->back_color))) + goto ERROR3; + if (!(result->font = clone_font(result->font))) + goto ERROR4; return result; +ERROR4: + psiconv_free_color(result->back_color); +ERROR3: + psiconv_free_color(result->color); +ERROR2: + free(result); +ERROR1: + return NULL; } psiconv_paragraph_layout psiconv_clone_paragraph_layout @@ -206,16 +275,40 @@ { psiconv_paragraph_layout result; - result = malloc(sizeof(*result)); + if (!(result = malloc(sizeof(*result)))) + goto ERROR1; *result = *ls; - result->back_color = clone_color(result->back_color); - result->bullet = clone_bullet(result->bullet); - result->left_border = clone_border(result->left_border); - result->right_border = clone_border(result->right_border); - result->top_border = clone_border(result->top_border); - result->bottom_border = clone_border(result->bottom_border); - result->tabs = clone_all_tabs(result->tabs); + if (!(result->back_color = clone_color(result->back_color))) + goto ERROR2; + if (!(result->bullet = clone_bullet(result->bullet))) + goto ERROR3; + if (!(result->left_border = clone_border(result->left_border))) + goto ERROR4; + if (!(result->right_border = clone_border(result->right_border))) + goto ERROR5; + if (!(result->top_border = clone_border(result->top_border))) + goto ERROR6; + if (!(result->bottom_border = clone_border(result->bottom_border))) + goto ERROR7; + if (!(result->tabs = clone_all_tabs(result->tabs))) + goto ERROR8; return result; +ERROR8: + psiconv_free_border(result->bottom_border); +ERROR7: + psiconv_free_border(result->top_border); +ERROR6: + psiconv_free_border(result->right_border); +ERROR5: + psiconv_free_border(result->left_border); +ERROR4: + psiconv_free_bullet(result->bullet); +ERROR3: + psiconv_free_color(result->back_color); +ERROR2: + free(result); +ERROR1: + return NULL; } psiconv_word_style psiconv_get_style (psiconv_word_styles_section ss, int nr) @@ -451,6 +544,122 @@ } } +void psiconv_free_sheet_status_section(psiconv_sheet_status_section section) +{ + if (section) + free(section); +} + +void psiconv_free_sheet_numberformat(psiconv_sheet_numberformat numberformat) +{ + if (numberformat) + free(numberformat); +} + +void psiconv_free_sheet_cell_layout(psiconv_sheet_cell_layout layout) +{ + psiconv_free_paragraph_layout(layout->paragraph); + psiconv_free_character_layout(layout->character); + psiconv_free_sheet_numberformat(layout->numberformat); +} + +void psiconv_free_sheet_cell_aux(void *cell) +{ + psiconv_sheet_cell data = cell; + + psiconv_free_sheet_cell_layout(data->layout); + + if ((data->type == psiconv_cell_string) && (data->data.dat_string)) + free(data->data.dat_string); +} + +void psiconv_free_sheet_cell(psiconv_sheet_cell cell) +{ + if (cell) { + psiconv_free_sheet_cell_aux(cell); + free(cell); + } +} + +void psiconv_free_sheet_cell_list(psiconv_sheet_cell_list list) +{ + if (list) + psiconv_list_free_el(list,psiconv_free_sheet_cell_aux); +} + +void psiconv_free_sheet_worksheet_aux (void *data) +{ + psiconv_sheet_worksheet section = data; + psiconv_free_sheet_cell_layout(section->default_layout); + psiconv_free_sheet_cell_list(section->cells); +} + +void psiconv_free_sheet_worksheet(psiconv_sheet_worksheet sheet) +{ + if (sheet) { + psiconv_free_sheet_worksheet_aux(sheet); + free(sheet); + } +} + +void psiconv_free_sheet_worksheet_list(psiconv_sheet_worksheet_list list) +{ + if (list) + psiconv_list_free_el(list,psiconv_free_sheet_worksheet_aux); +} + +void psiconv_free_formula_aux(void *data) +{ + psiconv_formula formula; + formula = data; + if (formula->type == psiconv_formula_dat_string) + free(formula->data.dat_string); + else if ((formula->type != psiconv_formula_dat_int) && + (formula->type != psiconv_formula_dat_var) && + (formula->type != psiconv_formula_dat_float) && + (formula->type != psiconv_formula_dat_cellref) && + (formula->type != psiconv_formula_dat_cellblock) && + (formula->type != psiconv_formula_dat_vcellblock) && + (formula->type != psiconv_formula_mark_opsep) && + (formula->type != psiconv_formula_mark_opend) && + (formula->type != psiconv_formula_mark_eof) && + (formula->type != psiconv_formula_unknown)) + psiconv_free_formula_list(formula->data.fun_operands); +} + +void psiconv_free_formula(psiconv_formula formula) +{ + if (formula) { + psiconv_free_formula_aux(formula); + free(formula); + } +} + +void psiconv_free_formula_list(psiconv_formula_list list) +{ + if (list) + psiconv_list_free_el(list,psiconv_free_formula_aux); +} + +void psiconv_free_sheet_workbook_section(psiconv_sheet_workbook_section section) +{ + if (section) { + psiconv_free_formula_list(section->formulas); + psiconv_free_sheet_worksheet_list(section->worksheets); + free(section); + } +} + +void psiconv_free_sheet_f(psiconv_sheet_f file) +{ + if (file) { + psiconv_free_page_layout_section(file->page_sec); + psiconv_free_sheet_status_section(file->status_sec); + psiconv_free_sheet_workbook_section(file->workbook_sec); + free(file); + } +} + void psiconv_free_texted_f(psiconv_texted_f file) { if (file) { @@ -555,6 +764,507 @@ psiconv_free_sketch_f((psiconv_sketch_f) file->file); else if (file->type == psiconv_clipart_file) psiconv_free_clipart_f((psiconv_clipart_f) file->file); + else if (file->type == psiconv_sheet_file) + psiconv_free_sheet_f((psiconv_sheet_f) file->file); free(file); } } + +int psiconv_compare_color(const psiconv_color value1, + const psiconv_color value2) +{ + if (!value1 || !value2) + return 1; + if ((value1->red == value2->red) && + (value1->green == value2->green) && + (value1->blue == value2->blue)) + return 0; + else + return 1; +} + +int psiconv_compare_font(const psiconv_font value1, + const psiconv_font value2) +{ + if (!value1 || !value2 || !value1->name || !value2->name) + return 1; + if ((value1->screenfont == value2->screenfont) && + !strcmp(value1->name,value2->name)) + return 0; + else + return 1; +} + +int psiconv_compare_border(const psiconv_border value1, + const psiconv_border value2) +{ + if (!value1 || !value2) + return 1; + if ((value1->kind == value2->kind) && + (value1->thickness == value2->thickness) && + !psiconv_compare_color(value1->color,value2->color)) + return 0; + else + return 1; +} + +int psiconv_compare_bullet(const psiconv_bullet value1, + const psiconv_bullet value2) +{ + if (!value1 || !value2) + return 1; + if ((value1->on == value2->on) && + (value1->font_size == value2->font_size) && + (value1->character == value2->character) && + (value1->indent == value2->indent) && + !psiconv_compare_color(value1->color,value2->color) && + !psiconv_compare_font(value1->font,value2->font)) + return 0; + else + return 1; +} + +int psiconv_compare_tab(const psiconv_tab value1, const psiconv_tab value2) +{ + if (!value1 || !value2) + return 1; + if ((value1->location == value2->location) && + (value1->kind == value2->kind)) + return 0; + else + return 1; +} + +int psiconv_compare_all_tabs(const psiconv_all_tabs value1, + const psiconv_all_tabs value2) +{ + int i; + + if (!value1 || !value2 || !value1->extras || !value2->extras) + return 1; + + if ((value1->normal != value2->normal) || + psiconv_list_length(value1->extras) != + psiconv_list_length(value2->extras)) + return 1; + for (i = 0; i < psiconv_list_length(value1->extras); i++) + if (psiconv_compare_tab(psiconv_list_get(value1->extras,i), + psiconv_list_get(value2->extras,i))) + + return 1; + return 0; +} + +int psiconv_compare_paragraph_layout(const psiconv_paragraph_layout value1, + const psiconv_paragraph_layout value2) +{ + if (!value1 || !value2) + return 1; + if ((value1->indent_left == value2->indent_left) && + (value1->indent_right == value2->indent_right) && + (value1->indent_first == value2->indent_first) && + (value1->justify_hor == value2->justify_hor) && + (value1->justify_ver == value2->justify_ver) && + (value1->linespacing == value2->linespacing) && + (value1->space_above == value2->space_above) && + (value1->space_below == value2->space_below) && + (value1->keep_together == value2->keep_together) && + (value1->keep_with_next == value2->keep_with_next) && + (value1->on_next_page == value2->on_next_page) && + (value1->no_widow_protection == value2->no_widow_protection) && + (value1->border_distance == value2->border_distance) && + !psiconv_compare_color(value1->back_color,value2->back_color) && + !psiconv_compare_bullet(value1->bullet,value2->bullet) && + !psiconv_compare_border(value1->left_border,value2->left_border) && + !psiconv_compare_border(value1->right_border,value2->right_border) && + !psiconv_compare_border(value1->top_border,value2->top_border) && + !psiconv_compare_border(value1->bottom_border,value2->bottom_border) && + !psiconv_compare_all_tabs(value1->tabs,value2->tabs)) + return 0; + else + return 1; +} + + +int psiconv_compare_character_layout(const psiconv_character_layout value1, + const psiconv_character_layout value2) +{ + if (!value1 || !value2) + return 1; + if ((value1->font_size == value2->font_size) && + (value1->italic == value2->italic) && + (value1->bold == value2->bold) && + (value1->super_sub == value2->super_sub) && + (value1->underline == value2->underline) && + (value1->strikethrough == value2->strikethrough) && + !psiconv_compare_color(value1->color,value2->color) && + !psiconv_compare_color(value1->back_color,value2->back_color) && + !psiconv_compare_font(value1->font,value2->font)) + return 0; + else + return 1; +} + + + +psiconv_word_styles_section psiconv_empty_word_styles_section(void) +{ + psiconv_word_styles_section result; + if (!(result = malloc(sizeof(*result)))) + goto ERROR1; + if (!(result->styles = psiconv_list_new(sizeof(struct psiconv_word_style_s)))) + goto ERROR2; + if (!(result->normal = malloc(sizeof(struct psiconv_word_style_s)))) + goto ERROR3; + if (!(result->normal->character = psiconv_basic_character_layout())) + goto ERROR4; + if (!(result->normal->paragraph = psiconv_basic_paragraph_layout())) + goto ERROR5; + result->normal->hotkey = 'N'; + result->normal->name = NULL; + result->normal->built_in = psiconv_bool_true; + result->normal->outline_level = 0; + return result; +ERROR5: + psiconv_free_character_layout(result->normal->character); +ERROR4: + free(result->normal); +ERROR3: + psiconv_list_free(result->styles); +ERROR2: + free(result); +ERROR1: + return NULL; +} + +psiconv_text_and_layout psiconv_empty_text_and_layout(void) +{ + return psiconv_list_new(sizeof(struct psiconv_paragraph_s)); +} + +psiconv_texted_section psiconv_empty_texted_section(void) +{ + psiconv_texted_section result; + if (!(result = malloc(sizeof(*result)))) + goto ERROR1; + if (!(result->paragraphs = psiconv_empty_text_and_layout())) + goto ERROR2; + return result; +ERROR2: + free(result); +ERROR1: + return NULL; +} + +psiconv_page_header psiconv_empty_page_header(void) +{ + psiconv_page_header result; + if (!(result = malloc(sizeof(*result)))) + goto ERROR1; + result->on_first_page = psiconv_bool_true; + if (!(result->base_paragraph_layout = psiconv_basic_paragraph_layout())) + goto ERROR2; + if (!(result->base_character_layout = psiconv_basic_character_layout())) + goto ERROR3; + if (!(result->text = psiconv_empty_texted_section())) + goto ERROR4; + return result; +ERROR4: + psiconv_free_character_layout(result->base_character_layout); +ERROR3: + psiconv_free_paragraph_layout(result->base_paragraph_layout); +ERROR2: + free(result); +ERROR1: + return NULL; +} + +psiconv_page_layout_section psiconv_empty_page_layout_section(void) +{ + psiconv_page_layout_section result; + if (!(result = malloc(sizeof(*result)))) + goto ERROR1; + result->first_page_nr = 1; + result->header_dist = result->footer_dist = 1.27; + result->left_margin = result->right_margin = 3.175; + result->top_margin = result->bottom_margin = 2.54; + result->page_width = 21.0; + result->page_height = 29.7; + result->landscape = psiconv_bool_false; + if (!(result->header = psiconv_empty_page_header())) + goto ERROR2; + if (!(result->footer = psiconv_empty_page_header())) + goto ERROR3; + return result; +ERROR3: + psiconv_free_page_header(result->header); +ERROR2: + free(result); +ERROR1: + return NULL; +} + +psiconv_word_status_section psiconv_empty_word_status_section(void) +{ + psiconv_word_status_section result; + if (!(result = malloc(sizeof(*result)))) + return NULL; + result->show_tabs = result->show_spaces = result->show_paragraph_ends = + result->show_hard_minus = result->show_hard_space = + result->fit_lines_to_screen = psiconv_bool_false; + result->show_full_pictures = result->show_full_graphs = + result->show_top_toolbar = result->show_side_toolbar = + psiconv_bool_true; + result->cursor_position = 0; + result->display_size = 1000; + return result; +} + +psiconv_word_f psiconv_empty_word_f(void) +{ + psiconv_word_f result; + if (!(result = malloc(sizeof(*result)))) + goto ERROR1; + if (!(result->page_sec = psiconv_empty_page_layout_section())) + goto ERROR2; + if (!(result->paragraphs = psiconv_empty_text_and_layout())) + goto ERROR3; + if (!(result->status_sec = psiconv_empty_word_status_section())) + goto ERROR4; + if (!(result->styles_sec = psiconv_empty_word_styles_section())) + goto ERROR5; + return result; +ERROR5: + psiconv_free_word_status_section(result->status_sec); +ERROR4: + psiconv_free_text_and_layout(result->paragraphs); +ERROR3: + psiconv_free_page_layout_section(result->page_sec); +ERROR2: + free(result); +ERROR1: + return NULL; +} + +psiconv_sheet_status_section psiconv_empty_sheet_status_section(void) +{ + psiconv_sheet_status_section result; + if (!(result = malloc(sizeof(*result)))) + return NULL; + result->show_horizontal_scrollbar = result->show_vertical_scrollbar = + psiconv_triple_auto; + result->show_graph = psiconv_bool_false; + result->show_top_sheet_toolbar = result->show_side_sheet_toolbar = + result->show_top_graph_toolbar = result->show_side_graph_toolbar = + psiconv_bool_true; + result->cursor_row = result->cursor_column = 0; + result->sheet_display_size = result->graph_display_size = 1000; + return result; +} + +psiconv_formula_list psiconv_empty_formula_list(void) +{ + return psiconv_list_new(sizeof(struct psiconv_formula_s)); +} + +psiconv_sheet_workbook_section psiconv_empty_sheet_workbook_section(void) +{ + psiconv_sheet_workbook_section result; + if (!(result = malloc(sizeof(*result)))) + goto ERROR1; + if (!(result->formulas = psiconv_empty_formula_list())) + goto ERROR2; + return result; +ERROR2: + free(result); +ERROR1: + return NULL; +} + + +psiconv_sheet_f psiconv_empty_sheet_f(void) +{ + psiconv_sheet_f result; + if (!(result = malloc(sizeof(*result)))) + goto ERROR1; + if (!(result->page_sec = psiconv_empty_page_layout_section())) + goto ERROR2; + if (!(result->status_sec = psiconv_empty_sheet_status_section())) + goto ERROR3; + if (!(result->workbook_sec = psiconv_empty_sheet_workbook_section())) + goto ERROR4; + return result; +ERROR4: + psiconv_free_sheet_status_section(result->status_sec); +ERROR3: + psiconv_free_page_layout_section(result->page_sec); +ERROR2: + free(result); +ERROR1: + return NULL; +} + +psiconv_texted_f psiconv_empty_texted_f(void) +{ + psiconv_texted_f result; + if (!(result = malloc(sizeof(*result)))) + goto ERROR1; + if (!(result->page_sec = psiconv_empty_page_layout_section())) + goto ERROR2; + if (!(result->texted_sec = psiconv_empty_texted_section())) + goto ERROR3; + return result; +ERROR3: + psiconv_free_page_layout_section(result->page_sec); +ERROR2: + free(result); +ERROR1: + return NULL; +} + +psiconv_paint_data_section psiconv_empty_paint_data_section(void) +{ + psiconv_paint_data_section result; + if (!(result = malloc(sizeof(*result)))) + goto ERROR1; + /* Is this correct? */ + result->xsize = result->ysize = result->pic_xsize = result->pic_ysize = 0; + /* Probably forbidden... */ + if (!(result->red = malloc(0))) + goto ERROR2; + if (!(result->green = malloc(0))) + goto ERROR3; + if (!(result->blue = malloc(0))) + goto ERROR4; + return result; +ERROR4: + free(result->green); +ERROR3: + free(result->red); +ERROR2: + free(result); +ERROR1: + return NULL; +} + + +psiconv_pictures psiconv_empty_pictures(void) +{ + psiconv_pictures result; + psiconv_paint_data_section pds; + if (!(result = psiconv_list_new(sizeof(struct psiconv_paint_data_section_s)))) + goto ERROR1; + if (!(pds = psiconv_empty_paint_data_section())) + goto ERROR2; + if (psiconv_list_add(result,pds)) + goto ERROR3; + free(pds); + return result; +ERROR3: + psiconv_free_paint_data_section(pds); +ERROR2: + psiconv_list_free(result); +ERROR1: + return NULL; +} + +psiconv_mbm_f psiconv_empty_mbm_f(void) +{ + psiconv_mbm_f result; + if (!(result = malloc(sizeof(*result)))) + goto ERROR1; + if (!(result->sections = psiconv_empty_pictures())) + goto ERROR2; + return result; +ERROR2: + free(result); +ERROR1: + return NULL; +} + +psiconv_sketch_section psiconv_empty_sketch_section(void) +{ + psiconv_sketch_section result; + if (!(result = malloc(sizeof(*result)))) + goto ERROR1; + result->form_xsize = 320; + result->form_ysize = 200; + result->picture_x_offset = result->picture_y_offset = result->picture_xsize = + result->picture_ysize = 0; + result->magnification_x = result->magnification_y = 1.0; + result->cut_left = result->cut_right = result->cut_top = + result->cut_bottom = 0.0; + if (!(result->picture = psiconv_empty_paint_data_section())) + goto ERROR2; + return result; +ERROR2: + free(result); +ERROR1: + return NULL; +} + +psiconv_sketch_f psiconv_empty_sketch_f(void) +{ + psiconv_sketch_f result; + if (!(result = malloc(sizeof(*result)))) + goto ERROR1; + if (!(result->sketch_sec = psiconv_empty_sketch_section())) + goto ERROR2; + return result; +ERROR2: + free(result); +ERROR1: + return NULL; +} + +psiconv_cliparts psiconv_empty_cliparts(void) +{ + /* Is this correct? */ + return psiconv_list_new(sizeof(struct psiconv_clipart_section_s)); +} + +psiconv_clipart_f psiconv_empty_clipart_f(void) +{ + psiconv_clipart_f result; + if (!(result = malloc(sizeof(*result)))) + goto ERROR1; + if (!(result->sections = psiconv_empty_cliparts())) + goto ERROR2; + return result; +ERROR2: + free(result); +ERROR1: + return NULL; +} + +psiconv_file psiconv_empty_file(psiconv_file_type_t type) +{ + psiconv_file result; + if (!(result = malloc(sizeof(*result)))) + return NULL; + result->type = type; + if (type == psiconv_word_file) { + if (!(result->file = psiconv_empty_word_f())) + goto ERROR; + } else if (type == psiconv_sheet_file) { + if (!(result->file = psiconv_empty_sheet_f())) + goto ERROR; + } else if (type == psiconv_texted_file) { + if (!(result->file = psiconv_empty_texted_f())) + goto ERROR; + } else if (type == psiconv_mbm_file) { + if (!(result->file = psiconv_empty_mbm_f())) + goto ERROR; + } else if (type == psiconv_sketch_file) { + if (!(result->file = psiconv_empty_sketch_f())) + goto ERROR; + } else if (type == psiconv_clipart_file) { + if (!(result->file = psiconv_empty_clipart_f())) + goto ERROR; + } else + goto ERROR; + return result; +ERROR: + free(result); + return NULL; +}