fa.openbsd.tech
[Top] [All Lists]

Patch to add verbose mode (-v) to cp

Subject: Patch to add verbose mode (-v) to cp
From: Rodolfo Gouveia
Date: Sun, 18 Nov 2007 20:12:01 UTC
Newsgroups: fa.openbsd.tech

Taken from NetBSD's cp.


Index: cp.c
===================================================================
RCS file: /cvs/src/bin/cp/cp.c,v
retrieving revision 1.34
diff -u -r1.34 cp.c
--- cp.c        4 Nov 2007 02:01:57 -0000       1.34
+++ cp.c        18 Nov 2007 19:35:32 -0000
@@ -71,7 +71,7 @@
 PATH_T to = { to.p_path, "" };
 
 uid_t myuid;
-int Rflag, fflag, iflag, pflag, rflag;
+int Rflag, fflag, iflag, pflag, rflag, vflag;
 mode_t myumask;
 
 enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
@@ -91,7 +91,7 @@
        (void)setlocale(LC_ALL, "");
 
        Hflag = Lflag = Pflag = Rflag = 0;
-       while ((ch = getopt(argc, argv, "HLPRfipr")) != -1)
+       while ((ch = getopt(argc, argv, "HLPRfiprv")) != -1)
                switch (ch) {
                case 'H':
                        Hflag = 1;
@@ -122,6 +122,9 @@
                case 'r':
                        rflag = 1;
                        break;
+               case 'v':
+                       vflag = 1;
+                       break;
                default:
                        usage();
                        break;
@@ -440,6 +443,8 @@
                                rval = 1;
                        break;
                }
+               if (vflag)
+                       (void)printf("%s ->  %s\n", curr->fts_path, to.p_path);
        }
        if (errno)
                err(1, "fts_read");

Index: cp.1
===================================================================
RCS file: /cvs/src/bin/cp/cp.1,v
retrieving revision 1.29
diff -u -r1.29 cp.1
--- cp.1        16 Sep 2007 18:13:57 -0000      1.29
+++ cp.1        18 Nov 2007 19:35:25 -0000
@@ -44,14 +44,14 @@
 .Op Fl fip
 .Oo
 .Fl R
-.Op Fl H | L | P
+.Op Fl H | L | P | v
 .Oc
 .Ar source target
 .Nm cp
 .Op Fl fip
 .Oo
 .Fl R
-.Op Fl H | L | P
+.Op Fl H | L | P | v
 .Oc
 .Ar source ... directory
 .Sh DESCRIPTION
@@ -137,6 +137,8 @@
 or
 .Xr tar 1
 instead.
+.It Fl v
+Verbose mode that shows files as they are copied.
 .El
 .Pp
 For each destination file that already exists, its contents are

Index: utils.c
===================================================================
RCS file: /cvs/src/bin/cp/utils.c,v
retrieving revision 1.29
diff -u -r1.29 utils.c
--- utils.c     22 Sep 2007 21:10:49 -0000      1.29
+++ utils.c     18 Nov 2007 19:53:55 -0000
@@ -324,9 +324,9 @@
 usage(void)
 {
        (void)fprintf(stderr,
-           "usage: %s [-fip] [-R [-H | -L | -P]] source target\n", __progname);
+           "usage: %s [-fip] [-R [-H | -L | -P | -v]] source target\n", 
__progname);
        (void)fprintf(stderr,
-           "       %s [-fip] [-R [-H | -L | -P]] source ... directory\n",
+           "       %s [-fip] [-R [-H | -L | -P | -v]] source ... directory\n",
            __progname);
        exit(1);
 }


<Prev in Thread] Current Thread [Next in Thread>
  • Patch to add verbose mode (-v) to cp, Rodolfo Gouveia <=