diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-02-23 21:09:49 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-02-23 21:09:49 +0000 |
commit | 92cc1717a9e2a69b24ba4ff44f1fce702d9edf88 (patch) | |
tree | 6d6f6cf5efa560293151f8fe53258bc72dd1a99d /shell | |
parent | 11d0c5d3f69fc689695067cf1512aa652f806bb3 (diff) | |
download | busybox-w32-92cc1717a9e2a69b24ba4ff44f1fce702d9edf88.tar.gz busybox-w32-92cc1717a9e2a69b24ba4ff44f1fce702d9edf88.tar.bz2 busybox-w32-92cc1717a9e2a69b24ba4ff44f1fce702d9edf88.zip |
ash: cleanup part 2.3
git-svn-id: svn://busybox.net/trunk/busybox@17965 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 143 |
1 files changed, 69 insertions, 74 deletions
diff --git a/shell/ash.c b/shell/ash.c index 6f3142952..e3a43979a 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -436,11 +436,6 @@ out2str(const char *p) | |||
436 | #define VSTRIMLEFTMAX 0x9 /* ${var##pattern} */ | 436 | #define VSTRIMLEFTMAX 0x9 /* ${var##pattern} */ |
437 | #define VSLENGTH 0xa /* ${#var} */ | 437 | #define VSLENGTH 0xa /* ${#var} */ |
438 | 438 | ||
439 | /* values of checkkwd variable */ | ||
440 | #define CHKALIAS 0x1 | ||
441 | #define CHKKWD 0x2 | ||
442 | #define CHKNL 0x4 | ||
443 | |||
444 | #define NCMD 0 | 439 | #define NCMD 0 |
445 | #define NPIPE 1 | 440 | #define NPIPE 1 |
446 | #define NREDIR 2 | 441 | #define NREDIR 2 |
@@ -2393,48 +2388,15 @@ pwdcmd(int argc, char **argv) | |||
2393 | 2388 | ||
2394 | /* ============ ... */ | 2389 | /* ============ ... */ |
2395 | 2390 | ||
2396 | /* | ||
2397 | * NEOF is returned by parsecmd when it encounters an end of file. It | ||
2398 | * must be distinct from NULL, so we use the address of a variable that | ||
2399 | * happens to be handy. | ||
2400 | */ | ||
2401 | static int plinno = 1; /* input line number */ | ||
2402 | |||
2403 | /* number of characters left in input buffer */ | ||
2404 | static int parsenleft; /* copy of parsefile->nleft */ | ||
2405 | static int parselleft; /* copy of parsefile->lleft */ | ||
2406 | |||
2407 | /* next character in input buffer */ | ||
2408 | static char *parsenextc; /* copy of parsefile->nextc */ | ||
2409 | |||
2410 | #define IBUFSIZ (BUFSIZ + 1) | 2391 | #define IBUFSIZ (BUFSIZ + 1) |
2411 | #define basebuf bb_common_bufsiz1 /* buffer for top level input file */ | 2392 | #define basebuf bb_common_bufsiz1 /* buffer for top level input file */ |
2412 | 2393 | ||
2413 | static int tokpushback; /* last token pushed back */ | ||
2414 | #define NEOF ((union node *)&tokpushback) | ||
2415 | static int parsebackquote; /* nonzero if we are inside backquotes */ | ||
2416 | static int lasttoken; /* last token read */ | ||
2417 | static char *wordtext; /* text of last word returned by readtoken */ | ||
2418 | static int checkkwd; | ||
2419 | static struct nodelist *backquotelist; | ||
2420 | static union node *redirnode; | ||
2421 | static struct heredoc *heredoc; | ||
2422 | static int quoteflag; /* set if (part of) last token was quoted */ | ||
2423 | |||
2424 | static void fixredir(union node *, const char *, int); | ||
2425 | |||
2426 | 2394 | ||
2427 | /* shell.h */ | 2395 | /* shell.h */ |
2428 | 2396 | ||
2429 | static const char spcstr[] = " "; | 2397 | static const char spcstr[] = " "; |
2430 | static const char dolatstr[] = { CTLVAR, VSNORMAL|VSQUOTE, '@', '=', '\0' }; | 2398 | static const char dolatstr[] = { CTLVAR, VSNORMAL|VSQUOTE, '@', '=', '\0' }; |
2431 | 2399 | ||
2432 | #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96) | ||
2433 | #define __builtin_expect(x, expected_value) (x) | ||
2434 | #endif | ||
2435 | |||
2436 | #define xlikely(x) __builtin_expect((x),1) | ||
2437 | |||
2438 | /* Syntax classes */ | 2400 | /* Syntax classes */ |
2439 | #define CWORD 0 /* character is nothing special */ | 2401 | #define CWORD 0 /* character is nothing special */ |
2440 | #define CNL 1 /* newline character */ | 2402 | #define CNL 1 /* newline character */ |
@@ -2996,40 +2958,6 @@ static void clearredir(int); | |||
2996 | static int copyfd(int, int); | 2958 | static int copyfd(int, int); |
2997 | static int redirectsafe(union node *, int); | 2959 | static int redirectsafe(union node *, int); |
2998 | 2960 | ||
2999 | static int is_safe_applet(char *name) | ||
3000 | { | ||
3001 | /* It isn't a bug to have non-existent applet here... */ | ||
3002 | /* ...just a waste of space... */ | ||
3003 | static const char safe_applets[][8] = { | ||
3004 | "[" | ||
3005 | USE_AWK (, "awk" ) | ||
3006 | USE_CAT (, "cat" ) | ||
3007 | USE_CHMOD (, "chmod" ) | ||
3008 | USE_CHOWN (, "chown" ) | ||
3009 | USE_CP (, "cp" ) | ||
3010 | USE_CUT (, "cut" ) | ||
3011 | USE_DD (, "dd" ) | ||
3012 | USE_ECHO (, "echo" ) | ||
3013 | USE_FIND (, "find" ) | ||
3014 | USE_HEXDUMP(, "hexdump") | ||
3015 | USE_LN (, "ln" ) | ||
3016 | USE_LS (, "ls" ) | ||
3017 | USE_MKDIR (, "mkdir" ) | ||
3018 | USE_RM (, "rm" ) | ||
3019 | USE_SORT (, "sort" ) | ||
3020 | USE_TEST (, "test" ) | ||
3021 | USE_TOUCH (, "touch" ) | ||
3022 | USE_XARGS (, "xargs" ) | ||
3023 | }; | ||
3024 | int n = sizeof(safe_applets) / sizeof(safe_applets[0]); | ||
3025 | int i; | ||
3026 | for (i = 0; i < n; i++) | ||
3027 | if (strcmp(safe_applets[i], name) == 0) | ||
3028 | return 1; | ||
3029 | |||
3030 | return 0; | ||
3031 | } | ||
3032 | |||
3033 | 2961 | ||
3034 | /* ============ Alias handling */ | 2962 | /* ============ Alias handling */ |
3035 | 2963 | ||
@@ -4720,6 +4648,40 @@ casematch(union node *pattern, char *val) | |||
4720 | 4648 | ||
4721 | /* ============ find_command */ | 4649 | /* ============ find_command */ |
4722 | 4650 | ||
4651 | static int is_safe_applet(char *name) | ||
4652 | { | ||
4653 | /* It isn't a bug to have non-existent applet here... */ | ||
4654 | /* ...just a waste of space... */ | ||
4655 | static const char safe_applets[][8] = { | ||
4656 | "[" | ||
4657 | USE_AWK (, "awk" ) | ||
4658 | USE_CAT (, "cat" ) | ||
4659 | USE_CHMOD (, "chmod" ) | ||
4660 | USE_CHOWN (, "chown" ) | ||
4661 | USE_CP (, "cp" ) | ||
4662 | USE_CUT (, "cut" ) | ||
4663 | USE_DD (, "dd" ) | ||
4664 | USE_ECHO (, "echo" ) | ||
4665 | USE_FIND (, "find" ) | ||
4666 | USE_HEXDUMP(, "hexdump") | ||
4667 | USE_LN (, "ln" ) | ||
4668 | USE_LS (, "ls" ) | ||
4669 | USE_MKDIR (, "mkdir" ) | ||
4670 | USE_RM (, "rm" ) | ||
4671 | USE_SORT (, "sort" ) | ||
4672 | USE_TEST (, "test" ) | ||
4673 | USE_TOUCH (, "touch" ) | ||
4674 | USE_XARGS (, "xargs" ) | ||
4675 | }; | ||
4676 | int n = sizeof(safe_applets) / sizeof(safe_applets[0]); | ||
4677 | int i; | ||
4678 | for (i = 0; i < n; i++) | ||
4679 | if (strcmp(safe_applets[i], name) == 0) | ||
4680 | return 1; | ||
4681 | |||
4682 | return 0; | ||
4683 | } | ||
4684 | |||
4723 | struct builtincmd { | 4685 | struct builtincmd { |
4724 | const char *name; | 4686 | const char *name; |
4725 | int (*builtin)(int, char **); | 4687 | int (*builtin)(int, char **); |
@@ -5957,6 +5919,7 @@ evalsubshell(union node *n, int flags) | |||
5957 | /* | 5919 | /* |
5958 | * Compute the names of the files in a redirection list. | 5920 | * Compute the names of the files in a redirection list. |
5959 | */ | 5921 | */ |
5922 | static void fixredir(union node *, const char *, int); | ||
5960 | static void | 5923 | static void |
5961 | expredir(union node *n) | 5924 | expredir(union node *n) |
5962 | { | 5925 | { |
@@ -6943,6 +6906,7 @@ execcmd(int argc, char **argv) | |||
6943 | * | 6906 | * |
6944 | * This implements the input routines used by the parser. | 6907 | * This implements the input routines used by the parser. |
6945 | */ | 6908 | */ |
6909 | |||
6946 | #define EOF_NLEFT -99 /* value of parsenleft when EOF pushed back */ | 6910 | #define EOF_NLEFT -99 /* value of parsenleft when EOF pushed back */ |
6947 | 6911 | ||
6948 | enum { | 6912 | enum { |
@@ -6950,6 +6914,25 @@ enum { | |||
6950 | INPUT_NOFILE_OK = 2, | 6914 | INPUT_NOFILE_OK = 2, |
6951 | }; | 6915 | }; |
6952 | 6916 | ||
6917 | /* | ||
6918 | * NEOF is returned by parsecmd when it encounters an end of file. It | ||
6919 | * must be distinct from NULL, so we use the address of a variable that | ||
6920 | * happens to be handy. | ||
6921 | */ | ||
6922 | static int plinno = 1; /* input line number */ | ||
6923 | /* number of characters left in input buffer */ | ||
6924 | static int parsenleft; /* copy of parsefile->nleft */ | ||
6925 | static int parselleft; /* copy of parsefile->lleft */ | ||
6926 | /* next character in input buffer */ | ||
6927 | static char *parsenextc; /* copy of parsefile->nextc */ | ||
6928 | |||
6929 | static int checkkwd; | ||
6930 | /* values of checkkwd variable */ | ||
6931 | #define CHKALIAS 0x1 | ||
6932 | #define CHKKWD 0x2 | ||
6933 | #define CHKNL 0x4 | ||
6934 | |||
6935 | |||
6953 | static void | 6936 | static void |
6954 | popstring(void) | 6937 | popstring(void) |
6955 | { | 6938 | { |
@@ -8255,7 +8238,7 @@ growjobtab(void) | |||
8255 | jq--; | 8238 | jq--; |
8256 | #define joff(p) ((struct job *)((char *)(p) + l)) | 8239 | #define joff(p) ((struct job *)((char *)(p) + l)) |
8257 | #define jmove(p) (p) = (void *)((char *)(p) + offset) | 8240 | #define jmove(p) (p) = (void *)((char *)(p) + offset) |
8258 | if (xlikely(joff(jp)->ps == &jq->ps0)) | 8241 | if (joff(jp)->ps == &jq->ps0) |
8259 | jmove(joff(jp)->ps); | 8242 | jmove(joff(jp)->ps); |
8260 | if (joff(jp)->prev_job) | 8243 | if (joff(jp)->prev_job) |
8261 | jmove(joff(jp)->prev_job); | 8244 | jmove(joff(jp)->prev_job); |
@@ -9335,6 +9318,16 @@ getoptscmd(int argc, char **argv) | |||
9335 | 9318 | ||
9336 | /* ============ Shell parser */ | 9319 | /* ============ Shell parser */ |
9337 | 9320 | ||
9321 | static int tokpushback; /* last token pushed back */ | ||
9322 | #define NEOF ((union node *)&tokpushback) | ||
9323 | static int parsebackquote; /* nonzero if we are inside backquotes */ | ||
9324 | static int lasttoken; /* last token read */ | ||
9325 | static char *wordtext; /* text of last word returned by readtoken */ | ||
9326 | static struct nodelist *backquotelist; | ||
9327 | static union node *redirnode; | ||
9328 | static struct heredoc *heredoc; | ||
9329 | static int quoteflag; /* set if (part of) last token was quoted */ | ||
9330 | |||
9338 | static void raise_error_syntax(const char *) ATTRIBUTE_NORETURN; | 9331 | static void raise_error_syntax(const char *) ATTRIBUTE_NORETURN; |
9339 | static void | 9332 | static void |
9340 | raise_error_syntax(const char *msg) | 9333 | raise_error_syntax(const char *msg) |
@@ -9887,6 +9880,8 @@ parse_command(void) | |||
9887 | * will run code that appears at the end of readtoken1. | 9880 | * will run code that appears at the end of readtoken1. |
9888 | */ | 9881 | */ |
9889 | 9882 | ||
9883 | static int parsebackquote; /* nonzero if we are inside backquotes */ | ||
9884 | |||
9890 | #define CHECKEND() {goto checkend; checkend_return:;} | 9885 | #define CHECKEND() {goto checkend; checkend_return:;} |
9891 | #define PARSEREDIR() {goto parseredir; parseredir_return:;} | 9886 | #define PARSEREDIR() {goto parseredir; parseredir_return:;} |
9892 | #define PARSESUB() {goto parsesub; parsesub_return:;} | 9887 | #define PARSESUB() {goto parsesub; parsesub_return:;} |
@@ -10077,7 +10072,7 @@ readtoken1(int firstc, int syntax, char *eofmark, int striptabs) | |||
10077 | if (syntax == ARISYNTAX) | 10072 | if (syntax == ARISYNTAX) |
10078 | raise_error_syntax("Missing '))'"); | 10073 | raise_error_syntax("Missing '))'"); |
10079 | #endif | 10074 | #endif |
10080 | if (syntax != BASESYNTAX && ! parsebackquote && eofmark == NULL) | 10075 | if (syntax != BASESYNTAX && !parsebackquote && eofmark == NULL) |
10081 | raise_error_syntax("Unterminated quoted string"); | 10076 | raise_error_syntax("Unterminated quoted string"); |
10082 | if (varnest != 0) { | 10077 | if (varnest != 0) { |
10083 | startlinno = plinno; | 10078 | startlinno = plinno; |