Index: trunk/src/libcschem/abstract.c =================================================================== --- trunk/src/libcschem/abstract.c (revision 700) +++ trunk/src/libcschem/abstract.c (revision 701) @@ -79,7 +79,22 @@ return comp; } +csch_aport_t *csch_aport_get(csch_abstract_t *abs, csch_acomp_t *comp, const char *name, int alloc) +{ + csch_aport_t *port; + port = htsp_get(&comp->ports, name); + if ((port != NULL) || (!alloc)) + return port; + + port = calloc(sizeof(csch_acomp_t), 1); + csch_aobj_init(&port->hdr, CSCH_ATYPE_PORT); + comp->name = csch_strdup(name); + htsp_set(&comp->ports, port->name, port); + return port; +} + + static void dump_attr(const csch_attribs_t *attr, FILE *f, const char *prefix1, const char *prefix2) { htsp_entry_t *e; @@ -103,8 +118,17 @@ fprintf(f, "%sComponents:\n", prefix); for(e = htsp_first(&abs->comps); e != NULL; e = htsp_next(&abs->comps, e)) { + htsp_entry_t *pe; csch_acomp_t *comp = e->value; + fprintf(f, "%s %s\n", prefix, comp->name); + + fprintf(f, "%s Ports:\n", prefix); + for(pe = htsp_first(&comp->ports); pe != NULL; pe = htsp_next(&comp->ports, e)) { + csch_aport_t *port = e->value; + fprintf(f, "%s %s\n", prefix, port->name); + dump_attr(&port->hdr.attr, f, prefix, " "); + } dump_attr(&comp->hdr.attr, f, prefix, " "); } } Index: trunk/src/libcschem/abstract.h =================================================================== --- trunk/src/libcschem/abstract.h (revision 700) +++ trunk/src/libcschem/abstract.h (revision 701) @@ -92,9 +92,9 @@ typedef struct csch_aport_s { csch_ahdr_t hdr; csch_acomp_t *parent; + char *name; /* cached from attributes: */ - const char *name; const char *chan; } csch_aport_t; @@ -129,7 +129,8 @@ /*** net ***/ csch_anet_t *csch_anet_get(csch_abstract_t *abs, const char *netname, int alloc); -/*** component ***/ +/*** component and port ***/ csch_acomp_t *csch_acomp_get(csch_abstract_t *abs, const char *name, int alloc); +csch_aport_t *csch_aport_get(csch_abstract_t *abs, csch_acomp_t *comp, const char *name, int alloc); #endif Index: trunk/src/libcschem/compile.c =================================================================== --- trunk/src/libcschem/compile.c (revision 700) +++ trunk/src/libcschem/compile.c (revision 701) @@ -78,6 +78,7 @@ static int compile_symbol(csch_abstract_t *dst, const csch_sheet_t *sheet, const csch_cgrp_t *src) { char tmpname[128]; + htip_entry_t *e; const char *name; const csch_attrib_t *aname = NULL; csch_acomp_t *comp; @@ -104,6 +105,36 @@ if ((src->hdr.type == CSCH_CTYPE_GRP_REF) && (src->data.ref.grp != NULL)) res |= compile_attributes(&comp->hdr, &src->data.ref.grp->hdr.attr); + for(e = htip_first(&src->id2obj); e != NULL; e = htip_next(&src->id2obj, e)) { + csch_cgrp_t *t = e->value; + const csch_attrib_t *trole, *tname; + const char *pname; + + if ((t->hdr.type != CSCH_CTYPE_GRP) && (t->hdr.type != CSCH_CTYPE_GRP_REF)) + continue; + + if (t->hdr.type == CSCH_CTYPE_GRP_REF) + trole = csch_cgrp_ref_get_attr(t, "role"); + else + trole = csch_attrib_get(&t->hdr.attr, "role"); + if ((trole == NULL) || (trole->val == NULL) || (strcmp(trole->val, "terminal" != 0))) + continue; + + if (t->hdr.type == CSCH_CTYPE_GRP_REF) + tname = csch_cgrp_ref_get_attr(t, "name"); + else + tname = csch_attrib_get(&t->hdr.attr, "name"); + + if ((aname == NULL) || (aname->key == NULL) || (*aname->key == '\0')) { +#warning TODO: needs better naming + sprintf(tmpname, "anon_%p", src); + pname = tmpname; + } + else + pname = aname->val; + + comp = csch_aport_get(dst, comp, pname, 1); + } return res; }