diff options
| author | Ron Yorston <rmy@pobox.com> | 2023-04-17 07:32:52 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2023-04-17 07:32:52 +0100 |
| commit | 8cdeb571cfbf3bb6edc44779e46537b072b8cd08 (patch) | |
| tree | 9f3ad1d205418197bc53348b61f702602229a90d /shell | |
| parent | 41827dd448c001b52b4f0e591ea605cb5de1d230 (diff) | |
| parent | d2b81b3dc2b31d32e1060d3ea8bd998d30a37d8a (diff) | |
| download | busybox-w32-8cdeb571cfbf3bb6edc44779e46537b072b8cd08.tar.gz busybox-w32-8cdeb571cfbf3bb6edc44779e46537b072b8cd08.tar.bz2 busybox-w32-8cdeb571cfbf3bb6edc44779e46537b072b8cd08.zip | |
Merge branch 'busybox' into merge
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/ash.c | 32 | ||||
| -rw-r--r-- | shell/hush.c | 33 | ||||
| -rw-r--r-- | shell/hush_test/hush-misc/export-n.right | 4 |
3 files changed, 59 insertions, 10 deletions
diff --git a/shell/ash.c b/shell/ash.c index 3eb9d5852..28f4ec47d 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
| @@ -10696,7 +10696,7 @@ evalpipe(union node *n, int flags) | |||
| 10696 | 10696 | ||
| 10697 | /* setinteractive needs this forward reference */ | 10697 | /* setinteractive needs this forward reference */ |
| 10698 | #if ENABLE_FEATURE_TAB_COMPLETION | 10698 | #if ENABLE_FEATURE_TAB_COMPLETION |
| 10699 | static const char *get_builtin_name(int i) FAST_FUNC; | 10699 | static const char *ash_command_name(int i) FAST_FUNC; |
| 10700 | #endif | 10700 | #endif |
| 10701 | 10701 | ||
| 10702 | /* | 10702 | /* |
| @@ -10733,7 +10733,7 @@ setinteractive(int on) | |||
| 10733 | if (!line_input_state) { | 10733 | if (!line_input_state) { |
| 10734 | line_input_state = new_line_input_t(FOR_SHELL | WITH_PATH_LOOKUP); | 10734 | line_input_state = new_line_input_t(FOR_SHELL | WITH_PATH_LOOKUP); |
| 10735 | # if ENABLE_FEATURE_TAB_COMPLETION | 10735 | # if ENABLE_FEATURE_TAB_COMPLETION |
| 10736 | line_input_state->get_exe_name = get_builtin_name; | 10736 | line_input_state->get_exe_name = ash_command_name; |
| 10737 | # endif | 10737 | # endif |
| 10738 | # if EDITING_HAS_sh_get_var | 10738 | # if EDITING_HAS_sh_get_var |
| 10739 | line_input_state->sh_get_var = lookupvar; | 10739 | line_input_state->sh_get_var = lookupvar; |
| @@ -11252,9 +11252,33 @@ find_builtin(const char *name) | |||
| 11252 | 11252 | ||
| 11253 | #if ENABLE_FEATURE_TAB_COMPLETION | 11253 | #if ENABLE_FEATURE_TAB_COMPLETION |
| 11254 | static const char * FAST_FUNC | 11254 | static const char * FAST_FUNC |
| 11255 | get_builtin_name(int i) | 11255 | ash_command_name(int i) |
| 11256 | { | 11256 | { |
| 11257 | return /*i >= 0 &&*/ i < ARRAY_SIZE(builtintab) ? builtintab[i].name + 1 : NULL; | 11257 | int n; |
| 11258 | |||
| 11259 | if (/*i >= 0 &&*/ i < ARRAY_SIZE(builtintab)) | ||
| 11260 | return builtintab[i].name + 1; | ||
| 11261 | i -= ARRAY_SIZE(builtintab); | ||
| 11262 | |||
| 11263 | for (n = 0; n < CMDTABLESIZE; n++) { | ||
| 11264 | struct tblentry *cmdp; | ||
| 11265 | for (cmdp = cmdtable[n]; cmdp; cmdp = cmdp->next) { | ||
| 11266 | if (cmdp->cmdtype == CMDFUNCTION && --i < 0) | ||
| 11267 | return cmdp->cmdname; | ||
| 11268 | } | ||
| 11269 | } | ||
| 11270 | |||
| 11271 | # if ENABLE_ASH_ALIAS | ||
| 11272 | for (n = 0; n < ATABSIZE; n++) { | ||
| 11273 | struct alias *ap; | ||
| 11274 | for (ap = atab[n]; ap; ap = ap->next) { | ||
| 11275 | if (--i < 0) | ||
| 11276 | return ap->name; | ||
| 11277 | } | ||
| 11278 | } | ||
| 11279 | #endif | ||
| 11280 | |||
| 11281 | return NULL; | ||
| 11258 | } | 11282 | } |
| 11259 | #endif | 11283 | #endif |
| 11260 | 11284 | ||
diff --git a/shell/hush.c b/shell/hush.c index a938cc790..f8951d084 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
| @@ -8220,7 +8220,7 @@ static const struct built_in_command *find_builtin(const char *name) | |||
| 8220 | } | 8220 | } |
| 8221 | 8221 | ||
| 8222 | #if ENABLE_HUSH_JOB && ENABLE_FEATURE_TAB_COMPLETION | 8222 | #if ENABLE_HUSH_JOB && ENABLE_FEATURE_TAB_COMPLETION |
| 8223 | static const char * FAST_FUNC get_builtin_name(int i) | 8223 | static const char * FAST_FUNC hush_command_name(int i) |
| 8224 | { | 8224 | { |
| 8225 | if (/*i >= 0 && */ i < ARRAY_SIZE(bltins1)) { | 8225 | if (/*i >= 0 && */ i < ARRAY_SIZE(bltins1)) { |
| 8226 | return bltins1[i].b_cmd; | 8226 | return bltins1[i].b_cmd; |
| @@ -8229,6 +8229,16 @@ static const char * FAST_FUNC get_builtin_name(int i) | |||
| 8229 | if (i < ARRAY_SIZE(bltins2)) { | 8229 | if (i < ARRAY_SIZE(bltins2)) { |
| 8230 | return bltins2[i].b_cmd; | 8230 | return bltins2[i].b_cmd; |
| 8231 | } | 8231 | } |
| 8232 | # if ENABLE_HUSH_FUNCTIONS | ||
| 8233 | { | ||
| 8234 | struct function *funcp; | ||
| 8235 | i -= ARRAY_SIZE(bltins2); | ||
| 8236 | for (funcp = G.top_func; funcp; funcp = funcp->next) { | ||
| 8237 | if (--i < 0) | ||
| 8238 | return funcp->name; | ||
| 8239 | } | ||
| 8240 | } | ||
| 8241 | # endif | ||
| 8232 | return NULL; | 8242 | return NULL; |
| 8233 | } | 8243 | } |
| 8234 | #endif | 8244 | #endif |
| @@ -10716,7 +10726,7 @@ int hush_main(int argc, char **argv) | |||
| 10716 | # if ENABLE_FEATURE_EDITING | 10726 | # if ENABLE_FEATURE_EDITING |
| 10717 | G.line_input_state = new_line_input_t(FOR_SHELL); | 10727 | G.line_input_state = new_line_input_t(FOR_SHELL); |
| 10718 | # if ENABLE_FEATURE_TAB_COMPLETION | 10728 | # if ENABLE_FEATURE_TAB_COMPLETION |
| 10719 | G.line_input_state->get_exe_name = get_builtin_name; | 10729 | G.line_input_state->get_exe_name = hush_command_name; |
| 10720 | # endif | 10730 | # endif |
| 10721 | # if EDITING_HAS_sh_get_var | 10731 | # if EDITING_HAS_sh_get_var |
| 10722 | G.line_input_state->sh_get_var = get_local_var_value; | 10732 | G.line_input_state->sh_get_var = get_local_var_value; |
| @@ -11147,6 +11157,12 @@ static int FAST_FUNC builtin_umask(char **argv) | |||
| 11147 | #if ENABLE_HUSH_EXPORT || ENABLE_HUSH_TRAP | 11157 | #if ENABLE_HUSH_EXPORT || ENABLE_HUSH_TRAP |
| 11148 | static void print_escaped(const char *s) | 11158 | static void print_escaped(const char *s) |
| 11149 | { | 11159 | { |
| 11160 | //TODO? bash "set" does not quote variables which contain only alnums and "%+,-./:=@_~", | ||
| 11161 | // (but "export" quotes all variables, even with only these chars). | ||
| 11162 | // I think quoting strings with %+,=~ looks better | ||
| 11163 | // (example: "set" printing var== instead of var='=' looks strange) | ||
| 11164 | // IOW: do not quote "-./:@_": / is used in pathnames, : in PATH, -._ often in file names, @ in emails | ||
| 11165 | |||
| 11150 | if (*s == '\'') | 11166 | if (*s == '\'') |
| 11151 | goto squote; | 11167 | goto squote; |
| 11152 | do { | 11168 | do { |
| @@ -11401,8 +11417,17 @@ static int FAST_FUNC builtin_set(char **argv) | |||
| 11401 | 11417 | ||
| 11402 | if (arg == NULL) { | 11418 | if (arg == NULL) { |
| 11403 | struct variable *e; | 11419 | struct variable *e; |
| 11404 | for (e = G.top_var; e; e = e->next) | 11420 | for (e = G.top_var; e; e = e->next) { |
| 11405 | puts(e->varstr); | 11421 | const char *s = e->varstr; |
| 11422 | const char *p = strchr(s, '='); | ||
| 11423 | |||
| 11424 | if (!p) /* wtf? take next variable */ | ||
| 11425 | continue; | ||
| 11426 | /* var= */ | ||
| 11427 | printf("%.*s", (int)(p - s) + 1, s); | ||
| 11428 | print_escaped(p + 1); | ||
| 11429 | putchar('\n'); | ||
| 11430 | } | ||
| 11406 | return EXIT_SUCCESS; | 11431 | return EXIT_SUCCESS; |
| 11407 | } | 11432 | } |
| 11408 | 11433 | ||
diff --git a/shell/hush_test/hush-misc/export-n.right b/shell/hush_test/hush-misc/export-n.right index 3d55bf752..6079a0124 100644 --- a/shell/hush_test/hush-misc/export-n.right +++ b/shell/hush_test/hush-misc/export-n.right | |||
| @@ -2,8 +2,8 @@ export aaa1="'''" | |||
| 2 | export aaa2='' | 2 | export aaa2='' |
| 3 | export aaa3="'''"'abc' | 3 | export aaa3="'''"'abc' |
| 4 | export aaa8='8' | 4 | export aaa8='8' |
| 5 | aaa9=9 | 5 | aaa9='9' |
| 6 | aaa10=10 | 6 | aaa10='10' |
| 7 | Nothing: | 7 | Nothing: |
| 8 | Nothing: | 8 | Nothing: |
| 9 | Nothing: | 9 | Nothing: |
