comparison toys/other/help.c @ 858:34ac05521d94

Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
author Rob Landley <rob@landley.net>
date Sun, 14 Apr 2013 21:43:22 -0500
parents 786841fdb1e0
children 4654f241ccbe
comparison
equal deleted inserted replaced
857:da601285a86e 858:34ac05521d94
7 USE_HELP(NEWTOY(help, "<1", TOYFLAG_BIN)) 7 USE_HELP(NEWTOY(help, "<1", TOYFLAG_BIN))
8 8
9 config HELP 9 config HELP
10 bool "help" 10 bool "help"
11 default y 11 default y
12 depends on TOYBOX_HELP
12 help 13 help
13 usage: help [command] 14 usage: help [command]
14 15
15 Show usage information for toybox commands. 16 Show usage information for toybox commands.
16 Run "toybox" with no arguments for a list of available commands. 17 Run "toybox" with no arguments for a list of available commands.
17 */ 18 */
18 19
19 20
20 #include "toys.h" 21 #include "toys.h"
21 #include "generated/help.h"
22
23 #undef NEWTOY
24 #undef OLDTOY
25 #define NEWTOY(name,opt,flags) help_##name "\0"
26 #define OLDTOY(name,oldname,opts,flags) "\xff" #oldname "\0"
27 static char *help_data =
28 #include "generated/newtoys.h"
29 ;
30 22
31 void help_main(void) 23 void help_main(void)
32 { 24 {
33 struct toy_list *t = toy_find(*toys.optargs); 25 struct toy_list *t = toy_find(*toys.optargs);
34 int i = t-toy_list;
35 char *s = help_data;
36 26
37 if (!t) error_exit("Unknown command '%s'", *toys.optargs); 27 if (!t) error_exit("Unknown command '%s'", *toys.optargs);
38 for (;;) { 28 toys.which = t;
39 while (i--) s += strlen(s) + 1; 29 show_help();
40 if (*s != 255) break;
41 i = toy_find(++s)-toy_list;
42 s = help_data;
43 }
44
45 fprintf(toys.exithelp ? stderr : stdout, "%s", s);
46 } 30 }