--- psiconv/trunk/lib/psiconv/generate_driver.c 2003/11/25 17:57:05 168 +++ psiconv/trunk/lib/psiconv/generate_driver.c 2003/11/26 20:56:17 171 @@ -57,15 +57,23 @@ if ((res =psiconv_write_texted_file(config,*buf, (psiconv_texted_f) (value->file)))) goto ERROR; -#if 0 } else if (value->type == psiconv_sketch_file) { + if ((res = psiconv_write_header_section(config,*buf,PSICONV_ID_PSION5, + PSICONV_ID_DATA_FILE, + PSICONV_ID_SKETCH))) + goto ERROR; if ((res =psiconv_write_sketch_file(config,*buf, (psiconv_sketch_f) (value->file)))) goto ERROR; } else if (value->type == psiconv_mbm_file) { + if ((res = psiconv_write_header_section(config,*buf,PSICONV_ID_PSION5, + PSICONV_ID_MBM_FILE, + 0x00000000))) + goto ERROR; if ((res =psiconv_write_mbm_file(config,*buf, (psiconv_mbm_f) (value->file)))) goto ERROR; +#if 0 } else if (value->type == psiconv_clipart_file) { if ((res =psiconv_write_clipart_file(config,*buf, (psiconv_clipart_f) (value->file)))) @@ -271,3 +279,109 @@ ERROR1: return res; } + +int psiconv_write_sketch_file(const psiconv_config config, + psiconv_buffer buf,psiconv_sketch_f value) +{ + int res; + psiconv_section_table_section section_table; + psiconv_section_table_entry entry; + psiconv_u32 section_table_id; + + if (!value) { + psiconv_warn(config,0,0,"Null Sketch file"); + return -PSICONV_E_GENERATE; + } + + if (!(section_table = psiconv_list_new(sizeof(*entry)))) { + res = -PSICONV_E_NOMEM; + goto ERROR1; + } + + if (!(entry = malloc(sizeof(*entry)))) { + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + + section_table_id = psiconv_buffer_unique_id(); + if ((res = psiconv_write_offset(config,buf,section_table_id))) + goto ERROR3; + + entry->id = PSICONV_ID_APPL_ID_SECTION; + entry->offset = psiconv_buffer_unique_id(); + if ((res = psiconv_list_add(section_table,entry))) + goto ERROR3; + if ((res = psiconv_buffer_add_target(buf,entry->offset))) + goto ERROR3; + if ((res=psiconv_write_application_id_section(config,buf, + PSICONV_ID_SKETCH,"Paint.app"))) + goto ERROR3; + + entry->id = PSICONV_ID_SKETCH_SECTION; + entry->offset = psiconv_buffer_unique_id(); + if ((res = psiconv_list_add(section_table,entry))) + goto ERROR3; + if ((res = psiconv_buffer_add_target(buf,entry->offset))) + goto ERROR3; + if ((res = psiconv_write_sketch_section(config,buf,value->sketch_sec))) + goto ERROR3; + + if ((res = psiconv_buffer_add_target(buf,section_table_id))) + goto ERROR3; + res = psiconv_write_section_table_section(config,buf,section_table); + +ERROR3: + free(entry); +ERROR2: + psiconv_list_free(section_table); +ERROR1: + return res; +} + +int psiconv_write_mbm_file(const psiconv_config config, + psiconv_buffer buf,psiconv_mbm_f value) +{ + int res,i; + psiconv_jumptable_section jumptable; + psiconv_u32 *entry,id,table_id; + psiconv_paint_data_section section; + + if (!value) { + psiconv_warn(config,0,0,"Null MBM file"); + return -PSICONV_E_GENERATE; + } + + if (!(jumptable = psiconv_list_new(sizeof(*entry)))) { + res = -PSICONV_E_NOMEM; + goto ERROR1; + } + + table_id = psiconv_buffer_unique_id(); + if ((res = psiconv_buffer_add_reference(buf,table_id))) + goto ERROR2; + + for (i = 0; i < psiconv_list_length(value->sections); i++) { + if (!(section = psiconv_list_get(value->sections,i))) { + psiconv_warn(config,0,0,"Massive memory corruption"); + res = -PSICONV_E_NOMEM; + goto ERROR2; + } + id = psiconv_buffer_unique_id(); + psiconv_list_add(jumptable,&id); + if ((res = psiconv_buffer_add_target(buf,id))) + goto ERROR2; + if ((res = psiconv_write_paint_data_section(config,buf,section))) + goto ERROR2; + } + + if ((res = psiconv_buffer_add_target(buf,table_id))) + goto ERROR2; + if ((res = psiconv_write_jumptable_section(config,buf,jumptable))) + goto ERROR2; + + +ERROR2: + psiconv_list_free(jumptable); +ERROR1: + return res; +}