option-value-type.c [plain text]
#include "option-value-type.h"
# if 0
# endif
#include "option-value-type.h"
typedef struct {
char const * vtp_name;
option_value_type_enum_t vtp_id;
} option_value_type_map_t;
#include <string.h>
static unsigned int
option_value_type_hash (register const char *str, register unsigned int len)
{
static const unsigned char asso_values[] =
{
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 0, 18,
18, 18, 18, 18, 0, 10, 18, 5, 18, 18,
5, 18, 18, 18, 18, 0, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
18, 18, 18, 18, 18, 18
};
return len + asso_values[(unsigned char)str[0]];
}
static const option_value_type_map_t option_value_type_table[] =
{
{"",VTP_COUNT_CMD}, {"",VTP_COUNT_CMD},
{"",VTP_COUNT_CMD},
{"set", VTP_CMD_SET},
{"bool", VTP_CMD_BOOL},
{"",VTP_COUNT_CMD},
{"string", VTP_CMD_STRING},
{"boolean", VTP_CMD_BOOLEAN},
{"",VTP_COUNT_CMD},
{"hierarchy", VTP_CMD_HIERARCHY},
{"",VTP_COUNT_CMD},
{"nested", VTP_CMD_NESTED},
{"keyword", VTP_CMD_KEYWORD},
{"",VTP_COUNT_CMD},
{"set-membership", VTP_CMD_SET_MEMBERSHIP},
{"",VTP_COUNT_CMD}, {"",VTP_COUNT_CMD},
{"integer", VTP_CMD_INTEGER}
};
static inline const option_value_type_map_t *
find_option_value_type_name (register const char *str, register unsigned int len)
{
if (len <= 14 && len >= 3)
{
register int key = (int)option_value_type_hash (str, len);
if (key <= 17 && key >= 0)
{
register const char *s = option_value_type_table[key].vtp_name;
if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0')
return &option_value_type_table[key];
}
}
return 0;
}
option_value_type_enum_t
find_option_value_type_cmd(char const * str, size_t len)
{
option_value_type_map_t const * map;
map = find_option_value_type_name(str, (unsigned int)len);
return (map == NULL) ? VTP_INVALID_CMD : map->vtp_id;
}