1999-02-04 19:41:17 +03:00
|
|
|
/* $NetBSD: function.c,v 1.30 1999/02/04 16:41:17 kleink Exp $ */
|
1997-01-09 23:18:21 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*-
|
1993-12-31 00:15:18 +03:00
|
|
|
* Copyright (c) 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Cimarron D. Taylor of the University of California, Berkeley.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-10-19 15:52:12 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1997-10-19 15:52:12 +04:00
|
|
|
#if 0
|
1998-02-02 17:02:06 +03:00
|
|
|
static char sccsid[] = "from: @(#)function.c 8.10 (Berkeley) 5/4/95";
|
1997-10-19 15:52:12 +04:00
|
|
|
#else
|
1999-02-04 19:41:17 +03:00
|
|
|
__RCSID("$NetBSD: function.c,v 1.30 1999/02/04 16:41:17 kleink Exp $");
|
1997-10-19 15:52:12 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/mount.h>
|
1993-12-31 00:15:18 +03:00
|
|
|
|
|
|
|
#include <err.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <errno.h>
|
1993-12-31 00:15:18 +03:00
|
|
|
#include <fnmatch.h>
|
|
|
|
#include <fts.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <grp.h>
|
1999-02-04 19:41:17 +03:00
|
|
|
#include <inttypes.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <pwd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1993-12-31 00:15:18 +03:00
|
|
|
#include <tzfile.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "find.h"
|
1999-01-03 17:54:27 +03:00
|
|
|
#include "stat_flags.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-12-31 00:15:18 +03:00
|
|
|
#define COMPARE(a, b) { \
|
|
|
|
switch (plan->flags) { \
|
|
|
|
case F_EQUAL: \
|
|
|
|
return (a == b); \
|
|
|
|
case F_LESSTHAN: \
|
|
|
|
return (a < b); \
|
|
|
|
case F_GREATER: \
|
|
|
|
return (a > b); \
|
|
|
|
default: \
|
|
|
|
abort(); \
|
|
|
|
} \
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1999-02-04 19:41:17 +03:00
|
|
|
static int64_t find_parsenum __P((PLAN *, char *, char *, char *));
|
1997-10-19 15:52:12 +04:00
|
|
|
int f_always_true __P((PLAN *, FTSENT *));
|
1999-01-16 16:27:30 +03:00
|
|
|
int f_amin __P((PLAN *, FTSENT *));
|
1997-10-19 15:52:12 +04:00
|
|
|
int f_atime __P((PLAN *, FTSENT *));
|
1999-01-16 16:27:30 +03:00
|
|
|
int f_cmin __P((PLAN *, FTSENT *));
|
1997-10-19 15:52:12 +04:00
|
|
|
int f_ctime __P((PLAN *, FTSENT *));
|
|
|
|
int f_exec __P((PLAN *, FTSENT *));
|
1999-01-03 17:54:27 +03:00
|
|
|
int f_flags __P((PLAN *, FTSENT *));
|
1997-10-19 15:52:12 +04:00
|
|
|
int f_fstype __P((PLAN *, FTSENT *));
|
|
|
|
int f_group __P((PLAN *, FTSENT *));
|
|
|
|
int f_inum __P((PLAN *, FTSENT *));
|
|
|
|
int f_links __P((PLAN *, FTSENT *));
|
|
|
|
int f_ls __P((PLAN *, FTSENT *));
|
1999-01-16 16:27:30 +03:00
|
|
|
int f_mmin __P((PLAN *, FTSENT *));
|
1997-10-19 15:52:12 +04:00
|
|
|
int f_mtime __P((PLAN *, FTSENT *));
|
|
|
|
int f_name __P((PLAN *, FTSENT *));
|
|
|
|
int f_newer __P((PLAN *, FTSENT *));
|
|
|
|
int f_nogroup __P((PLAN *, FTSENT *));
|
|
|
|
int f_nouser __P((PLAN *, FTSENT *));
|
|
|
|
int f_path __P((PLAN *, FTSENT *));
|
|
|
|
int f_perm __P((PLAN *, FTSENT *));
|
|
|
|
int f_print __P((PLAN *, FTSENT *));
|
|
|
|
int f_print0 __P((PLAN *, FTSENT *));
|
1999-01-12 03:18:50 +03:00
|
|
|
int f_printx __P((PLAN *, FTSENT *));
|
1997-10-19 15:52:12 +04:00
|
|
|
int f_prune __P((PLAN *, FTSENT *));
|
|
|
|
int f_size __P((PLAN *, FTSENT *));
|
|
|
|
int f_type __P((PLAN *, FTSENT *));
|
|
|
|
int f_user __P((PLAN *, FTSENT *));
|
|
|
|
int f_not __P((PLAN *, FTSENT *));
|
|
|
|
int f_or __P((PLAN *, FTSENT *));
|
|
|
|
static PLAN *palloc __P((enum ntype, int (*) __P((PLAN *, FTSENT *))));
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* find_parsenum --
|
|
|
|
* Parse a string of the form [+-]# and return the value.
|
|
|
|
*/
|
1999-02-04 19:41:17 +03:00
|
|
|
static int64_t
|
1993-12-31 00:15:18 +03:00
|
|
|
find_parsenum(plan, option, vp, endch)
|
1993-03-21 12:45:37 +03:00
|
|
|
PLAN *plan;
|
1993-12-31 00:15:18 +03:00
|
|
|
char *option, *vp, *endch;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1999-02-04 19:41:17 +03:00
|
|
|
int64_t value;
|
1993-12-31 00:15:18 +03:00
|
|
|
char *endchar, *str; /* Pointer to character ending conversion. */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-12-31 00:15:18 +03:00
|
|
|
/* Determine comparison from leading + or -. */
|
|
|
|
str = vp;
|
|
|
|
switch (*str) {
|
1993-03-21 12:45:37 +03:00
|
|
|
case '+':
|
|
|
|
++str;
|
1993-12-31 00:15:18 +03:00
|
|
|
plan->flags = F_GREATER;
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
++str;
|
1993-12-31 00:15:18 +03:00
|
|
|
plan->flags = F_LESSTHAN;
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
default:
|
1993-12-31 00:15:18 +03:00
|
|
|
plan->flags = F_EQUAL;
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1993-12-31 00:15:18 +03:00
|
|
|
* Convert the string with strtol(). Note, if strtol() returns zero
|
1993-03-21 12:45:37 +03:00
|
|
|
* and endchar points to the beginning of the string we know we have
|
|
|
|
* a syntax error.
|
|
|
|
*/
|
1999-02-04 19:41:17 +03:00
|
|
|
value = strtoq(str, &endchar, 10);
|
1993-12-31 00:15:18 +03:00
|
|
|
if (value == 0 && endchar == str)
|
|
|
|
errx(1, "%s: %s: illegal numeric value", option, vp);
|
|
|
|
if (endchar[0] && (endch == NULL || endchar[0] != *endch))
|
|
|
|
errx(1, "%s: %s: illegal trailing character", option, vp);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (endch)
|
|
|
|
*endch = endchar[0];
|
1993-12-31 00:15:18 +03:00
|
|
|
return (value);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1993-12-31 00:15:18 +03:00
|
|
|
/*
|
|
|
|
* The value of n for the inode times (atime, ctime, and mtime) is a range,
|
|
|
|
* i.e. n matches from (n - 1) to n 24 hour periods. This interacts with
|
|
|
|
* -n, such that "-mtime -1" would be less than 0 days, which isn't what the
|
|
|
|
* user wanted. Correct so that -1 is "less than 1".
|
|
|
|
*/
|
|
|
|
#define TIME_CORRECT(p, ttype) \
|
|
|
|
if ((p)->type == ttype && (p)->flags == F_LESSTHAN) \
|
|
|
|
++((p)->t_data);
|
|
|
|
|
1999-01-16 16:27:30 +03:00
|
|
|
/*
|
|
|
|
* -amin n functions --
|
|
|
|
*
|
|
|
|
* True if the difference between the file access time and the
|
|
|
|
* current time is n 1 minute periods.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
f_amin(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
|
|
|
extern time_t now;
|
|
|
|
|
|
|
|
COMPARE((now - entry->fts_statp->st_atime +
|
|
|
|
SECSPERMIN - 1) / SECSPERMIN, plan->t_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
|
|
|
c_amin(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
|
|
|
{
|
|
|
|
char *arg = **argvp;
|
|
|
|
PLAN *new;
|
|
|
|
|
|
|
|
(*argvp)++;
|
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
|
|
|
new = palloc(N_AMIN, f_amin);
|
|
|
|
new->t_data = find_parsenum(new, "-amin", arg, NULL);
|
|
|
|
TIME_CORRECT(new, N_AMIN);
|
|
|
|
return (new);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* -atime n functions --
|
|
|
|
*
|
|
|
|
* True if the difference between the file access time and the
|
|
|
|
* current time is n 24 hour periods.
|
|
|
|
*/
|
1993-12-31 00:15:18 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
f_atime(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
|
|
|
extern time_t now;
|
|
|
|
|
1993-08-06 05:53:33 +04:00
|
|
|
COMPARE((now - entry->fts_statp->st_atime +
|
1993-03-21 12:45:37 +03:00
|
|
|
SECSPERDAY - 1) / SECSPERDAY, plan->t_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_atime(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1998-02-22 01:47:20 +03:00
|
|
|
char *arg = **argvp;
|
1993-03-21 12:45:37 +03:00
|
|
|
PLAN *new;
|
|
|
|
|
1998-02-22 01:47:20 +03:00
|
|
|
(*argvp)++;
|
1993-03-21 12:45:37 +03:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
|
|
|
new = palloc(N_ATIME, f_atime);
|
|
|
|
new->t_data = find_parsenum(new, "-atime", arg, NULL);
|
1993-12-31 00:15:18 +03:00
|
|
|
TIME_CORRECT(new, N_ATIME);
|
|
|
|
return (new);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1999-01-16 16:27:30 +03:00
|
|
|
/*
|
|
|
|
* -cmin n functions --
|
|
|
|
*
|
|
|
|
* True if the difference between the last change of file
|
|
|
|
* status information and the current time is n 24 hour periods.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
f_cmin(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
|
|
|
extern time_t now;
|
|
|
|
|
|
|
|
COMPARE((now - entry->fts_statp->st_ctime +
|
|
|
|
SECSPERMIN - 1) / SECSPERMIN, plan->t_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
|
|
|
c_cmin(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
|
|
|
{
|
|
|
|
char *arg = **argvp;
|
|
|
|
PLAN *new;
|
|
|
|
|
|
|
|
(*argvp)++;
|
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
|
|
|
new = palloc(N_CMIN, f_cmin);
|
|
|
|
new->t_data = find_parsenum(new, "-cmin", arg, NULL);
|
|
|
|
TIME_CORRECT(new, N_CMIN);
|
|
|
|
return (new);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* -ctime n functions --
|
|
|
|
*
|
|
|
|
* True if the difference between the last change of file
|
|
|
|
* status information and the current time is n 24 hour periods.
|
|
|
|
*/
|
1993-12-31 00:15:18 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
f_ctime(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
|
|
|
extern time_t now;
|
|
|
|
|
1993-08-06 05:53:33 +04:00
|
|
|
COMPARE((now - entry->fts_statp->st_ctime +
|
1993-03-21 12:45:37 +03:00
|
|
|
SECSPERDAY - 1) / SECSPERDAY, plan->t_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_ctime(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1998-02-22 01:47:20 +03:00
|
|
|
char *arg = **argvp;
|
1993-03-21 12:45:37 +03:00
|
|
|
PLAN *new;
|
|
|
|
|
1998-02-22 01:47:20 +03:00
|
|
|
(*argvp)++;
|
1993-03-21 12:45:37 +03:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
|
|
|
new = palloc(N_CTIME, f_ctime);
|
1993-12-31 00:15:18 +03:00
|
|
|
new->t_data = find_parsenum(new, "-ctime", arg, NULL);
|
|
|
|
TIME_CORRECT(new, N_CTIME);
|
|
|
|
return (new);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -depth functions --
|
|
|
|
*
|
|
|
|
* Always true, causes descent of the directory hierarchy to be done
|
|
|
|
* so that all entries in a directory are acted on before the directory
|
|
|
|
* itself.
|
|
|
|
*/
|
1993-12-31 00:15:18 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
f_always_true(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
1993-12-31 00:15:18 +03:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_depth(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
isdepth = 1;
|
|
|
|
|
1993-12-31 00:15:18 +03:00
|
|
|
return (palloc(N_DEPTH, f_always_true));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* [-exec | -ok] utility [arg ... ] ; functions --
|
|
|
|
*
|
|
|
|
* True if the executed utility returns a zero value as exit status.
|
|
|
|
* The end of the primary expression is delimited by a semicolon. If
|
|
|
|
* "{}" occurs anywhere, it gets replaced by the current pathname.
|
|
|
|
* The current directory for the execution of utility is the same as
|
|
|
|
* the current directory when the find utility was started.
|
|
|
|
*
|
|
|
|
* The primary -ok is different in that it requests affirmation of the
|
|
|
|
* user before executing the utility.
|
|
|
|
*/
|
1993-12-31 00:15:18 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
f_exec(plan, entry)
|
1997-10-19 15:52:12 +04:00
|
|
|
PLAN *plan;
|
1993-03-21 12:45:37 +03:00
|
|
|
FTSENT *entry;
|
|
|
|
{
|
|
|
|
extern int dotfd;
|
1997-10-19 15:52:12 +04:00
|
|
|
int cnt;
|
1993-03-21 12:45:37 +03:00
|
|
|
pid_t pid;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
for (cnt = 0; plan->e_argv[cnt]; ++cnt)
|
|
|
|
if (plan->e_len[cnt])
|
|
|
|
brace_subst(plan->e_orig[cnt], &plan->e_argv[cnt],
|
|
|
|
entry->fts_path, plan->e_len[cnt]);
|
|
|
|
|
1993-12-31 00:15:18 +03:00
|
|
|
if (plan->flags == F_NEEDOK && !queryuser(plan->e_argv))
|
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-01-21 05:59:38 +03:00
|
|
|
/* don't mix output of command with find output */
|
|
|
|
fflush(stdout);
|
|
|
|
fflush(stderr);
|
|
|
|
|
1993-12-31 00:15:18 +03:00
|
|
|
switch (pid = vfork()) {
|
1993-03-21 12:45:37 +03:00
|
|
|
case -1:
|
1993-12-31 00:15:18 +03:00
|
|
|
err(1, "fork");
|
1993-03-21 12:45:37 +03:00
|
|
|
/* NOTREACHED */
|
|
|
|
case 0:
|
|
|
|
if (fchdir(dotfd)) {
|
1993-12-31 00:15:18 +03:00
|
|
|
warn("chdir");
|
1993-03-21 12:45:37 +03:00
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
execvp(plan->e_argv[0], plan->e_argv);
|
1993-12-31 00:15:18 +03:00
|
|
|
warn("%s", plan->e_argv[0]);
|
1993-03-21 12:45:37 +03:00
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
pid = waitpid(pid, &status, 0);
|
1993-12-31 00:15:18 +03:00
|
|
|
return (pid != -1 && WIFEXITED(status) && !WEXITSTATUS(status));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* c_exec --
|
|
|
|
* build three parallel arrays, one with pointers to the strings passed
|
|
|
|
* on the command line, one with (possibly duplicated) pointers to the
|
|
|
|
* argv array, and one with integer values that are lengths of the
|
|
|
|
* strings, but also flags meaning that the string has to be massaged.
|
|
|
|
*/
|
|
|
|
PLAN *
|
|
|
|
c_exec(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
|
|
|
{
|
|
|
|
PLAN *new; /* node returned */
|
1997-10-19 15:52:12 +04:00
|
|
|
int cnt;
|
|
|
|
char **argv, **ap, *p;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
isoutput = 1;
|
|
|
|
|
|
|
|
new = palloc(N_EXEC, f_exec);
|
1993-12-31 00:15:18 +03:00
|
|
|
if (isok)
|
|
|
|
new->flags = F_NEEDOK;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
for (ap = argv = *argvp;; ++ap) {
|
|
|
|
if (!*ap)
|
1993-12-31 00:15:18 +03:00
|
|
|
errx(1,
|
|
|
|
"%s: no terminating \";\"", isok ? "-ok" : "-exec");
|
1993-03-21 12:45:37 +03:00
|
|
|
if (**ap == ';')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cnt = ap - *argvp + 1;
|
|
|
|
new->e_argv = (char **)emalloc((u_int)cnt * sizeof(char *));
|
|
|
|
new->e_orig = (char **)emalloc((u_int)cnt * sizeof(char *));
|
|
|
|
new->e_len = (int *)emalloc((u_int)cnt * sizeof(int));
|
|
|
|
|
|
|
|
for (argv = *argvp, cnt = 0; argv < ap; ++argv, ++cnt) {
|
|
|
|
new->e_orig[cnt] = *argv;
|
|
|
|
for (p = *argv; *p; ++p)
|
|
|
|
if (p[0] == '{' && p[1] == '}') {
|
|
|
|
new->e_argv[cnt] = emalloc((u_int)MAXPATHLEN);
|
|
|
|
new->e_len[cnt] = MAXPATHLEN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!*p) {
|
|
|
|
new->e_argv[cnt] = *argv;
|
|
|
|
new->e_len[cnt] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
new->e_argv[cnt] = new->e_orig[cnt] = NULL;
|
|
|
|
|
|
|
|
*argvp = argv + 1;
|
1993-12-31 00:15:18 +03:00
|
|
|
return (new);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1999-01-03 17:54:27 +03:00
|
|
|
/*
|
|
|
|
* -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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* -follow functions --
|
|
|
|
*
|
|
|
|
* Always true, causes symbolic links to be followed on a global
|
|
|
|
* basis.
|
|
|
|
*/
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_follow(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
ftsoptions &= ~FTS_PHYSICAL;
|
|
|
|
ftsoptions |= FTS_LOGICAL;
|
|
|
|
|
1993-12-31 00:15:18 +03:00
|
|
|
return (palloc(N_FOLLOW, f_always_true));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -fstype functions --
|
|
|
|
*
|
|
|
|
* True if the file is of a certain type.
|
|
|
|
*/
|
1993-12-31 00:15:18 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
f_fstype(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
|
|
|
static dev_t curdev; /* need a guaranteed illegal dev value */
|
|
|
|
static int first = 1;
|
1993-12-31 00:15:18 +03:00
|
|
|
struct statfs sb;
|
|
|
|
static short val;
|
1995-06-18 14:58:06 +04:00
|
|
|
static char fstype[MFSNAMELEN];
|
1993-03-21 12:45:37 +03:00
|
|
|
char *p, save[2];
|
|
|
|
|
1993-12-31 00:15:18 +03:00
|
|
|
/* Only check when we cross mount point. */
|
1993-08-06 05:53:33 +04:00
|
|
|
if (first || curdev != entry->fts_statp->st_dev) {
|
|
|
|
curdev = entry->fts_statp->st_dev;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Statfs follows symlinks; find wants the link's file system,
|
|
|
|
* not where it points.
|
|
|
|
*/
|
|
|
|
if (entry->fts_info == FTS_SL ||
|
|
|
|
entry->fts_info == FTS_SLNONE) {
|
1997-10-19 15:52:12 +04:00
|
|
|
if ((p = strrchr(entry->fts_accpath, '/')) != NULL)
|
1993-03-21 12:45:37 +03:00
|
|
|
++p;
|
|
|
|
else
|
|
|
|
p = entry->fts_accpath;
|
|
|
|
save[0] = p[0];
|
|
|
|
p[0] = '.';
|
|
|
|
save[1] = p[1];
|
|
|
|
p[1] = '\0';
|
|
|
|
|
|
|
|
} else
|
|
|
|
p = NULL;
|
|
|
|
|
|
|
|
if (statfs(entry->fts_accpath, &sb))
|
1993-12-31 00:15:18 +03:00
|
|
|
err(1, "%s", entry->fts_accpath);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
if (p) {
|
|
|
|
p[0] = save[0];
|
|
|
|
p[1] = save[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
first = 0;
|
1994-10-18 20:02:44 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Further tests may need both of these values, so
|
|
|
|
* always copy both of them.
|
|
|
|
*/
|
|
|
|
val = sb.f_flags;
|
|
|
|
strncpy(fstype, sb.f_fstypename, MFSNAMELEN);
|
1993-12-31 00:15:18 +03:00
|
|
|
}
|
1994-10-18 16:54:25 +03:00
|
|
|
switch (plan->flags) {
|
1993-12-31 00:15:18 +03:00
|
|
|
case F_MTFLAG:
|
|
|
|
return (val & plan->mt_data);
|
|
|
|
case F_MTTYPE:
|
1994-04-14 07:34:13 +04:00
|
|
|
return (strncmp(fstype, plan->c_data, MFSNAMELEN) == 0);
|
1993-12-31 00:15:18 +03:00
|
|
|
default:
|
|
|
|
abort();
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_fstype(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1998-02-22 01:47:20 +03:00
|
|
|
char *arg = **argvp;
|
1997-10-19 15:52:12 +04:00
|
|
|
PLAN *new;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1998-02-22 01:47:20 +03:00
|
|
|
(*argvp)++;
|
1993-03-21 12:45:37 +03:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
|
|
|
new = palloc(N_FSTYPE, f_fstype);
|
1998-02-02 17:02:06 +03:00
|
|
|
|
1993-12-31 00:15:18 +03:00
|
|
|
switch (*arg) {
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'l':
|
|
|
|
if (!strcmp(arg, "local")) {
|
1993-12-31 00:15:18 +03:00
|
|
|
new->flags = F_MTFLAG;
|
|
|
|
new->mt_data = MNT_LOCAL;
|
|
|
|
return (new);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
break;
|
1993-03-25 01:54:22 +03:00
|
|
|
case 'r':
|
|
|
|
if (!strcmp(arg, "rdonly")) {
|
1993-12-31 00:15:18 +03:00
|
|
|
new->flags = F_MTFLAG;
|
|
|
|
new->mt_data = MNT_RDONLY;
|
|
|
|
return (new);
|
1993-03-25 01:54:22 +03:00
|
|
|
}
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-04-14 07:34:13 +04:00
|
|
|
|
|
|
|
new->flags = F_MTTYPE;
|
|
|
|
new->c_data = arg;
|
|
|
|
return (new);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -group gname functions --
|
|
|
|
*
|
|
|
|
* True if the file belongs to the group gname. If gname is numeric and
|
|
|
|
* an equivalent of the getgrnam() function does not return a valid group
|
|
|
|
* name, gname is taken as a group ID.
|
|
|
|
*/
|
1993-12-31 00:15:18 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
f_group(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
1993-12-31 00:15:18 +03:00
|
|
|
return (entry->fts_statp->st_gid == plan->g_data);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_group(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1998-02-22 01:47:20 +03:00
|
|
|
char *gname = **argvp;
|
1993-03-21 12:45:37 +03:00
|
|
|
PLAN *new;
|
|
|
|
struct group *g;
|
|
|
|
gid_t gid;
|
|
|
|
|
1998-02-22 01:47:20 +03:00
|
|
|
(*argvp)++;
|
1993-03-21 12:45:37 +03:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
|
|
|
g = getgrnam(gname);
|
|
|
|
if (g == NULL) {
|
|
|
|
gid = atoi(gname);
|
|
|
|
if (gid == 0 && gname[0] != '0')
|
1993-12-31 00:15:18 +03:00
|
|
|
errx(1, "-group: %s: no such group", gname);
|
1993-03-21 12:45:37 +03:00
|
|
|
} else
|
|
|
|
gid = g->gr_gid;
|
|
|
|
|
|
|
|
new = palloc(N_GROUP, f_group);
|
|
|
|
new->g_data = gid;
|
1993-12-31 00:15:18 +03:00
|
|
|
return (new);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -inum n functions --
|
|
|
|
*
|
|
|
|
* True if the file has inode # n.
|
|
|
|
*/
|
1993-12-31 00:15:18 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
f_inum(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
1993-08-06 05:53:33 +04:00
|
|
|
COMPARE(entry->fts_statp->st_ino, plan->i_data);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_inum(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1998-02-22 01:47:20 +03:00
|
|
|
char *arg = **argvp;
|
1993-03-21 12:45:37 +03:00
|
|
|
PLAN *new;
|
|
|
|
|
1998-02-22 01:47:20 +03:00
|
|
|
(*argvp)++;
|
1993-03-21 12:45:37 +03:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
|
|
|
new = palloc(N_INUM, f_inum);
|
1993-12-31 00:15:18 +03:00
|
|
|
new->i_data = find_parsenum(new, "-inum", arg, NULL);
|
|
|
|
return (new);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -links n functions --
|
|
|
|
*
|
|
|
|
* True if the file has n links.
|
|
|
|
*/
|
1993-12-31 00:15:18 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
f_links(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
1993-08-06 05:53:33 +04:00
|
|
|
COMPARE(entry->fts_statp->st_nlink, plan->l_data);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_links(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1998-02-22 01:47:20 +03:00
|
|
|
char *arg = **argvp;
|
1993-03-21 12:45:37 +03:00
|
|
|
PLAN *new;
|
|
|
|
|
1998-02-22 01:47:20 +03:00
|
|
|
(*argvp)++;
|
1993-03-21 12:45:37 +03:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
|
|
|
new = palloc(N_LINKS, f_links);
|
1993-12-31 00:15:18 +03:00
|
|
|
new->l_data = (nlink_t)find_parsenum(new, "-links", arg, NULL);
|
|
|
|
return (new);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -ls functions --
|
|
|
|
*
|
|
|
|
* Always true - prints the current entry to stdout in "ls" format.
|
|
|
|
*/
|
1993-12-31 00:15:18 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
f_ls(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
1993-08-06 05:53:33 +04:00
|
|
|
printlong(entry->fts_path, entry->fts_accpath, entry->fts_statp);
|
1993-12-31 00:15:18 +03:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_ls(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
isoutput = 1;
|
|
|
|
|
1993-12-31 00:15:18 +03:00
|
|
|
return (palloc(N_LS, f_ls));
|
|
|
|
}
|
|
|
|
|
1999-01-16 16:27:30 +03:00
|
|
|
/*
|
|
|
|
* -mmin n functions --
|
|
|
|
*
|
|
|
|
* True if the difference between the file modification time and the
|
|
|
|
* current time is n 24 hour periods.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
f_mmin(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
|
|
|
extern time_t now;
|
|
|
|
|
|
|
|
COMPARE((now - entry->fts_statp->st_mtime + SECSPERMIN - 1) /
|
|
|
|
SECSPERMIN, plan->t_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
|
|
|
c_mmin(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
|
|
|
{
|
|
|
|
char *arg = **argvp;
|
|
|
|
PLAN *new;
|
|
|
|
|
|
|
|
(*argvp)++;
|
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
|
|
|
new = palloc(N_MMIN, f_mmin);
|
|
|
|
new->t_data = find_parsenum(new, "-mmin", arg, NULL);
|
|
|
|
TIME_CORRECT(new, N_MMIN);
|
|
|
|
return (new);
|
|
|
|
}
|
1993-12-31 00:15:18 +03:00
|
|
|
/*
|
|
|
|
* -mtime n functions --
|
|
|
|
*
|
|
|
|
* True if the difference between the file modification time and the
|
|
|
|
* current time is n 24 hour periods.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
f_mtime(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
|
|
|
extern time_t now;
|
|
|
|
|
|
|
|
COMPARE((now - entry->fts_statp->st_mtime + SECSPERDAY - 1) /
|
|
|
|
SECSPERDAY, plan->t_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_mtime(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-12-31 00:15:18 +03:00
|
|
|
{
|
1998-02-22 01:47:20 +03:00
|
|
|
char *arg = **argvp;
|
1993-12-31 00:15:18 +03:00
|
|
|
PLAN *new;
|
|
|
|
|
1998-02-22 01:47:20 +03:00
|
|
|
(*argvp)++;
|
1993-12-31 00:15:18 +03:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
|
|
|
new = palloc(N_MTIME, f_mtime);
|
|
|
|
new->t_data = find_parsenum(new, "-mtime", arg, NULL);
|
|
|
|
TIME_CORRECT(new, N_MTIME);
|
|
|
|
return (new);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -name functions --
|
|
|
|
*
|
|
|
|
* True if the basename of the filename being examined
|
|
|
|
* matches pattern using Pattern Matching Notation S3.14
|
|
|
|
*/
|
1993-12-31 00:15:18 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
f_name(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
1993-12-31 00:15:18 +03:00
|
|
|
return (!fnmatch(plan->c_data, entry->fts_name, 0));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_name(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1998-02-22 01:47:20 +03:00
|
|
|
char *pattern = **argvp;
|
1993-03-21 12:45:37 +03:00
|
|
|
PLAN *new;
|
|
|
|
|
1998-02-22 01:47:20 +03:00
|
|
|
(*argvp)++;
|
1993-03-21 12:45:37 +03:00
|
|
|
new = palloc(N_NAME, f_name);
|
|
|
|
new->c_data = pattern;
|
1993-12-31 00:15:18 +03:00
|
|
|
return (new);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -newer file functions --
|
|
|
|
*
|
|
|
|
* True if the current file has been modified more recently
|
|
|
|
* then the modification time of the file named by the pathname
|
|
|
|
* file.
|
|
|
|
*/
|
1993-12-31 00:15:18 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
f_newer(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
1993-12-31 00:15:18 +03:00
|
|
|
return (entry->fts_statp->st_mtime > plan->t_data);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_newer(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1998-02-22 01:47:20 +03:00
|
|
|
char *filename = **argvp;
|
1993-03-21 12:45:37 +03:00
|
|
|
PLAN *new;
|
|
|
|
struct stat sb;
|
|
|
|
|
1998-02-22 01:47:20 +03:00
|
|
|
(*argvp)++;
|
1993-03-21 12:45:37 +03:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
|
|
|
if (stat(filename, &sb))
|
1993-12-31 00:15:18 +03:00
|
|
|
err(1, "%s", filename);
|
1993-03-21 12:45:37 +03:00
|
|
|
new = palloc(N_NEWER, f_newer);
|
|
|
|
new->t_data = sb.st_mtime;
|
1993-12-31 00:15:18 +03:00
|
|
|
return (new);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -nogroup functions --
|
|
|
|
*
|
|
|
|
* True if file belongs to a user ID for which the equivalent
|
|
|
|
* of the getgrnam() 9.2.1 [POSIX.1] function returns NULL.
|
|
|
|
*/
|
1993-12-31 00:15:18 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
f_nogroup(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
1998-02-02 17:02:06 +03:00
|
|
|
|
1994-02-16 06:59:52 +03:00
|
|
|
return (group_from_gid(entry->fts_statp->st_gid, 1) ? 0 : 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_nogroup(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
1993-12-31 00:15:18 +03:00
|
|
|
return (palloc(N_NOGROUP, f_nogroup));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -nouser functions --
|
|
|
|
*
|
|
|
|
* True if file belongs to a user ID for which the equivalent
|
|
|
|
* of the getpwuid() 9.2.2 [POSIX.1] function returns NULL.
|
|
|
|
*/
|
1993-12-31 00:15:18 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
f_nouser(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
1998-02-02 17:02:06 +03:00
|
|
|
|
1994-02-16 06:59:52 +03:00
|
|
|
return (user_from_uid(entry->fts_statp->st_uid, 1) ? 0 : 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_nouser(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
1993-12-31 00:15:18 +03:00
|
|
|
return (palloc(N_NOUSER, f_nouser));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -path functions --
|
|
|
|
*
|
|
|
|
* True if the path of the filename being examined
|
|
|
|
* matches pattern using Pattern Matching Notation S3.14
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
f_path(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
|
|
|
return (!fnmatch(plan->c_data, entry->fts_path, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_path(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-12-31 00:15:18 +03:00
|
|
|
{
|
1998-02-22 01:47:20 +03:00
|
|
|
char *pattern = **argvp;
|
1993-12-31 00:15:18 +03:00
|
|
|
PLAN *new;
|
|
|
|
|
1998-02-22 01:47:20 +03:00
|
|
|
(*argvp)++;
|
1993-12-31 00:15:18 +03:00
|
|
|
new = palloc(N_NAME, f_path);
|
|
|
|
new->c_data = pattern;
|
|
|
|
return (new);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -perm functions --
|
|
|
|
*
|
|
|
|
* The mode argument is used to represent file mode bits. If it starts
|
|
|
|
* with a leading digit, it's treated as an octal mode, otherwise as a
|
|
|
|
* symbolic mode.
|
|
|
|
*/
|
1993-12-31 00:15:18 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
f_perm(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
|
|
|
mode_t mode;
|
|
|
|
|
1993-08-06 05:53:33 +04:00
|
|
|
mode = entry->fts_statp->st_mode &
|
1993-03-21 12:45:37 +03:00
|
|
|
(S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO);
|
1993-12-31 00:15:18 +03:00
|
|
|
if (plan->flags == F_ATLEAST)
|
|
|
|
return ((plan->m_data | mode) == mode);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
1993-12-31 00:15:18 +03:00
|
|
|
return (mode == plan->m_data);
|
1993-03-21 12:45:37 +03:00
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_perm(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1998-02-22 01:47:20 +03:00
|
|
|
char *perm = **argvp;
|
1993-03-21 12:45:37 +03:00
|
|
|
PLAN *new;
|
|
|
|
mode_t *set;
|
|
|
|
|
1998-02-22 01:47:20 +03:00
|
|
|
(*argvp)++;
|
1993-03-21 12:45:37 +03:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
|
|
|
new = palloc(N_PERM, f_perm);
|
|
|
|
|
|
|
|
if (*perm == '-') {
|
1993-12-31 00:15:18 +03:00
|
|
|
new->flags = F_ATLEAST;
|
1993-03-21 12:45:37 +03:00
|
|
|
++perm;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((set = setmode(perm)) == NULL)
|
1993-12-31 00:15:18 +03:00
|
|
|
err(1, "-perm: %s: illegal mode string", perm);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
new->m_data = getmode(set, 0);
|
1993-12-31 00:15:18 +03:00
|
|
|
return (new);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -print functions --
|
|
|
|
*
|
|
|
|
* Always true, causes the current pathame to be written to
|
|
|
|
* standard output.
|
|
|
|
*/
|
1993-12-31 00:15:18 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
f_print(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
|
|
|
(void)printf("%s\n", entry->fts_path);
|
1998-02-02 17:02:06 +03:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1993-10-27 20:52:30 +03:00
|
|
|
|
1997-10-19 15:52:12 +04:00
|
|
|
int
|
1993-10-27 20:52:30 +03:00
|
|
|
f_print0(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
|
|
|
(void)fputs(entry->fts_path, stdout);
|
|
|
|
(void)fputc('\0', stdout);
|
1998-02-02 17:02:06 +03:00
|
|
|
return (1);
|
1993-10-27 20:52:30 +03:00
|
|
|
}
|
1999-01-12 03:18:50 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
f_printx(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
for (cp = entry->fts_path; *cp; cp++) {
|
|
|
|
if (*cp == '\'' || *cp == '\"' || *cp == ' ' ||
|
|
|
|
*cp == '\t' || *cp == '\n' || *cp == '\\')
|
|
|
|
fputc('\\', stdout);
|
|
|
|
|
|
|
|
fputc(*cp, stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
fputc('\n', stdout);
|
|
|
|
return 1;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_print(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
isoutput = 1;
|
|
|
|
|
1998-02-02 17:02:06 +03:00
|
|
|
return (palloc(N_PRINT, f_print));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1993-10-27 20:52:30 +03:00
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_print0(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-10-27 20:52:30 +03:00
|
|
|
{
|
|
|
|
isoutput = 1;
|
|
|
|
|
1998-02-02 17:02:06 +03:00
|
|
|
return (palloc(N_PRINT0, f_print0));
|
1993-10-27 20:52:30 +03:00
|
|
|
}
|
1999-01-12 03:18:50 +03:00
|
|
|
|
|
|
|
PLAN *
|
|
|
|
c_printx(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
|
|
|
{
|
|
|
|
isoutput = 1;
|
|
|
|
|
|
|
|
return palloc(N_PRINTX, f_printx);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* -prune functions --
|
|
|
|
*
|
|
|
|
* Prune a portion of the hierarchy.
|
|
|
|
*/
|
1993-12-31 00:15:18 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
f_prune(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
|
|
|
extern FTS *tree;
|
|
|
|
|
|
|
|
if (fts_set(tree, entry, FTS_SKIP))
|
1993-12-31 00:15:18 +03:00
|
|
|
err(1, "%s", entry->fts_path);
|
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_prune(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1993-12-31 00:15:18 +03:00
|
|
|
return (palloc(N_PRUNE, f_prune));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -size n[c] functions --
|
|
|
|
*
|
|
|
|
* True if the file size in bytes, divided by an implementation defined
|
|
|
|
* value and rounded up to the next integer, is n. If n is followed by
|
|
|
|
* a c, the size is in bytes.
|
|
|
|
*/
|
|
|
|
#define FIND_SIZE 512
|
|
|
|
static int divsize = 1;
|
|
|
|
|
1993-12-31 00:15:18 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
f_size(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
|
|
|
off_t size;
|
|
|
|
|
1993-08-06 05:53:33 +04:00
|
|
|
size = divsize ? (entry->fts_statp->st_size + FIND_SIZE - 1) /
|
|
|
|
FIND_SIZE : entry->fts_statp->st_size;
|
1993-03-21 12:45:37 +03:00
|
|
|
COMPARE(size, plan->o_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_size(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1998-02-22 01:47:20 +03:00
|
|
|
char *arg = **argvp;
|
1993-03-21 12:45:37 +03:00
|
|
|
PLAN *new;
|
|
|
|
char endch;
|
|
|
|
|
1998-02-22 01:47:20 +03:00
|
|
|
(*argvp)++;
|
1993-03-21 12:45:37 +03:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
|
|
|
new = palloc(N_SIZE, f_size);
|
1993-09-17 01:41:30 +04:00
|
|
|
endch = 'c';
|
1993-03-21 12:45:37 +03:00
|
|
|
new->o_data = find_parsenum(new, "-size", arg, &endch);
|
|
|
|
if (endch == 'c')
|
|
|
|
divsize = 0;
|
1993-12-31 00:15:18 +03:00
|
|
|
return (new);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -type c functions --
|
|
|
|
*
|
1998-02-02 17:02:06 +03:00
|
|
|
* True if the type of the file is c, where c is b, c, d, p, f or w
|
|
|
|
* for block special file, character special file, directory, FIFO,
|
|
|
|
* regular file or whiteout respectively.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1993-12-31 00:15:18 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
f_type(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
1993-12-31 00:15:18 +03:00
|
|
|
return ((entry->fts_statp->st_mode & S_IFMT) == plan->m_data);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_type(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1998-02-22 01:47:20 +03:00
|
|
|
char *typestring = **argvp;
|
1993-03-21 12:45:37 +03:00
|
|
|
PLAN *new;
|
1998-10-14 04:50:43 +04:00
|
|
|
mode_t mask = (mode_t)0;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1998-02-22 01:47:20 +03:00
|
|
|
(*argvp)++;
|
1993-03-21 12:45:37 +03:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
|
|
|
switch (typestring[0]) {
|
1996-05-21 17:43:50 +04:00
|
|
|
#ifdef S_IFWHT
|
|
|
|
case 'W':
|
1997-01-30 12:17:27 +03:00
|
|
|
#ifdef FTS_WHITEOUT
|
|
|
|
ftsoptions |= FTS_WHITEOUT;
|
|
|
|
#endif
|
1996-05-21 17:43:50 +04:00
|
|
|
mask = S_IFWHT;
|
|
|
|
break;
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'b':
|
|
|
|
mask = S_IFBLK;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
mask = S_IFCHR;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
mask = S_IFDIR;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
mask = S_IFREG;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
mask = S_IFLNK;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
mask = S_IFIFO;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
mask = S_IFSOCK;
|
|
|
|
break;
|
1998-02-02 17:02:06 +03:00
|
|
|
#ifdef FTS_WHITEOUT
|
|
|
|
case 'w':
|
|
|
|
mask = S_IFWHT;
|
|
|
|
ftsoptions |= FTS_WHITEOUT;
|
|
|
|
break;
|
|
|
|
#endif /* FTS_WHITEOUT */
|
1993-03-21 12:45:37 +03:00
|
|
|
default:
|
1993-12-31 00:15:18 +03:00
|
|
|
errx(1, "-type: %s: unknown type", typestring);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
new = palloc(N_TYPE, f_type);
|
|
|
|
new->m_data = mask;
|
1993-12-31 00:15:18 +03:00
|
|
|
return (new);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -user uname functions --
|
|
|
|
*
|
|
|
|
* True if the file belongs to the user uname. If uname is numeric and
|
|
|
|
* an equivalent of the getpwnam() S9.2.2 [POSIX.1] function does not
|
|
|
|
* return a valid user name, uname is taken as a user ID.
|
|
|
|
*/
|
1993-12-31 00:15:18 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
f_user(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
1993-12-31 00:15:18 +03:00
|
|
|
return (entry->fts_statp->st_uid == plan->u_data);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_user(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1998-02-22 01:47:20 +03:00
|
|
|
char *username = **argvp;
|
1993-03-21 12:45:37 +03:00
|
|
|
PLAN *new;
|
|
|
|
struct passwd *p;
|
|
|
|
uid_t uid;
|
|
|
|
|
1998-02-22 01:47:20 +03:00
|
|
|
(*argvp)++;
|
1993-03-21 12:45:37 +03:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
|
|
|
p = getpwnam(username);
|
|
|
|
if (p == NULL) {
|
|
|
|
uid = atoi(username);
|
|
|
|
if (uid == 0 && username[0] != '0')
|
1993-12-31 00:15:18 +03:00
|
|
|
errx(1, "-user: %s: no such user", username);
|
1993-03-21 12:45:37 +03:00
|
|
|
} else
|
|
|
|
uid = p->pw_uid;
|
|
|
|
|
|
|
|
new = palloc(N_USER, f_user);
|
|
|
|
new->u_data = uid;
|
1993-12-31 00:15:18 +03:00
|
|
|
return (new);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -xdev functions --
|
|
|
|
*
|
|
|
|
* Always true, causes find not to decend past directories that have a
|
|
|
|
* different device ID (st_dev, see stat() S5.6.2 [POSIX.1])
|
|
|
|
*/
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_xdev(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
ftsoptions |= FTS_XDEV;
|
|
|
|
|
1993-12-31 00:15:18 +03:00
|
|
|
return (palloc(N_XDEV, f_always_true));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ( expression ) functions --
|
|
|
|
*
|
|
|
|
* True if expression is true.
|
|
|
|
*/
|
1993-12-31 00:15:18 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
f_expr(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
1997-10-19 15:52:12 +04:00
|
|
|
PLAN *p;
|
|
|
|
int state;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 15:52:12 +04:00
|
|
|
state = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
for (p = plan->p_data[0];
|
|
|
|
p && (state = (p->eval)(p, entry)); p = p->next);
|
1993-12-31 00:15:18 +03:00
|
|
|
return (state);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* N_OPENPAREN and N_CLOSEPAREN nodes are temporary place markers. They are
|
|
|
|
* eliminated during phase 2 of find_formplan() --- the '(' node is converted
|
|
|
|
* to a N_EXPR node containing the expression and the ')' node is discarded.
|
|
|
|
*/
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_openparen(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 15:52:12 +04:00
|
|
|
return (palloc(N_OPENPAREN, (int (*) __P((PLAN *, FTSENT *)))-1));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_closeparen(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-19 15:52:12 +04:00
|
|
|
return (palloc(N_CLOSEPAREN, (int (*) __P((PLAN *, FTSENT *)))-1));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ! expression functions --
|
|
|
|
*
|
|
|
|
* Negation of a primary; the unary NOT operator.
|
|
|
|
*/
|
1993-12-31 00:15:18 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
f_not(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
1997-10-19 15:52:12 +04:00
|
|
|
PLAN *p;
|
|
|
|
int state;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 15:52:12 +04:00
|
|
|
state = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
for (p = plan->p_data[0];
|
|
|
|
p && (state = (p->eval)(p, entry)); p = p->next);
|
1993-12-31 00:15:18 +03:00
|
|
|
return (!state);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_not(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1993-12-31 00:15:18 +03:00
|
|
|
return (palloc(N_NOT, f_not));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* expression -o expression functions --
|
|
|
|
*
|
|
|
|
* Alternation of primaries; the OR operator. The second expression is
|
|
|
|
* not evaluated if the first expression is true.
|
|
|
|
*/
|
1993-12-31 00:15:18 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
f_or(plan, entry)
|
|
|
|
PLAN *plan;
|
|
|
|
FTSENT *entry;
|
|
|
|
{
|
1997-10-19 15:52:12 +04:00
|
|
|
PLAN *p;
|
|
|
|
int state;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 15:52:12 +04:00
|
|
|
state = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
for (p = plan->p_data[0];
|
|
|
|
p && (state = (p->eval)(p, entry)); p = p->next);
|
|
|
|
|
|
|
|
if (state)
|
1993-12-31 00:15:18 +03:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
for (p = plan->p_data[1];
|
|
|
|
p && (state = (p->eval)(p, entry)); p = p->next);
|
1993-12-31 00:15:18 +03:00
|
|
|
return (state);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
1998-02-22 01:47:20 +03:00
|
|
|
c_or(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1993-12-31 00:15:18 +03:00
|
|
|
return (palloc(N_OR, f_or));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1998-02-22 01:47:20 +03:00
|
|
|
PLAN *
|
|
|
|
c_null(argvp, isok)
|
|
|
|
char ***argvp;
|
|
|
|
int isok;
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
static PLAN *
|
|
|
|
palloc(t, f)
|
|
|
|
enum ntype t;
|
1993-12-31 00:15:18 +03:00
|
|
|
int (*f) __P((PLAN *, FTSENT *));
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
PLAN *new;
|
|
|
|
|
1998-02-02 17:02:06 +03:00
|
|
|
if ((new = malloc(sizeof(PLAN))) == NULL)
|
1998-02-22 01:47:20 +03:00
|
|
|
err(1, "%s", "");
|
1998-02-02 17:02:06 +03:00
|
|
|
new->type = t;
|
|
|
|
new->eval = f;
|
|
|
|
new->flags = 0;
|
|
|
|
new->next = NULL;
|
|
|
|
return (new);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|