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