Back to index

glibc  2.9
plural-exp.h
Go to the documentation of this file.
00001 /* Expression parsing and evaluation for plural form selection.
00002    Copyright (C) 2000, 2001, 2002, 2005, 2007 Free Software Foundation, Inc.
00003    Written by Ulrich Drepper <drepper@cygnus.com>, 2000.
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #ifndef _PLURAL_EXP_H
00022 #define _PLURAL_EXP_H
00023 
00024 #ifndef PARAMS
00025 # if __STDC__ || defined __GNUC__ || defined __SUNPRO_C || defined __cplusplus || __PROTOTYPES
00026 #  define PARAMS(args) args
00027 # else
00028 #  define PARAMS(args) ()
00029 # endif
00030 #endif
00031 
00032 #ifndef internal_function
00033 # define internal_function
00034 #endif
00035 
00036 #ifndef attribute_hidden
00037 # define attribute_hidden
00038 #endif
00039 
00040 
00041 /* This is the representation of the expressions to determine the
00042    plural form.  */
00043 struct expression
00044 {
00045   int nargs;                /* Number of arguments.  */
00046   enum operator
00047   {
00048     /* Without arguments:  */
00049     var,                    /* The variable "n".  */
00050     num,                    /* Decimal number.  */
00051     /* Unary operators:  */
00052     lnot,                   /* Logical NOT.  */
00053     /* Binary operators:  */
00054     mult,                   /* Multiplication.  */
00055     divide,                 /* Division.  */
00056     module,                 /* Modulo operation.  */
00057     plus,                   /* Addition.  */
00058     minus,                  /* Subtraction.  */
00059     less_than,                     /* Comparison.  */
00060     greater_than,           /* Comparison.  */
00061     less_or_equal,          /* Comparison.  */
00062     greater_or_equal,              /* Comparison.  */
00063     equal,                  /* Comparison for equality.  */
00064     not_equal,                     /* Comparison for inequality.  */
00065     land,                   /* Logical AND.  */
00066     lor,                    /* Logical OR.  */
00067     /* Ternary operators:  */
00068     qmop                    /* Question mark operator.  */
00069   } operation;
00070   union
00071   {
00072     unsigned long int num;  /* Number value for `num'.  */
00073     struct expression *args[3];    /* Up to three arguments.  */
00074   } val;
00075 };
00076 
00077 /* This is the data structure to pass information to the parser and get
00078    the result in a thread-safe way.  */
00079 struct parse_args
00080 {
00081   const char *cp;
00082   struct expression *res;
00083 };
00084 
00085 
00086 /* Names for the libintl functions are a problem.  This source code is used
00087    1. in the GNU C Library library,
00088    2. in the GNU libintl library,
00089    3. in the GNU gettext tools.
00090    The function names in each situation must be different, to allow for
00091    binary incompatible changes in 'struct expression'.  Furthermore,
00092    1. in the GNU C Library library, the names have a __ prefix,
00093    2.+3. in the GNU libintl library and in the GNU gettext tools, the names
00094          must follow ANSI C and not start with __.
00095    So we have to distinguish the three cases.  */
00096 #ifdef _LIBC
00097 # define FREE_EXPRESSION __gettext_free_exp
00098 # define PLURAL_PARSE __gettextparse
00099 # define GERMANIC_PLURAL __gettext_germanic_plural
00100 # define EXTRACT_PLURAL_EXPRESSION __gettext_extract_plural
00101 #elif defined (IN_LIBINTL)
00102 # define FREE_EXPRESSION libintl_gettext_free_exp
00103 # define PLURAL_PARSE libintl_gettextparse
00104 # define GERMANIC_PLURAL libintl_gettext_germanic_plural
00105 # define EXTRACT_PLURAL_EXPRESSION libintl_gettext_extract_plural
00106 #else
00107 # define FREE_EXPRESSION free_plural_expression
00108 # define PLURAL_PARSE parse_plural_expression
00109 # define GERMANIC_PLURAL germanic_plural
00110 # define EXTRACT_PLURAL_EXPRESSION extract_plural_expression
00111 #endif
00112 
00113 extern void FREE_EXPRESSION PARAMS ((struct expression *exp))
00114      internal_function;
00115 extern int PLURAL_PARSE PARAMS ((void *arg));
00116 extern const struct expression GERMANIC_PLURAL attribute_hidden;
00117 extern void EXTRACT_PLURAL_EXPRESSION PARAMS
00118   ((const char *nullentry, const struct expression **pluralp,
00119     unsigned long int *npluralsp)) internal_function;
00120 
00121 #if !defined (_LIBC) && !defined (IN_LIBINTL)
00122 extern unsigned long int plural_eval PARAMS ((const struct expression *pexp,
00123                                          unsigned long int n));
00124 #endif
00125 
00126 #endif /* _PLURAL_EXP_H */