Blame src/libopts/option-value-type.c

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