42 #include <visp3/robot/vpMy.h>
43 #include <visp3/robot/vpToken.h>
48 #ifndef DOXYGEN_SHOULD_SKIP_THIS
50 void open_keyword (Keyword *kwp);
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);
55 Index get_symbol (
char *ident,
int length);
58 static void delete_keyword (
void);
59 static char *get_keyword (
void);
64 #define NEXT(x) (x) = (x)->next
66 typedef struct bucket {
74 static Bucket **hash_tbl;
83 void open_keyword (Keyword *kwp)
86 for (; kwp->ident != NULL; kwp++)
87 insert_keyword (kwp->ident, kwp->token);
94 void close_keyword (
void)
105 static char proc_name[] =
"open_hash";
107 Bucket **head, **bend;
109 if ((hash_tbl = (Bucket **) malloc (
sizeof (Bucket *) * PRIME))==NULL){
115 for (; head < bend; *head++ = NULL) {};
124 Bucket **head = hash_tbl;
125 Bucket **bend = head + PRIME;
129 for (; head < bend; head++) {
130 for (bp = *head; bp != NULL; bp = next) {
135 free ((
char *) hash_tbl);
151 hashpjw (
const char *str)
156 for (; *str !=
'\0'; str++) {
157 h = (h << 4) + (
unsigned)(*str);
158 if ((g = h & ~0xfffffff) != 0) {
163 return ((
int)(h % PRIME));
176 insert_keyword (
const char *str, Index token)
178 static const char proc_name[] =
"insert_keyword";
180 Bucket **head = hash_tbl + hashpjw (str);
184 length = (Byte)( strlen(str) );
185 if ((bp = (Bucket *) malloc (
sizeof (Bucket) + length + 1)) == NULL) {
191 bp->ident = (
char *) (bp + 1);
192 strcpy (bp->ident, str);
209 Index get_symbol (
char *ident,
int length)
220 for (; len != 0; idn++, len--) {
221 h = (h << 4) + (
unsigned)(*idn);
222 if ((g = h & ~0xfffffff) != 0) {
227 bp = hash_tbl[h % PRIME];
232 for (; bp != NULL; NEXT(bp)) {
233 if (length == bp->length) {
237 for (; *idn == *kwd; idn++, kwd++)
238 if (--len == 0)
return (bp->token);