plural-exp.h 4.1 KB

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