--- psiconv/trunk/lib/psiconv/data.c 1999/12/03 23:13:55 42 +++ psiconv/trunk/lib/psiconv/data.c 2000/12/13 16:17:54 62 @@ -22,8 +22,6 @@ #include #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); @@ -39,24 +37,24 @@ 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 */ @@ -74,30 +72,30 @@ 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 +104,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 */ @@ -137,7 +135,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 +145,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 +154,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 +220,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 +245,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)