--- psiconv/trunk/lib/psiconv/generate_common.c 2000/12/25 22:25:33 79 +++ psiconv/trunk/lib/psiconv/generate_common.c 2000/12/31 01:36:30 88 @@ -64,7 +64,7 @@ } if ((res = psiconv_write_u32(buf,entry->id))) return res; - if ((res = psiconv_write_u32(buf,entry->offset))) + if ((res = psiconv_write_offset(buf,entry->offset))) return res; } return -PSICONV_E_OK; @@ -92,22 +92,26 @@ return -PSICONV_E_GENERATE; } - if (!(extra_buf = psiconv_buffer_new(0))) - 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"); @@ -145,17 +149,17 @@ goto ERROR1; } - if (!(buf_types = psiconv_buffer_new(0))) { + if (!(buf_types = psiconv_buffer_new())) { res = -PSICONV_E_NOMEM; goto ERROR2; } - if (!(buf_elements = psiconv_buffer_new(0))) { + if (!(buf_elements = psiconv_buffer_new())) { res = -PSICONV_E_NOMEM; goto ERROR3; } - if (!(buf_inlines = psiconv_buffer_new(0))) { + if (!(buf_inlines = psiconv_buffer_new())) { res = -PSICONV_E_NOMEM; goto ERROR4; } @@ -172,7 +176,7 @@ if (psiconv_list_length(paragraph->in_lines)) { /* Inline layouts, so we generate a paragraph element and inline elements */ - if ((res = psiconv_write_u32(buf_elements,0x00))) + if ((res = psiconv_write_u8(buf_elements,0x00))) goto ERROR5; if (!(style = psiconv_get_style(styles,paragraph->base_style))) { psiconv_warn(0,psiconv_buffer_length(buf),"Unknown style"); @@ -202,7 +206,7 @@ goto ERROR5; if ((res = psiconv_write_u32(buf_inlines,in_line->length))) goto ERROR5; - if ((res = psiconv_write_character_layout_list(buf_elements, + if ((res = psiconv_write_character_layout_list(buf_inlines, in_line->layout, style->character))) goto ERROR5; @@ -257,16 +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_u8(buf,with_styles?0x00:0x01))) - goto ERROR5; - if ((res = psiconv_write_u8(buf,0x00))) + 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;