--- psiconv/trunk/lib/psiconv/generate_common.c 2004/01/06 20:15:01 184 +++ psiconv/trunk/lib/psiconv/generate_common.c 2004/02/26 15:58:48 232 @@ -1,6 +1,6 @@ /* generate_common.c - Part of psiconv, a PSION 5 file formats converter - Copyright (c) 2000 Frodo Looijaard + Copyright (c) 2000-2004 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 @@ -43,12 +43,20 @@ int res; psiconv_progress(config,lev,0,"Writing header section"); if ((res = psiconv_write_u32(config,buf,lev+1,uid1))) - return res; + goto ERROR; if ((res = psiconv_write_u32(config,buf,lev+1,uid2))) - return res; + goto ERROR; if ((res = psiconv_write_u32(config,buf,lev+1,uid3))) - return res; - return psiconv_write_u32(config,buf,lev+1,psiconv_checkuid(uid1,uid2,uid3)); + goto ERROR; + if ((res = psiconv_write_u32(config,buf,lev+1, + psiconv_checkuid(uid1,uid2,uid3)))) + goto ERROR; + psiconv_progress(config,lev,0,"End of header section"); + return 0; + +ERROR: + psiconv_error(config,lev,0,"Writing of header section failed"); + return res; } int psiconv_write_section_table_section(const psiconv_config config, @@ -60,23 +68,30 @@ psiconv_progress(config,lev,0,"Writing section table section"); if (!value) { - psiconv_error(config,0,psiconv_buffer_length(buf),"Null section table section"); - return -PSICONV_E_GENERATE; + psiconv_error(config,lev,0,"Null section table section"); + res = -PSICONV_E_GENERATE; + goto ERROR; } if ((res = psiconv_write_u8(config,buf,lev+1,2 * psiconv_list_length(value)))) - return res; + goto ERROR; for (i = 0; i < psiconv_list_length(value); i++) { if (!(entry = psiconv_list_get(value,i))) { - psiconv_error(config,0,psiconv_buffer_length(buf),"Massive memory corruption"); - return -PSICONV_E_NOMEM; + psiconv_error(config,lev+1,0,"Massive memory corruption"); + res = -PSICONV_E_NOMEM; + goto ERROR; } if ((res = psiconv_write_u32(config,buf,lev+1,entry->id))) - return res; + goto ERROR; if ((res = psiconv_write_offset(config,buf,lev+1,entry->offset))) - return res; + goto ERROR; } + psiconv_progress(config,lev,0,"End of section table section"); return -PSICONV_E_OK; + +ERROR: + psiconv_error(config,lev,0,"Writing of section table section failed"); + return res; } int psiconv_write_application_id_section(const psiconv_config config, @@ -86,8 +101,14 @@ int res; psiconv_progress(config,lev,0,"Writing application id section"); if ((res = psiconv_write_u32(config,buf,lev+1,id))) - return res; - return psiconv_write_string(config,buf,lev+1,text); + goto ERROR; + if ((res = psiconv_write_string(config,buf,lev+1,text))) + goto ERROR; + psiconv_progress(config,lev,0,"End of application id section"); + return 0; +ERROR: + psiconv_error(config,lev,0,"Writing of application id section failed"); + return res; } int psiconv_write_text_section(const psiconv_config config, @@ -95,40 +116,49 @@ const psiconv_text_and_layout value) { int res; - psiconv_buffer extra_buf; + psiconv_buffer extra_buf = NULL; int i,j; psiconv_paragraph paragraph; psiconv_progress(config,lev,0,"Writing text section"); if (!value) { - psiconv_error(config,0,psiconv_buffer_length(buf),"Null text section"); - return -PSICONV_E_GENERATE; + psiconv_error(config,lev+1,0,"Null text section"); + res = -PSICONV_E_GENERATE; + goto ERROR; } if (psiconv_list_length(value)) { - if (!(extra_buf = psiconv_buffer_new())) - return -PSICONV_E_NOMEM; + if (!(extra_buf = psiconv_buffer_new())) { + res = -PSICONV_E_NOMEM; + goto ERROR; + } for (i = 0; i < psiconv_list_length(value); i++) { if (!(paragraph = psiconv_list_get(value,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; } for (j = 0; j < psiconv_unicode_strlen(paragraph->text); j++) - if ((res = psiconv_write_u8(config,extra_buf,lev+1, - psiconv_unicode_to_char(config,paragraph->text[j])))) + if ((res = psiconv_unicode_write_char(config,extra_buf,lev+1, + paragraph->text[j]))) goto ERROR; - psiconv_write_u8(config,extra_buf,lev+1,0x06); + psiconv_unicode_write_char(config,extra_buf,lev+1,0x06); } if ((res = psiconv_write_X(config,buf,lev+1,psiconv_buffer_length(extra_buf)))) goto ERROR; res = psiconv_buffer_concat(buf,extra_buf); } else /* Hack: empty text sections are just not allowed */ - return psiconv_write_u16(config,buf,lev+1,0x0602); + if ((res = psiconv_write_u16(config,buf,lev+1,0x0602))) + goto ERROR; + + psiconv_progress(config,lev,0,"End of text section"); + return 0; ERROR: - psiconv_buffer_free(extra_buf); + if (extra_buf) + psiconv_buffer_free(extra_buf); + psiconv_error(config,lev,0,"Writing of text section failed"); return res; } @@ -158,8 +188,9 @@ psiconv_progress(config,lev,0,"Writing layout section"); if (!value) { - psiconv_error(config,0,psiconv_buffer_length(buf),"Null text section"); - return -PSICONV_E_GENERATE; + psiconv_error(config,lev,0,"Null text section"); + res = -PSICONV_E_GENERATE; + goto ERROR1; } if (!(paragraph_type_list = psiconv_list_new(sizeof(new_type)))) { @@ -189,7 +220,7 @@ for (i = 0; i < psiconv_list_length(value); i++) { if (!(paragraph = psiconv_list_get(value,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 ERROR6; } @@ -199,8 +230,10 @@ /* We need it for the next if-statement */ if (psiconv_list_length(paragraph->in_lines) == 1) - if (!(in_line = psiconv_list_get(paragraph->in_lines,1))) + if (!(in_line = psiconv_list_get(paragraph->in_lines,1))) { + res = -PSICONV_E_NOMEM; goto ERROR6; + } if ((psiconv_list_length(paragraph->in_lines) > 1) || ((psiconv_list_length(paragraph->in_lines) == 1) && @@ -210,7 +243,7 @@ if ((res = psiconv_write_u8(config,buf_elements,lev+1,0x00))) goto ERROR6; if (!(style = psiconv_get_style(styles,paragraph->base_style))) { - psiconv_error(config,0,psiconv_buffer_length(buf),"Unknown style"); + psiconv_error(config,lev+1,0,"Unknown style"); res = -PSICONV_E_GENERATE; goto ERROR6; } @@ -230,8 +263,7 @@ for (j = 0; j < psiconv_list_length(paragraph->in_lines); j++) { nr_of_inlines ++; if (!(in_line = psiconv_list_get(paragraph->in_lines,j))) { - psiconv_error(config,0,psiconv_buffer_length(buf), - "Massive memory corruption"); + psiconv_error(config,lev,0,"Massive memory corruption"); res = -PSICONV_E_NOMEM; goto ERROR6; } @@ -279,8 +311,7 @@ para_charlayout = paragraph->base_character; else { if (!(in_line = psiconv_list_get(paragraph->in_lines,0))) { - psiconv_error(config,0,psiconv_buffer_length(buf), - "Massive memory corruption"); + psiconv_error(config,lev,0,"Massive memory corruption"); res = -PSICONV_E_NOMEM; goto ERROR6; } @@ -288,8 +319,7 @@ } for (j = 0; j < psiconv_list_length(paragraph_type_list); j++) { if (!(paragraph_type = psiconv_list_get(paragraph_type_list,j))) { - psiconv_error(config,0,psiconv_buffer_length(buf), - "Massive memory corruption"); + psiconv_error(config,lev,0,"Massive memory corruption"); res = -PSICONV_E_NOMEM; goto ERROR6; } @@ -315,7 +345,7 @@ if ((res = psiconv_write_u32(config,buf_types,lev+1,paragraph_type->nr))) goto ERROR6; if (!(style = psiconv_get_style(styles,paragraph_type->style))) { - psiconv_error(config,0,psiconv_buffer_length(buf),"Unknown style"); + psiconv_error(config,lev,0,"Unknown style"); res = -PSICONV_E_GENERATE; goto ERROR6; } @@ -386,6 +416,10 @@ ERROR2: psiconv_list_free(paragraph_type_list); ERROR1: + if (res) + psiconv_error(config,lev,0,"Writing of layout section failed"); + else + psiconv_progress(config,lev,0,"End of layout section"); return res; } @@ -394,8 +428,15 @@ psiconv_text_and_layout result, psiconv_word_styles_section styles) { + int res; + psiconv_progress(config,lev,0,"Writing styled layout section"); - return psiconv_write_layout_section(config,buf,lev+1,result,styles,1); + res = psiconv_write_layout_section(config,buf,lev+1,result,styles,1); + if (res) + psiconv_error(config,lev,0,"Writing of styles layout section failed"); + else + psiconv_progress(config,lev,0,"End of styled layout section"); + return res; } int psiconv_write_styleless_layout_section(const psiconv_config config, @@ -419,8 +460,7 @@ psiconv_clone_paragraph_layout(base_para))) goto ERROR4; styles_section->normal->hotkey = 0; - if ((res = psiconv_unicode_from_chars(config,"", - &styles_section->normal->name))) + if (!(styles_section->normal->name = psiconv_unicode_empty_string())) goto ERROR5; if (!(styles_section->styles = psiconv_list_new(sizeof( struct psiconv_word_style_s)))) @@ -428,6 +468,7 @@ res = psiconv_write_layout_section(config,buf,lev+1,value,styles_section,0); psiconv_free_word_styles_section(styles_section); + psiconv_progress(config,lev,0,"End of styleless layout section"); return res; ERROR6: @@ -441,6 +482,7 @@ ERROR2: free(styles_section); ERROR1: + psiconv_error(config,lev,0,"Writing of styleless layout section failed"); if (!res) return -PSICONV_E_NOMEM; else @@ -458,7 +500,7 @@ psiconv_progress(config,lev,0,"Writing embedded object section"); if (!value) { - psiconv_error(config,0,psiconv_buffer_length(buf),"Null Object"); + psiconv_error(config,lev,0,"Null Object"); res = -PSICONV_E_GENERATE; goto ERROR1; } @@ -515,8 +557,7 @@ break; */ default: - psiconv_error(config,0,psiconv_buffer_length(buf), - "Unknown or unsupported object type"); + psiconv_error(config,lev,0,"Unknown or unsupported object type"); res = -PSICONV_E_GENERATE; goto ERROR2; } @@ -525,12 +566,15 @@ goto ERROR2; if ((res = psiconv_buffer_concat(buf,extra_buf))) goto ERROR2; + psiconv_buffer_free(extra_buf); + psiconv_progress(config,lev,0,"End of embedded object section"); return 0; ERROR2: psiconv_buffer_free(extra_buf); ERROR1: + psiconv_error(config,lev,0,"Writing of embedded object section failed"); return res; } @@ -544,7 +588,7 @@ psiconv_progress(config,lev,0,"Writing object display section"); if (!value) { - psiconv_error(config,0,psiconv_buffer_length(buf),"Null Object Display Section"); + psiconv_error(config,lev,0,"Null Object Display Section"); res = -PSICONV_E_GENERATE; goto ERROR1; } @@ -558,9 +602,12 @@ if ((res = psiconv_write_u32(config,buf,lev+1,0x00000000))) goto ERROR1; + psiconv_progress(config,lev,0,"End of object display section"); + return 0; ERROR1: + psiconv_error(config,lev,0,"Writing of object display section failed"); return res; } @@ -573,7 +620,7 @@ psiconv_progress(config,lev,0,"Writing object icon section"); if (!value) { - psiconv_error(config,0,psiconv_buffer_length(buf),"Null Object Icon Section"); + psiconv_error(config,lev,0,"Null Object Icon Section"); res = -PSICONV_E_GENERATE; goto ERROR1; } @@ -585,8 +632,10 @@ if ((res = psiconv_write_length(config,buf,lev+1,value->icon_height))) goto ERROR1; + psiconv_progress(config,lev,0,"End of object icon section"); return 0; ERROR1: + psiconv_error(config,lev,0,"Writing of object icon section failed"); return res; }