45 #include <visp/vpMy.h>
46 #include <visp/vpToken.h>
51 #ifndef DOXYGEN_SHOULD_SKIP_THIS
53 void open_keyword (Keyword *kwp);
54 static void open_hash (
void);
55 static void close_hash (
void);
56 static int hashpjw (
const char *str);
57 static void insert_keyword (
const char *str, Index token);
58 Index get_symbol (
char *ident,
int length);
61 static void delete_keyword (
void);
62 static char *get_keyword (
void);
67 #define NEXT(x) (x) = (x)->next
69 typedef struct bucket {
77 static Bucket **hash_tbl;
86 void open_keyword (Keyword *kwp)
89 for (; kwp->ident != NULL; kwp++)
90 insert_keyword (kwp->ident, kwp->token);
97 void close_keyword (
void)
108 static char proc_name[] =
"open_hash";
110 Bucket **head, **bend;
112 if ((hash_tbl = (Bucket **) malloc (
sizeof (Bucket *) * PRIME))==NULL){
118 for (; head < bend; *head++ = NULL) {};
127 Bucket **head = hash_tbl;
128 Bucket **bend = head + PRIME;
132 for (; head < bend; head++) {
133 for (bp = *head; bp != NULL; bp = next) {
138 free ((
char *) hash_tbl);
154 hashpjw (
const char *str)
159 for (; *str !=
'\0'; str++) {
161 if ((g = h & ~0xfffffff) != 0) {
179 insert_keyword (
const char *str, Index token)
181 static const char proc_name[] =
"insert_keyword";
183 Bucket **head = hash_tbl + hashpjw (str);
187 length = (Byte)( strlen(str) );
188 if ((bp = (Bucket *) malloc (
sizeof (Bucket) + length + 1)) == NULL) {
194 bp->ident = (
char *) (bp + 1);
195 strcpy (bp->ident, str);
212 Index get_symbol (
char *ident,
int length)
223 for (; len != 0; idn++, len--) {
225 if ((g = h & ~0xfffffff) != 0) {
230 bp = hash_tbl[h % PRIME];
235 for (; bp != NULL; NEXT(bp)) {
236 if (length == bp->length) {
240 for (; *idn == *kwd; idn++, kwd++)
241 if (--len == 0)
return (bp->token);