MCPcopy Create free account
hub / github.com/F-Stack/f-stack / MatchCommand

Function MatchCommand

tools/ngctl/main.c:548–569  ·  view source on GitHub ↗

* See if string matches a prefix of "cmd" (or an alias) case insensitively */

Source from the content-addressed store, hash-verified

546 * See if string matches a prefix of "cmd" (or an alias) case insensitively
547 */
548static int
549MatchCommand(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()

Callers 1

FindCommandFunction · 0.85

Calls 2

strcspnFunction · 0.85
strncasecmpFunction · 0.85

Tested by

no test coverage detected