option-xat-attribute.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* -*- buffer-read-only: t -*- vi: set ro:
  2. *
  3. * DO NOT EDIT THIS FILE (stdin.c)
  4. *
  5. * It has been AutoGen-ed
  6. * From the definitions stdin
  7. * and the template file str2enum
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  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.
  20. *
  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.
  32. */
  33. #include "option-xat-attribute.h"
  34. /* ANSI-C code produced by gperf version 3.1 */
  35. /* Command-line: gperf option-xat-attribute.gp */
  36. /* Computed positions: -k'1' */
  37. # if 0 /* gperf build options: */
  38. // %struct-type
  39. // %language=ANSI-C
  40. // %includes
  41. // %global-table
  42. // %omit-struct-type
  43. // %readonly-tables
  44. // %compare-strncmp
  45. //
  46. // %define slot-name xat_name
  47. // %define hash-function-name option_xat_attribute_hash
  48. // %define lookup-function-name find_option_xat_attribute_name
  49. // %define word-array-name option_xat_attribute_table
  50. // %define initializer-suffix ,XAT_COUNT_CMD
  51. //
  52. # endif
  53. #include "option-xat-attribute.h"
  54. typedef struct {
  55. char const * xat_name;
  56. option_xat_attribute_enum_t xat_id;
  57. } option_xat_attribute_map_t;
  58. #include <string.h>
  59. /* maximum key range = 6, duplicates = 0 */
  60. static unsigned int
  61. option_xat_attribute_hash (register const char *str, register size_t len)
  62. {
  63. static const unsigned char asso_values[] =
  64. {
  65. 10,10,10,10,10,10,10,10,10,10,
  66. 10,10,10,10,10,10,10,10,10,10,
  67. 10,10,10,10,10,10,10,10,10,10,
  68. 10,10,10,10,10,10,10,10,10,10,
  69. 10,10,10,10,10,10,10,10,10,10,
  70. 10,10,10,10,10,10,10,10,10,10,
  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, 0,
  75. 10,10,10,10,10,10,10, 5,10, 0,
  76. 10,10,10,10,10,10, 0, 0,10, 0,
  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,10,
  81. 10,10,10,10,10,10,10,10,10,10,
  82. 10,10,10,10,10,10,10,10,10,10,
  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
  91. };
  92. return len + asso_values[(unsigned char)str[0]];
  93. }
  94. static const option_xat_attribute_map_t option_xat_attribute_table[] =
  95. {
  96. {"",XAT_COUNT_CMD}, {"",XAT_COUNT_CMD},
  97. {"",XAT_COUNT_CMD}, {"",XAT_COUNT_CMD},
  98. {"type", XAT_CMD_TYPE},
  99. {"words", XAT_CMD_WORDS},
  100. {"cooked", XAT_CMD_COOKED},
  101. {"members", XAT_CMD_MEMBERS},
  102. {"uncooked", XAT_CMD_UNCOOKED},
  103. {"keep", XAT_CMD_KEEP}
  104. };
  105. static inline const option_xat_attribute_map_t *
  106. find_option_xat_attribute_name (register const char *str, register size_t len)
  107. {
  108. if (len <= 8 && len >= 4)
  109. {
  110. register unsigned int key = (int)option_xat_attribute_hash (str, len);
  111. if (key <= 9)
  112. {
  113. register const char *s = option_xat_attribute_table[key].xat_name;
  114. if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0')
  115. return &option_xat_attribute_table[key];
  116. }
  117. }
  118. return 0;
  119. }
  120. /**
  121. * Convert a command (keyword) to a option_xat_attribute_enum_t enumeration value.
  122. *
  123. * @param[in] str a string that should start with a known key word.
  124. * @param[in] len the provided length of the keyword at \a str.
  125. * @returns the enumeration value.
  126. * If not found, that value is XAT_INVALID_CMD.
  127. */
  128. option_xat_attribute_enum_t
  129. find_option_xat_attribute_cmd(char const * str, size_t len)
  130. {
  131. option_xat_attribute_map_t const * map;
  132. map = find_option_xat_attribute_name(str, (unsigned int)len);
  133. return (map == NULL) ? XAT_INVALID_CMD : map->xat_id;
  134. }
  135. /* end of option-xat-attribute.c */