1 Index: src/console/console.c
2 ===================================================================
3 --- src/console/console.c (révision 5452)
4 +++ src/console/console.c (copie de travail)
10 +#define READLINE_LIBRARY 1
12 +#include "readline.h"
16 +get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec)
20 + rl_catch_signals = 0; /* do it ourselves */
21 + line = readline((char *)prompt); /* cast needed for old readlines */
26 + strip_trailing_junk(line);
27 + sock->msglen = pm_strcpy(&sock->msg, line);
29 + add_history(sock->msg);
35 +#else /* no readline, do it ourselves */
37 +#if !defined(HAVE_WIN32)
38 +static bool bisatty(int fd)
48 + * Returns: 1 if data available
53 +wait_for_data(int fd, int sec)
55 +#if defined(HAVE_WIN32)
65 + FD_SET((unsigned)fd, &fdset);
66 + switch(select(fd + 1, &fdset, NULL, NULL, &tv)) {
67 + case 0: /* timeout */
70 + if (errno == EINTR || errno == EAGAIN) {
73 + return -1; /* error return */
82 + * Get next input command from terminal.
84 + * Returns: 1 if got input
86 + * -1 if EOF or error
89 +get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec)
93 + if (output == stdout || teeout) {
98 + switch (wait_for_data(fileno(input), sec)) {
100 + return 0; /* timeout */
102 + return -1; /* error */
104 + len = sizeof_pool_memory(sock->msg) - 1;
110 + if (bisatty(fileno(input))) {
111 + input_line(sock->msg, len);
115 +#ifdef HAVE_WIN32 /* use special console for input on win32 */
116 + if (input == stdin) {
117 + if (win32_cgets(sock->msg, len) == NULL) {
123 + if (fgets(sock->msg, len, input) == NULL) {
132 + strip_trailing_junk(sock->msg);
133 + sock->msglen = strlen(sock->msg);
137 +#endif /* end non-readline code */
140 /*********************************************************************
142 * Main Bacula Console -- User Interface Program
145 /* Run commands in ~/.bconsolerc if any */
146 char *env = getenv("HOME");
148 +#ifdef HAVE_READLINE
149 + POOL_MEM history_file;
154 pm_strcpy(&UA_sock->msg, env);
156 read_and_process_input(fd, UA_sock);
160 +#ifdef HAVE_READLINE
161 + pm_strcpy(history_file, env);
162 + pm_strcat(history_file, "/.bconsole_history");
165 + read_history(history_file.c_str());
169 read_and_process_input(stdin, UA_sock);
174 +#ifdef HAVE_READLINE
176 + /* first, try to truncate the history file, and if it
177 + * fail, the file is probably not present, and we
178 + * can use write_history to create it
180 + if (history_truncate_file(history_file.c_str(), 100) == 0) {
181 + append_history(history_length, history_file.c_str());
183 + write_history(history_file.c_str());
187 terminate_console(0);
190 @@ -702,138 +858,6 @@
195 -#ifdef HAVE_READLINE
196 -#define READLINE_LIBRARY 1
198 -#include "readline.h"
199 -#include "history.h"
203 -get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec)
207 - rl_catch_signals = 0; /* do it ourselves */
208 - line = readline((char *)prompt); /* cast needed for old readlines */
213 - strip_trailing_junk(line);
214 - sock->msglen = pm_strcpy(&sock->msg, line);
215 - if (sock->msglen) {
216 - add_history(sock->msg);
222 -#else /* no readline, do it ourselves */
224 -#if !defined(HAVE_WIN32)
225 -static bool bisatty(int fd)
235 - * Returns: 1 if data available
240 -wait_for_data(int fd, int sec)
242 -#if defined(HAVE_WIN32)
252 - FD_SET((unsigned)fd, &fdset);
253 - switch(select(fd + 1, &fdset, NULL, NULL, &tv)) {
254 - case 0: /* timeout */
257 - if (errno == EINTR || errno == EAGAIN) {
260 - return -1; /* error return */
269 - * Get next input command from terminal.
271 - * Returns: 1 if got input
273 - * -1 if EOF or error
276 -get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec)
280 - if (output == stdout || teeout) {
285 - switch (wait_for_data(fileno(input), sec)) {
287 - return 0; /* timeout */
289 - return -1; /* error */
291 - len = sizeof_pool_memory(sock->msg) - 1;
297 - if (bisatty(fileno(input))) {
298 - input_line(sock->msg, len);
302 -#ifdef HAVE_WIN32 /* use special console for input on win32 */
303 - if (input == stdin) {
304 - if (win32_cgets(sock->msg, len) == NULL) {
310 - if (fgets(sock->msg, len, input) == NULL) {
319 - strip_trailing_junk(sock->msg);
320 - sock->msglen = strlen(sock->msg);
324 -#endif /* end non-readline code */
326 static int versioncmd(FILE *input, BSOCK *UA_sock)
328 senditf("Version: " VERSION " (" BDATE ") %s %s %s\n",