summaryrefslogtreecommitdiff
path: root/source3/client
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2001-03-19 00:22:52 +0000
committerAndrew Tridgell <tridge@samba.org>2001-03-19 00:22:52 +0000
commite17e7b64175dcfc9963405a9fa3724f8d7097d89 (patch)
treeeef4b00b64ea7ff5ded424c11af81afdb476c2bc /source3/client
parent4c9f7ab7f6e7fecfa6e4bc5f8476251e35b8b363 (diff)
downloadsamba-e17e7b64175dcfc9963405a9fa3724f8d7097d89.tar.gz
samba-e17e7b64175dcfc9963405a9fa3724f8d7097d89.tar.bz2
samba-e17e7b64175dcfc9963405a9fa3724f8d7097d89.zip
added basic command completion support
(This used to be commit 386fdff2dfeaeef60b210ebc0b4d33a6c7b5d5ec)
Diffstat (limited to 'source3/client')
-rw-r--r--source3/client/client.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/source3/client/client.c b/source3/client/client.c
index 83e1c696a4..059bde3c41 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -1752,6 +1752,40 @@ static void process_command_string(char *cmd)
}
}
+/****************************************************************************
+handle completion of commands for readline
+****************************************************************************/
+static char **completion_fn(char *text, int start, int end)
+{
+#define MAX_COMPLETIONS 100
+ char **matches;
+ int i, count=0;
+
+ /* for words not at the start of the line fallback to filename completion */
+ if (start) return NULL;
+
+ matches = (char **)malloc(sizeof(matches[0])*MAX_COMPLETIONS);
+ if (!matches) return NULL;
+
+ matches[count++] = strdup(text);
+ if (!matches[0]) return NULL;
+
+ for (i=0;commands[i].fn && count < MAX_COMPLETIONS-1;i++) {
+ if (strncmp(text, commands[i].name, strlen(text)) == 0) {
+ matches[count] = strdup(commands[i].name);
+ if (!matches[count]) return NULL;
+ count++;
+ }
+ }
+
+ if (count == 2) {
+ free(matches[0]);
+ matches[0] = strdup(matches[1]);
+ }
+ matches[count] = NULL;
+ return matches;
+}
+
/****************************************************************************
make sure we swallow keepalives during idle time
@@ -1805,7 +1839,7 @@ static void process_stdin(void)
/* display a prompt */
slprintf(prompt, sizeof(prompt), "smb: %s> ", cur_dir);
- line = smb_readline(prompt, readline_callback);
+ line = smb_readline(prompt, readline_callback, completion_fn);
if (!line) break;