diff options
author | Eric Faurot <eric@faurot.net> | 2013-07-19 11:27:20 +0200 |
---|---|---|
committer | Eric Faurot <eric@faurot.net> | 2013-07-19 11:27:20 +0200 |
commit | c6f6dc5adc7fbdc4f6e09c9a6b3143c18e8e9bd1 (patch) | |
tree | 247d3e3deedcfe7d65ac6f536061b9db2494348a /smtpd/parser.c | |
parent | Error out if the state is invalid. (diff) | |
download | OpenSMTPD-c6f6dc5adc7fbdc4f6e09c9a6b3143c18e8e9bd1.tar.xz OpenSMTPD-c6f6dc5adc7fbdc4f6e09c9a6b3143c18e8e9bd1.zip |
Implement command abbreviation when there is no ambiguity.
Diffstat (limited to 'smtpd/parser.c')
-rw-r--r-- | smtpd/parser.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/smtpd/parser.c b/smtpd/parser.c index d10f2eb9..05c563fb 100644 --- a/smtpd/parser.c +++ b/smtpd/parser.c @@ -174,7 +174,7 @@ int cmd_run(int argc, char **argv) { struct parameter param[ARGVMAX]; - struct node *node, *tmp, *stack[ARGVMAX]; + struct node *node, *tmp, *stack[ARGVMAX], *best; int i, j, np; node = root; @@ -191,8 +191,25 @@ cmd_run(int argc, char **argv) break; } } - if (tmp == NULL) - goto fail; + if (tmp == NULL) { + best = NULL; + TAILQ_FOREACH(tmp, &node->children, entry) { + if (tmp->type != P_TOKEN) + continue; + if (strstr(tmp->token, argv[i]) != tmp->token) + continue; + if (best) + goto fail; + best = tmp; + } + if (best == NULL) + goto fail; + stack[i] = best; + node = best; + param[np].type = node->type; + if (node->type != P_TOKEN) + np++; + } } if (node->cmd == NULL) |