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
73 static Bucket **hash_tbl;
81 void open_keyword(Keyword *kwp)
84 for (; kwp->ident != NULL; kwp++)
85 insert_keyword(kwp->ident, kwp->token);
92 void close_keyword(
void) { close_hash(); }
97 static void open_hash(
void)
99 Bucket **head, **bend;
101 if ((hash_tbl = (Bucket **)malloc(
sizeof(Bucket *) * PRIME)) == NULL) {
102 static char proc_name[] =
"open_hash";
108 for (; head < bend; *head++ = NULL) {
115 static void close_hash(
void)
117 Bucket **head = hash_tbl;
118 Bucket **bend = head + PRIME;
122 for (; head < bend; head++) {
123 for (bp = *head; bp != NULL; bp = next) {
128 free((
char *)hash_tbl);
143 static int hashpjw(
const char *str)
147 for (; *str !=
'\0'; str++) {
149 h = (h << 4) + (
unsigned)(*str);
150 if ((g = h & ~0xfffffff) != 0) {
155 return ((
int)(h % PRIME));
166 static void insert_keyword(
const char *str, Index token)
168 Bucket **head = hash_tbl + hashpjw(str);
172 length = (Byte)(strlen(str));
173 if ((bp = (Bucket *)malloc(
sizeof(Bucket) + length + 1)) == NULL) {
174 static const char proc_name[] =
"insert_keyword";
180 bp->ident = (
char *)(bp + 1);
181 strcpy(bp->ident, str);
198 Index get_symbol(
char *ident,
int length)
208 for (; len != 0; idn++, len--) {
210 h = (h << 4) + (
unsigned)(*idn);
211 if ((g = h & ~0xfffffff) != 0) {
216 bp = hash_tbl[h % PRIME];
221 for (; bp != NULL; NEXT(bp)) {
222 if (length == bp->length) {
226 for (; *idn == *kwd; idn++, kwd++) {
error that can be emitted by ViSP classes.