2 Unix SMB/Netbios implementation.
4 Samba readline wrapper implementation
5 Copyright (C) Simo Sorce 2001
6 Copyright (C) Andrew Tridgell 2001
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 /****************************************************************************
27 display the prompt and wait for input. Call callback() regularly
28 ****************************************************************************/
29 static char *smb_readline_replacement(char *prompt, void (*callback)(void),
30 char **(completion_fn)(char *text,
36 struct timeval timeout;
37 int fd = fileno(stdin);
40 x_fprintf(dbf, "%s", prompt);
50 if (sys_select_intr(fd+1,&fds,&timeout) == 1) {
51 ret = fgets(line, sizeof(line), stdin);
54 if (callback) callback();
58 /****************************************************************************
59 display the prompt and wait for input. Call callback() regularly
60 ****************************************************************************/
61 char *smb_readline(char *prompt, void (*callback)(void),
62 char **(completion_fn)(char *text, int start, int end))
67 /* Aargh! Readline does bizzare things with the terminal width
68 that mucks up expect(1). Set CLI_NO_READLINE in the environment
69 to force readline not to be used. */
71 if (getenv("CLI_NO_READLINE"))
72 return smb_readline_replacement(prompt, callback,
76 /* The callback prototype has changed slightly between
77 different versions of Readline, so the same
78 function works in all of them to date, but we get
79 compiler warnings in some. */
80 rl_attempted_completion_function = completion_fn;
83 if (callback) rl_event_hook = (Function *)callback;
84 ret = readline(prompt);
85 if (ret && *ret) add_history(ret);
88 return smb_readline_replacement(prompt, callback, completion_fn);
92 /****************************************************************************
94 ****************************************************************************/
97 #if defined(HAVE_LIBREADLINE)
101 hlist = history_list();
103 for (i = 0; hlist && hlist[i]; i++) {
104 DEBUG(0, ("%d: %s\n", i, hlist[i]->line));
107 DEBUG(0,("no history without readline support\n"));