merge lite2, sans getvfsbyname in functions.c (waiting on libc)

This commit is contained in:
mrg 1998-02-02 14:02:06 +00:00
parent e50f17aab7
commit 7b983ca6d5
9 changed files with 172 additions and 86 deletions

View File

@ -1,5 +1,5 @@
# $NetBSD: Makefile,v 1.5 1997/10/19 12:04:58 lukem Exp $
# from: @(#)Makefile 5.2 (Berkeley) 5/24/91
# $NetBSD: Makefile,v 1.6 1998/02/02 14:02:06 mrg Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/6/93
WARNS= 0
PROG= find

View File

@ -1,7 +1,7 @@
/* $NetBSD: extern.h,v 1.6 1997/10/19 11:52:12 lukem Exp $ */
/* $NetBSD: extern.h,v 1.7 1998/02/02 14:02:12 mrg Exp $ */
/*-
* Copyright (c) 1991, 1993
* Copyright (c) 1991, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -32,8 +32,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)extern.h 8.1 (Berkeley) 6/6/93
* $NetBSD: extern.h,v 1.6 1997/10/19 11:52:12 lukem Exp $
* from: @(#)extern.h 8.3 (Berkeley) 4/16/94
*/
#include <sys/cdefs.h>
@ -41,11 +40,10 @@
void brace_subst __P((char *, char **, char *, int));
void *emalloc __P((unsigned int));
PLAN *find_create __P((char ***));
void find_execute __P((PLAN *, char **));
int find_execute __P((PLAN *, char **));
PLAN *find_formplan __P((char **));
int f_expr __P((PLAN *, FTSENT *));
PLAN *not_squish __P((PLAN *));
OPTION *option __P((char *));
PLAN *or_squish __P((PLAN *));
PLAN *paren_squish __P((PLAN *));
struct stat;

View File

@ -1,4 +1,4 @@
.\" $NetBSD: find.1,v 1.12 1997/10/19 11:52:22 lukem Exp $
.\" $NetBSD: find.1,v 1.13 1998/02/02 14:02:14 mrg Exp $
.\"
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@ -34,18 +34,18 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" from: @(#)find.1 8.1 (Berkeley) 6/6/93
.\" $NetBSD: find.1,v 1.12 1997/10/19 11:52:22 lukem Exp $
.\" from: @(#)find.1 8.7 (Berkeley) 5/9/95
.\"
.Dd June 6, 1993
.Dd May 9, 1995
.Dt FIND 1
.Os
.Sh NAME
.Nm find
.Nd walk a file hierarchy
.Sh SYNOPSIS
.Nm
.Op Fl HdhXx
.Nm find
.Op Fl H | Fl L | Fl P
.Op Fl Xdx
.Op Fl f Ar file
.Op Ar file ...
.Ar expression
@ -65,12 +65,40 @@ The options are as follows:
The
.Fl H
option causes the file information and file type (see
.Xr stat 2 ) ,
.Xr stat 2 ) ,
returned for each symbolic link encountered on the command line to be
those of the file referenced by the link, not the link itself.
If the referenced file does not exist, the file information and type will
be for the link itself. File information of all symbolic links not on
the command line is that of the link itself.
.It Fl L
The
.Fl L
option causes the file information and file type (see
.Xr stat 2)
returned for each symbolic link to be those of the file referenced by the
link, not the link itself.
If the referenced file does not exist, the file information and type will
be for the link itself.
.It Fl P
The
.Fl P
option causes the file information and file type (see
.Xr stat 2)
returned for each symbolic link to be those of the link itself.
.It Fl X
The
.Fl X
option is a modification to permit
.Nm
to be safely used in conjunction with
.Xr xargs 1 .
If a file name contains any of the delimiting characters used by
.Xr xargs ,
a diagnostic message is displayed on standard error, and the file
is skipped.
The delimiting characters include single (`` ' '') and double (`` " '')
quotes, backslash (``\e''), space, tab and newline characters.
.It Fl d
The
.Fl d
@ -155,9 +183,15 @@ Follow symbolic links.
.It Ic -fstype Ar type
True if the file is contained in a file system of type
.Ar type .
Two special file system types are recognized: ``local'' and ``rdonly''.
These do not describe actual file system types;
the former matches any file system physically mounted on the system where
The
.Xr sysctl 8
command can be used to find out the types of filesystems
that are available on the system:
.Bd -literal -offset indent
sysctl vfs
.Ed
In addition, there are two pseudo-types, ``local'' and ``rdonly''.
The former matches any file system physically mounted on the system where
the
.Nm
is being executed, and the latter matches any file system which is
@ -193,7 +227,7 @@ True if the difference between the file last modification time and the time
was started, rounded up to the next full 24\-hour period, is
.Ar n
24\-hour periods.
.It Ic \&-ok Ar utility Ns Op argument ... ;
.It Ic \&-ok Ar utility Op argument ... ;
The
.Ic \&-ok
primary is identical to the
@ -263,7 +297,7 @@ Note, the first character of a symbolic mode may not be a dash (``\-'').
This primary always evaluates to true.
It prints the pathname of the current file to standard output, followed
by a newline character.
If neither
If none of
.Ic -exec ,
.Ic -ls ,
.Ic -ok ,
@ -419,7 +453,7 @@ primaries are extensions to
.Pp
Historically, the
.Fl d ,
.Fl s
.Fl h
and
.Fl x
options were implemented using the primaries ``\-depth'', ``\-follow'',

View File

@ -1,7 +1,7 @@
/* $NetBSD: find.c,v 1.9 1997/10/19 11:52:27 lukem Exp $ */
/* $NetBSD: find.c,v 1.10 1998/02/02 14:02:16 mrg Exp $ */
/*-
* Copyright (c) 1991, 1993
* Copyright (c) 1991, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
@ -39,9 +39,9 @@
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "from: @(#)find.c 8.1 (Berkeley) 6/6/93";
static char sccsid[] = "from: @(#)find.c 8.5 (Berkeley) 8/5/94";
#else
__RCSID("$NetBSD: find.c,v 1.9 1997/10/19 11:52:27 lukem Exp $");
__RCSID("$NetBSD: find.c,v 1.10 1998/02/02 14:02:16 mrg Exp $");
#endif
#endif /* not lint */
@ -153,19 +153,20 @@ FTS *tree; /* pointer to top of FTS hierarchy */
* take a search plan and an array of search paths and executes the plan
* over all FTSENT's returned for the given search paths.
*/
void
int
find_execute(plan, paths)
PLAN *plan; /* search plan */
char **paths; /* array of pathnames to traverse */
{
register FTSENT *entry;
PLAN *p;
int rval;
if (!(tree = fts_open(paths, ftsoptions, NULL)))
err(1, "ftsopen");
while ((entry = fts_read(tree)) != NULL) {
switch(entry->fts_info) {
for (rval = 0; (entry = fts_read(tree)) != NULL; ) {
switch (entry->fts_info) {
case FTS_D:
if (isdepth)
continue;
@ -178,23 +179,33 @@ find_execute(plan, paths)
case FTS_ERR:
case FTS_NS:
(void)fflush(stdout);
warn("%s", entry->fts_path);
warnx("%s: %s",
entry->fts_path, strerror(entry->fts_errno));
rval = 1;
continue;
#ifdef FTS_W
case FTS_W:
continue;
#endif /* FTS_W */
}
#define BADCH " \t\n\\'\""
if (isxargs && strpbrk(entry->fts_path, BADCH)) {
(void)fflush(stdout);
warnx("%s: illegal path", entry->fts_path);
rval = 1;
continue;
}
/*
* call all the functions in the execution plan until one is
* Call all the functions in the execution plan until one is
* false or all have been executed. This is where we do all
* the work specified by the user on the command line.
*/
for (p = plan; p && (p->eval)(p, entry); p = p->next)
;
}
if (errno)
err(1, "fts_read");
(void)fts_close(tree);
return (rval);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: find.h,v 1.6 1997/01/09 20:19:11 tls Exp $ */
/* $NetBSD: find.h,v 1.7 1998/02/02 14:02:19 mrg Exp $ */
/*-
* Copyright (c) 1990, 1993
@ -36,7 +36,6 @@
* SUCH DAMAGE.
*
* from: @(#)find.h 8.1 (Berkeley) 6/6/93
* $NetBSD: find.h,v 1.6 1997/01/09 20:19:11 tls Exp $
*/
/* node type */

View File

@ -1,4 +1,4 @@
/* $NetBSD: function.c,v 1.21 1997/10/19 11:52:32 lukem Exp $ */
/* $NetBSD: function.c,v 1.22 1998/02/02 14:02:21 mrg Exp $ */
/*-
* Copyright (c) 1990, 1993
@ -39,9 +39,9 @@
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "from: @(#)function.c 8.1 (Berkeley) 6/6/93";
static char sccsid[] = "from: @(#)function.c 8.10 (Berkeley) 5/4/95";
#else
__RCSID("$NetBSD: function.c,v 1.21 1997/10/19 11:52:32 lukem Exp $");
__RCSID("$NetBSD: function.c,v 1.22 1998/02/02 14:02:21 mrg Exp $");
#endif
#endif /* not lint */
@ -433,10 +433,25 @@ c_fstype(arg)
char *arg;
{
PLAN *new;
#if 0
struct vfsconf vfc;
#endif
ftsoptions &= ~FTS_NOSTAT;
new = palloc(N_FSTYPE, f_fstype);
#if 0
/*
* Check first for a filesystem name.
*/
if (getvfsbyname(arg, &vfc) == 0) {
new->flags = F_MTTYPE;
new->mt_data = vfc.vfc_typenum;
return (new);
}
#endif
switch (*arg) {
case 'l':
if (!strcmp(arg, "local")) {
@ -454,9 +469,14 @@ c_fstype(arg)
break;
}
#if 0
errx(1, "%s: unknown file type", arg);
/* NOTREACHED */
#else
new->flags = F_MTTYPE;
new->c_data = arg;
return (new);
#endif
}
/*
@ -670,6 +690,7 @@ f_nogroup(plan, entry)
PLAN *plan;
FTSENT *entry;
{
return (group_from_gid(entry->fts_statp->st_gid, 1) ? 0 : 1);
}
@ -692,6 +713,7 @@ f_nouser(plan, entry)
PLAN *plan;
FTSENT *entry;
{
return (user_from_uid(entry->fts_statp->st_uid, 1) ? 0 : 1);
}
@ -786,7 +808,7 @@ f_print(plan, entry)
FTSENT *entry;
{
(void)printf("%s\n", entry->fts_path);
return(1);
return (1);
}
int
@ -796,7 +818,7 @@ f_print0(plan, entry)
{
(void)fputs(entry->fts_path, stdout);
(void)fputc('\0', stdout);
return(1);
return (1);
}
PLAN *
@ -804,7 +826,7 @@ c_print()
{
isoutput = 1;
return(palloc(N_PRINT, f_print));
return (palloc(N_PRINT, f_print));
}
PLAN *
@ -812,7 +834,7 @@ c_print0()
{
isoutput = 1;
return(palloc(N_PRINT0, f_print0));
return (palloc(N_PRINT0, f_print0));
}
/*
@ -880,9 +902,9 @@ c_size(arg)
/*
* -type c functions --
*
* True if the type of the file is c, where c is b, c, d, p, or f for
* block special file, character special file, directory, FIFO, or
* regular file, respectively.
* 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.
*/
int
f_type(plan, entry)
@ -931,6 +953,12 @@ c_type(typestring)
case 's':
mask = S_IFSOCK;
break;
#ifdef FTS_WHITEOUT
case 'w':
mask = S_IFWHT;
ftsoptions |= FTS_WHITEOUT;
break;
#endif /* FTS_WHITEOUT */
default:
errx(1, "-type: %s: unknown type", typestring);
}
@ -1092,13 +1120,11 @@ palloc(t, f)
{
PLAN *new;
if ((new = malloc(sizeof(PLAN))) != NULL) {
new->type = t;
new->eval = f;
new->flags = 0;
new->next = NULL;
return (new);
}
err(1, "malloc");
/* NOTREACHED */
if ((new = malloc(sizeof(PLAN))) == NULL)
err(1, NULL);
new->type = t;
new->eval = f;
new->flags = 0;
new->next = NULL;
return (new);
}

View File

@ -1,9 +1,12 @@
/* $NetBSD: main.c,v 1.8 1997/10/19 11:52:43 lukem Exp $ */
/* $NetBSD: main.c,v 1.9 1998/02/02 14:02:23 mrg Exp $ */
/*-
* Copyright (c) 1990, 1993
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* 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:
@ -36,9 +39,11 @@
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 5/4/95";
#else
__RCSID("$NetBSD: main.c,v 1.8 1997/10/19 11:52:43 lukem Exp $");
__COPYRIGHT("@(#) Copyright (c) 1990, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n");
__RCSID("$NetBSD: main.c,v 1.9 1998/02/02 14:02:23 mrg Exp $");
#endif
#endif /* not lint */
@ -52,6 +57,7 @@ __RCSID("$NetBSD: main.c,v 1.8 1997/10/19 11:52:43 lukem Exp $");
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include "find.h"
@ -77,11 +83,25 @@ main(argc, argv)
(void)time(&now); /* initialize the time-of-day */
p = start = argv;
ftsoptions = FTS_NOSTAT|FTS_PHYSICAL;
while ((ch = getopt(argc, argv, "Hdf:hXx")) != -1)
ftsoptions = FTS_NOSTAT | FTS_PHYSICAL;
while ((ch = getopt(argc, argv, "HLPXdf:x")) != EOF)
switch(ch) {
case 'H':
ftsoptions |= FTS_COMFOLLOW;
#if 0 /* XXX necessary? */
ftsoptions &= ~FTS_LOGICAL;
#endif
break;
case 'L':
ftsoptions &= ~FTS_COMFOLLOW;
ftsoptions |= FTS_LOGICAL;
break;
case 'P':
ftsoptions &= ~(FTS_COMFOLLOW|FTS_LOGICAL);
ftsoptions |= FTS_PHYSICAL;
break;
case 'X':
isxargs = 1;
break;
case 'd':
isdepth = 1;
@ -93,11 +113,7 @@ main(argc, argv)
ftsoptions &= ~FTS_PHYSICAL;
ftsoptions |= FTS_LOGICAL;
break;
case 'X':
isxargs = 1;
break;
case 'x':
ftsoptions &= ~FTS_NOSTAT;
ftsoptions |= FTS_XDEV;
break;
case '?':
@ -108,15 +124,17 @@ main(argc, argv)
argc -= optind;
argv += optind;
/* The first argument that starts with a -, or is a ! or a (, and all
* subsequent arguments shall be interpreted as an expression ...
* (POSIX.2).
/*
* Find first option to delimit the file list. The first argument
* that starts with a -, or is a ! or a ( must be interpreted as a
* part of the find expression, according to POSIX .2.
*/
while (*argv) {
if (**argv == '-' ||
((**argv == '!' || **argv == '(') && (*argv)[1] == '\0'))
for (; *argv != NULL; *p++ = *argv++) {
if (argv[0][0] == '-')
break;
if ((argv[0][0] == '!' || argv[0][0] == '(') &&
argv[0][1] == '\0')
break;
*p++ = *argv++;
}
if (p == start)
@ -124,16 +142,15 @@ main(argc, argv)
*p = NULL;
if ((dotfd = open(".", O_RDONLY, 0)) < 0)
err(1, ".:");
err(1, ".");
find_execute(find_formplan(argv), start);
exit(0);
exit(find_execute(find_formplan(argv), start));
}
static void
usage()
{
(void)fprintf(stderr,
"usage: find [-HdhXx] [-f file] [file ...] expression\n");
"usage: find [-H | -L | -P] [-Xdhx] [-f file] [file ...] [expression]\n");
exit(1);
}

View File

@ -1,7 +1,7 @@
/* $NetBSD: misc.c,v 1.6 1997/10/19 11:52:50 lukem Exp $ */
/* $NetBSD: misc.c,v 1.7 1998/02/02 14:02:25 mrg Exp $ */
/*-
* Copyright (c) 1990, 1993
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
@ -39,9 +39,9 @@
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "from: @(#)misc.c 8.1 (Berkeley) 6/6/93";
static char sccsid[] = "from: @(#)misc.c 8.2 (Berkeley) 4/1/94";
#else
__RCSID("$NetBSD: misc.c,v 1.6 1997/10/19 11:52:50 lukem Exp $");
__RCSID("$NetBSD: misc.c,v 1.7 1998/02/02 14:02:25 mrg Exp $");
#endif
#endif /* not lint */
@ -71,7 +71,7 @@ brace_subst(orig, store, path, len)
char ch, *p;
plen = strlen(path);
for (p = *store; (ch = *orig) != 0; ++orig)
for (p = *store; (ch = *orig) != '\0'; ++orig)
if (ch == '{' && orig[1] == '}') {
while ((p - *store) + plen > len)
if (!(*store = realloc(*store, len *= 2)))
@ -129,7 +129,7 @@ emalloc(len)
{
void *p;
if ((p = malloc(len)) != NULL)
return (p);
err(1, "malloc");
if ((p = malloc(len)) == NULL)
err(1, "malloc");
return (p);
}

View File

@ -1,7 +1,7 @@
/* $NetBSD: option.c,v 1.7 1997/10/19 11:52:59 lukem Exp $ */
/* $NetBSD: option.c,v 1.8 1998/02/02 14:02:28 mrg Exp $ */
/*-
* Copyright (c) 1990, 1993
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
@ -39,9 +39,9 @@
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "from: @(#)option.c 8.1 (Berkeley) 6/6/93";
static char sccsid[] = "from: @(#)option.c 8.2 (Berkeley) 4/16/94";
#else
__RCSID("$NetBSD: option.c,v 1.7 1997/10/19 11:52:59 lukem Exp $");
__RCSID("$NetBSD: option.c,v 1.8 1998/02/02 14:02:28 mrg Exp $");
#endif
#endif /* not lint */
@ -57,9 +57,10 @@ __RCSID("$NetBSD: option.c,v 1.7 1997/10/19 11:52:59 lukem Exp $");
#include "find.h"
int typecompare __P((const void *, const void *));
static OPTION *option __P((char *));
/* NB: the following table must be sorted lexically. */
static OPTION options[] = {
static OPTION const options[] = {
{ "!", N_NOT, c_not, O_ZERO },
{ "(", N_OPENPAREN, c_openparen, O_ZERO },
{ ")", N_CLOSEPAREN, c_closeparen, O_ZERO },
@ -138,7 +139,7 @@ find_create(argvp)
return (new);
}
OPTION *
static OPTION *
option(name)
char *name;
{