]>
Commit | Line | Data |
---|---|---|
a04eba3f | 1 | /* Expression parsing and evaluation for plural form selection. |
b0cacab0 | 2 | Copyright (C) 2000-2003 Free Software Foundation, Inc. |
a04eba3f TT |
3 | Written by Ulrich Drepper <drepper@cygnus.com>, 2000. |
4 | ||
5 | This program is free software; you can redistribute it and/or modify it | |
6 | under the terms of the GNU Library General Public License as published | |
7 | by the Free Software Foundation; either version 2, or (at your option) | |
8 | any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Library General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Library General Public | |
16 | License along with this program; if not, write to the Free Software | |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
18 | USA. */ | |
19 | ||
20 | #ifndef _PLURAL_EXP_H | |
21 | #define _PLURAL_EXP_H | |
22 | ||
a04eba3f TT |
23 | #ifndef internal_function |
24 | # define internal_function | |
25 | #endif | |
26 | ||
27 | #ifndef attribute_hidden | |
28 | # define attribute_hidden | |
29 | #endif | |
30 | ||
31 | ||
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 | ||
68 | /* This is the data structure to pass information to the parser and get | |
69 | the result in a thread-safe way. */ | |
70 | struct parse_args | |
71 | { | |
72 | const char *cp; | |
73 | struct expression *res; | |
74 | }; | |
75 | ||
76 | ||
77 | /* Names for the libintl functions are a problem. This source code is used | |
78 | 1. in the GNU C Library library, | |
79 | 2. in the GNU libintl library, | |
80 | 3. in the GNU gettext tools. | |
81 | The function names in each situation must be different, to allow for | |
82 | binary incompatible changes in 'struct expression'. Furthermore, | |
83 | 1. in the GNU C Library library, the names have a __ prefix, | |
84 | 2.+3. in the GNU libintl library and in the GNU gettext tools, the names | |
85 | must follow ANSI C and not start with __. | |
86 | So we have to distinguish the three cases. */ | |
87 | #ifdef _LIBC | |
88 | # define FREE_EXPRESSION __gettext_free_exp | |
89 | # define PLURAL_PARSE __gettextparse | |
90 | # define GERMANIC_PLURAL __gettext_germanic_plural | |
91 | # define EXTRACT_PLURAL_EXPRESSION __gettext_extract_plural | |
92 | #elif defined (IN_LIBINTL) | |
93 | # define FREE_EXPRESSION libintl_gettext_free_exp | |
94 | # define PLURAL_PARSE libintl_gettextparse | |
95 | # define GERMANIC_PLURAL libintl_gettext_germanic_plural | |
96 | # define EXTRACT_PLURAL_EXPRESSION libintl_gettext_extract_plural | |
97 | #else | |
98 | # define FREE_EXPRESSION free_plural_expression | |
99 | # define PLURAL_PARSE parse_plural_expression | |
100 | # define GERMANIC_PLURAL germanic_plural | |
101 | # define EXTRACT_PLURAL_EXPRESSION extract_plural_expression | |
102 | #endif | |
103 | ||
b0cacab0 | 104 | extern void FREE_EXPRESSION (struct expression *exp) |
a04eba3f | 105 | internal_function; |
b0cacab0 | 106 | extern int PLURAL_PARSE (void *arg); |
a04eba3f | 107 | extern struct expression GERMANIC_PLURAL attribute_hidden; |
b0cacab0 TT |
108 | extern void EXTRACT_PLURAL_EXPRESSION (const char *nullentry, |
109 | struct expression **pluralp, | |
110 | unsigned long int *npluralsp) | |
a04eba3f TT |
111 | internal_function; |
112 | ||
113 | #if !defined (_LIBC) && !defined (IN_LIBINTL) | |
b0cacab0 TT |
114 | extern unsigned long int plural_eval (struct expression *pexp, |
115 | unsigned long int n); | |
a04eba3f TT |
116 | #endif |
117 | ||
118 | #endif /* _PLURAL_EXP_H */ |