change so that the command line file name is used for error/info messages
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Tue, 12 Mar 1991 06:31:22 +0000 (22:31 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Tue, 12 Mar 1991 06:31:22 +0000 (22:31 -0800)
SCCS-vsn: usr.bin/ar/append.c 5.3
SCCS-vsn: usr.bin/ar/ar.c 5.8
SCCS-vsn: usr.bin/ar/contents.c 5.4
SCCS-vsn: usr.bin/ar/delete.c 5.4
SCCS-vsn: usr.bin/ar/extract.c 5.3
SCCS-vsn: usr.bin/ar/move.c 5.4
SCCS-vsn: usr.bin/ar/print.c 5.4
SCCS-vsn: usr.bin/ar/replace.c 5.5

usr/src/usr.bin/ar/append.c
usr/src/usr.bin/ar/ar.c
usr/src/usr.bin/ar/contents.c
usr/src/usr.bin/ar/delete.c
usr/src/usr.bin/ar/extract.c
usr/src/usr.bin/ar/move.c
usr/src/usr.bin/ar/print.c
usr/src/usr.bin/ar/replace.c

index d52bfbd..bea9963 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)append.c   5.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)append.c   5.3 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -52,7 +52,7 @@ append(argv)
                        continue;
                }
                if (options & AR_V)
                        continue;
                }
                if (options & AR_V)
-                       (void)printf("q - %s\n", rname(file));
+                       (void)printf("q - %s\n", file);
                cf.rfd = fd;
                cf.rname = file;
                put_object(&cf, &sb);
                cf.rfd = fd;
                cf.rname = file;
                put_object(&cf, &sb);
index 5d6fdac..8a49071 100644 (file)
@@ -15,7 +15,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)ar.c       5.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)ar.c       5.8 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -28,7 +28,7 @@ static char sccsid[] = "@(#)ar.c      5.7 (Berkeley) %G%";
 
 CHDR chdr;
 u_int options;
 
 CHDR chdr;
 u_int options;
-char *archive, *envtmp, *posname;
+char *archive, *envtmp, *posarg, *posname;
 
 /*
  * main --
 
 /*
  * main --
@@ -141,12 +141,12 @@ main(argc, argv)
        }
        /* -ab require a position argument. */
        if (options & (AR_A|AR_B)) {
        }
        /* -ab require a position argument. */
        if (options & (AR_A|AR_B)) {
-               if (!(posname = *argv++)) {
+               if (!(posarg = *argv++)) {
                        (void)fprintf(stderr,
                            "ar: no position operand specified.\n");
                        usage();
                }
                        (void)fprintf(stderr,
                            "ar: no position operand specified.\n");
                        usage();
                }
-               posname = rname(posname);
+               posname = rname(posarg);
        }
        /* -d only valid with -sv. */
        if (options & AR_D && options & ~(AR_D|AR_S|AR_V))
        }
        /* -d only valid with -sv. */
        if (options & AR_D && options & ~(AR_D|AR_S|AR_V))
index d5e7e06..c5fbb7a 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)contents.c 5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)contents.c 5.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -37,26 +37,30 @@ contents(argv)
        register int afd, all;
        int eval;
        struct tm *tp;
        register int afd, all;
        int eval;
        struct tm *tp;
-       char buf[25];
+       char *file, buf[25];
        
        afd = open_archive(O_RDONLY);
 
        for (all = !*argv; get_header(afd);) {
        
        afd = open_archive(O_RDONLY);
 
        for (all = !*argv; get_header(afd);) {
-               if (all || files(argv)) {
-                       if (options & AR_V) {
-                               (void)strmode(chdr.mode, buf);
-                               (void)printf("%s %6d/%-6d %8ld ",
-                                   buf + 1, chdr.uid, chdr.gid, chdr.size);
-                               tp = localtime(&chdr.date);
-                               (void)strftime(buf, sizeof(buf),
-                                   "%b %e %H:%M %Y", tp);
-                               (void)printf("%s %s\n", buf, chdr.name);
-                       } else
-                               (void)printf("%s\n", chdr.name);
-                       if (!all && !*argv)
-                               break;
+               if (all)
+                       file = chdr.name;
+               else {
+                       file = *argv;
+                       if (!files(argv))
+                               goto next;
                }
                }
-               skipobj(afd);
+               if (options & AR_V) {
+                       (void)strmode(chdr.mode, buf);
+                       (void)printf("%s %6d/%-6d %8ld ",
+                           buf + 1, chdr.uid, chdr.gid, chdr.size);
+                       tp = localtime(&chdr.date);
+                       (void)strftime(buf, sizeof(buf), "%b %e %H:%M %Y", tp);
+                       (void)printf("%s %s\n", buf, file);
+               } else
+                       (void)printf("%s\n", file);
+               if (!all && !*argv)
+                       break;
+next:          skipobj(afd);
        } 
        eval = 0;
        ORPHANS;
        } 
        eval = 0;
        ORPHANS;
index b98accb..489cb0d 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)delete.c   5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)delete.c   5.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -36,6 +36,7 @@ delete(argv)
        CF cf;
        off_t size;
        int afd, eval, tfd;
        CF cf;
        off_t size;
        int afd, eval, tfd;
+       char *file;
 
        afd = open_archive(O_RDWR);
        tfd = tmp();
 
        afd = open_archive(O_RDWR);
        tfd = tmp();
@@ -43,9 +44,9 @@ delete(argv)
        /* Read and write to an archive; pad on both. */
        SETCF(afd, archive, tfd, tname, RPAD|WPAD);
        while (get_header(afd)) {
        /* Read and write to an archive; pad on both. */
        SETCF(afd, archive, tfd, tname, RPAD|WPAD);
        while (get_header(afd)) {
-               if (*argv && files(argv)) {
+               if ((file = *argv) && files(argv)) {
                        if (options & AR_V)
                        if (options & AR_V)
-                               (void)printf("d - %s\n", chdr.name);
+                               (void)printf("d - %s\n", file);
                        skipobj(afd);
                        continue;
                }
                        skipobj(afd);
                        continue;
                }
index 569e37c..7b33931 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)extract.c  5.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)extract.c  5.3 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -41,7 +41,7 @@ extract(argv)
        struct stat sb;
        CF cf;
        int eval;
        struct stat sb;
        CF cf;
        int eval;
-       char *file, *rname();
+       char *file;
 
        eval = 0;
        tv[0].tv_usec = tv[1].tv_usec = 0;
 
        eval = 0;
        tv[0].tv_usec = tv[1].tv_usec = 0;
@@ -74,7 +74,7 @@ extract(argv)
                }
 
                if (options & AR_V)
                }
 
                if (options & AR_V)
-                       (void)printf("x - %s\n", rname(file));
+                       (void)printf("x - %s\n", file);
 
                cf.wfd = tfd;
                cf.wname = file;
 
                cf.wfd = tfd;
                cf.wname = file;
index 3f5d856..a4008bc 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)move.c     5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)move.c     5.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -36,10 +36,11 @@ extern char *tname;                     /* temporary file "name" */
 move(argv)
        char **argv;
 {
 move(argv)
        char **argv;
 {
-       extern char *posname;           /* positioning file name */
+       extern char *posarg, *posname;  /* positioning file names */
        CF cf;
        off_t size, tsize;
        int afd, curfd, eval, mods, tfd1, tfd2, tfd3;
        CF cf;
        off_t size, tsize;
        int afd, curfd, eval, mods, tfd1, tfd2, tfd3;
+       char *file;
 
        afd = open_archive(O_RDWR);
        mods = options & (AR_A|AR_B);
 
        afd = open_archive(O_RDWR);
        mods = options & (AR_A|AR_B);
@@ -59,9 +60,9 @@ move(argv)
        /* Read and write to an archive; pad on both. */
        SETCF(afd, archive, 0, tname, RPAD|WPAD);
        for (curfd = tfd1; get_header(afd);) {  
        /* Read and write to an archive; pad on both. */
        SETCF(afd, archive, 0, tname, RPAD|WPAD);
        for (curfd = tfd1; get_header(afd);) {  
-               if (*argv && files(argv)) {
+               if ((file = *argv) && files(argv)) {
                        if (options & AR_V)
                        if (options & AR_V)
-                               (void)printf("m - %s\n", chdr.name);
+                               (void)printf("m - %s\n", file);
                        cf.wfd = tfd2;
                        put_object(&cf, (struct stat *)NULL);
                        continue;
                        cf.wfd = tfd2;
                        put_object(&cf, (struct stat *)NULL);
                        continue;
@@ -82,7 +83,7 @@ move(argv)
 
        if (mods) {
                (void)fprintf(stderr, "ar: %s: archive member not found.\n",
 
        if (mods) {
                (void)fprintf(stderr, "ar: %s: archive member not found.\n",
-                   posname);
+                   posarg);
                close_archive(afd);
                return(1);
        }
                close_archive(afd);
                return(1);
        }
index d4bd724..cd15b8b 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)print.c    5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)print.c    5.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -33,18 +33,24 @@ print(argv)
        CF cf;
        register int afd, all;
        int eval;
        CF cf;
        register int afd, all;
        int eval;
+       char *file;
 
        afd = open_archive(O_RDONLY);
 
        /* Read from an archive, write to stdout; pad on read. */
        SETCF(afd, archive, STDOUT_FILENO, "stdout", RPAD);
        for (all = !*argv; get_header(afd);) {
 
        afd = open_archive(O_RDONLY);
 
        /* Read from an archive, write to stdout; pad on read. */
        SETCF(afd, archive, STDOUT_FILENO, "stdout", RPAD);
        for (all = !*argv; get_header(afd);) {
-               if (!all && !files(argv)) {
-                       skipobj(afd);
-                       continue;
+               if (all)
+                       file = chdr.name;
+               else {
+                       file = *argv;
+                       if (!files(argv)) {
+                               skipobj(afd);
+                               continue;
+                       }
                }
                if (options & AR_V) {
                }
                if (options & AR_V) {
-                       (void)printf("\n<%s>\n\n", chdr.name);
+                       (void)printf("\n<%s>\n\n", file);
                        (void)fflush(stdout);
                }
                copyfile(&cf, chdr.size);
                        (void)fflush(stdout);
                }
                copyfile(&cf, chdr.size);
index 9407070..a3ace0f 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)replace.c  5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)replace.c  5.5 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -36,7 +36,7 @@ extern char *tname;                     /* temporary file "name" */
 replace(argv)
        char **argv;
 {
 replace(argv)
        char **argv;
 {
-       extern char *posname;           /* positioning file name */
+       extern char *posarg, *posname;  /* positioning file name */
        register char *file;
        register int afd, curfd, mods, sfd;
        struct stat sb;
        register char *file;
        register int afd, curfd, mods, sfd;
        struct stat sb;
@@ -82,7 +82,7 @@ replace(argv)
                                goto useold;
 
                        if (options & AR_V)
                                goto useold;
 
                        if (options & AR_V)
-                            (void)printf("r - %s\n", chdr.name);
+                            (void)printf("r - %s\n", file);
 
                        /* Read from disk, write to an archive; pad on write */
                        SETCF(sfd, file, curfd, tname, WPAD);
 
                        /* Read from disk, write to an archive; pad on write */
                        SETCF(sfd, file, curfd, tname, WPAD);
@@ -110,7 +110,7 @@ useold:                     SETCF(afd, archive, curfd, tname, RPAD|WPAD);
 
        if (mods) {
                (void)fprintf(stderr, "ar: %s: archive member not found.\n",
 
        if (mods) {
                (void)fprintf(stderr, "ar: %s: archive member not found.\n",
-                   posname);
+                   posarg);
                 close_archive(afd);
                 return(1);
         }
                 close_archive(afd);
                 return(1);
         }
@@ -118,7 +118,7 @@ useold:                     SETCF(afd, archive, curfd, tname, RPAD|WPAD);
        /* Append any left-over arguments to the end of the after file. */
 append:        while (file = *argv++) {
                if (options & AR_V)
        /* Append any left-over arguments to the end of the after file. */
 append:        while (file = *argv++) {
                if (options & AR_V)
-                       (void)printf("a - %s\n", rname(file));
+                       (void)printf("a - %s\n", file);
                if ((sfd = open(file, O_RDONLY)) < 0) {
                        err = 1;
                        (void)fprintf(stderr, "ar: %s: %s.\n",
                if ((sfd = open(file, O_RDONLY)) < 0) {
                        err = 1;
                        (void)fprintf(stderr, "ar: %s: %s.\n",