• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Function to display help text
2 
3 #include "toys.h"
4 
5 #if !CFG_TOYBOX_HELP
show_help(FILE * out)6 void show_help(FILE *out) {;}
7 #else
8 #include "generated/help.h"
9 
10 #undef NEWTOY
11 #undef OLDTOY
12 #define NEWTOY(name,opt,flags) HELP_##name "\0"
13 #define OLDTOY(name,oldname,flags) "\xff" #oldname "\0"
14 static char *help_data =
15 #include "generated/newtoys.h"
16 ;
17 
show_help(FILE * out)18 void show_help(FILE *out)
19 {
20   int i = toys.which-toy_list;
21   char *s;
22 
23   for (;;) {
24     s = help_data;
25     while (i--) s += strlen(s) + 1;
26     // If it's an alias, restart search for real name
27     if (*s != 255) break;
28     if (!CFG_TOYBOX) {
29       s = xmprintf("See %s --help\n", ++s);
30 
31       break;
32     }
33     i = toy_find(++s)-toy_list;
34   }
35 
36   fprintf(out, "%s", s);
37 }
38 #endif
39