annotate toys/help.c @ 139:fb0745eec453

Add "help" command. (Building help/help.h requires python, but I'll ship that file with release versions.)
author Rob Landley <rob@landley.net>
date Wed, 29 Aug 2007 08:10:01 -0500
parents
children 1fbc50374a30
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
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
4 */
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
5
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
6 #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
7 #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
8
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
9 #undef NEWTOY
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
10 #undef OLDTOY
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
11 #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
12 #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
13 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
14 #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
15 ;
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
16
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
17 int help_main(void)
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
18 {
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
19 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
20 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
21 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
22
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
23 if (!t) error_exit("Unknown command '%s'\n", *toys.optargs);
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
24 for (;;) {
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
25 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
26 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
27 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
28 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
29 }
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 printf("%s", s);
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
32 return 0;
fb0745eec453 Add "help" command. (Building help/help.h requires python, but I'll ship
Rob Landley <rob@landley.net>
parents:
diff changeset
33 }