~ubuntu-branches/ubuntu/hardy/klibc/hardy-updates

« back to all changes in this revision

Viewing changes to dash/arith_yylex.c

  • Committer: Bazaar Package Importer
  • Author(s): Jeff Bailey
  • Date: 2006-01-04 20:24:52 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060104202452-ec4v3n829rymukuv
Tags: 1.1.15-0ubuntu1
* New upstream version.

* Patch to fix compilation on parisc64 kernels.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-
 
2
 * Copyright (c) 2002
 
3
 *      Herbert Xu.
 
4
 * Copyright (c) 1993
 
5
 *      The Regents of the University of California.  All rights reserved.
 
6
 *
 
7
 * This code is derived from software contributed to Berkeley by
 
8
 * Kenneth Almquist.
 
9
 *
 
10
 * Redistribution and use in source and binary forms, with or without
 
11
 * modification, are permitted provided that the following conditions
 
12
 * are met:
 
13
 * 1. Redistributions of source code must retain the above copyright
 
14
 *    notice, this list of conditions and the following disclaimer.
 
15
 * 2. Redistributions in binary form must reproduce the above copyright
 
16
 *    notice, this list of conditions and the following disclaimer in the
 
17
 *    documentation and/or other materials provided with the distribution.
 
18
 * 3. Neither the name of the University nor the names of its contributors
 
19
 *    may be used to endorse or promote products derived from this software
 
20
 *    without specific prior written permission.
 
21
 *
 
22
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 
23
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
24
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
25
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 
26
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
27
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 
28
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
29
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
30
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 
31
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 
32
 * SUCH DAMAGE.
 
33
 */
 
34
 
 
35
#include <stdlib.h>
 
36
#include "arith.h"
 
37
#include "expand.h"
 
38
#include "error.h"
 
39
 
 
40
extern int yylval;
 
41
extern const char *arith_buf, *arith_startbuf;
 
42
 
 
43
int
 
44
yylex()
 
45
{
 
46
        int value;
 
47
        const char *buf = arith_buf;
 
48
 
 
49
        for (;;) {
 
50
                switch (*buf) {
 
51
                case ' ':
 
52
                case '\t':
 
53
                case '\n':
 
54
                        buf++;
 
55
                        continue;
 
56
                default:
 
57
err:
 
58
                        sh_error("arith: syntax error: \"%s\"", arith_startbuf);
 
59
                        /* NOTREACHED */
 
60
                case '0':
 
61
                case '1':
 
62
                case '2':
 
63
                case '3':
 
64
                case '4':
 
65
                case '5':
 
66
                case '6':
 
67
                case '7':
 
68
                case '8':
 
69
                case '9':
 
70
                        yylval = strtoll(buf, (char **) &arith_buf, 0);
 
71
                        return ARITH_NUM;
 
72
                case '=':
 
73
                        if (*++buf != '=') {
 
74
                                goto err;
 
75
                        }
 
76
                        value = ARITH_EQ;
 
77
                        break;
 
78
                case '>':
 
79
                        switch (*++buf) {
 
80
                        case '=':
 
81
                                value = ARITH_GE;
 
82
                                break;
 
83
                        case '>':
 
84
                                value = ARITH_RSHIFT;
 
85
                                break;
 
86
                        default:
 
87
                                value = ARITH_GT;
 
88
                                goto out;
 
89
                        }
 
90
                        break;
 
91
                case '<':
 
92
                        switch (*++buf) {
 
93
                        case '=':
 
94
                                value = ARITH_LE;
 
95
                                break;
 
96
                        case '<':
 
97
                                value = ARITH_LSHIFT;
 
98
                                break;
 
99
                        default:
 
100
                                value = ARITH_LT;
 
101
                                goto out;
 
102
                        }
 
103
                        break;
 
104
                case '|':
 
105
                        if (*++buf != '|') {
 
106
                                value = ARITH_BOR;
 
107
                                goto out;
 
108
                        }
 
109
                        value = ARITH_OR;
 
110
                        break;
 
111
                case '&':
 
112
                        if (*++buf != '&') {
 
113
                                value = ARITH_BAND;
 
114
                                goto out;
 
115
                        }
 
116
                        value = ARITH_AND;
 
117
                        break;
 
118
                case '!':
 
119
                        if (*++buf != '=') {
 
120
                                value = ARITH_NOT;
 
121
                                goto out;
 
122
                        }
 
123
                        value = ARITH_NE;
 
124
                        break;
 
125
                case 0:
 
126
                        value = 0;
 
127
                        goto out;
 
128
                case '(':
 
129
                        value = ARITH_LPAREN;
 
130
                        break;
 
131
                case ')':
 
132
                        value = ARITH_RPAREN;
 
133
                        break;
 
134
                case '*':
 
135
                        value = ARITH_MUL;
 
136
                        break;
 
137
                case '/':
 
138
                        value = ARITH_DIV;
 
139
                        break;
 
140
                case '%':
 
141
                        value = ARITH_REM;
 
142
                        break;
 
143
                case '+':
 
144
                        value = ARITH_ADD;
 
145
                        break;
 
146
                case '-':
 
147
                        value = ARITH_SUB;
 
148
                        break;
 
149
                case '~':
 
150
                        value = ARITH_BNOT;
 
151
                        break;
 
152
                case '^':
 
153
                        value = ARITH_BXOR;
 
154
                        break;
 
155
                }
 
156
                break;
 
157
        }
 
158
 
 
159
        buf++;
 
160
out:
 
161
        arith_buf = buf;
 
162
        return value;
 
163
}