Blame src/libopts/option-xat-attribute.c

Packit aea12f
/*   -*- buffer-read-only: t -*- vi: set ro:
Packit aea12f
 *
Packit aea12f
 *  DO NOT EDIT THIS FILE   (stdin.c)
Packit aea12f
 *
Packit aea12f
 *  It has been AutoGen-ed
Packit aea12f
 *  From the definitions    stdin
Packit aea12f
 *  and the template file   str2enum
Packit aea12f
 *
Packit aea12f
 * Redistribution and use in source and binary forms, with or without
Packit aea12f
 * modification, are permitted provided that the following conditions
Packit aea12f
 * are met:
Packit aea12f
 * 1. Redistributions of source code must retain the above copyright
Packit aea12f
 *    notice, this list of conditions and the following disclaimer.
Packit aea12f
 * 2. Redistributions in binary form must reproduce the above copyright
Packit aea12f
 *    notice, this list of conditions and the following disclaimer in the
Packit aea12f
 *    documentation and/or other materials provided with the distribution.
Packit aea12f
 * 3. Neither the name ``Bruce Korb'' nor the name of any other
Packit aea12f
 *    contributor may be used to endorse or promote products derived
Packit aea12f
 *    from this software without specific prior written permission.
Packit aea12f
 *
Packit aea12f
 * str2enum IS PROVIDED BY Bruce Korb ``AS IS'' AND ANY EXPRESS
Packit aea12f
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Packit aea12f
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit aea12f
 * ARE DISCLAIMED.  IN NO EVENT SHALL Bruce Korb OR ANY OTHER CONTRIBUTORS
Packit aea12f
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Packit aea12f
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Packit aea12f
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
Packit aea12f
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
Packit aea12f
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
Packit aea12f
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
Packit aea12f
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit aea12f
 */
Packit aea12f
#include "option-xat-attribute.h"
Packit Service 991b93
/* ANSI-C code produced by gperf version 3.1 */
Packit aea12f
/* Command-line: gperf option-xat-attribute.gp  */
Packit aea12f
/* Computed positions: -k'1' */
Packit aea12f
Packit aea12f
Packit aea12f
Packit aea12f
# if 0 /* gperf build options: */
Packit aea12f
// %struct-type
Packit aea12f
// %language=ANSI-C
Packit aea12f
// %includes
Packit aea12f
// %global-table
Packit aea12f
// %omit-struct-type
Packit aea12f
// %readonly-tables
Packit aea12f
// %compare-strncmp
Packit aea12f
//
Packit aea12f
// %define slot-name               xat_name
Packit aea12f
// %define hash-function-name      option_xat_attribute_hash
Packit aea12f
// %define lookup-function-name    find_option_xat_attribute_name
Packit aea12f
// %define word-array-name         option_xat_attribute_table
Packit aea12f
// %define initializer-suffix      ,XAT_COUNT_CMD
Packit aea12f
//
Packit aea12f
# endif
Packit aea12f
Packit aea12f
#include "option-xat-attribute.h"
Packit aea12f
typedef struct {
Packit aea12f
    char const *    xat_name;
Packit aea12f
    option_xat_attribute_enum_t xat_id;
Packit aea12f
} option_xat_attribute_map_t;
Packit aea12f
#include <string.h>
Packit aea12f
Packit aea12f
/* maximum key range = 6, duplicates = 0 */
Packit aea12f
Packit aea12f
static unsigned int
Packit Service 991b93
option_xat_attribute_hash (register const char *str, register size_t len)
Packit aea12f
{
Packit aea12f
  static const unsigned char asso_values[] =
Packit aea12f
    {
Packit aea12f
     10,10,10,10,10,10,10,10,10,10,
Packit aea12f
     10,10,10,10,10,10,10,10,10,10,
Packit aea12f
     10,10,10,10,10,10,10,10,10,10,
Packit aea12f
     10,10,10,10,10,10,10,10,10,10,
Packit aea12f
     10,10,10,10,10,10,10,10,10,10,
Packit aea12f
     10,10,10,10,10,10,10,10,10,10,
Packit aea12f
     10,10,10,10,10,10,10,10,10,10,
Packit aea12f
     10,10,10,10,10,10,10,10,10,10,
Packit aea12f
     10,10,10,10,10,10,10,10,10,10,
Packit aea12f
     10,10,10,10,10,10,10,10,10, 0,
Packit aea12f
     10,10,10,10,10,10,10, 5,10, 0,
Packit aea12f
     10,10,10,10,10,10, 0, 0,10, 0,
Packit aea12f
     10,10,10,10,10,10,10,10,10,10,
Packit aea12f
     10,10,10,10,10,10,10,10,10,10,
Packit aea12f
     10,10,10,10,10,10,10,10,10,10,
Packit aea12f
     10,10,10,10,10,10,10,10,10,10,
Packit aea12f
     10,10,10,10,10,10,10,10,10,10,
Packit aea12f
     10,10,10,10,10,10,10,10,10,10,
Packit aea12f
     10,10,10,10,10,10,10,10,10,10,
Packit aea12f
     10,10,10,10,10,10,10,10,10,10,
Packit aea12f
     10,10,10,10,10,10,10,10,10,10,
Packit aea12f
     10,10,10,10,10,10,10,10,10,10,
Packit aea12f
     10,10,10,10,10,10,10,10,10,10,
Packit aea12f
     10,10,10,10,10,10,10,10,10,10,
Packit aea12f
     10,10,10,10,10,10,10,10,10,10,
Packit aea12f
     10,10,10,10,10,10
Packit aea12f
    };
Packit aea12f
  return len + asso_values[(unsigned char)str[0]];
Packit aea12f
}
Packit aea12f
Packit aea12f
static const option_xat_attribute_map_t option_xat_attribute_table[] =
Packit aea12f
  {
Packit aea12f
    {"",XAT_COUNT_CMD}, {"",XAT_COUNT_CMD},
Packit aea12f
    {"",XAT_COUNT_CMD}, {"",XAT_COUNT_CMD},
Packit aea12f
    {"type",     XAT_CMD_TYPE},
Packit aea12f
    {"words",    XAT_CMD_WORDS},
Packit aea12f
    {"cooked",   XAT_CMD_COOKED},
Packit aea12f
    {"members",  XAT_CMD_MEMBERS},
Packit aea12f
    {"uncooked", XAT_CMD_UNCOOKED},
Packit aea12f
    {"keep",     XAT_CMD_KEEP}
Packit aea12f
  };
Packit aea12f
Packit aea12f
static inline const option_xat_attribute_map_t *
Packit Service 991b93
find_option_xat_attribute_name (register const char *str, register size_t len)
Packit aea12f
{
Packit aea12f
  if (len <= 8 && len >= 4)
Packit aea12f
    {
Packit Service 991b93
      register unsigned int key = (int)option_xat_attribute_hash (str, len);
Packit aea12f
Packit Service 991b93
      if (key <= 9)
Packit aea12f
        {
Packit aea12f
          register const char *s = option_xat_attribute_table[key].xat_name;
Packit aea12f
Packit aea12f
          if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0')
Packit aea12f
            return &option_xat_attribute_table[key];
Packit aea12f
        }
Packit aea12f
    }
Packit aea12f
  return 0;
Packit aea12f
}
Packit aea12f
Packit aea12f
/**
Packit aea12f
 * Convert a command (keyword) to a option_xat_attribute_enum_t enumeration value.
Packit aea12f
 *
Packit aea12f
 * @param[in] str   a string that should start with a known key word.
Packit aea12f
 * @param[in] len   the provided length of the keyword at \a str.
Packit aea12f
 * @returns the enumeration value.
Packit aea12f
 * If not found, that value is XAT_INVALID_CMD.
Packit aea12f
 */
Packit aea12f
option_xat_attribute_enum_t
Packit aea12f
find_option_xat_attribute_cmd(char const * str, size_t len)
Packit aea12f
{
Packit aea12f
    option_xat_attribute_map_t const * map;
Packit aea12f
Packit aea12f
    map = find_option_xat_attribute_name(str, (unsigned int)len);
Packit aea12f
    return (map == NULL) ? XAT_INVALID_CMD : map->xat_id;
Packit aea12f
}
Packit aea12f
Packit aea12f
/* end of option-xat-attribute.c */