diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-26 23:22:40 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-26 23:22:40 +0000 |
| commit | 28e67966f3fc0728fb2f923265a8b2275f410655 (patch) | |
| tree | 0c522b97ed681180f68d028094bd02b89b292b49 /shell | |
| parent | 572930027d5d86a18ebd68d5f4273150a2f302e1 (diff) | |
| download | busybox-w32-28e67966f3fc0728fb2f923265a8b2275f410655.tar.gz busybox-w32-28e67966f3fc0728fb2f923265a8b2275f410655.tar.bz2 busybox-w32-28e67966f3fc0728fb2f923265a8b2275f410655.zip | |
hush: make getopt32 usable in builtins. use it in unset.
more uses are expected in the future.
function old new delta
getopt32 1356 1393 +37
builtin_export 256 266 +10
builtin_unset 418 380 -38
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/hush.c | 42 | ||||
| -rw-r--r-- | shell/hush_test/hush-vars/unset.right | 5 |
2 files changed, 18 insertions, 29 deletions
diff --git a/shell/hush.c b/shell/hush.c index 292b8b2e3..d0819f691 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
| @@ -6451,7 +6451,11 @@ static int builtin_export(char **argv) | |||
| 6451 | } | 6451 | } |
| 6452 | 6452 | ||
| 6453 | #if ENABLE_HUSH_EXPORT_N | 6453 | #if ENABLE_HUSH_EXPORT_N |
| 6454 | opt_unexport = getopt32(argv, "+n"); /* "+": stop at 1st non-option */ | 6454 | /* "!": do not abort on errors */ |
| 6455 | /* "+": stop at 1st non-option */ | ||
| 6456 | opt_unexport = getopt32(argv, "!+n"); | ||
| 6457 | if (opt_unexport == (unsigned)-1) | ||
| 6458 | return EXIT_FAILURE; | ||
| 6455 | argv += optind; | 6459 | argv += optind; |
| 6456 | #else | 6460 | #else |
| 6457 | opt_unexport = 0; | 6461 | opt_unexport = 0; |
| @@ -6918,36 +6922,22 @@ static int builtin_umask(char **argv) | |||
| 6918 | static int builtin_unset(char **argv) | 6922 | static int builtin_unset(char **argv) |
| 6919 | { | 6923 | { |
| 6920 | int ret; | 6924 | int ret; |
| 6921 | char var; | 6925 | unsigned opts; |
| 6922 | char *arg; | ||
| 6923 | |||
| 6924 | if (!*++argv) | ||
| 6925 | return EXIT_SUCCESS; | ||
| 6926 | 6926 | ||
| 6927 | var = 0; | 6927 | /* "!": do not abort on errors */ |
| 6928 | while ((arg = *argv) != NULL && arg[0] == '-') { | 6928 | /* "+": stop at 1st non-option */ |
| 6929 | arg++; | 6929 | opts = getopt32(argv, "!+vf"); |
| 6930 | do { | 6930 | if (opts == (unsigned)-1) |
| 6931 | switch (*arg) { | 6931 | return EXIT_FAILURE; |
| 6932 | case 'v': | 6932 | if (opts == 3) { |
| 6933 | case 'f': | 6933 | bb_error_msg("unset: -v and -f are exclusive"); |
| 6934 | if (var == 0 || var == *arg) { | 6934 | return EXIT_FAILURE; |
| 6935 | var = *arg; | ||
| 6936 | break; | ||
| 6937 | } | ||
| 6938 | /* else: unset -vf, which is illegal. | ||
| 6939 | * fall through */ | ||
| 6940 | default: | ||
| 6941 | bb_error_msg("unset: %s: invalid option", *argv); | ||
| 6942 | return EXIT_FAILURE; | ||
| 6943 | } | ||
| 6944 | } while (*++arg); | ||
| 6945 | argv++; | ||
| 6946 | } | 6935 | } |
| 6936 | argv += optind; | ||
| 6947 | 6937 | ||
| 6948 | ret = EXIT_SUCCESS; | 6938 | ret = EXIT_SUCCESS; |
| 6949 | while (*argv) { | 6939 | while (*argv) { |
| 6950 | if (var != 'f') { | 6940 | if (!(opts & 2)) { /* not -f */ |
| 6951 | if (unset_local_var(*argv)) { | 6941 | if (unset_local_var(*argv)) { |
| 6952 | /* unset <nonexistent_var> doesn't fail. | 6942 | /* unset <nonexistent_var> doesn't fail. |
| 6953 | * Error is when one tries to unset RO var. | 6943 | * Error is when one tries to unset RO var. |
diff --git a/shell/hush_test/hush-vars/unset.right b/shell/hush_test/hush-vars/unset.right index 8dea7c40d..1fbe76a73 100644 --- a/shell/hush_test/hush-vars/unset.right +++ b/shell/hush_test/hush-vars/unset.right | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | hush: unset: -: invalid option | 1 | 0 |
| 2 | 1 | 2 | unset: invalid option -- m |
| 3 | hush: unset: -m: invalid option | ||
| 4 | 1 | 3 | 1 |
| 5 | 0 | 4 | 0 |
| 6 | ___ | 5 | ___ |
