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-xat-attribute.h"
34 /* ANSI-C code produced by gperf version 3.0.4 */
35 /* Command-line: gperf option-xat-attribute.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 xat_name
50 // %define hash-function-name option_xat_attribute_hash
51 // %define lookup-function-name find_option_xat_attribute_name
52 // %define word-array-name option_xat_attribute_table
53 // %define initializer-suffix ,XAT_COUNT_CMD
54 //
55 # endif
56
57 #include "option-xat-attribute.h"
58 typedef struct {
59 char const * xat_name;
60 option_xat_attribute_enum_t xat_id;
61 } option_xat_attribute_map_t;
62 #include <string.h>
63
64 /* maximum key range = 6, duplicates = 0 */
65
66 static unsigned int
option_xat_attribute_hash(register const char * str,register unsigned int len)67 option_xat_attribute_hash (register const char *str, register unsigned int len)
68 {
69 static const unsigned char asso_values[] =
70 {
71 10,10,10,10,10,10,10,10,10,10,
72 10,10,10,10,10,10,10,10,10,10,
73 10,10,10,10,10,10,10,10,10,10,
74 10,10,10,10,10,10,10,10,10,10,
75 10,10,10,10,10,10,10,10,10,10,
76 10,10,10,10,10,10,10,10,10,10,
77 10,10,10,10,10,10,10,10,10,10,
78 10,10,10,10,10,10,10,10,10,10,
79 10,10,10,10,10,10,10,10,10,10,
80 10,10,10,10,10,10,10,10,10, 0,
81 10,10,10,10,10,10,10, 5,10, 0,
82 10,10,10,10,10,10, 0, 0,10, 0,
83 10,10,10,10,10,10,10,10,10,10,
84 10,10,10,10,10,10,10,10,10,10,
85 10,10,10,10,10,10,10,10,10,10,
86 10,10,10,10,10,10,10,10,10,10,
87 10,10,10,10,10,10,10,10,10,10,
88 10,10,10,10,10,10,10,10,10,10,
89 10,10,10,10,10,10,10,10,10,10,
90 10,10,10,10,10,10,10,10,10,10,
91 10,10,10,10,10,10,10,10,10,10,
92 10,10,10,10,10,10,10,10,10,10,
93 10,10,10,10,10,10,10,10,10,10,
94 10,10,10,10,10,10,10,10,10,10,
95 10,10,10,10,10,10,10,10,10,10,
96 10,10,10,10,10,10
97 };
98 return len + asso_values[(unsigned char)str[0]];
99 }
100
101 static const option_xat_attribute_map_t option_xat_attribute_table[] =
102 {
103 {"",XAT_COUNT_CMD}, {"",XAT_COUNT_CMD},
104 {"",XAT_COUNT_CMD}, {"",XAT_COUNT_CMD},
105 {"type", XAT_CMD_TYPE},
106 {"words", XAT_CMD_WORDS},
107 {"cooked", XAT_CMD_COOKED},
108 {"members", XAT_CMD_MEMBERS},
109 {"uncooked", XAT_CMD_UNCOOKED},
110 {"keep", XAT_CMD_KEEP}
111 };
112
113 static inline const option_xat_attribute_map_t *
find_option_xat_attribute_name(register const char * str,register unsigned int len)114 find_option_xat_attribute_name (register const char *str, register unsigned int len)
115 {
116 if (len <= 8 && len >= 4)
117 {
118 register int key = (int)option_xat_attribute_hash (str, len);
119
120 if (key <= 9 && key >= 0)
121 {
122 register const char *s = option_xat_attribute_table[key].xat_name;
123
124 if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0')
125 return &option_xat_attribute_table[key];
126 }
127 }
128 return 0;
129 }
130
131 /**
132 * Convert a command (keyword) to a option_xat_attribute_enum_t enumeration value.
133 *
134 * @param[in] str a string that should start with a known key word.
135 * @param[in] len the provided length of the keyword at \a str.
136 * @returns the enumeration value.
137 * If not found, that value is XAT_INVALID_CMD.
138 */
139 option_xat_attribute_enum_t
find_option_xat_attribute_cmd(char const * str,size_t len)140 find_option_xat_attribute_cmd(char const * str, size_t len)
141 {
142 option_xat_attribute_map_t const * map;
143
144 map = find_option_xat_attribute_name(str, (unsigned int)len);
145 return (map == NULL) ? XAT_INVALID_CMD : map->xat_id;
146 }
147
148 /* end of option-xat-attribute.c */
149