Mercurial > hg > toybox
annotate lib/help.c @ 1766:190ecf70fbe5 draft
Fix an obvious typo in Makefile.
author | Elliott Hughes <enh@google.com> |
---|---|
date | Sat, 28 Mar 2015 13:13:42 -0500 |
parents | 5fac2769a159 |
children |
rev | line source |
---|---|
858
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1 // Function to display help text |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3 #include "toys.h" |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
4 |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
5 #if !CFG_TOYBOX_HELP |
888
c5e80c74ec6c
Fix conflicting types for show_help().
Rob Landley <rob@landley.net>
parents:
858
diff
changeset
|
6 void show_help(void) {;} |
858
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
7 #else |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
8 #include "generated/help.h" |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
9 |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
10 #undef NEWTOY |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
11 #undef OLDTOY |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
12 #define NEWTOY(name,opt,flags) help_##name "\0" |
1634
5fac2769a159
Redo option parsing infrastructure so #define FORCE_FLAGS can unzero flag macros for a disabled command (needed when multiple commands share infrastructure with a common set of flags).
Rob Landley <rob@landley.net>
parents:
1501
diff
changeset
|
13 #define OLDTOY(name,oldname,flags) "\xff" #oldname "\0" |
858
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
14 static char *help_data = |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
15 #include "generated/newtoys.h" |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
16 ; |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
17 |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
18 void show_help(void) |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
19 { |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
20 int i = toys.which-toy_list; |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
21 char *s; |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
22 |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
23 for (;;) { |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
24 s = help_data; |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
25 while (i--) s += strlen(s) + 1; |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
26 // If it's an alias, restart search for real name |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
27 if (*s != 255) break; |
1501
c51a4dbe5db7
Don't segfault for --help of single.sh build of OLDTOY commands that use another command's help.
Rob Landley <rob@landley.net>
parents:
888
diff
changeset
|
28 if (!CFG_TOYBOX) { |
c51a4dbe5db7
Don't segfault for --help of single.sh build of OLDTOY commands that use another command's help.
Rob Landley <rob@landley.net>
parents:
888
diff
changeset
|
29 s = xmprintf("See %s --help\n", ++s); |
c51a4dbe5db7
Don't segfault for --help of single.sh build of OLDTOY commands that use another command's help.
Rob Landley <rob@landley.net>
parents:
888
diff
changeset
|
30 |
c51a4dbe5db7
Don't segfault for --help of single.sh build of OLDTOY commands that use another command's help.
Rob Landley <rob@landley.net>
parents:
888
diff
changeset
|
31 break; |
c51a4dbe5db7
Don't segfault for --help of single.sh build of OLDTOY commands that use another command's help.
Rob Landley <rob@landley.net>
parents:
888
diff
changeset
|
32 } |
858
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
33 i = toy_find(++s)-toy_list; |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
34 } |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
35 |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
36 fprintf(toys.exithelp ? stderr : stdout, "%s", s); |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
37 } |
34ac05521d94
Move guts of help command into show_help() in lib/help.c, with config TOYBOX_HELP controlling infrastructure.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
38 #endif |