canonicalize names on command line and ignore dups
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Mon, 28 Feb 1983 16:36:50 +0000 (08:36 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Mon, 28 Feb 1983 16:36:50 +0000 (08:36 -0800)
SCCS-vsn: sbin/restore/main.c 3.4
SCCS-vsn: sbin/restore/utilities.c 3.4

usr/src/sbin/restore/main.c
usr/src/sbin/restore/utilities.c

index dfbb58e..9ef5111 100644 (file)
@@ -1,7 +1,7 @@
 /* Copyright (c) 1983 Regents of the University of California */
 
 #ifndef lint
 /* Copyright (c) 1983 Regents of the University of California */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     3.3     (Berkeley)      83/02/27";
+static char sccsid[] = "@(#)main.c     3.4     (Berkeley)      83/02/28";
 #endif
 
 /*
 #endif
 
 /*
@@ -45,6 +45,7 @@ main(argc, argv)
        char *inputdev = "/dev/rmt8";
        char *symtbl = "./restoresymtable";
        char *dirmodefile = "./dirmodes";
        char *inputdev = "/dev/rmt8";
        char *symtbl = "./restoresymtable";
        char *dirmodefile = "./dirmodes";
+       char name[BUFSIZ];
        int (*signal())();
        extern int onintr();
 
        int (*signal())();
        extern int onintr();
 
@@ -154,12 +155,13 @@ usage:
                setup();
                extractdirs((char *)0);
                while (argc--) {
                setup();
                extractdirs((char *)0);
                while (argc--) {
-                       if ((ino = psearch(*argv)) == 0 ||
+                       canon(*argv++, name);
+                       if ((ino = psearch(name)) == 0 ||
                            BIT(ino, dumpmap) == 0) {
                            BIT(ino, dumpmap) == 0) {
-                               fprintf(stderr, "%s: not on tape\n", *argv++);
+                               fprintf(stderr, "%s: not on tape\n", name);
                                continue;
                        }
                                continue;
                        }
-                       treescan(*argv++, ino, listfile);
+                       treescan(name, ino, listfile);
                }
                done(0);
 
                }
                done(0);
 
@@ -172,19 +174,19 @@ usage:
                        panic("no memory for entry table\n");
                (void)addentry(".", ROOTINO, NODE);
                while (argc--) {
                        panic("no memory for entry table\n");
                (void)addentry(".", ROOTINO, NODE);
                while (argc--) {
-                       if ((ino = psearch(*argv)) == 0 ||
+                       canon(*argv++, name);
+                       if ((ino = psearch(name)) == 0 ||
                            BIT(ino, dumpmap) == 0) {
                            BIT(ino, dumpmap) == 0) {
-                               fprintf(stderr, "%s: not on tape\n", *argv++);
+                               fprintf(stderr, "%s: not on tape\n", name);
                                continue;
                        }
                        if (mflag)
                                continue;
                        }
                        if (mflag)
-                               pathcheck(*argv, NEW);
+                               pathcheck(name, NULL);
                        if (hflag)
                        if (hflag)
-                               treescan(*argv++, ino, addfile);
+                               treescan(name, ino, addfile);
                        else
                        else
-                               addfile(*argv++, ino, LEAF);
+                               addfile(name, ino, inodetype(ino));
                }
                }
-               createnodes();
                createfiles();
                createlinks();
                setdirmodes(dirmodefile);
                createfiles();
                createlinks();
                setdirmodes(dirmodefile);
@@ -228,6 +230,8 @@ usage:
 
        case 'R':
                initsymtable(symtbl);
 
        case 'R':
                initsymtable(symtbl);
+               skipmaps();
+               skipdirs();
                createleaves(symtbl);
                createlinks();
                setdirmodes(dirmodefile);
                createleaves(symtbl);
                createlinks();
                setdirmodes(dirmodefile);
index 03f7e97..b51a116 100644 (file)
@@ -1,7 +1,7 @@
 /* Copyright (c) 1983 Regents of the University of California */
 
 #ifndef lint
 /* Copyright (c) 1983 Regents of the University of California */
 
 #ifndef lint
-static char sccsid[] = "@(#)utilities.c        3.3     (Berkeley)      83/02/27";
+static char sccsid[] = "@(#)utilities.c        3.4     (Berkeley)      83/02/28";
 #endif
 
 #include "restore.h"
 #endif
 
 #include "restore.h"
@@ -271,6 +271,26 @@ badentry(ep, msg)
        panic("flags: %s\n", &flagbuf[1]);
 }
 
        panic("flags: %s\n", &flagbuf[1]);
 }
 
+/*
+ * canonicalize file names to always start with ``./''
+ */
+canon(rawname, canonname)
+       char *rawname, *canonname;
+{
+       int len;
+
+       if (strcmp(rawname, ".") == 0 || strncmp(rawname, "./", 2) == 0)
+               strcpy(canonname, "");
+       else if (rawname[0] == '/')
+               strcpy(canonname, ".");
+       else
+               strcpy(canonname, "./");
+       strcat(canonname, rawname);
+       len = strlen(canonname) - 1;
+       if (canonname[len] == '/')
+               canonname[len] = '\0';
+}
+
 /*
  * elicit a reply
  */
 /*
  * elicit a reply
  */