Index: trunk/src/libcschem/abstract.c =================================================================== --- trunk/src/libcschem/abstract.c (revision 777) +++ trunk/src/libcschem/abstract.c (revision 778) @@ -111,6 +111,7 @@ fprintf(f, "%s%sAttributes:\n", prefix1, prefix2); for(e = htsp_first(attr); e != NULL; e = htsp_next(attr, e)) { const csch_attrib_t *a = e->value; + if (a->deleted) continue; fprintf(f, "%s%s %s=%s\n", prefix1, prefix2, a->key, a->val); } } Index: trunk/src/libcschem/attrib.c =================================================================== --- trunk/src/libcschem/attrib.c (revision 777) +++ trunk/src/libcschem/attrib.c (revision 778) @@ -2,7 +2,7 @@ * COPYRIGHT * * cschem - modular/flexible schematics editor - libcschem (core library) - * Copyright (C) 2018 Tibor 'Igor2' Palinkas + * Copyright (C) 2018,2019 Tibor 'Igor2' Palinkas * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -176,3 +176,16 @@ return dst; } + +int csch_attrib_del(csch_attribs_t *attribs, int prio, const char *key, const csch_source_arg_t source) +{ + csch_attrib_t *a = htsp_get((csch_attribs_t *)attribs, key); + if (a == NULL) + return -1; + + a->deleted = 1; + append_src(a, prio, source, 0); +} + + + Index: trunk/src/libcschem/attrib.h =================================================================== --- trunk/src/libcschem/attrib.h (revision 777) +++ trunk/src/libcschem/attrib.h (revision 778) @@ -41,6 +41,8 @@ char *key; int prio; + unsigned int deleted:1; + char *val; /* scalar; if NULL, use arr */ vts0_t arr; vts0_t source; @@ -93,9 +95,9 @@ /* Del a key from an attribute hash; if history is not NULL, the key is kept and the value is emptied so source history is preserved. */ -int csch_attrib_del(csch_attribs_t *attribs, int prio, const char *key, const char *source); -int csch_attrib_delptr(csch_attribs_t *attribs, int prio, const char *key, char *source); +int csch_attrib_del(csch_attribs_t *attribs, int prio, const char *key, const csch_source_arg_t source); + /* Build an ordered list of attributes; vector items point to (const csch_attrib_t *) */ void csch_attrib_sort(vtp0_t *dst, const csch_attribs_t *attribs); @@ -108,7 +110,7 @@ csch_inline const char *csch_attrib_get_str(csch_attribs_t *attribs, const char *key) { csch_attrib_t *a = csch_attrib_get(attribs, key); - if (a == NULL) return NULL; + if ((a == NULL) || (a->deleted)) return NULL; return a->val; } @@ -115,7 +117,7 @@ csch_inline const vts0_t *csch_attrib_get_arr(csch_attribs_t *attribs, const char *key) { csch_attrib_t *a = csch_attrib_get(attribs, key); - if (a != NULL) return NULL; + if ((a != NULL) || (a->deleted)) return NULL; return &a->arr; } Index: trunk/src/libcschem/engine.c =================================================================== --- trunk/src/libcschem/engine.c (revision 777) +++ trunk/src/libcschem/engine.c (revision 778) @@ -75,12 +75,12 @@ /* returns argc or -1 on error; arguments are packed starting from skip_first+1, making room for caller supplied arguments before argv[1] if skip_first > 0 */ -static int eng_load_args(csch_sheet_t *sheet, fgw_arg_t *argv, int max_argc, va_list ap, int skip_first) +static int eng_load_args(csch_hook_call_ctx_t *cctx, fgw_arg_t *argv, int max_argc, va_list ap, int skip_first) { int argc; argv[0].type = FGW_FUNC; - argv[0].val.argv0.user_call_ctx = sheet; + argv[0].val.argv0.user_call_ctx = cctx; for(argc = 1 + skip_first;;argc++) { fgw_type_t type = va_arg(ap, fgw_type_t); @@ -127,6 +127,7 @@ long n; const char *sres; fgw_arg_t argv[MAX_ARGS], ares; + csch_hook_call_ctx_t cctx; v = vtp0_get(&proj->views, proj->curr, 0); if (v == NULL) @@ -134,7 +135,7 @@ view = *v; va_start(ap, defval); - argc = eng_load_args(sheet, argv, (sizeof(argv)/sizeof(argv[0])), ap, 1); + argc = eng_load_args(&cctx, argv, (sizeof(argv)/sizeof(argv[0])), ap, 1); va_end(ap); if (argc < 0) goto error; @@ -141,6 +142,7 @@ sres = defval; + cctx.sheet = sheet; for(n = 0; n < view->engines.used; n++) { csch_view_eng_t *eng = view->engines.array[n]; @@ -148,6 +150,7 @@ if (hk == NULL) continue; + cctx.view_eng = eng; ares.type = FGW_INT; ares.val.nat_int = 0; argv[0].val.argv0.func = hk; @@ -185,6 +188,7 @@ int argc; long n; fgw_arg_t argv[MAX_ARGS], ares; + csch_hook_call_ctx_t cctx; v = vtp0_get(&proj->views, proj->curr, 0); if (v == NULL) @@ -192,11 +196,13 @@ view = *v; va_start(ap, hkid); - argc = eng_load_args(sheet, argv, (sizeof(argv)/sizeof(argv[0])), ap, 0); + argc = eng_load_args(&cctx, argv, (sizeof(argv)/sizeof(argv[0])), ap, 0); va_end(ap); if (argc < 0) return -1; + cctx.sheet = sheet; + for(n = 0; n < view->engines.used; n++) { csch_view_eng_t *eng = view->engines.array[n]; fgw_func_t *hk = eng->hook[hkid]; @@ -203,6 +209,7 @@ if (hk == NULL) continue; + cctx.view_eng = eng; ares.type = FGW_INT; ares.val.nat_int = 0; argv[0].val.argv0.func = hk; Index: trunk/src/libcschem/engine.h =================================================================== --- trunk/src/libcschem/engine.h (revision 777) +++ trunk/src/libcschem/engine.h (revision 778) @@ -51,6 +51,11 @@ }; +typedef struct csch_hook_call_ctx_s { + csch_sheet_t *sheet; + const csch_view_eng_t *view_eng; +} csch_hook_call_ctx_t; + csch_view_eng_t *csch_eng_alloc(csch_view_t *view, const char *user_name, const char *eng_name, const char *file_name); /* temporary until fungw C binding installation is sorted out */