[hackers] [sbase] cp: add -v, fix manpage info || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Mon, 21 Jul 2014 17:43:37 +0200

commit f67320ce937c21b85b4e0bfb1ee4c3e21e9801fb
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Thu Jul 10 20:30:30 2014 +0000

    cp: add -v, fix manpage info
    
    Signed-off-by: Hiltjo Posthuma <hiltjo_AT_codemadness.org>

diff --git a/cp.1 b/cp.1
index 85eb47b..f0f5b65 100644
--- a/cp.1
+++ b/cp.1
_AT_@ -8,7 +8,7 @@ cp \- copy files and directories
 .RI [ name ]
 .P
 .B cp
-.RB [ \-adpRr ]
+.RB [ \-adpRrv ]
 .RI [ file ...]
 .RI [ directory ]
 .SH DESCRIPTION
_AT_@ -25,7 +25,7 @@ Implies \-d, \-p, \-r.
 don't dereference links. preserve links.
 .TP
 .B \-p
-preserve mode, timestamp, links and permissions.
+preserve mode, timestamp and permissions.
 .TP
 .B \-f
 if an existing destination file cannot be opened, remove it and try again.
_AT_@ -36,3 +36,7 @@ equivalent to -r.
 .B \-r
 copies directories recursively. If this flag is not specified, directories are
 not copied.
+.TP
+.B \-v
+print names of source and destination per file to stdout. In the format:
+"source \-> destination".
diff --git a/cp.c b/cp.c
index 9e3ded3..62f4593 100644
--- a/cp.c
+++ b/cp.c
_AT_@ -8,7 +8,7 @@
 static void
 usage(void)
 {
- eprintf("usage: %s [-adfpRr] source... dest
", argv0);
+ eprintf("usage: %s [-adfpRrv] source... dest
", argv0);
 }
 
 int
_AT_@ -36,6 +36,9 @@ main(int argc, char *argv[])
         case 'r':
                 cp_rflag = true;
                 break;
+ case 'v':
+ cp_vflag = true;
+ break;
         default:
                 usage();
         } ARGEND;
diff --git a/fs.h b/fs.h
index 3d9c795..cb66856 100644
--- a/fs.h
+++ b/fs.h
_AT_@ -6,6 +6,7 @@ extern bool cp_dflag;
 extern bool cp_fflag;
 extern bool cp_pflag;
 extern bool cp_rflag;
+extern bool cp_vflag;
 
 extern bool rm_fflag;
 extern bool rm_rflag;
diff --git a/util/apathmax.c b/util/apathmax.c
index 5dc831f..109f0ac 100644
--- a/util/apathmax.c
+++ b/util/apathmax.c
_AT_@ -22,4 +22,3 @@ apathmax(char **p, long *size)
         if(!(*p = malloc(*size)))
                 eprintf("malloc:");
 }
-
diff --git a/util/cp.c b/util/cp.c
index ebad41a..c50a81c 100644
--- a/util/cp.c
+++ b/util/cp.c
_AT_@ -20,6 +20,7 @@ bool cp_dflag = false;
 bool cp_fflag = false;
 bool cp_pflag = false;
 bool cp_rflag = false;
+bool cp_vflag = false;
 
 int
 cp(const char *s1, const char *s2)
_AT_@ -39,6 +40,9 @@ cp(const char *s1, const char *s2)
         else
                 r = stat(s1, &st);
 
+ if(cp_vflag)
+ printf("'%s' -> '%s'
", s1, s2);
+
         if(r == 0) {
                 if(cp_dflag == true && S_ISLNK(st.st_mode)) {
                         if(cp_fflag == true)
_AT_@ -86,7 +90,6 @@ cp(const char *s1, const char *s2)
                         free(ns1);
                         free(ns2);
                         goto preserve;
- return 0;
                 }
         }
         if(!(f1 = fopen(s1, "r")))
Received on Mon Jul 21 2014 - 17:43:37 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 17:48:18 CEST