From c21181e6ddd678c63a0a2d75f0dc3a6ceb3df3bf Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Thu, 1 May 2008 11:50:35 +0000 Subject: [PATCH] Apply patch from bug #1076 by Tullio Andreatta that implements multiple commands per line in the console when using readline. Modify the default to use a semicolon as the command separator. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6862 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/AUTHORS | 1 + bacula/src/console/console.c | 61 +++++++++++++++++++++++++----- bacula/src/version.h | 4 +- bacula/src/win32/compat/compat.cpp | 1 + bacula/technotes-2.3 | 4 ++ 5 files changed, 60 insertions(+), 11 deletions(-) diff --git a/bacula/AUTHORS b/bacula/AUTHORS index 1d4b26752c..605ae87e7e 100644 --- a/bacula/AUTHORS +++ b/bacula/AUTHORS @@ -90,5 +90,6 @@ Thomas Glatthor Thorsten Enge Tim Oberfoell Tomas Cameron +Tullio Andreatta Wolfgang Denk Yves Orton diff --git a/bacula/src/console/console.c b/bacula/src/console/console.c index 67e9baa707..386fac430b 100644 --- a/bacula/src/console/console.c +++ b/bacula/src/console/console.c @@ -103,6 +103,9 @@ static int echocmd(FILE *input, BSOCK *UA_sock); static int timecmd(FILE *input, BSOCK *UA_sock); static int sleepcmd(FILE *input, BSOCK *UA_sock); static int execcmd(FILE *input, BSOCK *UA_sock); +#ifdef HAVE_READLINE +static int eolcmd(FILE *input, BSOCK *UA_sock); +#endif #define CONFIG_FILE "bconsole.conf" /* default configuration file */ @@ -171,6 +174,9 @@ static struct cmdstruct commands[] = { { N_("exec"), execcmd, _("execute an external command")}, { N_("exit"), quitcmd, _("exit = quit")}, { N_("zed_keys"), zed_keyscmd, _("zed_keys = use zed keys instead of bash keys")}, +#ifdef HAVE_READLINE + { N_("separator"), eolcmd, _("set command separator")}, +#endif }; #define comsize (sizeof(commands)/sizeof(struct cmdstruct)) @@ -340,23 +346,60 @@ static int tls_pem_callback(char *buf, int size, const void *userdata) #include "readline.h" #include "history.h" +static char eol = ';'; +static int eolcmd(FILE *input, BSOCK *UA_sock) +{ + if ((argc > 1) && (strchr("!$%&'()*+,-/:;<>?[]^`{|}~", argk[1][0]) != NULL)) { + eol = argk[1][0]; + return 1; + } + sendit(_("Missing or illegal separator character.\n")); + return 1; +} + int get_cmd(FILE *input, const char *prompt, BSOCK *sock, int sec) { - char *line; + static char *line = NULL; + static char *next = NULL; + static int do_history = 0; + char *command; - rl_catch_signals = 0; /* do it ourselves */ - line = readline((char *)prompt); /* cast needed for old readlines */ + if (line == NULL) { + do_history = 0; + rl_catch_signals = 0; /* do it ourselves */ + line = readline((char *)prompt); /* cast needed for old readlines */ - if (!line) { - exit(1); + if (!line) { + exit(1); + } + strip_trailing_junk(line); + command = line; + } else { + *next = eol; + command = next + 1; + } + + next = strchr(command, eol); + if (next != NULL) { + *next = '\0'; } - strip_trailing_junk(line); - sock->msglen = pm_strcpy(&sock->msg, line); + if (command != line && isatty(fileno(input))) { + senditf("%s%s\n", prompt, command); + } + + sock->msglen = pm_strcpy(&sock->msg, command); if (sock->msglen) { - add_history(sock->msg); + do_history++; + } + + if (next == NULL) { + if (do_history) { + add_history(line); + } + free(line); + line = NULL; } - free(line); return 1; } diff --git a/bacula/src/version.h b/bacula/src/version.h index 2aceda5db4..57bdc43f34 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "2.3.18" -#define BDATE "19 April 2008" -#define LSMDATE "19Apr08" +#define BDATE "01 May 2008" +#define LSMDATE "01May08" #define PROG_COPYRIGHT "Copyright (C) %d-2008 Free Software Foundation Europe e.V.\n" #define BYEAR "2008" /* year for copyright messages in progs */ diff --git a/bacula/src/win32/compat/compat.cpp b/bacula/src/win32/compat/compat.cpp index 152dc23b1a..f224c93de3 100644 --- a/bacula/src/win32/compat/compat.cpp +++ b/bacula/src/win32/compat/compat.cpp @@ -644,6 +644,7 @@ statDir(const char *file, struct stat *sb) sb->st_ctime = now; sb->st_mtime = now; sb->st_atime = now; + sb->st_rdev = 0; return 0; } diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index 24152de4c0..2d695e4780 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -24,6 +24,10 @@ Add long term statistics job table General: +01May08 +kes Apply patch from bug #1076 by Tullio Andreatta + that implements multiple commands per line in the console when using + readline. Modify the default to use a semicolon as the command separator. 28Apr08 ebl Fix SQL query in migration code. ebl Make accurate mode with hash disk pass regression tests -- 2.39.5