* See if string matches a prefix of "cmd" (or an alias) case insensitively */
| 546 | * See if string matches a prefix of "cmd" (or an alias) case insensitively |
| 547 | */ |
| 548 | static int |
| 549 | MatchCommand(const struct ngcmd *cmd, const char *s) |
| 550 | { |
| 551 | int a; |
| 552 | |
| 553 | /* Try to match command, ignoring the usage stuff */ |
| 554 | if (strlen(s) <= strcspn(cmd->cmd, WHITESPACE)) { |
| 555 | if (strncasecmp(s, cmd->cmd, strlen(s)) == 0) |
| 556 | return (1); |
| 557 | } |
| 558 | |
| 559 | /* Try to match aliases */ |
| 560 | for (a = 0; a < MAX_CMD_ALIAS && cmd->aliases[a] != NULL; a++) { |
| 561 | if (strlen(cmd->aliases[a]) >= strlen(s)) { |
| 562 | if (strncasecmp(s, cmd->aliases[a], strlen(s)) == 0) |
| 563 | return (1); |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | /* No match */ |
| 568 | return (0); |
| 569 | } |
| 570 | |
| 571 | /* |
| 572 | * ReadCmd() |
no test coverage detected