# HG changeset patch # User Space Falcon # Date 1438468680 0 # Node ID 73abf2c1388475abeeb675fd7534fe89053dfbcf # Parent 62f8d6874a87db451b175227b48d3cb12ce16024 libunet: nethash functions implemented diff -r 62f8d6874a87 -r 73abf2c13884 ueda/libunet/Makefile --- a/ueda/libunet/Makefile Sat Aug 01 20:52:33 2015 +0000 +++ b/ueda/libunet/Makefile Sat Aug 01 22:38:00 2015 +0000 @@ -1,6 +1,6 @@ CC= gcc CFLAGS= -O2 -LIBOBJS=unetrd.o +LIBOBJS=nethash.o unetrd.o all: libunet.a diff -r 62f8d6874a87 -r 73abf2c13884 ueda/libunet/nethash.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ueda/libunet/nethash.c Sat Aug 01 22:38:00 2015 +0000 @@ -0,0 +1,76 @@ +/* + * This module provides library functions for managing the list of NET objects + * read from unet files. + */ + +#include +#include +#include +#include +#include "nethash.h" + +struct net *net_list_head; +int longest_net_name; + +#define HASH_SIZE 1103 +static struct net *hashtab[HASH_SIZE]; +static struct net **global_tailp = &net_list_head; + +static int +hash_netname(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 net * +enter_net_object(netname, extra_alloc) + char *netname; + unsigned extra_alloc; +{ + register struct net *n, **np; + int namelen; + + for (np = hashtab + hash_netname(netname); n = *np; np = &n->nextinhash) + if (!strcmp(n->name, netname)) { + fprintf(stderr, "error: duplicate NET name %s\n", + netname); + exit(1); + } + namelen = strlen(netname); + if (namelen > longest_net_name) + longest_net_name = namelen; + n = (struct net *) malloc(sizeof(struct net) + extra_alloc + + namelen + 1); + if (!n) { + perror("malloc"); + exit(1); + } + n->name = (char *)(n + 1) + extra_alloc; + strcpy(n->name, netname); + n->nextinlist = 0; + n->nextinhash = 0; + *np = n; + *global_tailp = n; + global_tailp = &n->nextinlist; + return n; +} + +struct net * +find_net_by_name(soughtname) + register char *soughtname; +{ + register struct net *n; + + for (n = hashtab[hash_netname(soughtname)]; n; n = n->nextinhash) + if (!strcmp(n->name, soughtname)) + return(n); + fprintf(stderr, "error: no net named \"%s\"\n", soughtname); + exit(1); +} diff -r 62f8d6874a87 -r 73abf2c13884 ueda/libunet/nethash.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ueda/libunet/nethash.h Sat Aug 01 22:38:00 2015 +0000 @@ -0,0 +1,7 @@ +/* struct net definition for working with unet netlists */ + +struct net { + char *name; + struct net *nextinlist; + struct net *nextinhash; +};