40 #include <visp3/core/vpConfig.h>
41 #include <visp3/core/vpException.h>
43 #include "vpKeyword.h"
50 #ifndef DOXYGEN_SHOULD_SKIP_THIS
52 static void open_hash(
void);
53 static void close_hash(
void);
54 static int hashpjw(
const char *str);
55 static void insert_keyword(
const char *str, Index token);
58 static void delete_keyword(
void);
59 static char *get_keyword(
void);
63 #define NEXT(x) (x) = (x)->next
65 typedef struct bucket {
72 static Bucket **hash_tbl;
80 void open_keyword(Keyword *kwp)
83 for (; kwp->ident != NULL; kwp++)
84 insert_keyword(kwp->ident, kwp->token);
91 void close_keyword(
void) { close_hash(); }
96 static void open_hash(
void)
98 Bucket **head, **bend;
100 if ((hash_tbl = (Bucket **)malloc(
sizeof(Bucket *) * PRIME)) == NULL) {
101 static char proc_name[] =
"open_hash";
107 for (; head < bend; *head++ = NULL) {
114 static void close_hash(
void)
116 Bucket **head = hash_tbl;
117 Bucket **bend = head + PRIME;
121 for (; head < bend; head++) {
122 for (bp = *head; bp != NULL; bp = next) {
127 free((
char *)hash_tbl);
142 static int hashpjw(
const char *str)
146 for (; *str !=
'\0'; str++) {
148 h = (h << 4) + (
unsigned)(*str);
149 if ((g = h & ~0xfffffff) != 0) {
154 return ((
int)(h % PRIME));
165 static void insert_keyword(
const char *str, Index token)
167 Bucket **head = hash_tbl + hashpjw(str);
171 length = (
Byte)(strlen(str));
172 if ((bp = (Bucket *)malloc(
sizeof(Bucket) + length + 1)) == NULL) {
173 static const char proc_name[] =
"insert_keyword";
179 bp->ident = (
char *)(bp + 1);
180 strcpy(bp->ident, str);
197 Index get_symbol(
char *ident,
int length)
207 for (; len != 0; idn++, len--) {
209 h = (h << 4) + (
unsigned)(*idn);
210 if ((g = h & ~0xfffffff) != 0) {
215 bp = hash_tbl[h % PRIME];
220 for (; bp != NULL; NEXT(bp)) {
221 if (length == bp->length) {
225 for (; *idn == *kwd; idn++, kwd++) {
error that can be emitted by ViSP classes.