aboutsummaryrefslogtreecommitdiff
path: root/ash.c
diff options
context:
space:
mode:
Diffstat (limited to 'ash.c')
-rw-r--r--ash.c105
1 files changed, 56 insertions, 49 deletions
diff --git a/ash.c b/ash.c
index bb5bf3601..9a5435e8b 100644
--- a/ash.c
+++ b/ash.c
@@ -51,9 +51,8 @@
51#define ASH_ALIAS 51#define ASH_ALIAS
52 52
53/* If you need ash to act as a full Posix shell, with full math 53/* If you need ash to act as a full Posix shell, with full math
54 * support, enable this. This option needs some work, since it 54 * support, enable this. This adds a bit over 2k an x86 system. */
55 * doesn't compile right now... */ 55#define ASH_MATH_SUPPORT
56#undef ASH_MATH_SUPPORT
57 56
58/* Getopts is used by shell procedures to parse positional parameters. 57/* Getopts is used by shell procedures to parse positional parameters.
59 * You probably want to leave this disabled, and use the busybox getopt 58 * You probably want to leave this disabled, and use the busybox getopt
@@ -80,6 +79,7 @@
80#undef FNMATCH_BROKEN 79#undef FNMATCH_BROKEN
81#undef GLOB_BROKEN 80#undef GLOB_BROKEN
82#undef _GNU_SOURCE 81#undef _GNU_SOURCE
82#undef __USE_GNU
83 83
84#include <assert.h> 84#include <assert.h>
85#include <ctype.h> 85#include <ctype.h>
@@ -1562,8 +1562,10 @@ __lookupalias(const char *name) {
1562#endif 1562#endif
1563 1563
1564#ifdef ASH_MATH_SUPPORT 1564#ifdef ASH_MATH_SUPPORT
1565/* The generated file arith.c has been snipped. If you want this 1565/* The generated file arith.c has been replaced with a custom hand
1566 * stuff back in, feel free to add it to your own copy. */ 1566 * written implementation written by Aaron Lehmann <aaronl@vitelus.com>.
1567 * This is now part of libbb, so that it can be used by all the shells
1568 * in busybox. */
1567#define ARITH_NUM 257 1569#define ARITH_NUM 257
1568#define ARITH_LPAREN 258 1570#define ARITH_LPAREN 258
1569#define ARITH_RPAREN 259 1571#define ARITH_RPAREN 259
@@ -1592,11 +1594,8 @@ __lookupalias(const char *name) {
1592 1594
1593static void expari (int); 1595static void expari (int);
1594/* From arith.y */ 1596/* From arith.y */
1595static int arith (const char *); 1597static long ash_arith(const char *p);
1596static int expcmd (int , char **); 1598static int expcmd (int , char **);
1597static void arith_lex_reset (void);
1598static int yylex (void);
1599
1600#endif 1599#endif
1601 1600
1602static char *trap[NSIG]; /* trap handler commands */ 1601static char *trap[NSIG]; /* trap handler commands */
@@ -2173,52 +2172,22 @@ exverror(int cond, const char *msg, va_list ap)
2173} 2172}
2174 2173
2175 2174
2176#ifdef __STDC__ 2175static void
2177static void
2178error(const char *msg, ...) 2176error(const char *msg, ...)
2179#else
2180static void
2181error(va_alist)
2182 va_dcl
2183#endif
2184{ 2177{
2185#ifndef __STDC__
2186 const char *msg;
2187#endif
2188 va_list ap; 2178 va_list ap;
2189#ifdef __STDC__
2190 va_start(ap, msg); 2179 va_start(ap, msg);
2191#else
2192 va_start(ap);
2193 msg = va_arg(ap, const char *);
2194#endif
2195 exverror(EXERROR, msg, ap); 2180 exverror(EXERROR, msg, ap);
2196 /* NOTREACHED */ 2181 /* NOTREACHED */
2197 va_end(ap); 2182 va_end(ap);
2198} 2183}
2199 2184
2200 2185
2201#ifdef __STDC__
2202static void 2186static void
2203exerror(int cond, const char *msg, ...) 2187exerror(int cond, const char *msg, ...)
2204#else
2205static void
2206exerror(va_alist)
2207 va_dcl
2208#endif
2209{ 2188{
2210#ifndef __STDC__
2211 int cond;
2212 const char *msg;
2213#endif
2214 va_list ap; 2189 va_list ap;
2215#ifdef __STDC__
2216 va_start(ap, msg); 2190 va_start(ap, msg);
2217#else
2218 va_start(ap);
2219 cond = va_arg(ap, int);
2220 msg = va_arg(ap, const char *);
2221#endif
2222 exverror(cond, msg, ap); 2191 exverror(cond, msg, ap);
2223 /* NOTREACHED */ 2192 /* NOTREACHED */
2224 va_end(ap); 2193 va_end(ap);
@@ -4914,7 +4883,7 @@ expari(int flag)
4914 removerecordregions(begoff); 4883 removerecordregions(begoff);
4915 if (quotes) 4884 if (quotes)
4916 rmescapes(p+2); 4885 rmescapes(p+2);
4917 result = arith(p+2); 4886 result = ash_arith(p+2);
4918 snprintf(p, 12, "%d", result); 4887 snprintf(p, 12, "%d", result);
4919 4888
4920 while (*p++) 4889 while (*p++)
@@ -11952,13 +11921,7 @@ static void
11952trace(const char *fmt, ...) 11921trace(const char *fmt, ...)
11953{ 11922{
11954 va_list va; 11923 va_list va;
11955#ifdef __STDC__
11956 va_start(va, fmt); 11924 va_start(va, fmt);
11957#else
11958 char *fmt;
11959 va_start(va);
11960 fmt = va_arg(va, char *);
11961#endif
11962 if (tracefile != NULL) { 11925 if (tracefile != NULL) {
11963 (void) vfprintf(tracefile, fmt, va); 11926 (void) vfprintf(tracefile, fmt, va);
11964 if (strchr(fmt, '\n')) 11927 if (strchr(fmt, '\n'))
@@ -12657,7 +12620,6 @@ found:;
12657 return 0; 12620 return 0;
12658} 12621}
12659 12622
12660
12661/* 12623/*
12662 * The "local" command. 12624 * The "local" command.
12663 */ 12625 */
@@ -12916,7 +12878,7 @@ findvar(struct var **vpp, const char *name)
12916/* 12878/*
12917 * Copyright (c) 1999 Herbert Xu <herbert@debian.org> 12879 * Copyright (c) 1999 Herbert Xu <herbert@debian.org>
12918 * This file contains code for the times builtin. 12880 * This file contains code for the times builtin.
12919 * $Id: ash.c,v 1.13 2001/07/26 05:58:40 russ Exp $ 12881 * $Id: ash.c,v 1.14 2001/07/30 21:41:37 andersen Exp $
12920 */ 12882 */
12921static int timescmd (int argc, char **argv) 12883static int timescmd (int argc, char **argv)
12922{ 12884{
@@ -12937,6 +12899,51 @@ static int timescmd (int argc, char **argv)
12937} 12899}
12938 12900
12939 12901
12902#ifdef ASH_MATH_SUPPORT
12903/* The exp(1) builtin. */
12904int expcmd(int argc, char **argv)
12905{
12906 const char *p;
12907 char *concat;
12908 char **ap;
12909 long i;
12910
12911 if (argc > 1) {
12912 p = argv[1];
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 }
12927 } else
12928 p = "";
12929
12930 i = ash_arith(p);
12931
12932 printf("%ld\n", i);
12933 return (! i);
12934}
12935
12936static long ash_arith(const char *p)
12937{
12938 long i = arith(p);
12939 if (i <0)
12940 error("arith: syntax error: \"%s\"\n", p);
12941 return i;
12942}
12943#endif
12944
12945
12946
12940/*- 12947/*-
12941 * Copyright (c) 1989, 1991, 1993, 1994 12948 * Copyright (c) 1989, 1991, 1993, 1994
12942 * The Regents of the University of California. All rights reserved. 12949 * The Regents of the University of California. All rights reserved.