forked from Stichting-MINIX-Research-Foundation/minix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlook.c
More file actions
executable file
·110 lines (100 loc) · 1.57 KB
/
Copy pathlook.c
File metadata and controls
executable file
·110 lines (100 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* look.c
* Facility: m4 macro processor
* by: oz
*/
#include "mdef.h"
#include "extr.h"
/*
* hash - compute hash value using the proverbial
* hashing function. Taken from K&R.
*/
int hash (name)
register char *name;
{
register int h = 0;
while (*name)
h += *name++;
return (h % HASHSIZE);
}
/*
* lookup - find name in the hash table
*
*/
ndptr lookup(name)
char *name;
{
register ndptr p;
for (p = hashtab[hash(name)]; p != nil; p = p->nxtptr)
if (strcmp(name, p->name) == 0)
break;
return (p);
}
/*
* addent - hash and create an entry in the hash
* table. The new entry is added in front
* of a hash bucket.
*/
ndptr addent(name)
char *name;
{
register int h;
ndptr p;
h = hash(name);
if ((p = (ndptr) malloc(sizeof(struct ndblock))) != NULL) {
p->nxtptr = hashtab[h];
hashtab[h] = p;
p->name = strsave(name);
}
else
error("m4: no more memory.");
return p;
}
/*
* remhash - remove an entry from the hashtable
*
*/
void remhash(name, all)
char *name;
int all;
{
register int h;
register ndptr xp, tp, mp;
h = hash(name);
mp = hashtab[h];
tp = nil;
while (mp != nil) {
if (strcmp(mp->name, name) == 0) {
mp = mp->nxtptr;
if (tp == nil) {
freent(hashtab[h]);
hashtab[h] = mp;
}
else {
xp = tp->nxtptr;
tp->nxtptr = mp;
freent(xp);
}
if (!all)
break;
}
else {
tp = mp;
mp = mp->nxtptr;
}
}
}
/*
* freent - free a hashtable information block
*
*/
void freent(p)
ndptr p;
{
if (!(p->type & STATIC)) {
free(p->name);
if (p->defn != null)
free(p->defn);
}
free(p);
}