diff options
author | Ondrej Zajicek <santiago@crfreenet.org> | 2012-03-22 11:46:38 +0100 |
---|---|---|
committer | Ondrej Zajicek <santiago@crfreenet.org> | 2012-03-22 12:13:26 +0100 |
commit | c47d037ecb5b9c835700b152eed7589409a2e42f (patch) | |
tree | 5b68978bc6af43b93d2772dece1b66a9996e4fcf /client/commands.c | |
parent | df27911880bffb88c1eae90e36c755a3ed3d77ad (diff) |
Some minor changes to CLI.
Diffstat (limited to 'client/commands.c')
-rw-r--r-- | client/commands.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/client/commands.c b/client/commands.c index 7612b64c..08e7949a 100644 --- a/client/commands.c +++ b/client/commands.c @@ -29,6 +29,7 @@ struct cmd_node { struct cmd_node *sibling, *son, **plastson; struct cmd_info *cmd, *help; int len; + signed char prio; char token[1]; }; @@ -66,6 +67,7 @@ cmd_build_tree(void) new->plastson = &new->son; new->len = c-d; memcpy(new->token, d, c-d); + new->prio = (new->len == 3 && !memcmp(new->token, "roa", 3)) ? 0 : 1; /* Hack */ } old = new; while (isspace(*c)) @@ -108,7 +110,10 @@ cmd_find_abbrev(struct cmd_node *root, char *cmd, int len, int *pambiguous) return m; if (m->len > len && !memcmp(m->token, cmd, len)) { - best2 = best; + if (best && best->prio > m->prio) + continue; + if (best && best->prio == m->prio) + best2 = best; best = m; } } @@ -168,19 +173,31 @@ static int cmd_find_common_match(struct cmd_node *root, char *cmd, int len, int *pcount, char *buf) { struct cmd_node *m; - int best, i; + int best, best_prio, i; *pcount = 0; best = -1; + best_prio = -1; for(m=root->son; m; m=m->sibling) { if (m->len < len || memcmp(m->token, cmd, len)) continue; + + if (best_prio > m->prio) + continue; + + if (best_prio < m->prio) + { + *pcount = 0; + best = -1; + } + (*pcount)++; if (best < 0) { strcpy(buf, m->token + len); best = m->len - len; + best_prio = m->prio; } else { |