plural-exp.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* Expression parsing and evaluation for plural form selection.
  2. Copyright (C) 2000-2019 Free Software Foundation, Inc.
  3. Written by Ulrich Drepper <drepper@cygnus.com>, 2000.
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #ifndef _PLURAL_EXP_H
  15. #define _PLURAL_EXP_H
  16. #ifndef attribute_hidden
  17. # define attribute_hidden
  18. #endif
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. enum expression_operator
  23. {
  24. /* Without arguments: */
  25. var, /* The variable "n". */
  26. num, /* Decimal number. */
  27. /* Unary operators: */
  28. lnot, /* Logical NOT. */
  29. /* Binary operators: */
  30. mult, /* Multiplication. */
  31. divide, /* Division. */
  32. module, /* Modulo operation. */
  33. plus, /* Addition. */
  34. minus, /* Subtraction. */
  35. less_than, /* Comparison. */
  36. greater_than, /* Comparison. */
  37. less_or_equal, /* Comparison. */
  38. greater_or_equal, /* Comparison. */
  39. equal, /* Comparison for equality. */
  40. not_equal, /* Comparison for inequality. */
  41. land, /* Logical AND. */
  42. lor, /* Logical OR. */
  43. /* Ternary operators: */
  44. qmop /* Question mark operator. */
  45. };
  46. /* This is the representation of the expressions to determine the
  47. plural form. */
  48. struct expression
  49. {
  50. int nargs; /* Number of arguments. */
  51. enum expression_operator operation;
  52. union
  53. {
  54. unsigned long int num; /* Number value for `num'. */
  55. struct expression *args[3]; /* Up to three arguments. */
  56. } val;
  57. };
  58. /* This is the data structure to pass information to the parser and get
  59. the result in a thread-safe way. */
  60. struct parse_args
  61. {
  62. const char *cp;
  63. struct expression *res;
  64. };
  65. /* Names for the libintl functions are a problem. This source code is used
  66. 1. in the GNU C Library library,
  67. 2. in the GNU libintl library,
  68. 3. in the GNU gettext tools.
  69. The function names in each situation must be different, to allow for
  70. binary incompatible changes in 'struct expression'. Furthermore,
  71. 1. in the GNU C Library library, the names have a __ prefix,
  72. 2.+3. in the GNU libintl library and in the GNU gettext tools, the names
  73. must follow ANSI C and not start with __.
  74. So we have to distinguish the three cases. */
  75. #ifdef _LIBC
  76. # define FREE_EXPRESSION __gettext_free_exp
  77. # define PLURAL_PARSE __gettextparse
  78. # define GERMANIC_PLURAL __gettext_germanic_plural
  79. # define EXTRACT_PLURAL_EXPRESSION __gettext_extract_plural
  80. #elif defined (IN_LIBINTL)
  81. # define FREE_EXPRESSION libintl_gettext_free_exp
  82. # define PLURAL_PARSE libintl_gettextparse
  83. # define GERMANIC_PLURAL libintl_gettext_germanic_plural
  84. # define EXTRACT_PLURAL_EXPRESSION libintl_gettext_extract_plural
  85. #else
  86. # define FREE_EXPRESSION free_plural_expression
  87. # define PLURAL_PARSE parse_plural_expression
  88. # define GERMANIC_PLURAL germanic_plural
  89. # define EXTRACT_PLURAL_EXPRESSION extract_plural_expression
  90. #endif
  91. extern void FREE_EXPRESSION (struct expression *exp) attribute_hidden;
  92. extern int PLURAL_PARSE (struct parse_args *arg);
  93. extern const struct expression GERMANIC_PLURAL attribute_hidden;
  94. extern void EXTRACT_PLURAL_EXPRESSION (const char *nullentry,
  95. const struct expression **pluralp,
  96. unsigned long int *npluralsp)
  97. attribute_hidden;
  98. #if !defined (_LIBC) && !defined (IN_LIBINTL) && !defined (IN_LIBGLOCALE)
  99. extern unsigned long int plural_eval (const struct expression *pexp,
  100. unsigned long int n);
  101. #endif
  102. #ifdef __cplusplus
  103. }
  104. #endif
  105. #endif /* _PLURAL_EXP_H */