1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#define FOR_help
25#include "toys.h"
26
27static void do_help(struct toy_list *t)
28{
29 if (FLAG(h))
30 xprintf("<a name=\"%s\"><h1>%s</h1><blockquote><pre>\n", t->name, t->name);
31
32 toys.which = t;
33 show_help(stdout, !FLAG(u)+(!!toys.argv[1]<<1)+(!!FLAG(h)<<2));
34
35 if (FLAG(h)) xprintf("</blockquote></pre>\n");
36}
37
38
39
40
41void help_main(void)
42{
43 int i;
44
45
46 if (toys.rebound && !*toys.optargs && !toys.optflags) {
47 for (i = 0; i < toys.toycount; i++) {
48 if (!(toy_list[i].flags&(TOYFLAG_NOFORK|TOYFLAG_MAYFORK))) continue;
49 toys.which = toy_list+i;
50 show_help(stdout, FLAG(u));
51 }
52 return;
53 }
54
55 if (!FLAG(a)) {
56 struct toy_list *t = toys.which;
57
58 if (*toys.optargs && !(t = toy_find(*toys.optargs)))
59 error_exit("Unknown command '%s'", *toys.optargs);
60 do_help(t);
61 return;
62 }
63
64 if (FLAG(h)) {
65 sprintf(toybuf, "Toybox %s command help", toybox_version);
66 xprintf("<html>\n<title>%s</title>\n<body>\n<h1>%s</h1><hr /><p>",
67 toybuf, toybuf);
68 for (i=0; i<toys.toycount; i++)
69 if (toy_list[i].flags)
70 xprintf("<a href=\"#%s\">%s</a> \n", toy_list[i].name,toy_list[i].name);
71 xprintf("</p>\n");
72 }
73
74 for (i = 0; i < toys.toycount; i++) {
75 if (!toy_list[i].flags) continue;
76 if (FLAG(h)) xprintf("<hr>\n<pre>\n");
77 else if (!FLAG(u)) {
78 memset(toybuf, '-', 78);
79 memcpy(toybuf+3, toy_list[i].name, strlen(toy_list[i].name));
80 printf("\n%s\n\n", toybuf);
81 }
82 do_help(toy_list+i);
83 if (FLAG(h)) xprintf("</pre>\n");
84 }
85
86 if (FLAG(h)) xprintf("</html>");
87}
88