FreeCalypso > hg > ueda-linux
diff ueda/libuschem/matchtomcl.c @ 0:cd92449fdb51
initial import of ueda and ifctf-part-lib from ifctfvax CVS
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 20 Jul 2015 00:24:37 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ueda/libuschem/matchtomcl.c Mon Jul 20 00:24:37 2015 +0000 @@ -0,0 +1,68 @@ +/* + * Logic to match uschem component instances to MCL components + */ + +#include <sys/types.h> +#include <stdio.h> +#include <ctype.h> +#include <strings.h> +#include "../libueda/mcl.h" +#include "schemstruct.h" + +extern struct component *find_comp_by_refdes(); +extern char *get_comp_attr(); + +match_schem_to_mcl(schem) + struct schem *schem; +{ + register struct schemobj *obj; + int errflag = 0; + + for (obj = schem->obj_next; obj != (struct schemobj *)schem; + obj = obj->obj_next) + if (obj->obj_type == OBJTYPE_COMPINST) + if (match_compinst_to_mcl(schem, obj)) + errflag = 1; + if (errflag) + exit(1); + return(0); +} + +match_compinst_to_mcl(schem, obj) + struct schem *schem; + register struct schemobj *obj; +{ + char refdes[256]; + register char *cp; + register struct component *comp; + + strcpy(refdes, obj->compobj_instname); + cp = index(refdes, '\0'); + while (cp > refdes && islower(cp[-1])) + cp--; + *cp = '\0'; + comp = find_comp_by_refdes(refdes); + if (comp) { + obj->compobj_mclcomp = comp; + return(0); + } else { + fprintf(stderr, + "%s: line %d: component %s not found in the MCL\n", + schem->orig_filename, obj->obj_lineno, refdes); + return(-1); + } +} + +char * +get_compinst_attr(obj, attrname) + struct schemobj *obj; + register char *attrname; +{ + register struct decoration *decor; + + for (decor = obj->obj_decorations; decor; decor = decor->decor_next) + if (decor->decor_type == DECOR_TYPE_ATTR && + !strcmp(decor->decorattr_name, attrname)) + return(decor->decorattr_value); + return(get_comp_attr(obj->compobj_mclcomp, attrname)); +}