aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-07-31 21:38:23 +0000
committerEric Andersen <andersen@codepoet.org>2001-07-31 21:38:23 +0000
commitfa1c5aac51c5e4f880f72ffc66d409d61706ad8a (patch)
tree3b707d1edbcaa0b6eb69e8b568976f75601ac498
parent73f6a1b058e994a44820b3ee987b04d14f05051d (diff)
downloadbusybox-w32-fa1c5aac51c5e4f880f72ffc66d409d61706ad8a.tar.gz
busybox-w32-fa1c5aac51c5e4f880f72ffc66d409d61706ad8a.tar.bz2
busybox-w32-fa1c5aac51c5e4f880f72ffc66d409d61706ad8a.zip
Fix the let builtin (so we can close bug #1196) and remove the
nonstandard exp builtin. -Erik
-rw-r--r--ash.c76
-rw-r--r--shell/ash.c76
2 files changed, 56 insertions, 96 deletions
diff --git a/ash.c b/ash.c
index 9a5435e8b..15e1adb7c 100644
--- a/ash.c
+++ b/ash.c
@@ -1593,9 +1593,6 @@ __lookupalias(const char *name) {
1593#define ARITH_BNOT 281 1593#define ARITH_BNOT 281
1594 1594
1595static void expari (int); 1595static void expari (int);
1596/* From arith.y */
1597static long ash_arith(const char *p);
1598static int expcmd (int , char **);
1599#endif 1596#endif
1600 1597
1601static char *trap[NSIG]; /* trap handler commands */ 1598static char *trap[NSIG]; /* trap handler commands */
@@ -1647,7 +1644,7 @@ static int waitcmd (int, char **);
1647static int ulimitcmd (int, char **); 1644static int ulimitcmd (int, char **);
1648static int timescmd (int, char **); 1645static int timescmd (int, char **);
1649#ifdef ASH_MATH_SUPPORT 1646#ifdef ASH_MATH_SUPPORT
1650static int expcmd (int, char **); 1647static int letcmd (int, char **);
1651#endif 1648#endif
1652static int typecmd (int, char **); 1649static int typecmd (int, char **);
1653#ifdef ASH_GETOPTS 1650#ifdef ASH_GETOPTS
@@ -1706,9 +1703,6 @@ static const struct builtincmd builtincmds[] = {
1706 { BUILTIN_SPECIAL "eval", evalcmd }, 1703 { BUILTIN_SPECIAL "eval", evalcmd },
1707 { BUILTIN_SPECIAL "exec", execcmd }, 1704 { BUILTIN_SPECIAL "exec", execcmd },
1708 { BUILTIN_SPECIAL "exit", exitcmd }, 1705 { BUILTIN_SPECIAL "exit", exitcmd },
1709#ifdef ASH_MATH_SUPPORT
1710 { BUILTIN_NOSPEC "exp", expcmd },
1711#endif
1712 { BUILTIN_SPEC_ASSG "export", exportcmd }, 1706 { BUILTIN_SPEC_ASSG "export", exportcmd },
1713 { BUILTIN_REGULAR "false", false_main }, 1707 { BUILTIN_REGULAR "false", false_main },
1714 { BUILTIN_REGULAR "fc", histcmd }, 1708 { BUILTIN_REGULAR "fc", histcmd },
@@ -1725,7 +1719,7 @@ static const struct builtincmd builtincmds[] = {
1725 { BUILTIN_REGULAR "kill", killcmd }, 1719 { BUILTIN_REGULAR "kill", killcmd },
1726#endif 1720#endif
1727#ifdef ASH_MATH_SUPPORT 1721#ifdef ASH_MATH_SUPPORT
1728 { BUILTIN_NOSPEC "let", expcmd }, 1722 { BUILTIN_REGULAR "let", letcmd },
1729#endif 1723#endif
1730 { BUILTIN_ASSIGN "local", localcmd }, 1724 { BUILTIN_ASSIGN "local", localcmd },
1731#ifndef BB_PWD 1725#ifndef BB_PWD
@@ -4883,7 +4877,9 @@ expari(int flag)
4883 removerecordregions(begoff); 4877 removerecordregions(begoff);
4884 if (quotes) 4878 if (quotes)
4885 rmescapes(p+2); 4879 rmescapes(p+2);
4886 result = ash_arith(p+2); 4880 result = arith(p+2);
4881 if (result < 0)
4882 error("arith: syntax error: \"%s\"\n", p+2);
4887 snprintf(p, 12, "%d", result); 4883 snprintf(p, 12, "%d", result);
4888 4884
4889 while (*p++) 4885 while (*p++)
@@ -12878,7 +12874,7 @@ findvar(struct var **vpp, const char *name)
12878/* 12874/*
12879 * Copyright (c) 1999 Herbert Xu <herbert@debian.org> 12875 * Copyright (c) 1999 Herbert Xu <herbert@debian.org>
12880 * This file contains code for the times builtin. 12876 * This file contains code for the times builtin.
12881 * $Id: ash.c,v 1.14 2001/07/30 21:41:37 andersen Exp $ 12877 * $Id: ash.c,v 1.15 2001/07/31 21:38:23 andersen Exp $
12882 */ 12878 */
12883static int timescmd (int argc, char **argv) 12879static int timescmd (int argc, char **argv)
12884{ 12880{
@@ -12900,45 +12896,29 @@ static int timescmd (int argc, char **argv)
12900 12896
12901 12897
12902#ifdef ASH_MATH_SUPPORT 12898#ifdef ASH_MATH_SUPPORT
12903/* The exp(1) builtin. */ 12899/* The let builtin. */
12904int expcmd(int argc, char **argv) 12900int letcmd(int argc, char **argv)
12905{ 12901{
12906 const char *p; 12902 long result=0;
12907 char *concat; 12903 if (argc == 2) {
12908 char **ap; 12904 char *tmp, *expression, p[13];
12909 long i; 12905 expression = strchr(argv[1], '=');
12910 12906 if (!expression) {
12911 if (argc > 1) { 12907 out2fmt("sh: let: syntax error: \"%s\"\n", argv[1]);
12912 p = argv[1]; 12908 return 0;
12913 if (argc > 2) {
12914 /* concatenate arguments */
12915 STARTSTACKSTR(concat);
12916 ap = argv + 2;
12917 for (;;) {
12918 while (*p)
12919 STPUTC(*p++, concat);
12920 if ((p = *ap++) == NULL)
12921 break;
12922 STPUTC(' ', concat);
12923 }
12924 STPUTC('\0', concat);
12925 p = grabstackstr(concat);
12926 } 12909 }
12927 } else 12910 *expression = '\0';
12928 p = ""; 12911 tmp = ++expression;
12929 12912 result = arith(tmp);
12930 i = ash_arith(p); 12913 if (result < 0) {
12931 12914 out2fmt("sh: let: syntax error: \"%s=%s\"\n", argv[1], expression);
12932 printf("%ld\n", i); 12915 return 0;
12933 return (! i); 12916 }
12934} 12917 snprintf(p, 12, "%ld", result);
12935 12918 setvar(argv[1], savestr(p), 0);
12936static long ash_arith(const char *p) 12919 } else if (argc >= 3)
12937{ 12920 synerror("invalid operand");
12938 long i = arith(p); 12921 return !result;
12939 if (i <0)
12940 error("arith: syntax error: \"%s\"\n", p);
12941 return i;
12942} 12922}
12943#endif 12923#endif
12944 12924
diff --git a/shell/ash.c b/shell/ash.c
index 9a5435e8b..15e1adb7c 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -1593,9 +1593,6 @@ __lookupalias(const char *name) {
1593#define ARITH_BNOT 281 1593#define ARITH_BNOT 281
1594 1594
1595static void expari (int); 1595static void expari (int);
1596/* From arith.y */
1597static long ash_arith(const char *p);
1598static int expcmd (int , char **);
1599#endif 1596#endif
1600 1597
1601static char *trap[NSIG]; /* trap handler commands */ 1598static char *trap[NSIG]; /* trap handler commands */
@@ -1647,7 +1644,7 @@ static int waitcmd (int, char **);
1647static int ulimitcmd (int, char **); 1644static int ulimitcmd (int, char **);
1648static int timescmd (int, char **); 1645static int timescmd (int, char **);
1649#ifdef ASH_MATH_SUPPORT 1646#ifdef ASH_MATH_SUPPORT
1650static int expcmd (int, char **); 1647static int letcmd (int, char **);
1651#endif 1648#endif
1652static int typecmd (int, char **); 1649static int typecmd (int, char **);
1653#ifdef ASH_GETOPTS 1650#ifdef ASH_GETOPTS
@@ -1706,9 +1703,6 @@ static const struct builtincmd builtincmds[] = {
1706 { BUILTIN_SPECIAL "eval", evalcmd }, 1703 { BUILTIN_SPECIAL "eval", evalcmd },
1707 { BUILTIN_SPECIAL "exec", execcmd }, 1704 { BUILTIN_SPECIAL "exec", execcmd },
1708 { BUILTIN_SPECIAL "exit", exitcmd }, 1705 { BUILTIN_SPECIAL "exit", exitcmd },
1709#ifdef ASH_MATH_SUPPORT
1710 { BUILTIN_NOSPEC "exp", expcmd },
1711#endif
1712 { BUILTIN_SPEC_ASSG "export", exportcmd }, 1706 { BUILTIN_SPEC_ASSG "export", exportcmd },
1713 { BUILTIN_REGULAR "false", false_main }, 1707 { BUILTIN_REGULAR "false", false_main },
1714 { BUILTIN_REGULAR "fc", histcmd }, 1708 { BUILTIN_REGULAR "fc", histcmd },
@@ -1725,7 +1719,7 @@ static const struct builtincmd builtincmds[] = {
1725 { BUILTIN_REGULAR "kill", killcmd }, 1719 { BUILTIN_REGULAR "kill", killcmd },
1726#endif 1720#endif
1727#ifdef ASH_MATH_SUPPORT 1721#ifdef ASH_MATH_SUPPORT
1728 { BUILTIN_NOSPEC "let", expcmd }, 1722 { BUILTIN_REGULAR "let", letcmd },
1729#endif 1723#endif
1730 { BUILTIN_ASSIGN "local", localcmd }, 1724 { BUILTIN_ASSIGN "local", localcmd },
1731#ifndef BB_PWD 1725#ifndef BB_PWD
@@ -4883,7 +4877,9 @@ expari(int flag)
4883 removerecordregions(begoff); 4877 removerecordregions(begoff);
4884 if (quotes) 4878 if (quotes)
4885 rmescapes(p+2); 4879 rmescapes(p+2);
4886 result = ash_arith(p+2); 4880 result = arith(p+2);
4881 if (result < 0)
4882 error("arith: syntax error: \"%s\"\n", p+2);
4887 snprintf(p, 12, "%d", result); 4883 snprintf(p, 12, "%d", result);
4888 4884
4889 while (*p++) 4885 while (*p++)
@@ -12878,7 +12874,7 @@ findvar(struct var **vpp, const char *name)
12878/* 12874/*
12879 * Copyright (c) 1999 Herbert Xu <herbert@debian.org> 12875 * Copyright (c) 1999 Herbert Xu <herbert@debian.org>
12880 * This file contains code for the times builtin. 12876 * This file contains code for the times builtin.
12881 * $Id: ash.c,v 1.14 2001/07/30 21:41:37 andersen Exp $ 12877 * $Id: ash.c,v 1.15 2001/07/31 21:38:23 andersen Exp $
12882 */ 12878 */
12883static int timescmd (int argc, char **argv) 12879static int timescmd (int argc, char **argv)
12884{ 12880{
@@ -12900,45 +12896,29 @@ static int timescmd (int argc, char **argv)
12900 12896
12901 12897
12902#ifdef ASH_MATH_SUPPORT 12898#ifdef ASH_MATH_SUPPORT
12903/* The exp(1) builtin. */ 12899/* The let builtin. */
12904int expcmd(int argc, char **argv) 12900int letcmd(int argc, char **argv)
12905{ 12901{
12906 const char *p; 12902 long result=0;
12907 char *concat; 12903 if (argc == 2) {
12908 char **ap; 12904 char *tmp, *expression, p[13];
12909 long i; 12905 expression = strchr(argv[1], '=');
12910 12906 if (!expression) {
12911 if (argc > 1) { 12907 out2fmt("sh: let: syntax error: \"%s\"\n", argv[1]);
12912 p = argv[1]; 12908 return 0;
12913 if (argc > 2) {
12914 /* concatenate arguments */
12915 STARTSTACKSTR(concat);
12916 ap = argv + 2;
12917 for (;;) {
12918 while (*p)
12919 STPUTC(*p++, concat);
12920 if ((p = *ap++) == NULL)
12921 break;
12922 STPUTC(' ', concat);
12923 }
12924 STPUTC('\0', concat);
12925 p = grabstackstr(concat);
12926 } 12909 }
12927 } else 12910 *expression = '\0';
12928 p = ""; 12911 tmp = ++expression;
12929 12912 result = arith(tmp);
12930 i = ash_arith(p); 12913 if (result < 0) {
12931 12914 out2fmt("sh: let: syntax error: \"%s=%s\"\n", argv[1], expression);
12932 printf("%ld\n", i); 12915 return 0;
12933 return (! i); 12916 }
12934} 12917 snprintf(p, 12, "%ld", result);
12935 12918 setvar(argv[1], savestr(p), 0);
12936static long ash_arith(const char *p) 12919 } else if (argc >= 3)
12937{ 12920 synerror("invalid operand");
12938 long i = arith(p); 12921 return !result;
12939 if (i <0)
12940 error("arith: syntax error: \"%s\"\n", p);
12941 return i;
12942} 12922}
12943#endif 12923#endif
12944 12924