… | |
… | |
55 | PSICONV_ID_TEXTED))) |
55 | PSICONV_ID_TEXTED))) |
56 | goto ERROR; |
56 | goto ERROR; |
57 | if ((res =psiconv_write_texted_file(config,*buf, |
57 | if ((res =psiconv_write_texted_file(config,*buf, |
58 | (psiconv_texted_f) (value->file)))) |
58 | (psiconv_texted_f) (value->file)))) |
59 | goto ERROR; |
59 | goto ERROR; |
60 | #if 0 |
|
|
61 | } else if (value->type == psiconv_sketch_file) { |
60 | } else if (value->type == psiconv_sketch_file) { |
|
|
61 | if ((res = psiconv_write_header_section(config,*buf,PSICONV_ID_PSION5, |
|
|
62 | PSICONV_ID_DATA_FILE, |
|
|
63 | PSICONV_ID_SKETCH))) |
|
|
64 | goto ERROR; |
62 | if ((res =psiconv_write_sketch_file(config,*buf, |
65 | if ((res =psiconv_write_sketch_file(config,*buf, |
63 | (psiconv_sketch_f) (value->file)))) |
66 | (psiconv_sketch_f) (value->file)))) |
64 | goto ERROR; |
67 | goto ERROR; |
65 | } else if (value->type == psiconv_mbm_file) { |
68 | } else if (value->type == psiconv_mbm_file) { |
|
|
69 | if ((res = psiconv_write_header_section(config,*buf,PSICONV_ID_PSION5, |
|
|
70 | PSICONV_ID_MBM_FILE, |
|
|
71 | 0x00000000))) |
|
|
72 | goto ERROR; |
66 | if ((res =psiconv_write_mbm_file(config,*buf, |
73 | if ((res =psiconv_write_mbm_file(config,*buf, |
67 | (psiconv_mbm_f) (value->file)))) |
74 | (psiconv_mbm_f) (value->file)))) |
68 | goto ERROR; |
75 | goto ERROR; |
69 | } else if (value->type == psiconv_clipart_file) { |
76 | } else if (value->type == psiconv_clipart_file) { |
|
|
77 | /* No complete header section, so we do it all in the below function */ |
70 | if ((res =psiconv_write_clipart_file(config,*buf, |
78 | if ((res =psiconv_write_clipart_file(config,*buf, |
71 | (psiconv_clipart_f) (value->file)))) |
79 | (psiconv_clipart_f) (value->file)))) |
72 | goto ERROR; |
80 | goto ERROR; |
73 | #endif |
|
|
74 | } else { |
81 | } else { |
75 | psiconv_warn(config,0,0,"Unknown or unsupported file type"); |
82 | psiconv_warn(config,0,0,"Unknown or unsupported file type"); |
76 | res = -PSICONV_E_GENERATE; |
83 | res = -PSICONV_E_GENERATE; |
77 | goto ERROR; |
84 | goto ERROR; |
78 | } |
85 | } |
… | |
… | |
269 | ERROR2: |
276 | ERROR2: |
270 | psiconv_list_free(section_table); |
277 | psiconv_list_free(section_table); |
271 | ERROR1: |
278 | ERROR1: |
272 | return res; |
279 | return res; |
273 | } |
280 | } |
|
|
281 | |
|
|
282 | int psiconv_write_sketch_file(const psiconv_config config, |
|
|
283 | psiconv_buffer buf,psiconv_sketch_f value) |
|
|
284 | { |
|
|
285 | int res; |
|
|
286 | psiconv_section_table_section section_table; |
|
|
287 | psiconv_section_table_entry entry; |
|
|
288 | psiconv_u32 section_table_id; |
|
|
289 | |
|
|
290 | if (!value) { |
|
|
291 | psiconv_warn(config,0,0,"Null Sketch file"); |
|
|
292 | return -PSICONV_E_GENERATE; |
|
|
293 | } |
|
|
294 | |
|
|
295 | if (!(section_table = psiconv_list_new(sizeof(*entry)))) { |
|
|
296 | res = -PSICONV_E_NOMEM; |
|
|
297 | goto ERROR1; |
|
|
298 | } |
|
|
299 | |
|
|
300 | if (!(entry = malloc(sizeof(*entry)))) { |
|
|
301 | res = -PSICONV_E_NOMEM; |
|
|
302 | goto ERROR2; |
|
|
303 | } |
|
|
304 | |
|
|
305 | section_table_id = psiconv_buffer_unique_id(); |
|
|
306 | if ((res = psiconv_write_offset(config,buf,section_table_id))) |
|
|
307 | goto ERROR3; |
|
|
308 | |
|
|
309 | entry->id = PSICONV_ID_APPL_ID_SECTION; |
|
|
310 | entry->offset = psiconv_buffer_unique_id(); |
|
|
311 | if ((res = psiconv_list_add(section_table,entry))) |
|
|
312 | goto ERROR3; |
|
|
313 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) |
|
|
314 | goto ERROR3; |
|
|
315 | if ((res=psiconv_write_application_id_section(config,buf, |
|
|
316 | PSICONV_ID_SKETCH,"Paint.app"))) |
|
|
317 | goto ERROR3; |
|
|
318 | |
|
|
319 | entry->id = PSICONV_ID_SKETCH_SECTION; |
|
|
320 | entry->offset = psiconv_buffer_unique_id(); |
|
|
321 | if ((res = psiconv_list_add(section_table,entry))) |
|
|
322 | goto ERROR3; |
|
|
323 | if ((res = psiconv_buffer_add_target(buf,entry->offset))) |
|
|
324 | goto ERROR3; |
|
|
325 | if ((res = psiconv_write_sketch_section(config,buf,value->sketch_sec))) |
|
|
326 | goto ERROR3; |
|
|
327 | |
|
|
328 | if ((res = psiconv_buffer_add_target(buf,section_table_id))) |
|
|
329 | goto ERROR3; |
|
|
330 | res = psiconv_write_section_table_section(config,buf,section_table); |
|
|
331 | |
|
|
332 | ERROR3: |
|
|
333 | free(entry); |
|
|
334 | ERROR2: |
|
|
335 | psiconv_list_free(section_table); |
|
|
336 | ERROR1: |
|
|
337 | return res; |
|
|
338 | } |
|
|
339 | |
|
|
340 | int psiconv_write_mbm_file(const psiconv_config config, |
|
|
341 | psiconv_buffer buf,psiconv_mbm_f value) |
|
|
342 | { |
|
|
343 | int res,i; |
|
|
344 | psiconv_jumptable_section jumptable; |
|
|
345 | psiconv_u32 *entry,id,table_id; |
|
|
346 | psiconv_paint_data_section section; |
|
|
347 | |
|
|
348 | if (!value) { |
|
|
349 | psiconv_warn(config,0,0,"Null MBM file"); |
|
|
350 | return -PSICONV_E_GENERATE; |
|
|
351 | } |
|
|
352 | |
|
|
353 | if (!(jumptable = psiconv_list_new(sizeof(*entry)))) { |
|
|
354 | res = -PSICONV_E_NOMEM; |
|
|
355 | goto ERROR1; |
|
|
356 | } |
|
|
357 | |
|
|
358 | table_id = psiconv_buffer_unique_id(); |
|
|
359 | if ((res = psiconv_buffer_add_reference(buf,table_id))) |
|
|
360 | goto ERROR2; |
|
|
361 | |
|
|
362 | for (i = 0; i < psiconv_list_length(value->sections); i++) { |
|
|
363 | if (!(section = psiconv_list_get(value->sections,i))) { |
|
|
364 | psiconv_warn(config,0,0,"Massive memory corruption"); |
|
|
365 | res = -PSICONV_E_NOMEM; |
|
|
366 | goto ERROR2; |
|
|
367 | } |
|
|
368 | id = psiconv_buffer_unique_id(); |
|
|
369 | psiconv_list_add(jumptable,&id); |
|
|
370 | if ((res = psiconv_buffer_add_target(buf,id))) |
|
|
371 | goto ERROR2; |
|
|
372 | if ((res = psiconv_write_paint_data_section(config,buf,section,0))) |
|
|
373 | goto ERROR2; |
|
|
374 | } |
|
|
375 | |
|
|
376 | if ((res = psiconv_buffer_add_target(buf,table_id))) |
|
|
377 | goto ERROR2; |
|
|
378 | if ((res = psiconv_write_jumptable_section(config,buf,jumptable))) |
|
|
379 | goto ERROR2; |
|
|
380 | |
|
|
381 | |
|
|
382 | ERROR2: |
|
|
383 | psiconv_list_free(jumptable); |
|
|
384 | ERROR1: |
|
|
385 | return res; |
|
|
386 | } |
|
|
387 | |
|
|
388 | /* Note: this file is special, because it does not have a complete header! */ |
|
|
389 | int psiconv_write_clipart_file(const psiconv_config config, |
|
|
390 | psiconv_buffer buf,psiconv_clipart_f value) |
|
|
391 | { |
|
|
392 | int res,i; |
|
|
393 | psiconv_jumptable_section jumptable; |
|
|
394 | psiconv_u32 *entry,id; |
|
|
395 | psiconv_clipart_section section; |
|
|
396 | psiconv_buffer sec_buf; |
|
|
397 | |
|
|
398 | if (!value) { |
|
|
399 | psiconv_warn(config,0,0,"Null Clipart file"); |
|
|
400 | return -PSICONV_E_GENERATE; |
|
|
401 | } |
|
|
402 | |
|
|
403 | if (!(jumptable = psiconv_list_new(sizeof(*entry)))) { |
|
|
404 | res = -PSICONV_E_NOMEM; |
|
|
405 | goto ERROR1; |
|
|
406 | } |
|
|
407 | |
|
|
408 | if (!(sec_buf = psiconv_buffer_new())) { |
|
|
409 | res = -PSICONV_E_NOMEM; |
|
|
410 | goto ERROR2; |
|
|
411 | } |
|
|
412 | |
|
|
413 | if ((res = psiconv_write_u32(config,buf,PSICONV_ID_CLIPART))) |
|
|
414 | goto ERROR3; |
|
|
415 | |
|
|
416 | for (i = 0; i < psiconv_list_length(value->sections); i++) { |
|
|
417 | if (!(section = psiconv_list_get(value->sections,i))) { |
|
|
418 | psiconv_warn(config,0,0,"Massive memory corruption"); |
|
|
419 | res = -PSICONV_E_NOMEM; |
|
|
420 | goto ERROR3; |
|
|
421 | } |
|
|
422 | id = psiconv_buffer_unique_id(); |
|
|
423 | psiconv_list_add(jumptable,&id); |
|
|
424 | if ((res = psiconv_buffer_add_target(sec_buf,id))) |
|
|
425 | goto ERROR3; |
|
|
426 | if ((res = psiconv_write_clipart_section(config,sec_buf, section))) |
|
|
427 | goto ERROR3; |
|
|
428 | } |
|
|
429 | |
|
|
430 | if ((res = psiconv_write_jumptable_section(config,buf,jumptable))) |
|
|
431 | goto ERROR3; |
|
|
432 | |
|
|
433 | if ((res = psiconv_buffer_concat(buf,sec_buf))) |
|
|
434 | goto ERROR3; |
|
|
435 | |
|
|
436 | |
|
|
437 | ERROR3: |
|
|
438 | psiconv_buffer_free(sec_buf); |
|
|
439 | ERROR2: |
|
|
440 | psiconv_list_free(jumptable); |
|
|
441 | ERROR1: |
|
|
442 | return res; |
|
|
443 | } |