44 #include "vpKeyword.h"
49 #ifndef DOXYGEN_SHOULD_SKIP_THIS
51 static void open_hash (
void);
52 static void close_hash (
void);
53 static int hashpjw (
const char *str);
54 static void insert_keyword (
const char *str, Index token);
57 static void delete_keyword (
void);
58 static char *get_keyword (
void);
63 #define NEXT(x) (x) = (x)->next
65 typedef struct bucket {
73 static Bucket **hash_tbl;
82 void open_keyword (Keyword *kwp)
85 for (; kwp->ident != NULL; kwp++)
86 insert_keyword (kwp->ident, kwp->token);
93 void close_keyword (
void)
104 Bucket **head, **bend;
106 if ((hash_tbl = (Bucket **) malloc (
sizeof (Bucket *) * PRIME))==NULL){
107 static char proc_name[] =
"open_hash";
113 for (; head < bend; *head++ = NULL) {};
122 Bucket **head = hash_tbl;
123 Bucket **bend = head + PRIME;
127 for (; head < bend; head++) {
128 for (bp = *head; bp != NULL; bp = next) {
133 free ((
char *) hash_tbl);
149 hashpjw (
const char *str)
153 for (; *str !=
'\0'; str++) {
155 h = (h << 4) + (
unsigned)(*str);
156 if ((g = h & ~0xfffffff) != 0) {
161 return ((
int)(h % PRIME));
174 insert_keyword (
const char *str, Index token)
176 Bucket **head = hash_tbl + hashpjw (str);
180 length = (Byte)( strlen(str) );
181 if ((bp = (Bucket *) malloc (
sizeof (Bucket) + length + 1)) == NULL) {
182 static const char proc_name[] =
"insert_keyword";
188 bp->ident = (
char *) (bp + 1);
189 strcpy (bp->ident, str);
206 Index get_symbol (
char *ident,
int length)
216 for (; len != 0; idn++, len--) {
218 h = (h << 4) + (
unsigned)(*idn);
219 if ((g = h & ~0xfffffff) != 0) {
224 bp = hash_tbl[h % PRIME];
229 for (; bp != NULL; NEXT(bp)) {
230 if (length == bp->length) {
234 for (; *idn == *kwd; idn++, kwd++) {
236 if (len == 0)
return (bp->token);