mirror of https://github.com/mirror/busybox.git
- remove args from bss, minor misc shrinkage while at it.
text data bss dec hex filename 2577 0 4 2581 a15 expr.o 2522 0 0 2522 9da expr.o1_6_stable
parent
729bd9e0b0
commit
adb01b1583
|
@ -62,15 +62,18 @@ struct valinfo {
|
||||||
typedef struct valinfo VALUE;
|
typedef struct valinfo VALUE;
|
||||||
|
|
||||||
/* The arguments given to the program, minus the program name. */
|
/* The arguments given to the program, minus the program name. */
|
||||||
static char **args;
|
struct globals {
|
||||||
|
char **args;
|
||||||
|
};
|
||||||
|
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||||
|
|
||||||
static VALUE *docolon(VALUE * sv, VALUE * pv);
|
static VALUE *docolon(VALUE * sv, VALUE * pv);
|
||||||
static VALUE *eval(void);
|
static VALUE *eval(void);
|
||||||
static VALUE *int_value(arith_t i);
|
static VALUE *int_value(arith_t i);
|
||||||
static VALUE *str_value(const char *s);
|
static VALUE *str_value(const char *s);
|
||||||
static int nextarg(const char *str);
|
static bool nextarg(const char *str);
|
||||||
static int null(VALUE * v);
|
static int null(VALUE * v);
|
||||||
static int toarith(VALUE * v);
|
static bool toarith(VALUE * v);
|
||||||
static void freev(VALUE * v);
|
static void freev(VALUE * v);
|
||||||
static void tostring(VALUE * v);
|
static void tostring(VALUE * v);
|
||||||
|
|
||||||
|
@ -83,10 +86,10 @@ int expr_main(int argc, char **argv)
|
||||||
bb_error_msg_and_die("too few arguments");
|
bb_error_msg_and_die("too few arguments");
|
||||||
}
|
}
|
||||||
|
|
||||||
args = argv + 1;
|
G.args = argv + 1;
|
||||||
|
|
||||||
v = eval();
|
v = eval();
|
||||||
if (*args)
|
if (*G.args)
|
||||||
bb_error_msg_and_die("syntax error");
|
bb_error_msg_and_die("syntax error");
|
||||||
|
|
||||||
if (v->type == integer)
|
if (v->type == integer)
|
||||||
|
@ -152,7 +155,7 @@ static void tostring(VALUE * v)
|
||||||
|
|
||||||
/* Coerce V to an integer value. Return 1 on success, 0 on failure. */
|
/* Coerce V to an integer value. Return 1 on success, 0 on failure. */
|
||||||
|
|
||||||
static int toarith(VALUE * v)
|
static bool toarith(VALUE * v)
|
||||||
{
|
{
|
||||||
if (v->type == string) {
|
if (v->type == string) {
|
||||||
arith_t i;
|
arith_t i;
|
||||||
|
@ -173,11 +176,11 @@ static int toarith(VALUE * v)
|
||||||
/* Return nonzero if the next token matches STR exactly.
|
/* Return nonzero if the next token matches STR exactly.
|
||||||
STR must not be NULL. */
|
STR must not be NULL. */
|
||||||
|
|
||||||
static int nextarg(const char *str)
|
static bool nextarg(const char *str)
|
||||||
{
|
{
|
||||||
if (*args == NULL)
|
if (*G.args == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
return strcmp(*args, str) == 0;
|
return strcmp(*G.args, str) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The comparison operator handling functions. */
|
/* The comparison operator handling functions. */
|
||||||
|
@ -281,53 +284,57 @@ static VALUE *eval7(void)
|
||||||
{
|
{
|
||||||
VALUE *v;
|
VALUE *v;
|
||||||
|
|
||||||
if (!*args)
|
if (!*G.args)
|
||||||
bb_error_msg_and_die("syntax error");
|
bb_error_msg_and_die("syntax error");
|
||||||
|
|
||||||
if (nextarg("(")) {
|
if (nextarg("(")) {
|
||||||
args++;
|
G.args++;
|
||||||
v = eval();
|
v = eval();
|
||||||
if (!nextarg(")"))
|
if (!nextarg(")"))
|
||||||
bb_error_msg_and_die("syntax error");
|
bb_error_msg_and_die("syntax error");
|
||||||
args++;
|
G.args++;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextarg(")"))
|
if (nextarg(")"))
|
||||||
bb_error_msg_and_die("syntax error");
|
bb_error_msg_and_die("syntax error");
|
||||||
|
|
||||||
return str_value(*args++);
|
return str_value(*G.args++);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle match, substr, index, length, and quote keywords. */
|
/* Handle match, substr, index, length, and quote keywords. */
|
||||||
|
|
||||||
static VALUE *eval6(void)
|
static VALUE *eval6(void)
|
||||||
{
|
{
|
||||||
VALUE *l, *r, *v, *i1, *i2;
|
VALUE *l, *r, *v = NULL /* silence gcc */, *i1, *i2;
|
||||||
|
const char * const keywords[] = {
|
||||||
|
"quote", "length", "match", "index", "substr", NULL
|
||||||
|
};
|
||||||
|
|
||||||
if (nextarg("quote")) {
|
smalluint key = *G.args ? index_in_str_array(keywords, *G.args) + 1 : 0;
|
||||||
args++;
|
if (key == 0) /* not a keyword */
|
||||||
if (!*args)
|
return eval7();
|
||||||
|
G.args++; /* We have a valid token, so get the next argument. */
|
||||||
|
if (key == 1) { /* quote */
|
||||||
|
if (!*G.args)
|
||||||
bb_error_msg_and_die("syntax error");
|
bb_error_msg_and_die("syntax error");
|
||||||
return str_value(*args++);
|
return str_value(*G.args++);
|
||||||
} else if (nextarg("length")) {
|
}
|
||||||
args++;
|
if (key == 2) { /* length */
|
||||||
r = eval6();
|
r = eval6();
|
||||||
tostring(r);
|
tostring(r);
|
||||||
v = int_value(strlen(r->u.s));
|
v = int_value(strlen(r->u.s));
|
||||||
freev(r);
|
freev(r);
|
||||||
return v;
|
} else
|
||||||
} else if (nextarg("match")) {
|
|
||||||
args++;
|
|
||||||
l = eval6();
|
l = eval6();
|
||||||
|
|
||||||
|
if (key == 3) { /* match */
|
||||||
r = eval6();
|
r = eval6();
|
||||||
v = docolon(l, r);
|
v = docolon(l, r);
|
||||||
freev(l);
|
freev(l);
|
||||||
freev(r);
|
freev(r);
|
||||||
return v;
|
}
|
||||||
} else if (nextarg("index")) {
|
if (key == 4) { /* index */
|
||||||
args++;
|
|
||||||
l = eval6();
|
|
||||||
r = eval6();
|
r = eval6();
|
||||||
tostring(l);
|
tostring(l);
|
||||||
tostring(r);
|
tostring(r);
|
||||||
|
@ -336,10 +343,8 @@ static VALUE *eval6(void)
|
||||||
v->u.i = 0;
|
v->u.i = 0;
|
||||||
freev(l);
|
freev(l);
|
||||||
freev(r);
|
freev(r);
|
||||||
return v;
|
}
|
||||||
} else if (nextarg("substr")) {
|
if (key == 5) { /* substr */
|
||||||
args++;
|
|
||||||
l = eval6();
|
|
||||||
i1 = eval6();
|
i1 = eval6();
|
||||||
i2 = eval6();
|
i2 = eval6();
|
||||||
tostring(l);
|
tostring(l);
|
||||||
|
@ -355,9 +360,9 @@ static VALUE *eval6(void)
|
||||||
freev(l);
|
freev(l);
|
||||||
freev(i1);
|
freev(i1);
|
||||||
freev(i2);
|
freev(i2);
|
||||||
return v;
|
}
|
||||||
} else
|
return v;
|
||||||
return eval7();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle : operator (pattern matching).
|
/* Handle : operator (pattern matching).
|
||||||
|
@ -369,7 +374,7 @@ static VALUE *eval5(void)
|
||||||
|
|
||||||
l = eval6();
|
l = eval6();
|
||||||
while (nextarg(":")) {
|
while (nextarg(":")) {
|
||||||
args++;
|
G.args++;
|
||||||
r = eval6();
|
r = eval6();
|
||||||
v = docolon(l, r);
|
v = docolon(l, r);
|
||||||
freev(l);
|
freev(l);
|
||||||
|
@ -397,7 +402,7 @@ static VALUE *eval4(void)
|
||||||
op = '%';
|
op = '%';
|
||||||
else
|
else
|
||||||
return l;
|
return l;
|
||||||
args++;
|
G.args++;
|
||||||
r = eval5();
|
r = eval5();
|
||||||
val = arithmetic_common(l, r, op);
|
val = arithmetic_common(l, r, op);
|
||||||
freev(l);
|
freev(l);
|
||||||
|
@ -422,7 +427,7 @@ static VALUE *eval3(void)
|
||||||
op = '-';
|
op = '-';
|
||||||
else
|
else
|
||||||
return l;
|
return l;
|
||||||
args++;
|
G.args++;
|
||||||
r = eval4();
|
r = eval4();
|
||||||
val = arithmetic_common(l, r, op);
|
val = arithmetic_common(l, r, op);
|
||||||
freev(l);
|
freev(l);
|
||||||
|
@ -455,7 +460,7 @@ static VALUE *eval2(void)
|
||||||
op = '>';
|
op = '>';
|
||||||
else
|
else
|
||||||
return l;
|
return l;
|
||||||
args++;
|
G.args++;
|
||||||
r = eval3();
|
r = eval3();
|
||||||
toarith(l);
|
toarith(l);
|
||||||
toarith(r);
|
toarith(r);
|
||||||
|
@ -474,7 +479,7 @@ static VALUE *eval1(void)
|
||||||
|
|
||||||
l = eval2();
|
l = eval2();
|
||||||
while (nextarg("&")) {
|
while (nextarg("&")) {
|
||||||
args++;
|
G.args++;
|
||||||
r = eval2();
|
r = eval2();
|
||||||
if (null(l) || null(r)) {
|
if (null(l) || null(r)) {
|
||||||
freev(l);
|
freev(l);
|
||||||
|
@ -494,7 +499,7 @@ static VALUE *eval(void)
|
||||||
|
|
||||||
l = eval1();
|
l = eval1();
|
||||||
while (nextarg("|")) {
|
while (nextarg("|")) {
|
||||||
args++;
|
G.args++;
|
||||||
r = eval1();
|
r = eval1();
|
||||||
if (null(l)) {
|
if (null(l)) {
|
||||||
freev(l);
|
freev(l);
|
||||||
|
|
Loading…
Reference in New Issue