1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31#define FOR_help
32#include "toys.h"
33
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(stdout);
41
42 if (toys.optflags & FLAG_h) xprintf("</blockquote></pre>\n");
43}
44
45
46
47
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\n</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 else {
72 memset(toybuf, '-', 78);
73 memcpy(toybuf+3, toy_list[i].name, strlen(toy_list[i].name));
74 printf("\n%s\n\n", toybuf);
75 }
76 do_help(toy_list+i);
77 if (toys.optflags & FLAG_h) xprintf("</pre>\n");
78 }
79
80 if (toys.optflags & FLAG_h) xprintf("</html>");
81}
82