--- psiconv/trunk/lib/psiconv/generate_driver.c 2000/12/24 16:03:57 73 +++ psiconv/trunk/lib/psiconv/generate_driver.c 2000/12/25 22:25:33 79 @@ -28,18 +28,14 @@ int psiconv_write(psiconv_buffer *buf,const psiconv_file value) { - int allocated = 0; int res; if (!value) { psiconv_warn(0,0,"Can't parse to an empty buffer!"); return -PSICONV_E_OTHER; } - if (!*buf) { - if (!(*buf = psiconv_new_buffer())) - return -PSICONV_E_NOMEM; - allocated = 1; - } + if (!(*buf = psiconv_buffer_new(0))) + return -PSICONV_E_NOMEM; #if 0 if (value->type == psiconv_word_file) { @@ -73,8 +69,7 @@ return -PSICONV_E_OK; ERROR: - if (allocated) - psiconv_free_buffer(*buf); + psiconv_buffer_free(*buf); return res; } @@ -102,7 +97,8 @@ goto ERROR2; } - if (!(extra_buf = psiconv_new_buffer())) { + /* Base offset is 0x18: 0x10 header section plus the section table offset */ + if (!(extra_buf = psiconv_buffer_new(0x14))) { res = -PSICONV_E_NOMEM; goto ERROR3; } @@ -123,32 +119,36 @@ entry->id = PSICONV_ID_APPL_ID_SECTION; - entry->offset = psiconv_list_length(extra_buf) + 0x14; - if ((res = psiconv_list_add(section_table,&entry))) + entry->offset = psiconv_buffer_length(extra_buf) + + psiconv_buffer_base_offset(extra_buf); + if ((res = psiconv_list_add(section_table,entry))) goto ERROR6; if ((res=psiconv_write_application_id_section(extra_buf, PSICONV_ID_TEXTED,"TextEd.app"))) goto ERROR6; entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION; - entry->offset = psiconv_list_length(extra_buf) + 0x14; - if ((res = psiconv_list_add(section_table,&entry))) + entry->offset = psiconv_buffer_length(extra_buf) + + psiconv_buffer_base_offset(extra_buf); + if ((res = psiconv_list_add(section_table,entry))) goto ERROR6; if ((res = psiconv_write_page_layout_section(extra_buf,value->page_sec))) goto ERROR6; entry->id = PSICONV_ID_TEXTED; - entry->offset = psiconv_list_length(extra_buf) + 0x14; - if ((res = psiconv_list_add(section_table,&entry))) + entry->offset = psiconv_buffer_length(extra_buf) + + psiconv_buffer_base_offset(extra_buf); + if ((res = psiconv_list_add(section_table,entry))) goto ERROR6; if ((res = psiconv_write_texted_section(extra_buf,value->texted_sec, base_char,base_para))) goto ERROR6; - if ((res = psiconv_write_u32(buf,psiconv_list_length(extra_buf) + 0x14))) + if ((res = psiconv_write_u32(buf,psiconv_buffer_length(extra_buf) + + psiconv_buffer_base_offset(extra_buf)))) goto ERROR6; - if ((res = psiconv_list_concat(buf,extra_buf))) + if ((res = psiconv_buffer_concat(buf,extra_buf))) goto ERROR6; res = psiconv_write_section_table_section(buf,section_table); @@ -158,7 +158,7 @@ ERROR5: psiconv_free_character_layout(base_char); ERROR4: - psiconv_free_buffer(extra_buf); + psiconv_buffer_free(extra_buf); ERROR3: free(entry); ERROR2: