mirror of https://github.com/mirror/busybox.git
hush: shrink code in builtin_eval
function old new delta builtin_eval 126 119 -7 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>pull/3/head
parent
8717b14f37
commit
b0441a7189
52
shell/hush.c
52
shell/hush.c
|
@ -9806,41 +9806,41 @@ static int FAST_FUNC builtin_pwd(char **argv UNUSED_PARAM)
|
||||||
|
|
||||||
static int FAST_FUNC builtin_eval(char **argv)
|
static int FAST_FUNC builtin_eval(char **argv)
|
||||||
{
|
{
|
||||||
int rcode = EXIT_SUCCESS;
|
|
||||||
|
|
||||||
argv = skip_dash_dash(argv);
|
argv = skip_dash_dash(argv);
|
||||||
if (argv[0]) {
|
|
||||||
char *str = NULL;
|
|
||||||
|
|
||||||
if (argv[1]) {
|
if (!argv[0])
|
||||||
/* "The eval utility shall construct a command by
|
return EXIT_SUCCESS;
|
||||||
* concatenating arguments together, separating
|
|
||||||
* each with a <space> character."
|
|
||||||
*/
|
|
||||||
char *p;
|
|
||||||
unsigned len = 0;
|
|
||||||
char **pp = argv;
|
|
||||||
do
|
|
||||||
len += strlen(*pp) + 1;
|
|
||||||
while (*++pp);
|
|
||||||
str = p = xmalloc(len);
|
|
||||||
pp = argv;
|
|
||||||
do {
|
|
||||||
p = stpcpy(p, *pp);
|
|
||||||
*p++ = ' ';
|
|
||||||
} while (*++pp);
|
|
||||||
p[-1] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!argv[1]) {
|
||||||
/* bash:
|
/* bash:
|
||||||
* eval "echo Hi; done" ("done" is syntax error):
|
* eval "echo Hi; done" ("done" is syntax error):
|
||||||
* "echo Hi" will not execute too.
|
* "echo Hi" will not execute too.
|
||||||
*/
|
*/
|
||||||
parse_and_run_string(str ? str : argv[0]);
|
parse_and_run_string(argv[0]);
|
||||||
|
} else {
|
||||||
|
/* "The eval utility shall construct a command by
|
||||||
|
* concatenating arguments together, separating
|
||||||
|
* each with a <space> character."
|
||||||
|
*/
|
||||||
|
char *str, *p;
|
||||||
|
unsigned len = 0;
|
||||||
|
char **pp = argv;
|
||||||
|
do
|
||||||
|
len += strlen(*pp) + 1;
|
||||||
|
while (*++pp);
|
||||||
|
str = p = xmalloc(len);
|
||||||
|
pp = argv;
|
||||||
|
for (;;) {
|
||||||
|
p = stpcpy(p, *pp);
|
||||||
|
pp++;
|
||||||
|
if (!*pp)
|
||||||
|
break;
|
||||||
|
*p++ = ' ';
|
||||||
|
}
|
||||||
|
parse_and_run_string(str);
|
||||||
free(str);
|
free(str);
|
||||||
rcode = G.last_exitcode;
|
|
||||||
}
|
}
|
||||||
return rcode;
|
return G.last_exitcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int FAST_FUNC builtin_exec(char **argv)
|
static int FAST_FUNC builtin_exec(char **argv)
|
||||||
|
|
Loading…
Reference in New Issue