Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/bash/src/expr.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* expr.c -- arithmetic expression evaluation. */ | - | ||||||||||||||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||||||||||||||
3 | /* Copyright (C) 1990-2015 Free Software Foundation, Inc. | - | ||||||||||||||||||||||||||||||||||||
4 | - | |||||||||||||||||||||||||||||||||||||
5 | This file is part of GNU Bash, the Bourne Again SHell. | - | ||||||||||||||||||||||||||||||||||||
6 | - | |||||||||||||||||||||||||||||||||||||
7 | Bash is free software: you can redistribute it and/or modify | - | ||||||||||||||||||||||||||||||||||||
8 | it under the terms of the GNU General Public License as published by | - | ||||||||||||||||||||||||||||||||||||
9 | the Free Software Foundation, either version 3 of the License, or | - | ||||||||||||||||||||||||||||||||||||
10 | (at your option) any later version. | - | ||||||||||||||||||||||||||||||||||||
11 | - | |||||||||||||||||||||||||||||||||||||
12 | Bash is distributed in the hope that it will be useful, | - | ||||||||||||||||||||||||||||||||||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | - | ||||||||||||||||||||||||||||||||||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | - | ||||||||||||||||||||||||||||||||||||
15 | GNU General Public License for more details. | - | ||||||||||||||||||||||||||||||||||||
16 | - | |||||||||||||||||||||||||||||||||||||
17 | You should have received a copy of the GNU General Public License | - | ||||||||||||||||||||||||||||||||||||
18 | along with Bash. If not, see <http://www.gnu.org/licenses/>. | - | ||||||||||||||||||||||||||||||||||||
19 | */ | - | ||||||||||||||||||||||||||||||||||||
20 | - | |||||||||||||||||||||||||||||||||||||
21 | /* | - | ||||||||||||||||||||||||||||||||||||
22 | All arithmetic is done as intmax_t integers with no checking for overflow | - | ||||||||||||||||||||||||||||||||||||
23 | (though division by 0 is caught and flagged as an error). | - | ||||||||||||||||||||||||||||||||||||
24 | - | |||||||||||||||||||||||||||||||||||||
25 | The following operators are handled, grouped into a set of levels in | - | ||||||||||||||||||||||||||||||||||||
26 | order of decreasing precedence. | - | ||||||||||||||||||||||||||||||||||||
27 | - | |||||||||||||||||||||||||||||||||||||
28 | "id++", "id--" [post-increment and post-decrement] | - | ||||||||||||||||||||||||||||||||||||
29 | "++id", "--id" [pre-increment and pre-decrement] | - | ||||||||||||||||||||||||||||||||||||
30 | "-", "+" [(unary operators)] | - | ||||||||||||||||||||||||||||||||||||
31 | "!", "~" | - | ||||||||||||||||||||||||||||||||||||
32 | "**" [(exponentiation)] | - | ||||||||||||||||||||||||||||||||||||
33 | "*", "/", "%" | - | ||||||||||||||||||||||||||||||||||||
34 | "+", "-" | - | ||||||||||||||||||||||||||||||||||||
35 | "<<", ">>" | - | ||||||||||||||||||||||||||||||||||||
36 | "<=", ">=", "<", ">" | - | ||||||||||||||||||||||||||||||||||||
37 | "==", "!=" | - | ||||||||||||||||||||||||||||||||||||
38 | "&" | - | ||||||||||||||||||||||||||||||||||||
39 | "^" | - | ||||||||||||||||||||||||||||||||||||
40 | "|" | - | ||||||||||||||||||||||||||||||||||||
41 | "&&" | - | ||||||||||||||||||||||||||||||||||||
42 | "||" | - | ||||||||||||||||||||||||||||||||||||
43 | "expr ? expr : expr" | - | ||||||||||||||||||||||||||||||||||||
44 | "=", "*=", "/=", "%=", "+=", "-=", "<<=", ">>=", "&=", "^=", "|=" | - | ||||||||||||||||||||||||||||||||||||
45 | , [comma] | - | ||||||||||||||||||||||||||||||||||||
46 | - | |||||||||||||||||||||||||||||||||||||
47 | (Note that most of these operators have special meaning to bash, and an | - | ||||||||||||||||||||||||||||||||||||
48 | entire expression should be quoted, e.g. "a=$a+1" or "a=a+1" to ensure | - | ||||||||||||||||||||||||||||||||||||
49 | that it is passed intact to the evaluator when using `let'. When using | - | ||||||||||||||||||||||||||||||||||||
50 | the $[] or $(( )) forms, the text between the `[' and `]' or `((' and `))' | - | ||||||||||||||||||||||||||||||||||||
51 | is treated as if in double quotes.) | - | ||||||||||||||||||||||||||||||||||||
52 | - | |||||||||||||||||||||||||||||||||||||
53 | Sub-expressions within parentheses have a precedence level greater than | - | ||||||||||||||||||||||||||||||||||||
54 | all of the above levels and are evaluated first. Within a single prece- | - | ||||||||||||||||||||||||||||||||||||
55 | dence group, evaluation is left-to-right, except for the arithmetic | - | ||||||||||||||||||||||||||||||||||||
56 | assignment operator (`='), which is evaluated right-to-left (as in C). | - | ||||||||||||||||||||||||||||||||||||
57 | - | |||||||||||||||||||||||||||||||||||||
58 | The expression evaluator returns the value of the expression (assignment | - | ||||||||||||||||||||||||||||||||||||
59 | statements have as a value what is returned by the RHS). The `let' | - | ||||||||||||||||||||||||||||||||||||
60 | builtin, on the other hand, returns 0 if the last expression evaluates to | - | ||||||||||||||||||||||||||||||||||||
61 | a non-zero, and 1 otherwise. | - | ||||||||||||||||||||||||||||||||||||
62 | - | |||||||||||||||||||||||||||||||||||||
63 | Implementation is a recursive-descent parser. | - | ||||||||||||||||||||||||||||||||||||
64 | - | |||||||||||||||||||||||||||||||||||||
65 | Chet Ramey | - | ||||||||||||||||||||||||||||||||||||
66 | chet@po.cwru.edu | - | ||||||||||||||||||||||||||||||||||||
67 | */ | - | ||||||||||||||||||||||||||||||||||||
68 | - | |||||||||||||||||||||||||||||||||||||
69 | #include "config.h" | - | ||||||||||||||||||||||||||||||||||||
70 | - | |||||||||||||||||||||||||||||||||||||
71 | #include <stdio.h> | - | ||||||||||||||||||||||||||||||||||||
72 | #include "bashansi.h" | - | ||||||||||||||||||||||||||||||||||||
73 | - | |||||||||||||||||||||||||||||||||||||
74 | #if defined (HAVE_UNISTD_H) | - | ||||||||||||||||||||||||||||||||||||
75 | # ifdef _MINIX | - | ||||||||||||||||||||||||||||||||||||
76 | # include <sys/types.h> | - | ||||||||||||||||||||||||||||||||||||
77 | # endif | - | ||||||||||||||||||||||||||||||||||||
78 | # include <unistd.h> | - | ||||||||||||||||||||||||||||||||||||
79 | #endif | - | ||||||||||||||||||||||||||||||||||||
80 | - | |||||||||||||||||||||||||||||||||||||
81 | #include "chartypes.h" | - | ||||||||||||||||||||||||||||||||||||
82 | #include "bashintl.h" | - | ||||||||||||||||||||||||||||||||||||
83 | - | |||||||||||||||||||||||||||||||||||||
84 | #include "shell.h" | - | ||||||||||||||||||||||||||||||||||||
85 | #include "arrayfunc.h" | - | ||||||||||||||||||||||||||||||||||||
86 | #include "execute_cmd.h" | - | ||||||||||||||||||||||||||||||||||||
87 | #include "flags.h" | - | ||||||||||||||||||||||||||||||||||||
88 | #include "subst.h" | - | ||||||||||||||||||||||||||||||||||||
89 | #include "typemax.h" /* INTMAX_MAX, INTMAX_MIN */ | - | ||||||||||||||||||||||||||||||||||||
90 | - | |||||||||||||||||||||||||||||||||||||
91 | /* Because of the $((...)) construct, expressions may include newlines. | - | ||||||||||||||||||||||||||||||||||||
92 | Here is a macro which accepts newlines, tabs and spaces as whitespace. */ | - | ||||||||||||||||||||||||||||||||||||
93 | #define cr_whitespace(c) (whitespace(c) || ((c) == '\n')) | - | ||||||||||||||||||||||||||||||||||||
94 | - | |||||||||||||||||||||||||||||||||||||
95 | /* Size be which the expression stack grows when necessary. */ | - | ||||||||||||||||||||||||||||||||||||
96 | #define EXPR_STACK_GROW_SIZE 10 | - | ||||||||||||||||||||||||||||||||||||
97 | - | |||||||||||||||||||||||||||||||||||||
98 | /* Maximum amount of recursion allowed. This prevents a non-integer | - | ||||||||||||||||||||||||||||||||||||
99 | variable such as "num=num+2" from infinitely adding to itself when | - | ||||||||||||||||||||||||||||||||||||
100 | "let num=num+2" is given. */ | - | ||||||||||||||||||||||||||||||||||||
101 | #define MAX_EXPR_RECURSION_LEVEL 1024 | - | ||||||||||||||||||||||||||||||||||||
102 | - | |||||||||||||||||||||||||||||||||||||
103 | /* The Tokens. Singing "The Lion Sleeps Tonight". */ | - | ||||||||||||||||||||||||||||||||||||
104 | - | |||||||||||||||||||||||||||||||||||||
105 | #define EQEQ 1 /* "==" */ | - | ||||||||||||||||||||||||||||||||||||
106 | #define NEQ 2 /* "!=" */ | - | ||||||||||||||||||||||||||||||||||||
107 | #define LEQ 3 /* "<=" */ | - | ||||||||||||||||||||||||||||||||||||
108 | #define GEQ 4 /* ">=" */ | - | ||||||||||||||||||||||||||||||||||||
109 | #define STR 5 /* string */ | - | ||||||||||||||||||||||||||||||||||||
110 | #define NUM 6 /* number */ | - | ||||||||||||||||||||||||||||||||||||
111 | #define LAND 7 /* "&&" Logical AND */ | - | ||||||||||||||||||||||||||||||||||||
112 | #define LOR 8 /* "||" Logical OR */ | - | ||||||||||||||||||||||||||||||||||||
113 | #define LSH 9 /* "<<" Left SHift */ | - | ||||||||||||||||||||||||||||||||||||
114 | #define RSH 10 /* ">>" Right SHift */ | - | ||||||||||||||||||||||||||||||||||||
115 | #define OP_ASSIGN 11 /* op= expassign as in Posix.2 */ | - | ||||||||||||||||||||||||||||||||||||
116 | #define COND 12 /* exp1 ? exp2 : exp3 */ | - | ||||||||||||||||||||||||||||||||||||
117 | #define POWER 13 /* exp1**exp2 */ | - | ||||||||||||||||||||||||||||||||||||
118 | #define PREINC 14 /* ++var */ | - | ||||||||||||||||||||||||||||||||||||
119 | #define PREDEC 15 /* --var */ | - | ||||||||||||||||||||||||||||||||||||
120 | #define POSTINC 16 /* var++ */ | - | ||||||||||||||||||||||||||||||||||||
121 | #define POSTDEC 17 /* var-- */ | - | ||||||||||||||||||||||||||||||||||||
122 | #define EQ '=' | - | ||||||||||||||||||||||||||||||||||||
123 | #define GT '>' | - | ||||||||||||||||||||||||||||||||||||
124 | #define LT '<' | - | ||||||||||||||||||||||||||||||||||||
125 | #define PLUS '+' | - | ||||||||||||||||||||||||||||||||||||
126 | #define MINUS '-' | - | ||||||||||||||||||||||||||||||||||||
127 | #define MUL '*' | - | ||||||||||||||||||||||||||||||||||||
128 | #define DIV '/' | - | ||||||||||||||||||||||||||||||||||||
129 | #define MOD '%' | - | ||||||||||||||||||||||||||||||||||||
130 | #define NOT '!' | - | ||||||||||||||||||||||||||||||||||||
131 | #define LPAR '(' | - | ||||||||||||||||||||||||||||||||||||
132 | #define RPAR ')' | - | ||||||||||||||||||||||||||||||||||||
133 | #define BAND '&' /* Bitwise AND */ | - | ||||||||||||||||||||||||||||||||||||
134 | #define BOR '|' /* Bitwise OR. */ | - | ||||||||||||||||||||||||||||||||||||
135 | #define BXOR '^' /* Bitwise eXclusive OR. */ | - | ||||||||||||||||||||||||||||||||||||
136 | #define BNOT '~' /* Bitwise NOT; Two's complement. */ | - | ||||||||||||||||||||||||||||||||||||
137 | #define QUES '?' | - | ||||||||||||||||||||||||||||||||||||
138 | #define COL ':' | - | ||||||||||||||||||||||||||||||||||||
139 | #define COMMA ',' | - | ||||||||||||||||||||||||||||||||||||
140 | - | |||||||||||||||||||||||||||||||||||||
141 | /* This should be the function corresponding to the operator with the | - | ||||||||||||||||||||||||||||||||||||
142 | highest precedence. */ | - | ||||||||||||||||||||||||||||||||||||
143 | #define EXP_HIGHEST expcomma | - | ||||||||||||||||||||||||||||||||||||
144 | - | |||||||||||||||||||||||||||||||||||||
145 | #ifndef MAX_INT_LEN | - | ||||||||||||||||||||||||||||||||||||
146 | # define MAX_INT_LEN 32 | - | ||||||||||||||||||||||||||||||||||||
147 | #endif | - | ||||||||||||||||||||||||||||||||||||
148 | - | |||||||||||||||||||||||||||||||||||||
149 | struct lvalue | - | ||||||||||||||||||||||||||||||||||||
150 | { | - | ||||||||||||||||||||||||||||||||||||
151 | char *tokstr; /* possibly-rewritten lvalue if not NULL */ | - | ||||||||||||||||||||||||||||||||||||
152 | intmax_t tokval; /* expression evaluated value */ | - | ||||||||||||||||||||||||||||||||||||
153 | SHELL_VAR *tokvar; /* variable described by array or var reference */ | - | ||||||||||||||||||||||||||||||||||||
154 | intmax_t ind; /* array index if not -1 */ | - | ||||||||||||||||||||||||||||||||||||
155 | }; | - | ||||||||||||||||||||||||||||||||||||
156 | - | |||||||||||||||||||||||||||||||||||||
157 | /* A structure defining a single expression context. */ | - | ||||||||||||||||||||||||||||||||||||
158 | typedef struct { | - | ||||||||||||||||||||||||||||||||||||
159 | int curtok, lasttok; | - | ||||||||||||||||||||||||||||||||||||
160 | char *expression, *tp, *lasttp; | - | ||||||||||||||||||||||||||||||||||||
161 | intmax_t tokval; | - | ||||||||||||||||||||||||||||||||||||
162 | char *tokstr; | - | ||||||||||||||||||||||||||||||||||||
163 | int noeval; | - | ||||||||||||||||||||||||||||||||||||
164 | struct lvalue lval; | - | ||||||||||||||||||||||||||||||||||||
165 | } EXPR_CONTEXT; | - | ||||||||||||||||||||||||||||||||||||
166 | - | |||||||||||||||||||||||||||||||||||||
167 | static char *expression; /* The current expression */ | - | ||||||||||||||||||||||||||||||||||||
168 | static char *tp; /* token lexical position */ | - | ||||||||||||||||||||||||||||||||||||
169 | static char *lasttp; /* pointer to last token position */ | - | ||||||||||||||||||||||||||||||||||||
170 | static int curtok; /* the current token */ | - | ||||||||||||||||||||||||||||||||||||
171 | static int lasttok; /* the previous token */ | - | ||||||||||||||||||||||||||||||||||||
172 | static int assigntok; /* the OP in OP= */ | - | ||||||||||||||||||||||||||||||||||||
173 | static char *tokstr; /* current token string */ | - | ||||||||||||||||||||||||||||||||||||
174 | static intmax_t tokval; /* current token value */ | - | ||||||||||||||||||||||||||||||||||||
175 | static int noeval; /* set to 1 if no assignment to be done */ | - | ||||||||||||||||||||||||||||||||||||
176 | static procenv_t evalbuf; | - | ||||||||||||||||||||||||||||||||||||
177 | - | |||||||||||||||||||||||||||||||||||||
178 | /* set to 1 if the expression has already been run through word expansion */ | - | ||||||||||||||||||||||||||||||||||||
179 | static int already_expanded; | - | ||||||||||||||||||||||||||||||||||||
180 | - | |||||||||||||||||||||||||||||||||||||
181 | static struct lvalue curlval = {0, 0, 0, -1}; | - | ||||||||||||||||||||||||||||||||||||
182 | static struct lvalue lastlval = {0, 0, 0, -1}; | - | ||||||||||||||||||||||||||||||||||||
183 | - | |||||||||||||||||||||||||||||||||||||
184 | static int _is_arithop __P((int)); | - | ||||||||||||||||||||||||||||||||||||
185 | static void readtok __P((void)); /* lexical analyzer */ | - | ||||||||||||||||||||||||||||||||||||
186 | - | |||||||||||||||||||||||||||||||||||||
187 | static void init_lvalue __P((struct lvalue *)); | - | ||||||||||||||||||||||||||||||||||||
188 | static struct lvalue *alloc_lvalue __P((void)); | - | ||||||||||||||||||||||||||||||||||||
189 | static void free_lvalue __P((struct lvalue *)); | - | ||||||||||||||||||||||||||||||||||||
190 | - | |||||||||||||||||||||||||||||||||||||
191 | static intmax_t expr_streval __P((char *, int, struct lvalue *)); | - | ||||||||||||||||||||||||||||||||||||
192 | static intmax_t strlong __P((char *)); | - | ||||||||||||||||||||||||||||||||||||
193 | static void evalerror __P((const char *)); | - | ||||||||||||||||||||||||||||||||||||
194 | - | |||||||||||||||||||||||||||||||||||||
195 | static void pushexp __P((void)); | - | ||||||||||||||||||||||||||||||||||||
196 | static void popexp __P((void)); | - | ||||||||||||||||||||||||||||||||||||
197 | static void expr_unwind __P((void)); | - | ||||||||||||||||||||||||||||||||||||
198 | static void expr_bind_variable __P((char *, char *)); | - | ||||||||||||||||||||||||||||||||||||
199 | #if defined (ARRAY_VARS) | - | ||||||||||||||||||||||||||||||||||||
200 | static void expr_bind_array_element __P((char *, arrayind_t, char *)); | - | ||||||||||||||||||||||||||||||||||||
201 | #endif | - | ||||||||||||||||||||||||||||||||||||
202 | - | |||||||||||||||||||||||||||||||||||||
203 | static intmax_t subexpr __P((char *)); | - | ||||||||||||||||||||||||||||||||||||
204 | - | |||||||||||||||||||||||||||||||||||||
205 | static intmax_t expcomma __P((void)); | - | ||||||||||||||||||||||||||||||||||||
206 | static intmax_t expassign __P((void)); | - | ||||||||||||||||||||||||||||||||||||
207 | static intmax_t expcond __P((void)); | - | ||||||||||||||||||||||||||||||||||||
208 | static intmax_t explor __P((void)); | - | ||||||||||||||||||||||||||||||||||||
209 | static intmax_t expland __P((void)); | - | ||||||||||||||||||||||||||||||||||||
210 | static intmax_t expbor __P((void)); | - | ||||||||||||||||||||||||||||||||||||
211 | static intmax_t expbxor __P((void)); | - | ||||||||||||||||||||||||||||||||||||
212 | static intmax_t expband __P((void)); | - | ||||||||||||||||||||||||||||||||||||
213 | static intmax_t exp5 __P((void)); | - | ||||||||||||||||||||||||||||||||||||
214 | static intmax_t exp4 __P((void)); | - | ||||||||||||||||||||||||||||||||||||
215 | static intmax_t expshift __P((void)); | - | ||||||||||||||||||||||||||||||||||||
216 | static intmax_t exp3 __P((void)); | - | ||||||||||||||||||||||||||||||||||||
217 | static intmax_t exp2 __P((void)); | - | ||||||||||||||||||||||||||||||||||||
218 | static intmax_t exppower __P((void)); | - | ||||||||||||||||||||||||||||||||||||
219 | static intmax_t exp1 __P((void)); | - | ||||||||||||||||||||||||||||||||||||
220 | static intmax_t exp0 __P((void)); | - | ||||||||||||||||||||||||||||||||||||
221 | - | |||||||||||||||||||||||||||||||||||||
222 | /* Global var which contains the stack of expression contexts. */ | - | ||||||||||||||||||||||||||||||||||||
223 | static EXPR_CONTEXT **expr_stack; | - | ||||||||||||||||||||||||||||||||||||
224 | static int expr_depth; /* Location in the stack. */ | - | ||||||||||||||||||||||||||||||||||||
225 | static int expr_stack_size; /* Number of slots already allocated. */ | - | ||||||||||||||||||||||||||||||||||||
226 | - | |||||||||||||||||||||||||||||||||||||
227 | #if defined (ARRAY_VARS) | - | ||||||||||||||||||||||||||||||||||||
228 | extern const char * const bash_badsub_errmsg; | - | ||||||||||||||||||||||||||||||||||||
229 | #endif | - | ||||||||||||||||||||||||||||||||||||
230 | - | |||||||||||||||||||||||||||||||||||||
231 | #define SAVETOK(X) \ | - | ||||||||||||||||||||||||||||||||||||
232 | do { \ | - | ||||||||||||||||||||||||||||||||||||
233 | (X)->curtok = curtok; \ | - | ||||||||||||||||||||||||||||||||||||
234 | (X)->lasttok = lasttok; \ | - | ||||||||||||||||||||||||||||||||||||
235 | (X)->tp = tp; \ | - | ||||||||||||||||||||||||||||||||||||
236 | (X)->lasttp = lasttp; \ | - | ||||||||||||||||||||||||||||||||||||
237 | (X)->tokval = tokval; \ | - | ||||||||||||||||||||||||||||||||||||
238 | (X)->tokstr = tokstr; \ | - | ||||||||||||||||||||||||||||||||||||
239 | (X)->noeval = noeval; \ | - | ||||||||||||||||||||||||||||||||||||
240 | (X)->lval = curlval; \ | - | ||||||||||||||||||||||||||||||||||||
241 | } while (0) | - | ||||||||||||||||||||||||||||||||||||
242 | - | |||||||||||||||||||||||||||||||||||||
243 | #define RESTORETOK(X) \ | - | ||||||||||||||||||||||||||||||||||||
244 | do { \ | - | ||||||||||||||||||||||||||||||||||||
245 | curtok = (X)->curtok; \ | - | ||||||||||||||||||||||||||||||||||||
246 | lasttok = (X)->lasttok; \ | - | ||||||||||||||||||||||||||||||||||||
247 | tp = (X)->tp; \ | - | ||||||||||||||||||||||||||||||||||||
248 | lasttp = (X)->lasttp; \ | - | ||||||||||||||||||||||||||||||||||||
249 | tokval = (X)->tokval; \ | - | ||||||||||||||||||||||||||||||||||||
250 | tokstr = (X)->tokstr; \ | - | ||||||||||||||||||||||||||||||||||||
251 | noeval = (X)->noeval; \ | - | ||||||||||||||||||||||||||||||||||||
252 | curlval = (X)->lval; \ | - | ||||||||||||||||||||||||||||||||||||
253 | } while (0) | - | ||||||||||||||||||||||||||||||||||||
254 | - | |||||||||||||||||||||||||||||||||||||
255 | /* Push and save away the contents of the globals describing the | - | ||||||||||||||||||||||||||||||||||||
256 | current expression context. */ | - | ||||||||||||||||||||||||||||||||||||
257 | static void | - | ||||||||||||||||||||||||||||||||||||
258 | pushexp () | - | ||||||||||||||||||||||||||||||||||||
259 | { | - | ||||||||||||||||||||||||||||||||||||
260 | EXPR_CONTEXT *context; | - | ||||||||||||||||||||||||||||||||||||
261 | - | |||||||||||||||||||||||||||||||||||||
262 | if (expr_depth >= MAX_EXPR_RECURSION_LEVEL)
| 0-14508109 | ||||||||||||||||||||||||||||||||||||
263 | evalerror (_("expression recursion level exceeded")); never executed: evalerror ( dcgettext (((void *)0), "expression recursion level exceeded" , 5) ); | 0 | ||||||||||||||||||||||||||||||||||||
264 | - | |||||||||||||||||||||||||||||||||||||
265 | if (expr_depth >= expr_stack_size)
| 4344-14503765 | ||||||||||||||||||||||||||||||||||||
266 | { | - | ||||||||||||||||||||||||||||||||||||
267 | expr_stack_size += EXPR_STACK_GROW_SIZE; | - | ||||||||||||||||||||||||||||||||||||
268 | expr_stack = (EXPR_CONTEXT **)xrealloc (expr_stack, expr_stack_size * sizeof (EXPR_CONTEXT *)); | - | ||||||||||||||||||||||||||||||||||||
269 | } executed 4344 times by 1 test: end of block Executed by:
| 4344 | ||||||||||||||||||||||||||||||||||||
270 | - | |||||||||||||||||||||||||||||||||||||
271 | context = (EXPR_CONTEXT *)xmalloc (sizeof (EXPR_CONTEXT)); | - | ||||||||||||||||||||||||||||||||||||
272 | - | |||||||||||||||||||||||||||||||||||||
273 | context->expression = expression; | - | ||||||||||||||||||||||||||||||||||||
274 | SAVETOK(context); | - | ||||||||||||||||||||||||||||||||||||
275 | - | |||||||||||||||||||||||||||||||||||||
276 | expr_stack[expr_depth++] = context; | - | ||||||||||||||||||||||||||||||||||||
277 | } executed 14508109 times by 1 test: end of block Executed by:
| 14508109 | ||||||||||||||||||||||||||||||||||||
278 | - | |||||||||||||||||||||||||||||||||||||
279 | /* Pop the the contents of the expression context stack into the | - | ||||||||||||||||||||||||||||||||||||
280 | globals describing the current expression context. */ | - | ||||||||||||||||||||||||||||||||||||
281 | static void | - | ||||||||||||||||||||||||||||||||||||
282 | popexp () | - | ||||||||||||||||||||||||||||||||||||
283 | { | - | ||||||||||||||||||||||||||||||||||||
284 | EXPR_CONTEXT *context; | - | ||||||||||||||||||||||||||||||||||||
285 | - | |||||||||||||||||||||||||||||||||||||
286 | if (expr_depth <= 0)
| 0-14507889 | ||||||||||||||||||||||||||||||||||||
287 | { | - | ||||||||||||||||||||||||||||||||||||
288 | /* See the comment at the top of evalexp() for an explanation of why | - | ||||||||||||||||||||||||||||||||||||
289 | this is done. */ | - | ||||||||||||||||||||||||||||||||||||
290 | expression = lasttp = 0; | - | ||||||||||||||||||||||||||||||||||||
291 | evalerror (_("recursion stack underflow")); | - | ||||||||||||||||||||||||||||||||||||
292 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
293 | - | |||||||||||||||||||||||||||||||||||||
294 | context = expr_stack[--expr_depth]; | - | ||||||||||||||||||||||||||||||||||||
295 | - | |||||||||||||||||||||||||||||||||||||
296 | expression = context->expression; | - | ||||||||||||||||||||||||||||||||||||
297 | RESTORETOK (context); | - | ||||||||||||||||||||||||||||||||||||
298 | - | |||||||||||||||||||||||||||||||||||||
299 | free (context); | - | ||||||||||||||||||||||||||||||||||||
300 | } executed 14507889 times by 1 test: end of block Executed by:
| 14507889 | ||||||||||||||||||||||||||||||||||||
301 | - | |||||||||||||||||||||||||||||||||||||
302 | static void | - | ||||||||||||||||||||||||||||||||||||
303 | expr_unwind () | - | ||||||||||||||||||||||||||||||||||||
304 | { | - | ||||||||||||||||||||||||||||||||||||
305 | while (--expr_depth > 0)
| 7-209 | ||||||||||||||||||||||||||||||||||||
306 | { | - | ||||||||||||||||||||||||||||||||||||
307 | if (expr_stack[expr_depth]->tokstr)
| 0-7 | ||||||||||||||||||||||||||||||||||||
308 | free (expr_stack[expr_depth]->tokstr); executed 7 times by 1 test: sh_xfree((expr_stack[expr_depth]->tokstr), "expr.c", 308); Executed by:
| 7 | ||||||||||||||||||||||||||||||||||||
309 | - | |||||||||||||||||||||||||||||||||||||
310 | if (expr_stack[expr_depth]->expression)
| 0-7 | ||||||||||||||||||||||||||||||||||||
311 | free (expr_stack[expr_depth]->expression); executed 7 times by 1 test: sh_xfree((expr_stack[expr_depth]->expression), "expr.c", 311); Executed by:
| 7 | ||||||||||||||||||||||||||||||||||||
312 | - | |||||||||||||||||||||||||||||||||||||
313 | free (expr_stack[expr_depth]); | - | ||||||||||||||||||||||||||||||||||||
314 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||||||||||||||||||||
315 | if (expr_depth == 0)
| 0-209 | ||||||||||||||||||||||||||||||||||||
316 | free (expr_stack[expr_depth]); /* free the allocated EXPR_CONTEXT */ executed 209 times by 1 test: sh_xfree((expr_stack[expr_depth]), "expr.c", 316); Executed by:
| 209 | ||||||||||||||||||||||||||||||||||||
317 | - | |||||||||||||||||||||||||||||||||||||
318 | noeval = 0; /* XXX */ | - | ||||||||||||||||||||||||||||||||||||
319 | } executed 209 times by 1 test: end of block Executed by:
| 209 | ||||||||||||||||||||||||||||||||||||
320 | - | |||||||||||||||||||||||||||||||||||||
321 | static void | - | ||||||||||||||||||||||||||||||||||||
322 | expr_bind_variable (lhs, rhs) | - | ||||||||||||||||||||||||||||||||||||
323 | char *lhs, *rhs; | - | ||||||||||||||||||||||||||||||||||||
324 | { | - | ||||||||||||||||||||||||||||||||||||
325 | SHELL_VAR *v; | - | ||||||||||||||||||||||||||||||||||||
326 | int aflags; | - | ||||||||||||||||||||||||||||||||||||
327 | - | |||||||||||||||||||||||||||||||||||||
328 | #if defined (ARRAY_VARS) | - | ||||||||||||||||||||||||||||||||||||
329 | aflags = (assoc_expand_once && already_expanded) ? ASS_NOEXPAND : 0;
| 0-7183335 | ||||||||||||||||||||||||||||||||||||
330 | #else | - | ||||||||||||||||||||||||||||||||||||
331 | aflags = 0; | - | ||||||||||||||||||||||||||||||||||||
332 | #endif | - | ||||||||||||||||||||||||||||||||||||
333 | v = bind_int_variable (lhs, rhs, aflags); | - | ||||||||||||||||||||||||||||||||||||
334 | if (v && (readonly_p (v) || noassign_p (v)))
| 0-7183341 | ||||||||||||||||||||||||||||||||||||
335 | sh_longjmp (evalbuf, 1); /* variable assignment error */ executed 2 times by 1 test: siglongjmp((evalbuf), (1)); Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||
336 | stupidly_hack_special_variables (lhs); | - | ||||||||||||||||||||||||||||||||||||
337 | } executed 7183345 times by 1 test: end of block Executed by:
| 7183345 | ||||||||||||||||||||||||||||||||||||
338 | - | |||||||||||||||||||||||||||||||||||||
339 | #if defined (ARRAY_VARS) | - | ||||||||||||||||||||||||||||||||||||
340 | /* Rewrite tok, which is of the form vname[expression], to vname[ind], where | - | ||||||||||||||||||||||||||||||||||||
341 | IND is the already-calculated value of expression. */ | - | ||||||||||||||||||||||||||||||||||||
342 | static void | - | ||||||||||||||||||||||||||||||||||||
343 | expr_bind_array_element (tok, ind, rhs) | - | ||||||||||||||||||||||||||||||||||||
344 | char *tok; | - | ||||||||||||||||||||||||||||||||||||
345 | arrayind_t ind; | - | ||||||||||||||||||||||||||||||||||||
346 | char *rhs; | - | ||||||||||||||||||||||||||||||||||||
347 | { | - | ||||||||||||||||||||||||||||||||||||
348 | char *lhs, *vname; | - | ||||||||||||||||||||||||||||||||||||
349 | size_t llen; | - | ||||||||||||||||||||||||||||||||||||
350 | char ibuf[INT_STRLEN_BOUND (arrayind_t) + 1], *istr; | - | ||||||||||||||||||||||||||||||||||||
351 | - | |||||||||||||||||||||||||||||||||||||
352 | istr = fmtumax (ind, 10, ibuf, sizeof (ibuf), 0); | - | ||||||||||||||||||||||||||||||||||||
353 | vname = array_variable_name (tok, 0, (char **)NULL, (int *)NULL); | - | ||||||||||||||||||||||||||||||||||||
354 | - | |||||||||||||||||||||||||||||||||||||
355 | llen = strlen (vname) + sizeof (ibuf) + 3; | - | ||||||||||||||||||||||||||||||||||||
356 | lhs = xmalloc (llen); | - | ||||||||||||||||||||||||||||||||||||
357 | - | |||||||||||||||||||||||||||||||||||||
358 | sprintf (lhs, "%s[%s]", vname, istr); /* XXX */ | - | ||||||||||||||||||||||||||||||||||||
359 | - | |||||||||||||||||||||||||||||||||||||
360 | /*itrace("expr_bind_array_element: %s=%s", lhs, rhs);*/ | - | ||||||||||||||||||||||||||||||||||||
361 | expr_bind_variable (lhs, rhs); | - | ||||||||||||||||||||||||||||||||||||
362 | free (vname); | - | ||||||||||||||||||||||||||||||||||||
363 | free (lhs); | - | ||||||||||||||||||||||||||||||||||||
364 | } executed 10010 times by 1 test: end of block Executed by:
| 10010 | ||||||||||||||||||||||||||||||||||||
365 | #endif /* ARRAY_VARS */ | - | ||||||||||||||||||||||||||||||||||||
366 | - | |||||||||||||||||||||||||||||||||||||
367 | /* Evaluate EXPR, and return the arithmetic result. If VALIDP is | - | ||||||||||||||||||||||||||||||||||||
368 | non-null, a zero is stored into the location to which it points | - | ||||||||||||||||||||||||||||||||||||
369 | if the expression is invalid, non-zero otherwise. If a non-zero | - | ||||||||||||||||||||||||||||||||||||
370 | value is returned in *VALIDP, the return value of evalexp() may | - | ||||||||||||||||||||||||||||||||||||
371 | be used. | - | ||||||||||||||||||||||||||||||||||||
372 | - | |||||||||||||||||||||||||||||||||||||
373 | The `while' loop after the longjmp is caught relies on the above | - | ||||||||||||||||||||||||||||||||||||
374 | implementation of pushexp and popexp leaving in expr_stack[0] the | - | ||||||||||||||||||||||||||||||||||||
375 | values that the variables had when the program started. That is, | - | ||||||||||||||||||||||||||||||||||||
376 | the first things saved are the initial values of the variables that | - | ||||||||||||||||||||||||||||||||||||
377 | were assigned at program startup or by the compiler. Therefore, it is | - | ||||||||||||||||||||||||||||||||||||
378 | safe to let the loop terminate when expr_depth == 0, without freeing up | - | ||||||||||||||||||||||||||||||||||||
379 | any of the expr_depth[0] stuff. */ | - | ||||||||||||||||||||||||||||||||||||
380 | intmax_t | - | ||||||||||||||||||||||||||||||||||||
381 | evalexp (expr, flags, validp) | - | ||||||||||||||||||||||||||||||||||||
382 | char *expr; | - | ||||||||||||||||||||||||||||||||||||
383 | int flags; | - | ||||||||||||||||||||||||||||||||||||
384 | int *validp; | - | ||||||||||||||||||||||||||||||||||||
385 | { | - | ||||||||||||||||||||||||||||||||||||
386 | intmax_t val; | - | ||||||||||||||||||||||||||||||||||||
387 | int c; | - | ||||||||||||||||||||||||||||||||||||
388 | procenv_t oevalbuf; | - | ||||||||||||||||||||||||||||||||||||
389 | - | |||||||||||||||||||||||||||||||||||||
390 | val = 0; | - | ||||||||||||||||||||||||||||||||||||
391 | noeval = 0; | - | ||||||||||||||||||||||||||||||||||||
392 | already_expanded = (flags&EXP_EXPANDED); | - | ||||||||||||||||||||||||||||||||||||
393 | - | |||||||||||||||||||||||||||||||||||||
394 | FASTCOPY (evalbuf, oevalbuf, sizeof (evalbuf)); | - | ||||||||||||||||||||||||||||||||||||
395 | - | |||||||||||||||||||||||||||||||||||||
396 | c = setjmp_nosigs (evalbuf); | - | ||||||||||||||||||||||||||||||||||||
397 | - | |||||||||||||||||||||||||||||||||||||
398 | if (c)
| 209-7256486 | ||||||||||||||||||||||||||||||||||||
399 | { | - | ||||||||||||||||||||||||||||||||||||
400 | FREE (tokstr); executed 82 times by 1 test: sh_xfree((tokstr), "expr.c", 400); Executed by:
| 82-127 | ||||||||||||||||||||||||||||||||||||
401 | FREE (expression); executed 209 times by 1 test: sh_xfree((expression), "expr.c", 401); Executed by:
| 0-209 | ||||||||||||||||||||||||||||||||||||
402 | tokstr = expression = (char *)NULL; | - | ||||||||||||||||||||||||||||||||||||
403 | - | |||||||||||||||||||||||||||||||||||||
404 | expr_unwind (); | - | ||||||||||||||||||||||||||||||||||||
405 | expr_depth = 0; /* XXX - make sure */ | - | ||||||||||||||||||||||||||||||||||||
406 | - | |||||||||||||||||||||||||||||||||||||
407 | /* We copy in case we've called evalexp recursively */ | - | ||||||||||||||||||||||||||||||||||||
408 | FASTCOPY (oevalbuf, evalbuf, sizeof (evalbuf)); | - | ||||||||||||||||||||||||||||||||||||
409 | - | |||||||||||||||||||||||||||||||||||||
410 | if (validp)
| 0-209 | ||||||||||||||||||||||||||||||||||||
411 | *validp = 0; executed 209 times by 1 test: *validp = 0; Executed by:
| 209 | ||||||||||||||||||||||||||||||||||||
412 | return (0); executed 209 times by 1 test: return (0); Executed by:
| 209 | ||||||||||||||||||||||||||||||||||||
413 | } | - | ||||||||||||||||||||||||||||||||||||
414 | - | |||||||||||||||||||||||||||||||||||||
415 | val = subexpr (expr); | - | ||||||||||||||||||||||||||||||||||||
416 | - | |||||||||||||||||||||||||||||||||||||
417 | if (validp)
| 0-7256272 | ||||||||||||||||||||||||||||||||||||
418 | *validp = 1; executed 7256272 times by 1 test: *validp = 1; Executed by:
| 7256272 | ||||||||||||||||||||||||||||||||||||
419 | - | |||||||||||||||||||||||||||||||||||||
420 | FASTCOPY (oevalbuf, evalbuf, sizeof (evalbuf)); | - | ||||||||||||||||||||||||||||||||||||
421 | - | |||||||||||||||||||||||||||||||||||||
422 | return (val); executed 7256272 times by 1 test: return (val); Executed by:
| 7256272 | ||||||||||||||||||||||||||||||||||||
423 | } | - | ||||||||||||||||||||||||||||||||||||
424 | - | |||||||||||||||||||||||||||||||||||||
425 | static intmax_t | - | ||||||||||||||||||||||||||||||||||||
426 | subexpr (expr) | - | ||||||||||||||||||||||||||||||||||||
427 | char *expr; | - | ||||||||||||||||||||||||||||||||||||
428 | { | - | ||||||||||||||||||||||||||||||||||||
429 | intmax_t val; | - | ||||||||||||||||||||||||||||||||||||
430 | char *p; | - | ||||||||||||||||||||||||||||||||||||
431 | - | |||||||||||||||||||||||||||||||||||||
432 | for (p = expr; p && *p && cr_whitespace (*p); p++)
| 0-14516482 | ||||||||||||||||||||||||||||||||||||
433 | ; executed 8346 times by 1 test: ; Executed by:
| 8346 | ||||||||||||||||||||||||||||||||||||
434 | - | |||||||||||||||||||||||||||||||||||||
435 | if (p == NULL || *p == '\0')
| 16-14508136 | ||||||||||||||||||||||||||||||||||||
436 | return (0); executed 43 times by 1 test: return (0); Executed by:
| 43 | ||||||||||||||||||||||||||||||||||||
437 | - | |||||||||||||||||||||||||||||||||||||
438 | pushexp (); | - | ||||||||||||||||||||||||||||||||||||
439 | expression = savestring (expr); | - | ||||||||||||||||||||||||||||||||||||
440 | tp = expression; | - | ||||||||||||||||||||||||||||||||||||
441 | - | |||||||||||||||||||||||||||||||||||||
442 | curtok = lasttok = 0; | - | ||||||||||||||||||||||||||||||||||||
443 | tokstr = (char *)NULL; | - | ||||||||||||||||||||||||||||||||||||
444 | tokval = 0; | - | ||||||||||||||||||||||||||||||||||||
445 | init_lvalue (&curlval); | - | ||||||||||||||||||||||||||||||||||||
446 | lastlval = curlval; | - | ||||||||||||||||||||||||||||||||||||
447 | - | |||||||||||||||||||||||||||||||||||||
448 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
449 | - | |||||||||||||||||||||||||||||||||||||
450 | val = EXP_HIGHEST (); | - | ||||||||||||||||||||||||||||||||||||
451 | - | |||||||||||||||||||||||||||||||||||||
452 | if (curtok != 0)
| 15-14507889 | ||||||||||||||||||||||||||||||||||||
453 | evalerror (_("syntax error in expression")); executed 15 times by 1 test: evalerror ( dcgettext (((void *)0), "syntax error in expression" , 5) ); Executed by:
| 15 | ||||||||||||||||||||||||||||||||||||
454 | - | |||||||||||||||||||||||||||||||||||||
455 | FREE (tokstr); executed 736643 times by 1 test: sh_xfree((tokstr), "expr.c", 455); Executed by:
| 736643-13771246 | ||||||||||||||||||||||||||||||||||||
456 | FREE (expression); executed 14507889 times by 1 test: sh_xfree((expression), "expr.c", 456); Executed by:
| 0-14507889 | ||||||||||||||||||||||||||||||||||||
457 | - | |||||||||||||||||||||||||||||||||||||
458 | popexp (); | - | ||||||||||||||||||||||||||||||||||||
459 | - | |||||||||||||||||||||||||||||||||||||
460 | return val; executed 14507889 times by 1 test: return val; Executed by:
| 14507889 | ||||||||||||||||||||||||||||||||||||
461 | } | - | ||||||||||||||||||||||||||||||||||||
462 | - | |||||||||||||||||||||||||||||||||||||
463 | static intmax_t | - | ||||||||||||||||||||||||||||||||||||
464 | expcomma () | - | ||||||||||||||||||||||||||||||||||||
465 | { | - | ||||||||||||||||||||||||||||||||||||
466 | register intmax_t value; | - | ||||||||||||||||||||||||||||||||||||
467 | - | |||||||||||||||||||||||||||||||||||||
468 | value = expassign (); | - | ||||||||||||||||||||||||||||||||||||
469 | while (curtok == COMMA)
| 39613-14528747 | ||||||||||||||||||||||||||||||||||||
470 | { | - | ||||||||||||||||||||||||||||||||||||
471 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
472 | value = expassign (); | - | ||||||||||||||||||||||||||||||||||||
473 | } executed 39613 times by 1 test: end of block Executed by:
| 39613 | ||||||||||||||||||||||||||||||||||||
474 | - | |||||||||||||||||||||||||||||||||||||
475 | return value; executed 14528747 times by 1 test: return value; Executed by:
| 14528747 | ||||||||||||||||||||||||||||||||||||
476 | } | - | ||||||||||||||||||||||||||||||||||||
477 | - | |||||||||||||||||||||||||||||||||||||
478 | static intmax_t | - | ||||||||||||||||||||||||||||||||||||
479 | expassign () | - | ||||||||||||||||||||||||||||||||||||
480 | { | - | ||||||||||||||||||||||||||||||||||||
481 | register intmax_t value; | - | ||||||||||||||||||||||||||||||||||||
482 | char *lhs, *rhs; | - | ||||||||||||||||||||||||||||||||||||
483 | arrayind_t lind; | - | ||||||||||||||||||||||||||||||||||||
484 | #if defined (HAVE_IMAXDIV) | - | ||||||||||||||||||||||||||||||||||||
485 | imaxdiv_t idiv; | - | ||||||||||||||||||||||||||||||||||||
486 | #endif | - | ||||||||||||||||||||||||||||||||||||
487 | - | |||||||||||||||||||||||||||||||||||||
488 | value = expcond (); | - | ||||||||||||||||||||||||||||||||||||
489 | if (curtok == EQ || curtok == OP_ASSIGN)
| 2636-21074228 | ||||||||||||||||||||||||||||||||||||
490 | { | - | ||||||||||||||||||||||||||||||||||||
491 | int special, op; | - | ||||||||||||||||||||||||||||||||||||
492 | intmax_t lvalue; | - | ||||||||||||||||||||||||||||||||||||
493 | - | |||||||||||||||||||||||||||||||||||||
494 | special = curtok == OP_ASSIGN; | - | ||||||||||||||||||||||||||||||||||||
495 | - | |||||||||||||||||||||||||||||||||||||
496 | if (lasttok != STR)
| 52-6508450 | ||||||||||||||||||||||||||||||||||||
497 | evalerror (_("attempted assignment to non-variable")); executed 52 times by 1 test: evalerror ( dcgettext (((void *)0), "attempted assignment to non-variable" , 5) ); Executed by:
| 52 | ||||||||||||||||||||||||||||||||||||
498 | - | |||||||||||||||||||||||||||||||||||||
499 | if (special)
| 2592-6505858 | ||||||||||||||||||||||||||||||||||||
500 | { | - | ||||||||||||||||||||||||||||||||||||
501 | op = assigntok; /* a OP= b */ | - | ||||||||||||||||||||||||||||||||||||
502 | lvalue = value; | - | ||||||||||||||||||||||||||||||||||||
503 | } executed 6505858 times by 1 test: end of block Executed by:
| 6505858 | ||||||||||||||||||||||||||||||||||||
504 | - | |||||||||||||||||||||||||||||||||||||
505 | if (tokstr == 0)
| 0-6508450 | ||||||||||||||||||||||||||||||||||||
506 | evalerror (_("syntax error in variable assignment")); never executed: evalerror ( dcgettext (((void *)0), "syntax error in variable assignment" , 5) ); | 0 | ||||||||||||||||||||||||||||||||||||
507 | - | |||||||||||||||||||||||||||||||||||||
508 | /* XXX - watch out for pointer aliasing issues here */ | - | ||||||||||||||||||||||||||||||||||||
509 | lhs = savestring (tokstr); | - | ||||||||||||||||||||||||||||||||||||
510 | /* save ind in case rhs is string var and evaluation overwrites it */ | - | ||||||||||||||||||||||||||||||||||||
511 | lind = curlval.ind; | - | ||||||||||||||||||||||||||||||||||||
512 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
513 | value = expassign (); | - | ||||||||||||||||||||||||||||||||||||
514 | - | |||||||||||||||||||||||||||||||||||||
515 | if (special)
| 2584-6505842 | ||||||||||||||||||||||||||||||||||||
516 | { | - | ||||||||||||||||||||||||||||||||||||
517 | if ((op == DIV || op == MOD) && value == 0)
| 0-6505832 | ||||||||||||||||||||||||||||||||||||
518 | { | - | ||||||||||||||||||||||||||||||||||||
519 | if (noeval == 0)
| 0 | ||||||||||||||||||||||||||||||||||||
520 | evalerror (_("division by 0")); never executed: evalerror ( dcgettext (((void *)0), "division by 0" , 5) ); | 0 | ||||||||||||||||||||||||||||||||||||
521 | else | - | ||||||||||||||||||||||||||||||||||||
522 | value = 1; never executed: value = 1; | 0 | ||||||||||||||||||||||||||||||||||||
523 | } | - | ||||||||||||||||||||||||||||||||||||
524 | - | |||||||||||||||||||||||||||||||||||||
525 | switch (op) | - | ||||||||||||||||||||||||||||||||||||
526 | { | - | ||||||||||||||||||||||||||||||||||||
527 | case MUL: executed 19819 times by 1 test: case '*': Executed by:
| 19819 | ||||||||||||||||||||||||||||||||||||
528 | lvalue *= value; | - | ||||||||||||||||||||||||||||||||||||
529 | break; executed 19819 times by 1 test: break; Executed by:
| 19819 | ||||||||||||||||||||||||||||||||||||
530 | case DIV: executed 10 times by 1 test: case '/': Executed by:
| 10 | ||||||||||||||||||||||||||||||||||||
531 | case MOD: executed 11 times by 1 test: case '%': Executed by:
| 11 | ||||||||||||||||||||||||||||||||||||
532 | if (lvalue == INTMAX_MIN && value == -1)
| 0-17 | ||||||||||||||||||||||||||||||||||||
533 | lvalue = (op == DIV) ? INTMAX_MIN : 0; executed 4 times by 1 test: lvalue = (op == '/') ? (-9223372036854775807L -1) : 0; Executed by:
| 2-4 | ||||||||||||||||||||||||||||||||||||
534 | else | - | ||||||||||||||||||||||||||||||||||||
535 | #if HAVE_IMAXDIV | - | ||||||||||||||||||||||||||||||||||||
536 | { | - | ||||||||||||||||||||||||||||||||||||
537 | idiv = imaxdiv (lvalue, value); | - | ||||||||||||||||||||||||||||||||||||
538 | lvalue = (op == DIV) ? idiv.quot : idiv.rem;
| 8-9 | ||||||||||||||||||||||||||||||||||||
539 | } executed 17 times by 1 test: end of block Executed by:
| 17 | ||||||||||||||||||||||||||||||||||||
540 | #else | - | ||||||||||||||||||||||||||||||||||||
541 | lvalue = (op == DIV) ? lvalue / value : lvalue % value; | - | ||||||||||||||||||||||||||||||||||||
542 | #endif | - | ||||||||||||||||||||||||||||||||||||
543 | break; executed 21 times by 1 test: break; Executed by:
| 21 | ||||||||||||||||||||||||||||||||||||
544 | case PLUS: executed 6485953 times by 1 test: case '+': Executed by:
| 6485953 | ||||||||||||||||||||||||||||||||||||
545 | lvalue += value; | - | ||||||||||||||||||||||||||||||||||||
546 | break; executed 6485953 times by 1 test: break; Executed by:
| 6485953 | ||||||||||||||||||||||||||||||||||||
547 | case MINUS: executed 9 times by 1 test: case '-': Executed by:
| 9 | ||||||||||||||||||||||||||||||||||||
548 | lvalue -= value; | - | ||||||||||||||||||||||||||||||||||||
549 | break; executed 9 times by 1 test: break; Executed by:
| 9 | ||||||||||||||||||||||||||||||||||||
550 | case LSH: executed 16 times by 1 test: case 9: Executed by:
| 16 | ||||||||||||||||||||||||||||||||||||
551 | lvalue <<= value; | - | ||||||||||||||||||||||||||||||||||||
552 | break; executed 16 times by 1 test: break; Executed by:
| 16 | ||||||||||||||||||||||||||||||||||||
553 | case RSH: executed 8 times by 1 test: case 10: Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||
554 | lvalue >>= value; | - | ||||||||||||||||||||||||||||||||||||
555 | break; executed 8 times by 1 test: break; Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||
556 | case BAND: executed 8 times by 1 test: case '&': Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||
557 | lvalue &= value; | - | ||||||||||||||||||||||||||||||||||||
558 | break; executed 8 times by 1 test: break; Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||
559 | case BOR: executed 8 times by 1 test: case '|': Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||
560 | lvalue |= value; | - | ||||||||||||||||||||||||||||||||||||
561 | break; executed 8 times by 1 test: break; Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||
562 | case BXOR: never executed: case '^': | 0 | ||||||||||||||||||||||||||||||||||||
563 | lvalue ^= value; | - | ||||||||||||||||||||||||||||||||||||
564 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
565 | default: never executed: default: | 0 | ||||||||||||||||||||||||||||||||||||
566 | free (lhs); | - | ||||||||||||||||||||||||||||||||||||
567 | evalerror (_("bug: bad expassign token")); | - | ||||||||||||||||||||||||||||||||||||
568 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
569 | } | - | ||||||||||||||||||||||||||||||||||||
570 | value = lvalue; | - | ||||||||||||||||||||||||||||||||||||
571 | } executed 6505842 times by 1 test: end of block Executed by:
| 6505842 | ||||||||||||||||||||||||||||||||||||
572 | - | |||||||||||||||||||||||||||||||||||||
573 | rhs = itos (value); | - | ||||||||||||||||||||||||||||||||||||
574 | if (noeval == 0)
| 17753-6490673 | ||||||||||||||||||||||||||||||||||||
575 | { | - | ||||||||||||||||||||||||||||||||||||
576 | #if defined (ARRAY_VARS) | - | ||||||||||||||||||||||||||||||||||||
577 | if (lind != -1)
| 4-6490669 | ||||||||||||||||||||||||||||||||||||
578 | expr_bind_array_element (lhs, lind, rhs); executed 4 times by 1 test: expr_bind_array_element (lhs, lind, rhs); Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||
579 | else | - | ||||||||||||||||||||||||||||||||||||
580 | #endif | - | ||||||||||||||||||||||||||||||||||||
581 | expr_bind_variable (lhs, rhs); executed 6490669 times by 1 test: expr_bind_variable (lhs, rhs); Executed by:
| 6490669 | ||||||||||||||||||||||||||||||||||||
582 | } | - | ||||||||||||||||||||||||||||||||||||
583 | if (curlval.tokstr && curlval.tokstr == tokstr)
| 0-6488134 | ||||||||||||||||||||||||||||||||||||
584 | init_lvalue (&curlval); executed 6488134 times by 1 test: init_lvalue (&curlval); Executed by:
| 6488134 | ||||||||||||||||||||||||||||||||||||
585 | - | |||||||||||||||||||||||||||||||||||||
586 | free (rhs); | - | ||||||||||||||||||||||||||||||||||||
587 | free (lhs); | - | ||||||||||||||||||||||||||||||||||||
588 | FREE (tokstr); executed 6507816 times by 1 test: sh_xfree((tokstr), "expr.c", 588); Executed by:
| 608-6507816 | ||||||||||||||||||||||||||||||||||||
589 | tokstr = (char *)NULL; /* For freeing on errors. */ | - | ||||||||||||||||||||||||||||||||||||
590 | } executed 6508424 times by 1 test: end of block Executed by:
| 6508424 | ||||||||||||||||||||||||||||||||||||
591 | - | |||||||||||||||||||||||||||||||||||||
592 | return (value); executed 21076786 times by 1 test: return (value); Executed by:
| 21076786 | ||||||||||||||||||||||||||||||||||||
593 | } | - | ||||||||||||||||||||||||||||||||||||
594 | - | |||||||||||||||||||||||||||||||||||||
595 | /* Conditional expression (expr?expr:expr) */ | - | ||||||||||||||||||||||||||||||||||||
596 | static intmax_t | - | ||||||||||||||||||||||||||||||||||||
597 | expcond () | - | ||||||||||||||||||||||||||||||||||||
598 | { | - | ||||||||||||||||||||||||||||||||||||
599 | intmax_t cval, val1, val2, rval; | - | ||||||||||||||||||||||||||||||||||||
600 | int set_noeval; | - | ||||||||||||||||||||||||||||||||||||
601 | - | |||||||||||||||||||||||||||||||||||||
602 | set_noeval = 0; | - | ||||||||||||||||||||||||||||||||||||
603 | rval = cval = explor (); | - | ||||||||||||||||||||||||||||||||||||
604 | if (curtok == QUES) /* found conditional expr */
| 240-21076864 | ||||||||||||||||||||||||||||||||||||
605 | { | - | ||||||||||||||||||||||||||||||||||||
606 | if (cval == 0)
| 68-172 | ||||||||||||||||||||||||||||||||||||
607 | { | - | ||||||||||||||||||||||||||||||||||||
608 | set_noeval = 1; | - | ||||||||||||||||||||||||||||||||||||
609 | noeval++; | - | ||||||||||||||||||||||||||||||||||||
610 | } executed 68 times by 1 test: end of block Executed by:
| 68 | ||||||||||||||||||||||||||||||||||||
611 | - | |||||||||||||||||||||||||||||||||||||
612 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
613 | if (curtok == 0 || curtok == COL)
| 0-240 | ||||||||||||||||||||||||||||||||||||
614 | evalerror (_("expression expected")); executed 6 times by 1 test: evalerror ( dcgettext (((void *)0), "expression expected" , 5) ); Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||
615 | - | |||||||||||||||||||||||||||||||||||||
616 | val1 = EXP_HIGHEST (); | - | ||||||||||||||||||||||||||||||||||||
617 | - | |||||||||||||||||||||||||||||||||||||
618 | if (set_noeval)
| 68-166 | ||||||||||||||||||||||||||||||||||||
619 | noeval--; executed 68 times by 1 test: noeval--; Executed by:
| 68 | ||||||||||||||||||||||||||||||||||||
620 | if (curtok != COL)
| 6-228 | ||||||||||||||||||||||||||||||||||||
621 | evalerror (_("`:' expected for conditional expression")); executed 6 times by 1 test: evalerror ( dcgettext (((void *)0), "`:' expected for conditional expression" , 5) ); Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||
622 | - | |||||||||||||||||||||||||||||||||||||
623 | set_noeval = 0; | - | ||||||||||||||||||||||||||||||||||||
624 | if (cval)
| 68-160 | ||||||||||||||||||||||||||||||||||||
625 | { | - | ||||||||||||||||||||||||||||||||||||
626 | set_noeval = 1; | - | ||||||||||||||||||||||||||||||||||||
627 | noeval++; | - | ||||||||||||||||||||||||||||||||||||
628 | } executed 160 times by 1 test: end of block Executed by:
| 160 | ||||||||||||||||||||||||||||||||||||
629 | - | |||||||||||||||||||||||||||||||||||||
630 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
631 | if (curtok == 0)
| 6-222 | ||||||||||||||||||||||||||||||||||||
632 | evalerror (_("expression expected")); executed 6 times by 1 test: evalerror ( dcgettext (((void *)0), "expression expected" , 5) ); Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||
633 | val2 = expcond (); | - | ||||||||||||||||||||||||||||||||||||
634 | - | |||||||||||||||||||||||||||||||||||||
635 | if (set_noeval)
| 68-154 | ||||||||||||||||||||||||||||||||||||
636 | noeval--; executed 154 times by 1 test: noeval--; Executed by:
| 154 | ||||||||||||||||||||||||||||||||||||
637 | rval = cval ? val1 : val2;
| 68-154 | ||||||||||||||||||||||||||||||||||||
638 | lasttok = COND; | - | ||||||||||||||||||||||||||||||||||||
639 | } executed 222 times by 1 test: end of block Executed by:
| 222 | ||||||||||||||||||||||||||||||||||||
640 | return rval; executed 21077086 times by 1 test: return rval; Executed by:
| 21077086 | ||||||||||||||||||||||||||||||||||||
641 | } | - | ||||||||||||||||||||||||||||||||||||
642 | - | |||||||||||||||||||||||||||||||||||||
643 | /* Logical OR. */ | - | ||||||||||||||||||||||||||||||||||||
644 | static intmax_t | - | ||||||||||||||||||||||||||||||||||||
645 | explor () | - | ||||||||||||||||||||||||||||||||||||
646 | { | - | ||||||||||||||||||||||||||||||||||||
647 | register intmax_t val1, val2; | - | ||||||||||||||||||||||||||||||||||||
648 | int set_noeval; | - | ||||||||||||||||||||||||||||||||||||
649 | - | |||||||||||||||||||||||||||||||||||||
650 | val1 = expland (); | - | ||||||||||||||||||||||||||||||||||||
651 | - | |||||||||||||||||||||||||||||||||||||
652 | while (curtok == LOR)
| 19837-21077104 | ||||||||||||||||||||||||||||||||||||
653 | { | - | ||||||||||||||||||||||||||||||||||||
654 | set_noeval = 0; | - | ||||||||||||||||||||||||||||||||||||
655 | if (val1 != 0)
| 2112-17725 | ||||||||||||||||||||||||||||||||||||
656 | { | - | ||||||||||||||||||||||||||||||||||||
657 | noeval++; | - | ||||||||||||||||||||||||||||||||||||
658 | set_noeval = 1; | - | ||||||||||||||||||||||||||||||||||||
659 | } executed 17725 times by 1 test: end of block Executed by:
| 17725 | ||||||||||||||||||||||||||||||||||||
660 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
661 | val2 = expland (); | - | ||||||||||||||||||||||||||||||||||||
662 | if (set_noeval)
| 2112-17725 | ||||||||||||||||||||||||||||||||||||
663 | noeval--; executed 17725 times by 1 test: noeval--; Executed by:
| 17725 | ||||||||||||||||||||||||||||||||||||
664 | val1 = val1 || val2;
| 102-17725 | ||||||||||||||||||||||||||||||||||||
665 | lasttok = LOR; | - | ||||||||||||||||||||||||||||||||||||
666 | } executed 19837 times by 1 test: end of block Executed by:
| 19837 | ||||||||||||||||||||||||||||||||||||
667 | - | |||||||||||||||||||||||||||||||||||||
668 | return (val1); executed 21077104 times by 1 test: return (val1); Executed by:
| 21077104 | ||||||||||||||||||||||||||||||||||||
669 | } | - | ||||||||||||||||||||||||||||||||||||
670 | - | |||||||||||||||||||||||||||||||||||||
671 | /* Logical AND. */ | - | ||||||||||||||||||||||||||||||||||||
672 | static intmax_t | - | ||||||||||||||||||||||||||||||||||||
673 | expland () | - | ||||||||||||||||||||||||||||||||||||
674 | { | - | ||||||||||||||||||||||||||||||||||||
675 | register intmax_t val1, val2; | - | ||||||||||||||||||||||||||||||||||||
676 | int set_noeval; | - | ||||||||||||||||||||||||||||||||||||
677 | - | |||||||||||||||||||||||||||||||||||||
678 | val1 = expbor (); | - | ||||||||||||||||||||||||||||||||||||
679 | - | |||||||||||||||||||||||||||||||||||||
680 | while (curtok == LAND)
| 65-21096941 | ||||||||||||||||||||||||||||||||||||
681 | { | - | ||||||||||||||||||||||||||||||||||||
682 | set_noeval = 0; | - | ||||||||||||||||||||||||||||||||||||
683 | if (val1 == 0)
| 24-41 | ||||||||||||||||||||||||||||||||||||
684 | { | - | ||||||||||||||||||||||||||||||||||||
685 | set_noeval = 1; | - | ||||||||||||||||||||||||||||||||||||
686 | noeval++; | - | ||||||||||||||||||||||||||||||||||||
687 | } executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||||||||||||||||||||||||||
688 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
689 | val2 = expbor (); | - | ||||||||||||||||||||||||||||||||||||
690 | if (set_noeval)
| 24-41 | ||||||||||||||||||||||||||||||||||||
691 | noeval--; executed 24 times by 1 test: noeval--; Executed by:
| 24 | ||||||||||||||||||||||||||||||||||||
692 | val1 = val1 && val2;
| 19-41 | ||||||||||||||||||||||||||||||||||||
693 | lasttok = LAND; | - | ||||||||||||||||||||||||||||||||||||
694 | } executed 65 times by 1 test: end of block Executed by:
| 65 | ||||||||||||||||||||||||||||||||||||
695 | - | |||||||||||||||||||||||||||||||||||||
696 | return (val1); executed 21096941 times by 1 test: return (val1); Executed by:
| 21096941 | ||||||||||||||||||||||||||||||||||||
697 | } | - | ||||||||||||||||||||||||||||||||||||
698 | - | |||||||||||||||||||||||||||||||||||||
699 | /* Bitwise OR. */ | - | ||||||||||||||||||||||||||||||||||||
700 | static intmax_t | - | ||||||||||||||||||||||||||||||||||||
701 | expbor () | - | ||||||||||||||||||||||||||||||||||||
702 | { | - | ||||||||||||||||||||||||||||||||||||
703 | register intmax_t val1, val2; | - | ||||||||||||||||||||||||||||||||||||
704 | - | |||||||||||||||||||||||||||||||||||||
705 | val1 = expbxor (); | - | ||||||||||||||||||||||||||||||||||||
706 | - | |||||||||||||||||||||||||||||||||||||
707 | while (curtok == BOR)
| 33-21097006 | ||||||||||||||||||||||||||||||||||||
708 | { | - | ||||||||||||||||||||||||||||||||||||
709 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
710 | val2 = expbxor (); | - | ||||||||||||||||||||||||||||||||||||
711 | val1 = val1 | val2; | - | ||||||||||||||||||||||||||||||||||||
712 | lasttok = NUM; | - | ||||||||||||||||||||||||||||||||||||
713 | } executed 33 times by 1 test: end of block Executed by:
| 33 | ||||||||||||||||||||||||||||||||||||
714 | - | |||||||||||||||||||||||||||||||||||||
715 | return (val1); executed 21097006 times by 1 test: return (val1); Executed by:
| 21097006 | ||||||||||||||||||||||||||||||||||||
716 | } | - | ||||||||||||||||||||||||||||||||||||
717 | - | |||||||||||||||||||||||||||||||||||||
718 | /* Bitwise XOR. */ | - | ||||||||||||||||||||||||||||||||||||
719 | static intmax_t | - | ||||||||||||||||||||||||||||||||||||
720 | expbxor () | - | ||||||||||||||||||||||||||||||||||||
721 | { | - | ||||||||||||||||||||||||||||||||||||
722 | register intmax_t val1, val2; | - | ||||||||||||||||||||||||||||||||||||
723 | - | |||||||||||||||||||||||||||||||||||||
724 | val1 = expband (); | - | ||||||||||||||||||||||||||||||||||||
725 | - | |||||||||||||||||||||||||||||||||||||
726 | while (curtok == BXOR)
| 8-21097039 | ||||||||||||||||||||||||||||||||||||
727 | { | - | ||||||||||||||||||||||||||||||||||||
728 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
729 | val2 = expband (); | - | ||||||||||||||||||||||||||||||||||||
730 | val1 = val1 ^ val2; | - | ||||||||||||||||||||||||||||||||||||
731 | lasttok = NUM; | - | ||||||||||||||||||||||||||||||||||||
732 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||
733 | - | |||||||||||||||||||||||||||||||||||||
734 | return (val1); executed 21097039 times by 1 test: return (val1); Executed by:
| 21097039 | ||||||||||||||||||||||||||||||||||||
735 | } | - | ||||||||||||||||||||||||||||||||||||
736 | - | |||||||||||||||||||||||||||||||||||||
737 | /* Bitwise AND. */ | - | ||||||||||||||||||||||||||||||||||||
738 | static intmax_t | - | ||||||||||||||||||||||||||||||||||||
739 | expband () | - | ||||||||||||||||||||||||||||||||||||
740 | { | - | ||||||||||||||||||||||||||||||||||||
741 | register intmax_t val1, val2; | - | ||||||||||||||||||||||||||||||||||||
742 | - | |||||||||||||||||||||||||||||||||||||
743 | val1 = exp5 (); | - | ||||||||||||||||||||||||||||||||||||
744 | - | |||||||||||||||||||||||||||||||||||||
745 | while (curtok == BAND)
| 26-21097047 | ||||||||||||||||||||||||||||||||||||
746 | { | - | ||||||||||||||||||||||||||||||||||||
747 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
748 | val2 = exp5 (); | - | ||||||||||||||||||||||||||||||||||||
749 | val1 = val1 & val2; | - | ||||||||||||||||||||||||||||||||||||
750 | lasttok = NUM; | - | ||||||||||||||||||||||||||||||||||||
751 | } executed 26 times by 1 test: end of block Executed by:
| 26 | ||||||||||||||||||||||||||||||||||||
752 | - | |||||||||||||||||||||||||||||||||||||
753 | return (val1); executed 21097047 times by 1 test: return (val1); Executed by:
| 21097047 | ||||||||||||||||||||||||||||||||||||
754 | } | - | ||||||||||||||||||||||||||||||||||||
755 | - | |||||||||||||||||||||||||||||||||||||
756 | static intmax_t | - | ||||||||||||||||||||||||||||||||||||
757 | exp5 () | - | ||||||||||||||||||||||||||||||||||||
758 | { | - | ||||||||||||||||||||||||||||||||||||
759 | register intmax_t val1, val2; | - | ||||||||||||||||||||||||||||||||||||
760 | - | |||||||||||||||||||||||||||||||||||||
761 | val1 = exp4 (); | - | ||||||||||||||||||||||||||||||||||||
762 | - | |||||||||||||||||||||||||||||||||||||
763 | while ((curtok == EQEQ) || (curtok == NEQ))
| 10-21097083 | ||||||||||||||||||||||||||||||||||||
764 | { | - | ||||||||||||||||||||||||||||||||||||
765 | int op = curtok; | - | ||||||||||||||||||||||||||||||||||||
766 | - | |||||||||||||||||||||||||||||||||||||
767 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
768 | val2 = exp4 (); | - | ||||||||||||||||||||||||||||||||||||
769 | if (op == EQEQ)
| 10-47 | ||||||||||||||||||||||||||||||||||||
770 | val1 = (val1 == val2); executed 47 times by 1 test: val1 = (val1 == val2); Executed by:
| 47 | ||||||||||||||||||||||||||||||||||||
771 | else if (op == NEQ)
| 0-10 | ||||||||||||||||||||||||||||||||||||
772 | val1 = (val1 != val2); executed 10 times by 1 test: val1 = (val1 != val2); Executed by:
| 10 | ||||||||||||||||||||||||||||||||||||
773 | lasttok = NUM; | - | ||||||||||||||||||||||||||||||||||||
774 | } executed 57 times by 1 test: end of block Executed by:
| 57 | ||||||||||||||||||||||||||||||||||||
775 | return (val1); executed 21097073 times by 1 test: return (val1); Executed by:
| 21097073 | ||||||||||||||||||||||||||||||||||||
776 | } | - | ||||||||||||||||||||||||||||||||||||
777 | - | |||||||||||||||||||||||||||||||||||||
778 | static intmax_t | - | ||||||||||||||||||||||||||||||||||||
779 | exp4 () | - | ||||||||||||||||||||||||||||||||||||
780 | { | - | ||||||||||||||||||||||||||||||||||||
781 | register intmax_t val1, val2; | - | ||||||||||||||||||||||||||||||||||||
782 | - | |||||||||||||||||||||||||||||||||||||
783 | val1 = expshift (); | - | ||||||||||||||||||||||||||||||||||||
784 | while ((curtok == LEQ) ||
| 19827-21117640 | ||||||||||||||||||||||||||||||||||||
785 | (curtok == GEQ) ||
| 1625-21116015 | ||||||||||||||||||||||||||||||||||||
786 | (curtok == LT) ||
| 16589-21099426 | ||||||||||||||||||||||||||||||||||||
787 | (curtok == GT))
| 2296-21097130 | ||||||||||||||||||||||||||||||||||||
788 | { | - | ||||||||||||||||||||||||||||||||||||
789 | int op = curtok; | - | ||||||||||||||||||||||||||||||||||||
790 | - | |||||||||||||||||||||||||||||||||||||
791 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
792 | val2 = expshift (); | - | ||||||||||||||||||||||||||||||||||||
793 | - | |||||||||||||||||||||||||||||||||||||
794 | if (op == LEQ)
| 19827-20510 | ||||||||||||||||||||||||||||||||||||
795 | val1 = val1 <= val2; executed 19827 times by 1 test: val1 = val1 <= val2; Executed by:
| 19827 | ||||||||||||||||||||||||||||||||||||
796 | else if (op == GEQ)
| 1625-18885 | ||||||||||||||||||||||||||||||||||||
797 | val1 = val1 >= val2; executed 1625 times by 1 test: val1 = val1 >= val2; Executed by:
| 1625 | ||||||||||||||||||||||||||||||||||||
798 | else if (op == LT)
| 2296-16589 | ||||||||||||||||||||||||||||||||||||
799 | val1 = val1 < val2; executed 16589 times by 1 test: val1 = val1 < val2; Executed by:
| 16589 | ||||||||||||||||||||||||||||||||||||
800 | else /* (op == GT) */ | - | ||||||||||||||||||||||||||||||||||||
801 | val1 = val1 > val2; executed 2296 times by 1 test: val1 = val1 > val2; Executed by:
| 2296 | ||||||||||||||||||||||||||||||||||||
802 | lasttok = NUM; | - | ||||||||||||||||||||||||||||||||||||
803 | } executed 40337 times by 1 test: end of block Executed by:
| 40337 | ||||||||||||||||||||||||||||||||||||
804 | return (val1); executed 21097130 times by 1 test: return (val1); Executed by:
| 21097130 | ||||||||||||||||||||||||||||||||||||
805 | } | - | ||||||||||||||||||||||||||||||||||||
806 | - | |||||||||||||||||||||||||||||||||||||
807 | /* Left and right shifts. */ | - | ||||||||||||||||||||||||||||||||||||
808 | static intmax_t | - | ||||||||||||||||||||||||||||||||||||
809 | expshift () | - | ||||||||||||||||||||||||||||||||||||
810 | { | - | ||||||||||||||||||||||||||||||||||||
811 | register intmax_t val1, val2; | - | ||||||||||||||||||||||||||||||||||||
812 | - | |||||||||||||||||||||||||||||||||||||
813 | val1 = exp3 (); | - | ||||||||||||||||||||||||||||||||||||
814 | - | |||||||||||||||||||||||||||||||||||||
815 | while ((curtok == LSH) || (curtok == RSH))
| 8-21137475 | ||||||||||||||||||||||||||||||||||||
816 | { | - | ||||||||||||||||||||||||||||||||||||
817 | int op = curtok; | - | ||||||||||||||||||||||||||||||||||||
818 | - | |||||||||||||||||||||||||||||||||||||
819 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
820 | val2 = exp3 (); | - | ||||||||||||||||||||||||||||||||||||
821 | - | |||||||||||||||||||||||||||||||||||||
822 | if (op == LSH)
| 8-9 | ||||||||||||||||||||||||||||||||||||
823 | val1 = val1 << val2; executed 9 times by 1 test: val1 = val1 << val2; Executed by:
| 9 | ||||||||||||||||||||||||||||||||||||
824 | else | - | ||||||||||||||||||||||||||||||||||||
825 | val1 = val1 >> val2; executed 8 times by 1 test: val1 = val1 >> val2; Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||
826 | lasttok = NUM; | - | ||||||||||||||||||||||||||||||||||||
827 | } executed 17 times by 1 test: end of block Executed by:
| 17 | ||||||||||||||||||||||||||||||||||||
828 | - | |||||||||||||||||||||||||||||||||||||
829 | return (val1); executed 21137467 times by 1 test: return (val1); Executed by:
| 21137467 | ||||||||||||||||||||||||||||||||||||
830 | } | - | ||||||||||||||||||||||||||||||||||||
831 | - | |||||||||||||||||||||||||||||||||||||
832 | static intmax_t | - | ||||||||||||||||||||||||||||||||||||
833 | exp3 () | - | ||||||||||||||||||||||||||||||||||||
834 | { | - | ||||||||||||||||||||||||||||||||||||
835 | register intmax_t val1, val2; | - | ||||||||||||||||||||||||||||||||||||
836 | - | |||||||||||||||||||||||||||||||||||||
837 | val1 = exp2 (); | - | ||||||||||||||||||||||||||||||||||||
838 | - | |||||||||||||||||||||||||||||||||||||
839 | while ((curtok == PLUS) || (curtok == MINUS))
| 245-21137729 | ||||||||||||||||||||||||||||||||||||
840 | { | - | ||||||||||||||||||||||||||||||||||||
841 | int op = curtok; | - | ||||||||||||||||||||||||||||||||||||
842 | - | |||||||||||||||||||||||||||||||||||||
843 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
844 | val2 = exp2 (); | - | ||||||||||||||||||||||||||||||||||||
845 | - | |||||||||||||||||||||||||||||||||||||
846 | if (op == PLUS)
| 237-30829 | ||||||||||||||||||||||||||||||||||||
847 | val1 += val2; executed 30829 times by 1 test: val1 += val2; Executed by:
| 30829 | ||||||||||||||||||||||||||||||||||||
848 | else if (op == MINUS)
| 0-237 | ||||||||||||||||||||||||||||||||||||
849 | val1 -= val2; executed 237 times by 1 test: val1 -= val2; Executed by:
| 237 | ||||||||||||||||||||||||||||||||||||
850 | lasttok = NUM; | - | ||||||||||||||||||||||||||||||||||||
851 | } executed 31066 times by 1 test: end of block Executed by:
| 31066 | ||||||||||||||||||||||||||||||||||||
852 | return (val1); executed 21137484 times by 1 test: return (val1); Executed by:
| 21137484 | ||||||||||||||||||||||||||||||||||||
853 | } | - | ||||||||||||||||||||||||||||||||||||
854 | - | |||||||||||||||||||||||||||||||||||||
855 | static intmax_t | - | ||||||||||||||||||||||||||||||||||||
856 | exp2 () | - | ||||||||||||||||||||||||||||||||||||
857 | { | - | ||||||||||||||||||||||||||||||||||||
858 | register intmax_t val1, val2; | - | ||||||||||||||||||||||||||||||||||||
859 | #if defined (HAVE_IMAXDIV) | - | ||||||||||||||||||||||||||||||||||||
860 | imaxdiv_t idiv; | - | ||||||||||||||||||||||||||||||||||||
861 | #endif | - | ||||||||||||||||||||||||||||||||||||
862 | - | |||||||||||||||||||||||||||||||||||||
863 | val1 = exppower (); | - | ||||||||||||||||||||||||||||||||||||
864 | - | |||||||||||||||||||||||||||||||||||||
865 | while ((curtok == MUL) ||
| 29-21208682 | ||||||||||||||||||||||||||||||||||||
866 | (curtok == DIV) ||
| 60-21208622 | ||||||||||||||||||||||||||||||||||||
867 | (curtok == MOD))
| 40038-21168584 | ||||||||||||||||||||||||||||||||||||
868 | { | - | ||||||||||||||||||||||||||||||||||||
869 | int op = curtok; | - | ||||||||||||||||||||||||||||||||||||
870 | char *stp, *sltp; | - | ||||||||||||||||||||||||||||||||||||
871 | - | |||||||||||||||||||||||||||||||||||||
872 | stp = tp; | - | ||||||||||||||||||||||||||||||||||||
873 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
874 | - | |||||||||||||||||||||||||||||||||||||
875 | val2 = exppower (); | - | ||||||||||||||||||||||||||||||||||||
876 | - | |||||||||||||||||||||||||||||||||||||
877 | /* Handle division by 0 and twos-complement arithmetic overflow */ | - | ||||||||||||||||||||||||||||||||||||
878 | if (((op == DIV) || (op == MOD)) && (val2 == 0))
| 8-40090 | ||||||||||||||||||||||||||||||||||||
879 | { | - | ||||||||||||||||||||||||||||||||||||
880 | if (noeval == 0)
| 0-8 | ||||||||||||||||||||||||||||||||||||
881 | { | - | ||||||||||||||||||||||||||||||||||||
882 | sltp = lasttp; | - | ||||||||||||||||||||||||||||||||||||
883 | lasttp = stp; | - | ||||||||||||||||||||||||||||||||||||
884 | while (lasttp && *lasttp && whitespace (*lasttp))
| 0-16 | ||||||||||||||||||||||||||||||||||||
885 | lasttp++; executed 8 times by 1 test: lasttp++; Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||
886 | evalerror (_("division by 0")); | - | ||||||||||||||||||||||||||||||||||||
887 | lasttp = sltp; | - | ||||||||||||||||||||||||||||||||||||
888 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
889 | else | - | ||||||||||||||||||||||||||||||||||||
890 | val2 = 1; never executed: val2 = 1; | 0 | ||||||||||||||||||||||||||||||||||||
891 | } | - | ||||||||||||||||||||||||||||||||||||
892 | else if (op == MOD && val1 == INTMAX_MIN && val2 == -1)
| 0-40038 | ||||||||||||||||||||||||||||||||||||
893 | { | - | ||||||||||||||||||||||||||||||||||||
894 | val1 = 0; | - | ||||||||||||||||||||||||||||||||||||
895 | continue; executed 2 times by 1 test: continue; Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||
896 | } | - | ||||||||||||||||||||||||||||||||||||
897 | else if (op == DIV && val1 == INTMAX_MIN && val2 == -1)
| 0-40065 | ||||||||||||||||||||||||||||||||||||
898 | val2 = 1; executed 2 times by 1 test: val2 = 1; Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||
899 | - | |||||||||||||||||||||||||||||||||||||
900 | if (op == MUL)
| 29-40088 | ||||||||||||||||||||||||||||||||||||
901 | val1 *= val2; executed 29 times by 1 test: val1 *= val2; Executed by:
| 29 | ||||||||||||||||||||||||||||||||||||
902 | else if (op == DIV || op == MOD)
| 0-40036 | ||||||||||||||||||||||||||||||||||||
903 | #if defined (HAVE_IMAXDIV) | - | ||||||||||||||||||||||||||||||||||||
904 | { | - | ||||||||||||||||||||||||||||||||||||
905 | idiv = imaxdiv (val1, val2); | - | ||||||||||||||||||||||||||||||||||||
906 | val1 = (op == DIV) ? idiv.quot : idiv.rem;
| 52-40036 | ||||||||||||||||||||||||||||||||||||
907 | } executed 40088 times by 1 test: end of block Executed by:
| 40088 | ||||||||||||||||||||||||||||||||||||
908 | #else | - | ||||||||||||||||||||||||||||||||||||
909 | val1 = (op == DIV) ? val1 / val2 : val1 % val2; | - | ||||||||||||||||||||||||||||||||||||
910 | #endif | - | ||||||||||||||||||||||||||||||||||||
911 | lasttok = NUM; | - | ||||||||||||||||||||||||||||||||||||
912 | } executed 40117 times by 1 test: end of block Executed by:
| 40117 | ||||||||||||||||||||||||||||||||||||
913 | return (val1); executed 21168584 times by 1 test: return (val1); Executed by:
| 21168584 | ||||||||||||||||||||||||||||||||||||
914 | } | - | ||||||||||||||||||||||||||||||||||||
915 | - | |||||||||||||||||||||||||||||||||||||
916 | static intmax_t | - | ||||||||||||||||||||||||||||||||||||
917 | ipow (base, exp) | - | ||||||||||||||||||||||||||||||||||||
918 | intmax_t base, exp; | - | ||||||||||||||||||||||||||||||||||||
919 | { | - | ||||||||||||||||||||||||||||||||||||
920 | intmax_t result; | - | ||||||||||||||||||||||||||||||||||||
921 | - | |||||||||||||||||||||||||||||||||||||
922 | result = 1; | - | ||||||||||||||||||||||||||||||||||||
923 | while (exp)
| 27-126 | ||||||||||||||||||||||||||||||||||||
924 | { | - | ||||||||||||||||||||||||||||||||||||
925 | if (exp & 1)
| 24-102 | ||||||||||||||||||||||||||||||||||||
926 | result *= base; executed 102 times by 1 test: result *= base; Executed by:
| 102 | ||||||||||||||||||||||||||||||||||||
927 | exp >>= 1; | - | ||||||||||||||||||||||||||||||||||||
928 | base *= base; | - | ||||||||||||||||||||||||||||||||||||
929 | } executed 126 times by 1 test: end of block Executed by:
| 126 | ||||||||||||||||||||||||||||||||||||
930 | return result; executed 27 times by 1 test: return result; Executed by:
| 27 | ||||||||||||||||||||||||||||||||||||
931 | } | - | ||||||||||||||||||||||||||||||||||||
932 | - | |||||||||||||||||||||||||||||||||||||
933 | static intmax_t | - | ||||||||||||||||||||||||||||||||||||
934 | exppower () | - | ||||||||||||||||||||||||||||||||||||
935 | { | - | ||||||||||||||||||||||||||||||||||||
936 | register intmax_t val1, val2, c; | - | ||||||||||||||||||||||||||||||||||||
937 | - | |||||||||||||||||||||||||||||||||||||
938 | val1 = exp1 (); | - | ||||||||||||||||||||||||||||||||||||
939 | while (curtok == POWER)
| 33-21208746 | ||||||||||||||||||||||||||||||||||||
940 | { | - | ||||||||||||||||||||||||||||||||||||
941 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
942 | val2 = exppower (); /* exponentiation is right-associative */ | - | ||||||||||||||||||||||||||||||||||||
943 | lasttok = NUM; | - | ||||||||||||||||||||||||||||||||||||
944 | if (val2 == 0)
| 6-27 | ||||||||||||||||||||||||||||||||||||
945 | return (1); executed 6 times by 1 test: return (1); Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||
946 | if (val2 < 0)
| 0-27 | ||||||||||||||||||||||||||||||||||||
947 | evalerror (_("exponent less than 0")); never executed: evalerror ( dcgettext (((void *)0), "exponent less than 0" , 5) ); | 0 | ||||||||||||||||||||||||||||||||||||
948 | val1 = ipow (val1, val2); | - | ||||||||||||||||||||||||||||||||||||
949 | } executed 27 times by 1 test: end of block Executed by:
| 27 | ||||||||||||||||||||||||||||||||||||
950 | return (val1); executed 21208746 times by 1 test: return (val1); Executed by:
| 21208746 | ||||||||||||||||||||||||||||||||||||
951 | } | - | ||||||||||||||||||||||||||||||||||||
952 | - | |||||||||||||||||||||||||||||||||||||
953 | static intmax_t | - | ||||||||||||||||||||||||||||||||||||
954 | exp1 () | - | ||||||||||||||||||||||||||||||||||||
955 | { | - | ||||||||||||||||||||||||||||||||||||
956 | register intmax_t val; | - | ||||||||||||||||||||||||||||||||||||
957 | - | |||||||||||||||||||||||||||||||||||||
958 | if (curtok == NOT)
| 15-21238917 | ||||||||||||||||||||||||||||||||||||
959 | { | - | ||||||||||||||||||||||||||||||||||||
960 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
961 | val = !exp1 (); | - | ||||||||||||||||||||||||||||||||||||
962 | lasttok = NUM; | - | ||||||||||||||||||||||||||||||||||||
963 | } executed 15 times by 1 test: end of block Executed by:
| 15 | ||||||||||||||||||||||||||||||||||||
964 | else if (curtok == BNOT)
| 18-21238899 | ||||||||||||||||||||||||||||||||||||
965 | { | - | ||||||||||||||||||||||||||||||||||||
966 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
967 | val = ~exp1 (); | - | ||||||||||||||||||||||||||||||||||||
968 | lasttok = NUM; | - | ||||||||||||||||||||||||||||||||||||
969 | } executed 17 times by 1 test: end of block Executed by:
| 17 | ||||||||||||||||||||||||||||||||||||
970 | else if (curtok == MINUS)
| 30027-21208872 | ||||||||||||||||||||||||||||||||||||
971 | { | - | ||||||||||||||||||||||||||||||||||||
972 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
973 | val = - exp1 (); | - | ||||||||||||||||||||||||||||||||||||
974 | lasttok = NUM; | - | ||||||||||||||||||||||||||||||||||||
975 | } executed 30015 times by 1 test: end of block Executed by:
| 30015 | ||||||||||||||||||||||||||||||||||||
976 | else if (curtok == PLUS)
| 79-21208793 | ||||||||||||||||||||||||||||||||||||
977 | { | - | ||||||||||||||||||||||||||||||||||||
978 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
979 | val = exp1 (); | - | ||||||||||||||||||||||||||||||||||||
980 | lasttok = NUM; | - | ||||||||||||||||||||||||||||||||||||
981 | } executed 73 times by 1 test: end of block Executed by:
| 73 | ||||||||||||||||||||||||||||||||||||
982 | else | - | ||||||||||||||||||||||||||||||||||||
983 | val = exp0 (); executed 21208793 times by 1 test: val = exp0 (); Executed by:
| 21208793 | ||||||||||||||||||||||||||||||||||||
984 | - | |||||||||||||||||||||||||||||||||||||
985 | return (val); executed 21238872 times by 1 test: return (val); Executed by:
| 21238872 | ||||||||||||||||||||||||||||||||||||
986 | } | - | ||||||||||||||||||||||||||||||||||||
987 | - | |||||||||||||||||||||||||||||||||||||
988 | static intmax_t | - | ||||||||||||||||||||||||||||||||||||
989 | exp0 () | - | ||||||||||||||||||||||||||||||||||||
990 | { | - | ||||||||||||||||||||||||||||||||||||
991 | register intmax_t val = 0, v2; | - | ||||||||||||||||||||||||||||||||||||
992 | char *vincdec; | - | ||||||||||||||||||||||||||||||||||||
993 | int stok; | - | ||||||||||||||||||||||||||||||||||||
994 | EXPR_CONTEXT ec; | - | ||||||||||||||||||||||||||||||||||||
995 | - | |||||||||||||||||||||||||||||||||||||
996 | /* XXX - might need additional logic here to decide whether or not | - | ||||||||||||||||||||||||||||||||||||
997 | pre-increment or pre-decrement is legal at this point. */ | - | ||||||||||||||||||||||||||||||||||||
998 | if (curtok == PREINC || curtok == PREDEC)
| 16-21208761 | ||||||||||||||||||||||||||||||||||||
999 | { | - | ||||||||||||||||||||||||||||||||||||
1000 | stok = lasttok = curtok; | - | ||||||||||||||||||||||||||||||||||||
1001 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
1002 | if (curtok != STR)
| 0-48 | ||||||||||||||||||||||||||||||||||||
1003 | /* readtok() catches this */ | - | ||||||||||||||||||||||||||||||||||||
1004 | evalerror (_("identifier expected after pre-increment or pre-decrement")); never executed: evalerror ( dcgettext (((void *)0), "identifier expected after pre-increment or pre-decrement" , 5) ); | 0 | ||||||||||||||||||||||||||||||||||||
1005 | - | |||||||||||||||||||||||||||||||||||||
1006 | v2 = tokval + ((stok == PREINC) ? 1 : -1);
| 16-32 | ||||||||||||||||||||||||||||||||||||
1007 | vincdec = itos (v2); | - | ||||||||||||||||||||||||||||||||||||
1008 | if (noeval == 0)
| 0-48 | ||||||||||||||||||||||||||||||||||||
1009 | { | - | ||||||||||||||||||||||||||||||||||||
1010 | #if defined (ARRAY_VARS) | - | ||||||||||||||||||||||||||||||||||||
1011 | if (curlval.ind != -1)
| 3-45 | ||||||||||||||||||||||||||||||||||||
1012 | expr_bind_array_element (curlval.tokstr, curlval.ind, vincdec); executed 3 times by 1 test: expr_bind_array_element (curlval.tokstr, curlval.ind, vincdec); Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||
1013 | else | - | ||||||||||||||||||||||||||||||||||||
1014 | #endif | - | ||||||||||||||||||||||||||||||||||||
1015 | expr_bind_variable (tokstr, vincdec); executed 45 times by 1 test: expr_bind_variable (tokstr, vincdec); Executed by:
| 45 | ||||||||||||||||||||||||||||||||||||
1016 | } | - | ||||||||||||||||||||||||||||||||||||
1017 | free (vincdec); | - | ||||||||||||||||||||||||||||||||||||
1018 | val = v2; | - | ||||||||||||||||||||||||||||||||||||
1019 | - | |||||||||||||||||||||||||||||||||||||
1020 | curtok = NUM; /* make sure --x=7 is flagged as an error */ | - | ||||||||||||||||||||||||||||||||||||
1021 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
1022 | } executed 48 times by 1 test: end of block Executed by:
| 48 | ||||||||||||||||||||||||||||||||||||
1023 | else if (curtok == LPAR)
| 20615-21188130 | ||||||||||||||||||||||||||||||||||||
1024 | { | - | ||||||||||||||||||||||||||||||||||||
1025 | /* XXX - save curlval here? Or entire expression context? */ | - | ||||||||||||||||||||||||||||||||||||
1026 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
1027 | val = EXP_HIGHEST (); | - | ||||||||||||||||||||||||||||||||||||
1028 | - | |||||||||||||||||||||||||||||||||||||
1029 | if (curtok != RPAR) /* ( */
| 8-20601 | ||||||||||||||||||||||||||||||||||||
1030 | evalerror (_("missing `)'")); executed 8 times by 1 test: evalerror ( dcgettext (((void *)0), "missing `)'" , 5) ); Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||
1031 | - | |||||||||||||||||||||||||||||||||||||
1032 | /* Skip over closing paren. */ | - | ||||||||||||||||||||||||||||||||||||
1033 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
1034 | } executed 20601 times by 1 test: end of block Executed by:
| 20601 | ||||||||||||||||||||||||||||||||||||
1035 | else if ((curtok == NUM) || (curtok == STR))
| 26-13898301 | ||||||||||||||||||||||||||||||||||||
1036 | { | - | ||||||||||||||||||||||||||||||||||||
1037 | val = tokval; | - | ||||||||||||||||||||||||||||||||||||
1038 | if (curtok == STR)
| 7289803-13898301 | ||||||||||||||||||||||||||||||||||||
1039 | { | - | ||||||||||||||||||||||||||||||||||||
1040 | SAVETOK (&ec); | - | ||||||||||||||||||||||||||||||||||||
1041 | tokstr = (char *)NULL; /* keep it from being freed */ | - | ||||||||||||||||||||||||||||||||||||
1042 | noeval = 1; | - | ||||||||||||||||||||||||||||||||||||
1043 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
1044 | stok = curtok; | - | ||||||||||||||||||||||||||||||||||||
1045 | - | |||||||||||||||||||||||||||||||||||||
1046 | /* post-increment or post-decrement */ | - | ||||||||||||||||||||||||||||||||||||
1047 | if (stok == POSTINC || stok == POSTDEC)
| 48332-7241471 | ||||||||||||||||||||||||||||||||||||
1048 | { | - | ||||||||||||||||||||||||||||||||||||
1049 | /* restore certain portions of EC */ | - | ||||||||||||||||||||||||||||||||||||
1050 | tokstr = ec.tokstr; | - | ||||||||||||||||||||||||||||||||||||
1051 | noeval = ec.noeval; | - | ||||||||||||||||||||||||||||||||||||
1052 | curlval = ec.lval; | - | ||||||||||||||||||||||||||||||||||||
1053 | lasttok = STR; /* ec.curtok */ | - | ||||||||||||||||||||||||||||||||||||
1054 | - | |||||||||||||||||||||||||||||||||||||
1055 | v2 = val + ((stok == POSTINC) ? 1 : -1);
| 48332-661983 | ||||||||||||||||||||||||||||||||||||
1056 | vincdec = itos (v2); | - | ||||||||||||||||||||||||||||||||||||
1057 | if (noeval == 0)
| 17688-692627 | ||||||||||||||||||||||||||||||||||||
1058 | { | - | ||||||||||||||||||||||||||||||||||||
1059 | #if defined (ARRAY_VARS) | - | ||||||||||||||||||||||||||||||||||||
1060 | if (curlval.ind != -1)
| 10003-682624 | ||||||||||||||||||||||||||||||||||||
1061 | expr_bind_array_element (curlval.tokstr, curlval.ind, vincdec); executed 10003 times by 1 test: expr_bind_array_element (curlval.tokstr, curlval.ind, vincdec); Executed by:
| 10003 | ||||||||||||||||||||||||||||||||||||
1062 | else | - | ||||||||||||||||||||||||||||||||||||
1063 | #endif | - | ||||||||||||||||||||||||||||||||||||
1064 | expr_bind_variable (tokstr, vincdec); executed 682624 times by 1 test: expr_bind_variable (tokstr, vincdec); Executed by:
| 682624 | ||||||||||||||||||||||||||||||||||||
1065 | } | - | ||||||||||||||||||||||||||||||||||||
1066 | free (vincdec); | - | ||||||||||||||||||||||||||||||||||||
1067 | curtok = NUM; /* make sure x++=7 is flagged as an error */ | - | ||||||||||||||||||||||||||||||||||||
1068 | } executed 710314 times by 1 test: end of block Executed by:
| 710314 | ||||||||||||||||||||||||||||||||||||
1069 | else | - | ||||||||||||||||||||||||||||||||||||
1070 | { | - | ||||||||||||||||||||||||||||||||||||
1071 | /* XXX - watch out for pointer aliasing issues here */ | - | ||||||||||||||||||||||||||||||||||||
1072 | if (stok == STR) /* free new tokstr before old one is restored */
| 9-6579479 | ||||||||||||||||||||||||||||||||||||
1073 | FREE (tokstr); executed 9 times by 1 test: sh_xfree((tokstr), "expr.c", 1073); Executed by:
executed 9 times by 1 test: end of block Executed by:
| 0-9 | ||||||||||||||||||||||||||||||||||||
1074 | RESTORETOK (&ec); | - | ||||||||||||||||||||||||||||||||||||
1075 | } executed 6579488 times by 1 test: end of block Executed by:
| 6579488 | ||||||||||||||||||||||||||||||||||||
1076 | } | - | ||||||||||||||||||||||||||||||||||||
1077 | - | |||||||||||||||||||||||||||||||||||||
1078 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
1079 | } executed 21188103 times by 1 test: end of block Executed by:
| 21188103 | ||||||||||||||||||||||||||||||||||||
1080 | else | - | ||||||||||||||||||||||||||||||||||||
1081 | evalerror (_("syntax error: operand expected")); executed 26 times by 1 test: evalerror ( dcgettext (((void *)0), "syntax error: operand expected" , 5) ); Executed by:
| 26 | ||||||||||||||||||||||||||||||||||||
1082 | - | |||||||||||||||||||||||||||||||||||||
1083 | return (val); executed 21208752 times by 1 test: return (val); Executed by:
| 21208752 | ||||||||||||||||||||||||||||||||||||
1084 | } | - | ||||||||||||||||||||||||||||||||||||
1085 | - | |||||||||||||||||||||||||||||||||||||
1086 | static void | - | ||||||||||||||||||||||||||||||||||||
1087 | init_lvalue (lv) | - | ||||||||||||||||||||||||||||||||||||
1088 | struct lvalue *lv; | - | ||||||||||||||||||||||||||||||||||||
1089 | { | - | ||||||||||||||||||||||||||||||||||||
1090 | lv->tokstr = 0; | - | ||||||||||||||||||||||||||||||||||||
1091 | lv->tokvar = 0; | - | ||||||||||||||||||||||||||||||||||||
1092 | lv->tokval = lv->ind = -1; | - | ||||||||||||||||||||||||||||||||||||
1093 | } executed 21040922 times by 1 test: end of block Executed by:
| 21040922 | ||||||||||||||||||||||||||||||||||||
1094 | - | |||||||||||||||||||||||||||||||||||||
1095 | static struct lvalue * | - | ||||||||||||||||||||||||||||||||||||
1096 | alloc_lvalue () | - | ||||||||||||||||||||||||||||||||||||
1097 | { | - | ||||||||||||||||||||||||||||||||||||
1098 | struct lvalue *lv; | - | ||||||||||||||||||||||||||||||||||||
1099 | - | |||||||||||||||||||||||||||||||||||||
1100 | lv = xmalloc (sizeof (struct lvalue)); | - | ||||||||||||||||||||||||||||||||||||
1101 | init_lvalue (lv); | - | ||||||||||||||||||||||||||||||||||||
1102 | return (lv); never executed: return (lv); | 0 | ||||||||||||||||||||||||||||||||||||
1103 | } | - | ||||||||||||||||||||||||||||||||||||
1104 | - | |||||||||||||||||||||||||||||||||||||
1105 | static void | - | ||||||||||||||||||||||||||||||||||||
1106 | free_lvalue (lv) | - | ||||||||||||||||||||||||||||||||||||
1107 | struct lvalue *lv; | - | ||||||||||||||||||||||||||||||||||||
1108 | { | - | ||||||||||||||||||||||||||||||||||||
1109 | free (lv); /* should be inlined */ | - | ||||||||||||||||||||||||||||||||||||
1110 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
1111 | - | |||||||||||||||||||||||||||||||||||||
1112 | static intmax_t | - | ||||||||||||||||||||||||||||||||||||
1113 | expr_streval (tok, e, lvalue) | - | ||||||||||||||||||||||||||||||||||||
1114 | char *tok; | - | ||||||||||||||||||||||||||||||||||||
1115 | int e; | - | ||||||||||||||||||||||||||||||||||||
1116 | struct lvalue *lvalue; | - | ||||||||||||||||||||||||||||||||||||
1117 | { | - | ||||||||||||||||||||||||||||||||||||
1118 | SHELL_VAR *v; | - | ||||||||||||||||||||||||||||||||||||
1119 | char *value; | - | ||||||||||||||||||||||||||||||||||||
1120 | intmax_t tval; | - | ||||||||||||||||||||||||||||||||||||
1121 | int initial_depth; | - | ||||||||||||||||||||||||||||||||||||
1122 | #if defined (ARRAY_VARS) | - | ||||||||||||||||||||||||||||||||||||
1123 | arrayind_t ind; | - | ||||||||||||||||||||||||||||||||||||
1124 | int tflag, aflag; | - | ||||||||||||||||||||||||||||||||||||
1125 | #endif | - | ||||||||||||||||||||||||||||||||||||
1126 | - | |||||||||||||||||||||||||||||||||||||
1127 | /*itrace("expr_streval: %s: noeval = %d expanded=%d", tok, noeval, already_expanded);*/ | - | ||||||||||||||||||||||||||||||||||||
1128 | /* If we are suppressing evaluation, just short-circuit here instead of | - | ||||||||||||||||||||||||||||||||||||
1129 | going through the rest of the evaluator. */ | - | ||||||||||||||||||||||||||||||||||||
1130 | if (noeval)
| 35477-7251807 | ||||||||||||||||||||||||||||||||||||
1131 | return (0); executed 35477 times by 1 test: return (0); Executed by:
| 35477 | ||||||||||||||||||||||||||||||||||||
1132 | - | |||||||||||||||||||||||||||||||||||||
1133 | initial_depth = expr_depth; | - | ||||||||||||||||||||||||||||||||||||
1134 | - | |||||||||||||||||||||||||||||||||||||
1135 | #if defined (ARRAY_VARS) | - | ||||||||||||||||||||||||||||||||||||
1136 | tflag = assoc_expand_once && already_expanded; /* for a start */
| 0-7251800 | ||||||||||||||||||||||||||||||||||||
1137 | #endif | - | ||||||||||||||||||||||||||||||||||||
1138 | - | |||||||||||||||||||||||||||||||||||||
1139 | /* [[[[[ */ | - | ||||||||||||||||||||||||||||||||||||
1140 | #if defined (ARRAY_VARS) | - | ||||||||||||||||||||||||||||||||||||
1141 | aflag = (tflag) ? AV_NOEXPAND : 0;
| 7-7251800 | ||||||||||||||||||||||||||||||||||||
1142 | v = (e == ']') ? array_variable_part (tok, tflag, (char **)0, (int *)0) : find_variable (tok);
| 10105-7241702 | ||||||||||||||||||||||||||||||||||||
1143 | #else | - | ||||||||||||||||||||||||||||||||||||
1144 | v = find_variable (tok); | - | ||||||||||||||||||||||||||||||||||||
1145 | #endif | - | ||||||||||||||||||||||||||||||||||||
1146 | - | |||||||||||||||||||||||||||||||||||||
1147 | if ((v == 0 || invisible_p (v)) && unbound_vars_is_error)
| 0-7251702 | ||||||||||||||||||||||||||||||||||||
1148 | { | - | ||||||||||||||||||||||||||||||||||||
1149 | #if defined (ARRAY_VARS) | - | ||||||||||||||||||||||||||||||||||||
1150 | value = (e == ']') ? array_variable_name (tok, tflag, (char **)0, (int *)0) : tok;
| 0 | ||||||||||||||||||||||||||||||||||||
1151 | #else | - | ||||||||||||||||||||||||||||||||||||
1152 | value = tok; | - | ||||||||||||||||||||||||||||||||||||
1153 | #endif | - | ||||||||||||||||||||||||||||||||||||
1154 | - | |||||||||||||||||||||||||||||||||||||
1155 | last_command_exit_value = EXECUTION_FAILURE; | - | ||||||||||||||||||||||||||||||||||||
1156 | err_unboundvar (value); | - | ||||||||||||||||||||||||||||||||||||
1157 | - | |||||||||||||||||||||||||||||||||||||
1158 | #if defined (ARRAY_VARS) | - | ||||||||||||||||||||||||||||||||||||
1159 | if (e == ']')
| 0 | ||||||||||||||||||||||||||||||||||||
1160 | FREE (value); /* array_variable_name returns new memory */ never executed: sh_xfree((value), "expr.c", 1160); never executed: end of block
| 0 | ||||||||||||||||||||||||||||||||||||
1161 | #endif | - | ||||||||||||||||||||||||||||||||||||
1162 | - | |||||||||||||||||||||||||||||||||||||
1163 | if (no_longjmp_on_fatal_error && interactive_shell)
| 0 | ||||||||||||||||||||||||||||||||||||
1164 | sh_longjmp (evalbuf, 1); never executed: siglongjmp((evalbuf), (1)); | 0 | ||||||||||||||||||||||||||||||||||||
1165 | - | |||||||||||||||||||||||||||||||||||||
1166 | if (interactive_shell)
| 0 | ||||||||||||||||||||||||||||||||||||
1167 | { | - | ||||||||||||||||||||||||||||||||||||
1168 | expr_unwind (); | - | ||||||||||||||||||||||||||||||||||||
1169 | top_level_cleanup (); | - | ||||||||||||||||||||||||||||||||||||
1170 | jump_to_top_level (DISCARD); | - | ||||||||||||||||||||||||||||||||||||
1171 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
1172 | else | - | ||||||||||||||||||||||||||||||||||||
1173 | jump_to_top_level (FORCE_EOF); never executed: jump_to_top_level (1); | 0 | ||||||||||||||||||||||||||||||||||||
1174 | } | - | ||||||||||||||||||||||||||||||||||||
1175 | - | |||||||||||||||||||||||||||||||||||||
1176 | #if defined (ARRAY_VARS) | - | ||||||||||||||||||||||||||||||||||||
1177 | ind = -1; | - | ||||||||||||||||||||||||||||||||||||
1178 | /* If the second argument to get_array_value doesn't include AV_ALLOWALL, | - | ||||||||||||||||||||||||||||||||||||
1179 | we don't allow references like array[@]. In this case, get_array_value | - | ||||||||||||||||||||||||||||||||||||
1180 | is just like get_variable_value in that it does not return newly-allocated | - | ||||||||||||||||||||||||||||||||||||
1181 | memory or quote the results. AFLAG is set above and is either AV_NOEXPAND | - | ||||||||||||||||||||||||||||||||||||
1182 | or 0. */ | - | ||||||||||||||||||||||||||||||||||||
1183 | value = (e == ']') ? get_array_value (tok, aflag, (int *)NULL, &ind) : get_variable_value (v);
| 10105-7241702 | ||||||||||||||||||||||||||||||||||||
1184 | #else | - | ||||||||||||||||||||||||||||||||||||
1185 | value = get_variable_value (v); | - | ||||||||||||||||||||||||||||||||||||
1186 | #endif | - | ||||||||||||||||||||||||||||||||||||
1187 | - | |||||||||||||||||||||||||||||||||||||
1188 | if (expr_depth < initial_depth)
| 0-7251803 | ||||||||||||||||||||||||||||||||||||
1189 | { | - | ||||||||||||||||||||||||||||||||||||
1190 | if (no_longjmp_on_fatal_error && interactive_shell)
| 0 | ||||||||||||||||||||||||||||||||||||
1191 | sh_longjmp (evalbuf, 1); never executed: siglongjmp((evalbuf), (1)); | 0 | ||||||||||||||||||||||||||||||||||||
1192 | return (0); never executed: return (0); | 0 | ||||||||||||||||||||||||||||||||||||
1193 | } | - | ||||||||||||||||||||||||||||||||||||
1194 | - | |||||||||||||||||||||||||||||||||||||
1195 | tval = (value && *value) ? subexpr (value) : 0;
| 0-7251666 | ||||||||||||||||||||||||||||||||||||
1196 | - | |||||||||||||||||||||||||||||||||||||
1197 | if (lvalue)
| 0-7251797 | ||||||||||||||||||||||||||||||||||||
1198 | { | - | ||||||||||||||||||||||||||||||||||||
1199 | lvalue->tokstr = tok; /* XXX */ | - | ||||||||||||||||||||||||||||||||||||
1200 | lvalue->tokval = tval; | - | ||||||||||||||||||||||||||||||||||||
1201 | lvalue->tokvar = v; /* XXX */ | - | ||||||||||||||||||||||||||||||||||||
1202 | #if defined (ARRAY_VARS) | - | ||||||||||||||||||||||||||||||||||||
1203 | lvalue->ind = ind; | - | ||||||||||||||||||||||||||||||||||||
1204 | #else | - | ||||||||||||||||||||||||||||||||||||
1205 | lvalue->ind = -1; | - | ||||||||||||||||||||||||||||||||||||
1206 | #endif | - | ||||||||||||||||||||||||||||||||||||
1207 | } executed 7251797 times by 1 test: end of block Executed by:
| 7251797 | ||||||||||||||||||||||||||||||||||||
1208 | - | |||||||||||||||||||||||||||||||||||||
1209 | return (tval); executed 7251797 times by 1 test: return (tval); Executed by:
| 7251797 | ||||||||||||||||||||||||||||||||||||
1210 | } | - | ||||||||||||||||||||||||||||||||||||
1211 | - | |||||||||||||||||||||||||||||||||||||
1212 | static int | - | ||||||||||||||||||||||||||||||||||||
1213 | _is_multiop (c) | - | ||||||||||||||||||||||||||||||||||||
1214 | int c; | - | ||||||||||||||||||||||||||||||||||||
1215 | { | - | ||||||||||||||||||||||||||||||||||||
1216 | switch (c) | - | ||||||||||||||||||||||||||||||||||||
1217 | { | - | ||||||||||||||||||||||||||||||||||||
1218 | case EQEQ: never executed: case 1: | 0 | ||||||||||||||||||||||||||||||||||||
1219 | case NEQ: never executed: case 2: | 0 | ||||||||||||||||||||||||||||||||||||
1220 | case LEQ: never executed: case 3: | 0 | ||||||||||||||||||||||||||||||||||||
1221 | case GEQ: never executed: case 4: | 0 | ||||||||||||||||||||||||||||||||||||
1222 | case LAND: never executed: case 7: | 0 | ||||||||||||||||||||||||||||||||||||
1223 | case LOR: never executed: case 8: | 0 | ||||||||||||||||||||||||||||||||||||
1224 | case LSH: never executed: case 9: | 0 | ||||||||||||||||||||||||||||||||||||
1225 | case RSH: never executed: case 10: | 0 | ||||||||||||||||||||||||||||||||||||
1226 | case OP_ASSIGN: executed 16 times by 1 test: case 11: Executed by:
| 16 | ||||||||||||||||||||||||||||||||||||
1227 | case COND: never executed: case 12: | 0 | ||||||||||||||||||||||||||||||||||||
1228 | case POWER: never executed: case 13: | 0 | ||||||||||||||||||||||||||||||||||||
1229 | case PREINC: never executed: case 14: | 0 | ||||||||||||||||||||||||||||||||||||
1230 | case PREDEC: never executed: case 15: | 0 | ||||||||||||||||||||||||||||||||||||
1231 | case POSTINC: never executed: case 16: | 0 | ||||||||||||||||||||||||||||||||||||
1232 | case POSTDEC: never executed: case 17: | 0 | ||||||||||||||||||||||||||||||||||||
1233 | return 1; executed 16 times by 1 test: return 1; Executed by:
| 16 | ||||||||||||||||||||||||||||||||||||
1234 | default: executed 1 time by 1 test: default: Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||
1235 | return 0; executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||
1236 | } | - | ||||||||||||||||||||||||||||||||||||
1237 | } | - | ||||||||||||||||||||||||||||||||||||
1238 | - | |||||||||||||||||||||||||||||||||||||
1239 | static int | - | ||||||||||||||||||||||||||||||||||||
1240 | _is_arithop (c) | - | ||||||||||||||||||||||||||||||||||||
1241 | int c; | - | ||||||||||||||||||||||||||||||||||||
1242 | { | - | ||||||||||||||||||||||||||||||||||||
1243 | switch (c) | - | ||||||||||||||||||||||||||||||||||||
1244 | { | - | ||||||||||||||||||||||||||||||||||||
1245 | case EQ: executed 7860 times by 1 test: case '=': Executed by:
| 7860 | ||||||||||||||||||||||||||||||||||||
1246 | case GT: executed 6820 times by 1 test: case '>': Executed by:
| 6820 | ||||||||||||||||||||||||||||||||||||
1247 | case LT: executed 49615 times by 1 test: case '<': Executed by:
| 49615 | ||||||||||||||||||||||||||||||||||||
1248 | case PLUS: executed 31403 times by 1 test: case '+': Executed by:
| 31403 | ||||||||||||||||||||||||||||||||||||
1249 | case MINUS: executed 30325 times by 1 test: case '-': Executed by:
| 30325 | ||||||||||||||||||||||||||||||||||||
1250 | case MUL: executed 29 times by 1 test: case '*': Executed by:
| 29 | ||||||||||||||||||||||||||||||||||||
1251 | case DIV: executed 62 times by 1 test: case '/': Executed by:
| 62 | ||||||||||||||||||||||||||||||||||||
1252 | case MOD: executed 100077 times by 1 test: case '%': Executed by:
| 100077 | ||||||||||||||||||||||||||||||||||||
1253 | case NOT: executed 15 times by 1 test: case '!': Executed by:
| 15 | ||||||||||||||||||||||||||||||||||||
1254 | case LPAR: executed 20615 times by 1 test: case '(': Executed by:
| 20615 | ||||||||||||||||||||||||||||||||||||
1255 | case RPAR: executed 20657 times by 1 test: case ')': Executed by:
| 20657 | ||||||||||||||||||||||||||||||||||||
1256 | case BAND: executed 58 times by 1 test: case '&': Executed by:
| 58 | ||||||||||||||||||||||||||||||||||||
1257 | case BOR: executed 65 times by 1 test: case '|': Executed by:
| 65 | ||||||||||||||||||||||||||||||||||||
1258 | case BXOR: executed 8 times by 1 test: case '^': Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||
1259 | case BNOT: executed 18 times by 1 test: case '~': Executed by:
| 18 | ||||||||||||||||||||||||||||||||||||
1260 | return 1; /* operator tokens */ executed 267627 times by 1 test: return 1; Executed by:
| 267627 | ||||||||||||||||||||||||||||||||||||
1261 | case QUES: executed 360 times by 1 test: case '?': Executed by:
| 360 | ||||||||||||||||||||||||||||||||||||
1262 | case COL: executed 238 times by 1 test: case ':': Executed by:
| 238 | ||||||||||||||||||||||||||||||||||||
1263 | case COMMA: executed 39627 times by 1 test: case ',': Executed by:
| 39627 | ||||||||||||||||||||||||||||||||||||
1264 | return 1; /* questionable */ executed 40225 times by 1 test: return 1; Executed by:
| 40225 | ||||||||||||||||||||||||||||||||||||
1265 | default: executed 65 times by 1 test: default: Executed by:
| 65 | ||||||||||||||||||||||||||||||||||||
1266 | return 0; /* anything else is invalid */ executed 65 times by 1 test: return 0; Executed by:
| 65 | ||||||||||||||||||||||||||||||||||||
1267 | } | - | ||||||||||||||||||||||||||||||||||||
1268 | } | - | ||||||||||||||||||||||||||||||||||||
1269 | - | |||||||||||||||||||||||||||||||||||||
1270 | /* Lexical analyzer/token reader for the expression evaluator. Reads the | - | ||||||||||||||||||||||||||||||||||||
1271 | next token and puts its value into curtok, while advancing past it. | - | ||||||||||||||||||||||||||||||||||||
1272 | Updates value of tp. May also set tokval (for number) or tokstr (for | - | ||||||||||||||||||||||||||||||||||||
1273 | string). */ | - | ||||||||||||||||||||||||||||||||||||
1274 | static void | - | ||||||||||||||||||||||||||||||||||||
1275 | readtok () | - | ||||||||||||||||||||||||||||||||||||
1276 | { | - | ||||||||||||||||||||||||||||||||||||
1277 | register char *cp, *xp; | - | ||||||||||||||||||||||||||||||||||||
1278 | register unsigned char c, c1; | - | ||||||||||||||||||||||||||||||||||||
1279 | register int e; | - | ||||||||||||||||||||||||||||||||||||
1280 | struct lvalue lval; | - | ||||||||||||||||||||||||||||||||||||
1281 | - | |||||||||||||||||||||||||||||||||||||
1282 | /* Skip leading whitespace. */ | - | ||||||||||||||||||||||||||||||||||||
1283 | cp = tp; | - | ||||||||||||||||||||||||||||||||||||
1284 | c = e = 0; | - | ||||||||||||||||||||||||||||||||||||
1285 | while (cp && (c = *cp) && (cr_whitespace (c)))
| 0-57559084 | ||||||||||||||||||||||||||||||||||||
1286 | cp++; executed 531554 times by 1 test: cp++; Executed by:
| 531554 | ||||||||||||||||||||||||||||||||||||
1287 | - | |||||||||||||||||||||||||||||||||||||
1288 | if (c)
| 14548177-42479353 | ||||||||||||||||||||||||||||||||||||
1289 | cp++; executed 42479353 times by 1 test: cp++; Executed by:
| 42479353 | ||||||||||||||||||||||||||||||||||||
1290 | - | |||||||||||||||||||||||||||||||||||||
1291 | if (c == '\0')
| 14548177-42479353 | ||||||||||||||||||||||||||||||||||||
1292 | { | - | ||||||||||||||||||||||||||||||||||||
1293 | lasttok = curtok; | - | ||||||||||||||||||||||||||||||||||||
1294 | curtok = 0; | - | ||||||||||||||||||||||||||||||||||||
1295 | tp = cp; | - | ||||||||||||||||||||||||||||||||||||
1296 | return; executed 14548177 times by 1 test: return; Executed by:
| 14548177 | ||||||||||||||||||||||||||||||||||||
1297 | } | - | ||||||||||||||||||||||||||||||||||||
1298 | lasttp = tp = cp - 1; | - | ||||||||||||||||||||||||||||||||||||
1299 | - | |||||||||||||||||||||||||||||||||||||
1300 | if (legal_variable_starter (c))
| 96-35189556 | ||||||||||||||||||||||||||||||||||||
1301 | { | - | ||||||||||||||||||||||||||||||||||||
1302 | /* variable names not preceded with a dollar sign are shell variables. */ | - | ||||||||||||||||||||||||||||||||||||
1303 | char *savecp; | - | ||||||||||||||||||||||||||||||||||||
1304 | EXPR_CONTEXT ec; | - | ||||||||||||||||||||||||||||||||||||
1305 | int peektok; | - | ||||||||||||||||||||||||||||||||||||
1306 | - | |||||||||||||||||||||||||||||||||||||
1307 | while (legal_variable_char (c))
| 2360-39686936 | ||||||||||||||||||||||||||||||||||||
1308 | c = *cp++; executed 39689296 times by 1 test: c = *cp++; Executed by:
| 39689296 | ||||||||||||||||||||||||||||||||||||
1309 | - | |||||||||||||||||||||||||||||||||||||
1310 | c = *--cp; | - | ||||||||||||||||||||||||||||||||||||
1311 | - | |||||||||||||||||||||||||||||||||||||
1312 | #if defined (ARRAY_VARS) | - | ||||||||||||||||||||||||||||||||||||
1313 | if (c == '[')
| 10154-7279739 | ||||||||||||||||||||||||||||||||||||
1314 | { | - | ||||||||||||||||||||||||||||||||||||
1315 | e = skipsubscript (cp, 0, 1); /* XXX - arg 3 was 0 */ | - | ||||||||||||||||||||||||||||||||||||
1316 | if (cp[e] == ']')
| 0-10154 | ||||||||||||||||||||||||||||||||||||
1317 | { | - | ||||||||||||||||||||||||||||||||||||
1318 | cp += e + 1; | - | ||||||||||||||||||||||||||||||||||||
1319 | c = *cp; | - | ||||||||||||||||||||||||||||||||||||
1320 | e = ']'; | - | ||||||||||||||||||||||||||||||||||||
1321 | } executed 10154 times by 1 test: end of block Executed by:
| 10154 | ||||||||||||||||||||||||||||||||||||
1322 | else | - | ||||||||||||||||||||||||||||||||||||
1323 | evalerror (bash_badsub_errmsg); never executed: evalerror (bash_badsub_errmsg); | 0 | ||||||||||||||||||||||||||||||||||||
1324 | } | - | ||||||||||||||||||||||||||||||||||||
1325 | #endif /* ARRAY_VARS */ | - | ||||||||||||||||||||||||||||||||||||
1326 | - | |||||||||||||||||||||||||||||||||||||
1327 | *cp = '\0'; | - | ||||||||||||||||||||||||||||||||||||
1328 | /* XXX - watch out for pointer aliasing issues here */ | - | ||||||||||||||||||||||||||||||||||||
1329 | if (curlval.tokstr && curlval.tokstr == tokstr)
| 9-7245205 | ||||||||||||||||||||||||||||||||||||
1330 | init_lvalue (&curlval); executed 44679 times by 1 test: init_lvalue (&curlval); Executed by:
| 44679 | ||||||||||||||||||||||||||||||||||||
1331 | - | |||||||||||||||||||||||||||||||||||||
1332 | FREE (tokstr); executed 45322 times by 1 test: sh_xfree((tokstr), "expr.c", 1332); Executed by:
| 45322-7244571 | ||||||||||||||||||||||||||||||||||||
1333 | tokstr = savestring (tp); | - | ||||||||||||||||||||||||||||||||||||
1334 | *cp = c; | - | ||||||||||||||||||||||||||||||||||||
1335 | - | |||||||||||||||||||||||||||||||||||||
1336 | /* XXX - make peektok part of saved token state? */ | - | ||||||||||||||||||||||||||||||||||||
1337 | SAVETOK (&ec); | - | ||||||||||||||||||||||||||||||||||||
1338 | tokstr = (char *)NULL; /* keep it from being freed */ | - | ||||||||||||||||||||||||||||||||||||
1339 | tp = savecp = cp; | - | ||||||||||||||||||||||||||||||||||||
1340 | noeval = 1; | - | ||||||||||||||||||||||||||||||||||||
1341 | curtok = STR; | - | ||||||||||||||||||||||||||||||||||||
1342 | readtok (); | - | ||||||||||||||||||||||||||||||||||||
1343 | peektok = curtok; | - | ||||||||||||||||||||||||||||||||||||
1344 | if (peektok == STR) /* free new tokstr before old one is restored */
| 9-7289883 | ||||||||||||||||||||||||||||||||||||
1345 | FREE (tokstr); executed 9 times by 1 test: sh_xfree((tokstr), "expr.c", 1345); Executed by:
executed 9 times by 1 test: end of block Executed by:
| 0-9 | ||||||||||||||||||||||||||||||||||||
1346 | RESTORETOK (&ec); | - | ||||||||||||||||||||||||||||||||||||
1347 | cp = savecp; | - | ||||||||||||||||||||||||||||||||||||
1348 | - | |||||||||||||||||||||||||||||||||||||
1349 | /* The tests for PREINC and PREDEC aren't strictly correct, but they | - | ||||||||||||||||||||||||||||||||||||
1350 | preserve old behavior if a construct like --x=9 is given. */ | - | ||||||||||||||||||||||||||||||||||||
1351 | if (lasttok == PREINC || lasttok == PREDEC || peektok != EQ)
| 16-7289860 | ||||||||||||||||||||||||||||||||||||
1352 | { | - | ||||||||||||||||||||||||||||||||||||
1353 | lastlval = curlval; | - | ||||||||||||||||||||||||||||||||||||
1354 | tokval = expr_streval (tokstr, e, &curlval); | - | ||||||||||||||||||||||||||||||||||||
1355 | } executed 7287274 times by 1 test: end of block Executed by:
| 7287274 | ||||||||||||||||||||||||||||||||||||
1356 | else | - | ||||||||||||||||||||||||||||||||||||
1357 | tokval = 0; executed 2608 times by 1 test: tokval = 0; Executed by:
| 2608 | ||||||||||||||||||||||||||||||||||||
1358 | - | |||||||||||||||||||||||||||||||||||||
1359 | lasttok = curtok; | - | ||||||||||||||||||||||||||||||||||||
1360 | curtok = STR; | - | ||||||||||||||||||||||||||||||||||||
1361 | } executed 7289882 times by 1 test: end of block Executed by:
| 7289882 | ||||||||||||||||||||||||||||||||||||
1362 | else if (DIGIT(c))
| 109805-21181316 | ||||||||||||||||||||||||||||||||||||
1363 | { | - | ||||||||||||||||||||||||||||||||||||
1364 | while (ISALNUM (c) || c == '#' || c == '@' || c == '_')
| 8-33140000 | ||||||||||||||||||||||||||||||||||||
1365 | c = *cp++; executed 33140174 times by 1 test: c = *cp++; Executed by:
| 33140174 | ||||||||||||||||||||||||||||||||||||
1366 | - | |||||||||||||||||||||||||||||||||||||
1367 | c = *--cp; | - | ||||||||||||||||||||||||||||||||||||
1368 | *cp = '\0'; | - | ||||||||||||||||||||||||||||||||||||
1369 | - | |||||||||||||||||||||||||||||||||||||
1370 | tokval = strlong (tp); | - | ||||||||||||||||||||||||||||||||||||
1371 | *cp = c; | - | ||||||||||||||||||||||||||||||||||||
1372 | lasttok = curtok; | - | ||||||||||||||||||||||||||||||||||||
1373 | curtok = NUM; | - | ||||||||||||||||||||||||||||||||||||
1374 | } executed 13898307 times by 1 test: end of block Executed by:
| 13898307 | ||||||||||||||||||||||||||||||||||||
1375 | else | - | ||||||||||||||||||||||||||||||||||||
1376 | { | - | ||||||||||||||||||||||||||||||||||||
1377 | c1 = *cp++; | - | ||||||||||||||||||||||||||||||||||||
1378 | if ((c == EQ) && (c1 == EQ))
| 95-21283166 | ||||||||||||||||||||||||||||||||||||
1379 | c = EQEQ; executed 95 times by 1 test: c = 1; Executed by:
| 95 | ||||||||||||||||||||||||||||||||||||
1380 | else if ((c == NOT) && (c1 == EQ))
| 15-21290985 | ||||||||||||||||||||||||||||||||||||
1381 | c = NEQ; executed 26 times by 1 test: c = 2; Executed by:
| 26 | ||||||||||||||||||||||||||||||||||||
1382 | else if ((c == GT) && (c1 == EQ))
| 4859-21279273 | ||||||||||||||||||||||||||||||||||||
1383 | c = GEQ; executed 4859 times by 1 test: c = 4; Executed by:
| 4859 | ||||||||||||||||||||||||||||||||||||
1384 | else if ((c == LT) && (c1 == EQ))
| 19881-21216586 | ||||||||||||||||||||||||||||||||||||
1385 | c = LEQ; executed 19881 times by 1 test: c = 3; Executed by:
| 19881 | ||||||||||||||||||||||||||||||||||||
1386 | else if ((c == LT) && (c1 == LT))
| 59-21216586 | ||||||||||||||||||||||||||||||||||||
1387 | { | - | ||||||||||||||||||||||||||||||||||||
1388 | if (*cp == '=') /* a <<= b */
| 11-48 | ||||||||||||||||||||||||||||||||||||
1389 | { | - | ||||||||||||||||||||||||||||||||||||
1390 | assigntok = LSH; | - | ||||||||||||||||||||||||||||||||||||
1391 | c = OP_ASSIGN; | - | ||||||||||||||||||||||||||||||||||||
1392 | cp++; | - | ||||||||||||||||||||||||||||||||||||
1393 | } executed 48 times by 1 test: end of block Executed by:
| 48 | ||||||||||||||||||||||||||||||||||||
1394 | else | - | ||||||||||||||||||||||||||||||||||||
1395 | c = LSH; executed 11 times by 1 test: c = 9; Executed by:
| 11 | ||||||||||||||||||||||||||||||||||||
1396 | } | - | ||||||||||||||||||||||||||||||||||||
1397 | else if ((c == GT) && (c1 == GT))
| 48-21259333 | ||||||||||||||||||||||||||||||||||||
1398 | { | - | ||||||||||||||||||||||||||||||||||||
1399 | if (*cp == '=')
| 24 | ||||||||||||||||||||||||||||||||||||
1400 | { | - | ||||||||||||||||||||||||||||||||||||
1401 | assigntok = RSH; /* a >>= b */ | - | ||||||||||||||||||||||||||||||||||||
1402 | c = OP_ASSIGN; | - | ||||||||||||||||||||||||||||||||||||
1403 | cp++; | - | ||||||||||||||||||||||||||||||||||||
1404 | } executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||||||||||||||||||||||||||
1405 | else | - | ||||||||||||||||||||||||||||||||||||
1406 | c = RSH; executed 24 times by 1 test: c = 10; Executed by:
| 24 | ||||||||||||||||||||||||||||||||||||
1407 | } | - | ||||||||||||||||||||||||||||||||||||
1408 | else if ((c == BAND) && (c1 == BAND))
| 82-21265946 | ||||||||||||||||||||||||||||||||||||
1409 | c = LAND; executed 125 times by 1 test: c = 7; Executed by:
| 125 | ||||||||||||||||||||||||||||||||||||
1410 | else if ((c == BOR) && (c1 == BOR))
| 89-21246102 | ||||||||||||||||||||||||||||||||||||
1411 | c = LOR; executed 19837 times by 1 test: c = 8; Executed by:
| 19837 | ||||||||||||||||||||||||||||||||||||
1412 | else if ((c == '*') && (c1 == '*'))
| 33-21186672 | ||||||||||||||||||||||||||||||||||||
1413 | c = POWER; executed 33 times by 1 test: c = 13; Executed by:
| 33 | ||||||||||||||||||||||||||||||||||||
1414 | else if ((c == '-' || c == '+') && c1 == c && curtok == STR)
| 102-19891797 | ||||||||||||||||||||||||||||||||||||
1415 | c = (c == '-') ? POSTDEC : POSTINC; executed 1420630 times by 1 test: c = (c == '-') ? 17 : 16; Executed by:
| 96664-1420630 | ||||||||||||||||||||||||||||||||||||
1416 | else if ((c == '-' || c == '+') && c1 == c && curtok == NUM && (lasttok == PREINC || lasttok == PREDEC))
| 0-19795133 | ||||||||||||||||||||||||||||||||||||
1417 | { | - | ||||||||||||||||||||||||||||||||||||
1418 | /* This catches something like --FOO++ */ | - | ||||||||||||||||||||||||||||||||||||
1419 | if (c == '-')
| 0 | ||||||||||||||||||||||||||||||||||||
1420 | evalerror ("--: assignment requires lvalue"); never executed: evalerror ("--: assignment requires lvalue"); | 0 | ||||||||||||||||||||||||||||||||||||
1421 | else | - | ||||||||||||||||||||||||||||||||||||
1422 | evalerror ("++: assignment requires lvalue"); never executed: evalerror ("++: assignment requires lvalue"); | 0 | ||||||||||||||||||||||||||||||||||||
1423 | } | - | ||||||||||||||||||||||||||||||||||||
1424 | else if ((c == '-' || c == '+') && c1 == c)
| 102-19795133 | ||||||||||||||||||||||||||||||||||||
1425 | { | - | ||||||||||||||||||||||||||||||||||||
1426 | /* Quickly scan forward to see if this is followed by optional | - | ||||||||||||||||||||||||||||||||||||
1427 | whitespace and an identifier. */ | - | ||||||||||||||||||||||||||||||||||||
1428 | xp = cp; | - | ||||||||||||||||||||||||||||||||||||
1429 | while (xp && *xp && cr_whitespace (*xp))
| 0-128 | ||||||||||||||||||||||||||||||||||||
1430 | xp++; executed 26 times by 1 test: xp++; Executed by:
| 26 | ||||||||||||||||||||||||||||||||||||
1431 | if (legal_variable_starter ((unsigned char)*xp))
| 0-54 | ||||||||||||||||||||||||||||||||||||
1432 | c = (c == '-') ? PREDEC : PREINC; executed 48 times by 1 test: c = (c == '-') ? 15 : 14; Executed by:
| 16-48 | ||||||||||||||||||||||||||||||||||||
1433 | else | - | ||||||||||||||||||||||||||||||||||||
1434 | /* Could force parsing as preinc or predec and throw an error */ | - | ||||||||||||||||||||||||||||||||||||
1435 | #if 0 | - | ||||||||||||||||||||||||||||||||||||
1436 | { | - | ||||||||||||||||||||||||||||||||||||
1437 | /* bash-5.0 */ | - | ||||||||||||||||||||||||||||||||||||
1438 | /* This catches something like --4++ */ | - | ||||||||||||||||||||||||||||||||||||
1439 | if (c == '-') | - | ||||||||||||||||||||||||||||||||||||
1440 | evalerror ("--: assignment requires lvalue"); | - | ||||||||||||||||||||||||||||||||||||
1441 | else | - | ||||||||||||||||||||||||||||||||||||
1442 | evalerror ("++: assignment requires lvalue"); | - | ||||||||||||||||||||||||||||||||||||
1443 | } | - | ||||||||||||||||||||||||||||||||||||
1444 | #else | - | ||||||||||||||||||||||||||||||||||||
1445 | cp--; /* not preinc or predec, so unget the character */ executed 54 times by 1 test: cp--; Executed by:
| 54 | ||||||||||||||||||||||||||||||||||||
1446 | #endif | - | ||||||||||||||||||||||||||||||||||||
1447 | } | - | ||||||||||||||||||||||||||||||||||||
1448 | else if (c1 == EQ && member (c, "*/%+-&^|"))
| 0-19517526 | ||||||||||||||||||||||||||||||||||||
1449 | { | - | ||||||||||||||||||||||||||||||||||||
1450 | assigntok = c; /* a OP= b */ | - | ||||||||||||||||||||||||||||||||||||
1451 | c = OP_ASSIGN; | - | ||||||||||||||||||||||||||||||||||||
1452 | } executed 19517526 times by 1 test: end of block Executed by:
| 19517526 | ||||||||||||||||||||||||||||||||||||
1453 | else if (_is_arithop (c) == 0)
| 48-307852 | ||||||||||||||||||||||||||||||||||||
1454 | { | - | ||||||||||||||||||||||||||||||||||||
1455 | cp--; | - | ||||||||||||||||||||||||||||||||||||
1456 | /* use curtok, since it hasn't been copied to lasttok yet */ | - | ||||||||||||||||||||||||||||||||||||
1457 | if (curtok == 0 || _is_arithop (curtok) || _is_multiop (curtok))
| 0-31 | ||||||||||||||||||||||||||||||||||||
1458 | evalerror (_("syntax error: operand expected")); executed 47 times by 1 test: evalerror ( dcgettext (((void *)0), "syntax error: operand expected" , 5) ); Executed by:
| 47 | ||||||||||||||||||||||||||||||||||||
1459 | else | - | ||||||||||||||||||||||||||||||||||||
1460 | evalerror (_("syntax error: invalid arithmetic operator")); executed 1 time by 1 test: evalerror ( dcgettext (((void *)0), "syntax error: invalid arithmetic operator" , 5) ); Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||
1461 | } | - | ||||||||||||||||||||||||||||||||||||
1462 | else | - | ||||||||||||||||||||||||||||||||||||
1463 | cp--; /* `unget' the character */ executed 307852 times by 1 test: cp--; Executed by:
| 307852 | ||||||||||||||||||||||||||||||||||||
1464 | - | |||||||||||||||||||||||||||||||||||||
1465 | /* Should check here to make sure that the current character is one | - | ||||||||||||||||||||||||||||||||||||
1466 | of the recognized operators and flag an error if not. Could create | - | ||||||||||||||||||||||||||||||||||||
1467 | a character map the first time through and check it on subsequent | - | ||||||||||||||||||||||||||||||||||||
1468 | calls. */ | - | ||||||||||||||||||||||||||||||||||||
1469 | lasttok = curtok; | - | ||||||||||||||||||||||||||||||||||||
1470 | curtok = c; | - | ||||||||||||||||||||||||||||||||||||
1471 | } executed 21291073 times by 1 test: end of block Executed by:
| 21291073 | ||||||||||||||||||||||||||||||||||||
1472 | tp = cp; | - | ||||||||||||||||||||||||||||||||||||
1473 | } executed 42479262 times by 1 test: end of block Executed by:
| 42479262 | ||||||||||||||||||||||||||||||||||||
1474 | - | |||||||||||||||||||||||||||||||||||||
1475 | static void | - | ||||||||||||||||||||||||||||||||||||
1476 | evalerror (msg) | - | ||||||||||||||||||||||||||||||||||||
1477 | const char *msg; | - | ||||||||||||||||||||||||||||||||||||
1478 | { | - | ||||||||||||||||||||||||||||||||||||
1479 | char *name, *t; | - | ||||||||||||||||||||||||||||||||||||
1480 | - | |||||||||||||||||||||||||||||||||||||
1481 | name = this_command_name; | - | ||||||||||||||||||||||||||||||||||||
1482 | for (t = expression; t && whitespace (*t); t++)
| 0-332 | ||||||||||||||||||||||||||||||||||||
1483 | ; executed 125 times by 1 test: ; Executed by:
| 125 | ||||||||||||||||||||||||||||||||||||
1484 | internal_error (_("%s%s%s: %s (error token is \"%s\")"), | - | ||||||||||||||||||||||||||||||||||||
1485 | name ? name : "", name ? ": " : "", | - | ||||||||||||||||||||||||||||||||||||
1486 | t ? t : "", msg, (lasttp && *lasttp) ? lasttp : ""); | - | ||||||||||||||||||||||||||||||||||||
1487 | sh_longjmp (evalbuf, 1); | - | ||||||||||||||||||||||||||||||||||||
1488 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
1489 | - | |||||||||||||||||||||||||||||||||||||
1490 | /* Convert a string to an intmax_t integer, with an arbitrary base. | - | ||||||||||||||||||||||||||||||||||||
1491 | 0nnn -> base 8 | - | ||||||||||||||||||||||||||||||||||||
1492 | 0[Xx]nn -> base 16 | - | ||||||||||||||||||||||||||||||||||||
1493 | Anything else: [base#]number (this is implemented to match ksh93) | - | ||||||||||||||||||||||||||||||||||||
1494 | - | |||||||||||||||||||||||||||||||||||||
1495 | Base may be >=2 and <=64. If base is <= 36, the numbers are drawn | - | ||||||||||||||||||||||||||||||||||||
1496 | from [0-9][a-zA-Z], and lowercase and uppercase letters may be used | - | ||||||||||||||||||||||||||||||||||||
1497 | interchangably. If base is > 36 and <= 64, the numbers are drawn | - | ||||||||||||||||||||||||||||||||||||
1498 | from [0-9][a-z][A-Z]_@ (a = 10, z = 35, A = 36, Z = 61, @ = 62, _ = 63 -- | - | ||||||||||||||||||||||||||||||||||||
1499 | you get the picture). */ | - | ||||||||||||||||||||||||||||||||||||
1500 | - | |||||||||||||||||||||||||||||||||||||
1501 | static intmax_t | - | ||||||||||||||||||||||||||||||||||||
1502 | strlong (num) | - | ||||||||||||||||||||||||||||||||||||
1503 | char *num; | - | ||||||||||||||||||||||||||||||||||||
1504 | { | - | ||||||||||||||||||||||||||||||||||||
1505 | register char *s; | - | ||||||||||||||||||||||||||||||||||||
1506 | register unsigned char c; | - | ||||||||||||||||||||||||||||||||||||
1507 | int base, foundbase; | - | ||||||||||||||||||||||||||||||||||||
1508 | intmax_t val; | - | ||||||||||||||||||||||||||||||||||||
1509 | - | |||||||||||||||||||||||||||||||||||||
1510 | s = num; | - | ||||||||||||||||||||||||||||||||||||
1511 | - | |||||||||||||||||||||||||||||||||||||
1512 | base = 10; | - | ||||||||||||||||||||||||||||||||||||
1513 | foundbase = 0; | - | ||||||||||||||||||||||||||||||||||||
1514 | if (*s == '0')
| 35809-13862530 | ||||||||||||||||||||||||||||||||||||
1515 | { | - | ||||||||||||||||||||||||||||||||||||
1516 | s++; | - | ||||||||||||||||||||||||||||||||||||
1517 | - | |||||||||||||||||||||||||||||||||||||
1518 | if (*s == '\0')
| 1808-34001 | ||||||||||||||||||||||||||||||||||||
1519 | return 0; executed 34001 times by 1 test: return 0; Executed by:
| 34001 | ||||||||||||||||||||||||||||||||||||
1520 | - | |||||||||||||||||||||||||||||||||||||
1521 | /* Base 16? */ | - | ||||||||||||||||||||||||||||||||||||
1522 | if (*s == 'x' || *s == 'X')
| 0-1792 | ||||||||||||||||||||||||||||||||||||
1523 | { | - | ||||||||||||||||||||||||||||||||||||
1524 | base = 16; | - | ||||||||||||||||||||||||||||||||||||
1525 | s++; | - | ||||||||||||||||||||||||||||||||||||
1526 | } executed 1792 times by 1 test: end of block Executed by:
| 1792 | ||||||||||||||||||||||||||||||||||||
1527 | else | - | ||||||||||||||||||||||||||||||||||||
1528 | base = 8; executed 16 times by 1 test: base = 8; Executed by:
| 16 | ||||||||||||||||||||||||||||||||||||
1529 | foundbase++; | - | ||||||||||||||||||||||||||||||||||||
1530 | } executed 1808 times by 1 test: end of block Executed by:
| 1808 | ||||||||||||||||||||||||||||||||||||
1531 | - | |||||||||||||||||||||||||||||||||||||
1532 | val = 0; | - | ||||||||||||||||||||||||||||||||||||
1533 | for (c = *s++; c; c = *s++)
| 13864306-33102525 | ||||||||||||||||||||||||||||||||||||
1534 | { | - | ||||||||||||||||||||||||||||||||||||
1535 | if (c == '#')
| 158-33102367 | ||||||||||||||||||||||||||||||||||||
1536 | { | - | ||||||||||||||||||||||||||||||||||||
1537 | if (foundbase)
| 16-142 | ||||||||||||||||||||||||||||||||||||
1538 | evalerror (_("invalid number")); executed 16 times by 1 test: evalerror ( dcgettext (((void *)0), "invalid number" , 5) ); Executed by:
| 16 | ||||||||||||||||||||||||||||||||||||
1539 | - | |||||||||||||||||||||||||||||||||||||
1540 | /* Illegal base specifications raise an evaluation error. */ | - | ||||||||||||||||||||||||||||||||||||
1541 | if (val < 2 || val > 64)
| 0-142 | ||||||||||||||||||||||||||||||||||||
1542 | evalerror (_("invalid arithmetic base")); executed 8 times by 1 test: evalerror ( dcgettext (((void *)0), "invalid arithmetic base" , 5) ); Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||
1543 | - | |||||||||||||||||||||||||||||||||||||
1544 | base = val; | - | ||||||||||||||||||||||||||||||||||||
1545 | val = 0; | - | ||||||||||||||||||||||||||||||||||||
1546 | foundbase++; | - | ||||||||||||||||||||||||||||||||||||
1547 | } executed 134 times by 1 test: end of block Executed by:
| 134 | ||||||||||||||||||||||||||||||||||||
1548 | else if (ISALNUM(c) || (c == '_') || (c == '@'))
| 0-33102351 | ||||||||||||||||||||||||||||||||||||
1549 | { | - | ||||||||||||||||||||||||||||||||||||
1550 | if (DIGIT(c))
| 0-33102367 | ||||||||||||||||||||||||||||||||||||
1551 | c = TODIGIT(c); executed 33100977 times by 1 test: c = ((c) - '0'); Executed by:
| 33100977 | ||||||||||||||||||||||||||||||||||||
1552 | else if (c >= 'a' && c <= 'z')
| 0-1127 | ||||||||||||||||||||||||||||||||||||
1553 | c -= 'a' - 10; executed 1127 times by 1 test: c -= 'a' - 10; Executed by:
| 1127 | ||||||||||||||||||||||||||||||||||||
1554 | else if (c >= 'A' && c <= 'Z')
| 8-255 | ||||||||||||||||||||||||||||||||||||
1555 | c -= 'A' - ((base <= 36) ? 10 : 36); executed 247 times by 1 test: c -= 'A' - ((base <= 36) ? 10 : 36); Executed by:
| 16-247 | ||||||||||||||||||||||||||||||||||||
1556 | else if (c == '@')
| 8 | ||||||||||||||||||||||||||||||||||||
1557 | c = 62; executed 8 times by 1 test: c = 62; Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||
1558 | else if (c == '_')
| 0-8 | ||||||||||||||||||||||||||||||||||||
1559 | c = 63; executed 8 times by 1 test: c = 63; Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||
1560 | - | |||||||||||||||||||||||||||||||||||||
1561 | if (c >= base)
| 8-33102359 | ||||||||||||||||||||||||||||||||||||
1562 | evalerror (_("value too great for base")); executed 8 times by 1 test: evalerror ( dcgettext (((void *)0), "value too great for base" , 5) ); Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||
1563 | - | |||||||||||||||||||||||||||||||||||||
1564 | val = (val * base) + c; | - | ||||||||||||||||||||||||||||||||||||
1565 | } executed 33102359 times by 1 test: end of block Executed by:
| 33102359 | ||||||||||||||||||||||||||||||||||||
1566 | else | - | ||||||||||||||||||||||||||||||||||||
1567 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
1568 | } | - | ||||||||||||||||||||||||||||||||||||
1569 | - | |||||||||||||||||||||||||||||||||||||
1570 | return (val); executed 13864306 times by 1 test: return (val); Executed by:
| 13864306 | ||||||||||||||||||||||||||||||||||||
1571 | } | - | ||||||||||||||||||||||||||||||||||||
1572 | - | |||||||||||||||||||||||||||||||||||||
1573 | #if defined (EXPR_TEST) | - | ||||||||||||||||||||||||||||||||||||
1574 | void * | - | ||||||||||||||||||||||||||||||||||||
1575 | xmalloc (n) | - | ||||||||||||||||||||||||||||||||||||
1576 | int n; | - | ||||||||||||||||||||||||||||||||||||
1577 | { | - | ||||||||||||||||||||||||||||||||||||
1578 | return (malloc (n)); | - | ||||||||||||||||||||||||||||||||||||
1579 | } | - | ||||||||||||||||||||||||||||||||||||
1580 | - | |||||||||||||||||||||||||||||||||||||
1581 | void * | - | ||||||||||||||||||||||||||||||||||||
1582 | xrealloc (s, n) | - | ||||||||||||||||||||||||||||||||||||
1583 | char *s; | - | ||||||||||||||||||||||||||||||||||||
1584 | int n; | - | ||||||||||||||||||||||||||||||||||||
1585 | { | - | ||||||||||||||||||||||||||||||||||||
1586 | return (realloc (s, n)); | - | ||||||||||||||||||||||||||||||||||||
1587 | } | - | ||||||||||||||||||||||||||||||||||||
1588 | - | |||||||||||||||||||||||||||||||||||||
1589 | SHELL_VAR *find_variable () { return 0;} | - | ||||||||||||||||||||||||||||||||||||
1590 | SHELL_VAR *bind_variable () { return 0; } | - | ||||||||||||||||||||||||||||||||||||
1591 | - | |||||||||||||||||||||||||||||||||||||
1592 | char *get_string_value () { return 0; } | - | ||||||||||||||||||||||||||||||||||||
1593 | - | |||||||||||||||||||||||||||||||||||||
1594 | procenv_t top_level; | - | ||||||||||||||||||||||||||||||||||||
1595 | - | |||||||||||||||||||||||||||||||||||||
1596 | main (argc, argv) | - | ||||||||||||||||||||||||||||||||||||
1597 | int argc; | - | ||||||||||||||||||||||||||||||||||||
1598 | char **argv; | - | ||||||||||||||||||||||||||||||||||||
1599 | { | - | ||||||||||||||||||||||||||||||||||||
1600 | register int i; | - | ||||||||||||||||||||||||||||||||||||
1601 | intmax_t v; | - | ||||||||||||||||||||||||||||||||||||
1602 | int expok; | - | ||||||||||||||||||||||||||||||||||||
1603 | - | |||||||||||||||||||||||||||||||||||||
1604 | if (setjmp (top_level)) | - | ||||||||||||||||||||||||||||||||||||
1605 | exit (0); | - | ||||||||||||||||||||||||||||||||||||
1606 | - | |||||||||||||||||||||||||||||||||||||
1607 | for (i = 1; i < argc; i++) | - | ||||||||||||||||||||||||||||||||||||
1608 | { | - | ||||||||||||||||||||||||||||||||||||
1609 | v = evalexp (argv[i], 0, &expok); | - | ||||||||||||||||||||||||||||||||||||
1610 | if (expok == 0) | - | ||||||||||||||||||||||||||||||||||||
1611 | fprintf (stderr, _("%s: expression error\n"), argv[i]); | - | ||||||||||||||||||||||||||||||||||||
1612 | else | - | ||||||||||||||||||||||||||||||||||||
1613 | printf ("'%s' -> %ld\n", argv[i], v); | - | ||||||||||||||||||||||||||||||||||||
1614 | } | - | ||||||||||||||||||||||||||||||||||||
1615 | exit (0); | - | ||||||||||||||||||||||||||||||||||||
1616 | } | - | ||||||||||||||||||||||||||||||||||||
1617 | - | |||||||||||||||||||||||||||||||||||||
1618 | int | - | ||||||||||||||||||||||||||||||||||||
1619 | builtin_error (format, arg1, arg2, arg3, arg4, arg5) | - | ||||||||||||||||||||||||||||||||||||
1620 | char *format; | - | ||||||||||||||||||||||||||||||||||||
1621 | { | - | ||||||||||||||||||||||||||||||||||||
1622 | fprintf (stderr, "expr: "); | - | ||||||||||||||||||||||||||||||||||||
1623 | fprintf (stderr, format, arg1, arg2, arg3, arg4, arg5); | - | ||||||||||||||||||||||||||||||||||||
1624 | fprintf (stderr, "\n"); | - | ||||||||||||||||||||||||||||||||||||
1625 | return 0; | - | ||||||||||||||||||||||||||||||||||||
1626 | } | - | ||||||||||||||||||||||||||||||||||||
1627 | - | |||||||||||||||||||||||||||||||||||||
1628 | char * | - | ||||||||||||||||||||||||||||||||||||
1629 | itos (n) | - | ||||||||||||||||||||||||||||||||||||
1630 | intmax_t n; | - | ||||||||||||||||||||||||||||||||||||
1631 | { | - | ||||||||||||||||||||||||||||||||||||
1632 | return ("42"); | - | ||||||||||||||||||||||||||||||||||||
1633 | } | - | ||||||||||||||||||||||||||||||||||||
1634 | - | |||||||||||||||||||||||||||||||||||||
1635 | #endif /* EXPR_TEST */ | - | ||||||||||||||||||||||||||||||||||||
Source code | Switch to Preprocessed file |