* Copyright (c) 1991, 1993
* 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
* 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
static char sccsid
[] = "@(#)find.c 8.1 (Berkeley) 6/6/93";
* process the command line and create a "plan" corresponding to the
* for each argument in the command line, determine what kind of node
* it is, create the appropriate node type and add the new plan node
* to the end of the existing plan. The resulting plan is a linked
* list of plan nodes. For example, the string:
* % find . -name foo -newer bar -print
* [-name foo]--> [-newer bar]--> [-print]
* in this diagram, `[-name foo]' represents the plan node generated
* by c_name() with an argument of foo and `-->' represents the
for (plan
= tail
= NULL
; *argv
;) {
if (!(new = find_create(&argv
)))
* if the user didn't specify one of -print, -ok or -exec, then -print
* is assumed so we add a -print node on the end. It is possible that
* the user might want the -print someplace else on the command line,
* but there's no way to know that.
* the command line has been completely processed into a search plan
* except for the (, ), !, and -o operators. Rearrange the plan so
* that the portions of the plan which are affected by the operators
* are moved into operator nodes themselves. For example:
* [!]--> [-name foo]--> [-print]
* [! [-name foo] ]--> [-print]
* [(]--> [-depth]--> [-name foo]--> [)]--> [-print]
* [expr [-depth]-->[-name foo] ]--> [-print]
* operators are handled in order of precedence.
plan
= paren_squish(plan
); /* ()'s */
plan
= not_squish(plan
); /* !'s */
plan
= or_squish(plan
); /* -o's */
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.
find_execute(plan
, paths
)
PLAN
*plan
; /* search plan */
char **paths
; /* array of pathnames to traverse */
if (!(tree
= fts_open(paths
, ftsoptions
, (int (*)())NULL
)))
while (entry
= fts_read(tree
)) {
switch(entry
->fts_info
) {
warn("%s", entry
->fts_path
);
#define BADCH " \t\n\\'\""
if (isxargs
&& strpbrk(entry
->fts_path
, BADCH
)) {
warnx("%s: illegal path", entry
->fts_path
);
* 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
);