aboutsummaryrefslogtreecommitdiff
path: root/toys/other
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2020-01-03 03:10:17 -0600
committerRob Landley <rob@landley.net>2020-01-03 03:10:17 -0600
commita2cd46a5f342553c05ae6ef4e7a73069df0e1be1 (patch)
tree55c7f84b31d94aa578616a04ec92480ced1553f3 /toys/other
parent53090cd6c1343954d953625223b50e73abb6b9f3 (diff)
downloadtoybox-a2cd46a5f342553c05ae6ef4e7a73069df0e1be1.tar.gz
Add MAYFORK to "help", teach it to behave differently when called as a
builtin, and add -u.
Diffstat (limited to 'toys/other')
-rw-r--r--toys/other/help.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/toys/other/help.c b/toys/other/help.c
index 6ce1b02e..eba3cb1e 100644
--- a/toys/other/help.c
+++ b/toys/other/help.c
@@ -4,7 +4,7 @@
*
* Often a shell builtin.
-USE_HELP(NEWTOY(help, ""USE_HELP_EXTRAS("ah"), TOYFLAG_BIN))
+USE_HELP(NEWTOY(help, ""USE_HELP_EXTRAS("ahu"), TOYFLAG_BIN|TOYFLAG_MAYFORK))
config HELP
bool "help"
@@ -22,9 +22,10 @@ config HELP_EXTRAS
depends on TOYBOX
depends on HELP
help
- usage: help [-ah]
+ usage: help [-ah] [COMMAND]
-a All commands
+ -u Usage only
-h HTML output
*/
@@ -33,13 +34,13 @@ config HELP_EXTRAS
static void do_help(struct toy_list *t)
{
- if (toys.optflags & FLAG_h)
+ if (FLAG(h))
xprintf("<a name=\"%s\"><h1>%s</h1><blockquote><pre>\n", t->name, t->name);
toys.which = t;
- show_help(stdout);
+ show_help(stdout, !FLAG(u));
- if (toys.optflags & FLAG_h) xprintf("</blockquote></pre>\n");
+ if (FLAG(h)) xprintf("</blockquote></pre>\n");
}
// The simple help is just toys.which = toy_find("name"); show_help(stdout);
@@ -48,8 +49,18 @@ static void do_help(struct toy_list *t)
void help_main(void)
{
int i;
-
- if (!(toys.optflags & FLAG_a)) {
+
+ // If called with no arguments as a builtin form the shell, show all builtins
+ if (!*toys.optargs && (toys.optflags&FLAGS_BUILTIN)) {
+ for (i = 0; i < toys.toycount; i++) {
+ if (!(toy_list[i].flags&(TOYFLAG_NOFORK|TOYFLAG_MAYFORK))) continue;
+ toys.which = toy_list+i;
+ show_help(stdout, 0);
+ }
+ return;
+ }
+
+ if (!FLAG(a)) {
struct toy_list *t = toys.which;
if (*toys.optargs && !(t = toy_find(*toys.optargs)))
@@ -58,7 +69,7 @@ void help_main(void)
return;
}
- if (toys.optflags & FLAG_h) {
+ if (FLAG(h)) {
xprintf("<html>\n<title>Toybox command list</title>\n<body>\n<p>\n");
for (i=0; i < toys.toycount; i++)
xprintf("<a href=\"#%s\">%s\n</a>\n", toy_list[i].name,
@@ -67,15 +78,15 @@ void help_main(void)
}
for (i = 0; i < toys.toycount; i++) {
- if (toys.optflags & FLAG_h) xprintf("<hr>\n<pre>\n");
- else {
+ if (FLAG(h)) xprintf("<hr>\n<pre>\n");
+ else if (!FLAG(u)) {
memset(toybuf, '-', 78);
memcpy(toybuf+3, toy_list[i].name, strlen(toy_list[i].name));
printf("\n%s\n\n", toybuf);
}
do_help(toy_list+i);
- if (toys.optflags & FLAG_h) xprintf("</pre>\n");
+ if (FLAG(h)) xprintf("</pre>\n");
}
- if (toys.optflags & FLAG_h) xprintf("</html>");
+ if (FLAG(h)) xprintf("</html>");
}