Index: trunk/src/plugins/io_easyeda/io_easyeda.c =================================================================== --- trunk/src/plugins/io_easyeda/io_easyeda.c (revision 10664) +++ trunk/src/plugins/io_easyeda/io_easyeda.c (revision 10665) @@ -91,11 +91,9 @@ easypro.load_prio = io_easypro_load_prio; easypro.load_grp = io_easypro_load_grp; easypro.test_parse = io_easypro_test_parse; /* for syms */ -/* easystd.load_sheet_bundled = io_easypro_load_sheet_bundled; easystd.test_parse_bundled = io_easypro_test_parse_bundled; easystd.end_bundled = io_easypro_end_bundled; -*/ easypro.ext_save_sheet = "sch"; easypro.ext_save_grp = "sym"; csch_plug_io_register(&easypro); Index: trunk/src/plugins/io_easyeda/read.c =================================================================== --- trunk/src/plugins/io_easyeda/read.c (revision 10664) +++ trunk/src/plugins/io_easyeda/read.c (revision 10665) @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include Index: trunk/src/plugins/io_easyeda/read.h =================================================================== --- trunk/src/plugins/io_easyeda/read.h (revision 10664) +++ trunk/src/plugins/io_easyeda/read.h (revision 10665) @@ -4,15 +4,19 @@ int io_easystd_test_parse(FILE *f, const char *fn, const char *fmt, csch_plug_io_type_t type); csch_cgrp_t *io_easystd_load_grp(FILE *f, const char *fn, const char *fmt, csch_sheet_t *sheet); +void *io_easystd_test_parse_bundled(FILE *f, const char *fn, const char *fmt, csch_plug_io_type_t type); +int io_easystd_load_sheet_bundled(void *cookie, FILE *f, const char *fn, csch_sheet_t *dst); +void io_easystd_end_bundled(void *cookie, const char *fn); + /*** pro ***/ int io_easypro_test_parse(FILE *f, const char *fn, const char *fmt, csch_plug_io_type_t type); csch_cgrp_t *io_easypro_load_grp(FILE *f, const char *fn, const char *fmt, csch_sheet_t *sheet); -void *io_easystd_test_parse_bundled(FILE *f, const char *fn, const char *fmt, csch_plug_io_type_t type); -int io_easystd_load_sheet_bundled(void *cookie, FILE *f, const char *fn, csch_sheet_t *dst); -void io_easystd_end_bundled(void *cookie, const char *fn); +void *io_easypro_test_parse_bundled(FILE *f, const char *fn, const char *fmt, csch_plug_io_type_t type); +int io_easypro_load_sheet_bundled(void *cookie, FILE *f, const char *fn, csch_sheet_t *dst); +void io_easypro_end_bundled(void *cookie, const char *fn); Index: trunk/src/plugins/io_easyeda/read_hi_pro.c =================================================================== --- trunk/src/plugins/io_easyeda/read_hi_pro.c (revision 10664) +++ trunk/src/plugins/io_easyeda/read_hi_pro.c (revision 10665) @@ -727,13 +727,16 @@ /* allocate memory and print a zip command line: first prefix (if not NULL), then template with %s substituted wuth path */ -static char *easypro_zip_cmd(const char *prefix, const char *template, const char *path) +static char *easypro_zip_cmd(const char **prefix, const char *template, const char *path) { gds_t tmp = {0}; const char *s; - if (prefix != NULL) - gds_append_str(&tmp, prefix); + if (prefix != NULL) { + const char **p; + for(p = prefix; *p != NULL; p++) + gds_append_str(&tmp, *p); + } for(s = template; *s != '\0'; s++) { if ((s[0] == '%') && (s[1] == 's')) { @@ -879,14 +882,14 @@ } +#define CAN_UNZIP ((io_easyeda_conf.plugins.io_easyeda.zip_list_cmd != NULL) && (*io_easyeda_conf.plugins.io_easyeda.zip_list_cmd != '\0')) - int io_easypro_test_parse(FILE *f, const char *fn, const char *fmt, csch_plug_io_type_t type) { if (easypro_test_parse_sym(f, fn, fmt, type) == 0) return 0; - if ((io_easyeda_conf.plugins.io_easyeda.zip_list_cmd != NULL) && (*io_easyeda_conf.plugins.io_easyeda.zip_list_cmd != '\0')) { + if (CAN_UNZIP) { int is_sym, res; rewind(f); res = easypro_test_parse_zip(f, fn, fmt, type, &is_sym); @@ -899,4 +902,69 @@ } return -1; -} \ No newline at end of file +} + +typedef struct { + char *dir; + unsigned is_sym:1; +} easypro_bundle_t; + + +int io_easypro_load_sheet_bundled(void *cookie, FILE *f, const char *fn, csch_sheet_t *dst) +{ + rnd_trace("pro bundled read unpacked!\n"); + return -1; +} + +/* called only for sheets */ +void *io_easypro_test_parse_bundled(FILE *f, const char *fn, const char *fmt, csch_plug_io_type_t type) +{ + int is_sym, res; + easypro_bundle_t *bnd; + char *cmd, *fullpath; + const char *prefix[4]; + + if (!CAN_UNZIP) + return NULL; + + res = easypro_test_parse_zip(f, fn, fmt, type, &is_sym); + if (res != 0) + return NULL; + + bnd = calloc(sizeof(easypro_bundle_t), 1); + bnd->is_sym = is_sym; + + /* unpack */ + bnd->dir = "/tmp/easypro"; + TODO("make temp dir with librnd instead"); + + prefix[0] = "cd "; + prefix[1] = bnd->dir; + prefix[2] = ";"; + prefix[3] = NULL; + + fullpath = rnd_lrealpath(fn); + cmd = easypro_zip_cmd(prefix, io_easyeda_conf.plugins.io_easyeda.zip_extract_cmd, fullpath); + free(fullpath); + rnd_trace("cmd='%s'\n", cmd); + + res = rnd_system(NULL, cmd); + if (res != 0) { + rnd_message(RND_MSG_ERROR, "io_easyeda: unable to unzip using command: '%s'\nDetails on stderr.\nPlease check your configuration!\n", cmd); + free(cmd); + io_easypro_end_bundled(bnd, fn); + return NULL; + } + free(cmd); + + return bnd; +} + + +void io_easypro_end_bundled(void *cookie, const char *fn) +{ + easypro_bundle_t *bnd = cookie; + TODO("free temp dir bnd->dir with librnd"); + free(bnd); +} +