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