--- psiconv/trunk/lib/psiconv/generate_driver.c 2000/12/24 16:03:57 73 +++ psiconv/trunk/lib/psiconv/generate_driver.c 2000/12/27 02:12:23 80 @@ -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())) + return -PSICONV_E_NOMEM; #if 0 if (value->type == psiconv_word_file) { @@ -53,15 +49,15 @@ goto ERROR; #if 0 } else if (value->type == psiconv_sketch_file) { - if ((res =psiconv_write_texted_file(*buf, + if ((res =psiconv_write_sketch_file(*buf, (psiconv_sketch_f) (value->file)))) goto ERROR; } else if (value->type == psiconv_mbm_file) { - if ((res =psiconv_write_texted_file(*buf, + if ((res =psiconv_write_mbm_file(*buf, (psiconv_mbm_f) (value->file)))) goto ERROR; } else if (value->type == psiconv_clipart_file) { - if ((res =psiconv_write_texted_file(*buf, + if ((res =psiconv_write_clipart_file(*buf, (psiconv_clipart_f) (value->file)))) goto ERROR; #endif @@ -70,11 +66,12 @@ res = -PSICONV_E_GENERATE; goto ERROR; } + if ((res = psiconv_buffer_resolve(*buf))) + goto ERROR; return -PSICONV_E_OK; ERROR: - if (allocated) - psiconv_free_buffer(*buf); + psiconv_buffer_free(*buf); return res; } @@ -83,9 +80,10 @@ psiconv_character_layout base_char; psiconv_paragraph_layout base_para; int res; - psiconv_buffer extra_buf; psiconv_section_table_section section_table; psiconv_section_table_entry entry; + psiconv_u32 section_table_id; + psiconv_buffer buf_texted; if (!value) { psiconv_warn(0,0,"Null TextEd file"); @@ -102,63 +100,68 @@ goto ERROR2; } - if (!(extra_buf = psiconv_new_buffer())) { - res = -PSICONV_E_NOMEM; - goto ERROR3; - } - if (!(base_char = psiconv_basic_character_layout())) { res = -PSICONV_E_NOMEM; - goto ERROR4; + goto ERROR3; } if (!(base_para = psiconv_basic_paragraph_layout())) { res = -PSICONV_E_NOMEM; - goto ERROR5; + goto ERROR4; } if ((res = psiconv_write_header_section(buf,PSICONV_ID_PSION5, PSICONV_ID_DATA_FILE, PSICONV_ID_TEXTED))) - goto ERROR6; + goto ERROR5; + section_table_id = psiconv_buffer_unique_id(); + if ((res = psiconv_write_offset(buf,section_table_id))) + goto ERROR5; entry->id = PSICONV_ID_APPL_ID_SECTION; - entry->offset = psiconv_list_length(extra_buf) + 0x14; - if ((res = psiconv_list_add(section_table,&entry))) - goto ERROR6; - if ((res=psiconv_write_application_id_section(extra_buf, + entry->offset = psiconv_buffer_unique_id(); + if ((res = psiconv_list_add(section_table,entry))) + goto ERROR5; + if ((res = psiconv_buffer_add_target(buf,entry->offset))) + goto ERROR5; + if ((res=psiconv_write_application_id_section(buf, PSICONV_ID_TEXTED,"TextEd.app"))) - goto ERROR6; + goto ERROR5; entry->id = PSICONV_ID_PAGE_LAYOUT_SECTION; - entry->offset = psiconv_list_length(extra_buf) + 0x14; - 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->offset = psiconv_buffer_unique_id(); + if ((res = psiconv_list_add(section_table,entry))) + goto ERROR5; + if ((res = psiconv_buffer_add_target(buf,entry->offset))) + goto ERROR5; + if ((res = psiconv_write_page_layout_section(buf,value->page_sec))) + goto ERROR5; entry->id = PSICONV_ID_TEXTED; - entry->offset = psiconv_list_length(extra_buf) + 0x14; - 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; + entry->offset = psiconv_buffer_unique_id(); + if ((res = psiconv_list_add(section_table,entry))) + goto ERROR5; + if ((res = psiconv_buffer_add_target(buf,entry->offset))) + goto ERROR5; + if ((res = psiconv_write_texted_section(buf,value->texted_sec, + base_char,base_para,&buf_texted))) + goto ERROR5; - if ((res = psiconv_write_u32(buf,psiconv_list_length(extra_buf) + 0x14))) + if ((res = psiconv_buffer_concat(buf,buf_texted))) goto ERROR6; - if ((res = psiconv_list_concat(buf,extra_buf))) + + if ((res = psiconv_buffer_add_target(buf,section_table_id))) goto ERROR6; res = psiconv_write_section_table_section(buf,section_table); ERROR6: - psiconv_free_paragraph_layout(base_para); + psiconv_buffer_free(buf_texted); ERROR5: - psiconv_free_character_layout(base_char); + psiconv_free_paragraph_layout(base_para); ERROR4: - psiconv_free_buffer(extra_buf); + psiconv_free_character_layout(base_char); ERROR3: free(entry); ERROR2: