40 #include "vpKeyword.h" 47 #ifndef DOXYGEN_SHOULD_SKIP_THIS 49 static void open_hash(
void);
50 static void close_hash(
void);
51 static int hashpjw(
const char *str);
52 static void insert_keyword(
const char *str, Index token);
55 static void delete_keyword(
void);
56 static char *get_keyword(
void);
60 #define NEXT(x) (x) = (x)->next 62 typedef struct bucket {
69 static Bucket **hash_tbl;
77 void open_keyword(Keyword *kwp)
80 for (; kwp->ident != NULL; kwp++)
81 insert_keyword(kwp->ident, kwp->token);
88 void close_keyword(
void) { close_hash(); }
93 static void open_hash(
void)
95 Bucket **head, **bend;
97 if ((hash_tbl = (Bucket **)malloc(
sizeof(Bucket *) * PRIME)) == NULL) {
98 static char proc_name[] =
"open_hash";
104 for (; head < bend; *head++ = NULL) {
111 static void close_hash(
void)
113 Bucket **head = hash_tbl;
114 Bucket **bend = head + PRIME;
118 for (; head < bend; head++) {
119 for (bp = *head; bp != NULL; bp = next) {
124 free((
char *)hash_tbl);
139 static int hashpjw(
const char *str)
143 for (; *str !=
'\0'; str++) {
145 h = (h << 4) + (
unsigned)(*str);
146 if ((g = h & ~0xfffffff) != 0) {
151 return ((
int)(h % PRIME));
162 static void insert_keyword(
const char *str, Index token)
164 Bucket **head = hash_tbl + hashpjw(str);
168 length = (Byte)(strlen(str));
169 if ((bp = (Bucket *)malloc(
sizeof(Bucket) + length + 1)) == NULL) {
170 static const char proc_name[] =
"insert_keyword";
176 bp->ident = (
char *)(bp + 1);
177 strcpy(bp->ident, str);
194 Index get_symbol(
char *ident,
int length)
204 for (; len != 0; idn++, len--) {
206 h = (h << 4) + (
unsigned)(*idn);
207 if ((g = h & ~0xfffffff) != 0) {
212 bp = hash_tbl[h % PRIME];
217 for (; bp != NULL; NEXT(bp)) {
218 if (length == bp->length) {
222 for (; *idn == *kwd; idn++, kwd++) {