Add a -v (verbose) option.

This commit is contained in:
des 2004-03-21 04:56:06 +00:00
parent 854f282025
commit 88d86ea2c1
2 changed files with 26 additions and 13 deletions

View File

@ -35,7 +35,7 @@
.\" @(#)rmdir.1 8.1 (Berkeley) 5/31/93
.\" $FreeBSD$
.\"
.Dd May 31, 1993
.Dd March 21, 2004
.Dt RMDIR 1
.Os
.Sh NAME
@ -43,7 +43,7 @@
.Nd remove directories
.Sh SYNOPSIS
.Nm
.Op Fl p
.Op Fl pv
.Ar directory ...
.Sh DESCRIPTION
The
@ -72,6 +72,8 @@ starting with the last most component.
(See
.Xr rm 1
for fully non-discriminant recursive removal.)
.It Fl v
Be verbose, listing each directory as it is removed.
.El
.Pp
The

View File

@ -52,21 +52,25 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include <unistd.h>
int rm_path(char *);
void usage(void);
static int rm_path(char *);
static void usage(void);
static int pflag;
static int vflag;
int
main(int argc, char *argv[])
{
int ch, errors;
int pflag;
pflag = 0;
while ((ch = getopt(argc, argv, "p")) != -1)
while ((ch = getopt(argc, argv, "pv")) != -1)
switch(ch) {
case 'p':
pflag = 1;
break;
case 'v':
vflag = 1;
break;
case '?':
default:
usage();
@ -78,17 +82,22 @@ main(int argc, char *argv[])
usage();
for (errors = 0; *argv; argv++) {
if (rmdir(*argv) < 0) {
warn("%s", *argv);
errors = 1;
} else if (pflag)
if (pflag) {
errors |= rm_path(*argv);
} else {
if (rmdir(*argv) < 0) {
warn("%s", *argv);
errors = 1;
}
if (vflag)
printf("%s\n", *argv);
}
}
exit(errors);
}
int
static int
rm_path(char *path)
{
char *p;
@ -107,12 +116,14 @@ rm_path(char *path)
warn("%s", path);
return (1);
}
if (vflag)
printf("%s\n", path);
}
return (0);
}
void
static void
usage(void)
{