Index: trunk/scconfig/Rev.h =================================================================== --- trunk/scconfig/Rev.h (revision 10576) +++ trunk/scconfig/Rev.h (revision 10577) @@ -1 +1 @@ -static const int myrev = 10576; +static const int myrev = 10577; Index: trunk/scconfig/Rev.tab =================================================================== --- trunk/scconfig/Rev.tab (revision 10576) +++ trunk/scconfig/Rev.tab (revision 10577) @@ -1,4 +1,4 @@ -10576 configure new IO plugins: io_eeschema and io_easyeda +10577 configure new IO plugins: io_eeschema and io_easyeda 10230 configure new plugin for hierarchic library from file system 10028 configure hierarchy support 9983 configure io_orcad: enable by default Index: trunk/src/plugins/io_easyeda/Plug.tmpasm =================================================================== --- trunk/src/plugins/io_easyeda/Plug.tmpasm (revision 10576) +++ trunk/src/plugins/io_easyeda/Plug.tmpasm (revision 10577) @@ -3,6 +3,7 @@ $(PLUGDIR)/io_easyeda/io_easyeda.o $(PLUGDIR)/io_easyeda/read.o $(PLUGDIR)/io_easyeda/read_low_std.o + $(PLUGDIR)/io_easyeda/read_low_pro.o $(PLUGDIR)/io_easyeda/easyeda_sphash.o $(PLUGDIR)/io_easyeda/svgpath.o @] Index: trunk/src/plugins/io_easyeda/read_low_pro.c =================================================================== --- trunk/src/plugins/io_easyeda/read_low_pro.c (revision 10576) +++ trunk/src/plugins/io_easyeda/read_low_pro.c (revision 10577) @@ -27,60 +27,81 @@ #include #include -#include +#include -#include -#include +#include +#include #include #include "io_easyeda_conf.h" extern conf_io_easyeda_t io_easyeda_conf; extern void easyeda_dump_tree(FILE *f, gdom_node_t *tree); /* in the std */ +extern long easyeda_str2name(const char *str); /* in the std */ + static void parse_pro_obj(gdom_node_t *obj) { } -static gdom_node_t *gdom_node_t *easyeda_low_sch_parse(FILE *f) +typedef struct { + FILE *f; + enum { PRS_BEGIN, PRS_NORMAL, PRS_NL, PRS_END } state; +} pro_read_ctx_t; + +/* Emulate a valid json by wrapping the file in {} and inserting commas before + each newline */ +static int pro_getchr(void *uctx) { - gdom_node_t *root, *schs; + pro_read_ctx_t *prc = uctx; + int c; - /* low level json parse -> initial dom */ - root = gdom_json_parse(f, easyeda_str2name); - if (root == NULL) - return NULL; - - if (root->type == GDOM_ARRAY) { - long n; - for(n = 0; n < schs->value.array.used; n++) - parse_pro_obj(schs->value.array.child[n]); + switch(prc->state) { + case PRS_BEGIN: + prc->state = PRS_NORMAL; + return '{'; + case PRS_NORMAL: + c = fgetc(prc->f); + if (c == '\n') { + prc->state = PRS_NL; + return ','; + } + else if (c == EOF) { + prc->state = PRS_END; + return '}'; + } + return c; + case PRS_NL: + prc->state = PRS_NORMAL; + return '\n'; + case PRS_END: + return EOF; } - return root; + abort(); } -(FILE *f) +static gdom_node_t *easyeda_pro_parse_(FILE *f) { gdom_node_t *root, *schs; + pro_read_ctx_t prc; + prc.state = PRS_BEGIN; + prc.f = f; + /* low level json parse -> initial dom */ - root = gdom_json_parse(f, easyeda_str2name); + root = gdom_json_parse_any(&prc, pro_getchr, easyeda_str2name); if (root == NULL) return NULL; - /* parse strings into dom subtrees */ - schs = gdom_hash_get(root, easy_schematics); - if ((schs != NULL) && (schs->type == GDOM_ARRAY)) { + if (root->type == GDOM_ARRAY) { long n; for(n = 0; n < schs->value.array.used; n++) - parse_sch_strs(schs->value.array.child[n]); + parse_pro_obj(schs->value.array.child[n]); } return root; } - - gdom_node_t *easyeda_low_pro_parse(FILE *f) { gdom_node_t *tree = easyeda_pro_parse_(f); Index: trunk/src/plugins/io_easyeda/read_low_std.c =================================================================== --- trunk/src/plugins/io_easyeda/read_low_std.c (revision 10576) +++ trunk/src/plugins/io_easyeda/read_low_std.c (revision 10577) @@ -925,7 +925,7 @@ parse_canvas(&canvas); } -static long easyeda_str2name(const char *str) +long easyeda_str2name(const char *str) { return easy_sphash(str); } Index: trunk/src/sch-rnd/Makefile.dep =================================================================== --- trunk/src/sch-rnd/Makefile.dep (revision 10576) +++ trunk/src/sch-rnd/Makefile.dep (revision 10577) @@ -361,6 +361,17 @@ ../plugins/io_easyeda/easyeda_sphash.h \ ../../src_3rd/rnd_inclib/lib_easyeda/gendom.h \ ../plugins/io_easyeda/read.h ../libcschem/plug_io.h +../plugins/io_easyeda/read_low_pro.o: \ + ../plugins/io_easyeda/read_low_pro.c \ + ../plugins/io_easyeda/read_low_pro.h \ + ../plugins/io_easyeda/easyeda_sphash.h \ + ../../src_3rd/rnd_inclib/lib_easyeda/gendom.h \ + ../../src_3rd/libnanojson/nanojson.h \ + ../../src_3rd/rnd_inclib/lib_easyeda/gendom_json.h \ + ../../src_3rd/rnd_inclib/lib_easyeda/gendom.h \ + ../../src_3rd/rnd_inclib/lib_easyeda/easyeda_low.c \ + ../../src_3rd/rnd_inclib/lib_easyeda/gendom_json.h \ + ../plugins/io_easyeda/io_easyeda_conf.h ../plugins/io_easyeda/read_low_std.o: \ ../plugins/io_easyeda/read_low_std.c \ ../plugins/io_easyeda/read_low_std.h \