1 /* help.c - Show help for toybox commands 2 * 3 * Copyright 2007 Rob Landley <rob@landley.net> 4 * 5 * Often a shell builtin. 6 7 USE_HELP(NEWTOY(help, ""USE_HELP_EXTRAS("ah"), TOYFLAG_BIN)) 8 9 config HELP 10 bool "help" 11 default y 12 depends on TOYBOX_HELP 13 help 14 usage: help [command] 15 16 Show usage information for toybox commands. 17 Run "toybox" with no arguments for a list of available commands. 18 19 config HELP_EXTRAS 20 bool "help -ah" 21 default y 22 depends on TOYBOX 23 depends on HELP 24 help 25 usage: help [-ah] 26 27 -a All commands 28 -h HTML output 29 */ 30 31 #define FOR_help 32 #include "toys.h" 33 do_help(struct toy_list * t)34static void do_help(struct toy_list *t) 35 { 36 if (toys.optflags & FLAG_h) 37 xprintf("<a name=\"%s\"><h1>%s</h1><blockquote><pre>\n", t->name, t->name); 38 39 toys.which = t; 40 show_help(); 41 42 if (toys.optflags & FLAG_h) xprintf("</blockquote></pre>\n"); 43 } 44 45 // The simple help is just toys.which = toy_find("name"); show_help(); 46 // But iterating through html output and all commands is a big more 47 help_main(void)48void help_main(void) 49 { 50 int i; 51 52 if (!(toys.optflags & FLAG_a)) { 53 struct toy_list *t = toys.which; 54 55 if (*toys.optargs && !(t = toy_find(*toys.optargs))) 56 error_exit("Unknown command '%s'", *toys.optargs); 57 do_help(t); 58 return; 59 } 60 61 if (toys.optflags & FLAG_h) { 62 xprintf("<html>\n<title>Toybox command list</title>\n<body>\n<p>\n"); 63 for (i=0; i < toys.toycount; i++) 64 xprintf("<a href=\"#%s\">%s</a>\n", toy_list[i].name, 65 toy_list[i].name); 66 xprintf("</p>\n"); 67 } 68 69 for (i = 0; i < toys.toycount; i++) { 70 if (toys.optflags & FLAG_h) xprintf("<hr>\n<pre>\n"); 71 do_help(toy_list+i); 72 if (toys.optflags & FLAG_h) xprintf("</pre>\n"); 73 } 74 75 if (toys.optflags & FLAG_h) xprintf("</html>"); 76 } 77