VirtualBox

source: kBuild/trunk/src/sed/intl/eval-plural.h@ 1294

Last change on this file since 1294 was 599, checked in by bird, 18 years ago

GNU sed 4.1.5.

File size: 2.7 KB
Line 
1/* Plural expression evaluation.
2 Copyright (C) 2000, 2001 Free Software Foundation, Inc.
3
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.
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
12 GNU General Public License for more details.
13
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. */
17
18#ifndef STATIC
19#define STATIC static
20#endif
21
22/* Evaluate the plural expression and return an index value. */
23STATIC unsigned long int plural_eval PARAMS ((struct expression *pexp,
24 unsigned long int n))
25 internal_function;
26
27STATIC
28unsigned long int
29internal_function
30plural_eval (pexp, n)
31 struct expression *pexp;
32 unsigned long int n;
33{
34 switch (pexp->nargs)
35 {
36 case 0:
37 switch (pexp->operation)
38 {
39 case var:
40 return n;
41 case num:
42 return pexp->val.num;
43 default:
44 break;
45 }
46 /* NOTREACHED */
47 break;
48 case 1:
49 {
50 /* pexp->operation must be lnot. */
51 unsigned long int arg = plural_eval (pexp->val.args[0], n);
52 return ! arg;
53 }
54 case 2:
55 {
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
62 {
63 unsigned long int rightarg = plural_eval (pexp->val.args[1], n);
64
65 switch (pexp->operation)
66 {
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;
91 }
92 }
93 /* NOTREACHED */
94 break;
95 }
96 case 3:
97 {
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);
101 }
102 }
103 /* NOTREACHED */
104 return 0;
105}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette