diff options
Diffstat (limited to 'source3/lib/readline.c')
-rw-r--r-- | source3/lib/readline.c | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/source3/lib/readline.c b/source3/lib/readline.c index 75a38c6852..11d65a2b16 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -43,25 +43,17 @@ /**************************************************************************** display the prompt and wait for input. Call callback() regularly ****************************************************************************/ -char *smb_readline(char *prompt, void (*callback)(void), - char **(completion_fn)(char *text, int start, int end)) +static char *smb_readline_replacement(char *prompt, void (*callback)(void), + char **(completion_fn)(char *text, + int start, + int end)) { - char *ret; -#if HAVE_LIBREADLINE - if (completion_fn) { - rl_attempted_completion_function = completion_fn; - } - - if (callback) rl_event_hook = (Function *)callback; - ret = readline(prompt); - if (ret && *ret) add_history(ret); - return ret; -#else fd_set fds; extern FILE *dbf; static pstring line; struct timeval timeout; int fd = fileno(stdin); + char *ret; fprintf(dbf, "%s", prompt); fflush(dbf); @@ -79,6 +71,35 @@ char *smb_readline(char *prompt, void (*callback)(void), } if (callback) callback(); } +} + +/**************************************************************************** +display the prompt and wait for input. Call callback() regularly +****************************************************************************/ +char *smb_readline(char *prompt, void (*callback)(void), + char **(completion_fn)(char *text, int start, int end)) +{ +#if HAVE_LIBREADLINE + char *ret; + + /* Aargh! Readline does bizzare things with the terminal width + that mucks up expect(1). Set CLI_NO_READLINE in the environment + to force readline not to be used. */ + + if (getenv("CLI_NO_READLINE")) + return smb_readline_replacement(prompt, callback, + completion_fn); + + if (completion_fn) { + rl_attempted_completion_function = completion_fn; + } + + if (callback) rl_event_hook = (Function *)callback; + ret = readline(prompt); + if (ret && *ret) add_history(ret); + return ret; +#else + return smb_readline_replacement(prompt, callback, completion_fn); #endif } |