FreeCalypso > hg > ueda-linux
comparison ueda/unet-bind/insthash.c @ 101:ffab0a4424ad
ueda: unet-bind program moved into sensibly named unet-bind subdir
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 29 Sep 2019 22:42:41 +0000 |
parents | ueda/sverp-bind/insthash.c@f7b09a54c2ce |
children |
comparison
equal
deleted
inserted
replaced
100:071b24bca546 | 101:ffab0a4424ad |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <strings.h> | |
5 #include "struct.h" | |
6 | |
7 #define HASH_SIZE 1103 | |
8 static struct instance *hashtab[HASH_SIZE]; | |
9 | |
10 static int | |
11 hash_instname(str) | |
12 char *str; | |
13 { | |
14 register u_long accum = 0; | |
15 register char *cp; | |
16 register int c, i; | |
17 | |
18 for (cp = str, i = 1; c = *cp; cp++, i++) | |
19 accum += c * i; | |
20 return(accum % HASH_SIZE); | |
21 } | |
22 | |
23 struct instance * | |
24 enter_instance(newname) | |
25 char *newname; | |
26 { | |
27 register struct instance *n, **np; | |
28 int namelen; | |
29 | |
30 for (np = hashtab + hash_instname(newname); n = *np; | |
31 np = &n->nextinhash) | |
32 if (!strcmp(n->name, newname)) { | |
33 fprintf(stderr, "error: duplicate instance name %s\n", | |
34 newname); | |
35 exit(1); | |
36 } | |
37 namelen = strlen(newname); | |
38 n = (struct instance *) malloc(sizeof(struct instance) + namelen + 1); | |
39 if (!n) { | |
40 perror("malloc"); | |
41 exit(1); | |
42 } | |
43 bzero(n, sizeof(struct instance)); | |
44 n->name = (char *)(n + 1); | |
45 strcpy(n->name, newname); | |
46 *np = n; | |
47 return n; | |
48 } | |
49 | |
50 struct instance * | |
51 find_instance(soughtname) | |
52 register char *soughtname; | |
53 { | |
54 register struct instance *n; | |
55 | |
56 for (n = hashtab[hash_instname(soughtname)]; n; n = n->nextinhash) | |
57 if (!strcmp(n->name, soughtname)) | |
58 return(n); | |
59 return(0); | |
60 } | |
61 | |
62 check_unclaimed_instances() | |
63 { | |
64 int hb; | |
65 register struct instance *n; | |
66 unsigned unclaimed_count = 0; | |
67 | |
68 for (hb = 0; hb < HASH_SIZE; hb++) | |
69 for (n = hashtab[hb]; n; n = n->nextinhash) | |
70 if (!n->claimed) { | |
71 fprintf(stderr, | |
72 "error: declared instance %s not claimed by input netlist\n", | |
73 n->name); | |
74 unclaimed_count++; | |
75 } | |
76 if (unclaimed_count) { | |
77 fprintf(stderr, "error: unclaimed instances found, aborting\n"); | |
78 exit(1); | |
79 } | |
80 } |