Hello,

This patch add globing character to the cd command of amrecover.
You will be able to do:

    cd Buchf*
or  cd Buchf*hrung


Christoph, could you try this patch

Jean-Louis


On Wed, Nov 15, 2000 at 05:14:49PM -0500, John R. Jackson wrote:
> >... How do i change into a folder like this?
> >"cd Buchführung" didn't do the job...
> 
> I don't think you can.
> 
> At one point I was going to add a "cdx" command to amrecover ala "addx"
> that accepts regular expressions, then you could do "cdx Buchf.*", but
> it's not there and I don't know of any way to get past this.
> 
> It also wouldn't surprise me to find out that even if this feature
> were there, other places in amrecover (and amindexd) had trouble with
> such names.
> 
> I've got users who like to annoy me with "odd" characters in filenames,
> too, and the best I've come up with is "doing it by hand", i.e. figuring
> out what tapes are needed and running amrestore myself instead of using
> amrecover.
> 
> Sorry.  I know it's a pain in the ass.
> 
> >Christoph Stoppe
> 
> John R. Jackson, Technical Software Specialist, [EMAIL PROTECTED]

-- 
Jean-Louis Martineau             email: [EMAIL PROTECTED] 
Departement IRO, Universite de Montreal
C.P. 6128, Succ. CENTRE-VILLE    Tel: (514) 343-6111 ext. 3529
Montreal, Canada, H3C 3J7        Fax: (514) 343-5834
--- recover-src/set_commands.c.orig     Wed Nov 15 17:47:23 2000
+++ recover-src/set_commands.c  Wed Nov 15 18:42:32 2000
@@ -212,6 +212,95 @@
     }
 }
 
+void cd_glob(glob)
+char *glob;
+{
+    char *regex;
+    char *regex_path;
+    char *s;
+
+    char *path_on_disk = NULL;
+    char *path_on_disk_slash = NULL;
+    char *dir = NULL;
+
+    int nb_found;
+    int i;
+
+    DIR_ITEM *ditem;
+
+    regex = glob_to_regex(glob);
+    dbprintf(("add_glob (%s) -> %s\n", glob, regex));
+    if ((s = validate_regexp(regex)) != NULL) {
+        printf("\"%s\" is not a valid shell wildcard pattern: ", glob);
+        puts(s);
+        return;
+    }
+    /*
+     * glob_to_regex() anchors the beginning of the pattern with ^,
+     * but we will be tacking it onto the end of the current directory
+     * in add_file, so strip that off.  Also, it anchors the end with
+     * $, but we need to match a trailing /, add it if it is not there
+     */
+    regex_path = stralloc(regex + 1);
+    amfree(regex);
+    if(regex_path[strlen(regex_path) - 2] != '/' ) {
+       regex_path[strlen(regex_path) - 1] = '\0';
+       strappend(regex_path, "/$");
+    }
+
+    if (disk_path == NULL) {
+        printf("Must select directory before adding files\n");
+        return;
+    }
+
+    /* convert path (assumed in cwd) to one on disk */
+    if (strcmp(disk_path, "/") == 0)
+        path_on_disk = stralloc2("/", regex_path);
+    else {
+        char *clean_disk_path = clean_regex(disk_path);
+        path_on_disk = vstralloc(clean_disk_path, "/", regex_path, NULL);
+        amfree(clean_disk_path);
+    }
+
+    path_on_disk_slash = stralloc2(path_on_disk, "/");
+
+    nb_found = 0;
+
+    for (ditem=get_dir_list(); ditem!=NULL && nb_found <= 1; 
+                              ditem=get_next_dir_item(ditem))
+    {
+       if (match(path_on_disk, ditem->path)
+           || match(path_on_disk_slash, ditem->path))
+       {
+           i = strlen(ditem->path);
+           if((i > 0 && ditem->path[i-1] == '/')
+               || (i > 1 && ditem->path[i-2] == '/' && ditem->path[i-1] == '.'))
+            {   /* It is a directory */
+               char *dir1, *dir2;
+               nb_found++;
+               dir = newstralloc(dir,ditem->path);
+               if(dir[strlen(dir)-1] == '/')
+                   dir[strlen(dir)-1] = '\0'; /* remove last / */
+               /* remove everything before the last / */
+               dir1 = rindex(dir,'/');
+               dir1++;
+               dir2 = stralloc(dir1);
+               amfree(dir);
+               dir = dir2;
+           }
+       }
+    }
+    if(nb_found==0) {
+       set_directory(glob);
+    }
+    else if(nb_found==1) {
+       set_directory(dir);
+    }
+    else {
+       printf("Too many directory\n");
+    }
+    amfree(regex_path);
+}
 
 void set_directory(dir)
 char *dir;
--- recover-src/uparse.y.orig   Wed Nov 15 18:17:01 2000
+++ recover-src/uparse.y        Wed Nov 15 18:17:17 2000
@@ -79,7 +79,7 @@
   |     SETDISK PATH { set_disk($2, NULL); }
   |     SETTAPE PATH { set_tape($2); }
   |     SETTAPE { set_tape(""); }
-  |     CD PATH { set_directory($2); }
+  |     CD PATH { cd_glob($2); }
   |     SETMODE SMB {
 #ifdef SAMBA_CLIENT
                         set_mode(SAMBA_SMBCLIENT);

Reply via email to