--- psiconv/trunk/lib/psiconv/generate_common.c 2004/02/25 20:56:43 230 +++ psiconv/trunk/lib/psiconv/generate_common.c 2004/02/25 20:57:10 231 @@ -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,22 +116,25 @@ 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; } @@ -125,10 +149,16 @@ 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; } @@ -210,7 +241,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 +261,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 +309,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 +317,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 +343,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 +414,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 +426,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, @@ -427,6 +466,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: @@ -440,6 +480,7 @@ ERROR2: free(styles_section); ERROR1: + psiconv_error(config,lev,0,"Writing of styleless layout section failed"); if (!res) return -PSICONV_E_NOMEM; else @@ -457,7 +498,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; } @@ -514,8 +555,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; } @@ -526,11 +566,13 @@ 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 +586,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 +600,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 +618,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 +630,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; }