view ueda/unet-bind/insthash.c @ 139:bf188727e606

donl-rename-parts reader: no tEDAx-style escapes
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 07 Sep 2020 04:25:11 +0000
parents ffab0a4424ad
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);
	}
}