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 /* user input through readline callback */
26 static char *command_line;
27 static int *readline_event;
29 /****************************************************************************
30 samba readline callback function
31 ****************************************************************************/
32 static int smb_rl_callback_handler(char *line_read)
34 if (!command_line) return RL_ERROR;
38 pstrcpy(command_line, line_read);
39 #if defined(HAVE_LIBREADLINE)
40 #if defined(HAVE_READLINE_HISTORY_H) || defined(HAVE_HISTORY_H)
41 if (strlen(line_read)) add_history(line_read);
45 *readline_event = RL_GOT_LINE;
47 *readline_event = RL_GOT_EOF;
52 void smb_rl_read_char (void)
54 #ifdef HAVE_LIBREADLINE
55 *readline_event = RL_NO_EVENTS;
56 rl_callback_read_char ();
59 fgets(line, sizeof(line), stdin);
60 smb_rl_callback_handler(line);
64 /****************************************************************************
66 ****************************************************************************/
67 void init_smb_readline(char *prg_name, char *cline_ptr, int *event_ptr)
69 command_line = cline_ptr;
70 readline_event = event_ptr;
72 #ifdef HAVE_LIBREADLINE
73 rl_readline_name = prg_name;
74 rl_already_prompted = 1;
75 rl_callback_handler_install(NULL, (VFunction *)&smb_rl_callback_handler);
79 /****************************************************************************
81 ****************************************************************************/
82 void smb_readline_prompt(char *prompt)
86 fprintf(dbf, "%s", prompt);
89 #ifdef HAVE_LIBREADLINE
90 rl_callback_handler_remove();
91 rl_callback_handler_install(prompt, (VFunction *)&smb_rl_callback_handler);
95 /****************************************************************************
96 removes readline callback handler
97 ****************************************************************************/
98 void smb_readline_remove_handler(void)
100 #ifdef HAVE_LIBREADLINE
101 rl_callback_handler_remove ();
104 readline_event = NULL;
108 /****************************************************************************
110 ****************************************************************************/
111 void cmd_history(void)
113 #if defined(HAVE_LIBREADLINE) && (defined(HAVE_READLINE_HISTORY_H) || defined(HAVE_HISTORY_H))
117 hlist = history_list ();
119 for (i = 0; hlist && hlist[i]; i++) {
120 DEBUG(0, ("%d: %s\n", i, hlist[i]->line));
123 DEBUG(0,("no history without readline support\n"));