--- psiconv/trunk/lib/psiconv/data.c 2000/12/25 14:34:17 78 +++ psiconv/trunk/lib/psiconv/data.c 2000/12/30 22:17:59 87 @@ -22,6 +22,7 @@ #include #include #include "data.h" +#include "list.h" static psiconv_color clone_color(psiconv_color color); static psiconv_font clone_font(psiconv_font font); @@ -34,6 +35,23 @@ static void psiconv_free_paint_data_section_aux(void * section); static void psiconv_free_clipart_section_aux(void * section); +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_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) @@ -760,3 +778,306 @@ 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 = 0; + 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_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_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; +}