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