aboutsummaryrefslogtreecommitdiff
path: root/lib
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 /lib
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 'lib')
-rw-r--r--lib/help.c11
-rw-r--r--lib/lib.c2
-rw-r--r--lib/lib.h3
3 files changed, 11 insertions, 5 deletions
diff --git a/lib/help.c b/lib/help.c
index 7b97e8b9..86d6392b 100644
--- a/lib/help.c
+++ b/lib/help.c
@@ -16,10 +16,10 @@ static char *help_data =
#include "generated/newtoys.h"
;
-void show_help(FILE *out)
+void show_help(FILE *out, int full)
{
int i = toys.which-toy_list;
- char *s;
+ char *s, *ss;
if (CFG_TOYBOX_HELP) {
for (;;) {
@@ -30,6 +30,11 @@ void show_help(FILE *out)
i = toy_find(++s)-toy_list;
}
- fprintf(out, "%s\n", s);
+ if (full) fprintf(out, "%s\n", s);
+ else {
+ strstart(&s, "usage: ");
+ for (ss = s; *ss && *ss!='\n'; ss++);
+ fprintf(out, "%.*s\n", (int)(ss-s), s);
+ }
}
}
diff --git a/lib/lib.c b/lib/lib.c
index 2250caf4..26ba546f 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -72,7 +72,7 @@ void help_exit(char *msg, ...)
{
va_list va;
- if (!msg) show_help(stdout);
+ if (!msg) show_help(stdout, 1);
else {
va_start(va, msg);
verror_msg(msg, -1, va);
diff --git a/lib/lib.h b/lib/lib.h
index 5ec648c8..398d261d 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -55,6 +55,7 @@ struct num_cache *add_num_cache(struct num_cache **cache, long long num,
// args.c
#define FLAGS_NODASH (1LL<<63)
+#define FLAGS_BUILTIN (1LL<<62)
void get_optflags(void);
// dirtree.c
@@ -107,7 +108,7 @@ struct dirtree *dirtree_read(char *path, int (*callback)(struct dirtree *node));
// help.c
-void show_help(FILE *out);
+void show_help(FILE *out, int full);
// Tell xopen and friends to print warnings but return -1 as necessary
// The largest O_BLAH flag so far is arch/alpha's O_PATH at 0x800000 so