summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-07-29 06:38:40 +0000
committerEric Andersen <andersen@codepoet.org>2003-07-29 06:38:40 +0000
commit81fe123040b53490b239b3d2abc8cc93d6d462ae (patch)
treec3f501afd6305ff9415e5a9ab5e371d7fc2db101 /shell
parent9cdef5d9286839a0b787c25f41633508f8623765 (diff)
downloadbusybox-w32-81fe123040b53490b239b3d2abc8cc93d6d462ae.tar.gz
busybox-w32-81fe123040b53490b239b3d2abc8cc93d6d462ae.tar.bz2
busybox-w32-81fe123040b53490b239b3d2abc8cc93d6d462ae.zip
Vladimir N. Oleynik writes:
Last patch have synced form Manuel Nova III xxreadtoken() function, corrected (C) form dash debian/copyright, removed my small mistake with IFS_BROKEN (thanks by Herbert), and synced cmdedit.c from current CVS (removed libc5 support, your email correction, my (C) year corertion).
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c120
-rw-r--r--shell/cmdedit.c10
2 files changed, 97 insertions, 33 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 334dc2235..f852b26d3 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -5,6 +5,10 @@
5 * Copyright (c) 1989, 1991, 1993, 1994 5 * Copyright (c) 1989, 1991, 1993, 1994
6 * The Regents of the University of California. All rights reserved. 6 * The Regents of the University of California. All rights reserved.
7 * 7 *
8 * Copyright (c) 1997-2003 Herbert Xu <herbert@debian.org>
9 * was re-ported from NetBSD and debianized.
10 *
11 *
8 * This code is derived from software contributed to Berkeley by 12 * This code is derived from software contributed to Berkeley by
9 * Kenneth Almquist. 13 * Kenneth Almquist.
10 * 14 *
@@ -22,14 +26,11 @@
22 * along with this program; if not, write to the Free Software 26 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * 28 *
25 * This version of ash is adapted from the source in Debian's ash 0.3.8-5
26 * package.
27 * Maintainer Herbert Xu <herbert@debian.org> (C) 1997-2002
28 * 29 *
29 * Modified by Vladimir Oleynik <dzo@simtreas.ru> to be used in busybox 30 * Modified by Vladimir Oleynik <dzo@simtreas.ru> to be used in busybox
30 * 31 *
31 * 32 *
32 * Original copyright notice is retained at the end of this file. 33 * Original BSD copyright notice is retained at the end of this file.
33 */ 34 */
34 35
35/* 36/*
@@ -1485,8 +1486,11 @@ static const char defpathvar[] =
1485 "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"; 1486 "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
1486#ifdef IFS_BROKEN 1487#ifdef IFS_BROKEN
1487static const char defifsvar[] = "IFS= \t\n"; 1488static const char defifsvar[] = "IFS= \t\n";
1488#endif 1489#define defifs (defifsvar + 4)
1490#else
1489static const char defifs[] = " \t\n"; 1491static const char defifs[] = " \t\n";
1492#endif
1493
1490 1494
1491static struct var varinit[] = { 1495static struct var varinit[] = {
1492#ifdef IFS_BROKEN 1496#ifdef IFS_BROKEN
@@ -9848,6 +9852,89 @@ out:
9848 * have parseword (readtoken1?) handle both words and redirection.] 9852 * have parseword (readtoken1?) handle both words and redirection.]
9849 */ 9853 */
9850 9854
9855#define NEW_xxreadtoken
9856#ifdef NEW_xxreadtoken
9857
9858/* singles must be first! */
9859static const char xxreadtoken_chars[7] = { '\n', '(', ')', '&', '|', ';', 0 };
9860
9861static const char xxreadtoken_tokens[] = {
9862 TNL, TLP, TRP, /* only single occurrence allowed */
9863 TBACKGND, TPIPE, TSEMI, /* if single occurrence */
9864 TEOF, /* corresponds to trailing nul */
9865 TAND, TOR, TENDCASE, /* if double occurrence */
9866};
9867
9868#define xxreadtoken_doubles \
9869 (sizeof(xxreadtoken_tokens) - sizeof(xxreadtoken_chars))
9870#define xxreadtoken_singles \
9871 (sizeof(xxreadtoken_chars) - xxreadtoken_doubles - 1)
9872
9873static int xxreadtoken()
9874{
9875 int c;
9876
9877 if (tokpushback) {
9878 tokpushback = 0;
9879 return lasttoken;
9880 }
9881 if (needprompt) {
9882 setprompt(2);
9883 needprompt = 0;
9884 }
9885 startlinno = plinno;
9886 for (;;) { /* until token or start of word found */
9887 c = pgetc_macro();
9888
9889 if ((c != ' ') && (c != '\t')
9890#ifdef CONFIG_ASH_ALIAS
9891 && (c != PEOA)
9892#endif
9893 ) {
9894 if (c == '#') {
9895 while ((c = pgetc()) != '\n' && c != PEOF);
9896 pungetc();
9897 } else if (c == '\\') {
9898 if (pgetc() != '\n') {
9899 pungetc();
9900 goto READTOKEN1;
9901 }
9902 startlinno = ++plinno;
9903 if (doprompt)
9904 setprompt(2);
9905 } else {
9906 const char *p
9907 = xxreadtoken_chars + sizeof(xxreadtoken_chars) - 1;
9908
9909 if (c != PEOF) {
9910 if (c == '\n') {
9911 plinno++;
9912 needprompt = doprompt;
9913 }
9914
9915 p = strchr(xxreadtoken_chars, c);
9916 if (p == NULL) {
9917 READTOKEN1:
9918 return readtoken1(c, BASESYNTAX, (char *) NULL, 0);
9919 }
9920
9921 if (p - xxreadtoken_chars >= xxreadtoken_singles) {
9922 if (pgetc() == *p) { /* double occurrence? */
9923 p += xxreadtoken_doubles + 1;
9924 } else {
9925 pungetc();
9926 }
9927 }
9928 }
9929
9930 return lasttoken = xxreadtoken_tokens[p - xxreadtoken_chars];
9931 }
9932 }
9933 }
9934}
9935
9936
9937#else
9851#define RETURN(token) return lasttoken = token 9938#define RETURN(token) return lasttoken = token
9852 9939
9853static int 9940static int
@@ -9918,7 +10005,7 @@ breakloop:
9918 return readtoken1(c, BASESYNTAX, (char *)NULL, 0); 10005 return readtoken1(c, BASESYNTAX, (char *)NULL, 0);
9919#undef RETURN 10006#undef RETURN
9920} 10007}
9921 10008#endif /* NEW_xxreadtoken */
9922 10009
9923 10010
9924/* 10011/*
@@ -10909,10 +10996,6 @@ redirect(union node *redir, int flags)
10909} 10996}
10910 10997
10911 10998
10912
10913
10914
10915
10916/* 10999/*
10917 * Undo the effects of the last redirection. 11000 * Undo the effects of the last redirection.
10918 */ 11001 */
@@ -10962,7 +11045,6 @@ clearredir(int drop)
10962} 11045}
10963 11046
10964 11047
10965
10966/* 11048/*
10967 * Copy a file descriptor to be >= to. Returns -1 11049 * Copy a file descriptor to be >= to. Returns -1
10968 * if the source file descriptor is closed, EMPTY if there are no unused 11050 * if the source file descriptor is closed, EMPTY if there are no unused
@@ -11073,7 +11155,6 @@ binop:
11073} 11155}
11074 11156
11075 11157
11076
11077static void 11158static void
11078shcmd(union node *cmd, FILE *fp) 11159shcmd(union node *cmd, FILE *fp)
11079{ 11160{
@@ -11422,7 +11503,6 @@ trapcmd(int argc, char **argv)
11422} 11503}
11423 11504
11424 11505
11425
11426/* 11506/*
11427 * Clear traps on a fork. 11507 * Clear traps on a fork.
11428 */ 11508 */
@@ -11445,7 +11525,6 @@ clear_traps(void)
11445} 11525}
11446 11526
11447 11527
11448
11449/* 11528/*
11450 * Set the signal handler for the specified signal. The routine figures 11529 * Set the signal handler for the specified signal. The routine figures
11451 * out what it should be set to. 11530 * out what it should be set to.
@@ -11546,7 +11625,6 @@ ignoresig(int signo)
11546} 11625}
11547 11626
11548 11627
11549
11550/* 11628/*
11551 * Signal handler. 11629 * Signal handler.
11552 */ 11630 */
@@ -11565,7 +11643,6 @@ onsig(int signo)
11565} 11643}
11566 11644
11567 11645
11568
11569/* 11646/*
11570 * Called to execute a trap. Perhaps we should avoid entering new trap 11647 * Called to execute a trap. Perhaps we should avoid entering new trap
11571 * handlers while we are executing a trap handler. 11648 * handlers while we are executing a trap handler.
@@ -11591,12 +11668,10 @@ dotrap(void)
11591} 11668}
11592 11669
11593 11670
11594
11595/* 11671/*
11596 * Controls whether the shell is interactive or not. 11672 * Controls whether the shell is interactive or not.
11597 */ 11673 */
11598 11674
11599
11600void 11675void
11601setinteractive(int on) 11676setinteractive(int on)
11602{ 11677{
@@ -11691,7 +11766,6 @@ exitshell(void)
11691 } 11766 }
11692#endif 11767#endif
11693out: 11768out:
11694 out1c('\n');
11695 _exit(status); 11769 _exit(status);
11696 /* NOTREACHED */ 11770 /* NOTREACHED */
11697} 11771}
@@ -11780,7 +11854,6 @@ setvar(const char *name, const char *val, int flags)
11780} 11854}
11781 11855
11782 11856
11783
11784/* 11857/*
11785 * Same as setvar except that the variable and value are passed in 11858 * Same as setvar except that the variable and value are passed in
11786 * the first argument as name=value. Since the first argument will 11859 * the first argument as name=value. Since the first argument will
@@ -11830,7 +11903,6 @@ setvareq(char *s, int flags)
11830} 11903}
11831 11904
11832 11905
11833
11834/* 11906/*
11835 * Process a linked list of variable assignments. 11907 * Process a linked list of variable assignments.
11836 */ 11908 */
@@ -11866,7 +11938,6 @@ lookupvar(const char *name)
11866} 11938}
11867 11939
11868 11940
11869
11870/* 11941/*
11871 * Search the environment of a builtin command. 11942 * Search the environment of a builtin command.
11872 */ 11943 */
@@ -11884,7 +11955,6 @@ bltinlookup(const char *name)
11884} 11955}
11885 11956
11886 11957
11887
11888/* 11958/*
11889 * Generate a list of variables satisfying the given conditions. 11959 * Generate a list of variables satisfying the given conditions.
11890 */ 11960 */
@@ -11917,7 +11987,6 @@ listvars(int on, int off, char ***end)
11917} 11987}
11918 11988
11919 11989
11920
11921/* 11990/*
11922 * POSIX requires that 'set' (but not export or readonly) output the 11991 * POSIX requires that 'set' (but not export or readonly) output the
11923 * variables in lexicographic order - by the locale's collating order (sigh). 11992 * variables in lexicographic order - by the locale's collating order (sigh).
@@ -12054,7 +12123,6 @@ localcmd(int argc, char **argv)
12054 12123
12055 12124
12056 12125
12057
12058/* 12126/*
12059 * Called after a function returns. 12127 * Called after a function returns.
12060 * Interrupts must be off. 12128 * Interrupts must be off.
@@ -12568,7 +12636,7 @@ ulimitcmd(int argc, char **argv)
12568 12636
12569 if (all || argptr[1]) 12637 if (all || argptr[1])
12570 error("too many arguments"); 12638 error("too many arguments");
12571 if (strcmp(p, "unlimited") == 0) 12639 if (strncmp(p, "unlimited\n", 9) == 0)
12572 val = RLIM_INFINITY; 12640 val = RLIM_INFINITY;
12573 else { 12641 else {
12574 val = (rlim_t) 0; 12642 val = (rlim_t) 0;
diff --git a/shell/cmdedit.c b/shell/cmdedit.c
index 717067267..0ab195803 100644
--- a/shell/cmdedit.c
+++ b/shell/cmdedit.c
@@ -2,14 +2,14 @@
2/* 2/*
3 * Termios command line History and Editting. 3 * Termios command line History and Editting.
4 * 4 *
5 * Copyright (c) 1986-2001 may safely be consumed by a BSD or GPL license. 5 * Copyright (c) 1986-2003 may safely be consumed by a BSD or GPL license.
6 * Written by: Vladimir Oleynik <dzo@simtreas.ru> 6 * Written by: Vladimir Oleynik <dzo@simtreas.ru>
7 * 7 *
8 * Used ideas: 8 * Used ideas:
9 * Adam Rogoyski <rogoyski@cs.utexas.edu> 9 * Adam Rogoyski <rogoyski@cs.utexas.edu>
10 * Dave Cinege <dcinege@psychosis.com> 10 * Dave Cinege <dcinege@psychosis.com>
11 * Jakub Jelinek (c) 1995 11 * Jakub Jelinek (c) 1995
12 * Erik Andersen <andersee@debian.org> (Majorly adjusted for busybox) 12 * Erik Andersen <andersen@codepoet.org> (Majorly adjusted for busybox)
13 * 13 *
14 * This code is 'as is' with no warranty. 14 * This code is 'as is' with no warranty.
15 * 15 *
@@ -163,11 +163,6 @@ static int my_gid;
163 163
164#endif /* CONFIG_FEATURE_COMMAND_TAB_COMPLETION */ 164#endif /* CONFIG_FEATURE_COMMAND_TAB_COMPLETION */
165 165
166/* It seems that libc5 doesn't know what a sighandler_t is... */
167#if (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 1)
168typedef void (*sighandler_t) (int);
169#endif
170
171static void cmdedit_setwidth(int w, int redraw_flg); 166static void cmdedit_setwidth(int w, int redraw_flg);
172 167
173static void win_changed(int nsig) 168static void win_changed(int nsig)
@@ -264,6 +259,7 @@ static inline void out1str(const char *s)
264 if ( s ) 259 if ( s )
265 fputs(s, stdout); 260 fputs(s, stdout);
266} 261}
262
267static inline void beep(void) 263static inline void beep(void)
268{ 264{
269 putchar('\007'); 265 putchar('\007');