Rob Landley | 2896480 | 2008-01-19 17:08:39 -0600 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: |
| 2 | * |
Rob Landley | 7ecedea | 2007-08-29 08:10:01 -0500 | [diff] [blame] | 3 | * help.c - Show help for toybox |
Rob Landley | fece5cb | 2007-12-03 20:05:57 -0600 | [diff] [blame] | 4 | * |
Rob Landley | 2896480 | 2008-01-19 17:08:39 -0600 | [diff] [blame] | 5 | * Copyright 2007 Rob Landley <rob@landley.net> |
| 6 | * |
Rob Landley | fece5cb | 2007-12-03 20:05:57 -0600 | [diff] [blame] | 7 | * Not in SUSv3, but exists as a bash builtin. |
Rob Landley | 2896480 | 2008-01-19 17:08:39 -0600 | [diff] [blame] | 8 | |
Rob Landley | 55928b1 | 2008-01-19 17:43:27 -0600 | [diff] [blame] | 9 | USE_HELP(NEWTOY(help, "<1", TOYFLAG_BIN)) |
| 10 | |
Rob Landley | 2896480 | 2008-01-19 17:08:39 -0600 | [diff] [blame] | 11 | config HELP |
| 12 | bool "help" |
| 13 | default y |
| 14 | help |
| 15 | usage: help [command] |
| 16 | |
| 17 | Show usage information for toybox commands. |
| 18 | |
| 19 | config HELP_LONG |
| 20 | bool "Verbose help text" |
| 21 | default y |
| 22 | depends on HELP |
| 23 | help |
| 24 | Show more than one line of help information per command. |
| 25 | */ |
| 26 | |
Rob Landley | 7ecedea | 2007-08-29 08:10:01 -0500 | [diff] [blame] | 27 | |
| 28 | #include "toys.h" |
Rob Landley | 58ecc3e | 2008-01-10 14:40:13 -0600 | [diff] [blame] | 29 | #include "generated/help.h" |
Rob Landley | 7ecedea | 2007-08-29 08:10:01 -0500 | [diff] [blame] | 30 | |
| 31 | #undef NEWTOY |
| 32 | #undef OLDTOY |
| 33 | #define NEWTOY(name,opt,flags) help_##name "\0" |
| 34 | #define OLDTOY(name,oldname,opts,flags) "\xff" #oldname "\0" |
| 35 | static char *help_data = |
Rob Landley | 55928b1 | 2008-01-19 17:43:27 -0600 | [diff] [blame] | 36 | #include "generated/newtoys.h" |
Rob Landley | 7ecedea | 2007-08-29 08:10:01 -0500 | [diff] [blame] | 37 | ; |
| 38 | |
Rob Landley | efda21c | 2007-11-29 18:14:37 -0600 | [diff] [blame] | 39 | void help_main(void) |
Rob Landley | 7ecedea | 2007-08-29 08:10:01 -0500 | [diff] [blame] | 40 | { |
| 41 | struct toy_list *t = toy_find(*toys.optargs); |
| 42 | int i = t-toy_list; |
| 43 | char *s = help_data; |
| 44 | |
Rob Landley | 860f263 | 2007-11-27 01:41:32 -0600 | [diff] [blame] | 45 | if (!t) error_exit("Unknown command '%s'", *toys.optargs); |
Rob Landley | 7ecedea | 2007-08-29 08:10:01 -0500 | [diff] [blame] | 46 | for (;;) { |
| 47 | while (i--) s += strlen(s) + 1; |
| 48 | if (*s != 255) break; |
| 49 | i = toy_find(++s)-toy_list; |
| 50 | s = help_data; |
| 51 | } |
| 52 | |
Rob Landley | d06c58d | 2007-10-11 15:36:36 -0500 | [diff] [blame] | 53 | fprintf(toys.exithelp ? stderr : stdout, "%s", s); |
Rob Landley | 7ecedea | 2007-08-29 08:10:01 -0500 | [diff] [blame] | 54 | } |