From 9c4927d3624c594ea6647d946540ce286a948805 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 18 Mar 2001 13:24:57 +0000 Subject: much better readline support from Simo Sorce, with some mods from me to make it a bit simpler (This used to be commit e1487eb2c4626dbe0cc3b17606eda702cedef28b) --- source3/lib/readline.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 source3/lib/readline.c (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c new file mode 100644 index 0000000000..d031fa2fb4 --- /dev/null +++ b/source3/lib/readline.c @@ -0,0 +1,126 @@ +/* + Unix SMB/Netbios implementation. + Version 3.0 + Samba readline wrapper implementation + Copyright (C) Simo Sorce 2001, + Copyright (C) Andrew Tridgell 2001 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +/* user input through readline callback */ +static char *command_line; +static int *readline_event; + +/**************************************************************************** +samba readline callback function +****************************************************************************/ +static int smb_rl_callback_handler(char *line_read) +{ + if (!command_line) return RL_ERROR; + + if (line_read) + { + pstrcpy(command_line, line_read); +#if defined(HAVE_LIBREADLINE) +#if defined(HAVE_READLINE_HISTORY_H) || defined(HAVE_HISTORY_H) + if (strlen(line_read)) add_history(line_read); + free(line_read); +#endif +#endif + *readline_event = RL_GOT_LINE; + } else { + *readline_event = RL_GOT_EOF; + } + return 0; +} + +void smb_rl_read_char (void) +{ +#ifdef HAVE_LIBREADLINE + *readline_event = RL_NO_EVENTS; + rl_callback_read_char (); +#else + pstring line; + fgets(line, sizeof(line), stdin); + smb_rl_callback_handler(line); +#endif +} + +/**************************************************************************** +init samba readline +****************************************************************************/ +void init_smb_readline(char *prg_name, char *cline_ptr, int *event_ptr) +{ + command_line = cline_ptr; + readline_event = event_ptr; + +#ifdef HAVE_LIBREADLINE + rl_readline_name = prg_name; + rl_already_prompted = 1; + rl_callback_handler_install(NULL, (VFunction *)&smb_rl_callback_handler); +#endif +} + +/**************************************************************************** +display the prompt +****************************************************************************/ +void smb_readline_prompt(char *prompt) +{ + extern FILE *dbf; + + fprintf(dbf, "%s", prompt); + fflush(dbf); + +#ifdef HAVE_LIBREADLINE + rl_callback_handler_remove(); + rl_callback_handler_install(prompt, (VFunction *)&smb_rl_callback_handler); +#endif +} + +/**************************************************************************** +removes readline callback handler +****************************************************************************/ +void smb_readline_remove_handler(void) +{ +#ifdef HAVE_LIBREADLINE + rl_callback_handler_remove (); +#endif + + readline_event = NULL; + command_line = NULL; +} + +/**************************************************************************** +history +****************************************************************************/ +void cmd_history(void) +{ +#if defined(HAVE_LIBREADLINE) && (defined(HAVE_READLINE_HISTORY_H) || defined(HAVE_HISTORY_H)) + HIST_ENTRY **hlist; + int i; + + hlist = history_list (); + + for (i = 0; hlist && hlist[i]; i++) { + DEBUG(0, ("%d: %s\n", i, hlist[i]->line)); + } +#else + DEBUG(0,("no history without readline support\n")); +#endif +} + -- cgit From bc25293f96fb559b875d03e6ddbd9079b4af9dff Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 18 Mar 2001 23:41:53 +0000 Subject: much simpler readline code should work with readline 2.x (This used to be commit 7940b6b0cf614ac72266d9e600220c9a9dbd2a43) --- source3/lib/readline.c | 117 +++++++++++++++++++------------------------------ 1 file changed, 44 insertions(+), 73 deletions(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index d031fa2fb4..f0d8b1267f 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -2,7 +2,7 @@ Unix SMB/Netbios implementation. Version 3.0 Samba readline wrapper implementation - Copyright (C) Simo Sorce 2001, + Copyright (C) Simo Sorce 2001 Copyright (C) Andrew Tridgell 2001 This program is free software; you can redistribute it and/or modify @@ -22,87 +22,59 @@ #include "includes.h" -/* user input through readline callback */ -static char *command_line; -static int *readline_event; - -/**************************************************************************** -samba readline callback function -****************************************************************************/ -static int smb_rl_callback_handler(char *line_read) -{ - if (!command_line) return RL_ERROR; - - if (line_read) - { - pstrcpy(command_line, line_read); -#if defined(HAVE_LIBREADLINE) -#if defined(HAVE_READLINE_HISTORY_H) || defined(HAVE_HISTORY_H) - if (strlen(line_read)) add_history(line_read); - free(line_read); -#endif -#endif - *readline_event = RL_GOT_LINE; - } else { - *readline_event = RL_GOT_EOF; - } - return 0; -} - -void smb_rl_read_char (void) -{ #ifdef HAVE_LIBREADLINE - *readline_event = RL_NO_EVENTS; - rl_callback_read_char (); -#else - pstring line; - fgets(line, sizeof(line), stdin); - smb_rl_callback_handler(line); +# ifdef HAVE_READLINE_READLINE_H +# include +# ifdef HAVE_READLINE_HISTORY_H +# include +# endif +# else +# ifdef HAVE_READLINE_H +# include +# ifdef HAVE_HISTORY_H +# include +# endif +# else +# undef HAVE_LIBREADLINE +# endif +# endif #endif -} /**************************************************************************** -init samba readline +display the prompt and wait for input. Call callback() regularly ****************************************************************************/ -void init_smb_readline(char *prg_name, char *cline_ptr, int *event_ptr) -{ - command_line = cline_ptr; - readline_event = event_ptr; - -#ifdef HAVE_LIBREADLINE - rl_readline_name = prg_name; - rl_already_prompted = 1; - rl_callback_handler_install(NULL, (VFunction *)&smb_rl_callback_handler); -#endif -} - -/**************************************************************************** -display the prompt -****************************************************************************/ -void smb_readline_prompt(char *prompt) +char *smb_readline(char *prompt, void (*callback)(void)) { + char *ret; +#if HAVE_LIBREADLINE + 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); + fprintf(dbf, "%s", prompt); fflush(dbf); -#ifdef HAVE_LIBREADLINE - rl_callback_handler_remove(); - rl_callback_handler_install(prompt, (VFunction *)&smb_rl_callback_handler); -#endif -} + while (1) { + timeout.tv_sec = 5; + timeout.tv_usec = 0; -/**************************************************************************** -removes readline callback handler -****************************************************************************/ -void smb_readline_remove_handler(void) -{ -#ifdef HAVE_LIBREADLINE - rl_callback_handler_remove (); + FD_ZERO(&fds); + FD_SET(fd,&fds); + + if (sys_select_intr(fd+1,&fds,&timeout) == 1) { + ret = fgets(line, sizeof(line), stdin); + return ret; + } + if (callback) callback(); + } #endif - - readline_event = NULL; - command_line = NULL; } /**************************************************************************** @@ -110,11 +82,11 @@ history ****************************************************************************/ void cmd_history(void) { -#if defined(HAVE_LIBREADLINE) && (defined(HAVE_READLINE_HISTORY_H) || defined(HAVE_HISTORY_H)) +#if defined(HAVE_LIBREADLINE) HIST_ENTRY **hlist; int i; - hlist = history_list (); + hlist = history_list(); for (i = 0; hlist && hlist[i]; i++) { DEBUG(0, ("%d: %s\n", i, hlist[i]->line)); @@ -123,4 +95,3 @@ void cmd_history(void) DEBUG(0,("no history without readline support\n")); #endif } - -- cgit From e17e7b64175dcfc9963405a9fa3724f8d7097d89 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 19 Mar 2001 00:22:52 +0000 Subject: added basic command completion support (This used to be commit 386fdff2dfeaeef60b210ebc0b4d33a6c7b5d5ec) --- source3/lib/readline.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index f0d8b1267f..4a3c5434c7 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -43,10 +43,15 @@ /**************************************************************************** display the prompt and wait for input. Call callback() regularly ****************************************************************************/ -char *smb_readline(char *prompt, void (*callback)(void)) +char *smb_readline(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; + } + rl_event_hook = (Function *)callback; ret = readline(prompt); if (ret && *ret) add_history(ret); -- cgit From 62711a9ceb375fef2c0af0f649d8c77eb94483f9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 19 Mar 2001 00:32:16 +0000 Subject: fixed rpcclient readline code (This used to be commit 4ec971e905cefada5f3980a25781730acdbf4469) --- source3/lib/readline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index 4a3c5434c7..75a38c6852 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -52,7 +52,7 @@ char *smb_readline(char *prompt, void (*callback)(void), rl_attempted_completion_function = completion_fn; } - rl_event_hook = (Function *)callback; + if (callback) rl_event_hook = (Function *)callback; ret = readline(prompt); if (ret && *ret) add_history(ret); return ret; -- cgit From 3bb92410a46d37d4487f1ea8a95af17828c727be Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 7 May 2001 01:08:41 +0000 Subject: Fixed compiler warning. (This used to be commit 063c2dea920dbf415e22d0359baa7b36bf513f09) --- source3/lib/readline.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index 75a38c6852..a524e1a7f0 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -49,7 +49,8 @@ char *smb_readline(char *prompt, void (*callback)(void), char *ret; #if HAVE_LIBREADLINE if (completion_fn) { - rl_attempted_completion_function = completion_fn; + rl_attempted_completion_function = + (rl_completion_func_t *)completion_fn; } if (callback) rl_event_hook = (Function *)callback; -- cgit From 3762d48404c60fdeda25ff4083b9ef878917a011 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 7 May 2001 02:03:32 +0000 Subject: Some versions of readline don't have rl_completion_func_t. )-: Spotted by http://build.samba.org/ (This used to be commit da5a0f5c5b0917148fb6b668d4316aa4924708a1) --- source3/lib/readline.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index a524e1a7f0..75a38c6852 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -49,8 +49,7 @@ char *smb_readline(char *prompt, void (*callback)(void), char *ret; #if HAVE_LIBREADLINE if (completion_fn) { - rl_attempted_completion_function = - (rl_completion_func_t *)completion_fn; + rl_attempted_completion_function = completion_fn; } if (callback) rl_event_hook = (Function *)callback; -- cgit From f905c74d9ab24a51d036853a8c609d8da3e5c91f Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 20 Jul 2001 07:46:39 +0000 Subject: ^$&%&*$&)% readline uses \n characters instead of letting the terminal wrap the screen. This mucks up expect something severe. )-: Don't use readline if the CLI_NO_READLINE environment variable is set. (This used to be commit f0b7593ef54f8f093018ee2a8325e6f4422a4bbd) --- source3/lib/readline.c | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'source3/lib/readline.c') 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 } -- cgit From b30e75692d68233448b3ad3d7ddd4b4ac423d3ab Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Sep 2001 11:08:57 +0000 Subject: replaced stdio in many parts of samba with a XFILE. XFILE is a cut-down replacemnt of stdio that doesn't suffer from the 8-bit filedescriptor limit that we hit with nasty consequences on some systems I would eventually prefer us to have a configure test to see if we need to replace stdio, but for now this code needs to be tested widely so I'm enabling it by default. (This used to be commit 1af8bf34f1caa3e7ec312d8109c07d32a945a448) --- source3/lib/readline.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index 11d65a2b16..b03d37695e 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -49,14 +49,14 @@ static char *smb_readline_replacement(char *prompt, void (*callback)(void), int end)) { fd_set fds; - extern FILE *dbf; + extern XFILE *dbf; static pstring line; struct timeval timeout; int fd = fileno(stdin); char *ret; - fprintf(dbf, "%s", prompt); - fflush(dbf); + x_fprintf(dbf, "%s", prompt); + x_fflush(dbf); while (1) { timeout.tv_sec = 5; -- cgit From b12a4dd9b655485420d5c67dd143d8f49ac28a40 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Sep 2001 12:14:18 +0000 Subject: declare dbf in one spot (This used to be commit f41c3bb80f1e498a9d27f6e236b0ff3a742764c9) --- source3/lib/readline.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index b03d37695e..76bc34f775 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -49,7 +49,6 @@ static char *smb_readline_replacement(char *prompt, void (*callback)(void), int end)) { fd_set fds; - extern XFILE *dbf; static pstring line; struct timeval timeout; int fd = fileno(stdin); -- cgit From 59681e1655f9289bbc5e9170b6a5bc924b56fc57 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sun, 30 Sep 2001 01:33:02 +0000 Subject: merge from 2.2 (This used to be commit c308459bda3f3036c305ee7b9307f740aec66811) --- source3/lib/readline.c | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index 76bc34f775..f7ef40b001 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -22,23 +22,6 @@ #include "includes.h" -#ifdef HAVE_LIBREADLINE -# ifdef HAVE_READLINE_READLINE_H -# include -# ifdef HAVE_READLINE_HISTORY_H -# include -# endif -# else -# ifdef HAVE_READLINE_H -# include -# ifdef HAVE_HISTORY_H -# include -# endif -# else -# undef HAVE_LIBREADLINE -# endif -# endif -#endif /**************************************************************************** display the prompt and wait for input. Call callback() regularly -- cgit From 52341e94a86420368b479acd2c760468444fef72 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 9 Oct 2001 19:12:18 +0000 Subject: initial support to error report in smbclient, useful when using smbclient -c in scripts. Thanks to Claudio Cicali aka FleXer for the initial patch (This used to be commit 53b95b3c0fd087b1cade95fd8de849547ac3bfcb) --- source3/lib/readline.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index f7ef40b001..2475017adf 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -88,7 +88,7 @@ char *smb_readline(char *prompt, void (*callback)(void), /**************************************************************************** history ****************************************************************************/ -void cmd_history(void) +int cmd_history(void) { #if defined(HAVE_LIBREADLINE) HIST_ENTRY **hlist; @@ -102,4 +102,6 @@ void cmd_history(void) #else DEBUG(0,("no history without readline support\n")); #endif + + return 0; } -- cgit From eb2bf006acc4842d9b6d2749805dc24404a3d423 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 19 Nov 2001 03:11:28 +0000 Subject: Quieten compiler warnings about a callback function prototype that has changed in recent versions of Readline. (This used to be commit d0a0d27caa04029a814d942e35fb5382bb9a492c) --- source3/lib/readline.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index 2475017adf..543e4c3349 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -73,7 +73,13 @@ char *smb_readline(char *prompt, void (*callback)(void), completion_fn); if (completion_fn) { - rl_attempted_completion_function = completion_fn; + /* The cast is here because the callback prototype has + changed slightly between different versions of + Readline. The same function works in all of them + to date, but we get compiler warnings without the + cast. */ + rl_attempted_completion_function = + (rl_completion_func_t *) completion_fn; } if (callback) rl_event_hook = (Function *)callback; -- cgit From 4ea31fb67595ae8705701bd9fb8d8a993c4013fb Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 19 Nov 2001 03:34:45 +0000 Subject: Oops, Tim says rl_completion_func_t doesn't exist in all versions of readline. (This used to be commit c4b44cfc3f15f9e85a36981867e534792ccb724e) --- source3/lib/readline.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index 543e4c3349..927c903255 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -73,13 +73,11 @@ char *smb_readline(char *prompt, void (*callback)(void), completion_fn); if (completion_fn) { - /* The cast is here because the callback prototype has - changed slightly between different versions of - Readline. The same function works in all of them - to date, but we get compiler warnings without the - cast. */ - rl_attempted_completion_function = - (rl_completion_func_t *) completion_fn; + /* The callback prototype has changed slightly between + different versions of Readline, so the same + function works in all of them to date, but we get + compiler warnings in some. */ + rl_attempted_completion_function = completion_fn; } if (callback) rl_event_hook = (Function *)callback; -- cgit From d173bf704904329797fa32d29607e8ebd639f5cd Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 19 Nov 2001 03:44:19 +0000 Subject: Added comment about why not to cast the assignment of rl_attempted_completion_function to rl_completion_function_t. (This used to be commit dfaafcd6221412613f9e4eccdaaa2e84253def81) --- source3/lib/readline.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index 927c903255..fa2be0e16b 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -74,9 +74,12 @@ char *smb_readline(char *prompt, void (*callback)(void), if (completion_fn) { /* The callback prototype has changed slightly between - different versions of Readline, so the same - function works in all of them to date, but we get - compiler warnings in some. */ + different versions of Readline, so the same function + works in all of them to date, but we get compiler + warnings in some. NOTE: that not all versions of + readline have rl_completion_func_t so attempting to cast + the statement below to get rid of the warning will not + compile for everyone. */ rl_attempted_completion_function = completion_fn; } -- cgit From b99209cce4a91de279bb62dbc4246845bf0e755d Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 19 Nov 2001 04:18:45 +0000 Subject: Detect libreadline>=4.0, and set HAVE_NEW_LIBREADLINE. At the moment this is only to get the cast right, but it might help with other parts of the API that changed later. (This used to be commit b792c9317ab62fe407de34ed811cc883a7652cc4) --- source3/lib/readline.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index fa2be0e16b..1b81c68d03 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -22,6 +22,13 @@ #include "includes.h" +#ifdef HAVE_NEW_LIBREADLINE +# define RL_COMPLETION_CAST (rl_completion_func_t *) +#else +/* This type is missing from libreadline<4.0 (approximately) */ +# define RL_COMPLETION_FUNC_T +#endif /* HAVE_NEW_LIBREADLINE */ + /**************************************************************************** display the prompt and wait for input. Call callback() regularly @@ -76,11 +83,9 @@ char *smb_readline(char *prompt, void (*callback)(void), /* The callback prototype has changed slightly between different versions of Readline, so the same function works in all of them to date, but we get compiler - warnings in some. NOTE: that not all versions of - readline have rl_completion_func_t so attempting to cast - the statement below to get rid of the warning will not - compile for everyone. */ - rl_attempted_completion_function = completion_fn; + warnings in some. */ + rl_attempted_completion_function = RL_COMPLETION_CAST + completion_fn; } if (callback) rl_event_hook = (Function *)callback; -- cgit From 94ad8127f58d9feba51f8071b96b920f25b4160d Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 19 Nov 2001 07:39:35 +0000 Subject: Fix typo. (This used to be commit 2c1e68d4ce45c7862fbc79a83eb36ee5b077251e) --- source3/lib/readline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index 1b81c68d03..325b70d2cf 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -26,7 +26,7 @@ # define RL_COMPLETION_CAST (rl_completion_func_t *) #else /* This type is missing from libreadline<4.0 (approximately) */ -# define RL_COMPLETION_FUNC_T +# define RL_COMPLETION_CAST #endif /* HAVE_NEW_LIBREADLINE */ -- cgit From 74462c0c17caecf19bc01d5159776ae6a0f39a11 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 19 Jan 2002 22:54:13 +0000 Subject: Readline has problems on non tty fd's. Use readline replacement to in cases where stdin is !isatty to allow stripts to work. Jeremy. (This used to be commit 997d6687fc67e98fe561775b522edfaa00f5ee5f) --- source3/lib/readline.c | 63 +++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 31 deletions(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index 325b70d2cf..efd198db8d 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -29,20 +29,18 @@ # define RL_COMPLETION_CAST #endif /* HAVE_NEW_LIBREADLINE */ - /**************************************************************************** -display the prompt and wait for input. Call callback() regularly + Display the prompt and wait for input. Call callback() regularly ****************************************************************************/ + static char *smb_readline_replacement(char *prompt, void (*callback)(void), - char **(completion_fn)(char *text, - int start, - int end)) + char **(completion_fn)(char *text, int start, int end)) { fd_set fds; static pstring line; struct timeval timeout; int fd = fileno(stdin); - char *ret; + char *ret; x_fprintf(dbf, "%s", prompt); x_fflush(dbf); @@ -58,43 +56,46 @@ static char *smb_readline_replacement(char *prompt, void (*callback)(void), ret = fgets(line, sizeof(line), stdin); return ret; } - if (callback) callback(); + if (callback) + callback(); } } /**************************************************************************** -display the prompt and wait for input. Call callback() regularly + 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; + if (isatty(fileno(stdin))) { + 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) { - /* The callback prototype has changed slightly between - different versions of Readline, so the same function - works in all of them to date, but we get compiler - warnings in some. */ - rl_attempted_completion_function = RL_COMPLETION_CAST - completion_fn; - } + /* 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 (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); + if (getenv("CLI_NO_READLINE")) + return smb_readline_replacement(prompt, callback, completion_fn); + + if (completion_fn) { + /* The callback prototype has changed slightly between + different versions of Readline, so the same function + works in all of them to date, but we get compiler + warnings in some. */ + rl_attempted_completion_function = RL_COMPLETION_CAST completion_fn; + } + + if (callback) + rl_event_hook = (Function *)callback; + ret = readline(prompt); + if (ret && *ret) + add_history(ret); + return ret; + } else #endif + return smb_readline_replacement(prompt, callback, completion_fn); } /**************************************************************************** -- cgit From cd68afe31256ad60748b34f7318a180cfc2127cc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 30 Jan 2002 06:08:46 +0000 Subject: Removed version number from file header. Changed "SMB/Netbios" to "SMB/CIFS" in file header. (This used to be commit 6a58c9bd06d0d7502a24bf5ce5a2faf0a146edfa) --- source3/lib/readline.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index efd198db8d..013b8516f8 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 3.0 + Unix SMB/CIFS implementation. Samba readline wrapper implementation Copyright (C) Simo Sorce 2001 Copyright (C) Andrew Tridgell 2001 -- cgit From 69adbb0ce3bb9d5bd569c13aaa3ac8f390c1586a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 31 Jan 2002 23:26:12 +0000 Subject: Fix from Michael Steffens to make signal processing work correctly in winbindd. This is a really good patch that gives full select semantics to the Samba modified select. Jeremy. (This used to be commit 3af16ade173cac24c1ac5eff4a36b439f16ac036) --- source3/lib/readline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index 013b8516f8..d80c571dd3 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -51,7 +51,7 @@ static char *smb_readline_replacement(char *prompt, void (*callback)(void), FD_ZERO(&fds); FD_SET(fd,&fds); - if (sys_select_intr(fd+1,&fds,&timeout) == 1) { + if (sys_select_intr(fd+1,&fds,NULL,NULL,&timeout) == 1) { ret = fgets(line, sizeof(line), stdin); return ret; } -- cgit From a834a73e341059be154426390304a42e4a011f72 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 25 Sep 2002 15:19:00 +0000 Subject: sync'ing up for 3.0alpha20 release (This used to be commit 65e7b5273bb58802bf0c389b77f7fcae0a1f6139) --- source3/lib/readline.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index d80c571dd3..58c4ecf482 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -21,6 +21,24 @@ #include "includes.h" +#ifdef HAVE_LIBREADLINE +# ifdef HAVE_READLINE_READLINE_H +# include +# ifdef HAVE_READLINE_HISTORY_H +# include +# endif +# else +# ifdef HAVE_READLINE_H +# include +# ifdef HAVE_HISTORY_H +# include +# endif +# else +# undef HAVE_LIBREADLINE +# endif +# endif +#endif + #ifdef HAVE_NEW_LIBREADLINE # define RL_COMPLETION_CAST (rl_completion_func_t *) #else -- cgit From b36a53b0cb794ad7b620cfa8e794e4149965c15e Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 8 Feb 2003 00:08:23 +0000 Subject: Merge from HEAD - don't mix FILE and X_FILE - fixes debian bug http://bugs.debian.org/178219 where the first 4096 bytes where being chewed into the FILE buffer, and never available to X_FILE's read. Andrew Bartlett (This used to be commit 8af72c13841ee51bca4f061a91c05e8fd366f586) --- source3/lib/readline.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index 58c4ecf482..c0ccf44715 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -56,7 +56,7 @@ static char *smb_readline_replacement(char *prompt, void (*callback)(void), fd_set fds; static pstring line; struct timeval timeout; - int fd = fileno(stdin); + int fd = x_fileno(x_stdin); char *ret; x_fprintf(dbf, "%s", prompt); @@ -70,7 +70,7 @@ static char *smb_readline_replacement(char *prompt, void (*callback)(void), FD_SET(fd,&fds); if (sys_select_intr(fd+1,&fds,NULL,NULL,&timeout) == 1) { - ret = fgets(line, sizeof(line), stdin); + ret = x_fgets(line, sizeof(line), x_stdin); return ret; } if (callback) @@ -86,7 +86,7 @@ char *smb_readline(char *prompt, void (*callback)(void), char **(completion_fn)(char *text, int start, int end)) { #if HAVE_LIBREADLINE - if (isatty(fileno(stdin))) { + if (isatty(fileno(x_stdin))) { char *ret; /* Aargh! Readline does bizzare things with the terminal width -- cgit From 8f166a97259444a284f9839689db563ff58cf73b Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 8 Feb 2003 01:01:49 +0000 Subject: merge from HEAD - x_fileno, not fileno on an XFILE (This used to be commit e3468d8edc77c4d3dffc81770f4bc991e5a5fe52) --- source3/lib/readline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index c0ccf44715..8b90c32c7f 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -86,7 +86,7 @@ char *smb_readline(char *prompt, void (*callback)(void), char **(completion_fn)(char *text, int start, int end)) { #if HAVE_LIBREADLINE - if (isatty(fileno(x_stdin))) { + if (isatty(x_fileno(x_stdin))) { char *ret; /* Aargh! Readline does bizzare things with the terminal width -- cgit From c823b191ab476fc2583d6d6aaa1e2edb09cbb88e Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 12 May 2003 18:12:31 +0000 Subject: And finally IDMAP in 3_0 We really need idmap_ldap to have a good solution with ldapsam, porting it from the prvious code is beeing made, the code is really simple to do so I am confident it is not a problem to commit this code in. Not committing it would have been worst. I really would have been able to finish also the group code, maybe we can put it into a followin release after 3.0.0 even if it may be an upgrade problem. The code has been tested and seem to work right, more testing is needed for corner cases. Currently winbind pdc (working only for users and not for groups) is disabled as I was not able to make a complete group code replacement that works somewhat in a week (I have a complete patch, but there are bugs) Simo. (This used to be commit 0e58085978f984436815114a2ec347cf7899a89d) --- source3/lib/readline.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index 8b90c32c7f..ceb02ef749 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -115,6 +115,29 @@ char *smb_readline(char *prompt, void (*callback)(void), return smb_readline_replacement(prompt, callback, completion_fn); } +/**************************************************************************** + * return line buffer text + ****************************************************************************/ +const char *smb_readline_get_line_buffer(void) +{ +#if defined(HAVE_LIBREADLINE) + return rl_line_buffer; +#else + return NULL; +#endif +} + + +/**************************************************************************** + * set completion append character + ***************************************************************************/ +void smb_readline_ca_char(char c) +{ +#if defined(HAVE_LIBREADLINE) + rl_completion_append_character = c; +#endif +} + /**************************************************************************** history ****************************************************************************/ @@ -135,3 +158,4 @@ int cmd_history(void) return 0; } + -- cgit From 268a3593adf36cd9be3135ac84a12abda226b62f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 11 Aug 2003 19:11:43 +0000 Subject: Apply some const (This used to be commit 502b45b55d7ab1c32c9dbc3301f025b2eec620a4) --- source3/lib/readline.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index ceb02ef749..78b99fd7fb 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -51,7 +51,7 @@ ****************************************************************************/ static char *smb_readline_replacement(char *prompt, void (*callback)(void), - char **(completion_fn)(char *text, int start, int end)) + char **(completion_fn)(const char *text, int start, int end)) { fd_set fds; static pstring line; @@ -83,7 +83,7 @@ static char *smb_readline_replacement(char *prompt, void (*callback)(void), ****************************************************************************/ char *smb_readline(char *prompt, void (*callback)(void), - char **(completion_fn)(char *text, int start, int end)) + char **(completion_fn)(const char *text, int start, int end)) { #if HAVE_LIBREADLINE if (isatty(x_fileno(x_stdin))) { -- cgit From 0af1500fc0bafe61019f1b2ab1d9e1d369221240 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 3 Feb 2006 22:19:41 +0000 Subject: r13316: Let the carnage begin.... Sync with trunk as off r13315 (This used to be commit 17e63ac4ed8325c0d44fe62b2442449f3298559f) --- source3/lib/readline.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index 78b99fd7fb..c1f1dc7f40 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -50,7 +50,7 @@ Display the prompt and wait for input. Call callback() regularly ****************************************************************************/ -static char *smb_readline_replacement(char *prompt, void (*callback)(void), +static char *smb_readline_replacement(const char *prompt, void (*callback)(void), char **(completion_fn)(const char *text, int start, int end)) { fd_set fds; @@ -82,7 +82,7 @@ static char *smb_readline_replacement(char *prompt, void (*callback)(void), Display the prompt and wait for input. Call callback() regularly. ****************************************************************************/ -char *smb_readline(char *prompt, void (*callback)(void), +char *smb_readline(const char *prompt, void (*callback)(void), char **(completion_fn)(const char *text, int start, int end)) { #if HAVE_LIBREADLINE -- cgit From 06491a4cb12d8753c63525b3ba4d754d2ab1e822 Mon Sep 17 00:00:00 2001 From: James Peach Date: Thu, 15 Jun 2006 23:51:20 +0000 Subject: r16274: Fix the smbclient prompting behaviour for both systems that have libreadline and those that don't. We always use the built-in readline replacement for non-interactive mode. Interactive prompts are always emitted to stdout and non-interactive mode never prompts at all. Introduce x_fdup to avoid spuriously closing stdout when a logfile is specified on the command line and setup_logging is called a second time. (This used to be commit 848ac756f651a4be231e5635580c0fd5f3d3fa0e) --- source3/lib/readline.c | 65 +++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 27 deletions(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index c1f1dc7f40..1f599dc0a7 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -59,8 +59,11 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void) int fd = x_fileno(x_stdin); char *ret; - x_fprintf(dbf, "%s", prompt); - x_fflush(dbf); + /* Prompt might be NULL in non-interactive mode. */ + if (prompt) { + x_fprintf(x_stdout, "%s", prompt); + x_fflush(x_stdout); + } while (1) { timeout.tv_sec = 5; @@ -85,34 +88,42 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void) char *smb_readline(const char *prompt, void (*callback)(void), char **(completion_fn)(const char *text, int start, int end)) { + char *ret; + BOOL interactive; + + interactive = isatty(x_fileno(x_stdin)) || getenv("CLI_FORCE_INTERACTIVE"); + if (!interactive) { + return smb_readline_replacement(NULL, callback, completion_fn); + } + #if HAVE_LIBREADLINE - if (isatty(x_fileno(x_stdin))) { - 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) { - /* The callback prototype has changed slightly between - different versions of Readline, so the same function - works in all of them to date, but we get compiler - warnings in some. */ - rl_attempted_completion_function = RL_COMPLETION_CAST completion_fn; - } - if (callback) - rl_event_hook = (Function *)callback; - ret = readline(prompt); - if (ret && *ret) - add_history(ret); - return ret; - } else + /* 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) { + /* The callback prototype has changed slightly between + different versions of Readline, so the same function + works in all of them to date, but we get compiler + warnings in some. */ + rl_attempted_completion_function = RL_COMPLETION_CAST completion_fn; + } + + if (callback) + rl_event_hook = (Function *)callback; + ret = readline(prompt); + if (ret && *ret) + add_history(ret); + +#else + ret = smb_readline_replacement(prompt, callback, completion_fn); #endif - return smb_readline_replacement(prompt, callback, completion_fn); + + return ret; } /**************************************************************************** -- cgit From f9f3a2d7904548ebe1ecb06aff063a93123ec589 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 11 Oct 2006 13:59:03 +0000 Subject: r19246: merge from samba4 rev 18207 and 18208: readline fixes for mac os 10 metze (This used to be commit 976b97ecbf9bde400a6f92cad9d9709d56e73058) --- source3/lib/readline.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index 1f599dc0a7..24d16ea34f 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -113,8 +113,10 @@ char *smb_readline(const char *prompt, void (*callback)(void), rl_attempted_completion_function = RL_COMPLETION_CAST completion_fn; } +#if HAVE_DECL_RL_EVENT_HOOK if (callback) rl_event_hook = (Function *)callback; +#endif ret = readline(prompt); if (ret && *ret) add_history(ret); @@ -154,7 +156,7 @@ history ****************************************************************************/ int cmd_history(void) { -#if defined(HAVE_LIBREADLINE) +#if defined(HAVE_LIBREADLINE) && defined(HAVE_HISTORY_LIST) HIST_ENTRY **hlist; int i; -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/lib/readline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index 24d16ea34f..e7bd48cef7 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -6,7 +6,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/lib/readline.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index e7bd48cef7..fe1a0362a9 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -15,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/lib/readline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index fe1a0362a9..9d1597abb1 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -88,7 +88,7 @@ char *smb_readline(const char *prompt, void (*callback)(void), char **(completion_fn)(const char *text, int start, int end)) { char *ret; - BOOL interactive; + bool interactive; interactive = isatty(x_fileno(x_stdin)) || getenv("CLI_FORCE_INTERACTIVE"); if (!interactive) { -- cgit From 68be9a820059ee96dd26c527efd7c14e679d3f2c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 15 Nov 2007 14:19:52 -0800 Subject: More pstring removal. This one was tricky. I had to add one horror (pstring_clean_name()) which will have to remain until I've removed all pstrings from the client code. Jeremy. (This used to be commit 1ea3ac80146b83c2522b69e7747c823366a2b47d) --- source3/lib/readline.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index 9d1597abb1..6fed929be0 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -53,7 +53,7 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void) char **(completion_fn)(const char *text, int start, int end)) { fd_set fds; - static pstring line; + static char *line; struct timeval timeout; int fd = x_fileno(x_stdin); char *ret; @@ -64,15 +64,22 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void) x_fflush(x_stdout); } + if (line == NULL) { + line = SMB_MALLOC(BUFSIZ); + if (!line) { + return NULL; + } + } + while (1) { timeout.tv_sec = 5; timeout.tv_usec = 0; FD_ZERO(&fds); FD_SET(fd,&fds); - + if (sys_select_intr(fd+1,&fds,NULL,NULL,&timeout) == 1) { - ret = x_fgets(line, sizeof(line), x_stdin); + ret = x_fgets(line, BUFSIZ, x_stdin); return ret; } if (callback) -- cgit From b3976c2ea25732a9f939fbc23020b7ab54c67783 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 16 Nov 2007 22:22:05 +0100 Subject: Fix an implicit cast warning. Michael (This used to be commit d2c7417393e58de12b5747b9d6c19aea3c343ea5) --- source3/lib/readline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index 6fed929be0..7c127817be 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -65,7 +65,7 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void) } if (line == NULL) { - line = SMB_MALLOC(BUFSIZ); + line = (char *)SMB_MALLOC(BUFSIZ); if (!line) { return NULL; } -- cgit From 1b92ea5559bfa00016103508feac9a06ea4b66ae Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 6 Dec 2007 17:16:33 -0800 Subject: Remove pstrings from client/client.c by doing a large rewrite. Mostly compiles.... Jeremy. (This used to be commit c87f3eba9aa52f4ab25d77e2167262bf5c43b1a6) --- source3/lib/readline.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'source3/lib/readline.c') diff --git a/source3/lib/readline.c b/source3/lib/readline.c index 7c127817be..254f55c86a 100644 --- a/source3/lib/readline.c +++ b/source3/lib/readline.c @@ -53,7 +53,7 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void) char **(completion_fn)(const char *text, int start, int end)) { fd_set fds; - static char *line; + char *line = NULL; struct timeval timeout; int fd = x_fileno(x_stdin); char *ret; @@ -64,11 +64,9 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void) x_fflush(x_stdout); } - if (line == NULL) { - line = (char *)SMB_MALLOC(BUFSIZ); - if (!line) { - return NULL; - } + line = (char *)SMB_MALLOC(BUFSIZ); + if (!line) { + return NULL; } while (1) { @@ -80,10 +78,14 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void) if (sys_select_intr(fd+1,&fds,NULL,NULL,&timeout) == 1) { ret = x_fgets(line, BUFSIZ, x_stdin); + if (ret == 0) { + SAFE_FREE(line); + } return ret; } - if (callback) + if (callback) { callback(); + } } } @@ -91,7 +93,7 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void) Display the prompt and wait for input. Call callback() regularly. ****************************************************************************/ -char *smb_readline(const char *prompt, void (*callback)(void), +char *smb_readline(const char *prompt, void (*callback)(void), char **(completion_fn)(const char *text, int start, int end)) { char *ret; @@ -99,7 +101,7 @@ char *smb_readline(const char *prompt, void (*callback)(void), interactive = isatty(x_fileno(x_stdin)) || getenv("CLI_FORCE_INTERACTIVE"); if (!interactive) { - return smb_readline_replacement(NULL, callback, completion_fn); + return smb_readline_replacement(NULL, callback, completion_fn); } #if HAVE_LIBREADLINE @@ -167,7 +169,7 @@ int cmd_history(void) int i; hlist = history_list(); - + for (i = 0; hlist && hlist[i]; i++) { DEBUG(0, ("%d: %s\n", i, hlist[i]->line)); } @@ -177,4 +179,3 @@ int cmd_history(void) return 0; } - -- cgit