OSDN Git Service

5e2b6ec4f1c7db00f722c196b48790e24d47ef85
[android-x86/external-toybox.git] / toys / other / help.c
1 /* vi: set sw=4 ts=4:
2  *
3  * help.c - Show help for toybox
4  *
5  * Copyright 2007 Rob Landley <rob@landley.net>
6  *
7  * Not in SUSv3, but exists as a bash builtin.
8
9 USE_HELP(NEWTOY(help, "<1", TOYFLAG_BIN))
10
11 config HELP
12         bool "help"
13         default y
14         help
15           usage: help [command]
16
17           Show usage information for toybox commands.
18           Run "toybox" with no arguments for a list of available commands.
19 */
20  
21
22 #include "toys.h"
23 #include "generated/help.h"
24
25 #undef NEWTOY
26 #undef OLDTOY
27 #define NEWTOY(name,opt,flags) help_##name "\0"
28 #define OLDTOY(name,oldname,opts,flags) "\xff" #oldname "\0"
29 static char *help_data =
30 #include "generated/newtoys.h"
31 ;
32
33 void help_main(void)
34 {
35         struct toy_list *t = toy_find(*toys.optargs);
36         int i = t-toy_list;
37         char *s = help_data;
38
39         if (!t) error_exit("Unknown command '%s'", *toys.optargs);
40         for (;;) {
41                 while (i--) s += strlen(s) + 1;
42                 if (*s != 255) break;
43                 i = toy_find(++s)-toy_list;
44                 s = help_data;
45         }
46
47         fprintf(toys.exithelp ? stderr : stdout, "%s", s);
48 }