Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

eval-plural.h

00001 /* Plural expression evaluation.
00002    Copyright (C) 2000-2002 Free Software Foundation, Inc.
00003 
00004    This program is free software; you can redistribute it and/or modify it
00005    under the terms of the GNU Library General Public License as published
00006    by the Free Software Foundation; either version 2, or (at your option)
00007    any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public
00015    License along with this program; if not, write to the Free Software
00016    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00017    USA.  */
00018 
00019 #ifndef STATIC
00020 #define STATIC static
00021 #endif
00022 
00023 /* Evaluate the plural expression and return an index value.  */
00024 STATIC unsigned long int plural_eval PARAMS ((struct expression *pexp,
00025                                               unsigned long int n))
00026      internal_function;
00027 
00028 STATIC
00029 unsigned long int
00030 internal_function
00031 plural_eval (pexp, n)
00032      struct expression *pexp;
00033      unsigned long int n;
00034 {
00035   switch (pexp->nargs)
00036     {
00037     case 0:
00038       switch (pexp->operation)
00039         {
00040         case var:
00041           return n;
00042         case num:
00043           return pexp->val.num;
00044         default:
00045           break;
00046         }
00047       /* NOTREACHED */
00048       break;
00049     case 1:
00050       {
00051         /* pexp->operation must be lnot.  */
00052         unsigned long int arg = plural_eval (pexp->val.args[0], n);
00053         return ! arg;
00054       }
00055     case 2:
00056       {
00057         unsigned long int leftarg = plural_eval (pexp->val.args[0], n);
00058         if (pexp->operation == lor)
00059           return leftarg || plural_eval (pexp->val.args[1], n);
00060         else if (pexp->operation == land)
00061           return leftarg && plural_eval (pexp->val.args[1], n);
00062         else
00063           {
00064             unsigned long int rightarg = plural_eval (pexp->val.args[1], n);
00065 
00066             switch (pexp->operation)
00067               {
00068               case mult:
00069                 return leftarg * rightarg;
00070               case divide:
00071 #if !INTDIV0_RAISES_SIGFPE
00072                 if (rightarg == 0)
00073                   raise (SIGFPE);
00074 #endif
00075                 return leftarg / rightarg;
00076               case module:
00077 #if !INTDIV0_RAISES_SIGFPE
00078                 if (rightarg == 0)
00079                   raise (SIGFPE);
00080 #endif
00081                 return leftarg % rightarg;
00082               case plus:
00083                 return leftarg + rightarg;
00084               case minus:
00085                 return leftarg - rightarg;
00086               case less_than:
00087                 return leftarg < rightarg;
00088               case greater_than:
00089                 return leftarg > rightarg;
00090               case less_or_equal:
00091                 return leftarg <= rightarg;
00092               case greater_or_equal:
00093                 return leftarg >= rightarg;
00094               case equal:
00095                 return leftarg == rightarg;
00096               case not_equal:
00097                 return leftarg != rightarg;
00098               default:
00099                 break;
00100               }
00101           }
00102         /* NOTREACHED */
00103         break;
00104       }
00105     case 3:
00106       {
00107         /* pexp->operation must be qmop.  */
00108         unsigned long int boolarg = plural_eval (pexp->val.args[0], n);
00109         return plural_eval (pexp->val.args[boolarg ? 1 : 2], n);
00110       }
00111     }
00112   /* NOTREACHED */
00113   return 0;
00114 }

Generated on Tue Dec 20 10:14:20 2005 for vlc-0.8.4a by  doxygen 1.4.2