Navit SVN

/work/compile/navit/src/intl/plural-exp.h

00001 /* Expression parsing and evaluation for plural form selection.
00002    Copyright (C) 2000-2003 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
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 
00032 /* This is the representation of the expressions to determine the
00033    plural form.  */
00034 struct expression
00035 {
00036   int nargs;                    /* Number of arguments.  */
00037   enum operator
00038   {
00039     /* Without arguments:  */
00040     var,                        /* The variable "n".  */
00041     num,                        /* Decimal number.  */
00042     /* Unary operators:  */
00043     lnot,                       /* Logical NOT.  */
00044     /* Binary operators:  */
00045     mult,                       /* Multiplication.  */
00046     divide,                     /* Division.  */
00047     module,                     /* Modulo operation.  */
00048     plus,                       /* Addition.  */
00049     minus,                      /* Subtraction.  */
00050     less_than,                  /* Comparison.  */
00051     greater_than,               /* Comparison.  */
00052     less_or_equal,              /* Comparison.  */
00053     greater_or_equal,           /* Comparison.  */
00054     equal,                      /* Comparison for equality.  */
00055     not_equal,                  /* Comparison for inequality.  */
00056     land,                       /* Logical AND.  */
00057     lor,                        /* Logical OR.  */
00058     /* Ternary operators:  */
00059     qmop                        /* Question mark operator.  */
00060   } operation;
00061   union
00062   {
00063     unsigned long int num;      /* Number value for `num'.  */
00064     struct expression *args[3]; /* Up to three arguments.  */
00065   } val;
00066 };
00067 
00068 /* This is the data structure to pass information to the parser and get
00069    the result in a thread-safe way.  */
00070 struct parse_args
00071 {
00072   const char *cp;
00073   struct expression *res;
00074 };
00075 
00076 
00077 /* Names for the libintl functions are a problem.  This source code is used
00078    1. in the GNU C Library library,
00079    2. in the GNU libintl library,
00080    3. in the GNU gettext tools.
00081    The function names in each situation must be different, to allow for
00082    binary incompatible changes in 'struct expression'.  Furthermore,
00083    1. in the GNU C Library library, the names have a __ prefix,
00084    2.+3. in the GNU libintl library and in the GNU gettext tools, the names
00085          must follow ANSI C and not start with __.
00086    So we have to distinguish the three cases.  */
00087 #ifdef _LIBC
00088 # define FREE_EXPRESSION __gettext_free_exp
00089 # define PLURAL_PARSE __gettextparse
00090 # define GERMANIC_PLURAL __gettext_germanic_plural
00091 # define EXTRACT_PLURAL_EXPRESSION __gettext_extract_plural
00092 #elif defined (IN_LIBINTL)
00093 # define FREE_EXPRESSION libintl_gettext_free_exp
00094 # define PLURAL_PARSE libintl_gettextparse
00095 # define GERMANIC_PLURAL libintl_gettext_germanic_plural
00096 # define EXTRACT_PLURAL_EXPRESSION libintl_gettext_extract_plural
00097 #else
00098 # define FREE_EXPRESSION free_plural_expression
00099 # define PLURAL_PARSE parse_plural_expression
00100 # define GERMANIC_PLURAL germanic_plural
00101 # define EXTRACT_PLURAL_EXPRESSION extract_plural_expression
00102 #endif
00103 
00104 extern void FREE_EXPRESSION (struct expression *exp)
00105      internal_function;
00106 extern int PLURAL_PARSE (void *arg);
00107 extern struct expression GERMANIC_PLURAL attribute_hidden;
00108 extern void EXTRACT_PLURAL_EXPRESSION (const char *nullentry,
00109                                        struct expression **pluralp,
00110                                        unsigned long int *npluralsp)
00111      internal_function;
00112 
00113 #if !defined (_LIBC) && !defined (IN_LIBINTL)
00114 extern unsigned long int plural_eval (struct expression *pexp,
00115                                       unsigned long int n);
00116 #endif
00117 
00118 #endif /* _PLURAL_EXP_H */