Index: trunk/scconfig/Rev.h =================================================================== --- trunk/scconfig/Rev.h (revision 10858) +++ trunk/scconfig/Rev.h (revision 10859) @@ -1 +1 @@ -static const int myrev = 10786; +static const int myrev = 10859; Index: trunk/scconfig/Rev.tab =================================================================== --- trunk/scconfig/Rev.tab (revision 10858) +++ trunk/scconfig/Rev.tab (revision 10859) @@ -1,3 +1,4 @@ +10859 configure extobj infrastructure 10786 configure new dialog box: viewport 10577 configure new IO plugins: io_eeschema and io_easyeda 10230 configure new plugin for hierarchic library from file system Index: trunk/src/libcschem/Makefile.in =================================================================== --- trunk/src/libcschem/Makefile.in (revision 10858) +++ trunk/src/libcschem/Makefile.in (revision 10859) @@ -13,7 +13,6 @@ actions_csch.o attrib.o concrete.o - drc.o cnc_any_obj.o cnc_arc.o cnc_bitmap.o @@ -27,8 +26,10 @@ cnc_text_dyn.o csch_printf.o compile.o + drc.o engine.o event.o + extobj.o hierarchy.o htPo.o htepu.o Index: trunk/src/libcschem/extobj.c =================================================================== --- trunk/src/libcschem/extobj.c (nonexistent) +++ trunk/src/libcschem/extobj.c (revision 10859) @@ -0,0 +1,110 @@ +/* + * COPYRIGHT + * + * cschem - modular/flexible schematics editor - libcschem (core library) + * Copyright (C) 2024 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 + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version.* + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; 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 "config.h" + +#include +#include +#include +#include + +#include "extobj.h" + +/* persistent copy of impl; both key and value are allocated; on unregister + a zombie impl is kept with all fields (including name) set to NULL */ +htsp_t extobjs_impls; + +void csch_extobj_impl_reg(const csch_extobj_impl_t *impl) +{ + csch_extobj_impl_t *i = htsp_get(&extobjs_impls, impl->name); + + if (i != NULL) { + /* reuse existing if it's a zombie */ + if (impl->name == i->name) { + rnd_message(RND_MSG_ERROR, "Double registration of extobj %s (same)\n", impl->name); + return; + } + if (impl->name != NULL) { + rnd_message(RND_MSG_ERROR, "Double registration of extobj %s (different)\n", impl->name); + return; + } + memcpy(i, impl, sizeof(csch_extobj_impl_t)); + return; + } + + i = malloc(sizeof(csch_extobj_impl_t)); + memcpy(i, impl, sizeof(csch_extobj_impl_t)); + htsp_set(&extobjs_impls, rnd_strdup(impl->name), i); +} + + +void csch_extobj_impl_unreg(const csch_extobj_impl_t *impl) +{ + csch_extobj_impl_t *i = htsp_get(&extobjs_impls, impl->name); + + if (i == NULL) { + rnd_message(RND_MSG_ERROR, "Can't unregister extobj %s (not in hash)\n", impl->name); + return; + } + if (impl->name != i->name) { + rnd_message(RND_MSG_ERROR, "Can't unregister extobj %s (name ptr mismatch)\n", impl->name); + return; + } + + /* retain it as a zombie */ + memset(i, 0, sizeof(csch_extobj_impl_t)); +} + + +const csch_extobj_impl_t *csch_extobj_lookup(const char *name) +{ + csch_extobj_impl_t *i = htsp_get(&extobjs_impls, name); + + if (i != NULL) + return i; + + /* allocate zombie for persistent pointer; an extobj plugin loaded later + would fill in this struct on registration */ + i = calloc(sizeof(csch_extobj_impl_t), 1); + htsp_set(&extobjs_impls, rnd_strdup(name), i); + return i; +} + + +void csch_extobj_init(void) +{ + htsp_init(&extobjs_impls, strhash, strkeyeq); +} + +void csch_extobj_uninit(void) +{ + htsp_entry_t *e; + for(e = htsp_first(&extobjs_impls); e != NULL; e = htsp_next(&extobjs_impls, e)) { + free(e->key); + free(e->value); + } + htsp_uninit(&extobjs_impls); +} Index: trunk/src/libcschem/extobj.h =================================================================== --- trunk/src/libcschem/extobj.h (nonexistent) +++ trunk/src/libcschem/extobj.h (revision 10859) @@ -0,0 +1,45 @@ +/* + * COPYRIGHT + * + * cschem - modular/flexible schematics editor - libcschem (core library) + * Copyright (C) 2024 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 + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version.* + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; 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 + +typedef struct csch_extobj_impl_s { + const char *name; /* also the hash key */ + + void (*attr_edit_pre)(csch_cgrp_t *grp, const char *key); + void (*attr_edit_post)(csch_cgrp_t *grp, const char *key); + void (*update)(csch_cgrp_t *grp); + void (*gui_edit)(csch_cgrp_t *grp); +} csch_extobj_impl_t; + +void csch_extobj_impl_reg(const csch_extobj_impl_t *impl); +void csch_extobj_impl_unreg(const csch_extobj_impl_t *impl); + + + +/* internal, do not call */ +void csch_extobj_init(void); +void csch_extobj_uninit(void); Index: trunk/src/libcschem/libcschem.c =================================================================== --- trunk/src/libcschem/libcschem.c (revision 10858) +++ trunk/src/libcschem/libcschem.c (revision 10859) @@ -2,7 +2,7 @@ * COPYRIGHT * * cschem - modular/flexible schematics editor - libcschem (core library) - * Copyright (C) 2018 Tibor 'Igor2' Palinkas + * Copyright (C) 2018,2024 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 @@ -44,6 +44,7 @@ #include "undo.h" #include "actions_csch.h" #include "drc.h" +#include "extobj.h" const int *csch_cfg_multiport_net_merge = NULL; const int *csch_cfg_hier_net_allow_rename = NULL; @@ -58,6 +59,7 @@ minuid_init(&csch_minuid); minuid_salt(&csch_minuid, &pid, sizeof(pid)); + csch_extobj_init(); csch_plug_library_init(); return 0; @@ -71,6 +73,7 @@ csch_drc_act_uninit(); csch_undo_act_uninit(); csch_plug_library_uninit(); + csch_extobj_uninit(); } void csch_uninit_last(void)