diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-14 15:50:55 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-14 15:50:55 +0000 |
commit | dd316dd283704b9adb588c3fb7cdec6ba5fbceb8 (patch) | |
tree | 7e5a4f524e01190d04bc79a4814c4ff6dce9d40d | |
parent | a84420062a1e7a6e149b7d1ca77e1a787e55d45b (diff) | |
download | busybox-w32-dd316dd283704b9adb588c3fb7cdec6ba5fbceb8.tar.gz busybox-w32-dd316dd283704b9adb588c3fb7cdec6ba5fbceb8.tar.bz2 busybox-w32-dd316dd283704b9adb588c3fb7cdec6ba5fbceb8.zip |
hush: add support for ':'; create testsuite entries
text data bss dec hex filename
809569 612 7044 817225 c7849 busybox_old
809528 612 7044 817184 c7820 busybox_unstripped
-rwxr-xr-x | scripts/trylink | 14 | ||||
-rw-r--r-- | shell/hush.c | 36 | ||||
-rw-r--r-- | shell/hush_test/hush-bugs/glob_and_assign.right | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | shell/hush_test/hush-bugs/glob_and_assign.tests (renamed from shell/hush_test/zbad2) | 3 | ||||
-rw-r--r-- | shell/hush_test/hush-bugs/glob_and_vars.right | 1 | ||||
-rwxr-xr-x | shell/hush_test/hush-bugs/glob_and_vars.tests | 2 | ||||
-rw-r--r-- | shell/hush_test/hush-bugs/while_in_subshell.right | 1 | ||||
-rwxr-xr-x | shell/hush_test/hush-bugs/while_in_subshell.tests | 2 | ||||
-rw-r--r-- | shell/hush_test/hush-misc/colon.right | 2 | ||||
-rwxr-xr-x | shell/hush_test/hush-misc/colon.tests | 6 | ||||
-rw-r--r-- | shell/hush_test/zbad | 3 |
11 files changed, 47 insertions, 25 deletions
diff --git a/scripts/trylink b/scripts/trylink index c24d49d52..adc045ad8 100755 --- a/scripts/trylink +++ b/scripts/trylink | |||
@@ -126,11 +126,12 @@ try $CC $CFLAGS $LDFLAGS \ | |||
126 | while test "$LDLIBS"; do | 126 | while test "$LDLIBS"; do |
127 | $debug && echo "Trying libraries: $LDLIBS" | 127 | $debug && echo "Trying libraries: $LDLIBS" |
128 | all_needed=true | 128 | all_needed=true |
129 | last_needed=false | ||
129 | for one in $LDLIBS; do | 130 | for one in $LDLIBS; do |
130 | without_one=`echo " $LDLIBS " | sed "s/ $one / /g" | xargs` | 131 | without_one=`echo " $LDLIBS " | sed "s/ $one / /g" | xargs` |
131 | # "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3" | 132 | # "lib1 lib2 lib3" -> "-llib1 -llib2 -llib3" |
132 | l_list=`echo "$without_one" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'` | 133 | l_list=`echo "$without_one" | sed -e 's/ / -l/g' -e 's/^/-l/' -e 's/^-l$//'` |
133 | test "x$l_list" != "x" && l_list="-Wl,--start-group $l_list -Wl,--end-group" | 134 | test x"$l_list" != x"" && l_list="-Wl,--start-group $l_list -Wl,--end-group" |
134 | $debug && echo "Trying -l options: '$l_list'" | 135 | $debug && echo "Trying -l options: '$l_list'" |
135 | try $CC $CFLAGS $LDFLAGS \ | 136 | try $CC $CFLAGS $LDFLAGS \ |
136 | -o $EXE \ | 137 | -o $EXE \ |
@@ -143,16 +144,19 @@ while test "$LDLIBS"; do | |||
143 | echo " Library $one is not needed" | 144 | echo " Library $one is not needed" |
144 | LDLIBS="$without_one" | 145 | LDLIBS="$without_one" |
145 | all_needed=false | 146 | all_needed=false |
147 | last_needed=false | ||
146 | else | 148 | else |
147 | echo " Library $one is needed" | 149 | echo " Library $one is needed" |
150 | last_needed=true | ||
148 | fi | 151 | fi |
149 | done | 152 | done |
150 | # All libs were needed, can't remove any | 153 | # All libs were needed, can't remove any |
151 | $all_needed && break | 154 | $all_needed && break |
152 | # If there is no space char, the list has just one lib. | 155 | # Optimization: was the last tried lib needed? |
153 | # I'm not sure that in this case lib really is 100% needed. | 156 | if $last_needed; then |
154 | # Let's try linking without it anyway... thus commented out. | 157 | # Was it the only one lib left? Don't test again then. |
155 | #{ echo "$LDLIBS" | grep -q ' '; } || break | 158 | { echo "$LDLIBS" | grep -q ' '; } || break |
159 | fi | ||
156 | done | 160 | done |
157 | 161 | ||
158 | # Make the binary with final, minimal list of libs | 162 | # Make the binary with final, minimal list of libs |
diff --git a/shell/hush.c b/shell/hush.c index 222fd9fb5..a84bb92dc 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -615,6 +615,7 @@ static int builtin_help(char **argv); | |||
615 | static int builtin_pwd(char **argv); | 615 | static int builtin_pwd(char **argv); |
616 | static int builtin_read(char **argv); | 616 | static int builtin_read(char **argv); |
617 | static int builtin_test(char **argv); | 617 | static int builtin_test(char **argv); |
618 | static int builtin_true(char **argv); | ||
618 | static int builtin_set(char **argv); | 619 | static int builtin_set(char **argv); |
619 | static int builtin_shift(char **argv); | 620 | static int builtin_shift(char **argv); |
620 | static int builtin_source(char **argv); | 621 | static int builtin_source(char **argv); |
@@ -629,10 +630,10 @@ static int builtin_unset(char **argv); | |||
629 | * For example, 'unset foo | whatever' will parse and run, but foo will | 630 | * For example, 'unset foo | whatever' will parse and run, but foo will |
630 | * still be set at the end. */ | 631 | * still be set at the end. */ |
631 | struct built_in_command { | 632 | struct built_in_command { |
632 | const char *cmd; /* name */ | 633 | const char *cmd; |
633 | int (*function) (char **argv); /* function ptr */ | 634 | int (*function)(char **argv); |
634 | #if ENABLE_HUSH_HELP | 635 | #if ENABLE_HUSH_HELP |
635 | const char *descr; /* description */ | 636 | const char *descr; |
636 | #define BLTIN(cmd, func, help) { cmd, func, help } | 637 | #define BLTIN(cmd, func, help) { cmd, func, help } |
637 | #else | 638 | #else |
638 | #define BLTIN(cmd, func, help) { cmd, func } | 639 | #define BLTIN(cmd, func, help) { cmd, func } |
@@ -642,24 +643,25 @@ struct built_in_command { | |||
642 | /* For now, echo and test are unconditionally enabled. | 643 | /* For now, echo and test are unconditionally enabled. |
643 | * Maybe make it configurable? */ | 644 | * Maybe make it configurable? */ |
644 | static const struct built_in_command bltins[] = { | 645 | static const struct built_in_command bltins[] = { |
646 | BLTIN("." , builtin_source, "Run commands in a file"), | ||
647 | BLTIN(":" , builtin_true, "No-op"), | ||
645 | BLTIN("[" , builtin_test, "Test condition"), | 648 | BLTIN("[" , builtin_test, "Test condition"), |
646 | BLTIN("[[" , builtin_test, "Test condition"), | 649 | BLTIN("[[" , builtin_test, "Test condition"), |
647 | #if ENABLE_HUSH_JOB | 650 | #if ENABLE_HUSH_JOB |
648 | BLTIN("bg" , builtin_fg_bg, "Resume a job in the background"), | 651 | BLTIN("bg" , builtin_fg_bg, "Resume a job in the background"), |
649 | #endif | 652 | #endif |
650 | // BLTIN("break" , builtin_not_written, "Exit for, while or until loop"), | 653 | // BLTIN("break" , builtin_not_written, "Exit for, while or until loop"), |
651 | BLTIN("cd" , builtin_cd, "Change working directory"), | 654 | BLTIN("cd" , builtin_cd, "Change directory"), |
652 | // BLTIN("continue", builtin_not_written, "Continue for, while or until loop"), | 655 | // BLTIN("continue", builtin_not_written, "Continue for, while or until loop"), |
653 | BLTIN("echo" , builtin_echo, "Write strings to stdout"), | 656 | BLTIN("echo" , builtin_echo, "Write strings to stdout"), |
654 | BLTIN("eval" , builtin_eval, "Construct and run shell command"), | 657 | BLTIN("eval" , builtin_eval, "Construct and run shell command"), |
655 | BLTIN("exec" , builtin_exec, "Exec command, replacing this shell with the exec'd process"), | 658 | BLTIN("exec" , builtin_exec, "Execute command, don't return to shell"), |
656 | BLTIN("exit" , builtin_exit, "Exit from shell"), | 659 | BLTIN("exit" , builtin_exit, "Exit"), |
657 | BLTIN("export", builtin_export, "Set environment variable"), | 660 | BLTIN("export", builtin_export, "Set environment variable"), |
658 | #if ENABLE_HUSH_JOB | 661 | #if ENABLE_HUSH_JOB |
659 | BLTIN("fg" , builtin_fg_bg, "Bring job into the foreground"), | 662 | BLTIN("fg" , builtin_fg_bg, "Bring job into the foreground"), |
660 | BLTIN("jobs" , builtin_jobs, "Lists the active jobs"), | 663 | BLTIN("jobs" , builtin_jobs, "List active jobs"), |
661 | #endif | 664 | #endif |
662 | // TODO: remove pwd? we have it as an applet... | ||
663 | BLTIN("pwd" , builtin_pwd, "Print current directory"), | 665 | BLTIN("pwd" , builtin_pwd, "Print current directory"), |
664 | BLTIN("read" , builtin_read, "Input environment variable"), | 666 | BLTIN("read" , builtin_read, "Input environment variable"), |
665 | // BLTIN("return", builtin_not_written, "Return from a function"), | 667 | // BLTIN("return", builtin_not_written, "Return from a function"), |
@@ -667,14 +669,12 @@ static const struct built_in_command bltins[] = { | |||
667 | BLTIN("shift" , builtin_shift, "Shift positional parameters"), | 669 | BLTIN("shift" , builtin_shift, "Shift positional parameters"), |
668 | // BLTIN("trap" , builtin_not_written, "Trap signals"), | 670 | // BLTIN("trap" , builtin_not_written, "Trap signals"), |
669 | BLTIN("test" , builtin_test, "Test condition"), | 671 | BLTIN("test" , builtin_test, "Test condition"), |
670 | // BLTIN("ulimit", builtin_not_written, "Controls resource limits"), | 672 | // BLTIN("ulimit", builtin_not_written, "Control resource limits"), |
671 | BLTIN("umask" , builtin_umask, "Sets file creation mask"), | 673 | BLTIN("umask" , builtin_umask, "Set file creation mask"), |
672 | BLTIN("unset" , builtin_unset, "Unset environment variable"), | 674 | BLTIN("unset" , builtin_unset, "Unset environment variable"), |
673 | BLTIN("." , builtin_source, "Source-in and run commands in a file"), | ||
674 | #if ENABLE_HUSH_HELP | 675 | #if ENABLE_HUSH_HELP |
675 | BLTIN("help" , builtin_help, "List shell built-in commands"), | 676 | BLTIN("help" , builtin_help, "List shell built-in commands"), |
676 | #endif | 677 | #endif |
677 | BLTIN(NULL, NULL, NULL) | ||
678 | }; | 678 | }; |
679 | 679 | ||
680 | /* Signals are grouped, we handle them in batches */ | 680 | /* Signals are grouped, we handle them in batches */ |
@@ -810,6 +810,12 @@ static const char *set_cwd(void) | |||
810 | } | 810 | } |
811 | 811 | ||
812 | 812 | ||
813 | /* built-in 'true' handler */ | ||
814 | static int builtin_true(char **argv ATTRIBUTE_UNUSED) | ||
815 | { | ||
816 | return 0; | ||
817 | } | ||
818 | |||
813 | /* built-in 'test' handler */ | 819 | /* built-in 'test' handler */ |
814 | static int builtin_test(char **argv) | 820 | static int builtin_test(char **argv) |
815 | { | 821 | { |
@@ -1005,7 +1011,7 @@ static int builtin_help(char **argv ATTRIBUTE_UNUSED) | |||
1005 | 1011 | ||
1006 | printf("\nBuilt-in commands:\n"); | 1012 | printf("\nBuilt-in commands:\n"); |
1007 | printf("-------------------\n"); | 1013 | printf("-------------------\n"); |
1008 | for (x = bltins; x->cmd; x++) { | 1014 | for (x = bltins; x != &bltins[ARRAY_SIZE(bltins)]; x++) { |
1009 | printf("%s\t%s\n", x->cmd, x->descr); | 1015 | printf("%s\t%s\n", x->cmd, x->descr); |
1010 | } | 1016 | } |
1011 | printf("\n\n"); | 1017 | printf("\n\n"); |
@@ -1583,7 +1589,7 @@ static void pseudo_exec_argv(char **ptrs2free, char **argv) | |||
1583 | * easier to waste a few CPU cycles than it is to figure out | 1589 | * easier to waste a few CPU cycles than it is to figure out |
1584 | * if this is one of those cases. | 1590 | * if this is one of those cases. |
1585 | */ | 1591 | */ |
1586 | for (x = bltins; x->cmd; x++) { | 1592 | for (x = bltins; x != &bltins[ARRAY_SIZE(bltins)]; x++) { |
1587 | if (strcmp(argv[0], x->cmd) == 0) { | 1593 | if (strcmp(argv[0], x->cmd) == 0) { |
1588 | debug_printf_exec("running builtin '%s'\n", argv[0]); | 1594 | debug_printf_exec("running builtin '%s'\n", argv[0]); |
1589 | rcode = x->function(argv); | 1595 | rcode = x->function(argv); |
@@ -1965,7 +1971,7 @@ static int run_pipe(struct pipe *pi) | |||
1965 | p = expand_string_to_string(argv[i]); | 1971 | p = expand_string_to_string(argv[i]); |
1966 | putenv(p); | 1972 | putenv(p); |
1967 | } | 1973 | } |
1968 | for (x = bltins; x->cmd; x++) { | 1974 | for (x = bltins; x != &bltins[ARRAY_SIZE(bltins)]; x++) { |
1969 | if (strcmp(argv[i], x->cmd) == 0) { | 1975 | if (strcmp(argv[i], x->cmd) == 0) { |
1970 | if (x->function == builtin_exec && argv[i+1] == NULL) { | 1976 | if (x->function == builtin_exec && argv[i+1] == NULL) { |
1971 | debug_printf("magic exec\n"); | 1977 | debug_printf("magic exec\n"); |
diff --git a/shell/hush_test/hush-bugs/glob_and_assign.right b/shell/hush_test/hush-bugs/glob_and_assign.right new file mode 100644 index 000000000..dae832361 --- /dev/null +++ b/shell/hush_test/hush-bugs/glob_and_assign.right | |||
@@ -0,0 +1,2 @@ | |||
1 | ZVAR=z.map | ||
2 | *.map | ||
diff --git a/shell/hush_test/zbad2 b/shell/hush_test/hush-bugs/glob_and_assign.tests index b6fffe59e..ea11e364b 100644..100755 --- a/shell/hush_test/zbad2 +++ b/shell/hush_test/hush-bugs/glob_and_assign.tests | |||
@@ -1,5 +1,3 @@ | |||
1 | ## TODO: fix and add to testsuite | ||
2 | |||
3 | ## # bash zbad2 | 1 | ## # bash zbad2 |
4 | ## ZVAR=z.map | 2 | ## ZVAR=z.map |
5 | ## *.map | 3 | ## *.map |
@@ -17,3 +15,4 @@ | |||
17 | ZVAR=*.map /bin/echo ZVAR=*.map | 15 | ZVAR=*.map /bin/echo ZVAR=*.map |
18 | ZVAR=*.map | 16 | ZVAR=*.map |
19 | echo "$ZVAR" | 17 | echo "$ZVAR" |
18 | rm ZVAR=z.map | ||
diff --git a/shell/hush_test/hush-bugs/glob_and_vars.right b/shell/hush_test/hush-bugs/glob_and_vars.right new file mode 100644 index 000000000..3ac7ec5ff --- /dev/null +++ b/shell/hush_test/hush-bugs/glob_and_vars.right | |||
@@ -0,0 +1 @@ | |||
./glob_and_vars.right ./glob_and_vars.tests | |||
diff --git a/shell/hush_test/hush-bugs/glob_and_vars.tests b/shell/hush_test/hush-bugs/glob_and_vars.tests new file mode 100755 index 000000000..c8e0c067d --- /dev/null +++ b/shell/hush_test/hush-bugs/glob_and_vars.tests | |||
@@ -0,0 +1,2 @@ | |||
1 | v=. | ||
2 | echo $v/glob_and_vars.* | ||
diff --git a/shell/hush_test/hush-bugs/while_in_subshell.right b/shell/hush_test/hush-bugs/while_in_subshell.right new file mode 100644 index 000000000..290d39b7e --- /dev/null +++ b/shell/hush_test/hush-bugs/while_in_subshell.right | |||
@@ -0,0 +1 @@ | |||
OK: 0 | |||
diff --git a/shell/hush_test/hush-bugs/while_in_subshell.tests b/shell/hush_test/hush-bugs/while_in_subshell.tests new file mode 100755 index 000000000..def8e092b --- /dev/null +++ b/shell/hush_test/hush-bugs/while_in_subshell.tests | |||
@@ -0,0 +1,2 @@ | |||
1 | (while true; do exit; done) | ||
2 | echo OK: $? | ||
diff --git a/shell/hush_test/hush-misc/colon.right b/shell/hush_test/hush-misc/colon.right new file mode 100644 index 000000000..2a87d0293 --- /dev/null +++ b/shell/hush_test/hush-misc/colon.right | |||
@@ -0,0 +1,2 @@ | |||
1 | 0 | ||
2 | OK: 0 | ||
diff --git a/shell/hush_test/hush-misc/colon.tests b/shell/hush_test/hush-misc/colon.tests new file mode 100755 index 000000000..ea3b4d5f3 --- /dev/null +++ b/shell/hush_test/hush-misc/colon.tests | |||
@@ -0,0 +1,6 @@ | |||
1 | false | ||
2 | : | ||
3 | echo $? | ||
4 | # Extra ; after done is due to a bug | ||
5 | (while :; do exit; done;) | ||
6 | echo OK: $? | ||
diff --git a/shell/hush_test/zbad b/shell/hush_test/zbad deleted file mode 100644 index e4b5caa61..000000000 --- a/shell/hush_test/zbad +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | # TODO: hush doesn't know ':' null command | ||
2 | |||
3 | while :; do exit; done | ||