20 |
|
|
21 |
|
#include "copyright.h" |
22 |
|
|
23 |
+ |
#include <stdlib.h> |
24 |
+ |
|
25 |
+ |
#include "rtmisc.h" |
26 |
+ |
#include "rterror.h" |
27 |
+ |
#include "rtio.h" |
28 |
+ |
|
29 |
|
#ifndef NHASH |
30 |
< |
#define NHASH 509 /* hash table size (prime!) */ |
30 |
> |
#define NHASH 2039 /* hash table size (prime!) */ |
31 |
|
#endif |
32 |
|
|
33 |
|
typedef struct s_head { |
39 |
|
|
40 |
|
#define hash(s) (shash(s)%NHASH) |
41 |
|
|
36 |
– |
extern char *savestr(), *strcpy(), *malloc(); |
37 |
– |
|
38 |
– |
#define NULL 0 |
39 |
– |
|
42 |
|
#define string(sp) ((char *)((sp)+1)) |
43 |
|
|
44 |
|
#define salloc(str) (S_HEAD *)malloc(sizeof(S_HEAD)+1+strlen(str)) |
47 |
|
|
48 |
|
|
49 |
|
char * |
50 |
< |
savestr(str) /* save a string */ |
49 |
< |
char *str; |
50 |
> |
savestr(char *str) /* save a string */ |
51 |
|
{ |
52 |
< |
register int hval; |
53 |
< |
register S_HEAD *sp; |
52 |
> |
int hval; |
53 |
> |
S_HEAD *sp; |
54 |
|
|
55 |
|
if (str == NULL) |
56 |
|
return(NULL); |
57 |
+ |
if (!*str) |
58 |
+ |
return ""; |
59 |
|
hval = hash(str); |
60 |
|
for (sp = stab[hval]; sp != NULL; sp = sp->next) |
61 |
|
if (!strcmp(str, string(sp))) { |
75 |
|
|
76 |
|
|
77 |
|
void |
78 |
< |
freestr(s) /* free a string */ |
76 |
< |
char *s; |
78 |
> |
freestr(char *s) /* free a string */ |
79 |
|
{ |
80 |
|
int hval; |
81 |
< |
register S_HEAD *spl, *sp; |
81 |
> |
S_HEAD *spl, *sp; |
82 |
|
|
83 |
< |
if (s == NULL) |
83 |
> |
if (s == NULL || !*s) |
84 |
|
return; |
85 |
|
hval = hash(s); |
86 |
|
for (spl = NULL, sp = stab[hval]; sp != NULL; spl = sp, sp = sp->next) |
98 |
|
|
99 |
|
|
100 |
|
int |
101 |
< |
shash(s) |
100 |
< |
register char *s; |
101 |
> |
shash(char *s) |
102 |
|
{ |
103 |
< |
register int h = 0; |
103 |
> |
int h = 0; |
104 |
|
|
105 |
|
while (*s) |
106 |
|
h = (h<<1 & 0x7fff) ^ (*s++ & 0xff); |