10f66f451Sopenharmony_ci// Function to display help text
20f66f451Sopenharmony_ci
30f66f451Sopenharmony_ci#include "toys.h"
40f66f451Sopenharmony_ci
50f66f451Sopenharmony_ci#include "generated/help.h"
60f66f451Sopenharmony_ci
70f66f451Sopenharmony_ci#undef NEWTOY
80f66f451Sopenharmony_ci#undef OLDTOY
90f66f451Sopenharmony_ci#define NEWTOY(name,opt,flags) HELP_##name "\0"
100f66f451Sopenharmony_ci#if CFG_TOYBOX
110f66f451Sopenharmony_ci#define OLDTOY(name,oldname,flags) "\xff" #oldname "\0"
120f66f451Sopenharmony_ci#else
130f66f451Sopenharmony_ci#define OLDTOY(name, oldname, flags) HELP_##oldname "\0"
140f66f451Sopenharmony_ci#endif
150f66f451Sopenharmony_cistatic char *help_data =
160f66f451Sopenharmony_ci#include "generated/newtoys.h"
170f66f451Sopenharmony_ci;
180f66f451Sopenharmony_ci
190f66f451Sopenharmony_civoid show_help(FILE *out)
200f66f451Sopenharmony_ci{
210f66f451Sopenharmony_ci  int i = toys.which-toy_list;
220f66f451Sopenharmony_ci  char *s;
230f66f451Sopenharmony_ci
240f66f451Sopenharmony_ci  if (CFG_TOYBOX_HELP) {
250f66f451Sopenharmony_ci    for (;;) {
260f66f451Sopenharmony_ci      s = help_data;
270f66f451Sopenharmony_ci      while (i--) s += strlen(s) + 1;
280f66f451Sopenharmony_ci      // If it's an alias, restart search for real name
290f66f451Sopenharmony_ci      if (*s != 255) break;
300f66f451Sopenharmony_ci      i = toy_find(++s)-toy_list;
310f66f451Sopenharmony_ci    }
320f66f451Sopenharmony_ci
330f66f451Sopenharmony_ci    fprintf(out, "%s\n", s);
340f66f451Sopenharmony_ci  }
350f66f451Sopenharmony_ci}
36