value-type.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 vtp_name
  12. // %define hash-function-name value_type_hash
  13. // %define lookup-function-name find_value_type_name
  14. // %define word-array-name value_type_table
  15. // %define initializer-suffix ,VTP_COUNT_KWD
  16. #endif /* gperf build options: */
  17. #include "value-type.h"
  18. typedef struct {
  19. char const * vtp_name;
  20. value_type_enum_t vtp_id;
  21. } value_type_map_t;
  22. #include <string.h>
  23. /* maximum key range = 20, duplicates = 0 */
  24. #ifdef __GNUC__
  25. #else
  26. #ifdef __cplusplus
  27. #endif
  28. #endif
  29. inline static unsigned int
  30. value_type_hash (register const char *str, register unsigned int len)
  31. {
  32. static const unsigned char asso_values[] =
  33. {
  34. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  35. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  36. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  37. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  38. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  39. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  40. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  41. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  42. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  43. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  44. 23, 10, 23, 23, 23, 23, 23, 23, 23, 23,
  45. 23, 5, 23, 23, 5, 0, 0, 23, 15, 23,
  46. 23, 10, 23, 23, 23, 23, 23, 23, 23, 23,
  47. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  48. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  49. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  50. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  51. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  52. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  53. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  54. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  55. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  56. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  57. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  58. 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
  59. 23, 23, 23, 23, 23, 23
  60. };
  61. return len + asso_values[(unsigned char)str[2]];
  62. }
  63. static const value_type_map_t value_type_table[] =
  64. {
  65. {"",VTP_COUNT_KWD}, {"",VTP_COUNT_KWD},
  66. {"",VTP_COUNT_KWD},
  67. {"set", VTP_KWD_SET},
  68. {"",VTP_COUNT_KWD}, {"",VTP_COUNT_KWD},
  69. {"nested", VTP_KWD_NESTED},
  70. {"integer", VTP_KWD_INTEGER},
  71. {"",VTP_COUNT_KWD},
  72. {"bool", VTP_KWD_BOOL},
  73. {"",VTP_COUNT_KWD},
  74. {"string", VTP_KWD_STRING},
  75. {"boolean", VTP_KWD_BOOLEAN},
  76. {"",VTP_COUNT_KWD},
  77. {"set-membership", VTP_KWD_SET_MEMBERSHIP},
  78. {"",VTP_COUNT_KWD}, {"",VTP_COUNT_KWD},
  79. {"keyword", VTP_KWD_KEYWORD},
  80. {"",VTP_COUNT_KWD},
  81. {"hierarchy", VTP_KWD_HIERARCHY},
  82. {"",VTP_COUNT_KWD}, {"",VTP_COUNT_KWD},
  83. {"invalid", VTP_KWD_INVALID}
  84. };
  85. #ifdef __GNUC__
  86. #ifdef __GNUC_STDC_INLINE__
  87. __attribute__ ((__gnu_inline__))
  88. #endif
  89. #endif
  90. static inline const value_type_map_t *
  91. find_value_type_name (register const char *str, register unsigned int len)
  92. {
  93. if (len <= 14 && len >= 3)
  94. {
  95. register int key = value_type_hash (str, len);
  96. if (key <= 22 && key >= 0)
  97. {
  98. register const char *s = value_type_table[key].vtp_name;
  99. if (*str == *s && !strncmp (str + 1, s + 1, len - 1) && s[len] == '\0')
  100. return &value_type_table[key];
  101. }
  102. }
  103. return 0;
  104. }
  105. value_type_enum_t
  106. find_value_type_id(char const * str, unsigned int len)
  107. {
  108. const value_type_map_t * p =
  109. find_value_type_name(str, len);
  110. return (p == 0) ? VTP_KWD_INVALID : p->vtp_id;
  111. }