Update.
[glibc.git] / intl / plural-exp.h
blob25b7c8b8aa85289691a96381e3653f69eb2ef0b0
1 /* Expression parsing and evaluation for plural form selection.
2 Copyright (C) 2000, 2001, 2002 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__
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
37 /* This is the representation of the expressions to determine the
38 plural form. */
39 struct expression
41 int nargs; /* Number of arguments. */
42 enum operator
44 /* Without arguments: */
45 var, /* The variable "n". */
46 num, /* Decimal number. */
47 /* Unary operators: */
48 lnot, /* Logical NOT. */
49 /* Binary operators: */
50 mult, /* Multiplication. */
51 divide, /* Division. */
52 module, /* Modulo operation. */
53 plus, /* Addition. */
54 minus, /* Subtraction. */
55 less_than, /* Comparison. */
56 greater_than, /* Comparison. */
57 less_or_equal, /* Comparison. */
58 greater_or_equal, /* Comparison. */
59 equal, /* Comparison for equality. */
60 not_equal, /* Comparison for inequality. */
61 land, /* Logical AND. */
62 lor, /* Logical OR. */
63 /* Ternary operators: */
64 qmop /* Question mark operator. */
65 } operation;
66 union
68 unsigned long int num; /* Number value for `num'. */
69 struct expression *args[3]; /* Up to three arguments. */
70 } val;
73 /* This is the data structure to pass information to the parser and get
74 the result in a thread-safe way. */
75 struct parse_args
77 const char *cp;
78 struct expression *res;
82 /* Names for the libintl functions are a problem. This source code is used
83 1. in the GNU C Library library,
84 2. in the GNU libintl library,
85 3. in the GNU gettext tools.
86 The function names in each situation must be different, to allow for
87 binary incompatible changes in 'struct expression'. Furthermore,
88 1. in the GNU C Library library, the names have a __ prefix,
89 2.+3. in the GNU libintl library and in the GNU gettext tools, the names
90 must follow ANSI C and not start with __.
91 So we have to distinguish the three cases. */
92 #ifdef _LIBC
93 # define FREE_EXPRESSION __gettext_free_exp
94 # define PLURAL_PARSE __gettextparse
95 # define GERMANIC_PLURAL __gettext_germanic_plural
96 # define EXTRACT_PLURAL_EXPRESSION __gettext_extract_plural
97 #elif defined (IN_LIBINTL)
98 # define FREE_EXPRESSION gettext_free_exp__
99 # define PLURAL_PARSE gettextparse__
100 # define GERMANIC_PLURAL gettext_germanic_plural__
101 # define EXTRACT_PLURAL_EXPRESSION gettext_extract_plural__
102 #else
103 # define FREE_EXPRESSION free_plural_expression
104 # define PLURAL_PARSE parse_plural_expression
105 # define GERMANIC_PLURAL germanic_plural
106 # define EXTRACT_PLURAL_EXPRESSION extract_plural_expression
107 #endif
109 #ifndef attribute_hidden
110 # define attribute_hidden
111 #endif
113 extern void FREE_EXPRESSION PARAMS ((struct expression *exp))
114 internal_function;
115 extern int PLURAL_PARSE PARAMS ((void *arg));
116 extern struct expression GERMANIC_PLURAL attribute_hidden;
117 extern void EXTRACT_PLURAL_EXPRESSION PARAMS ((const char *nullentry,
118 struct expression **pluralp,
119 unsigned long int *npluralsp))
120 internal_function;
122 #endif /* _PLURAL_EXP_H */