~ubuntu-branches/ubuntu/breezy/groundhog/breezy

« back to all changes in this revision

Viewing changes to intl/eval-plural.h

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2003-06-18 19:46:15 UTC
  • mto: (2.1.1 warty)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20030618194615-sztk57bkfjhmctl4
Tags: upstream-1.4
ImportĀ upstreamĀ versionĀ 1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Plural expression evaluation.
 
2
   Copyright (C) 2000-2002 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
#ifndef STATIC
 
20
#define STATIC static
 
21
#endif
 
22
 
 
23
/* Evaluate the plural expression and return an index value.  */
 
24
STATIC unsigned long int plural_eval PARAMS ((struct expression *pexp,
 
25
                                              unsigned long int n))
 
26
     internal_function;
 
27
 
 
28
STATIC
 
29
unsigned long int
 
30
internal_function
 
31
plural_eval (pexp, n)
 
32
     struct expression *pexp;
 
33
     unsigned long int n;
 
34
{
 
35
  switch (pexp->nargs)
 
36
    {
 
37
    case 0:
 
38
      switch (pexp->operation)
 
39
        {
 
40
        case var:
 
41
          return n;
 
42
        case num:
 
43
          return pexp->val.num;
 
44
        default:
 
45
          break;
 
46
        }
 
47
      /* NOTREACHED */
 
48
      break;
 
49
    case 1:
 
50
      {
 
51
        /* pexp->operation must be lnot.  */
 
52
        unsigned long int arg = plural_eval (pexp->val.args[0], n);
 
53
        return ! arg;
 
54
      }
 
55
    case 2:
 
56
      {
 
57
        unsigned long int leftarg = plural_eval (pexp->val.args[0], n);
 
58
        if (pexp->operation == lor)
 
59
          return leftarg || plural_eval (pexp->val.args[1], n);
 
60
        else if (pexp->operation == land)
 
61
          return leftarg && plural_eval (pexp->val.args[1], n);
 
62
        else
 
63
          {
 
64
            unsigned long int rightarg = plural_eval (pexp->val.args[1], n);
 
65
 
 
66
            switch (pexp->operation)
 
67
              {
 
68
              case mult:
 
69
                return leftarg * rightarg;
 
70
              case divide:
 
71
                return leftarg / rightarg;
 
72
              case module:
 
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
}