Imported Upstream version 2.6.0
[debian/amanda] / oldrecover-src / set_commands.c
index 48e655d602e5792ffa1a2d62b860a808c201f2d6..a0c83babd339769127d9473b0e4313eb7a79cc98 100644 (file)
@@ -30,6 +30,7 @@
  */
 
 #include "amanda.h"
+#include "util.h"
 #include "amrecover.h"
 
 #ifdef SAMBA_CLIENT
@@ -62,8 +63,8 @@ set_date(
        }
        else
        {
-           printf("No index records for cwd on new date\n");
-           printf("Setting cwd to mount point\n");
+           g_printf(_("No index records for cwd on new date\n"));
+           g_printf(_("Setting cwd to mount point\n"));
            disk_path = newstralloc(disk_path, "/");    /* fake it */
            clear_dir_list();
        }
@@ -81,14 +82,15 @@ set_host(
     struct hostent *hp;
     char **hostp;
     int found_host = 0;
+    char *uqhost = unquote_string(host);
 
     if (is_extract_list_nonempty())
     {
-       printf("Must clear extract list before changing host\n");
+       g_printf(_("Must clear extract list before changing host\n"));
        return;
     }
 
-    cmd = stralloc2("HOST ", host);
+    cmd = stralloc2("HOST ", uqhost);
     if (converse(cmd) == -1)
        exit(1);
     if (server_happy())
@@ -101,9 +103,9 @@ set_host(
         * Try converting the given host to a fully qualified name
         * and then try each of the aliases.
         */
-       if ((hp = gethostbyname(host)) != NULL) {
+       if ((hp = gethostbyname(uqhost)) != NULL) {
            host = hp->h_name;
-           printf("Trying host %s ...\n", host);
+           g_printf(_("Trying host %s ...\n"), host);
            cmd = newstralloc2(cmd, "HOST ", host);
            if (converse(cmd) == -1)
                exit(1);
@@ -115,7 +117,7 @@ set_host(
            {
                for (hostp = hp->h_aliases; (host = *hostp) != NULL; hostp++)
                {
-                   printf("Trying host %s ...\n", host);
+                   g_printf(_("Trying host %s ...\n"), host);
                    cmd = newstralloc2(cmd, "HOST ", host);
                    if (converse(cmd) == -1)
                        exit(1);
@@ -137,6 +139,7 @@ set_host(
        clear_dir_list();
     }
     amfree(cmd);
+    amfree(uqhost);
 }
 
 
@@ -157,22 +160,28 @@ set_disk(
     char *     mtpt)
 {
     char *cmd = NULL;
+    char *uqdsk;
+    char *uqmtpt = NULL;
 
     if (is_extract_list_nonempty())
     {
-       printf("Must clear extract list before changing disk\n");
+       g_printf(_("Must clear extract list before changing disk\n"));
        return;
     }
 
     /* if mount point specified, check it is valid */
-    if ((mtpt != NULL) && (*mtpt != '/'))
-    {
-       printf("Mount point \"%s\" invalid - must start with /\n", mtpt);
-       return;
+    if (mtpt != NULL) {
+       uqmtpt = unquote_string(mtpt);
+       if (*mtpt != '/') {
+           g_printf(_("Mount point \"%s\" invalid - must start with /\n"), uqmtpt);
+           amfree(uqmtpt);
+           return;
+       }
     }
 
     clear_dir_list();
-    cmd = stralloc2("DISK ", dsk);
+    uqdsk = unquote_string(dsk);
+    cmd = stralloc2("DISK ", uqdsk);
     if (converse(cmd) == -1)
        exit(1);
     amfree(cmd);
@@ -180,14 +189,14 @@ set_disk(
     if (!server_happy())
        return;
 
-    disk_name = newstralloc(disk_name, dsk);
+    disk_name = newstralloc(disk_name, uqdsk);
     if (mtpt == NULL)
     {
        /* mount point not specified */
-       if (*dsk == '/')
+       if (*uqdsk == '/')
        {
            /* disk specified by mount point, hence use it */
-           mount_point = newstralloc(mount_point, dsk);
+           mount_point = newstralloc(mount_point, uqdsk);
        }
        else
        {
@@ -198,7 +207,7 @@ set_disk(
     else
     {
        /* mount point specified */
-       mount_point = newstralloc(mount_point, mtpt);
+       mount_point = newstralloc(mount_point, uqmtpt);
     }
 
     /* set the working directory to the mount point */
@@ -215,11 +224,13 @@ set_disk(
     }
     else
     {
-       printf("No index records for disk for specified date\n");
-       printf("If date correct, notify system administrator\n");
+       g_printf(_("No index records for disk for specified date\n"));
+       g_printf(_("If date correct, notify system administrator\n"));
        disk_path = newstralloc(disk_path, "/");        /* fake it */
        clear_dir_list();
     }
+    amfree(uqmtpt);
+    amfree(uqdsk);
 }
 
 void
@@ -227,9 +238,12 @@ list_disk(
     char *     amdevice)
 {
     char *cmd = NULL;
+    char *uqamdevice;
 
     if(amdevice) {
-       cmd = stralloc2("LISTDISK ", amdevice);
+       uqamdevice = unquote_string(amdevice);
+       cmd = stralloc2("LISTDISK ", uqamdevice);
+       amfree(uqamdevice);
        if (converse(cmd) == -1)
            exit(1);
        amfree(cmd);
@@ -242,6 +256,17 @@ list_disk(
     }
 }
 
+void
+local_cd(
+    char *dir)
+{
+    char *uqdir = unquote_string(dir);
+    if (chdir(uqdir) == -1) {
+       perror(uqdir);
+    }
+    amfree(uqdir);
+}
+
 void
 cd_glob(
     char *     glob)
@@ -249,18 +274,20 @@ cd_glob(
     char *regex;
     char *regex_path;
     char *s;
+    char *uqglob;
 
     char *path_on_disk = NULL;
 
     if (disk_name == NULL) {
-       printf("Must select disk before changing directory\n");
+       g_printf(_("Must select disk before changing directory\n"));
        return;
     }
 
-    regex = glob_to_regex(glob);
-    dbprintf(("cd_glob (%s) -> %s\n", glob, regex));
+    uqglob = unquote_string(glob);
+    regex = glob_to_regex(uqglob);
+    dbprintf(_("cd_glob (%s) -> %s\n"), uqglob, regex);
     if ((s = validate_regexp(regex)) != NULL) {
-        printf("\"%s\" is not a valid shell wildcard pattern: ", glob);
+        g_printf(_("\"%s\" is not a valid shell wildcard pattern: "), glob);
         puts(s);
        amfree(regex);
         return;
@@ -287,10 +314,11 @@ cd_glob(
         amfree(clean_disk_path);
     }
 
-    cd_dir(path_on_disk, glob);
+    cd_dir(path_on_disk, uqglob);
 
     amfree(regex_path);
     amfree(path_on_disk);
+    amfree(uqglob);
 }
 
 void
@@ -298,16 +326,19 @@ cd_regex(
     char *     regex)
 {
     char *s;
+    char *uqregex;
 
     char *path_on_disk = NULL;
 
     if (disk_name == NULL) {
-       printf("Must select disk before changing directory\n");
+       g_printf(_("Must select disk before changing directory\n"));
        return;
     }
 
-    if ((s = validate_regexp(regex)) != NULL) {
-       printf("\"%s\" is not a valid regular expression: ", regex);
+    uqregex = unquote_string(regex);
+    if ((s = validate_regexp(uqregex)) != NULL) {
+       g_printf(_("\"%s\" is not a valid regular expression: "), uqregex);
+       amfree(uqregex);
        puts(s);
        return;
     }
@@ -321,9 +352,10 @@ cd_regex(
         amfree(clean_disk_path);
     }
 
-    cd_dir(path_on_disk, regex);
+    cd_dir(path_on_disk, uqregex);
 
     amfree(path_on_disk);
+    amfree(uqregex);
 }
 
 void
@@ -378,7 +410,7 @@ cd_dir(
        set_directory(dir);
     }
     else {
-       printf("Too many directory\n");
+       g_printf(_("Too many directory\n"));
     }
     amfree(dir);
 }
@@ -400,7 +432,7 @@ set_directory(
     }
 
     if (disk_name == NULL) {
-       printf("Must select disk before setting directory\n");
+       g_printf(_("Must select disk before setting directory\n"));
        return;
        /*NOTREACHED*/
     }
@@ -420,7 +452,7 @@ set_directory(
        {
            if (strncmp(mount_point, ldir, strlen(mount_point)) != 0)
            {
-               printf("Invalid directory - Can't cd outside mount point \"%s\"\n",
+               g_printf(_("Invalid directory - Can't cd outside mount point \"%s\"\n"),
                       mount_point);
                amfree(ldir);
                return;
@@ -456,7 +488,7 @@ set_directory(
        if (strcmp(dp, "..") == 0) {
            if (strcmp(new_dir, "/") == 0) {
                /* at top of disk */
-               printf("Invalid directory - Can't cd outside mount point \"%s\"\n",
+               g_printf(_("Invalid directory - Can't cd outside mount point \"%s\"\n"),
                       mount_point);
                /*@ignore@*/
                amfree(new_dir);
@@ -500,7 +532,7 @@ set_directory(
     }
     else
     {
-       printf("Invalid directory - %s\n", dir);
+       g_printf(_("Invalid directory - %s\n"), dir);
     }
 
     /*@ignore@*/
@@ -515,13 +547,13 @@ void
 show_directory(void)
 {
     if (mount_point == NULL || disk_path == NULL)
-        printf("Must select disk first\n");
+        g_printf(_("Must select disk first\n"));
     else if (strcmp(mount_point, "/") == 0)
-       printf("%s\n", disk_path);
+       g_printf("%s\n", disk_path);
     else if (strcmp(disk_path, "/") == 0)
-       printf("%s\n", mount_point);
+       g_printf("%s\n", mount_point);
     else
-       printf("%s%s\n", mount_point, disk_path);
+       g_printf("%s%s\n", mount_point, disk_path);
 }
 
 
@@ -530,21 +562,22 @@ void
 set_tape(
     char *     tape)
 {
-    char *tapedev = strchr(tape, ':');
+    char *uqtape = unquote_string(tape);
+    char *tapedev = strchr(uqtape, ':');
 
     if (tapedev)
     {
-       if (tapedev != tape) {
+       if (tapedev != uqtape) {
            if((strchr(tapedev+1, ':') == NULL) &&
-              (strncmp(tape, "null:", 5) == 0 ||
-               strncmp(tape, "rait:", 5) == 0 ||
-               strncmp(tape, "file:", 5) == 0 ||
-               strncmp(tape, "tape:", 5) == 0)) {
-               tapedev = tape;
+              (strncmp(uqtape, "null:", 5) == 0 ||
+               strncmp(uqtape, "rait:", 5) == 0 ||
+               strncmp(uqtape, "file:", 5) == 0 ||
+               strncmp(uqtape, "tape:", 5) == 0)) {
+               tapedev = uqtape;
            }
            else {
                *tapedev = '\0';
-               tape_server_name = newstralloc(tape_server_name, tape);
+               tape_server_name = newstralloc(tape_server_name, uqtape);
                ++tapedev;
            }
        } else { /* reset server_name if start with : */
@@ -552,7 +585,7 @@ set_tape(
            ++tapedev;
        }
     } else
-       tapedev = tape;
+       tapedev = uqtape;
     
     if (tapedev[0])
     {
@@ -563,14 +596,14 @@ set_tape(
     }
 
     if (tape_device_name)
-       printf ("Using tape \"%s\"", tape_device_name);
+       g_printf (_("Using tape \"%s\""), tape_device_name);
     else
-       printf ("Using default tape");
+       g_printf (_("Using default tape"));
 
     if (tape_server_name)
-       printf (" from server %s.\n", tape_server_name);
+       g_printf (_(" from server %s.\n"), tape_server_name);
     else
-       printf (".\nTape server unspecified, assumed to be %s.\n",
+       g_printf (_(".\nTape server unspecified, assumed to be %s.\n"),
                server_name);
 }
 
@@ -580,11 +613,11 @@ set_mode(
 {
 #ifdef SAMBA_CLIENT
   if (mode == SAMBA_SMBCLIENT) {
-    printf ("SAMBA dumps will be extracted using smbclient\n");
+    g_printf (_("SAMBA dumps will be extracted using smbclient\n"));
     samba_extract_method = SAMBA_SMBCLIENT;
   } else {
     if (mode == SAMBA_TAR) {
-      printf ("SAMBA dumps will be extracted as TAR dumps\n");
+      g_printf (_("SAMBA dumps will be extracted as TAR dumps\n"));
       samba_extract_method = SAMBA_TAR;
     }
   }
@@ -597,12 +630,12 @@ void
 show_mode(void) 
 {
 #ifdef SAMBA_CLIENT
-  printf ("SAMBA dumps are extracted ");
+  g_printf (_("SAMBA dumps are extracted "));
 
   if (samba_extract_method == SAMBA_TAR) {
-    printf (" as TAR dumps\n");
+    g_printf (_(" as TAR dumps\n"));
   } else {
-    printf ("using smbclient\n");
+    g_printf (_("using smbclient\n"));
   }
 #endif /* SAMBA_CLIENT */
 }