Second part of bin/3648: add -flags to search for specific flags.
I added $FreeBSD$ whicle I was here. The patch wasn't usable anymore due to its age so I adapted it. PR: bin/3648 Submitted by: Martin Birgmeier <mbirg@austria.ds.philips.com>
This commit is contained in:
parent
27d5775d8c
commit
567664c4a7
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=54828
@ -1,6 +1,8 @@
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||
# $FreeBSD$
|
||||
|
||||
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
|
||||
.PATH: ${.CURDIR}/../../bin/ls
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
@ -31,6 +31,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)extern.h 8.3 (Berkeley) 4/16/94
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
@ -54,6 +55,7 @@ PLAN *c_ctime __P((char *));
|
||||
PLAN *c_delete __P((void));
|
||||
PLAN *c_depth __P((void));
|
||||
PLAN *c_exec __P((char ***, int));
|
||||
PLAN *c_flags __P((char *));
|
||||
PLAN *c_execdir __P((char ***));
|
||||
PLAN *c_follow __P((void));
|
||||
#if !defined(__NetBSD__)
|
||||
|
@ -327,6 +327,19 @@ if at least all of the bits in the mode are set in the file's mode bits.
|
||||
If the mode is not preceded by a dash, this primary evaluates to true if
|
||||
the bits in the mode exactly match the file's mode bits.
|
||||
Note, the first character of a symbolic mode may not be a dash (``\-'').
|
||||
.It Ic -flags Op Fl Ns Ar flags
|
||||
This primary evaluates to true if exactly those flags of the file are
|
||||
set which are also set using the specified
|
||||
.Ar flags
|
||||
(if these are not preceded by a dash (``\-''),
|
||||
or if they match the specified flags (if these are preceded by a dash).
|
||||
The
|
||||
.Ar flags
|
||||
are specified using symbolic names (see
|
||||
.Xr chflags 1 ).
|
||||
Note that this is different from
|
||||
.Ic -perm ,
|
||||
which only allows you to specify flags which are set.
|
||||
.It Ic -print
|
||||
This primary always evaluates to true.
|
||||
It prints the pathname of the current file to standard output.
|
||||
@ -458,6 +471,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 whereis 1 ,
|
||||
|
@ -34,13 +34,14 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)find.h 8.1 (Berkeley) 6/6/93
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/* node type */
|
||||
enum ntype {
|
||||
N_AND = 1, /* must start > 0 */
|
||||
N_AMIN, N_ATIME, N_CLOSEPAREN, N_CMIN, N_CTIME, N_DEPTH,
|
||||
N_EXEC, N_EXECDIR, N_EXPR,
|
||||
N_EXEC, N_EXECDIR, N_EXPR, N_FLAGS,
|
||||
N_FOLLOW, N_FSTYPE, N_GROUP, N_INUM, N_LINKS, N_LS, N_MMIN,
|
||||
N_MTIME, N_NAME,
|
||||
N_NEWER, N_NOGROUP, N_NOT, N_NOUSER, N_OK, N_OPENPAREN, N_OR, N_PATH,
|
||||
@ -66,6 +67,10 @@ typedef struct _plandata {
|
||||
gid_t _g_data; /* gid */
|
||||
ino_t _i_data; /* inode */
|
||||
mode_t _m_data; /* mode mask */
|
||||
struct {
|
||||
u_long _f_flags;
|
||||
u_long _f_mask;
|
||||
} fl;
|
||||
nlink_t _l_data; /* link count */
|
||||
off_t _o_data; /* file size */
|
||||
time_t _t_data; /* time value */
|
||||
@ -83,8 +88,10 @@ typedef struct _plandata {
|
||||
} PLAN;
|
||||
#define a_data p_un._a_data
|
||||
#define c_data p_un._c_data
|
||||
#define i_data p_un._i_data
|
||||
#define fl_flags p_un.fl._f_flags
|
||||
#define fl_mask p_un.fl._f_mask
|
||||
#define g_data p_un._g_data
|
||||
#define i_data p_un._i_data
|
||||
#define l_data p_un._l_data
|
||||
#define m_data p_un._m_data
|
||||
#define mt_data p_un._mt_data
|
||||
|
@ -36,6 +36,7 @@
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)function.c 8.10 (Berkeley) 5/4/95";
|
||||
static char rcsid[] = "$FreeBSD$";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -57,6 +58,8 @@ static char sccsid[] = "@(#)function.c 8.10 (Berkeley) 5/4/95";
|
||||
|
||||
#include "find.h"
|
||||
|
||||
int string_to_flags __P((char **, u_long *, u_long *));
|
||||
|
||||
#define COMPARE(a, b) { \
|
||||
switch (plan->flags) { \
|
||||
case F_EQUAL: \
|
||||
@ -945,13 +948,67 @@ c_perm(perm)
|
||||
}
|
||||
|
||||
if ((set = setmode(perm)) == NULL)
|
||||
err(1, "-perm: %s: illegal mode string", perm);
|
||||
errx(1, "-perm: %s: illegal mode string", perm);
|
||||
|
||||
new->m_data = getmode(set, 0);
|
||||
free(set);
|
||||
return (new);
|
||||
}
|
||||
|
||||
/*
|
||||
* -flags functions --
|
||||
*
|
||||
* The flags argument is used to represent file flags bits.
|
||||
*/
|
||||
int
|
||||
f_flags(plan, entry)
|
||||
PLAN *plan;
|
||||
FTSENT *entry;
|
||||
{
|
||||
u_long flags;
|
||||
|
||||
flags = entry->fts_statp->st_flags &
|
||||
(UF_NODUMP | UF_IMMUTABLE | UF_APPEND | UF_OPAQUE |
|
||||
SF_ARCHIVED | SF_IMMUTABLE | SF_APPEND);
|
||||
if (plan->flags == F_ATLEAST)
|
||||
/* note that plan->fl_flags always is a subset of
|
||||
plan->fl_mask */
|
||||
return (flags & plan->fl_mask) == plan->fl_flags;
|
||||
else
|
||||
return flags == plan->fl_flags;
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
PLAN *
|
||||
c_flags(flags_str)
|
||||
char *flags_str;
|
||||
{
|
||||
PLAN *new;
|
||||
u_long flags, notflags;
|
||||
|
||||
ftsoptions &= ~FTS_NOSTAT;
|
||||
|
||||
new = palloc(N_FLAGS, f_flags);
|
||||
|
||||
if (*flags_str == '-') {
|
||||
new->flags = F_ATLEAST;
|
||||
flags_str++;
|
||||
}
|
||||
if (string_to_flags(&flags_str, &flags, ¬flags) == 1)
|
||||
errx(1, "-flags: %s: illegal flags string", flags_str);
|
||||
|
||||
new->fl_flags = flags;
|
||||
new->fl_mask = flags | notflags;
|
||||
#if 0
|
||||
printf("flags = %08x, mask = %08x (%08x, %08x)\n",
|
||||
new->fl_flags, new->fl_mask, flags, notflags);
|
||||
#endif
|
||||
return new;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
|
||||
/*
|
||||
* -print functions --
|
||||
*
|
||||
|
@ -70,6 +70,7 @@ static OPTION const options[] = {
|
||||
{ "-depth", N_DEPTH, c_depth, O_ZERO },
|
||||
{ "-exec", N_EXEC, c_exec, O_ARGVP },
|
||||
{ "-execdir", N_EXECDIR, c_execdir, O_ARGVP },
|
||||
{ "-flags", N_FLAGS, c_flags, O_ARGV },
|
||||
{ "-follow", N_FOLLOW, c_follow, O_ZERO },
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user