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