aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2005-09-25 17:26:52 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2005-09-25 17:26:52 +0000
commitd0d9b0f1922fafd27cad4436c29d70fa90d8cffd (patch)
tree0565e1ef3f4b11ff3f0512ef047909d4d6590788
parentb2951e6b76b50f45a7999aef1e09e90fb1c4c8cf (diff)
fix incorrect CLI tab completion (issue #5041)
git-svn-id: http://svn.digium.com/svn/asterisk/branches/v1-0@6647 f38db490-d61c-443f-a65b-d21fe96a405b
-rwxr-xr-xcli.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/cli.c b/cli.c
index 11edf1faf..34fb016d6 100755
--- a/cli.c
+++ b/cli.c
@@ -756,7 +756,7 @@ static struct ast_cli_entry *find_cli(char *cmds[], int exact)
return e;
}
-static void join(char *dest, size_t destsize, char *w[])
+static void join(char *dest, size_t destsize, char *w[], int tws)
{
int x;
/* Join words into a string */
@@ -769,6 +769,8 @@ static void join(char *dest, size_t destsize, char *w[])
strncat(dest, " ", destsize - strlen(dest) - 1);
strncat(dest, w[x], destsize - strlen(dest) - 1);
}
+ if (tws)
+ strncat(dest, " ", destsize - strlen(dest) - 1);
}
static void join2(char *dest, size_t destsize, char *w[])
@@ -797,7 +799,7 @@ static char *find_best(char *argv[])
if (!find_cli(myargv, -1))
break;
}
- join(cmdline, sizeof(cmdline), myargv);
+ join(cmdline, sizeof(cmdline), myargv, 0);
return cmdline;
}
@@ -879,12 +881,12 @@ static int help_workhorse(int fd, char *match[])
e1 = builtins;
e2 = helpers;
if (match)
- join(matchstr, sizeof(matchstr), match);
+ join(matchstr, sizeof(matchstr), match, 0);
while(e1->cmda[0] || e2) {
if (e2)
- join(fullcmd2, sizeof(fullcmd2), e2->cmda);
+ join(fullcmd2, sizeof(fullcmd2), e2->cmda, 0);
if (e1->cmda[0])
- join(fullcmd1, sizeof(fullcmd1), e1->cmda);
+ join(fullcmd1, sizeof(fullcmd1), e1->cmda, 0);
if (!e1->cmda[0] ||
(e2 && (strcmp(fullcmd2, fullcmd1) < 0))) {
/* Use e2 */
@@ -922,14 +924,14 @@ static int handle_help(int fd, int argc, char *argv[]) {
if (e->usage)
ast_cli(fd, "%s", e->usage);
else {
- join(fullcmd, sizeof(fullcmd), argv+1);
+ join(fullcmd, sizeof(fullcmd), argv+1, 0);
ast_cli(fd, "No help text available for '%s'.\n", fullcmd);
}
} else {
if (find_cli(argv + 1, -1)) {
return help_workhorse(fd, argv + 1);
} else {
- join(fullcmd, sizeof(fullcmd), argv+1);
+ join(fullcmd, sizeof(fullcmd), argv+1, 0);
ast_cli(fd, "No such command '%s'.\n", fullcmd);
}
}
@@ -939,7 +941,7 @@ static int handle_help(int fd, int argc, char *argv[]) {
return RESULT_SUCCESS;
}
-static char *parse_args(char *s, int *argc, char *argv[], int max)
+static char *parse_args(char *s, int *argc, char *argv[], int max, int *trailingwhitespace)
{
char *dup, *cur;
int x = 0;
@@ -947,6 +949,7 @@ static char *parse_args(char *s, int *argc, char *argv[], int max)
int escaped = 0;
int whitespace = 1;
+ *trailingwhitespace = 0;
if (!(dup = strdup(s)))
return NULL;
@@ -994,7 +997,7 @@ static char *parse_args(char *s, int *argc, char *argv[], int max)
*(cur++) = '\0';
argv[x] = NULL;
*argc = x;
-
+ *trailingwhitespace = whitespace;
return dup;
}
@@ -1066,18 +1069,19 @@ static char *__ast_cli_generator(char *text, char *word, int state, int lock)
char fullcmd2[80] = "";
char matchstr[80];
char *fullcmd = NULL;
+ int tws;
- if ((dup = parse_args(text, &x, argv, sizeof(argv) / sizeof(argv[0])))) {
- join(matchstr, sizeof(matchstr), argv);
+ if ((dup = parse_args(text, &x, argv, sizeof(argv) / sizeof(argv[0]), &tws))) {
+ join(matchstr, sizeof(matchstr), argv, tws);
if (lock)
ast_mutex_lock(&clilock);
e1 = builtins;
e2 = helpers;
while(e1->cmda[0] || e2) {
if (e2)
- join(fullcmd2, sizeof(fullcmd2), e2->cmda);
+ join(fullcmd2, sizeof(fullcmd2), e2->cmda, tws);
if (e1->cmda[0])
- join(fullcmd1, sizeof(fullcmd1), e1->cmda);
+ join(fullcmd1, sizeof(fullcmd1), e1->cmda, tws);
if (!e1->cmda[0] ||
(e2 && (strcmp(fullcmd2, fullcmd1) < 0))) {
/* Use e2 */
@@ -1138,8 +1142,9 @@ int ast_cli_command(int fd, char *s)
struct ast_cli_entry *e;
int x;
char *dup;
+ int tws;
- if ((dup = parse_args(s, &x, argv, sizeof(argv) / sizeof(argv[0])))) {
+ if ((dup = parse_args(s, &x, argv, sizeof(argv) / sizeof(argv[0]), &tws))) {
/* We need at least one entry, or ignore */
if (x > 0) {
ast_mutex_lock(&clilock);