Fix the let builtin (so we can close bug #1196) and remove the

nonstandard exp builtin.
 -Erik
This commit is contained in:
Eric Andersen 2001-07-31 21:38:23 +00:00
parent 73f6a1b058
commit fa1c5aac51
2 changed files with 54 additions and 94 deletions

74
ash.c
View File

@ -1593,9 +1593,6 @@ __lookupalias(const char *name) {
#define ARITH_BNOT 281 #define ARITH_BNOT 281
static void expari (int); static void expari (int);
/* From arith.y */
static long ash_arith(const char *p);
static int expcmd (int , char **);
#endif #endif
static char *trap[NSIG]; /* trap handler commands */ static char *trap[NSIG]; /* trap handler commands */
@ -1647,7 +1644,7 @@ static int waitcmd (int, char **);
static int ulimitcmd (int, char **); static int ulimitcmd (int, char **);
static int timescmd (int, char **); static int timescmd (int, char **);
#ifdef ASH_MATH_SUPPORT #ifdef ASH_MATH_SUPPORT
static int expcmd (int, char **); static int letcmd (int, char **);
#endif #endif
static int typecmd (int, char **); static int typecmd (int, char **);
#ifdef ASH_GETOPTS #ifdef ASH_GETOPTS
@ -1706,9 +1703,6 @@ static const struct builtincmd builtincmds[] = {
{ BUILTIN_SPECIAL "eval", evalcmd }, { BUILTIN_SPECIAL "eval", evalcmd },
{ BUILTIN_SPECIAL "exec", execcmd }, { BUILTIN_SPECIAL "exec", execcmd },
{ BUILTIN_SPECIAL "exit", exitcmd }, { BUILTIN_SPECIAL "exit", exitcmd },
#ifdef ASH_MATH_SUPPORT
{ BUILTIN_NOSPEC "exp", expcmd },
#endif
{ BUILTIN_SPEC_ASSG "export", exportcmd }, { BUILTIN_SPEC_ASSG "export", exportcmd },
{ BUILTIN_REGULAR "false", false_main }, { BUILTIN_REGULAR "false", false_main },
{ BUILTIN_REGULAR "fc", histcmd }, { BUILTIN_REGULAR "fc", histcmd },
@ -1725,7 +1719,7 @@ static const struct builtincmd builtincmds[] = {
{ BUILTIN_REGULAR "kill", killcmd }, { BUILTIN_REGULAR "kill", killcmd },
#endif #endif
#ifdef ASH_MATH_SUPPORT #ifdef ASH_MATH_SUPPORT
{ BUILTIN_NOSPEC "let", expcmd }, { BUILTIN_REGULAR "let", letcmd },
#endif #endif
{ BUILTIN_ASSIGN "local", localcmd }, { BUILTIN_ASSIGN "local", localcmd },
#ifndef BB_PWD #ifndef BB_PWD
@ -4883,7 +4877,9 @@ expari(int flag)
removerecordregions(begoff); removerecordregions(begoff);
if (quotes) if (quotes)
rmescapes(p+2); rmescapes(p+2);
result = ash_arith(p+2); result = arith(p+2);
if (result < 0)
error("arith: syntax error: \"%s\"\n", p+2);
snprintf(p, 12, "%d", result); snprintf(p, 12, "%d", result);
while (*p++) while (*p++)
@ -12878,7 +12874,7 @@ findvar(struct var **vpp, const char *name)
/* /*
* Copyright (c) 1999 Herbert Xu <herbert@debian.org> * Copyright (c) 1999 Herbert Xu <herbert@debian.org>
* This file contains code for the times builtin. * This file contains code for the times builtin.
* $Id: ash.c,v 1.14 2001/07/30 21:41:37 andersen Exp $ * $Id: ash.c,v 1.15 2001/07/31 21:38:23 andersen Exp $
*/ */
static int timescmd (int argc, char **argv) static int timescmd (int argc, char **argv)
{ {
@ -12900,45 +12896,29 @@ static int timescmd (int argc, char **argv)
#ifdef ASH_MATH_SUPPORT #ifdef ASH_MATH_SUPPORT
/* The exp(1) builtin. */ /* The let builtin. */
int expcmd(int argc, char **argv) int letcmd(int argc, char **argv)
{ {
const char *p; long result=0;
char *concat; if (argc == 2) {
char **ap; char *tmp, *expression, p[13];
long i; expression = strchr(argv[1], '=');
if (!expression) {
if (argc > 1) { out2fmt("sh: let: syntax error: \"%s\"\n", argv[1]);
p = argv[1]; return 0;
if (argc > 2) {
/* concatenate arguments */
STARTSTACKSTR(concat);
ap = argv + 2;
for (;;) {
while (*p)
STPUTC(*p++, concat);
if ((p = *ap++) == NULL)
break;
STPUTC(' ', concat);
}
STPUTC('\0', concat);
p = grabstackstr(concat);
} }
} else *expression = '\0';
p = ""; tmp = ++expression;
result = arith(tmp);
i = ash_arith(p); if (result < 0) {
out2fmt("sh: let: syntax error: \"%s=%s\"\n", argv[1], expression);
printf("%ld\n", i); return 0;
return (! i); }
} snprintf(p, 12, "%ld", result);
setvar(argv[1], savestr(p), 0);
static long ash_arith(const char *p) } else if (argc >= 3)
{ synerror("invalid operand");
long i = arith(p); return !result;
if (i <0)
error("arith: syntax error: \"%s\"\n", p);
return i;
} }
#endif #endif

View File

@ -1593,9 +1593,6 @@ __lookupalias(const char *name) {
#define ARITH_BNOT 281 #define ARITH_BNOT 281
static void expari (int); static void expari (int);
/* From arith.y */
static long ash_arith(const char *p);
static int expcmd (int , char **);
#endif #endif
static char *trap[NSIG]; /* trap handler commands */ static char *trap[NSIG]; /* trap handler commands */
@ -1647,7 +1644,7 @@ static int waitcmd (int, char **);
static int ulimitcmd (int, char **); static int ulimitcmd (int, char **);
static int timescmd (int, char **); static int timescmd (int, char **);
#ifdef ASH_MATH_SUPPORT #ifdef ASH_MATH_SUPPORT
static int expcmd (int, char **); static int letcmd (int, char **);
#endif #endif
static int typecmd (int, char **); static int typecmd (int, char **);
#ifdef ASH_GETOPTS #ifdef ASH_GETOPTS
@ -1706,9 +1703,6 @@ static const struct builtincmd builtincmds[] = {
{ BUILTIN_SPECIAL "eval", evalcmd }, { BUILTIN_SPECIAL "eval", evalcmd },
{ BUILTIN_SPECIAL "exec", execcmd }, { BUILTIN_SPECIAL "exec", execcmd },
{ BUILTIN_SPECIAL "exit", exitcmd }, { BUILTIN_SPECIAL "exit", exitcmd },
#ifdef ASH_MATH_SUPPORT
{ BUILTIN_NOSPEC "exp", expcmd },
#endif
{ BUILTIN_SPEC_ASSG "export", exportcmd }, { BUILTIN_SPEC_ASSG "export", exportcmd },
{ BUILTIN_REGULAR "false", false_main }, { BUILTIN_REGULAR "false", false_main },
{ BUILTIN_REGULAR "fc", histcmd }, { BUILTIN_REGULAR "fc", histcmd },
@ -1725,7 +1719,7 @@ static const struct builtincmd builtincmds[] = {
{ BUILTIN_REGULAR "kill", killcmd }, { BUILTIN_REGULAR "kill", killcmd },
#endif #endif
#ifdef ASH_MATH_SUPPORT #ifdef ASH_MATH_SUPPORT
{ BUILTIN_NOSPEC "let", expcmd }, { BUILTIN_REGULAR "let", letcmd },
#endif #endif
{ BUILTIN_ASSIGN "local", localcmd }, { BUILTIN_ASSIGN "local", localcmd },
#ifndef BB_PWD #ifndef BB_PWD
@ -4883,7 +4877,9 @@ expari(int flag)
removerecordregions(begoff); removerecordregions(begoff);
if (quotes) if (quotes)
rmescapes(p+2); rmescapes(p+2);
result = ash_arith(p+2); result = arith(p+2);
if (result < 0)
error("arith: syntax error: \"%s\"\n", p+2);
snprintf(p, 12, "%d", result); snprintf(p, 12, "%d", result);
while (*p++) while (*p++)
@ -12878,7 +12874,7 @@ findvar(struct var **vpp, const char *name)
/* /*
* Copyright (c) 1999 Herbert Xu <herbert@debian.org> * Copyright (c) 1999 Herbert Xu <herbert@debian.org>
* This file contains code for the times builtin. * This file contains code for the times builtin.
* $Id: ash.c,v 1.14 2001/07/30 21:41:37 andersen Exp $ * $Id: ash.c,v 1.15 2001/07/31 21:38:23 andersen Exp $
*/ */
static int timescmd (int argc, char **argv) static int timescmd (int argc, char **argv)
{ {
@ -12900,45 +12896,29 @@ static int timescmd (int argc, char **argv)
#ifdef ASH_MATH_SUPPORT #ifdef ASH_MATH_SUPPORT
/* The exp(1) builtin. */ /* The let builtin. */
int expcmd(int argc, char **argv) int letcmd(int argc, char **argv)
{ {
const char *p; long result=0;
char *concat; if (argc == 2) {
char **ap; char *tmp, *expression, p[13];
long i; expression = strchr(argv[1], '=');
if (!expression) {
if (argc > 1) { out2fmt("sh: let: syntax error: \"%s\"\n", argv[1]);
p = argv[1]; return 0;
if (argc > 2) {
/* concatenate arguments */
STARTSTACKSTR(concat);
ap = argv + 2;
for (;;) {
while (*p)
STPUTC(*p++, concat);
if ((p = *ap++) == NULL)
break;
STPUTC(' ', concat);
}
STPUTC('\0', concat);
p = grabstackstr(concat);
} }
} else *expression = '\0';
p = ""; tmp = ++expression;
result = arith(tmp);
i = ash_arith(p); if (result < 0) {
out2fmt("sh: let: syntax error: \"%s=%s\"\n", argv[1], expression);
printf("%ld\n", i); return 0;
return (! i); }
} snprintf(p, 12, "%ld", result);
setvar(argv[1], savestr(p), 0);
static long ash_arith(const char *p) } else if (argc >= 3)
{ synerror("invalid operand");
long i = arith(p); return !result;
if (i <0)
error("arith: syntax error: \"%s\"\n", p);
return i;
} }
#endif #endif