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 cast is here because the callback prototype has
77 changed slightly between different versions of
78 Readline. The same function works in all of them
79 to date, but we get compiler warnings without the
81 rl_attempted_completion_function =
82 (rl_completion_func_t *) completion_fn;
85 if (callback) rl_event_hook = (Function *)callback;
86 ret = readline(prompt);
87 if (ret && *ret) add_history(ret);
90 return smb_readline_replacement(prompt, callback, completion_fn);
94 /****************************************************************************
96 ****************************************************************************/
99 #if defined(HAVE_LIBREADLINE)
103 hlist = history_list();
105 for (i = 0; hlist && hlist[i]; i++) {
106 DEBUG(0, ("%d: %s\n", i, hlist[i]->line));
109 DEBUG(0,("no history without readline support\n"));