Add support for "-flags [-]flags", which matches the file flags in a

similar way that "-perm [-]mode" matches the file mode.
This commit is contained in:
lukem 1999-01-03 14:54:27 +00:00
parent 2ebc95cb82
commit adfde6fdc9
6 changed files with 94 additions and 13 deletions

View File

@ -1,7 +1,10 @@
# $NetBSD: Makefile,v 1.7 1998/02/21 22:47:20 christos Exp $
# $NetBSD: Makefile,v 1.8 1999/01/03 14:54:27 lukem Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= find
SRCS= find.c function.c ls.c main.c misc.c operator.c option.c
SRCS= find.c function.c ls.c main.c misc.c operator.c option.c stat_flags.c
CPPFLAGS+= -I${.CURDIR}/../../bin/ls
.PATH: ${.CURDIR}/../../bin/ls
.include <bsd.prog.mk>

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.8 1998/02/21 22:47:20 christos Exp $ */
/* $NetBSD: extern.h,v 1.9 1999/01/03 14:54:28 lukem Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@ -54,6 +54,7 @@ PLAN *c_atime __P((char ***, int));
PLAN *c_ctime __P((char ***, int));
PLAN *c_depth __P((char ***, int));
PLAN *c_exec __P((char ***, int));
PLAN *c_flags __P((char ***, int));
PLAN *c_follow __P((char ***, int));
PLAN *c_fstype __P((char ***, int));
PLAN *c_group __P((char ***, int));

View File

@ -1,4 +1,4 @@
.\" $NetBSD: find.1,v 1.15 1999/01/03 14:11:54 lukem Exp $
.\" $NetBSD: find.1,v 1.16 1999/01/03 14:54:28 lukem Exp $
.\"
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@ -36,7 +36,7 @@
.\"
.\" from: @(#)find.1 8.7 (Berkeley) 5/9/95
.\"
.Dd May 9, 1995
.Dd January 4, 1999
.Dt FIND 1
.Os
.Sh NAME
@ -165,6 +165,31 @@ arguments it is replaced by the pathname of the current file.
will be executed from the directory from which
.Nm
was executed.
.It Xo
.Ic -flags
.Op Fl
.Ns Ar flags
.Xc
If
.Ar flags
are preceded by a dash (``\-''), this primary evaluates to true
if at least all of the bits in
.Ar flags
are set in the file's flags bits.
If
.Ar flags
are not preceded by a dash, this primary evaluates to true if
the bits in
.Ar flags
exactly match the file's flags bits.
If
.Ar flags
is
.Dq none ,
files with no flags bits set are matched.
(See
.Xr chflags 1
for more information about file flags.)
.It Ic -follow
Follow symbolic links.
.It Ic -fstype Ar type
@ -416,6 +441,7 @@ Print out a list of all the files that are either owned by ``wnj'' or
that are newer than ``ttt''.
.El
.Sh SEE ALSO
.Xr chflags 1 ,
.Xr chmod 1 ,
.Xr locate 1 ,
.Xr stat 2 ,

View File

@ -1,4 +1,4 @@
/* $NetBSD: find.h,v 1.8 1998/02/21 22:47:20 christos Exp $ */
/* $NetBSD: find.h,v 1.9 1999/01/03 14:54:28 lukem Exp $ */
/*-
* Copyright (c) 1990, 1993
@ -41,9 +41,9 @@
/* node type */
enum ntype {
N_AND = 1, /* must start > 0 */
N_ATIME, N_CLOSEPAREN, N_CTIME, N_DEPTH, N_EXEC, N_EXPR, N_FOLLOW,
N_FSTYPE, N_GROUP, N_INUM, N_LINKS, N_LS, N_MTIME, N_NAME, N_NEWER,
N_NOGROUP, N_NOT, N_NOUSER, N_OK, N_OPENPAREN, N_OR, N_PATH,
N_ATIME, N_CLOSEPAREN, N_CTIME, N_DEPTH, N_EXEC, N_EXPR, N_FLAGS,
N_FOLLOW, N_FSTYPE, N_GROUP, N_INUM, N_LINKS, N_LS, N_MTIME, N_NAME,
N_NEWER, N_NOGROUP, N_NOT, N_NOUSER, N_OK, N_OPENPAREN, N_OR, N_PATH,
N_PERM, N_PRINT, N_PRINT0, N_PRUNE, N_SIZE, N_TYPE, N_USER, N_XDEV,
};
@ -62,6 +62,7 @@ typedef struct _plandata {
int flags; /* private flags */
enum ntype type; /* plan node type */
union {
u_int32_t _f_data; /* flags */
gid_t _g_data; /* gid */
ino_t _i_data; /* inode */
mode_t _m_data; /* mode mask */
@ -83,6 +84,7 @@ typedef struct _plandata {
#define a_data p_un._a_data
#define c_data p_un._c_data
#define i_data p_un._i_data
#define f_data p_un._f_data
#define g_data p_un._g_data
#define l_data p_un._l_data
#define m_data p_un._m_data

View File

@ -1,4 +1,4 @@
/* $NetBSD: function.c,v 1.26 1998/11/06 23:21:01 christos Exp $ */
/* $NetBSD: function.c,v 1.27 1999/01/03 14:54:28 lukem Exp $ */
/*-
* Copyright (c) 1990, 1993
@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "from: @(#)function.c 8.10 (Berkeley) 5/4/95";
#else
__RCSID("$NetBSD: function.c,v 1.26 1998/11/06 23:21:01 christos Exp $");
__RCSID("$NetBSD: function.c,v 1.27 1999/01/03 14:54:28 lukem Exp $");
#endif
#endif /* not lint */
@ -63,6 +63,7 @@ __RCSID("$NetBSD: function.c,v 1.26 1998/11/06 23:21:01 christos Exp $");
#include <unistd.h>
#include "find.h"
#include "stat_flags.h"
#define COMPARE(a, b) { \
switch (plan->flags) { \
@ -82,6 +83,7 @@ static long find_parsenum __P((PLAN *, char *, char *, char *));
int f_atime __P((PLAN *, FTSENT *));
int f_ctime __P((PLAN *, FTSENT *));
int f_exec __P((PLAN *, FTSENT *));
int f_flags __P((PLAN *, FTSENT *));
int f_fstype __P((PLAN *, FTSENT *));
int f_group __P((PLAN *, FTSENT *));
int f_inum __P((PLAN *, FTSENT *));
@ -354,6 +356,52 @@ c_exec(argvp, isok)
return (new);
}
/*
* -flags [-]flags functions --
*/
int
f_flags(plan, entry)
PLAN *plan;
FTSENT *entry;
{
u_int32_t flags;
flags = entry->fts_statp->st_flags;
if (plan->flags == F_ATLEAST)
return ((plan->f_data | flags) == flags);
else
return (flags == plan->f_data);
/* NOTREACHED */
}
PLAN *
c_flags(argvp, isok)
char ***argvp;
int isok;
{
char *flags = **argvp;
PLAN *new;
u_long flagset;
(*argvp)++;
ftsoptions &= ~FTS_NOSTAT;
new = palloc(N_FLAGS, f_flags);
if (*flags == '-') {
new->flags = F_ATLEAST;
++flags;
}
flagset = 0;
if ((strcmp(flags, "none") != 0) &&
(string_to_flags(&flags, &flagset, NULL) != 0))
errx(1, "-flags: %s: illegal flags string", flags);
new->f_data = flagset;
return (new);
}
/*
* -follow functions --
*

View File

@ -1,4 +1,4 @@
/* $NetBSD: option.c,v 1.9 1998/02/21 22:47:21 christos Exp $ */
/* $NetBSD: option.c,v 1.10 1999/01/03 14:54:28 lukem Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "from: @(#)option.c 8.2 (Berkeley) 4/16/94";
#else
__RCSID("$NetBSD: option.c,v 1.9 1998/02/21 22:47:21 christos Exp $");
__RCSID("$NetBSD: option.c,v 1.10 1999/01/03 14:54:28 lukem Exp $");
#endif
#endif /* not lint */
@ -70,6 +70,7 @@ static OPTION const options[] = {
{ "-ctime", N_CTIME, c_ctime, 1 },
{ "-depth", N_DEPTH, c_depth, 0 },
{ "-exec", N_EXEC, c_exec, 1 },
{ "-flags", N_FLAGS, c_flags, 1 },
{ "-follow", N_FOLLOW, c_follow, 0 },
{ "-fstype", N_FSTYPE, c_fstype, 1 },
{ "-group", N_GROUP, c_group, 1 },