Built win.arm64 against r3658
[kbuild-mirror.git] / src / oldsed / intl / eval-plural.h
blobfdf5501073329bc1fcfe9202090948ea981cd69f
1 /* Plural expression evaluation.
2 Copyright (C) 2000, 2001 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 #ifndef STATIC
19 #define STATIC static
20 #endif
22 /* Evaluate the plural expression and return an index value. */
23 STATIC unsigned long int plural_eval PARAMS ((struct expression *pexp,
24 unsigned long int n))
25 internal_function;
27 STATIC
28 unsigned long int
29 internal_function
30 plural_eval (pexp, n)
31 struct expression *pexp;
32 unsigned long int n;
34 switch (pexp->nargs)
36 case 0:
37 switch (pexp->operation)
39 case var:
40 return n;
41 case num:
42 return pexp->val.num;
43 default:
44 break;
46 /* NOTREACHED */
47 break;
48 case 1:
50 /* pexp->operation must be lnot. */
51 unsigned long int arg = plural_eval (pexp->val.args[0], n);
52 return ! arg;
54 case 2:
56 unsigned long int leftarg = plural_eval (pexp->val.args[0], n);
57 if (pexp->operation == lor)
58 return leftarg || plural_eval (pexp->val.args[1], n);
59 else if (pexp->operation == land)
60 return leftarg && plural_eval (pexp->val.args[1], n);
61 else
63 unsigned long int rightarg = plural_eval (pexp->val.args[1], n);
65 switch (pexp->operation)
67 case mult:
68 return leftarg * rightarg;
69 case divide:
70 return leftarg / rightarg;
71 case module:
72 return leftarg % rightarg;
73 case plus:
74 return leftarg + rightarg;
75 case minus:
76 return leftarg - rightarg;
77 case less_than:
78 return leftarg < rightarg;
79 case greater_than:
80 return leftarg > rightarg;
81 case less_or_equal:
82 return leftarg <= rightarg;
83 case greater_or_equal:
84 return leftarg >= rightarg;
85 case equal:
86 return leftarg == rightarg;
87 case not_equal:
88 return leftarg != rightarg;
89 default:
90 break;
93 /* NOTREACHED */
94 break;
96 case 3:
98 /* pexp->operation must be qmop. */
99 unsigned long int boolarg = plural_eval (pexp->val.args[0], n);
100 return plural_eval (pexp->val.args[boolarg ? 1 : 2], n);
103 /* NOTREACHED */
104 return 0;