~ubuntu-branches/ubuntu/gutsy/evms/gutsy

« back to all changes in this revision

Viewing changes to intl/eval-plural.h

  • Committer: Bazaar Package Importer
  • Author(s): Steinar H. Gunderson
  • Date: 2006-09-14 19:32:30 UTC
  • mfrom: (2.1.13 edgy)
  • Revision ID: james.westby@ubuntu.com-20060914193230-4b1pmy0coqk81sqa
Tags: 2.5.5-18
* Apply patches from upstream:
  * cli_query_segfault.patch, fixes a segfault in the CLI when doing a
    query.
  * cli_reload_options.patch, reloads the right option descriptors after
    a change.
  * ntfs_unmkfs.patch, fixes a bug in the wiping of NTFS file systems.
  * raid5_remove_spare_fix.patch + raid5_remove_spare_fix_2.patch, lets the
    user remove a spare if resync does not run.
  * raid5_algorithm.patch, makes EVMS heed the parity algorithm the user
    selects when creating a RAID-5 array.

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
#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 unsigned long int plural_eval PARAMS ((struct expression *pexp,
 
27
                                              unsigned long int n))
 
28
     internal_function;
 
29
 
 
30
STATIC
 
31
unsigned long int
 
32
internal_function
 
33
plural_eval (pexp, n)
 
34
     struct expression *pexp;
 
35
     unsigned long int n;
 
36
{
 
37
  switch (pexp->nargs)
 
38
    {
 
39
    case 0:
 
40
      switch (pexp->operation)
 
41
        {
 
42
        case var:
 
43
          return n;
 
44
        case num:
 
45
          return pexp->val.num;
 
46
        default:
 
47
          break;
 
48
        }
 
49
      /* NOTREACHED */
 
50
      break;
 
51
    case 1:
 
52
      {
 
53
        /* pexp->operation must be lnot.  */
 
54
        unsigned long int arg = plural_eval (pexp->val.args[0], n);
 
55
        return ! arg;
 
56
      }
 
57
    case 2:
 
58
      {
 
59
        unsigned long int leftarg = plural_eval (pexp->val.args[0], n);
 
60
        if (pexp->operation == lor)
 
61
          return leftarg || plural_eval (pexp->val.args[1], n);
 
62
        else if (pexp->operation == land)
 
63
          return leftarg && plural_eval (pexp->val.args[1], n);
 
64
        else
 
65
          {
 
66
            unsigned long int rightarg = plural_eval (pexp->val.args[1], n);
 
67
 
 
68
            switch (pexp->operation)
 
69
              {
 
70
              case mult:
 
71
                return leftarg * rightarg;
 
72
              case divide:
 
73
                if (rightarg == 0)
 
74
                  raise (SIGFPE);
 
75
                return leftarg / rightarg;
 
76
              case module:
 
77
                if (rightarg == 0)
 
78
                  raise (SIGFPE);
 
79
                return leftarg % rightarg;
 
80
              case plus:
 
81
                return leftarg + rightarg;
 
82
              case minus:
 
83
                return leftarg - rightarg;
 
84
              case less_than:
 
85
                return leftarg < rightarg;
 
86
              case greater_than:
 
87
                return leftarg > rightarg;
 
88
              case less_or_equal:
 
89
                return leftarg <= rightarg;
 
90
              case greater_or_equal:
 
91
                return leftarg >= rightarg;
 
92
              case equal:
 
93
                return leftarg == rightarg;
 
94
              case not_equal:
 
95
                return leftarg != rightarg;
 
96
              default:
 
97
                break;
 
98
              }
 
99
          }
 
100
        /* NOTREACHED */
 
101
        break;
 
102
      }
 
103
    case 3:
 
104
      {
 
105
        /* pexp->operation must be qmop.  */
 
106
        unsigned long int boolarg = plural_eval (pexp->val.args[0], n);
 
107
        return plural_eval (pexp->val.args[boolarg ? 1 : 2], n);
 
108
      }
 
109
    }
 
110
  /* NOTREACHED */
 
111
  return 0;
 
112
}