annotate toys/help.c @ 241:4121825716b8

Fix crash when running unknown command via symlink. (The error message was trying to print an uninitialied field. Oops.)
author Rob Landley <rob@landley.net>
date Tue, 22 Jan 2008 15:33:50 -0600
parents 163498bf547b
children cb3c3c85b966
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
1 /* vi: set sw=4 ts=4:
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
2 *
139
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * help.c - Show help for toybox
194
30a6db5a95c2 Add comments about SUSv3 specs (or lack thereof).
Rob Landley <rob@landley.net>
parents: 186
diff changeset
4 *
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
5 * 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
6 *
194
30a6db5a95c2 Add comments about SUSv3 specs (or lack thereof).
Rob Landley <rob@landley.net>
parents: 186
diff changeset
7 * Not in SUSv3, but exists as a bash 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
8
234
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
9 USE_HELP(NEWTOY(help, "<1", TOYFLAG_BIN))
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
10
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
11 config HELP
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
12 bool "help"
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
13 default y
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
14 help
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
15 usage: help [command]
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
16
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
17 Show usage information for toybox commands.
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
18
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
19 config HELP_LONG
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
20 bool "Verbose help text"
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
21 default y
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
22 depends on HELP
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
23 help
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
24 Show more than one line of help information per command.
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
25 */
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
26
139
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
27
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
28 #include "toys.h"
232
cd4d5630c978 Move some generated files into the "generated" subdirectory.
Rob Landley <rob@landley.net>
parents: 194
diff changeset
29 #include "generated/help.h"
139
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
30
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
31 #undef NEWTOY
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
32 #undef OLDTOY
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
33 #define NEWTOY(name,opt,flags) help_##name "\0"
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
34 #define OLDTOY(name,oldname,opts,flags) "\xff" #oldname "\0"
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
35 static char *help_data =
234
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
36 #include "generated/newtoys.h"
139
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
37 ;
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
38
186
25447caf1b4b Change command main() functions to return void, and exit(toys.exitval) from
Rob Landley <rob@landley.net>
parents: 182
diff changeset
39 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
40 {
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
41 struct toy_list *t = toy_find(*toys.optargs);
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
42 int i = t-toy_list;
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
43 char *s = help_data;
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
44
182
ed26d3529575 Patch from Charlie Shepherd: remove extra \n from error_exit() arguments.
Rob Landley <rob@landley.net>
parents: 144
diff changeset
45 if (!t) error_exit("Unknown command '%s'", *toys.optargs);
139
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
46 for (;;) {
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
47 while (i--) s += strlen(s) + 1;
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
48 if (*s != 255) break;
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
49 i = toy_find(++s)-toy_list;
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
50 s = help_data;
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
51 }
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
52
144
1fbc50374a30 Promote help to global config option, teach error_exit() to output usage message when called
Rob Landley <rob@landley.net>
parents: 139
diff changeset
53 fprintf(toys.exithelp ? stderr : stdout, "%s", s);
139
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
54 }