1 /* -*- buffer-read-only: t -*- vi: set ro:
2 *
3 * DO NOT EDIT THIS FILE (stdin.c)
4 *
5 * It has been AutoGen-ed
6 * From the definitions stdin
7 * and the template file str2enum
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name ``Bruce Korb'' nor the name of any other
18 * contributor may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * str2enum IS PROVIDED BY Bruce Korb ``AS IS'' AND ANY EXPRESS
22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL Bruce Korb OR ANY OTHER CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 #include "option-value-type.h"
34 /* ANSI-C code produced by gperf version 3.1 */
35 /* Command-line: gperf option-value-type.gp */
36 /* Computed positions: -k'1' */
37
38
39
40 # if 0 /* gperf build options: */
41 // %struct-type
42 // %language=ANSI-C
43 // %includes
44 // %global-table
45 // %omit-struct-type
46 // %readonly-tables
47 // %compare-strncmp
48 //
49 // %define slot-name vtp_name
50 // %define hash-function-name option_value_type_hash
51 // %define lookup-function-name find_option_value_type_name
52 // %define word-array-name option_value_type_table
53 // %define initializer-suffix ,VTP_COUNT_CMD
54 //
55 # endif
56
57 #include "option-value-type.h"
58 typedef struct {
59 char const * vtp_name;
60 option_value_type_enum_t vtp_id;
61 } option_value_type_map_t;
62 #include <string.h>
63
64 /* maximum key range = 15, duplicates = 0 */
65
66 static unsigned int
option_value_type_hash(register const char * str,register size_t len)67 option_value_type_hash (register const char *str, register size_t len)
68 {
69 static const unsigned char asso_values[] =
70 {
71 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
72 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
73 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
74 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
75 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
76 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
77 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
78 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
79 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
80 18, 18, 18, 18, 18, 18, 18, 18, 0, 18,
81 18, 18, 18, 18, 0, 10, 18, 5, 18, 18,
82 5, 18, 18, 18, 18, 0, 18, 18, 18, 18,
83 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
84 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
85 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
86 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
87 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
88 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
89 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
90 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
91 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
92 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
93 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
94 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
95 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
96 18, 18, 18, 18, 18, 18
97 };
98 return len + asso_values[(unsigned char)str[0]];
99 }
100
101 static const option_value_type_map_t option_value_type_table[] =
102 {
103 {"",VTP_COUNT_CMD}, {"",VTP_COUNT_CMD},
104 {"",VTP_COUNT_CMD},
105 {"set", VTP_CMD_SET},
106 {"bool", VTP_CMD_BOOL},
107 {"",VTP_COUNT_CMD},
108 {"string", VTP_CMD_STRING},
109 {"boolean", VTP_CMD_BOOLEAN},
110 {"",VTP_COUNT_CMD},
111 {"hierarchy", VTP_CMD_HIERARCHY},
112 {"",VTP_COUNT_CMD},
113 {"nested", VTP_CMD_NESTED},
114 {"keyword", VTP_CMD_KEYWORD},
115 {"",VTP_COUNT_CMD},
116 {"set-membership", VTP_CMD_SET_MEMBERSHIP},
117 {"",VTP_COUNT_CMD}, {"",VTP_COUNT_CMD},
118 {"integer", VTP_CMD_INTEGER}
119 };
120
121 static inline const option_value_type_map_t *
find_option_value_type_name(register const char * str,register size_t len)122 find_option_value_type_name (register const char *str, register size_t len)
123 {
124 if (len <= 14 && len >= 3)
125 {
126 register unsigned int key = (int)option_value_type_hash (str, len);
127
128 if (key <= 17)
129 {
130 register const char *s = option_value_type_table[key].vtp_name;
131
132 if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0')
133 return &option_value_type_table[key];
134 }
135 }
136 return 0;
137 }
138
139 /**
140 * Convert a command (keyword) to a option_value_type_enum_t enumeration value.
141 *
142 * @param[in] str a string that should start with a known key word.
143 * @param[in] len the provided length of the keyword at \a str.
144 * @returns the enumeration value.
145 * If not found, that value is VTP_INVALID_CMD.
146 */
147 option_value_type_enum_t
find_option_value_type_cmd(char const * str,size_t len)148 find_option_value_type_cmd(char const * str, size_t len)
149 {
150 option_value_type_map_t const * map;
151
152 map = find_option_value_type_name(str, (unsigned int)len);
153 return (map == NULL) ? VTP_INVALID_CMD : map->vtp_id;
154 }
155
156 /* end of option-value-type.c */
157