Add RPM Packaging
[framework/uifw/ise-engine-hangul.git] / intl / eval-plural.h
1 /* Plural expression evaluation.
2    Copyright (C) 2000-2003 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or modify it
5    under the terms of the GNU Library General Public License as published
6    by the Free Software Foundation; either version 2, or (at your option)
7    any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Library General Public License for more details.
13
14    You should have received a copy of the GNU Library General Public
15    License along with this program; if not, write to the Free Software
16    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17    USA.  */
18
19 #include <signal.h>
20
21 #ifndef STATIC
22 #define STATIC static
23 #endif
24
25 /* Evaluate the plural expression and return an index value.  */
26 STATIC
27 unsigned long int
28 internal_function
29 plural_eval (struct expression *pexp, unsigned long int n)
30 {
31   switch (pexp->nargs)
32     {
33     case 0:
34       switch (pexp->operation)
35         {
36         case var:
37           return n;
38         case num:
39           return pexp->val.num;
40         default:
41           break;
42         }
43       /* NOTREACHED */
44       break;
45     case 1:
46       {
47         /* pexp->operation must be lnot.  */
48         unsigned long int arg = plural_eval (pexp->val.args[0], n);
49         return ! arg;
50       }
51     case 2:
52       {
53         unsigned long int leftarg = plural_eval (pexp->val.args[0], n);
54         if (pexp->operation == lor)
55           return leftarg || plural_eval (pexp->val.args[1], n);
56         else if (pexp->operation == land)
57           return leftarg && plural_eval (pexp->val.args[1], n);
58         else
59           {
60             unsigned long int rightarg = plural_eval (pexp->val.args[1], n);
61
62             switch (pexp->operation)
63               {
64               case mult:
65                 return leftarg * rightarg;
66               case divide:
67                 if (rightarg == 0)
68                   raise (SIGFPE);
69                 return leftarg / rightarg;
70               case module:
71                 if (rightarg == 0)
72                   raise (SIGFPE);
73                 return leftarg % rightarg;
74               case plus:
75                 return leftarg + rightarg;
76               case minus:
77                 return leftarg - rightarg;
78               case less_than:
79                 return leftarg < rightarg;
80               case greater_than:
81                 return leftarg > rightarg;
82               case less_or_equal:
83                 return leftarg <= rightarg;
84               case greater_or_equal:
85                 return leftarg >= rightarg;
86               case equal:
87                 return leftarg == rightarg;
88               case not_equal:
89                 return leftarg != rightarg;
90               default:
91                 break;
92               }
93           }
94         /* NOTREACHED */
95         break;
96       }
97     case 3:
98       {
99         /* pexp->operation must be qmop.  */
100         unsigned long int boolarg = plural_eval (pexp->val.args[0], n);
101         return plural_eval (pexp->val.args[boolarg ? 1 : 2], n);
102       }
103     }
104   /* NOTREACHED */
105   return 0;
106 }