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.
25 #ifdef HAVE_LIBREADLINE
26 # ifdef HAVE_READLINE_READLINE_H
27 # include <readline/readline.h>
28 # ifdef HAVE_READLINE_HISTORY_H
29 # include <readline/history.h>
32 # ifdef HAVE_READLINE_H
33 # include <readline.h>
34 # ifdef HAVE_HISTORY_H
38 # undef HAVE_LIBREADLINE
43 /****************************************************************************
44 display the prompt and wait for input. Call callback() regularly
45 ****************************************************************************/
46 char *smb_readline(char *prompt, void (*callback)(void),
47 char **(completion_fn)(char *text, int start, int end))
52 rl_attempted_completion_function =
53 (rl_completion_func_t *)completion_fn;
56 if (callback) rl_event_hook = (Function *)callback;
57 ret = readline(prompt);
58 if (ret && *ret) add_history(ret);
64 struct timeval timeout;
65 int fd = fileno(stdin);
67 fprintf(dbf, "%s", prompt);
77 if (sys_select_intr(fd+1,&fds,&timeout) == 1) {
78 ret = fgets(line, sizeof(line), stdin);
81 if (callback) callback();
86 /****************************************************************************
88 ****************************************************************************/
89 void cmd_history(void)
91 #if defined(HAVE_LIBREADLINE)
95 hlist = history_list();
97 for (i = 0; hlist && hlist[i]; i++) {
98 DEBUG(0, ("%d: %s\n", i, hlist[i]->line));
101 DEBUG(0,("no history without readline support\n"));