1 /* -*- buffer-read-only: t -*- vi: set ro:
3 * DO NOT EDIT THIS FILE (stdin.c)
5 * It has been AutoGen-ed
6 * From the definitions stdin
7 * and the template file str2enum
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
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.
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' */
40 # if 0 /* gperf build options: */
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
57 #include "option-xat-attribute.h"
59 char const * xat_name;
60 option_xat_attribute_enum_t xat_id;
61 } option_xat_attribute_map_t;
64 /* maximum key range = 6, duplicates = 0 */
67 option_xat_attribute_hash (register const char *str, register unsigned int len)
69 static const unsigned char asso_values[] =
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,
98 return len + asso_values[(unsigned char)str[0]];
101 static const option_xat_attribute_map_t option_xat_attribute_table[] =
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}
113 static inline const option_xat_attribute_map_t *
114 find_option_xat_attribute_name (register const char *str, register unsigned int len)
116 if (len <= 8 && len >= 4)
118 register int key = (int)option_xat_attribute_hash (str, len);
120 if (key <= 9 && key >= 0)
122 register const char *s = option_xat_attribute_table[key].xat_name;
124 if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0')
125 return &option_xat_attribute_table[key];
132 * Convert a command (keyword) to a option_xat_attribute_enum_t enumeration value.
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.
139 option_xat_attribute_enum_t
140 find_option_xat_attribute_cmd(char const * str, size_t len)
142 option_xat_attribute_map_t const * map;
144 map = find_option_xat_attribute_name(str, (unsigned int)len);
145 return (map == NULL) ? XAT_INVALID_CMD : map->xat_id;
148 /* end of option-xat-attribute.c */