plural-exp.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* Expression parsing and evaluation for plural form selection.
  2. Copyright (C) 2000-2020 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 it
  5. under the terms of the GNU Library General Public License as published
  6. by the Free Software Foundation; either version 2, or (at your option)
  7. 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 GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
  15. USA. */
  16. #ifndef _PLURAL_EXP_H
  17. #define _PLURAL_EXP_H
  18. #include <plural-config.h>
  19. #ifndef PARAMS
  20. # if __STDC__ || defined __GNUC__ || defined __SUNPRO_C || defined __cplusplus || __PROTOTYPES
  21. # define PARAMS(args) args
  22. # else
  23. # define PARAMS(args) ()
  24. # endif
  25. #endif
  26. #ifndef internal_function
  27. # define internal_function
  28. #endif
  29. #ifndef attribute_hidden
  30. # define attribute_hidden
  31. #endif
  32. /* This is the representation of the expressions to determine the
  33. plural form. */
  34. struct expression
  35. {
  36. int nargs; /* Number of arguments. */
  37. enum operator
  38. {
  39. /* Without arguments: */
  40. var, /* The variable "n". */
  41. num, /* Decimal number. */
  42. /* Unary operators: */
  43. lnot, /* Logical NOT. */
  44. /* Binary operators: */
  45. mult, /* Multiplication. */
  46. divide, /* Division. */
  47. module, /* Modulo operation. */
  48. plus, /* Addition. */
  49. minus, /* Subtraction. */
  50. less_than, /* Comparison. */
  51. greater_than, /* Comparison. */
  52. less_or_equal, /* Comparison. */
  53. greater_or_equal, /* Comparison. */
  54. equal, /* Comparison for equality. */
  55. not_equal, /* Comparison for inequality. */
  56. land, /* Logical AND. */
  57. lor, /* Logical OR. */
  58. /* Ternary operators: */
  59. qmop /* Question mark operator. */
  60. } operation;
  61. union
  62. {
  63. unsigned long int num; /* Number value for `num'. */
  64. struct expression *args[3]; /* Up to three arguments. */
  65. } val;
  66. };
  67. /* This is the data structure to pass information to the parser and get
  68. the result in a thread-safe way. */
  69. struct parse_args
  70. {
  71. const char *cp;
  72. struct expression *res;
  73. };
  74. /* Names for the libintl functions are a problem. This source code is used
  75. 1. in the GNU C Library library,
  76. 2. in the GNU libintl library,
  77. 3. in the GNU gettext tools.
  78. The function names in each situation must be different, to allow for
  79. binary incompatible changes in 'struct expression'. Furthermore,
  80. 1. in the GNU C Library library, the names have a __ prefix,
  81. 2.+3. in the GNU libintl library and in the GNU gettext tools, the names
  82. must follow ANSI C and not start with __.
  83. So we have to distinguish the three cases. */
  84. #ifdef _LIBC
  85. # define FREE_EXPRESSION __gettext_free_exp
  86. # define PLURAL_PARSE __gettextparse
  87. # define GERMANIC_PLURAL __gettext_germanic_plural
  88. # define EXTRACT_PLURAL_EXPRESSION __gettext_extract_plural
  89. #elif defined (IN_LIBINTL)
  90. # define FREE_EXPRESSION libintl_gettext_free_exp
  91. # define PLURAL_PARSE libintl_gettextparse
  92. # define GERMANIC_PLURAL libintl_gettext_germanic_plural
  93. # define EXTRACT_PLURAL_EXPRESSION libintl_gettext_extract_plural
  94. #else
  95. # define FREE_EXPRESSION free_plural_expression
  96. # define PLURAL_PARSE parse_plural_expression
  97. # define GERMANIC_PLURAL germanic_plural
  98. # define EXTRACT_PLURAL_EXPRESSION extract_plural_expression
  99. #endif
  100. extern void FREE_EXPRESSION PARAMS ((struct expression *exp))
  101. internal_function;
  102. #ifdef USE_BISON3
  103. extern int PLURAL_PARSE PARAMS ((struct parse_args *arg));
  104. #else
  105. extern int PLURAL_PARSE PARAMS ((void *arg));
  106. #endif
  107. extern struct expression GERMANIC_PLURAL attribute_hidden;
  108. extern void EXTRACT_PLURAL_EXPRESSION PARAMS ((const char *nullentry,
  109. struct expression **pluralp,
  110. unsigned long int *npluralsp))
  111. internal_function;
  112. #if !defined (_LIBC) && !defined (IN_LIBINTL)
  113. extern unsigned long int plural_eval PARAMS ((struct expression *pexp,
  114. unsigned long int n));
  115. #endif
  116. #endif /* _PLURAL_EXP_H */