--- psiconv/trunk/lib/psiconv/generate_common.c 2000/12/30 22:17:59 87 +++ psiconv/trunk/lib/psiconv/generate_common.c 2000/12/31 01:36:30 88 @@ -92,22 +92,26 @@ return -PSICONV_E_GENERATE; } - if (!(extra_buf = psiconv_buffer_new())) - return -PSICONV_E_NOMEM; - for (i = 0; i < psiconv_list_length(value); i++) { - if (!(paragraph = psiconv_list_get(value,i))) { - psiconv_warn(0,psiconv_buffer_length(buf),"Massive memory corruption"); - res = -PSICONV_E_OTHER; - goto ERROR; - } - for (j = 0; j < strlen(paragraph->text); j++) - if ((res = psiconv_write_u8(extra_buf,paragraph->text[j]))) + if (psiconv_list_length(value)) { + if (!(extra_buf = psiconv_buffer_new())) + return -PSICONV_E_NOMEM; + for (i = 0; i < psiconv_list_length(value); i++) { + if (!(paragraph = psiconv_list_get(value,i))) { + psiconv_warn(0,psiconv_buffer_length(buf),"Massive memory corruption"); + res = -PSICONV_E_OTHER; goto ERROR; - psiconv_write_u8(extra_buf,0x06); - } - if ((res = psiconv_write_X(buf,psiconv_buffer_length(extra_buf)))) - goto ERROR; - res = psiconv_buffer_concat(buf,extra_buf); + } + for (j = 0; j < strlen(paragraph->text); j++) + if ((res = psiconv_write_u8(extra_buf,paragraph->text[j]))) + goto ERROR; + psiconv_write_u8(extra_buf,0x06); + } + if ((res = psiconv_write_X(buf,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(buf,0x0602); ERROR: psiconv_buffer_free(extra_buf); @@ -133,7 +137,7 @@ psiconv_paragraph paragraph; psiconv_in_line_layout in_line; psiconv_word_style style; - int i,j,para_type,nr_of_inlines=0,res; + int i,j,para_type,nr_of_inlines=0,res,ptl_length,pel_length; if (!value) { psiconv_warn(0,psiconv_buffer_length(buf),"Null text section"); @@ -257,14 +261,37 @@ } } + /* HACK: special case: no paragraphs at all. We need to improvize. */ + if (!psiconv_list_length(value)) { + if ((res = psiconv_write_u32(buf_types,1))) + goto ERROR5; + if ((res = psiconv_write_u32(buf_types,0))) + goto ERROR5; + if (with_styles) + if ((res = psiconv_write_u8(buf_types,0))) + goto ERROR5; + if ((res = psiconv_write_u32(buf_types,0))) + goto ERROR5; + + if ((res = psiconv_write_u32(buf_elements,1))) + goto ERROR5; + if ((res = psiconv_write_u8(buf_elements,1))) + goto ERROR5; + pel_length = 1; + ptl_length = 1; + } else { + pel_length = psiconv_list_length(value); + ptl_length = psiconv_list_length(paragraph_type_list); + } + /* Now append everything */ if ((res = psiconv_write_u16(buf,with_styles?0x0001:0x0000))) goto ERROR5; - if ((res = psiconv_write_u8(buf,psiconv_list_length(paragraph_type_list)))) + if ((res = psiconv_write_u8(buf, ptl_length))) goto ERROR5; if ((res = psiconv_buffer_concat(buf,buf_types))) goto ERROR5; - if ((res = psiconv_write_u32(buf,psiconv_list_length(value)))) + if ((res = psiconv_write_u32(buf,pel_length))) goto ERROR5; if ((res = psiconv_buffer_concat(buf,buf_elements))) goto ERROR5;