12b15cb3dSCy Schubert /* -*- buffer-read-only: t -*- vi: set ro: 22b15cb3dSCy Schubert * 32b15cb3dSCy Schubert * DO NOT EDIT THIS FILE (stdin.c) 42b15cb3dSCy Schubert * 5*276da39aSCy Schubert * It has been AutoGen-ed 62b15cb3dSCy Schubert * From the definitions stdin 72b15cb3dSCy Schubert * and the template file str2enum 82b15cb3dSCy Schubert * 92b15cb3dSCy Schubert * Redistribution and use in source and binary forms, with or without 102b15cb3dSCy Schubert * modification, are permitted provided that the following conditions 112b15cb3dSCy Schubert * are met: 122b15cb3dSCy Schubert * 1. Redistributions of source code must retain the above copyright 132b15cb3dSCy Schubert * notice, this list of conditions and the following disclaimer. 142b15cb3dSCy Schubert * 2. Redistributions in binary form must reproduce the above copyright 152b15cb3dSCy Schubert * notice, this list of conditions and the following disclaimer in the 162b15cb3dSCy Schubert * documentation and/or other materials provided with the distribution. 172b15cb3dSCy Schubert * 3. Neither the name ``Bruce Korb'' nor the name of any other 182b15cb3dSCy Schubert * contributor may be used to endorse or promote products derived 192b15cb3dSCy Schubert * from this software without specific prior written permission. 202b15cb3dSCy Schubert * 212b15cb3dSCy Schubert * str2enum IS PROVIDED BY Bruce Korb ``AS IS'' AND ANY EXPRESS 222b15cb3dSCy Schubert * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 232b15cb3dSCy Schubert * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 242b15cb3dSCy Schubert * ARE DISCLAIMED. IN NO EVENT SHALL Bruce Korb OR ANY OTHER CONTRIBUTORS 252b15cb3dSCy Schubert * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 262b15cb3dSCy Schubert * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 272b15cb3dSCy Schubert * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 282b15cb3dSCy Schubert * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 292b15cb3dSCy Schubert * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 302b15cb3dSCy Schubert * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 312b15cb3dSCy Schubert * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 322b15cb3dSCy Schubert */ 332b15cb3dSCy Schubert #include "option-xat-attribute.h" 34*276da39aSCy Schubert /* ANSI-C code produced by gperf version 3.0.4 */ 352b15cb3dSCy Schubert /* Command-line: gperf option-xat-attribute.gp */ 362b15cb3dSCy Schubert /* Computed positions: -k'1' */ 372b15cb3dSCy Schubert 382b15cb3dSCy Schubert 392b15cb3dSCy Schubert 402b15cb3dSCy Schubert # if 0 /* gperf build options: */ 412b15cb3dSCy Schubert // %struct-type 422b15cb3dSCy Schubert // %language=ANSI-C 432b15cb3dSCy Schubert // %includes 442b15cb3dSCy Schubert // %global-table 452b15cb3dSCy Schubert // %omit-struct-type 462b15cb3dSCy Schubert // %readonly-tables 472b15cb3dSCy Schubert // %compare-strncmp 482b15cb3dSCy Schubert // 492b15cb3dSCy Schubert // %define slot-name xat_name 502b15cb3dSCy Schubert // %define hash-function-name option_xat_attribute_hash 512b15cb3dSCy Schubert // %define lookup-function-name find_option_xat_attribute_name 522b15cb3dSCy Schubert // %define word-array-name option_xat_attribute_table 532b15cb3dSCy Schubert // %define initializer-suffix ,XAT_COUNT_CMD 542b15cb3dSCy Schubert // 552b15cb3dSCy Schubert # endif 562b15cb3dSCy Schubert 572b15cb3dSCy Schubert #include "option-xat-attribute.h" 582b15cb3dSCy Schubert typedef struct { 592b15cb3dSCy Schubert char const * xat_name; 602b15cb3dSCy Schubert option_xat_attribute_enum_t xat_id; 612b15cb3dSCy Schubert } option_xat_attribute_map_t; 622b15cb3dSCy Schubert #include <string.h> 632b15cb3dSCy Schubert 642b15cb3dSCy Schubert /* maximum key range = 6, duplicates = 0 */ 652b15cb3dSCy Schubert 662b15cb3dSCy Schubert static unsigned int 672b15cb3dSCy Schubert option_xat_attribute_hash (register const char *str, register unsigned int len) 682b15cb3dSCy Schubert { 692b15cb3dSCy Schubert static const unsigned char asso_values[] = 702b15cb3dSCy Schubert { 712b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10,10, 722b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10,10, 732b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10,10, 742b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10,10, 752b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10,10, 762b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10,10, 772b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10,10, 782b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10,10, 792b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10,10, 802b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10, 0, 812b15cb3dSCy Schubert 10,10,10,10,10,10,10, 5,10, 0, 822b15cb3dSCy Schubert 10,10,10,10,10,10, 0, 0,10, 0, 832b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10,10, 842b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10,10, 852b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10,10, 862b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10,10, 872b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10,10, 882b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10,10, 892b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10,10, 902b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10,10, 912b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10,10, 922b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10,10, 932b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10,10, 942b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10,10, 952b15cb3dSCy Schubert 10,10,10,10,10,10,10,10,10,10, 962b15cb3dSCy Schubert 10,10,10,10,10,10 972b15cb3dSCy Schubert }; 982b15cb3dSCy Schubert return len + asso_values[(unsigned char)str[0]]; 992b15cb3dSCy Schubert } 1002b15cb3dSCy Schubert 1012b15cb3dSCy Schubert static const option_xat_attribute_map_t option_xat_attribute_table[] = 1022b15cb3dSCy Schubert { 1032b15cb3dSCy Schubert {"",XAT_COUNT_CMD}, {"",XAT_COUNT_CMD}, 1042b15cb3dSCy Schubert {"",XAT_COUNT_CMD}, {"",XAT_COUNT_CMD}, 1052b15cb3dSCy Schubert {"type", XAT_CMD_TYPE}, 1062b15cb3dSCy Schubert {"words", XAT_CMD_WORDS}, 1072b15cb3dSCy Schubert {"cooked", XAT_CMD_COOKED}, 1082b15cb3dSCy Schubert {"members", XAT_CMD_MEMBERS}, 1092b15cb3dSCy Schubert {"uncooked", XAT_CMD_UNCOOKED}, 1102b15cb3dSCy Schubert {"keep", XAT_CMD_KEEP} 1112b15cb3dSCy Schubert }; 1122b15cb3dSCy Schubert 1132b15cb3dSCy Schubert static inline const option_xat_attribute_map_t * 1142b15cb3dSCy Schubert find_option_xat_attribute_name (register const char *str, register unsigned int len) 1152b15cb3dSCy Schubert { 1162b15cb3dSCy Schubert if (len <= 8 && len >= 4) 1172b15cb3dSCy Schubert { 1182b15cb3dSCy Schubert register int key = (int)option_xat_attribute_hash (str, len); 1192b15cb3dSCy Schubert 1202b15cb3dSCy Schubert if (key <= 9 && key >= 0) 1212b15cb3dSCy Schubert { 1222b15cb3dSCy Schubert register const char *s = option_xat_attribute_table[key].xat_name; 1232b15cb3dSCy Schubert 1242b15cb3dSCy Schubert if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0') 1252b15cb3dSCy Schubert return &option_xat_attribute_table[key]; 1262b15cb3dSCy Schubert } 1272b15cb3dSCy Schubert } 1282b15cb3dSCy Schubert return 0; 1292b15cb3dSCy Schubert } 1302b15cb3dSCy Schubert 1312b15cb3dSCy Schubert /** 1322b15cb3dSCy Schubert * Convert a command (keyword) to a option_xat_attribute_enum_t enumeration value. 1332b15cb3dSCy Schubert * 1342b15cb3dSCy Schubert * @param[in] str a string that should start with a known key word. 1352b15cb3dSCy Schubert * @param[in] len the provided length of the keyword at \a str. 1362b15cb3dSCy Schubert * @returns the enumeration value. 1372b15cb3dSCy Schubert * If not found, that value is XAT_INVALID_CMD. 1382b15cb3dSCy Schubert */ 1392b15cb3dSCy Schubert option_xat_attribute_enum_t 1402b15cb3dSCy Schubert find_option_xat_attribute_cmd(char const * str, size_t len) 1412b15cb3dSCy Schubert { 1422b15cb3dSCy Schubert option_xat_attribute_map_t const * map; 1432b15cb3dSCy Schubert 1442b15cb3dSCy Schubert map = find_option_xat_attribute_name(str, (unsigned int)len); 1452b15cb3dSCy Schubert return (map == NULL) ? XAT_INVALID_CMD : map->xat_id; 1462b15cb3dSCy Schubert } 1472b15cb3dSCy Schubert 1482b15cb3dSCy Schubert /* end of option-xat-attribute.c */ 149