Index: trunk/scconfig/Rev.h =================================================================== --- trunk/scconfig/Rev.h (revision 9036) +++ trunk/scconfig/Rev.h (revision 9037) @@ -1 +1 @@ -static const int myrev = 8973; +static const int myrev = 9037; Index: trunk/scconfig/Rev.tab =================================================================== --- trunk/scconfig/Rev.tab (revision 9036) +++ trunk/scconfig/Rev.tab (revision 9037) @@ -1,3 +1,4 @@ +9037 configure move out tEDAx parse/write into a reusable lib plugin 8973 configure new source file for sheet utils 8741 configure enable the sim plugins by default 8712 configure new sources for sim gui and sim config Index: trunk/scconfig/plugins.h =================================================================== --- trunk/scconfig/plugins.h (revision 9036) +++ trunk/scconfig/plugins.h (revision 9037) @@ -72,6 +72,7 @@ plugin_dep("io_ngrp_fawk", "lib_ngrp") plugin_dep("io_ngrp_fawk", "script") plugin_dep("io_ngrp_tedax", "lib_ngrp") +plugin_dep("io_ngrp_tedax", "lib_tedax") plugin_dep("io_tinycad", "lib_alien") plugin_dep("lib_alien", "query") plugin_dep("lib_plot", "query") Index: trunk/src/plugins/io_ngrp_tedax/parse.h =================================================================== --- trunk/src/plugins/io_ngrp_tedax/parse.h (revision 9036) +++ trunk/src/plugins/io_ngrp_tedax/parse.h (nonexistent) @@ -1,4 +0,0 @@ -/* Low level tEDAx parser */ - -int tedax_getline_mem(char **src, char *buff, int buff_size, char *argv[], int argv_size); - Index: trunk/src/plugins/io_ngrp_tedax/parse.c =================================================================== --- trunk/src/plugins/io_ngrp_tedax/parse.c (revision 9036) +++ trunk/src/plugins/io_ngrp_tedax/parse.c (nonexistent) @@ -1,145 +0,0 @@ -/* - * COPYRIGHT - * - * tedax IO plugin - low level parser, similar to the reference implementation - * Copyright (C) 2023 Tibor 'Igor2' Palinkas - * pcb-rnd Copyright (C) 2017 Tibor 'Igor2' Palinkas - * - * (Supported by NLnet NGI0 Entrust in 2023) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Contact: - * Project page: http://repo.hu/projects/sch-rnd - * contact lead developer: http://www.repo.hu/projects/sch-rnd/contact.html - * mailing list: http://www.repo.hu/projects/sch-rnd/contact.html - */ - - -#include -#include -#include - -#include "parse.h" -#include -#include - -/* remove leading whitespace */ -#define ltrim(s) while(isspace(*s)) s++ - -/* remove trailing newline;; trailing backslash is an error */ -#define rtrim(s, slen) \ - do { \ - char *end; \ - for(end = s + slen - 1; (end >= s) && ((*end == '\r') || (*end == '\n')); end--) \ - *end = '\0'; \ - if ((end[0] == '\\') && ((end == s) || (end[-1] != '\\'))) \ - return -1; \ - } while(0) - -static char *tedax_get_line_mem(char *dst, int dst_len, char **src, int *len_out) -{ - char *sep; - int len; - - sep = strpbrk(*src, "\r\n"); - if (sep == NULL) - len = strlen(*src); - else - len = sep - *src; - - if (len > dst_len) { - /* line too long */ - return NULL; - } - - memcpy(dst, *src, len); - dst[len] = '\0'; - - (*src) += len; - while((**src == '\r')) (*src)++; - if((**src == '\n')) (*src)++; - - *len_out = len; - return dst; -} - -int tedax_getline_mem(char **src, char *buff, int buff_size, char *argv[], int argv_size) -{ - int argc, len; - - for(;;) { - char *s, *o; - - - while(**src == '\r') (*src)++; - - if (**src == '\n') { - (*src)++; - goto empty; /* have to return empty line for line counting */ - } - - if (tedax_get_line_mem(buff, buff_size, src, &len) == NULL) - return -1; - - s = buff; - if (*s == '#') /* comment */ - goto empty; - ltrim(s); - rtrim(s, len); - if (*s == '\0') /* empty line */ - goto empty; - - /* argv split */ - for(argc = 0, o = argv[0] = s; *s != '\0';) { - if (*s == '\\') { - s++; - switch(*s) { - case 'r': *o = '\r'; break; - case 'n': *o = '\n'; break; - case 't': *o = '\t'; break; - default: *o = *s; - } - o++; - s++; - continue; - } - if ((argc+1 < argv_size) && ((*s == ' ') || (*s == '\t'))) { - *o = *s = '\0'; - s++; - o++; - while((*s == ' ') || (*s == '\t')) - s++; - argc++; - argv[argc] = o; - } - else { - *o = *s; - s++; - o++; - } - } - *o = '\0'; - return argc+1; /* valid line, split up */ - } - - return -1; /* can't get here */ - - empty:; - *buff = '\0'; - argv[0] = NULL; - return 0; -} - Index: trunk/src/plugins/io_ngrp_tedax/Plug.tmpasm =================================================================== --- trunk/src/plugins/io_ngrp_tedax/Plug.tmpasm (revision 9036) +++ trunk/src/plugins/io_ngrp_tedax/Plug.tmpasm (revision 9037) @@ -2,7 +2,6 @@ put /local/rnd/mod/OBJS [@ $(PLUGDIR)/io_ngrp_tedax/io_ngrp_tedax.o $(PLUGDIR)/io_ngrp_tedax/read.o - $(PLUGDIR)/io_ngrp_tedax/parse.o @] switch /local/module/io_ngrp_tedax/controls Index: trunk/src/plugins/io_ngrp_tedax/io_ngrp_tedax.pup =================================================================== --- trunk/src/plugins/io_ngrp_tedax/io_ngrp_tedax.pup (revision 9036) +++ trunk/src/plugins/io_ngrp_tedax/io_ngrp_tedax.pup (revision 9037) @@ -6,5 +6,6 @@ $fmt-feature-r cschem non-graphical schematic sheets in tEDAx format $package (core) dep lib_ngrp +dep lib_tedax default buildin autoload 1 Index: trunk/src/plugins/io_ngrp_tedax/read.c =================================================================== --- trunk/src/plugins/io_ngrp_tedax/read.c (revision 9036) +++ trunk/src/plugins/io_ngrp_tedax/read.c (revision 9037) @@ -38,9 +38,8 @@ #include #include +#include -#include "parse.h" - #include "read.h" static void ngrp_tedax_free(csch_sheet_t *sheet) Index: trunk/src/plugins/lib_tedax/lib_tedax.c =================================================================== --- trunk/src/plugins/lib_tedax/lib_tedax.c (revision 9036) +++ trunk/src/plugins/lib_tedax/lib_tedax.c (revision 9037) @@ -38,6 +38,8 @@ /*** plugin ***/ +#include "parse.c" + int pplg_check_ver_lib_tedax(int ver_needed) { return 0; } void pplg_uninit_lib_tedax(void) Index: trunk/src/plugins/lib_tedax/parse.c =================================================================== --- trunk/src/plugins/lib_tedax/parse.c (nonexistent) +++ trunk/src/plugins/lib_tedax/parse.c (revision 9037) @@ -0,0 +1,145 @@ +/* + * COPYRIGHT + * + * tedax IO plugin - low level parser, similar to the reference implementation + * Copyright (C) 2023 Tibor 'Igor2' Palinkas + * pcb-rnd Copyright (C) 2017 Tibor 'Igor2' Palinkas + * + * (Supported by NLnet NGI0 Entrust in 2023) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Contact: + * Project page: http://repo.hu/projects/sch-rnd + * contact lead developer: http://www.repo.hu/projects/sch-rnd/contact.html + * mailing list: http://www.repo.hu/projects/sch-rnd/contact.html + */ + + +#include +#include +#include + +#include "parse.h" +#include +#include + +/* remove leading whitespace */ +#define ltrim(s) while(isspace(*s)) s++ + +/* remove trailing newline;; trailing backslash is an error */ +#define rtrim(s, slen) \ + do { \ + char *end; \ + for(end = s + slen - 1; (end >= s) && ((*end == '\r') || (*end == '\n')); end--) \ + *end = '\0'; \ + if ((end[0] == '\\') && ((end == s) || (end[-1] != '\\'))) \ + return -1; \ + } while(0) + +static char *tedax_get_line_mem(char *dst, int dst_len, char **src, int *len_out) +{ + char *sep; + int len; + + sep = strpbrk(*src, "\r\n"); + if (sep == NULL) + len = strlen(*src); + else + len = sep - *src; + + if (len > dst_len) { + /* line too long */ + return NULL; + } + + memcpy(dst, *src, len); + dst[len] = '\0'; + + (*src) += len; + while((**src == '\r')) (*src)++; + if((**src == '\n')) (*src)++; + + *len_out = len; + return dst; +} + +int tedax_getline_mem(char **src, char *buff, int buff_size, char *argv[], int argv_size) +{ + int argc, len; + + for(;;) { + char *s, *o; + + + while(**src == '\r') (*src)++; + + if (**src == '\n') { + (*src)++; + goto empty; /* have to return empty line for line counting */ + } + + if (tedax_get_line_mem(buff, buff_size, src, &len) == NULL) + return -1; + + s = buff; + if (*s == '#') /* comment */ + goto empty; + ltrim(s); + rtrim(s, len); + if (*s == '\0') /* empty line */ + goto empty; + + /* argv split */ + for(argc = 0, o = argv[0] = s; *s != '\0';) { + if (*s == '\\') { + s++; + switch(*s) { + case 'r': *o = '\r'; break; + case 'n': *o = '\n'; break; + case 't': *o = '\t'; break; + default: *o = *s; + } + o++; + s++; + continue; + } + if ((argc+1 < argv_size) && ((*s == ' ') || (*s == '\t'))) { + *o = *s = '\0'; + s++; + o++; + while((*s == ' ') || (*s == '\t')) + s++; + argc++; + argv[argc] = o; + } + else { + *o = *s; + s++; + o++; + } + } + *o = '\0'; + return argc+1; /* valid line, split up */ + } + + return -1; /* can't get here */ + + empty:; + *buff = '\0'; + argv[0] = NULL; + return 0; +} + Index: trunk/src/plugins/lib_tedax/parse.h =================================================================== --- trunk/src/plugins/lib_tedax/parse.h (nonexistent) +++ trunk/src/plugins/lib_tedax/parse.h (revision 9037) @@ -0,0 +1,4 @@ +/* Low level tEDAx parser */ + +int tedax_getline_mem(char **src, char *buff, int buff_size, char *argv[], int argv_size); + Index: trunk/src/sch-rnd/Makefile.dep =================================================================== --- trunk/src/sch-rnd/Makefile.dep (revision 9036) +++ trunk/src/sch-rnd/Makefile.dep (revision 9037) @@ -322,8 +322,8 @@ ../libcschem/cnc_text_dyn.h ../libcschem/cnc_conn.h \ ../libcschem/vtoidpath.h ../libcschem/project.h ../libcschem/engine.h \ ../libcschem/util_parse.h ../../src_3rd/load_cache/load_cache.h \ - ../plugins/io_lihata/read.h ../libcschem/plug_io.h \ - ../libcschem/abstract.h ../libcschem/TODO.h + ../sch-rnd/util_sheet.h ../plugins/io_lihata/read.h \ + ../libcschem/plug_io.h ../libcschem/abstract.h ../libcschem/TODO.h ../plugins/io_lihata/write.o: ../plugins/io_lihata/write.c \ ../libcschem/config.h ../libcschem/cnc_pen.h ../libcschem/concrete.h \ ../libcschem/common_types.h ../libcschem/rtree.h ../libcschem/attrib.h \ @@ -370,8 +370,6 @@ ../../src_3rd/gengeo2d/common.h ../../src_3rd/gengeo2d/prim.h \ ../libcschem/abstract.h ../libcschem/TODO.h ../libcschem/non_graphical.h \ ../plugins/io_ngrp_tedax/read.h -../plugins/io_ngrp_tedax/parse.o: ../plugins/io_ngrp_tedax/parse.c \ - ../libcschem/config.h ../plugins/io_ngrp_tedax/parse.h ../plugins/io_ngrp_tedax/read.o: ../plugins/io_ngrp_tedax/read.c \ ../libcschem/config.h ../libcschem/concrete.h \ ../libcschem/common_types.h ../libcschem/rtree.h ../libcschem/attrib.h \ @@ -380,7 +378,7 @@ ../../src_3rd/gengeo2d/typecfg_long_double.h ../../src_3rd/opc89.h \ ../../src_3rd/gengeo2d/common.h ../../src_3rd/gengeo2d/prim.h \ ../libcschem/non_graphical.h ../libcschem/event.h \ - ../plugins/lib_ngrp/lib_ngrp.h ../plugins/io_ngrp_tedax/parse.h \ + ../plugins/lib_ngrp/lib_ngrp.h ../plugins/lib_tedax/parse.h \ ../plugins/io_ngrp_tedax/read.h ../libcschem/plug_io.h \ ../libcschem/abstract.h ../libcschem/TODO.h ../plugins/io_tinycad/io_tinycad.o: ../plugins/io_tinycad/io_tinycad.c \ @@ -469,6 +467,9 @@ ../libcschem/config.h ../plugins/lib_target/lib_target.h \ ../libcschem/abstract.h ../libcschem/common_types.h \ ../libcschem/attrib.h ../libcschem/TODO.h +../plugins/lib_tedax/lib_tedax.o: ../plugins/lib_tedax/lib_tedax.c \ + ../libcschem/config.h ../plugins/lib_tedax/lib_tedax.h \ + ../plugins/lib_tedax/parse.c ../plugins/lib_tedax/parse.h ../plugins/place/place.o: ../plugins/place/place.c ../libcschem/config.h \ ../libcschem/search.h ../libcschem/concrete.h \ ../libcschem/common_types.h ../libcschem/rtree.h ../libcschem/attrib.h \ @@ -1248,7 +1249,8 @@ ../../src_3rd/gengeo2d/common.h ../../src_3rd/gengeo2d/prim.h \ ../libcschem/project.h ../libcschem/engine.h ../libcschem/plug_library.h \ ../libcschem/event.h ../libcschem/libcschem.h ../libcschem/plug_io.h \ - ../libcschem/abstract.h ../libcschem/TODO.h conf_core.h draw.h + ../libcschem/abstract.h ../libcschem/TODO.h conf_core.h util_sheet.h \ + draw.h style.o: style.c ../libcschem/config.h ../libcschem/concrete.h \ ../libcschem/common_types.h ../libcschem/rtree.h ../libcschem/attrib.h \ ../libcschem/oidpath.h ../libcschem/vtoid.h \