diff options
author | Tim Potter <tpot@samba.org> | 1999-07-09 05:10:10 +0000 |
---|---|---|
committer | Tim Potter <tpot@samba.org> | 1999-07-09 05:10:10 +0000 |
commit | d244f2d1c8b50b231abe490ebbad054bc5789407 (patch) | |
tree | 66d2b5778fe7b51b59253fe729eeef31a0b32c66 /source3/rpcclient/rpcclient.c | |
parent | 6919a92aee585d1d64b89ec359d038e5a6fa9b7e (diff) | |
download | samba-d244f2d1c8b50b231abe490ebbad054bc5789407.tar.gz samba-d244f2d1c8b50b231abe490ebbad054bc5789407.tar.bz2 samba-d244f2d1c8b50b231abe490ebbad054bc5789407.zip |
Partial GNU readline support for rpcclient. Only command line history
and command completion implemented.
(This used to be commit 795fa6a5185d9e245541a44a971a3fb588168c1e)
Diffstat (limited to 'source3/rpcclient/rpcclient.c')
-rw-r--r-- | source3/rpcclient/rpcclient.c | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c index 25308697a6..72963222e5 100644 --- a/source3/rpcclient/rpcclient.c +++ b/source3/rpcclient/rpcclient.c @@ -324,8 +324,13 @@ static BOOL process( struct client_info *info, char *cmd_str) } else while (!feof(stdin)) { +#ifdef HAVE_LIBREADLINE + pstring promptline; +#endif fstring tok; +#ifndef HAVE_LIBREADLINE + /* display a prompt */ fprintf(out_hnd, "smb: %s> ", CNV_LANG(info->cur_dir)); fflush(out_hnd); @@ -351,6 +356,24 @@ static BOOL process( struct client_info *info, char *cmd_str) } #endif +#else /* HAVE_LIBREADLINE */ + + slprintf(promptline, sizeof(promptline) - 1, "smb: %s> ", + CNV_LANG(info->cur_dir)); + + if (!readline(promptline)) + break; + + /* Copy read line to samba buffer */ + + pstrcpy(line, rl_line_buffer); + pstrcat(line, "\n"); + + /* Add to history */ + + if (strlen(line) > 0) + add_history(line); +#endif /* input language code to internal one */ CNV_INPUT (line); @@ -405,6 +428,88 @@ enum client_action CLIENT_SVC }; +#ifdef HAVE_LIBREADLINE + +/* Complete an rpcclient command */ + +char *complete_cmd(char *text, int state) +{ + static int cmd_index; + char *name; + + /* Initialise */ + + if (state == 0) { + cmd_index = 0; + } + + /* Return the next name which partially matches the list of commands */ + + while (strlen(name = commands[cmd_index++].name) > 0) { + if (strncmp(name, text, strlen(text)) == 0) { + return strdup(name); + } + } + + return NULL; +} + +/* Main completion function */ + +char **completion_fn(char *text, int start, int end) +{ + int i, num_words, cmd_index; + char lastch = ' '; + + /* Complete rpcclient command */ + + if (start == 0) { + return completion_matches(text, complete_cmd); + } + + /* Count # of words in command */ + + num_words = 0; + for (i = 0; i <= end; i++) { + if ((rl_line_buffer[i] != ' ') && (lastch == ' ')) + num_words++; + lastch = rl_line_buffer[i]; + } + + if (rl_line_buffer[end] == ' ') + num_words++; + + /* Work out which command we are completing for */ + + for (cmd_index = 0; strcmp(commands[cmd_index].name, "") != 0; + cmd_index++) { + + /* Check each command in array */ + + if (strncmp(rl_line_buffer, commands[cmd_index].name, + strlen(commands[cmd_index].name)) == 0) { + + /* Call appropriate completion function */ + + } + } + + /* Eeek! */ + + return NULL; +} + +/* To avoid filename completion being activated when no valid + completions are found, we assign this stub completion function + to the rl_completion_entry_function variable. */ + +char *complete_cmd_null(char *text, int state) +{ + return NULL; +} + +#endif /* HAVE_LIBREADLINE */ + /**************************************************************************** main program ****************************************************************************/ @@ -477,6 +582,20 @@ enum client_action fstrcpy(cli_info.dom.level3_dom, ""); fstrcpy(cli_info.dom.level5_dom, ""); +#ifdef HAVE_LIBREADLINE + + /* Initialise GNU Readline */ + + rl_readline_name = "rpcclient"; + rl_attempted_completion_function = completion_fn; + rl_completion_entry_function = (Function *)complete_cmd_null; + + /* Initialise history list */ + + using_history(); + +#endif /* HAVE_LIBREADLINE */ + TimeInit(); charset_initialise(); |