--- psiconv/trunk/lib/psiconv/generate_layout.c 2004/02/25 20:56:43 230 +++ psiconv/trunk/lib/psiconv/generate_layout.c 2004/02/25 20:57:10 231 @@ -38,14 +38,22 @@ psiconv_progress(config,lev,0,"Writing color"); if (!value) { - psiconv_error(config,0,psiconv_buffer_length(buf),"Null color"); - return -PSICONV_E_GENERATE; + psiconv_error(config,lev,0,"Null color"); + res = -PSICONV_E_GENERATE; + goto ERROR; } if ((res = psiconv_write_u8(config,buf,lev+1,value->red))) - return res; + goto ERROR; if ((res = psiconv_write_u8(config,buf,lev+1,value->green))) - return res; - return psiconv_write_u8(config,buf,lev+1,value->blue); + goto ERROR; + if ((res = psiconv_write_u8(config,buf,lev+1,value->blue))) + goto ERROR; + psiconv_progress(config,lev,0,"End of color"); + return 0; + +ERROR: + psiconv_error(config,lev,0,"Writing of color failed"); + return res; } int psiconv_write_font(const psiconv_config config, psiconv_buffer buf, @@ -56,14 +64,22 @@ psiconv_progress(config,lev,0,"Writing font"); if (!value) { psiconv_error(config,0,psiconv_buffer_length(buf),"Null font"); - return -PSICONV_E_GENERATE; + res = -PSICONV_E_GENERATE; + goto ERROR; } len = psiconv_unicode_strlen(value->name); if ((res = psiconv_write_u8(config,buf,lev+1,len+1))) - return res; + goto ERROR; if ((res = psiconv_write_charlist(config,buf,lev+1,value->name))) - return res; - return psiconv_write_u8(config,buf,lev+1,value->screenfont); + goto ERROR; + if ((res = psiconv_write_u8(config,buf,lev+1,value->screenfont))) + goto ERROR; + psiconv_progress(config,lev,0,"End of font"); + return 0; + +ERROR: + psiconv_error(config,lev,0,"Writing of font failed"); + return res; } int psiconv_write_border(const psiconv_config config, psiconv_buffer buf,int lev, const psiconv_border value) @@ -73,11 +89,12 @@ psiconv_progress(config,lev,0,"Writing border"); if (!value) { - psiconv_error(config,0,psiconv_buffer_length(buf),"Null border"); - return -PSICONV_E_GENERATE; + psiconv_error(config,lev,0,"Null border"); + res = -PSICONV_E_GENERATE; + goto ERROR; } if (value->kind > psiconv_border_dotdotdashed) - psiconv_warn(config,0,psiconv_buffer_length(buf), + psiconv_warn(config,lev,0, "Unknown border kind (%d); assuming none",value->kind); if ((res =psiconv_write_u8(config,buf,lev+1, value->kind == psiconv_border_none?0: @@ -88,15 +105,23 @@ value->kind == psiconv_border_dotdashed?5: value->kind == psiconv_border_dotdotdashed?6: 0))) - return res; - if ((res = psiconv_write_size(config,buf,lev+1,(value->kind == psiconv_border_solid) || - (value->kind == psiconv_border_double) ? - value->thickness:1.0/20.0))) - return res; + goto ERROR; + if ((res = psiconv_write_size(config,buf,lev+1, + (value->kind == psiconv_border_solid) || + (value->kind == psiconv_border_double) ? + value->thickness:1.0/20.0))) + goto ERROR; if ((res = psiconv_write_color(config,buf,lev+1,value->color))) - return res; + goto ERROR; /* Unknown byte */ - return psiconv_write_u8(config,buf,lev+1,1); + if ((res = psiconv_write_u8(config,buf,lev+1,1))) + goto ERROR; + psiconv_progress(config,lev,0,"End of border"); + return 0; + +ERROR: + psiconv_error(config,lev,0,"Writing of border failed"); + return res; } int psiconv_write_bullet(const psiconv_config config, psiconv_buffer buf,int lev, const psiconv_bullet value) @@ -108,29 +133,37 @@ if (!value) { psiconv_error(config,0,psiconv_buffer_length(buf),"Null bullet"); - return -PSICONV_E_GENERATE; + res = -PSICONV_E_GENERATE; + goto ERROR1; } - if (!(extra_buf = psiconv_buffer_new())) - return -PSICONV_E_NOMEM; + if (!(extra_buf = psiconv_buffer_new())) { + res = -PSICONV_E_NOMEM; + goto ERROR1; + } if ((res = psiconv_write_size(config,extra_buf,lev+1,value->font_size))) - goto ERROR; + goto ERROR2; if ((res = psiconv_unicode_write_char(config,extra_buf,lev+1, value->character))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_bool(config,extra_buf,lev+1,value->indent))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_color(config,extra_buf,lev+1,value->color))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_font(config,extra_buf,lev+1,value->font))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_u8(config,buf,lev+1,psiconv_buffer_length(extra_buf)))) - goto ERROR; + goto ERROR2; res = psiconv_buffer_concat(buf,extra_buf); -ERROR: +ERROR2: psiconv_buffer_free(extra_buf); +ERROR1: + if (res) + psiconv_error(config,lev,0,"Writing of bullet failed"); + else + psiconv_progress(config,lev,0,"End of bullet"); return res; } @@ -141,18 +174,26 @@ psiconv_progress(config,lev,0,"Writing tab"); if (!value) { - psiconv_error(config,0,psiconv_buffer_length(buf),"Null tab"); - return -PSICONV_E_GENERATE; + psiconv_error(config,lev,0,"Null tab"); + res = -PSICONV_E_GENERATE; + goto ERROR; } if ((res = psiconv_write_length(config,buf,lev+1,value->location))) - return res; + goto ERROR; if ((value->kind != psiconv_tab_left) && (value->kind != psiconv_tab_right) && (value->kind != psiconv_tab_centre)) - psiconv_warn(config,0,psiconv_buffer_length(buf), + psiconv_warn(config,lev,0, "Unknown tab kind (%d); assuming left",value->kind); - return psiconv_write_u8(config,buf,lev+1, value->kind == psiconv_tab_right?2: - value->kind == psiconv_tab_centre?3:1); + if ((res = psiconv_write_u8(config,buf,lev+1, + value->kind == psiconv_tab_right?2: + value->kind == psiconv_tab_centre?3:1))) + goto ERROR; + psiconv_progress(config,lev,0,"End of tab"); + return 0; +ERROR: + psiconv_error(config,lev,0,"Writing of tab failed"); + return res; } int psiconv_write_paragraph_layout_list(const psiconv_config config, @@ -167,58 +208,61 @@ psiconv_progress(config,lev,0,"Writing paragraph layout list"); if (!value) { - psiconv_error(config,0,psiconv_buffer_length(buf),"Null paragraph layout list"); - return -PSICONV_E_GENERATE; + psiconv_error(config,lev,0,"Null paragraph layout list"); + res = -PSICONV_E_GENERATE; + goto ERROR1; + } + if (!(extra_buf = psiconv_buffer_new())) { + res = -PSICONV_E_NOMEM; + goto ERROR1; } - if (!(extra_buf = psiconv_buffer_new())) - return -PSICONV_E_NOMEM; if (!base || psiconv_compare_color(base->back_color,value->back_color)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x01))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_color(config,extra_buf,lev+1,value->back_color))) - goto ERROR; + goto ERROR2; } if (!base || (value->indent_left != base->indent_left)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x02))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_length(config,extra_buf,lev+1,value->indent_left))) - goto ERROR; + goto ERROR2; } if (!base || (value->indent_right != base->indent_right)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x03))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_length(config,extra_buf,lev+1,value->indent_right))) - goto ERROR; + goto ERROR2; } if (!base || (value->indent_first != base->indent_first)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x04))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_length(config,extra_buf,lev+1,value->indent_first))) - goto ERROR; + goto ERROR2; } if (!base || (value->justify_hor != base->justify_hor)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x05))) - goto ERROR; + goto ERROR2; if ((value->justify_hor < psiconv_justify_left) || (value->justify_hor > psiconv_justify_full)) - psiconv_warn(config,0,psiconv_buffer_length(buf), + psiconv_warn(config,lev,0, "Unknown horizontal justify (%d); assuming left", value->justify_hor); if ((res = psiconv_write_u8(config,extra_buf,lev+1, value->justify_hor == psiconv_justify_centre?1: value->justify_hor == psiconv_justify_right?2: value->justify_hor == psiconv_justify_full?3:0))) - goto ERROR; + goto ERROR2; } if (!base || (value->justify_ver != base->justify_ver)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x06))) - goto ERROR; + goto ERROR2; if ((value->justify_ver < psiconv_justify_top) || (value->justify_ver > psiconv_justify_bottom)) psiconv_warn(config,0,psiconv_buffer_length(buf), @@ -227,122 +271,122 @@ if ((res = psiconv_write_u8(config,extra_buf,lev+1, value->justify_ver == psiconv_justify_centre?1: value->justify_ver == psiconv_justify_right?2:0))) - goto ERROR; + goto ERROR2; } if (!base || (value->linespacing != base->linespacing)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x07))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_size(config,extra_buf,lev+1,value->linespacing))) - goto ERROR; + goto ERROR2; } if (!base || (value->linespacing_exact != base->linespacing_exact)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x08))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_bool(config,extra_buf,lev+1,value->linespacing_exact))) - goto ERROR; + goto ERROR2; } if (!base || (value->space_above != base->space_above)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x09))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_size(config,extra_buf,lev+1,value->space_above))) - goto ERROR; + goto ERROR2; } if (!base || (value->space_below != base->space_below)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x0a))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_size(config,extra_buf,lev+1,value->space_below))) - goto ERROR; + goto ERROR2; } if (!base || (value->keep_together != base->keep_together)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x0b))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_bool(config,extra_buf,lev+1,value->keep_together))) - goto ERROR; + goto ERROR2; } if (!base || (value->keep_with_next != base->keep_with_next)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x0c))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_bool(config,extra_buf,lev+1,value->keep_with_next))) - goto ERROR; + goto ERROR2; } if (!base || (value->on_next_page != base->on_next_page)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x0d))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_bool(config,extra_buf,lev+1,value->on_next_page))) - goto ERROR; + goto ERROR2; } if (!base || (value->no_widow_protection != base->no_widow_protection)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x0e))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_bool(config,extra_buf,lev+1,value->no_widow_protection))) - goto ERROR; + goto ERROR2; } if (!base || (value->wrap_to_fit_cell != base->wrap_to_fit_cell)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x0f))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_bool(config,extra_buf,lev+1,value->wrap_to_fit_cell))) - goto ERROR; + goto ERROR2; } if (!base || (value->border_distance != base->border_distance)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x10))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_length(config,extra_buf,lev+1,value->border_distance))) - goto ERROR; + goto ERROR2; } if (!base || psiconv_compare_border(value->top_border,base->top_border)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x11))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_border(config,extra_buf,lev+1,value->top_border))) - goto ERROR; + goto ERROR2; } if (!base || psiconv_compare_border(value->bottom_border, base->bottom_border)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x12))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_border(config,extra_buf,lev+1,value->bottom_border))) - goto ERROR; + goto ERROR2; } if (!base || psiconv_compare_border(value->left_border, base->left_border)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x13))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_border(config,extra_buf,lev+1,value->left_border))) - goto ERROR; + goto ERROR2; } if (!base || psiconv_compare_border(value->right_border, base->right_border)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x14))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_border(config,extra_buf,lev+1,value->right_border))) - goto ERROR; + goto ERROR2; } if (!base || psiconv_compare_bullet(value->bullet, base->bullet)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x15))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_bullet(config,extra_buf,lev+1,value->bullet))) - goto ERROR; + goto ERROR2; } if (!value->tabs || !value->tabs->extras) { psiconv_error(config,0,psiconv_buffer_length(buf),"Null tabs"); res = -PSICONV_E_GENERATE; - goto ERROR; + goto ERROR2; } /* It is not entirely clear how tabs are inherited. For now, I assume @@ -350,29 +394,34 @@ the normal tab-interval, and all specific tabs */ if (!base || psiconv_compare_all_tabs(value->tabs,base->tabs)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x16))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_length(config,extra_buf,lev+1,value->tabs->normal))) - goto ERROR; + goto ERROR2; for (i = 0; i < psiconv_list_length(value->tabs->extras); i++) { if (!(tab = psiconv_list_get(value->tabs->extras,i))) { - psiconv_error(config,0,psiconv_buffer_length(buf),"Massive memory corruption"); + psiconv_error(config,lev+1,0,"Massive memory corruption"); res = -PSICONV_E_NOMEM; - goto ERROR; + goto ERROR2; } if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x17))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_tab(config,extra_buf,lev+1,tab))) - goto ERROR; + goto ERROR2; } } if ((res = psiconv_write_u32(config,buf,lev+1,psiconv_buffer_length(extra_buf)))) - goto ERROR; + goto ERROR2; res = psiconv_buffer_concat(buf,extra_buf); -ERROR: +ERROR2: psiconv_buffer_free(extra_buf); +ERROR1: + if (res) + psiconv_error(config,lev,0,"Writing of paragraph layout list failed"); + else + psiconv_progress(config,lev,0,"End of paragraph layout list"); return res; } @@ -387,89 +436,96 @@ psiconv_progress(config,lev,0,"Writing character layout list"); if (!value) { - psiconv_error(config,0,psiconv_buffer_length(buf),"Null character layout list"); - return -PSICONV_E_GENERATE; + psiconv_error(config,lev,0,"Null character layout list"); + res = -PSICONV_E_GENERATE; + goto ERROR1; + } + if (!(extra_buf = psiconv_buffer_new())) { + res = -PSICONV_E_NOMEM; + goto ERROR1; } - if (!(extra_buf = psiconv_buffer_new())) - return -PSICONV_E_NOMEM; if (!base || psiconv_compare_color(base->color,value->color)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x19))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_color(config,extra_buf,lev+1,value->color))) - goto ERROR; + goto ERROR2; } if (!base || psiconv_compare_color(base->back_color,value->back_color)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x1a))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_color(config,extra_buf,lev+1,value->back_color))) - goto ERROR; + goto ERROR2; } if (!base || (value->font_size != base->font_size)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x1c))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_size(config,extra_buf,lev+1,value->font_size))) - goto ERROR; + goto ERROR2; } if (!base || (value->italic != base->italic)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x1d))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_bool(config,extra_buf,lev+1,value->italic))) - goto ERROR; + goto ERROR2; } if (!base || (value->bold != base->bold)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x1e))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_bool(config,extra_buf,lev+1,value->bold))) - goto ERROR; + goto ERROR2; } if (!base || (value->super_sub != base->super_sub)) { if ((value->super_sub != psiconv_superscript) && (value->super_sub != psiconv_subscript) && (value->super_sub != psiconv_normalscript)) - psiconv_warn(config,0,psiconv_buffer_length(buf), - "Unknown supersubscript (%d); assuming normal", + psiconv_warn(config,lev,0,"Unknown supersubscript (%d); assuming normal", value->super_sub); if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x1f))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_u8(config,extra_buf,lev+1, value->super_sub == psiconv_superscript?1: value->super_sub == psiconv_subscript?2:0))) - goto ERROR; + goto ERROR2; } if (!base || (value->underline != base->underline)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x20))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_bool(config,extra_buf,lev+1,value->underline))) - goto ERROR; + goto ERROR2; } if (!base || (value->strikethrough != base->strikethrough)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x21))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_bool(config,extra_buf,lev+1,value->strikethrough))) - goto ERROR; + goto ERROR2; } if (!base || psiconv_compare_font(base->font,value->font)) { if ((res = psiconv_write_u8(config,extra_buf,lev+1,0x22))) - goto ERROR; + goto ERROR2; if ((res = psiconv_write_font(config,extra_buf,lev+1,value->font))) - goto ERROR; + goto ERROR2; } if ((res = psiconv_write_u32(config,buf,lev+1,psiconv_buffer_length(extra_buf)))) - goto ERROR; + goto ERROR2; res = psiconv_buffer_concat(buf,extra_buf); -ERROR: +ERROR2: psiconv_buffer_free(extra_buf); +ERROR1: + if (res) + psiconv_error(config,lev,0,"Writing of character layout list failed"); + else + psiconv_progress(config,lev,0,"End of character layout list"); return res; }