annotate intl/eval-plural.h @ 1471:4c5ceb777d60 trunk

[svn] - override InputPlugin::set_info.
author nenolod
date Wed, 02 Aug 2006 22:25:35 -0700
parents 705d4c089fce
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /* Plural expression evaluation.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 Copyright (C) 2000-2002 Free Software Foundation, Inc.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify it
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 under the terms of the GNU Library General Public License as published
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 by the Free Software Foundation; either version 2, or (at your option)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 Library General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 You should have received a copy of the GNU Library General Public
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 License along with this program; if not, write to the Free Software
1459
705d4c089fce [svn] Fix postal code.
chainsaw
parents: 1458
diff changeset
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 USA. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 #ifndef STATIC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20 #define STATIC static
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23 /* Evaluate the plural expression and return an index value. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 STATIC unsigned long int plural_eval PARAMS ((struct expression *pexp,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25 unsigned long int n))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 internal_function;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 STATIC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 unsigned long int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 internal_function
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 plural_eval (pexp, n)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32 struct expression *pexp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 unsigned long int n;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 switch (pexp->nargs)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 case 0:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 switch (pexp->operation)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 case var:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 return n;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 case num:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 return pexp->val.num;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 /* NOTREACHED */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 case 1:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 /* pexp->operation must be lnot. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52 unsigned long int arg = plural_eval (pexp->val.args[0], n);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 return ! arg;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 case 2:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 unsigned long int leftarg = plural_eval (pexp->val.args[0], n);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 if (pexp->operation == lor)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 return leftarg || plural_eval (pexp->val.args[1], n);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 else if (pexp->operation == land)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 return leftarg && plural_eval (pexp->val.args[1], n);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 unsigned long int rightarg = plural_eval (pexp->val.args[1], n);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 switch (pexp->operation)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 case mult:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 return leftarg * rightarg;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 case divide:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 #if !INTDIV0_RAISES_SIGFPE
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 if (rightarg == 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 raise (SIGFPE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 return leftarg / rightarg;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 case module:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 #if !INTDIV0_RAISES_SIGFPE
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 if (rightarg == 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 raise (SIGFPE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 return leftarg % rightarg;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 case plus:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 return leftarg + rightarg;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 case minus:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85 return leftarg - rightarg;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 case less_than:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 return leftarg < rightarg;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 case greater_than:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 return leftarg > rightarg;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 case less_or_equal:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 return leftarg <= rightarg;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 case greater_or_equal:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 return leftarg >= rightarg;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 case equal:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 return leftarg == rightarg;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96 case not_equal:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 return leftarg != rightarg;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 default:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 /* NOTREACHED */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 case 3:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 /* pexp->operation must be qmop. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108 unsigned long int boolarg = plural_eval (pexp->val.args[0], n);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 return plural_eval (pexp->val.args[boolarg ? 1 : 2], n);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 /* NOTREACHED */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 return 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 }