1275970Scy/* -*- buffer-read-only: t -*- vi: set ro: 2275970Scy * 3275970Scy * DO NOT EDIT THIS FILE (stdin.c) 4275970Scy * 5285169Scy * It has been AutoGen-ed 6275970Scy * From the definitions stdin 7275970Scy * and the template file str2enum 8275970Scy * 9275970Scy * Redistribution and use in source and binary forms, with or without 10275970Scy * modification, are permitted provided that the following conditions 11275970Scy * are met: 12275970Scy * 1. Redistributions of source code must retain the above copyright 13275970Scy * notice, this list of conditions and the following disclaimer. 14275970Scy * 2. Redistributions in binary form must reproduce the above copyright 15275970Scy * notice, this list of conditions and the following disclaimer in the 16275970Scy * documentation and/or other materials provided with the distribution. 17275970Scy * 3. Neither the name ``Bruce Korb'' nor the name of any other 18275970Scy * contributor may be used to endorse or promote products derived 19275970Scy * from this software without specific prior written permission. 20275970Scy * 21275970Scy * str2enum IS PROVIDED BY Bruce Korb ``AS IS'' AND ANY EXPRESS 22275970Scy * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23275970Scy * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24275970Scy * ARE DISCLAIMED. IN NO EVENT SHALL Bruce Korb OR ANY OTHER CONTRIBUTORS 25275970Scy * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26275970Scy * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27275970Scy * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 28275970Scy * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29275970Scy * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30275970Scy * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 31275970Scy * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32275970Scy */ 33275970Scy#include "option-xat-attribute.h" 34285169Scy/* ANSI-C code produced by gperf version 3.0.4 */ 35275970Scy/* Command-line: gperf option-xat-attribute.gp */ 36275970Scy/* Computed positions: -k'1' */ 37275970Scy 38275970Scy 39275970Scy 40275970Scy# if 0 /* gperf build options: */ 41275970Scy// %struct-type 42275970Scy// %language=ANSI-C 43275970Scy// %includes 44275970Scy// %global-table 45275970Scy// %omit-struct-type 46275970Scy// %readonly-tables 47275970Scy// %compare-strncmp 48275970Scy// 49275970Scy// %define slot-name xat_name 50275970Scy// %define hash-function-name option_xat_attribute_hash 51275970Scy// %define lookup-function-name find_option_xat_attribute_name 52275970Scy// %define word-array-name option_xat_attribute_table 53275970Scy// %define initializer-suffix ,XAT_COUNT_CMD 54275970Scy// 55275970Scy# endif 56275970Scy 57275970Scy#include "option-xat-attribute.h" 58275970Scytypedef struct { 59275970Scy char const * xat_name; 60275970Scy option_xat_attribute_enum_t xat_id; 61275970Scy} option_xat_attribute_map_t; 62275970Scy#include <string.h> 63275970Scy 64275970Scy/* maximum key range = 6, duplicates = 0 */ 65275970Scy 66275970Scystatic unsigned int 67275970Scyoption_xat_attribute_hash (register const char *str, register unsigned int len) 68275970Scy{ 69275970Scy static const unsigned char asso_values[] = 70275970Scy { 71275970Scy 10,10,10,10,10,10,10,10,10,10, 72275970Scy 10,10,10,10,10,10,10,10,10,10, 73275970Scy 10,10,10,10,10,10,10,10,10,10, 74275970Scy 10,10,10,10,10,10,10,10,10,10, 75275970Scy 10,10,10,10,10,10,10,10,10,10, 76275970Scy 10,10,10,10,10,10,10,10,10,10, 77275970Scy 10,10,10,10,10,10,10,10,10,10, 78275970Scy 10,10,10,10,10,10,10,10,10,10, 79275970Scy 10,10,10,10,10,10,10,10,10,10, 80275970Scy 10,10,10,10,10,10,10,10,10, 0, 81275970Scy 10,10,10,10,10,10,10, 5,10, 0, 82275970Scy 10,10,10,10,10,10, 0, 0,10, 0, 83275970Scy 10,10,10,10,10,10,10,10,10,10, 84275970Scy 10,10,10,10,10,10,10,10,10,10, 85275970Scy 10,10,10,10,10,10,10,10,10,10, 86275970Scy 10,10,10,10,10,10,10,10,10,10, 87275970Scy 10,10,10,10,10,10,10,10,10,10, 88275970Scy 10,10,10,10,10,10,10,10,10,10, 89275970Scy 10,10,10,10,10,10,10,10,10,10, 90275970Scy 10,10,10,10,10,10,10,10,10,10, 91275970Scy 10,10,10,10,10,10,10,10,10,10, 92275970Scy 10,10,10,10,10,10,10,10,10,10, 93275970Scy 10,10,10,10,10,10,10,10,10,10, 94275970Scy 10,10,10,10,10,10,10,10,10,10, 95275970Scy 10,10,10,10,10,10,10,10,10,10, 96275970Scy 10,10,10,10,10,10 97275970Scy }; 98275970Scy return len + asso_values[(unsigned char)str[0]]; 99275970Scy} 100275970Scy 101275970Scystatic const option_xat_attribute_map_t option_xat_attribute_table[] = 102275970Scy { 103275970Scy {"",XAT_COUNT_CMD}, {"",XAT_COUNT_CMD}, 104275970Scy {"",XAT_COUNT_CMD}, {"",XAT_COUNT_CMD}, 105275970Scy {"type", XAT_CMD_TYPE}, 106275970Scy {"words", XAT_CMD_WORDS}, 107275970Scy {"cooked", XAT_CMD_COOKED}, 108275970Scy {"members", XAT_CMD_MEMBERS}, 109275970Scy {"uncooked", XAT_CMD_UNCOOKED}, 110275970Scy {"keep", XAT_CMD_KEEP} 111275970Scy }; 112275970Scy 113275970Scystatic inline const option_xat_attribute_map_t * 114275970Scyfind_option_xat_attribute_name (register const char *str, register unsigned int len) 115275970Scy{ 116275970Scy if (len <= 8 && len >= 4) 117275970Scy { 118275970Scy register int key = (int)option_xat_attribute_hash (str, len); 119275970Scy 120275970Scy if (key <= 9 && key >= 0) 121275970Scy { 122275970Scy register const char *s = option_xat_attribute_table[key].xat_name; 123275970Scy 124275970Scy if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0') 125275970Scy return &option_xat_attribute_table[key]; 126275970Scy } 127275970Scy } 128275970Scy return 0; 129275970Scy} 130275970Scy 131275970Scy/** 132275970Scy * Convert a command (keyword) to a option_xat_attribute_enum_t enumeration value. 133275970Scy * 134275970Scy * @param[in] str a string that should start with a known key word. 135275970Scy * @param[in] len the provided length of the keyword at \a str. 136275970Scy * @returns the enumeration value. 137275970Scy * If not found, that value is XAT_INVALID_CMD. 138275970Scy */ 139275970Scyoption_xat_attribute_enum_t 140275970Scyfind_option_xat_attribute_cmd(char const * str, size_t len) 141275970Scy{ 142275970Scy option_xat_attribute_map_t const * map; 143275970Scy 144275970Scy map = find_option_xat_attribute_name(str, (unsigned int)len); 145275970Scy return (map == NULL) ? XAT_INVALID_CMD : map->xat_id; 146275970Scy} 147275970Scy 148275970Scy/* end of option-xat-attribute.c */ 149