annotate toys/help.c @ 194:30a6db5a95c2

Add comments about SUSv3 specs (or lack thereof).
author Rob Landley <rob@landley.net>
date Mon, 03 Dec 2007 20:05:57 -0600
parents 25447caf1b4b
children cd4d5630c978
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
139
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
1 /* vi: set sw=4 ts=4: */
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
2 /*
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 *
30a6db5a95c2 Add comments about SUSv3 specs (or lack thereof).
Rob Landley <rob@landley.net>
parents: 186
diff changeset
5 * Not in SUSv3, but exists as a bash builtin.
139
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
6 */
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
7
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
8 #include "toys.h"
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
9 #include "toys/help.h"
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
10
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
11 #undef NEWTOY
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
12 #undef OLDTOY
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
13 #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
14 #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
15 static char *help_data =
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
16 #include "toys/toylist.h"
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
17 ;
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
18
186
25447caf1b4b Change command main() functions to return void, and exit(toys.exitval) from
Rob Landley <rob@landley.net>
parents: 182
diff changeset
19 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
20 {
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
21 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
22 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
23 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
24
182
ed26d3529575 Patch from Charlie Shepherd: remove extra \n from error_exit() arguments.
Rob Landley <rob@landley.net>
parents: 144
diff changeset
25 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
26 for (;;) {
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
27 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
28 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
29 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
30 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
31 }
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
32
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
33 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
34 }