annotate toys/other/help.c @ 1232:4654f241ccbe draft

Add help -a (to show all commands) and -h (to produce HTML output).
author Rob Landley <rob@landley.net>
date Fri, 28 Mar 2014 17:48:02 -0500
parents 34ac05521d94
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
1 /* help.c - Show help for toybox commands
194
30a6db5a95c2 Add comments about SUSv3 specs (or lack thereof).
Rob Landley <rob@landley.net>
parents: 186
diff changeset
2 *
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
3 * Copyright 2007 Rob Landley <rob@landley.net>
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
4 *
656
6df4ccc0acbe Regularize command headers, update links to standards documents.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
5 * Often a shell builtin.
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
6
1232
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
7 USE_HELP(NEWTOY(help, ""USE_HELP_EXTRAS("ah"), TOYFLAG_BIN))
234
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
8
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
9 config HELP
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
10 bool "help"
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
11 default y
858
34ac05521d94 Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents: 694
diff changeset
12 depends on TOYBOX_HELP
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
13 help
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
14 usage: help [command]
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
15
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
16 Show usage information for toybox commands.
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
17 Run "toybox" with no arguments for a list of available commands.
1232
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
18
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
19 config HELP_EXTRAS
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
20 bool "help -ah"
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
21 default y
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
22 depends on TOYBOX
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
23 depends on HELP
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
24 help
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
25 usage: help [-ah]
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
26
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
27 -a All commands
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
28 -h HTML output
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
29 */
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
30
1232
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
31 #define FOR_help
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
32 #include "toys.h"
139
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
33
1232
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
34 static void do_help(struct toy_list *t)
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
35 {
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
36 if (toys.optflags & FLAG_h)
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
37 xprintf("<a name=\"%s\"><h1>%s</h1><blockquote><pre>\n", t->name, t->name);
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
38
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
39 toys.which = t;
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
40 show_help();
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
41
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
42 if (toys.optflags & FLAG_h) xprintf("</blockquote></pre>\n");
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
43 }
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
44
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
45 // The simple help is just toys.which = toy_find("name"); show_help();
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
46 // But iterating through html output and all commands is a big more
139
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
47
186
25447caf1b4b Change command main() functions to return void, and exit(toys.exitval) from
Rob Landley <rob@landley.net>
parents: 182
diff changeset
48 void help_main(void)
139
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
49 {
1232
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
50 int i;
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
51
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
52 if (!(toys.optflags & FLAG_a)) {
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
53 struct toy_list *t = toys.which;
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
54
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
55 if (*toys.optargs && !(t = toy_find(*toys.optargs)))
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
56 error_exit("Unknown command '%s'", *toys.optargs);
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
57 do_help(t);
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
58 return;
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
59 }
139
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
60
1232
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
61 if (toys.optflags & FLAG_h) {
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
62 xprintf("<html>\n<title>Toybox command list</title>\n<body>\n<p>\n");
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
63 for (i=0; i < toys.toycount; i++)
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
64 xprintf("<a href=\"#%s\">%s</a>\n", toy_list[i].name,
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
65 toy_list[i].name);
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
66 xprintf("</p>\n");
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
67 }
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
68
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
69 for (i = 0; i < toys.toycount; i++) {
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
70 if (toys.optflags & FLAG_h) xprintf("<hr>\n<pre>\n");
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
71 do_help(toy_list+i);
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
72 if (toys.optflags & FLAG_h) xprintf("</pre>\n");
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
73 }
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
74
4654f241ccbe Add help -a (to show all commands) and -h (to produce HTML output).
Rob Landley <rob@landley.net>
parents: 858
diff changeset
75 if (toys.optflags & FLAG_h) xprintf("</html>");
139
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
76 }