* HelpCmd() */
| 599 | * HelpCmd() |
| 600 | */ |
| 601 | static int |
| 602 | HelpCmd(int ac, char **av) |
| 603 | { |
| 604 | const struct ngcmd *cmd; |
| 605 | int k; |
| 606 | |
| 607 | switch (ac) { |
| 608 | case 0: |
| 609 | case 1: |
| 610 | /* Show all commands */ |
| 611 | printf("Available commands:\n"); |
| 612 | for (k = 0; cmds[k] != NULL; k++) { |
| 613 | char *s, buf[100]; |
| 614 | |
| 615 | cmd = cmds[k]; |
| 616 | snprintf(buf, sizeof(buf), "%s", cmd->cmd); |
| 617 | for (s = buf; *s != '\0' && !isspace(*s); s++); |
| 618 | *s = '\0'; |
| 619 | printf(" %-10s %s\n", buf, cmd->desc); |
| 620 | } |
| 621 | return (CMDRTN_OK); |
| 622 | default: |
| 623 | /* Show help on a specific command */ |
| 624 | if ((cmd = FindCommand(av[1])) != NULL) { |
| 625 | printf("usage: %s\n", cmd->cmd); |
| 626 | if (cmd->aliases[0] != NULL) { |
| 627 | int a = 0; |
| 628 | |
| 629 | printf("Aliases: "); |
| 630 | while (1) { |
| 631 | printf("%s", cmd->aliases[a++]); |
| 632 | if (a == MAX_CMD_ALIAS |
| 633 | || cmd->aliases[a] == NULL) { |
| 634 | printf("\n"); |
| 635 | break; |
| 636 | } |
| 637 | printf(", "); |
| 638 | } |
| 639 | } |
| 640 | printf("Summary: %s\n", cmd->desc); |
| 641 | if (cmd->help != NULL) { |
| 642 | const char *s; |
| 643 | char buf[65]; |
| 644 | int tot, len, done; |
| 645 | |
| 646 | printf("Description:\n"); |
| 647 | for (s = cmd->help; *s != '\0'; s += len) { |
| 648 | while (isspace(*s)) |
| 649 | s++; |
| 650 | tot = snprintf(buf, |
| 651 | sizeof(buf), "%s", s); |
| 652 | len = strlen(buf); |
| 653 | done = len == tot; |
| 654 | if (!done) { |
| 655 | while (len > 0 |
| 656 | && !isspace(buf[len-1])) |
| 657 | buf[--len] = '\0'; |
| 658 | } |
nothing calls this directly
no test coverage detected