38#include <visp3/core/vpConfig.h>
39#include <visp3/core/vpException.h>
48#ifndef DOXYGEN_SHOULD_SKIP_THIS
50static void open_hash(
void);
51static void close_hash(
void);
52static int hashpjw(
const char *str);
53static void insert_keyword(
const char *str, Index token);
56static void delete_keyword(
void);
57static char *get_keyword(
void);
61#define NEXT(x) (x) = (x)->next
71static Bucket **hash_tbl;
79void open_keyword(Keyword *kwp)
82 for (; kwp->ident != NULL; kwp++)
83 insert_keyword(kwp->ident, kwp->token);
90void close_keyword(
void) { close_hash(); }
95static void open_hash(
void)
97 Bucket **head, **bend;
99 if ((hash_tbl = (Bucket **)malloc(
sizeof(Bucket *) * PRIME)) == NULL) {
100 static char proc_name[] =
"open_hash";
106 for (; head < bend; *head++ = NULL) {
113static void close_hash(
void)
115 Bucket **head = hash_tbl;
116 Bucket **bend = head + PRIME;
120 for (; head < bend; head++) {
121 for (bp = *head; bp != NULL; bp = next) {
126 free((
char *)hash_tbl);
141static int hashpjw(
const char *str)
145 for (; *
str !=
'\0';
str++) {
147 h = (h << 4) + static_cast<unsigned int>(*str);
148 if ((g = h & ~0xfffffff) != 0) {
153 return (
static_cast<int>(h % PRIME));
164static void insert_keyword(
const char *str, Index token)
166 Bucket **head = hash_tbl + hashpjw(str);
170 length = (Byte)(strlen(str));
171 if ((bp = (Bucket *)malloc(
sizeof(Bucket) + length + 1)) == NULL) {
172 static const char proc_name[] =
"insert_keyword";
178 bp->ident = (
char *)(bp + 1);
179 strcpy(bp->ident, str);
196Index get_symbol(
char *ident,
int length)
206 for (; len != 0; idn++, len--) {
208 h = (h << 4) + static_cast<unsigned int>(*idn);
209 if ((g = h & ~0xfffffff) != 0) {
214 bp = hash_tbl[
h % PRIME];
219 for (; bp != NULL; NEXT(bp)) {
220 if (length == bp->length) {
224 for (; *idn == *kwd; idn++, kwd++) {
error that can be emitted by ViSP classes.