|
Packit |
6c4009 |
/* Expression parsing and evaluation for plural form selection.
|
|
Packit |
6c4009 |
Copyright (C) 2000-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
Written by Ulrich Drepper <drepper@cygnus.com>, 2000.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
This program is free software: you can redistribute it and/or modify
|
|
Packit |
6c4009 |
it under the terms of the GNU Lesser General Public License as published by
|
|
Packit |
6c4009 |
the Free Software Foundation; either version 2.1 of the License, or
|
|
Packit |
6c4009 |
(at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
This program is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
6c4009 |
GNU Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public License
|
|
Packit |
6c4009 |
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifndef _PLURAL_EXP_H
|
|
Packit |
6c4009 |
#define _PLURAL_EXP_H
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifndef attribute_hidden
|
|
Packit |
6c4009 |
# define attribute_hidden
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef __cplusplus
|
|
Packit |
6c4009 |
extern "C" {
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
enum expression_operator
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* Without arguments: */
|
|
Packit |
6c4009 |
var, /* The variable "n". */
|
|
Packit |
6c4009 |
num, /* Decimal number. */
|
|
Packit |
6c4009 |
/* Unary operators: */
|
|
Packit |
6c4009 |
lnot, /* Logical NOT. */
|
|
Packit |
6c4009 |
/* Binary operators: */
|
|
Packit |
6c4009 |
mult, /* Multiplication. */
|
|
Packit |
6c4009 |
divide, /* Division. */
|
|
Packit |
6c4009 |
module, /* Modulo operation. */
|
|
Packit |
6c4009 |
plus, /* Addition. */
|
|
Packit |
6c4009 |
minus, /* Subtraction. */
|
|
Packit |
6c4009 |
less_than, /* Comparison. */
|
|
Packit |
6c4009 |
greater_than, /* Comparison. */
|
|
Packit |
6c4009 |
less_or_equal, /* Comparison. */
|
|
Packit |
6c4009 |
greater_or_equal, /* Comparison. */
|
|
Packit |
6c4009 |
equal, /* Comparison for equality. */
|
|
Packit |
6c4009 |
not_equal, /* Comparison for inequality. */
|
|
Packit |
6c4009 |
land, /* Logical AND. */
|
|
Packit |
6c4009 |
lor, /* Logical OR. */
|
|
Packit |
6c4009 |
/* Ternary operators: */
|
|
Packit |
6c4009 |
qmop /* Question mark operator. */
|
|
Packit |
6c4009 |
};
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* This is the representation of the expressions to determine the
|
|
Packit |
6c4009 |
plural form. */
|
|
Packit |
6c4009 |
struct expression
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
int nargs; /* Number of arguments. */
|
|
Packit |
6c4009 |
enum expression_operator operation;
|
|
Packit |
6c4009 |
union
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
unsigned long int num; /* Number value for `num'. */
|
|
Packit |
6c4009 |
struct expression *args[3]; /* Up to three arguments. */
|
|
Packit |
6c4009 |
} val;
|
|
Packit |
6c4009 |
};
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* This is the data structure to pass information to the parser and get
|
|
Packit |
6c4009 |
the result in a thread-safe way. */
|
|
Packit |
6c4009 |
struct parse_args
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
const char *cp;
|
|
Packit |
6c4009 |
struct expression *res;
|
|
Packit |
6c4009 |
};
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Names for the libintl functions are a problem. This source code is used
|
|
Packit |
6c4009 |
1. in the GNU C Library library,
|
|
Packit |
6c4009 |
2. in the GNU libintl library,
|
|
Packit |
6c4009 |
3. in the GNU gettext tools.
|
|
Packit |
6c4009 |
The function names in each situation must be different, to allow for
|
|
Packit |
6c4009 |
binary incompatible changes in 'struct expression'. Furthermore,
|
|
Packit |
6c4009 |
1. in the GNU C Library library, the names have a __ prefix,
|
|
Packit |
6c4009 |
2.+3. in the GNU libintl library and in the GNU gettext tools, the names
|
|
Packit |
6c4009 |
must follow ANSI C and not start with __.
|
|
Packit |
6c4009 |
So we have to distinguish the three cases. */
|
|
Packit |
6c4009 |
#ifdef _LIBC
|
|
Packit |
6c4009 |
# define FREE_EXPRESSION __gettext_free_exp
|
|
Packit |
6c4009 |
# define PLURAL_PARSE __gettextparse
|
|
Packit |
6c4009 |
# define GERMANIC_PLURAL __gettext_germanic_plural
|
|
Packit |
6c4009 |
# define EXTRACT_PLURAL_EXPRESSION __gettext_extract_plural
|
|
Packit |
6c4009 |
#elif defined (IN_LIBINTL)
|
|
Packit |
6c4009 |
# define FREE_EXPRESSION libintl_gettext_free_exp
|
|
Packit |
6c4009 |
# define PLURAL_PARSE libintl_gettextparse
|
|
Packit |
6c4009 |
# define GERMANIC_PLURAL libintl_gettext_germanic_plural
|
|
Packit |
6c4009 |
# define EXTRACT_PLURAL_EXPRESSION libintl_gettext_extract_plural
|
|
Packit |
6c4009 |
#else
|
|
Packit |
6c4009 |
# define FREE_EXPRESSION free_plural_expression
|
|
Packit |
6c4009 |
# define PLURAL_PARSE parse_plural_expression
|
|
Packit |
6c4009 |
# define GERMANIC_PLURAL germanic_plural
|
|
Packit |
6c4009 |
# define EXTRACT_PLURAL_EXPRESSION extract_plural_expression
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
extern void FREE_EXPRESSION (struct expression *exp) attribute_hidden;
|
|
Packit |
6c4009 |
extern int PLURAL_PARSE (struct parse_args *arg);
|
|
Packit |
6c4009 |
extern const struct expression GERMANIC_PLURAL attribute_hidden;
|
|
Packit |
6c4009 |
extern void EXTRACT_PLURAL_EXPRESSION (const char *nullentry,
|
|
Packit |
6c4009 |
const struct expression **pluralp,
|
|
Packit |
6c4009 |
unsigned long int *npluralsp)
|
|
Packit |
6c4009 |
attribute_hidden;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#if !defined (_LIBC) && !defined (IN_LIBINTL) && !defined (IN_LIBGLOCALE)
|
|
Packit |
6c4009 |
extern unsigned long int plural_eval (const struct expression *pexp,
|
|
Packit |
6c4009 |
unsigned long int n);
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef __cplusplus
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#endif /* _PLURAL_EXP_H */
|