Exemplo n.º 1
0
void help_main(void)
{
  int i;
  
  if (!(toys.optflags & FLAG_a)) {
    struct toy_list *t = toys.which;

    if (*toys.optargs && !(t = toy_find(*toys.optargs)))
      error_exit("Unknown command '%s'", *toys.optargs);
    do_help(t);
    return;
  }

  if (toys.optflags & FLAG_h) {
    xprintf("<html>\n<title>Toybox command list</title>\n<body>\n<p>\n");
    for (i=0; i < toys.toycount; i++)
      xprintf("<a href=\"#%s\">%s</a>\n", toy_list[i].name,
              toy_list[i].name);
    xprintf("</p>\n");
  }

  for (i = 0; i < toys.toycount; i++) {
    if (toys.optflags & FLAG_h) xprintf("<hr>\n<pre>\n");
    do_help(toy_list+i);
    if (toys.optflags & FLAG_h) xprintf("</pre>\n");
  }

  if (toys.optflags & FLAG_h) xprintf("</html>");
}
Exemplo n.º 2
0
Arquivo: help.c Projeto: emaste/toybox
void show_help(FILE *out)
{
  int i = toys.which-toy_list;
  char *s;

  if (CFG_TOYBOX_HELP) {
    for (;;) {
      s = help_data;
      while (i--) s += strlen(s) + 1;
      // If it's an alias, restart search for real name
      if (*s != 255) break;
      i = toy_find(++s)-toy_list;
    }

    fprintf(out, "%s", s);
  }
}
Exemplo n.º 3
0
// Like exec() but runs an internal toybox command instead of another file.
// Only returns if it can't run command internally, otherwise exit() when done.
void toy_exec(char *argv[])
{
  struct toy_list *which;

  // Return if we can't find it (which includes no multiplexer case),
  if (!(which = toy_find(*argv))) return;

  // Return if stack depth getting noticeable (proxy for leaked heap, etc).
  if (toys.stacktop && labs((char *)toys.stacktop-(char *)&which)>6000)
    return;

  // Return if we need to re-exec to acquire root via suid bit.
  if (toys.which && (which->flags&TOYFLAG_ROOTONLY) && toys.wasroot) return;

  // Run command
  toy_init(which, argv);
  if (toys.which) toys.which->toy_main();
  xexit();
}
Exemplo n.º 4
0
// Setup toybox global state for this command.
static void toy_singleinit(struct toy_list *which, char *argv[])
{
  toys.which = which;
  toys.argv = argv;

  if (CFG_TOYBOX_I18N) setlocale(LC_ALL, "C"+!!(which->flags & TOYFLAG_LOCALE));

  if (CFG_TOYBOX_HELP_DASHDASH && argv[1] && !strcmp(argv[1], "--help")) {
    if (CFG_TOYBOX && toys.which == toy_list && toys.argv[2])
      if (!(toys.which = toy_find(toys.argv[2]))) return;
    show_help(stdout);
    xexit();
  }

  if (NEED_OPTIONS && which->options) get_optflags();
  else {
    toys.optargs = argv+1;
    for (toys.optc = 0; toys.optargs[toys.optc]; toys.optc++);
  }
  toys.old_umask = umask(0);
  if (!(which->flags & TOYFLAG_UMASK)) umask(toys.old_umask);
  toys.signalfd--;
  toys.toycount = ARRAY_LEN(toy_list);
}