Back to index

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