(root)/
gettext-0.22.4/
gettext-runtime/
intl/
plural-exp.h
       1  /* Expression parsing and evaluation for plural form selection.
       2     Copyright (C) 2000-2016, 2019, 2021 Free Software Foundation, Inc.
       3     Written by Ulrich Drepper <drepper@cygnus.com>, 2000.
       4  
       5     This program is free software: you can redistribute it and/or modify
       6     it under the terms of the GNU Lesser General Public License as published by
       7     the Free Software Foundation; either version 2.1 of the License, or
       8     (at your option) any later version.
       9  
      10     This program is distributed in the hope that it will be useful,
      11     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13     GNU Lesser General Public License for more details.
      14  
      15     You should have received a copy of the GNU Lesser General Public License
      16     along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
      17  
      18  #ifndef _PLURAL_EXP_H
      19  #define _PLURAL_EXP_H
      20  
      21  #ifndef internal_function
      22  # define internal_function
      23  #endif
      24  
      25  #ifndef attribute_hidden
      26  # define attribute_hidden
      27  #endif
      28  
      29  #ifdef __cplusplus
      30  extern "C" {
      31  #endif
      32  
      33  
      34  enum expression_operator
      35  {
      36    /* Without arguments:  */
      37    var,				/* The variable "n".  */
      38    num,				/* Decimal number.  */
      39    /* Unary operators:  */
      40    lnot,				/* Logical NOT.  */
      41    /* Binary operators:  */
      42    mult,				/* Multiplication.  */
      43    divide,			/* Division.  */
      44    module,			/* Modulo operation.  */
      45    plus,				/* Addition.  */
      46    minus,			/* Subtraction.  */
      47    less_than,			/* Comparison.  */
      48    greater_than,			/* Comparison.  */
      49    less_or_equal,		/* Comparison.  */
      50    greater_or_equal,		/* Comparison.  */
      51    equal,			/* Comparison for equality.  */
      52    not_equal,			/* Comparison for inequality.  */
      53    land,				/* Logical AND.  */
      54    lor,				/* Logical OR.  */
      55    /* Ternary operators:  */
      56    qmop				/* Question mark operator.  */
      57  };
      58  
      59  /* This is the representation of the expressions to determine the
      60     plural form.  */
      61  struct expression
      62  {
      63    int nargs;			/* Number of arguments.  */
      64    enum expression_operator operation;
      65    union
      66    {
      67      unsigned long int num;	/* Number value for `num'.  */
      68      struct expression *args[3];	/* Up to three arguments.  */
      69    } val;
      70  };
      71  
      72  /* This is the data structure to pass information to the parser and get
      73     the result in a thread-safe way.  */
      74  struct parse_args
      75  {
      76    const char *cp;
      77    struct expression *res;
      78  };
      79  
      80  
      81  /* Names for the libintl functions are a problem.  This source code is used
      82     1. in the GNU C Library library,
      83     2. in the GNU libintl library,
      84     3. in the GNU gettext tools.
      85     The function names in each situation must be different, to allow for
      86     binary incompatible changes in 'struct expression'.  Furthermore,
      87     1. in the GNU C Library library, the names have a __ prefix,
      88     2.+3. in the GNU libintl library and in the GNU gettext tools, the names
      89           must follow ANSI C and not start with __.
      90     So we have to distinguish the three cases.  */
      91  #ifdef _LIBC
      92  # define FREE_EXPRESSION __gettext_free_exp
      93  # define PLURAL_PARSE __gettextparse
      94  # define GERMANIC_PLURAL __gettext_germanic_plural
      95  # define EXTRACT_PLURAL_EXPRESSION __gettext_extract_plural
      96  #elif defined (IN_LIBINTL)
      97  # define FREE_EXPRESSION _libintl_gettext_free_exp
      98  # define PLURAL_PARSE _libintl_gettextparse
      99  # define GERMANIC_PLURAL _libintl_gettext_germanic_plural
     100  # define EXTRACT_PLURAL_EXPRESSION _libintl_gettext_extract_plural
     101  #else
     102  # define FREE_EXPRESSION free_plural_expression
     103  # define PLURAL_PARSE parse_plural_expression
     104  # define GERMANIC_PLURAL germanic_plural
     105  # define EXTRACT_PLURAL_EXPRESSION extract_plural_expression
     106  #endif
     107  
     108  #if (defined __GNUC__ && !(defined __APPLE_CC_ && __APPLE_CC__ > 1) \
     109       && !defined __cplusplus)                                       \
     110      || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L     \
     111          && !defined __HP_cc)                                        \
     112      || (defined __SUNPRO_C && 0x560 <= __SUNPRO_C                   \
     113          && !(defined __STDC__ && __STDC__ == 1))
     114  # define HAVE_STRUCT_INITIALIZER 1
     115  #else
     116  # define HAVE_STRUCT_INITIALIZER 0
     117  #endif
     118  
     119  extern void FREE_EXPRESSION (struct expression *exp)
     120       internal_function;
     121  extern int PLURAL_PARSE (struct parse_args *arg);
     122  #if HAVE_STRUCT_INITIALIZER
     123  extern const struct expression GERMANIC_PLURAL attribute_hidden;
     124  #else
     125  extern struct expression GERMANIC_PLURAL attribute_hidden;
     126  #endif
     127  extern void EXTRACT_PLURAL_EXPRESSION (const char *nullentry,
     128  				       const struct expression **pluralp,
     129  				       unsigned long int *npluralsp)
     130       internal_function;
     131  
     132  #if !defined (_LIBC) && !defined (IN_LIBINTL) && !defined (IN_LIBGLOCALE)
     133  extern unsigned long int plural_eval (const struct expression *pexp,
     134  				      unsigned long int n);
     135  #endif
     136  
     137  
     138  #ifdef __cplusplus
     139  }
     140  #endif
     141  
     142  #endif /* _PLURAL_EXP_H */