view ueda/sverp-bind/insthash.c @ 21:f7b09a54c2ce

unet-bind: implemented the check for unclaimed instances
author Space Falcon <falcon@ivan.Harhan.ORG>
date Sun, 02 Aug 2015 06:34:09 +0000
parents 1f3283f8e482
children
line wrap: on
line source

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "struct.h"

#define	HASH_SIZE	1103
static struct instance *hashtab[HASH_SIZE];

static int
hash_instname(str)
	char *str;
{
	register u_long accum = 0;
	register char *cp;
	register int c, i;

	for (cp = str, i = 1; c = *cp; cp++, i++)
		accum += c * i;
	return(accum % HASH_SIZE);
}

struct instance *
enter_instance(newname)
	char *newname;
{
	register struct instance *n, **np;
	int namelen;

	for (np = hashtab + hash_instname(newname); n = *np;
	     np = &n->nextinhash)
		if (!strcmp(n->name, newname)) {
			fprintf(stderr, "error: duplicate instance name %s\n",
				newname);
			exit(1);
		}
	namelen = strlen(newname);
	n = (struct instance *) malloc(sizeof(struct instance) + namelen + 1);
	if (!n) {
		perror("malloc");
		exit(1);
	}
	bzero(n, sizeof(struct instance));
	n->name = (char *)(n + 1);
	strcpy(n->name, newname);
	*np = n;
	return n;
}

struct instance *
find_instance(soughtname)
	register char *soughtname;
{
	register struct instance *n;

	for (n = hashtab[hash_instname(soughtname)]; n; n = n->nextinhash)
		if (!strcmp(n->name, soughtname))
			return(n);
	return(0);
}

check_unclaimed_instances()
{
	int hb;
	register struct instance *n;
	unsigned unclaimed_count = 0;

	for (hb = 0; hb < HASH_SIZE; hb++)
		for (n = hashtab[hb]; n; n = n->nextinhash)
			if (!n->claimed) {
				fprintf(stderr,
		"error: declared instance %s not claimed by input netlist\n",
					n->name);
				unclaimed_count++;
			}
	if (unclaimed_count) {
		fprintf(stderr, "error: unclaimed instances found, aborting\n");
		exit(1);
	}
}