]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/console/console.c
This commit was manufactured by cvs2svn to create tag
[bacula/bacula] / bacula / src / console / console.c
index 6a2bae7ab5b40c92ae7166160d8b11fc7dcec0de..79544a66a76cd5876bca9b9c1800d8afcdeab182 100644 (file)
@@ -8,21 +8,23 @@
  */
 
 /*
-   Copyright (C) 2000, 2001 Kern Sibbald and John Walker
+   Copyright (C) 2000-2003 Kern Sibbald and John Walker
 
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   as published by the Free Software Foundation; either version 2
-   of the License, or (at your option) any later version.
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
 
-   This program is distributed in the hope that it will be useful,
+   This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+   MA 02111-1307, USA.
 
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 
 #include "bacula.h"
@@ -74,15 +76,15 @@ static int sleepcmd(FILE *input, BSOCK *UA_sock);
 
 static void usage()
 {
-   fprintf(stderr,
-"\nVersion: " VERSION " (" BDATE ")\n\n"
+   fprintf(stderr, _(
+"\nVersion: " VERSION " (" BDATE ") %s %s %s\n\n"
 "Usage: console [-s] [-c config_file] [-d debug_level] [config_file]\n"
 "       -c <file>   set configuration file to file\n"
 "       -dnn        set debug level to nn\n"
 "       -s          no signals\n"
 "       -t          test - read configuration and exit\n"
 "       -?          print this message.\n"  
-"\n");
+"\n"), HOST_OS, DISTNAME, DISTVER);
 
    exit(1);
 }
@@ -180,6 +182,7 @@ static void read_and_process_input(FILE *input, BSOCK *UA_sock)
         if (fgets(UA_sock->msg, len, input) == NULL) {
            stat = -1;
         } else {
+            sendit("%s", UA_sock->msg);  /* echo to terminal */
            strip_trailing_junk(UA_sock->msg);
            UA_sock->msglen = strlen(UA_sock->msg);
            stat = 1;
@@ -188,12 +191,16 @@ static void read_and_process_input(FILE *input, BSOCK *UA_sock)
       if (stat < 0) {
         break;                       /* error */
       } else if (stat == 0) {        /* timeout */
-         bnet_fsend(UA_sock, ".messages");
+         if (strcmp(prompt, "*") == 0) {
+            bnet_fsend(UA_sock, ".messages");
+        } else {
+           continue;
+        }
       } else {
         at_prompt = FALSE;
         /* @ => internal command for us */
          if (UA_sock->msg[0] == '@') {
-           parse_command_args(UA_sock->msg, args, &argc, argk, argv);
+           parse_args(UA_sock->msg, &args, &argc, argk, argv, MAX_CMD_ARGS);
            if (!do_a_command(input, UA_sock)) {
               break;
            }
@@ -310,8 +317,8 @@ int main(int argc, char *argv[])
    }
    UnlockRes();
    if (ndir == 0) {
-      Emsg1(M_ERROR_TERM, 0, "No Director resource defined in %s\n\
-Without that I don't how to speak to the Director :-(\n", configfile);
+      Emsg1(M_ERROR_TERM, 0, _("No Director resource defined in %s\n\
+Without that I don't how to speak to the Director :-(\n"), configfile);
    }
 
    if (test_config) {
@@ -324,20 +331,20 @@ Without that I don't how to speak to the Director :-(\n", configfile);
    if (ndir > 1) {
       UA_sock = init_bsock(NULL, 0, "", "", 0);
 try_again:
-      sendit("Available Directors:\n");
+      sendit(_("Available Directors:\n"));
       LockRes();
       ndir = 0;
       for (dir = NULL; (dir = (DIRRES *)GetNextRes(R_DIRECTOR, (RES *)dir)); ) {
-         fprintf(output, "%d  %s at %s:%d\n", 1+ndir++, dir->hdr.name, dir->address,
+         fprintf(output, _("%d  %s at %s:%d\n"), 1+ndir++, dir->hdr.name, dir->address,
            dir->DIRport);
       }
       UnlockRes();
-      if (get_cmd(stdin, "Select Director: ", UA_sock, 600) < 0) {
+      if (get_cmd(stdin, _("Select Director: "), UA_sock, 600) < 0) {
         return 1;
       }
       item = atoi(UA_sock->msg);
       if (item < 0 || item > ndir) {
-         sendit("You must enter a number between 1 and %d\n", ndir);
+         sendit(_("You must enter a number between 1 and %d\n"), ndir);
         goto try_again;
       }
       LockRes();
@@ -354,7 +361,7 @@ try_again:
    }
       
 
-   sendit("Connecting to Director %s:%d\n", dir->address,dir->DIRport);
+   sendit(_("Connecting to Director %s:%d\n"), dir->address,dir->DIRport);
    UA_sock = bnet_connect(NULL, 5, 15, "Director daemon", dir->address, 
                          NULL, dir->DIRport, 0);
    if (UA_sock == NULL) {
@@ -370,6 +377,20 @@ try_again:
 
    Dmsg0(40, "Opened connection with Director daemon\n");
 
+   sendit(_("Enter a period to cancel a command.\n"));
+
+   char *env = getenv("HOME");
+   if (env) {
+      FILE *fd;
+      pm_strcpy(&UA_sock->msg, env);
+      pm_strcat(&UA_sock->msg, "/.bconsolerc");
+      fd = fopen(UA_sock->msg, "r");
+      if (fd) {
+       read_and_process_input(fd, UA_sock);
+       fclose(fd);
+      }
+   }
+
    read_and_process_input(stdin, UA_sock);
 
    if (UA_sock) {
@@ -399,9 +420,10 @@ static void terminate_console(int sig)
 }
 
 #ifdef HAVE_READLINE
+#define READLINE_LIBRARY 1
 #undef free
-#include "readline/readline.h"
-#include "readline/history.h"
+#include "readline.h"
+#include "history.h"
 
 
 int 
@@ -415,9 +437,8 @@ get_cmd(FILE *input, char *prompt, BSOCK *sock, int sec)
    if (!line) {
       exit(1);
    }
-   strcpy(sock->msg, line);
-   strip_trailing_junk(sock->msg);
-   sock->msglen = strlen(sock->msg);
+   strip_trailing_junk(line);
+   sock->msglen = pm_strcpy(&sock->msg, line);
    if (sock->msglen) {
       add_history(sock->msg);
    }
@@ -438,21 +459,21 @@ wait_for_data(int fd, int sec)
    fd_set fdset;
    struct timeval tv;
 
-   FD_ZERO(&fdset);
-   FD_SET(fd, &fdset);
    tv.tv_sec = sec;
    tv.tv_usec = 0;
    for ( ;; ) {
+      FD_ZERO(&fdset);
+      FD_SET(fd, &fdset);
       switch(select(fd + 1, &fdset, NULL, NULL, &tv)) {
-        case 0:                         /* timeout */
-           return 0;
-        case -1:
-           if (errno == EINTR || errno == EAGAIN) {
-              continue;
-           }
-           return -1;                  /* error return */
-        default:
-           return 1;
+      case 0:                        /* timeout */
+        return 0;
+      case -1:
+        if (errno == EINTR || errno == EAGAIN) {
+           continue;
+        }
+        return -1;                  /* error return */
+      default:
+        return 1;
       }
    }
 }
@@ -476,19 +497,20 @@ get_cmd(FILE *input, char *prompt, BSOCK *sock, int sec)
    }
 again:
    switch (wait_for_data(fileno(input), sec)) {
-      case 0:
-        return 0;                    /* timeout */
-      case -1: 
-        return -1;                   /* error */
-      default:
-        len = sizeof_pool_memory(sock->msg) - 1;
-        if (stop) {
-           goto again;
-        }
-        if (fgets(sock->msg, len, input) == NULL) {
-           return -1;
-        }
-        break;
+   case 0:
+      return 0;                   /* timeout */
+   case -1: 
+      return -1;                  /* error */
+   default:
+      len = sizeof_pool_memory(sock->msg) - 1;
+      if (stop) {
+        sleep(1);
+        goto again;
+      }
+      if (fgets(sock->msg, len, input) == NULL) {
+        return -1;
+      }
+      break;
    }
    strip_trailing_junk(sock->msg);
    sock->msglen = strlen(sock->msg);
@@ -499,7 +521,8 @@ again:
 
 static int versioncmd(FILE *input, BSOCK *UA_sock)
 {
-   sendit("Version: " VERSION " (" BDATE ")\n");
+   sendit("Version: " VERSION " (" BDATE ") %s %s %s\n",
+      HOST_OS, DISTNAME, DISTVER);
    return 1;
 }
 
@@ -508,17 +531,18 @@ static int inputcmd(FILE *input, BSOCK *UA_sock)
    FILE *fd;
 
    if (argc > 2) {
-      sendit("Too many arguments.\n");
-      return 0;
+      sendit(_("Too many arguments on input command.\n"));
+      return 1;
    }
    if (argc == 1) {
-      sendit("First argument must be a filename.\n");
-      return 0;
+      sendit(_("First argument to input command must be a filename.\n"));
+      return 1;
    }
    fd = fopen(argk[1], "r");
    if (!fd) {
-      sendit("Cannot open file. ERR=%s\n", strerror(errno));
-      return 0; 
+      sendit(_("Cannot open file %s for input. ERR=%s\n"), 
+        argk[1], strerror(errno));
+      return 1; 
    }
    read_and_process_input(fd, UA_sock);
    fclose(fd);
@@ -544,7 +568,7 @@ static int do_outputcmd(FILE *input, BSOCK *UA_sock)
    char *mode = "a+";
 
    if (argc > 3) {
-      sendit("Too many arguments.\n");
+      sendit(_("Too many arguments on output/tee command.\n"));
       return 1;
    }
    if (argc == 1) {
@@ -560,7 +584,8 @@ static int do_outputcmd(FILE *input, BSOCK *UA_sock)
    }
    fd = fopen(argk[1], mode);
    if (!fd) {
-      sendit("Cannot open file. ERR=%s\n", strerror(errno));
+      sendit(_("Cannot open file %s for output. ERR=%s\n"), 
+        argk[1], strerror(errno));
       return 1; 
    }
    output = fd;