blob: 515a09b5d2c7c8a49924daf72397907bb7d77490 [file] [log] [blame]
Rob Landley28964802008-01-19 17:08:39 -06001/* vi: set sw=4 ts=4:
2 *
Rob Landley7ecedea2007-08-29 08:10:01 -05003 * help.c - Show help for toybox
Rob Landleyfece5cb2007-12-03 20:05:57 -06004 *
Rob Landley28964802008-01-19 17:08:39 -06005 * Copyright 2007 Rob Landley <rob@landley.net>
6 *
Rob Landleyfece5cb2007-12-03 20:05:57 -06007 * Not in SUSv3, but exists as a bash builtin.
Rob Landley28964802008-01-19 17:08:39 -06008
Rob Landley55928b12008-01-19 17:43:27 -06009USE_HELP(NEWTOY(help, "<1", TOYFLAG_BIN))
10
Rob Landley28964802008-01-19 17:08:39 -060011config HELP
12 bool "help"
13 default y
14 help
15 usage: help [command]
16
17 Show usage information for toybox commands.
18
19config HELP_LONG
20 bool "Verbose help text"
21 default y
22 depends on HELP
23 help
24 Show more than one line of help information per command.
25*/
26
Rob Landley7ecedea2007-08-29 08:10:01 -050027
28#include "toys.h"
Rob Landley58ecc3e2008-01-10 14:40:13 -060029#include "generated/help.h"
Rob Landley7ecedea2007-08-29 08:10:01 -050030
31#undef NEWTOY
32#undef OLDTOY
33#define NEWTOY(name,opt,flags) help_##name "\0"
34#define OLDTOY(name,oldname,opts,flags) "\xff" #oldname "\0"
35static char *help_data =
Rob Landley55928b12008-01-19 17:43:27 -060036#include "generated/newtoys.h"
Rob Landley7ecedea2007-08-29 08:10:01 -050037;
38
Rob Landleyefda21c2007-11-29 18:14:37 -060039void help_main(void)
Rob Landley7ecedea2007-08-29 08:10:01 -050040{
41 struct toy_list *t = toy_find(*toys.optargs);
42 int i = t-toy_list;
43 char *s = help_data;
44
Rob Landley860f2632007-11-27 01:41:32 -060045 if (!t) error_exit("Unknown command '%s'", *toys.optargs);
Rob Landley7ecedea2007-08-29 08:10:01 -050046 for (;;) {
47 while (i--) s += strlen(s) + 1;
48 if (*s != 255) break;
49 i = toy_find(++s)-toy_list;
50 s = help_data;
51 }
52
Rob Landleyd06c58d2007-10-11 15:36:36 -050053 fprintf(toys.exithelp ? stderr : stdout, "%s", s);
Rob Landley7ecedea2007-08-29 08:10:01 -050054}