cp: add -v, fix manpage info

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
This commit is contained in:
Hiltjo Posthuma 2014-07-10 20:30:30 +00:00 committed by sin
parent ac402965d5
commit f67320ce93
5 changed files with 15 additions and 5 deletions

8
cp.1
View File

@ -8,7 +8,7 @@ cp \- copy files and directories
.RI [ name ] .RI [ name ]
.P .P
.B cp .B cp
.RB [ \-adpRr ] .RB [ \-adpRrv ]
.RI [ file ...] .RI [ file ...]
.RI [ directory ] .RI [ directory ]
.SH DESCRIPTION .SH DESCRIPTION
@ -25,7 +25,7 @@ Implies \-d, \-p, \-r.
don't dereference links. preserve links. don't dereference links. preserve links.
.TP .TP
.B \-p .B \-p
preserve mode, timestamp, links and permissions. preserve mode, timestamp and permissions.
.TP .TP
.B \-f .B \-f
if an existing destination file cannot be opened, remove it and try again. if an existing destination file cannot be opened, remove it and try again.
@ -36,3 +36,7 @@ equivalent to -r.
.B \-r .B \-r
copies directories recursively. If this flag is not specified, directories are copies directories recursively. If this flag is not specified, directories are
not copied. not copied.
.TP
.B \-v
print names of source and destination per file to stdout. In the format:
"source \-> destination".

5
cp.c
View File

@ -8,7 +8,7 @@
static void static void
usage(void) usage(void)
{ {
eprintf("usage: %s [-adfpRr] source... dest\n", argv0); eprintf("usage: %s [-adfpRrv] source... dest\n", argv0);
} }
int int
@ -36,6 +36,9 @@ main(int argc, char *argv[])
case 'r': case 'r':
cp_rflag = true; cp_rflag = true;
break; break;
case 'v':
cp_vflag = true;
break;
default: default:
usage(); usage();
} ARGEND; } ARGEND;

1
fs.h
View File

@ -6,6 +6,7 @@ extern bool cp_dflag;
extern bool cp_fflag; extern bool cp_fflag;
extern bool cp_pflag; extern bool cp_pflag;
extern bool cp_rflag; extern bool cp_rflag;
extern bool cp_vflag;
extern bool rm_fflag; extern bool rm_fflag;
extern bool rm_rflag; extern bool rm_rflag;

View File

@ -22,4 +22,3 @@ apathmax(char **p, long *size)
if(!(*p = malloc(*size))) if(!(*p = malloc(*size)))
eprintf("malloc:"); eprintf("malloc:");
} }

View File

@ -20,6 +20,7 @@ bool cp_dflag = false;
bool cp_fflag = false; bool cp_fflag = false;
bool cp_pflag = false; bool cp_pflag = false;
bool cp_rflag = false; bool cp_rflag = false;
bool cp_vflag = false;
int int
cp(const char *s1, const char *s2) cp(const char *s1, const char *s2)
@ -39,6 +40,9 @@ cp(const char *s1, const char *s2)
else else
r = stat(s1, &st); r = stat(s1, &st);
if(cp_vflag)
printf("'%s' -> '%s'\n", s1, s2);
if(r == 0) { if(r == 0) {
if(cp_dflag == true && S_ISLNK(st.st_mode)) { if(cp_dflag == true && S_ISLNK(st.st_mode)) {
if(cp_fflag == true) if(cp_fflag == true)
@ -86,7 +90,6 @@ cp(const char *s1, const char *s2)
free(ns1); free(ns1);
free(ns2); free(ns2);
goto preserve; goto preserve;
return 0;
} }
} }
if(!(f1 = fopen(s1, "r"))) if(!(f1 = fopen(s1, "r")))