aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2021-06-09 19:00:46 -0500
committerRob Landley <rob@landley.net>2021-06-09 19:00:46 -0500
commit0c6000ad4847a21ef1513985b1d96f5e1a0503e4 (patch)
tree659b34e818e5b6c8b8b9bc6cb5e94c8df9eb8d23
parent412054cff027ee52cadc3684f6018cfb0e5eb8e2 (diff)
downloadtoybox-0c6000ad4847a21ef1513985b1d96f5e1a0503e4.tar.gz
Ryan Prichard pointed out --help and --version can't be first in aliases.
-rw-r--r--main.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/main.c b/main.c
index d5abe6e6..ae50431c 100644
--- a/main.c
+++ b/main.c
@@ -30,7 +30,7 @@ struct toy_list *toy_find(char *name)
if (!CFG_TOYBOX || strchr(name, '/')) return 0;
// Multiplexer name works as prefix, else skip first entry (it's out of order)
- if (!toys.which && strstart(&name, "toybox")) return toy_list;
+ if (!toys.which && strstart(&name, toy_list->name)) return toy_list;
bottom = 1;
// Binary search to find this command.
@@ -75,17 +75,21 @@ void toy_singleinit(struct toy_list *which, char *argv[])
toys.toycount = ARRAY_LEN(toy_list);
// Parse --help and --version for (almost) all commands
- if (CFG_TOYBOX_HELP_DASHDASH && !(which->flags & TOYFLAG_NOHELP) && argv[1]) {
- if (!strcmp(argv[1], "--help")) {
- if (CFG_TOYBOX && toys.which == toy_list && toys.argv[2])
- if (!(toys.which = toy_find(toys.argv[2]))) unknown(toys.argv[2]);
- show_help(stdout, 1);
- xexit();
- }
+ if (CFG_TOYBOX_HELP_DASHDASH && !(which->flags & TOYFLAG_NOHELP)) {
+ char **args;
+
+ for (args = toys.argv+1; *args; args++) {
+ if (!strcmp(*args, "--help")) {
+ if (CFG_TOYBOX && toys.which == toy_list && args[1])
+ if (!(toys.which = toy_find(args[1]))) unknown(args[1]);
+ show_help(stdout, 1);
+ xexit();
+ }
- if (!strcmp(argv[1], "--version")) {
- xprintf("toybox %s\n", toybox_version);
- xexit();
+ if (!strcmp(*args, "--version")) {
+ xprintf("toybox %s\n", toybox_version);
+ xexit();
+ }
}
}