comparison 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
comparison
equal deleted inserted replaced
138:668d5abde8b0 139:fb0745eec453
1 /* vi: set sw=4 ts=4: */
2 /*
3 * help.c - Show help for toybox
4 */
5
6 #include "toys.h"
7 #include "toys/help.h"
8
9 #undef NEWTOY
10 #undef OLDTOY
11 #define NEWTOY(name,opt,flags) help_##name "\0"
12 #define OLDTOY(name,oldname,opts,flags) "\xff" #oldname "\0"
13 static char *help_data =
14 #include "toys/toylist.h"
15 ;
16
17 int help_main(void)
18 {
19 struct toy_list *t = toy_find(*toys.optargs);
20 int i = t-toy_list;
21 char *s = help_data;
22
23 if (!t) error_exit("Unknown command '%s'\n", *toys.optargs);
24 for (;;) {
25 while (i--) s += strlen(s) + 1;
26 if (*s != 255) break;
27 i = toy_find(++s)-toy_list;
28 s = help_data;
29 }
30
31 printf("%s", s);
32 return 0;
33 }