add verbose flag

This commit is contained in:
mharo 1999-08-29 08:21:16 +00:00
parent 5e14615656
commit 92582195da
2 changed files with 23 additions and 7 deletions

View File

@ -44,9 +44,11 @@
.Sh SYNOPSIS
.Nm mv
.Op Fl f | Fl i
.Op Fl v
.Ar source target
.Nm mv
.Op Fl f | Fl i
.Op Fl v
.Ar source ... directory
.Sh DESCRIPTION
In its first form, the
@ -95,6 +97,10 @@ the move is attempted.
option overrides any previous
.Fl f
options.)
.It Fl v
Cause
.Nm
to be verbose, showing files after they are moved.
.El
.Pp
It is an error for either the

View File

@ -60,11 +60,12 @@ static const char rcsid[] =
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sysexits.h>
#include <unistd.h>
#include "pathnames.h"
int fflg, iflg;
int fflg, iflg, vflg;
int copy __P((char *, char *));
int do_move __P((char *, char *));
@ -82,7 +83,7 @@ main(argc, argv)
int ch;
char path[MAXPATHLEN];
while ((ch = getopt(argc, argv, "fi")) != -1)
while ((ch = getopt(argc, argv, "fiv")) != -1)
switch (ch) {
case 'i':
iflg = 1;
@ -92,6 +93,9 @@ main(argc, argv)
fflg = 1;
iflg = 0;
break;
case 'v':
vflg = 1;
break;
default:
usage();
}
@ -188,8 +192,11 @@ do_move(from, to)
}
}
}
if (!rename(from, to))
if (!rename(from, to)) {
if (vflg)
printf("%s -> %s\n", from, to);
return (0);
}
if (errno == EXDEV) {
struct statfs sfs;
@ -299,6 +306,8 @@ err: if (unlink(to))
warn("%s: remove", from);
return (1);
}
if (vflg)
printf("%s -> %s\n", from, to);
return (0);
}
@ -309,7 +318,7 @@ copy(from, to)
int pid, status;
if ((pid = fork()) == 0) {
execl(_PATH_CP, "mv", "-PRp", from, to, NULL);
execl(_PATH_CP, "mv", vflg ? "-PRpv" : "-PRp", from, to, NULL);
warn("%s", _PATH_CP);
_exit(1);
}
@ -350,8 +359,9 @@ copy(from, to)
void
usage()
{
(void)fprintf(stderr, "%s\n%s\n",
"usage: mv [-f | -i] source target",
" mv [-f | -i] source ... directory");
exit(1);
"usage: mv [-f | -i] [-v] source target",
" mv [-f | -i] [-v] source ... directory");
exit(EX_USAGE);
}