From 72a5cbadc1498b58bc7873a450de4b50e322a676 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 3 May 2006 09:07:38 +0000 Subject: r15406: Move 'smbreadline' out of libreplace as it doesn't replace functionality not available on some platforms but is a Samba-specific library. (This used to be commit e9d3660fa6678424e5159708a1aa572824926c8e) --- source4/lib/smbreadline/smbreadline.c | 164 ++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 source4/lib/smbreadline/smbreadline.c (limited to 'source4/lib/smbreadline/smbreadline.c') diff --git a/source4/lib/smbreadline/smbreadline.c b/source4/lib/smbreadline/smbreadline.c new file mode 100644 index 0000000000..78febf5000 --- /dev/null +++ b/source4/lib/smbreadline/smbreadline.c @@ -0,0 +1,164 @@ +/* + Unix SMB/CIFS implementation. + 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" +#include "pstring.h" + +#include +#include "system/readline.h" + +/******************************************************************* + Similar to sys_select() but catch EINTR and continue. + This is what sys_select() used to do in Samba. +********************************************************************/ + +int sys_select_intr(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval) +{ + int ret; + fd_set *readfds2, readfds_buf, *writefds2, writefds_buf, *errorfds2, errorfds_buf; + struct timeval tval2, *ptval; + + readfds2 = (readfds ? &readfds_buf : NULL); + writefds2 = (writefds ? &writefds_buf : NULL); + errorfds2 = (errorfds ? &errorfds_buf : NULL); + ptval = (tval ? &tval2 : NULL); + + do { + if (readfds) + readfds_buf = *readfds; + if (writefds) + writefds_buf = *writefds; + if (errorfds) + errorfds_buf = *errorfds; + if (tval) + tval2 = *tval; + + /* We must use select and not sys_select here. If we use + sys_select we'd lose the fact a signal occurred when sys_select + read a byte from the pipe. Fix from Mark Weaver + + */ + + ret = select(maxfd, readfds2, writefds2, errorfds2, ptval); + } while (ret == -1 && errno == EINTR); + + if (readfds) + *readfds = readfds_buf; + if (writefds) + *writefds = writefds_buf; + if (errorfds) + *errorfds = errorfds_buf; + + return ret; +} + +/**************************************************************************** + Display the prompt and wait for input. Call callback() regularly +****************************************************************************/ + +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; + struct timeval timeout; + int fd = STDIN_FILENO; + char *ret; + + do_debug("%s", prompt); + + 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); + return ret; + } + if (callback) + callback(); + } +} + +/**************************************************************************** + Display the prompt and wait for input. Call callback() regularly. +****************************************************************************/ + +char *smb_readline(const char *prompt, void (*callback)(void), + char **(completion_fn)(const char *text, int start, int end)) +{ +#if HAVE_LIBREADLINE + if (isatty(STDIN_FILENO)) { + 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 +#endif + 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 +} + + + -- cgit From bf5b0606a53251d47ae220d3771b953d8e4a7b22 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 6 Sep 2006 05:42:23 +0000 Subject: r18134: the lib/replace/system/filesys.h in this patch should be system/filesys.h, but it doesn't work. Metze is looking into it :-) (This used to be commit 0dc0b7ff613d39f93c1680116c04348b720afaff) --- source4/lib/smbreadline/smbreadline.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/smbreadline/smbreadline.c') diff --git a/source4/lib/smbreadline/smbreadline.c b/source4/lib/smbreadline/smbreadline.c index 78febf5000..3d046f6099 100644 --- a/source4/lib/smbreadline/smbreadline.c +++ b/source4/lib/smbreadline/smbreadline.c @@ -21,9 +21,9 @@ #include "includes.h" #include "pstring.h" - -#include -#include "system/readline.h" +#include "lib/replace/system/filesys.h" +#include "lib/replace/system/select.h" +#include "lib/replace/system/readline.h" /******************************************************************* Similar to sys_select() but catch EINTR and continue. -- cgit From ead21647a248b250876ce7d2133bd4a1fe2b2d57 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 7 Sep 2006 07:56:41 +0000 Subject: r18207: not all readline libs have rl_event_hook this should help with coreserverbuild (Mac OS X) (This used to be commit b0efbdfa98cfda87a78874c2a71a52cc091e4021) --- source4/lib/smbreadline/smbreadline.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/lib/smbreadline/smbreadline.c') diff --git a/source4/lib/smbreadline/smbreadline.c b/source4/lib/smbreadline/smbreadline.c index 3d046f6099..6b8e54e1e3 100644 --- a/source4/lib/smbreadline/smbreadline.c +++ b/source4/lib/smbreadline/smbreadline.c @@ -127,8 +127,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); -- cgit From e7f2d247e40218ce3320e288780ad745bc38f6a2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 9 Sep 2006 02:32:12 +0000 Subject: r18281: a workaround for an infinite dependency loop in the dependency generation for smbreadline.d. The problem was caused by extra_flags.txt having ./lib/smbreadline/smbreadline.o but the build using lib/smbreadline/smbreadline.o, which means cflags.pl didn't match the target. Hopefully the workaround can be removed when metze or jelmer wake up and give me a hint on how to make SMB_SUBSYSTEM() not add the ./ prefix :-) (This used to be commit 826cd304a7cf54ab60ea41b6ecf00ca7b89f2b39) --- source4/lib/smbreadline/smbreadline.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/smbreadline/smbreadline.c') diff --git a/source4/lib/smbreadline/smbreadline.c b/source4/lib/smbreadline/smbreadline.c index 6b8e54e1e3..a1fa5d7df3 100644 --- a/source4/lib/smbreadline/smbreadline.c +++ b/source4/lib/smbreadline/smbreadline.c @@ -21,9 +21,9 @@ #include "includes.h" #include "pstring.h" -#include "lib/replace/system/filesys.h" -#include "lib/replace/system/select.h" -#include "lib/replace/system/readline.h" +#include "system/filesys.h" +#include "system/select.h" +#include "system/readline.h" /******************************************************************* Similar to sys_select() but catch EINTR and continue. -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/lib/smbreadline/smbreadline.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/smbreadline/smbreadline.c') diff --git a/source4/lib/smbreadline/smbreadline.c b/source4/lib/smbreadline/smbreadline.c index a1fa5d7df3..ae9fc4a3b7 100644 --- a/source4/lib/smbreadline/smbreadline.c +++ b/source4/lib/smbreadline/smbreadline.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, @@ -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 dccf3f99e45137b6cd18c1de1c79808ad67130d1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Sep 2007 13:27:14 +0000 Subject: r25027: Fix more warnings. (This used to be commit 5085c53fcfade614e83d21fc2c1a5bc43bb2a729) --- source4/lib/smbreadline/smbreadline.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/smbreadline/smbreadline.c') diff --git a/source4/lib/smbreadline/smbreadline.c b/source4/lib/smbreadline/smbreadline.c index ae9fc4a3b7..2a72750efb 100644 --- a/source4/lib/smbreadline/smbreadline.c +++ b/source4/lib/smbreadline/smbreadline.c @@ -23,6 +23,7 @@ #include "system/filesys.h" #include "system/select.h" #include "system/readline.h" +#include "lib/smbreadline/smbreadline.h" /******************************************************************* Similar to sys_select() but catch EINTR and continue. -- cgit From d8feba9faf8f135109e347b5bf5fa054df97a11a Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Fri, 14 Dec 2007 10:46:35 +0100 Subject: r26452: Janitorial: Remove a pstring. (This used to be commit d1d95024788bc549f838c0393411fa98ddec04ec) --- source4/lib/smbreadline/smbreadline.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/smbreadline/smbreadline.c') diff --git a/source4/lib/smbreadline/smbreadline.c b/source4/lib/smbreadline/smbreadline.c index 2a72750efb..e5cc3522e9 100644 --- a/source4/lib/smbreadline/smbreadline.c +++ b/source4/lib/smbreadline/smbreadline.c @@ -19,7 +19,6 @@ */ #include "includes.h" -#include "pstring.h" #include "system/filesys.h" #include "system/select.h" #include "system/readline.h" @@ -78,7 +77,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[1024]; struct timeval timeout; int fd = STDIN_FILENO; char *ret; @@ -91,7 +90,7 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void) 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); return ret; -- cgit From 43ac3d9b44b98d44db9b1550c47e8f96a410d1e9 Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Fri, 14 Dec 2007 14:04:56 +0100 Subject: r26453: Janitorial: Don't use a static char[] in smb_readline_replacement. Fix up callers to free the memory returned, as that is needed if we use the original readline function as well. (This used to be commit c81ead1c38f417d442157b21d0d389f6a540c6f9) --- source4/lib/smbreadline/smbreadline.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source4/lib/smbreadline/smbreadline.c') diff --git a/source4/lib/smbreadline/smbreadline.c b/source4/lib/smbreadline/smbreadline.c index e5cc3522e9..a85f335b8a 100644 --- a/source4/lib/smbreadline/smbreadline.c +++ b/source4/lib/smbreadline/smbreadline.c @@ -77,13 +77,18 @@ 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[1024]; + char *line; struct timeval timeout; int fd = STDIN_FILENO; char *ret; do_debug("%s", prompt); + line = (char *)malloc(BUFSIZ); + if (!line) { + return NULL; + } + while (1) { timeout.tv_sec = 5; timeout.tv_usec = 0; @@ -92,7 +97,7 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void) 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