Index: trunk/src/plugins/io_easyeda/io_easyeda.conf =================================================================== --- trunk/src/plugins/io_easyeda/io_easyeda.conf (revision 10663) +++ trunk/src/plugins/io_easyeda/io_easyeda.conf (revision 10664) @@ -6,6 +6,8 @@ auto_normalize = 1 line_approx_seg_len = 2.5 auto_lock_frame = 1 + zip_list_cmd = {unzip -l %s} + zip_extract_cmd = {unzip %s} li:library_search_paths { /usr/share/easyeda/sym /usr/local/share/easyeda/sym Index: trunk/src/plugins/io_easyeda/io_easyeda_conf.h =================================================================== --- trunk/src/plugins/io_easyeda/io_easyeda_conf.h (revision 10663) +++ trunk/src/plugins/io_easyeda/io_easyeda_conf.h (revision 10664) @@ -12,6 +12,8 @@ RND_CFT_LIST postproc_sheet_load; /* pattern;action pairs for object transformations after a succesful load; mostly used for attribute editing */ RND_CFT_REAL line_approx_seg_len; /* when approximating curves with line segments, try to use this segment length; in input units; smaller number is finer approximation but more line objects */ RND_CFT_BOOLEAN auto_lock_frame; /* enables heuristics to find the sheet frame symbol and lock it so that it doesn't interfere with selection */ + RND_CFT_STRING zip_list_cmd; /* shell command that lists the content of a zip file to stdout; %s is replaced by path to the file; noise (headers and file sizes) is accepted as long as file names are not cut by newlines */ + RND_CFT_STRING zip_extract_cmd; /* shell command that extracts a zip file in current working directory; %s is replaced by path to the file */ const struct { RND_CFT_BOOLEAN dump_dom; /* print the Document Object Model to stdout after the low level parse step */ } debug; Index: trunk/src/plugins/io_easyeda/read.c =================================================================== --- trunk/src/plugins/io_easyeda/read.c (revision 10663) +++ trunk/src/plugins/io_easyeda/read.c (revision 10664) @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include Index: trunk/src/plugins/io_easyeda/read_hi_pro.c =================================================================== --- trunk/src/plugins/io_easyeda/read_hi_pro.c (revision 10663) +++ trunk/src/plugins/io_easyeda/read_hi_pro.c (revision 10664) @@ -717,6 +717,96 @@ ctx->alien.flip_y = 1; } +static int easypro_is_file_zip(FILE *f) +{ + char buf[4]; + if (fread(buf, 1, 4, f) != 4) + return 0; + return (buf[0] == 'P') && (buf[1] == 'K') && (buf[2] == 3) && (buf[3] == 4); +} + +/* 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) +{ + gds_t tmp = {0}; + const char *s; + + if (prefix != NULL) + gds_append_str(&tmp, prefix); + + for(s = template; *s != '\0'; s++) { + if ((s[0] == '%') && (s[1] == 's')) { + gds_append_str(&tmp, path); + s++; + } + else + gds_append(&tmp, *s); + } + + return tmp.array; +} + +static int easypro_test_parse_sym(FILE *f, const char *fn, const char *fmt, csch_plug_io_type_t type) +{ + char line_[256], *line; + + /* sheets are loaded as bundles from zip */ + if (type == CSCH_IOTYP_SHEET) + return -1; + + /* first line is: ["DOCTYPE","SYMBOL","1.1"] */ + line = fgets(line_, sizeof(line_), f); + if ((line == NULL) || (*line != '[')) + return -1; + + if (strncmp(line+1, "\"DOCTYPE\",", 10) != 0) + return -1; + line += 11; + + if (type == CSCH_IOTYP_GROUP) { + if (strncmp(line, "\"SYMBOL\",", 9) != 0) + return -1; + return 0; + } + + return -1; +} + +static int easypro_test_parse_zip(FILE *f, const char *fn, const char *fmt, csch_plug_io_type_t type, int *is_sym) +{ + int res = -1; + char *cmd; + FILE *fc; + + *is_sym = 0; + + if (!easypro_is_file_zip(f)) + return -1; + + /* get a file list and look for known index files */ + cmd = easypro_zip_cmd(NULL, io_easyeda_conf.plugins.io_easyeda.zip_list_cmd, fn); + fc = rnd_popen(NULL, cmd, "r"); + if (fc != NULL) { + char *line, buf[1024]; + while((line = fgets(buf, sizeof(buf), fc)) != NULL) { + if (strstr(line, "project.json") != NULL) { + res = 0; + break; + } + else if (strstr(line, "device.json") != NULL) { + *is_sym = 1; + res = 0; + break; + } + } + + fclose(fc); + } + free(cmd); + return res; +} + /*** entry ***/ static csch_cgrp_t *easypro_load_sym(read_ctx_t *ctx) { @@ -790,28 +880,23 @@ + int io_easypro_test_parse(FILE *f, const char *fn, const char *fmt, csch_plug_io_type_t type) { - char line_[256], *line; + if (easypro_test_parse_sym(f, fn, fmt, type) == 0) + return 0; - /* sheets are loaded as bundles from zip */ - if (type == CSCH_IOTYP_SHEET) - return -1; + if ((io_easyeda_conf.plugins.io_easyeda.zip_list_cmd != NULL) && (*io_easyeda_conf.plugins.io_easyeda.zip_list_cmd != '\0')) { + int is_sym, res; + rewind(f); + res = easypro_test_parse_zip(f, fn, fmt, type, &is_sym); + if (res == 0) { + if (is_sym) /* can load sym in both cases */ + return 0; + if (type == CSCH_IOTYP_SHEET) /* can load a sheet only as a sheet */ + return 0; + } + } - /* first line is: ["DOCTYPE","SYMBOL","1.1"] */ - line = fgets(line_, sizeof(line_), f); - if ((line == NULL) || (*line != '[')) - return -1; - - if (strncmp(line+1, "\"DOCTYPE\",", 10) != 0) - return -1; - line += 11; - - if (type == CSCH_IOTYP_GROUP) { - if (strncmp(line, "\"SYMBOL\",", 9) != 0) - return -1; - return 0; - } - return -1; -} +} \ No newline at end of file