Index: trunk/scconfig/Rev.h =================================================================== --- trunk/scconfig/Rev.h (revision 7467) +++ trunk/scconfig/Rev.h (revision 7468) @@ -1 +1 @@ -static const int myrev = 7411; +static const int myrev = 7468; Index: trunk/scconfig/Rev.tab =================================================================== --- trunk/scconfig/Rev.tab (revision 7467) +++ trunk/scconfig/Rev.tab (revision 7468) @@ -1,4 +1,4 @@ -7411 configure new plugin for non-graphical tEDAx sheets +7468 configure new plugin for non-graphical tEDAx sheets 7370 configure cleanup: get rid of local "inline" defs 7322 configure enable io_altium by default 7257 configure plugin config for io_altium Index: trunk/scconfig/plugins.h =================================================================== --- trunk/scconfig/plugins.h (revision 7467) +++ trunk/scconfig/plugins.h (revision 7468) @@ -39,9 +39,11 @@ plugin_def("io_altium", "altium schematics", sbuildin, 1) plugin_def("io_geda", "gEDA schematics and symbols", sbuildin, 1) plugin_def("io_lihata", "lihata schematics and symbols", sbuildin, 1) +plugin_def("io_ngrp_fawk", "fawk non-graphical sheets", sdisable, 0) plugin_def("io_ngrp_tedax", "tEDAx non-graphical sheets", sbuildin, 1) plugin_def("io_tinycad", "TinyCAD schematics", sbuildin, 1) plugin_def("lib_alien", "alien format helper", sbuildin, 1) +plugin_def("lib_ngrp", "non-graphical seet helper", sbuildin, 1) plugin_header("\nGUI:\n") plugin_def("gui", "Graphical User Interface", sbuildin, 1) @@ -55,6 +57,8 @@ plugin_dep("gui", "lib_hid_common") plugin_dep("io_altium", "lib_alien") plugin_dep("io_geda", "lib_alien") +plugin_dep("io_ngrp_fawk", "lib_ngrp") +plugin_dep("io_ngrp_tedax", "lib_ngrp") plugin_dep("io_tinycad", "lib_alien") plugin_dep("lib_alien", "query") plugin_dep("sch_dialogs", "lib_hid_common") Index: trunk/src/plugins/io_ngrp_fawk/Plug.tmpasm =================================================================== --- trunk/src/plugins/io_ngrp_fawk/Plug.tmpasm (revision 7467) +++ trunk/src/plugins/io_ngrp_fawk/Plug.tmpasm (revision 7468) @@ -2,7 +2,6 @@ put /local/rnd/mod/OBJS [@ $(PLUGDIR)/io_ngrp_fawk/io_ngrp_fawk.o $(PLUGDIR)/io_ngrp_fawk/read.o - $(PLUGDIR)/io_ngrp_fawk/comp.o @] switch /local/module/io_ngrp_fawk/controls Index: trunk/src/plugins/io_ngrp_fawk/io_ngrp_fawk.pup =================================================================== --- trunk/src/plugins/io_ngrp_fawk/io_ngrp_fawk.pup (revision 7467) +++ trunk/src/plugins/io_ngrp_fawk/io_ngrp_fawk.pup (revision 7468) @@ -5,6 +5,6 @@ $fmt-native yes $fmt-feature-r cschem non-graphical schematic sheets in tEDAx format $package (core) -default buildin -dep io_ngrp_tedax +default disable-all +dep lib_ngrp autoload 1 Index: trunk/src/plugins/io_ngrp_tedax/comp.c =================================================================== --- trunk/src/plugins/io_ngrp_tedax/comp.c (revision 7467) +++ trunk/src/plugins/io_ngrp_tedax/comp.c (nonexistent) @@ -1,275 +0,0 @@ -/* - * COPYRIGHT - * - * cschem - modular/flexible schematics editor - tEDAx non-graphical sheet support - * Copyright (C) 2023 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 - */ - -/* Maintain a cache of parsed comp/net/conn objects and compile abstract - model from them */ - -#include - -#include -#include - -#include -#include -#include -#include - -#include - -#include "comp.h" - -/*** context ***/ -static void sch_ngrp_free_attribs(sch_ngrp_attrib_t *a) -{ - sch_ngrp_attrib_t *next; - for(; a != NULL; a = next) { - next = a->next; - free(a); - } -} - -static void sch_ngrp_free_objs(sch_ngrp_obj_t *o) -{ - sch_ngrp_obj_t *next; - for(; o != NULL; o = next) { - next = o->next; - sch_ngrp_free_attribs(o->attr_head); - free(o); - } -} - -static void sch_ngrp_free_conns(sch_ngrp_conn_t *c) -{ - sch_ngrp_conn_t *next; - for(; c != NULL; c = next) { - next = c->next; - free(c); - } -} - -void sch_ngrp_clean_cache(sch_ngrp_t *ctx) -{ - sch_ngrp_free_objs(ctx->comps); - sch_ngrp_free_objs(ctx->nets); - sch_ngrp_free_conns(ctx->conns); - ctx->comps = NULL; - ctx->nets = NULL; - ctx->conns = NULL; -} - -void sch_ngrp_free(sch_ngrp_t *ctx) -{ - sch_ngrp_clean_cache(ctx); - vtp0_uninit(&ctx->lines); - gds_uninit(&ctx->text); - free(ctx); -} - -void sch_ngrp_add_attr(sch_ngrp_attrib_t **head, const char *key, const char *val, int vl, long lineno) -{ - int kl = strlen(key); - sch_ngrp_attrib_t *a; - - if (vl < 0) - vl = strlen(val); - - a = malloc(sizeof(sch_ngrp_attrib_t) + kl + vl + 2); - memcpy(a->key, key, kl+1); - a->val = a->key+kl+1; - memcpy(a->val, val, vl); - a->val[vl] = '\0'; - - a->lineno = lineno; - a->next = *head; - *head = a; -} - -sch_ngrp_obj_t *sch_ngrp_add_obj(sch_ngrp_obj_t **head, const char *name, long lineno) -{ - int nl = strlen(name); - sch_ngrp_obj_t *o = malloc(sizeof(sch_ngrp_obj_t) + nl + 1); - memcpy(o->name, name, nl+1); - o->attr_head = NULL; - - o->lineno = lineno; - o->next = *head; - *head = o; - - return o; -} - -sch_ngrp_conn_t *sch_ngrp_add_conn(sch_ngrp_conn_t **head, const char *netname, const char *comp, const char *port, long lineno) -{ - int nl = strlen(netname), cl = strlen(comp), pl = strlen(port); - sch_ngrp_conn_t *c = malloc(sizeof(sch_ngrp_conn_t) + nl + cl + pl + 3); - memcpy(c->netname, netname, nl+1); - c->comp = c->netname+nl+1; - memcpy(c->comp, comp, cl+1); - c->port = c->comp+cl+1; - memcpy(c->port, port, pl+1); - - c->lineno = lineno; - c->next = *head; - *head = c; - - return c; -} - -static void comp_add_attrs(const csch_sheet_t *sheet, csch_ahdr_t *dst, const sch_ngrp_attrib_t *attr_src) -{ - const sch_ngrp_attrib_t *s; - - for(s = attr_src; s != NULL; s = s->next) { - csch_source_arg_t *src; - - src = csch_attrib_src_c(sheet->hidlib.fullpath, s->lineno, 0, "non-graphical: tEDAx"); - csch_attrib_set(&dst->attr, CSCH_ATP_USER_DEFAULT, s->key, s->val, src, NULL); - } -} - - -/*** compile ***/ - -static csch_cgrp_t *get_src_oid(const csch_sheet_t *sheet_, long *src_oid) -{ - csch_sheet_t *sheet = (csch_sheet_t *)sheet_; - csch_cgrp_t *cgrp; - - (*src_oid)++; - cgrp = htip_get(&sheet->direct.id2obj, *src_oid); - - if (cgrp == NULL) { - cgrp = calloc(sizeof(csch_cgrp_t), 1); - csch_cobj_init(cgrp, sheet, &sheet->direct, *src_oid, 0); - } - - return cgrp; -} - -int sch_ngrp_compile_sheet(csch_abstract_t *dst, int viewid, const csch_sheet_t *src, sch_ngrp_t *ctx) -{ - sch_ngrp_conn_t *cn; - sch_ngrp_comp_t *c; - sch_ngrp_net_t *n; - long src_oid = 0; - - - /* create components */ - for(c = ctx->comps; c != NULL; c = c->next) { - csch_acomp_t *acomp = csch_acomp_get(dst, c->name, 1); - csch_cgrp_t *cgrp = get_src_oid(src, &src_oid); - - csch_compile_add_source(cgrp, acomp); - comp_add_attrs(src, &acomp->hdr, c->attr_head); - } - - /* create nets */ - for(n = ctx->nets; n != NULL; n = n->next) { - csch_anet_t *anet = csch_anet_get(dst, n->name, 1, 1); - csch_cgrp_t *cgrp = get_src_oid(src, &src_oid); - - csch_compile_add_source(cgrp, anet); - comp_add_attrs(src, &anet->hdr, n->attr_head); - } - - /* create connections */ - for(cn = ctx->conns; cn != NULL; cn = cn->next) { - csch_anet_t *anet = csch_anet_get(dst, cn->netname, 1, 1); - csch_acomp_t *acomp = csch_acomp_get(dst, cn->comp, 1); - csch_aport_t *aport = csch_aport_get(dst, acomp, cn->port, 1); - csch_cgrp_t *cgrp = get_src_oid(src, &src_oid); - csch_compile_add_source(cgrp, aport); - csch_compile_connect_net_to(&anet, &aport->hdr, 1); - } - - return 0; -} - - - -/*** read ***/ - -int sch_ngrp_load_file(csch_sheet_t *sheet, sch_ngrp_t *ctx, const char *fn) -{ - long len, got; - char *s; - FILE *f; - - len = rnd_file_size(&sheet->hidlib, fn); - if (len < 0) - return -1; - - f = rnd_fopen(&sheet->hidlib, fn, "r"); - if (f == NULL) - return -1; - - if ((len > ctx->text.alloced) || (len < ctx->text.used*0.9)) { - gds_uninit(&ctx->text); - gds_enlarge(&ctx->text, len); - } - - got = fread(ctx->text.array, 1, len, f); - ctx->text.array[got] = '\0'; - fclose(f); - - ctx->lines.used = 0; - vtp0_append(&ctx->lines, ctx->text.array); - for(s = ctx->text.array; *s != '\0'; s++) { - if ((s[0] == '\n') && (s[1] != '\0')) - vtp0_append(&ctx->lines, s+1); - } - - return sch_draw_setup_non_graphical(sheet, ctx->lines.used); -} - -char *sch_ngrp_draw_getline(sch_ngrp_t *ctx, long *cnt, void **cookie) -{ - char *nl = *cookie, *res; - long next; - - if (nl != NULL) - *nl = '\n'; /* restore previous \n */ - - if (*cnt >= ctx->lines.used) - return NULL; - - *cookie = NULL; - next = (*cnt) + 1; - if (next < ctx->lines.used) { - nl = ctx->lines.array[next]; - nl--; - if (*nl == '\n') { - *cookie = nl; - *nl = '\0'; /* terminate string if it ends in \n */ - } - } - - res = ctx->lines.array[*cnt]; - (*cnt)++; - return res; -} Index: trunk/src/plugins/io_ngrp_tedax/comp.h =================================================================== --- trunk/src/plugins/io_ngrp_tedax/comp.h (revision 7467) +++ trunk/src/plugins/io_ngrp_tedax/comp.h (nonexistent) @@ -1,97 +0,0 @@ -/* - * COPYRIGHT - * - * cschem - modular/flexible schematics editor - tEDAx non-graphical sheet support - * Copyright (C) 2023 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 - */ - -/* Maintain a cache of parsed comp/net/conn objects and compile abstract - model from them */ - -#include -#include -#include - -typedef struct sch_ngrp_attrib_s sch_ngrp_attrib_t; -typedef struct sch_ngrp_obj_s sch_ngrp_obj_t; -typedef struct sch_ngrp_obj_s sch_ngrp_comp_t; -typedef struct sch_ngrp_obj_s sch_ngrp_net_t; -typedef struct sch_ngrp_conn_s sch_ngrp_conn_t; - -struct sch_ngrp_attrib_s { - char *val; - long lineno; - sch_ngrp_attrib_t *next; /* singly linked list */ - char key[1]; /* overallocated to hold both key and val */ -}; - -struct sch_ngrp_obj_s { - sch_ngrp_attrib_t *attr_head; - long lineno; - sch_ngrp_obj_t *next; /* singly linked list */ - char name[1]; /* overallocated */ -}; - -struct sch_ngrp_conn_s { - char *comp; - char *port; - long lineno; - sch_ngrp_conn_t *next; /* singly linked list */ - char netname[1]; /* overallocated to hold all net, comp and port */ -}; - -typedef struct { - csch_sheet_t *sheet; - gds_t text; /* raw text from the file */ - vtp0_t lines; /* pointer to the first char of each line */ - - /* cache: precompiled */ - sch_ngrp_comp_t *comps; /* head of linked list */ - sch_ngrp_net_t *nets; /* head of linked list */ - sch_ngrp_conn_t *conns; /* head of linked list */ -} sch_ngrp_t; - -/* Standard non-graphical sheet callback for compiling a sheet */ -int sch_ngrp_compile_sheet(csch_abstract_t *dst, int viewid, const csch_sheet_t *src, sch_ngrp_t *ctx); - - -/* Free all cache fields in ctx, set them to NULL */ -void sch_ngrp_clean_cache(sch_ngrp_t *ctx); - -/* Free all fields of ctx and ctx itself as well */ -void sch_ngrp_free(sch_ngrp_t *ctx); - - -/* Store different objects in the cache, allocating and linking in a new item; - if val_len is -1, calls strlen(val). */ -sch_ngrp_obj_t *sch_ngrp_add_obj(sch_ngrp_obj_t **head, const char *name, long lineno); -void sch_ngrp_add_attr(sch_ngrp_attrib_t **head, const char *key, const char *val, int val_len, long lineno); -sch_ngrp_conn_t *sch_ngrp_add_conn(sch_ngrp_conn_t **head, const char *netname, const char *comp, const char *port, long lineno); - - -/* Load a text file into ctx */ -int sch_ngrp_load_file(csch_sheet_t *sheet, sch_ngrp_t *ctx, const char *fn); - -/* Return text lines for the rendering code */ -char *sch_ngrp_draw_getline(sch_ngrp_t *ctx, long *cnt, void **cookie); Index: trunk/src/plugins/io_ngrp_tedax/Plug.tmpasm =================================================================== --- trunk/src/plugins/io_ngrp_tedax/Plug.tmpasm (revision 7467) +++ trunk/src/plugins/io_ngrp_tedax/Plug.tmpasm (revision 7468) @@ -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/comp.o $(PLUGDIR)/io_ngrp_tedax/parse.o @] Index: trunk/src/plugins/io_ngrp_tedax/io_ngrp_tedax.pup =================================================================== --- trunk/src/plugins/io_ngrp_tedax/io_ngrp_tedax.pup (revision 7467) +++ trunk/src/plugins/io_ngrp_tedax/io_ngrp_tedax.pup (revision 7468) @@ -5,5 +5,6 @@ $fmt-native yes $fmt-feature-r cschem non-graphical schematic sheets in tEDAx format $package (core) +dep lib_ngrp default buildin autoload 1 Index: trunk/src/plugins/io_ngrp_tedax/read.c =================================================================== --- trunk/src/plugins/io_ngrp_tedax/read.c (revision 7467) +++ trunk/src/plugins/io_ngrp_tedax/read.c (revision 7468) @@ -37,8 +37,9 @@ #include #include +#include + #include "parse.h" -#include "comp.h" #include "read.h" Index: trunk/src/plugins/lib_ngrp/Makefile =================================================================== --- trunk/src/plugins/lib_ngrp/Makefile (nonexistent) +++ trunk/src/plugins/lib_ngrp/Makefile (revision 7468) @@ -0,0 +1,2 @@ +all: + cd ../../sch-rnd && make mod_lib_nongrp Index: trunk/src/plugins/lib_ngrp/Plug.tmpasm =================================================================== --- trunk/src/plugins/lib_ngrp/Plug.tmpasm (nonexistent) +++ trunk/src/plugins/lib_ngrp/Plug.tmpasm (revision 7468) @@ -0,0 +1,10 @@ +put /local/rnd/mod {lib_ngrp} +put /local/rnd/mod/OBJS [@ + $(PLUGDIR)/lib_ngrp/lib_ngrp.o +@] + +switch /local/module/lib_ngrp/controls + case {buildin} include /local/csch/tmpasm/buildin; end; + case {plugin} include /local/csch/tmpasm/plugin; end; + case {disable} include /local/csch/tmpasm/disable; end; +end Index: trunk/src/plugins/lib_ngrp/lib_ngrp.c =================================================================== --- trunk/src/plugins/lib_ngrp/lib_ngrp.c (nonexistent) +++ trunk/src/plugins/lib_ngrp/lib_ngrp.c (revision 7468) @@ -0,0 +1,294 @@ +/* + * COPYRIGHT + * + * cschem - modular/flexible schematics editor - tEDAx non-graphical sheet support + * Copyright (C) 2023 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 + */ + +/* Maintain a cache of parsed comp/net/conn objects and compile abstract + model from them */ + +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include "lib_ngrp.h" + +/*** context ***/ +static void sch_ngrp_free_attribs(sch_ngrp_attrib_t *a) +{ + sch_ngrp_attrib_t *next; + for(; a != NULL; a = next) { + next = a->next; + free(a); + } +} + +static void sch_ngrp_free_objs(sch_ngrp_obj_t *o) +{ + sch_ngrp_obj_t *next; + for(; o != NULL; o = next) { + next = o->next; + sch_ngrp_free_attribs(o->attr_head); + free(o); + } +} + +static void sch_ngrp_free_conns(sch_ngrp_conn_t *c) +{ + sch_ngrp_conn_t *next; + for(; c != NULL; c = next) { + next = c->next; + free(c); + } +} + +void sch_ngrp_clean_cache(sch_ngrp_t *ctx) +{ + sch_ngrp_free_objs(ctx->comps); + sch_ngrp_free_objs(ctx->nets); + sch_ngrp_free_conns(ctx->conns); + ctx->comps = NULL; + ctx->nets = NULL; + ctx->conns = NULL; +} + +void sch_ngrp_free(sch_ngrp_t *ctx) +{ + sch_ngrp_clean_cache(ctx); + vtp0_uninit(&ctx->lines); + gds_uninit(&ctx->text); + free(ctx); +} + +void sch_ngrp_add_attr(sch_ngrp_attrib_t **head, const char *key, const char *val, int vl, long lineno) +{ + int kl = strlen(key); + sch_ngrp_attrib_t *a; + + if (vl < 0) + vl = strlen(val); + + a = malloc(sizeof(sch_ngrp_attrib_t) + kl + vl + 2); + memcpy(a->key, key, kl+1); + a->val = a->key+kl+1; + memcpy(a->val, val, vl); + a->val[vl] = '\0'; + + a->lineno = lineno; + a->next = *head; + *head = a; +} + +sch_ngrp_obj_t *sch_ngrp_add_obj(sch_ngrp_obj_t **head, const char *name, long lineno) +{ + int nl = strlen(name); + sch_ngrp_obj_t *o = malloc(sizeof(sch_ngrp_obj_t) + nl + 1); + memcpy(o->name, name, nl+1); + o->attr_head = NULL; + + o->lineno = lineno; + o->next = *head; + *head = o; + + return o; +} + +sch_ngrp_conn_t *sch_ngrp_add_conn(sch_ngrp_conn_t **head, const char *netname, const char *comp, const char *port, long lineno) +{ + int nl = strlen(netname), cl = strlen(comp), pl = strlen(port); + sch_ngrp_conn_t *c = malloc(sizeof(sch_ngrp_conn_t) + nl + cl + pl + 3); + memcpy(c->netname, netname, nl+1); + c->comp = c->netname+nl+1; + memcpy(c->comp, comp, cl+1); + c->port = c->comp+cl+1; + memcpy(c->port, port, pl+1); + + c->lineno = lineno; + c->next = *head; + *head = c; + + return c; +} + +static void comp_add_attrs(const csch_sheet_t *sheet, csch_ahdr_t *dst, const sch_ngrp_attrib_t *attr_src) +{ + const sch_ngrp_attrib_t *s; + + for(s = attr_src; s != NULL; s = s->next) { + csch_source_arg_t *src; + + src = csch_attrib_src_c(sheet->hidlib.fullpath, s->lineno, 0, "non-graphical: tEDAx"); + csch_attrib_set(&dst->attr, CSCH_ATP_USER_DEFAULT, s->key, s->val, src, NULL); + } +} + + +/*** compile ***/ + +static csch_cgrp_t *get_src_oid(const csch_sheet_t *sheet_, long *src_oid) +{ + csch_sheet_t *sheet = (csch_sheet_t *)sheet_; + csch_cgrp_t *cgrp; + + (*src_oid)++; + cgrp = htip_get(&sheet->direct.id2obj, *src_oid); + + if (cgrp == NULL) { + cgrp = calloc(sizeof(csch_cgrp_t), 1); + csch_cobj_init(cgrp, sheet, &sheet->direct, *src_oid, 0); + } + + return cgrp; +} + +int sch_ngrp_compile_sheet(csch_abstract_t *dst, int viewid, const csch_sheet_t *src, sch_ngrp_t *ctx) +{ + sch_ngrp_conn_t *cn; + sch_ngrp_comp_t *c; + sch_ngrp_net_t *n; + long src_oid = 0; + + + /* create components */ + for(c = ctx->comps; c != NULL; c = c->next) { + csch_acomp_t *acomp = csch_acomp_get(dst, c->name, 1); + csch_cgrp_t *cgrp = get_src_oid(src, &src_oid); + + csch_compile_add_source(cgrp, acomp); + comp_add_attrs(src, &acomp->hdr, c->attr_head); + } + + /* create nets */ + for(n = ctx->nets; n != NULL; n = n->next) { + csch_anet_t *anet = csch_anet_get(dst, n->name, 1, 1); + csch_cgrp_t *cgrp = get_src_oid(src, &src_oid); + + csch_compile_add_source(cgrp, anet); + comp_add_attrs(src, &anet->hdr, n->attr_head); + } + + /* create connections */ + for(cn = ctx->conns; cn != NULL; cn = cn->next) { + csch_anet_t *anet = csch_anet_get(dst, cn->netname, 1, 1); + csch_acomp_t *acomp = csch_acomp_get(dst, cn->comp, 1); + csch_aport_t *aport = csch_aport_get(dst, acomp, cn->port, 1); + csch_cgrp_t *cgrp = get_src_oid(src, &src_oid); + csch_compile_add_source(cgrp, aport); + csch_compile_connect_net_to(&anet, &aport->hdr, 1); + } + + return 0; +} + + + +/*** read ***/ + +int sch_ngrp_load_file(csch_sheet_t *sheet, sch_ngrp_t *ctx, const char *fn) +{ + long len, got; + char *s; + FILE *f; + + len = rnd_file_size(&sheet->hidlib, fn); + if (len < 0) + return -1; + + f = rnd_fopen(&sheet->hidlib, fn, "r"); + if (f == NULL) + return -1; + + if ((len > ctx->text.alloced) || (len < ctx->text.used*0.9)) { + gds_uninit(&ctx->text); + gds_enlarge(&ctx->text, len); + } + + got = fread(ctx->text.array, 1, len, f); + ctx->text.array[got] = '\0'; + fclose(f); + + ctx->lines.used = 0; + vtp0_append(&ctx->lines, ctx->text.array); + for(s = ctx->text.array; *s != '\0'; s++) { + if ((s[0] == '\n') && (s[1] != '\0')) + vtp0_append(&ctx->lines, s+1); + } + + return sch_draw_setup_non_graphical(sheet, ctx->lines.used); +} + +char *sch_ngrp_draw_getline(sch_ngrp_t *ctx, long *cnt, void **cookie) +{ + char *nl = *cookie, *res; + long next; + + if (nl != NULL) + *nl = '\n'; /* restore previous \n */ + + if (*cnt >= ctx->lines.used) + return NULL; + + *cookie = NULL; + next = (*cnt) + 1; + if (next < ctx->lines.used) { + nl = ctx->lines.array[next]; + nl--; + if (*nl == '\n') { + *cookie = nl; + *nl = '\0'; /* terminate string if it ends in \n */ + } + } + + res = ctx->lines.array[*cnt]; + (*cnt)++; + return res; +} + +/*** plugin ***/ + +int pplg_check_ver_lib_ngrp(int ver_needed) { return 0; } + +void pplg_uninit_lib_ngrp(void) +{ +} + +int pplg_init_lib_ngrp(void) +{ + RND_API_CHK_VER; + + return 0; +} + Index: trunk/src/plugins/lib_ngrp/lib_ngrp.h =================================================================== --- trunk/src/plugins/lib_ngrp/lib_ngrp.h (nonexistent) +++ trunk/src/plugins/lib_ngrp/lib_ngrp.h (revision 7468) @@ -0,0 +1,97 @@ +/* + * COPYRIGHT + * + * cschem - modular/flexible schematics editor - tEDAx non-graphical sheet support + * Copyright (C) 2023 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 + */ + +/* Maintain a cache of parsed comp/net/conn objects and compile abstract + model from them */ + +#include +#include +#include + +typedef struct sch_ngrp_attrib_s sch_ngrp_attrib_t; +typedef struct sch_ngrp_obj_s sch_ngrp_obj_t; +typedef struct sch_ngrp_obj_s sch_ngrp_comp_t; +typedef struct sch_ngrp_obj_s sch_ngrp_net_t; +typedef struct sch_ngrp_conn_s sch_ngrp_conn_t; + +struct sch_ngrp_attrib_s { + char *val; + long lineno; + sch_ngrp_attrib_t *next; /* singly linked list */ + char key[1]; /* overallocated to hold both key and val */ +}; + +struct sch_ngrp_obj_s { + sch_ngrp_attrib_t *attr_head; + long lineno; + sch_ngrp_obj_t *next; /* singly linked list */ + char name[1]; /* overallocated */ +}; + +struct sch_ngrp_conn_s { + char *comp; + char *port; + long lineno; + sch_ngrp_conn_t *next; /* singly linked list */ + char netname[1]; /* overallocated to hold all net, comp and port */ +}; + +typedef struct { + csch_sheet_t *sheet; + gds_t text; /* raw text from the file */ + vtp0_t lines; /* pointer to the first char of each line */ + + /* cache: precompiled */ + sch_ngrp_comp_t *comps; /* head of linked list */ + sch_ngrp_net_t *nets; /* head of linked list */ + sch_ngrp_conn_t *conns; /* head of linked list */ +} sch_ngrp_t; + +/* Standard non-graphical sheet callback for compiling a sheet */ +int sch_ngrp_compile_sheet(csch_abstract_t *dst, int viewid, const csch_sheet_t *src, sch_ngrp_t *ctx); + + +/* Free all cache fields in ctx, set them to NULL */ +void sch_ngrp_clean_cache(sch_ngrp_t *ctx); + +/* Free all fields of ctx and ctx itself as well */ +void sch_ngrp_free(sch_ngrp_t *ctx); + + +/* Store different objects in the cache, allocating and linking in a new item; + if val_len is -1, calls strlen(val). */ +sch_ngrp_obj_t *sch_ngrp_add_obj(sch_ngrp_obj_t **head, const char *name, long lineno); +void sch_ngrp_add_attr(sch_ngrp_attrib_t **head, const char *key, const char *val, int val_len, long lineno); +sch_ngrp_conn_t *sch_ngrp_add_conn(sch_ngrp_conn_t **head, const char *netname, const char *comp, const char *port, long lineno); + + +/* Load a text file into ctx */ +int sch_ngrp_load_file(csch_sheet_t *sheet, sch_ngrp_t *ctx, const char *fn); + +/* Return text lines for the rendering code */ +char *sch_ngrp_draw_getline(sch_ngrp_t *ctx, long *cnt, void **cookie); Index: trunk/src/plugins/lib_ngrp/lib_ngrp.pup =================================================================== --- trunk/src/plugins/lib_ngrp/lib_ngrp.pup (nonexistent) +++ trunk/src/plugins/lib_ngrp/lib_ngrp.pup (revision 7468) @@ -0,0 +1,7 @@ +$class io +$short non-graphical seet helper +$long Helper functions for handling non-graphical sheets +$state works +$package (core) +default buildin +autoload 1 Index: trunk/src/plugins/plugins_ALL.tmpasm =================================================================== --- trunk/src/plugins/plugins_ALL.tmpasm (revision 7467) +++ trunk/src/plugins/plugins_ALL.tmpasm (revision 7468) @@ -14,9 +14,11 @@ include {../src/plugins/io_altium/Plug.tmpasm} include {../src/plugins/io_geda/Plug.tmpasm} include {../src/plugins/io_lihata/Plug.tmpasm} +include {../src/plugins/io_ngrp_fawk/Plug.tmpasm} include {../src/plugins/io_ngrp_tedax/Plug.tmpasm} include {../src/plugins/io_tinycad/Plug.tmpasm} include {../src/plugins/lib_alien/Plug.tmpasm} +include {../src/plugins/lib_ngrp/Plug.tmpasm} include {../src/plugins/place/Plug.tmpasm} include {../src/plugins/propedit/Plug.tmpasm} include {../src/plugins/query/Plug.tmpasm} Index: trunk/src/sch-rnd/Makefile.dep =================================================================== --- trunk/src/sch-rnd/Makefile.dep (revision 7467) +++ trunk/src/sch-rnd/Makefile.dep (revision 7468) @@ -311,18 +311,6 @@ ../libcschem/vtoidpath.h ../libcschem/cnc_bitmap.h \ ../libcschem/project.h ../libcschem/engine.h \ ../plugins/io_lihata/write.h -../plugins/io_ngrp_tedax/comp.o: ../plugins/io_ngrp_tedax/comp.c \ - ../libcschem/config.h ../libcschem/concrete.h \ - ../libcschem/common_types.h ../libcschem/rtree.h ../libcschem/attrib.h \ - ../libcschem/oidpath.h ../libcschem/vtoid.h \ - ../../src_3rd/libuundo/uundo.h ../../src_3rd/libminuid/libminuid.h \ - ../../src_3rd/gengeo2d/typecfg_long_double.h ../../src_3rd/opc89.h \ - ../../src_3rd/gengeo2d/common.h ../../src_3rd/gengeo2d/prim.h \ - ../libcschem/compile.h ../libcschem/abstract.h ../libcschem/TODO.h \ - ../libcschem/project.h ../libcschem/engine.h ../libcschem/cnc_obj.h \ - ../libcschem/event.h ../libcschem/attrib.h ../libcschem/cnc_pen.h \ - ../libcschem/cnc_text.h ../libcschem/cnc_text_dyn.h \ - ../libcschem/cnc_text.h ../plugins/io_ngrp_tedax/comp.h ../plugins/io_ngrp_tedax/io_ngrp_tedax.o: \ ../plugins/io_ngrp_tedax/io_ngrp_tedax.c ../libcschem/config.h \ ../libcschem/plug_io.h ../libcschem/concrete.h \ @@ -342,8 +330,8 @@ ../../src_3rd/libuundo/uundo.h ../../src_3rd/libminuid/libminuid.h \ ../../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 ../sch-rnd/draw.h \ - ../plugins/io_ngrp_tedax/parse.h ../plugins/io_ngrp_tedax/comp.h \ + ../libcschem/non_graphical.h ../libcschem/event.h \ + ../plugins/lib_ngrp/lib_ngrp.h ../plugins/io_ngrp_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 \ @@ -397,6 +385,19 @@ ../plugins/query/fields_sphash.h ../plugins/query/query_access.h \ ../plugins/query/query.h ../plugins/query/query_exec.h \ ../plugins/lib_alien/read_helper.h ../plugins/lib_alien/read_postproc.c +../plugins/lib_ngrp/lib_ngrp.o: ../plugins/lib_ngrp/lib_ngrp.c \ + ../libcschem/config.h ../libcschem/concrete.h \ + ../libcschem/common_types.h ../libcschem/rtree.h ../libcschem/attrib.h \ + ../libcschem/oidpath.h ../libcschem/vtoid.h \ + ../../src_3rd/libuundo/uundo.h ../../src_3rd/libminuid/libminuid.h \ + ../../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/compile.h \ + ../libcschem/abstract.h ../libcschem/TODO.h ../libcschem/project.h \ + ../libcschem/engine.h ../libcschem/cnc_obj.h ../libcschem/event.h \ + ../libcschem/attrib.h ../libcschem/cnc_pen.h ../libcschem/cnc_text.h \ + ../libcschem/cnc_text_dyn.h ../libcschem/cnc_text.h ../sch-rnd/draw.h \ + ../plugins/lib_ngrp/lib_ngrp.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 \