xat-attribute.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* ANSI-C code produced by gperf version 3.0.3 */
  2. #if 0 /* gperf build options: */
  3. // %struct-type
  4. // %language=ANSI-C
  5. // %includes
  6. // %global-table
  7. // %omit-struct-type
  8. // %readonly-tables
  9. // %compare-strncmp
  10. //
  11. // %define slot-name xat_name
  12. // %define hash-function-name xat_attribute_hash
  13. // %define lookup-function-name find_xat_attribute_name
  14. // %define word-array-name xat_attribute_table
  15. // %define initializer-suffix ,XAT_COUNT_KWD
  16. #endif /* gperf build options: */
  17. #include "xat-attribute.h"
  18. typedef struct {
  19. char const * xat_name;
  20. xat_attribute_enum_t xat_id;
  21. } xat_attribute_map_t;
  22. #include <string.h>
  23. /* maximum key range = 9, duplicates = 0 */
  24. #ifdef __GNUC__
  25. #else
  26. #ifdef __cplusplus
  27. #endif
  28. #endif
  29. inline static unsigned int
  30. xat_attribute_hash (register const char *str, register unsigned int len)
  31. {
  32. static const unsigned char asso_values[] =
  33. {
  34. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  35. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  36. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  37. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  38. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  39. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  40. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  41. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  42. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  43. 13, 13, 13, 13, 13, 13, 13, 13, 13, 0,
  44. 13, 13, 13, 13, 13, 5, 13, 5, 13, 0,
  45. 13, 13, 13, 13, 13, 13, 0, 0, 13, 0,
  46. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  47. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  48. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  49. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  50. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  51. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  52. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  53. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  54. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  55. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  56. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  57. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  58. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  59. 13, 13, 13, 13, 13, 13
  60. };
  61. return len + asso_values[(unsigned char)str[0]];
  62. }
  63. static const xat_attribute_map_t xat_attribute_table[] =
  64. {
  65. {"",XAT_COUNT_KWD}, {"",XAT_COUNT_KWD},
  66. {"",XAT_COUNT_KWD}, {"",XAT_COUNT_KWD},
  67. {"type", XAT_KWD_TYPE},
  68. {"words", XAT_KWD_WORDS},
  69. {"cooked", XAT_KWD_COOKED},
  70. {"members", XAT_KWD_MEMBERS},
  71. {"uncooked", XAT_KWD_UNCOOKED},
  72. {"keep", XAT_KWD_KEEP},
  73. {"",XAT_COUNT_KWD}, {"",XAT_COUNT_KWD},
  74. {"invalid", XAT_KWD_INVALID}
  75. };
  76. #ifdef __GNUC__
  77. #ifdef __GNUC_STDC_INLINE__
  78. __attribute__ ((__gnu_inline__))
  79. #endif
  80. #endif
  81. static inline const xat_attribute_map_t *
  82. find_xat_attribute_name (register const char *str, register unsigned int len)
  83. {
  84. if (len <= 8 && len >= 4)
  85. {
  86. register int key = xat_attribute_hash (str, len);
  87. if (key <= 12 && key >= 0)
  88. {
  89. register const char *s = xat_attribute_table[key].xat_name;
  90. if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0')
  91. return &xat_attribute_table[key];
  92. }
  93. }
  94. return 0;
  95. }
  96. xat_attribute_enum_t
  97. find_xat_attribute_id(char const * str, unsigned int len)
  98. {
  99. const xat_attribute_map_t * p =
  100. find_xat_attribute_name(str, len);
  101. return (p == 0) ? XAT_KWD_INVALID : p->xat_id;
  102. }