1996-02-04 20:35:16 +00:00
|
|
|
/* tree.c -- helper functions to build and evaluate the expression tree.
|
2025-01-04 11:43:53 +01:00
|
|
|
Copyright (C) 1990-2025 Free Software Foundation, Inc.
|
1996-02-04 20:35:16 +00:00
|
|
|
|
2007-07-02 08:25:45 +00:00
|
|
|
This program is free software: you can redistribute it and/or modify
|
1996-02-04 20:35:16 +00:00
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-07-02 08:25:45 +00:00
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
1996-02-04 20:35:16 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
1996-02-04 20:35:16 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
all: prefer https:// URLs where possible
Change from http:// to https:// URLs for the following:
www.gnu.org, gnu.org, savannah.gnu.org, git.sv.gnu.org, lists.gnu.org,
translationproject.org, cve.mitre.org, cwe.mitre.org, xkcd.com,
standards.ieee.org, and gcc.gnu.org.
* COPYING: Do the above replacement.
* ChangeLog-2013: Likewise.
* NEWS: Likewise.
* README: Likewise.
* README-hacking: Likewise.
* build-aux/Makefile.am: Likewise.
* build-aux/check-testfiles.sh: Likewise.
* build-aux/gen-changelog.sh: Likewise.
* build-aux/man-lint.sh: Likewise.
* build-aux/src-sniff.py: Likewise.
* cfg.mk: Likewise.
* configure.ac: Likewise.
* doc/Makefile.am: Likewise.
* doc/find-maint.texi: Likewise.
* doc/find.texi: Likewise.
* find/defs.h: Likewise.
* find/exec.c: Likewise.
* find/find.1: Likewise.
* find/finddata.c: Likewise.
* find/fstype.c: Likewise.
* find/ftsfind.c: Likewise.
* find/oldfind.c: Likewise.
* find/parser.c: Likewise.
* find/pred.c: Likewise.
* find/print.c: Likewise.
* find/print.h: Likewise.
* find/sharefile.c: Likewise.
* find/sharefile.h: Likewise.
* find/testsuite/Makefile.am: Likewise.
* find/testsuite/binary_locations.sh: Likewise.
* find/testsuite/checklists.py: Likewise.
* find/testsuite/config/unix.exp: Likewise.
* find/testsuite/find.gnu/name-period.exp: Likewise.
* find/testsuite/find.posix/depth1.exp: Likewise.
* find/testsuite/sv-34079.sh: Likewise.
* find/testsuite/sv-34976-execdir-fd-leak.sh: Likewise.
* find/testsuite/sv-48030-exec-plus-bug.sh: Likewise.
* find/testsuite/sv-48180-refuse-noop.sh: Likewise.
* find/testsuite/sv-52220.sh: Likewise.
* find/testsuite/sv-bug-32043.sh: Likewise.
* find/testsuite/test_escape_c.sh: Likewise.
* find/testsuite/test_escapechars.sh: Likewise.
* find/testsuite/test_inode.sh: Likewise.
* find/testsuite/test_type-list.sh: Likewise.
* find/tree.c: Likewise.
* find/util.c: Likewise.
* gnulib-local/lib/gcc-function-attributes.h: Likewise.
* lib/bugreports.c: Likewise.
* lib/bugreports.h: Likewise.
* lib/buildcmd.c: Likewise.
* lib/buildcmd.h: Likewise.
* lib/check-regexprops.sh: Likewise.
* lib/dircallback.c: Likewise.
* lib/dircallback.h: Likewise.
* lib/extendbuf.c: Likewise.
* lib/extendbuf.h: Likewise.
* lib/fdleak.c: Likewise.
* lib/fdleak.h: Likewise.
* lib/findutils-version.c: Likewise.
* lib/findutils-version.h: Likewise.
* lib/listfile.c: Likewise.
* lib/listfile.h: Likewise.
* lib/printquoted.c: Likewise.
* lib/printquoted.h: Likewise.
* lib/qmark.c: Likewise.
* lib/regexprops.c: Likewise.
* lib/regextype.c: Likewise.
* lib/regextype.h: Likewise.
* lib/safe-atoi.c: Likewise.
* lib/safe-atoi.h: Likewise.
* lib/splitstring.c: Likewise.
* lib/splitstring.h: Likewise.
* lib/test_splitstring.c: Likewise.
* lib/unused-result.h: Likewise.
* locate/frcode.c: Likewise.
* locate/locate.1: Likewise.
* locate/locate.c: Likewise.
* locate/locatedb.5: Likewise.
* locate/locatedb.h: Likewise.
* locate/testsuite/Makefile.am: Likewise.
* locate/testsuite/config/unix.exp: Likewise.
* locate/updatedb.1: Likewise.
* locate/updatedb.sh: Likewise.
* locate/word_io.c: Likewise.
* po/fetch-po-files: Likewise.
* xargs/testsuite/Makefile.am: Likewise.
* xargs/testsuite/config/unix.exp: Likewise.
* xargs/xargs.1: Likewise.
* xargs/xargs.c: Likewise.
2017-10-23 00:19:34 +02:00
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2003-06-14 15:41:26 +00:00
|
|
|
*/
|
1996-02-04 20:35:16 +00:00
|
|
|
|
2011-06-20 01:30:22 +01:00
|
|
|
/* config.h must always come first. */
|
2007-06-09 12:25:27 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2011-06-20 01:30:22 +01:00
|
|
|
/* system headers. */
|
2007-05-01 09:46:30 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2011-06-20 01:30:22 +01:00
|
|
|
/* gnulib headers. */
|
2024-05-20 07:41:40 +02:00
|
|
|
#include <fnmatch.h>
|
2011-06-20 01:30:22 +01:00
|
|
|
#include "xalloc.h"
|
1996-02-04 20:35:16 +00:00
|
|
|
|
2011-06-20 01:30:22 +01:00
|
|
|
/* find headers. */
|
|
|
|
#include "defs.h"
|
2018-02-02 22:40:42 +01:00
|
|
|
#include "system.h"
|
2005-12-23 17:34:28 +00:00
|
|
|
|
|
|
|
|
2005-12-23 18:26:57 +00:00
|
|
|
/* All predicates for each path to process. */
|
2005-12-23 17:34:28 +00:00
|
|
|
static struct predicate *predicates = NULL;
|
2005-12-23 18:26:57 +00:00
|
|
|
|
|
|
|
/* The root of the evaluation tree. */
|
2005-12-23 17:34:28 +00:00
|
|
|
static struct predicate *eval_tree = NULL;
|
|
|
|
|
2005-12-23 19:02:59 +00:00
|
|
|
/* The last predicate allocated. */
|
|
|
|
static struct predicate *last_pred = NULL;
|
2005-12-23 17:34:28 +00:00
|
|
|
|
Savannah bug #23920: warn about -path arguments ending in /.
Savannah bug #23920: warn about -path arguments ending in /.
* find/parser.c (insert_path_check): new function; abstracts the
common functionality of parse_path, parse_ipath, parse_wholename,
parse_iwholename. Also check for a trailing slash and warn about
it (unless $POSIXLY_CORRECT is set). Don't warn if the pattern
also happens to be a start_point, because those could be matched.
(parse_path, parse_ipath, parse_wholename, parse_iwholename): Use
insert_path_check.
* find/tree.c (is_start_point): new function; returns true if the
indidated string matches a start point.
(num_start_points, start_points): new variables, storing the
starting points listed on the command line.
(build_expression_tree): Set num_start_points and start_points.
* find/defs.h: Declare is_start_point.
* doc/find.texi (Full Name Patterns): Explain that candidate names
for -path, -regex etc. will never end in a slash, so "-path /tmp/"
will never match anything.
* find/find.1: Likewise.
2009-07-12 21:49:46 +01:00
|
|
|
/* The starting points. */
|
|
|
|
static char **start_points;
|
|
|
|
static size_t num_start_points = 0;
|
|
|
|
|
|
|
|
|
2005-12-23 17:34:28 +00:00
|
|
|
|
2010-04-18 01:04:52 +01:00
|
|
|
static struct predicate *scan_rest (struct predicate **input,
|
2024-05-26 11:12:59 +01:00
|
|
|
struct predicate *head,
|
|
|
|
short int prev_prec);
|
2010-04-18 01:04:52 +01:00
|
|
|
static void merge_pred (struct predicate *beg_list, struct predicate *end_list, struct predicate **last_p);
|
|
|
|
static struct predicate *set_new_parent (struct predicate *curr, enum predicate_precedence high_prec, struct predicate **prevp);
|
|
|
|
static const char *cost_name (enum EvaluationCost cost);
|
2006-01-04 19:22:38 +00:00
|
|
|
|
1996-02-04 20:35:16 +00:00
|
|
|
|
Savannah bug #23920: warn about -path arguments ending in /.
Savannah bug #23920: warn about -path arguments ending in /.
* find/parser.c (insert_path_check): new function; abstracts the
common functionality of parse_path, parse_ipath, parse_wholename,
parse_iwholename. Also check for a trailing slash and warn about
it (unless $POSIXLY_CORRECT is set). Don't warn if the pattern
also happens to be a start_point, because those could be matched.
(parse_path, parse_ipath, parse_wholename, parse_iwholename): Use
insert_path_check.
* find/tree.c (is_start_point): new function; returns true if the
indidated string matches a start point.
(num_start_points, start_points): new variables, storing the
starting points listed on the command line.
(build_expression_tree): Set num_start_points and start_points.
* find/defs.h: Declare is_start_point.
* doc/find.texi (Full Name Patterns): Explain that candidate names
for -path, -regex etc. will never end in a slash, so "-path /tmp/"
will never match anything.
* find/find.1: Likewise.
2009-07-12 21:49:46 +01:00
|
|
|
/* Return true if the indicated path name is a start
|
|
|
|
point or not. If no start points were given on the
|
|
|
|
command line, we return true for ".".
|
|
|
|
*/
|
2010-04-05 20:52:45 +01:00
|
|
|
bool
|
2010-03-31 23:20:33 +01:00
|
|
|
matches_start_point (const char *glob, bool foldcase)
|
Savannah bug #23920: warn about -path arguments ending in /.
Savannah bug #23920: warn about -path arguments ending in /.
* find/parser.c (insert_path_check): new function; abstracts the
common functionality of parse_path, parse_ipath, parse_wholename,
parse_iwholename. Also check for a trailing slash and warn about
it (unless $POSIXLY_CORRECT is set). Don't warn if the pattern
also happens to be a start_point, because those could be matched.
(parse_path, parse_ipath, parse_wholename, parse_iwholename): Use
insert_path_check.
* find/tree.c (is_start_point): new function; returns true if the
indidated string matches a start point.
(num_start_points, start_points): new variables, storing the
starting points listed on the command line.
(build_expression_tree): Set num_start_points and start_points.
* find/defs.h: Declare is_start_point.
* doc/find.texi (Full Name Patterns): Explain that candidate names
for -path, -regex etc. will never end in a slash, so "-path /tmp/"
will never match anything.
* find/find.1: Likewise.
2009-07-12 21:49:46 +01:00
|
|
|
{
|
|
|
|
int fnmatch_flags = 0;
|
|
|
|
if (foldcase)
|
|
|
|
fnmatch_flags |= FNM_CASEFOLD;
|
|
|
|
|
|
|
|
if (num_start_points)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
for (i=0; i<num_start_points; i++)
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
if (fnmatch (glob, start_points[i], fnmatch_flags) == 0)
|
|
|
|
return true;
|
|
|
|
}
|
Savannah bug #23920: warn about -path arguments ending in /.
Savannah bug #23920: warn about -path arguments ending in /.
* find/parser.c (insert_path_check): new function; abstracts the
common functionality of parse_path, parse_ipath, parse_wholename,
parse_iwholename. Also check for a trailing slash and warn about
it (unless $POSIXLY_CORRECT is set). Don't warn if the pattern
also happens to be a start_point, because those could be matched.
(parse_path, parse_ipath, parse_wholename, parse_iwholename): Use
insert_path_check.
* find/tree.c (is_start_point): new function; returns true if the
indidated string matches a start point.
(num_start_points, start_points): new variables, storing the
starting points listed on the command line.
(build_expression_tree): Set num_start_points and start_points.
* find/defs.h: Declare is_start_point.
* doc/find.texi (Full Name Patterns): Explain that candidate names
for -path, -regex etc. will never end in a slash, so "-path /tmp/"
will never match anything.
* find/find.1: Likewise.
2009-07-12 21:49:46 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return fnmatch (glob, ".", fnmatch_flags) == 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-02-04 20:35:16 +00:00
|
|
|
/* Return a pointer to a tree that represents the
|
|
|
|
expression prior to non-unary operator *INPUT.
|
|
|
|
Set *INPUT to point at the next input predicate node.
|
|
|
|
|
|
|
|
Only accepts the following:
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
1996-02-04 20:35:16 +00:00
|
|
|
<primary>
|
2024-05-26 11:12:59 +01:00
|
|
|
expression [operators of higher precedence]
|
1996-02-04 20:35:16 +00:00
|
|
|
<uni_op><primary>
|
|
|
|
(arbitrary expression)
|
|
|
|
<uni_op>(arbitrary expression)
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2011-04-02 21:15:20 +01:00
|
|
|
In other words, you cannot start out with a bi_op or close_paren.
|
1996-02-04 20:35:16 +00:00
|
|
|
|
|
|
|
If the following operator (if any) is of a higher precedence than
|
|
|
|
PREV_PREC, the expression just nabbed is part of a following
|
|
|
|
expression, which really is the expression that should be handed to
|
|
|
|
our caller, so get_expr recurses. */
|
|
|
|
|
2011-06-14 23:14:21 +01:00
|
|
|
static struct predicate *
|
2005-12-20 19:22:28 +00:00
|
|
|
get_expr (struct predicate **input,
|
2024-05-26 11:12:59 +01:00
|
|
|
short int prev_prec,
|
|
|
|
const struct predicate* prev_pred)
|
1996-02-04 20:35:16 +00:00
|
|
|
{
|
2004-10-30 15:08:20 +00:00
|
|
|
struct predicate *next = NULL;
|
2005-12-23 16:55:09 +00:00
|
|
|
struct predicate *this_pred = (*input);
|
1996-02-04 20:35:16 +00:00
|
|
|
|
|
|
|
if (*input == NULL)
|
2023-09-30 14:57:05 +02:00
|
|
|
error (EXIT_FAILURE, 0, _("invalid expression"));
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
1996-02-04 20:35:16 +00:00
|
|
|
switch ((*input)->p_type)
|
|
|
|
{
|
|
|
|
case NO_TYPE:
|
2023-09-30 14:57:05 +02:00
|
|
|
error (EXIT_FAILURE, 0, _("invalid expression"));
|
2004-12-12 23:04:03 +00:00
|
|
|
break;
|
|
|
|
|
1996-02-04 20:35:16 +00:00
|
|
|
case BI_OP:
|
2005-12-23 16:55:09 +00:00
|
|
|
/* e.g. "find . -a" */
|
2023-09-30 14:57:05 +02:00
|
|
|
error (EXIT_FAILURE, 0,
|
2024-05-26 11:12:59 +01:00
|
|
|
_("invalid expression; you have used a binary operator '%s' with nothing before it."),
|
|
|
|
this_pred->p_name);
|
2004-12-12 23:04:03 +00:00
|
|
|
break;
|
|
|
|
|
1996-02-04 20:35:16 +00:00
|
|
|
case CLOSE_PAREN:
|
2021-08-07 02:18:05 +02:00
|
|
|
if (prev_pred == NULL)
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
/* Happens with e.g. "find -files0-from - ')' -print" */
|
|
|
|
error (EXIT_FAILURE, 0,
|
|
|
|
_("invalid expression: expected expression before closing parentheses '%s'."),
|
|
|
|
this_pred->p_name);
|
|
|
|
}
|
2021-08-07 02:18:05 +02:00
|
|
|
|
2005-12-23 16:55:09 +00:00
|
|
|
if ((UNI_OP == prev_pred->p_type
|
2024-05-26 11:12:59 +01:00
|
|
|
|| BI_OP == prev_pred->p_type)
|
|
|
|
&& !this_pred->artificial)
|
|
|
|
{
|
|
|
|
/* e.g. "find \( -not \)" or "find \( -true -a \)" */
|
|
|
|
error (EXIT_FAILURE, 0,
|
|
|
|
_("expected an expression between '%s' and ')'"),
|
|
|
|
prev_pred->p_name);
|
|
|
|
}
|
2005-12-23 16:55:09 +00:00
|
|
|
else if ( (*input)->artificial )
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
/* We have reached the end of the user-supplied predicates
|
|
|
|
* unexpectedly.
|
|
|
|
*/
|
|
|
|
/* e.g. "find . -true -a" */
|
|
|
|
error (EXIT_FAILURE, 0,
|
|
|
|
_("expected an expression after '%s'"), prev_pred->p_name);
|
|
|
|
}
|
2005-12-20 19:22:28 +00:00
|
|
|
else
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
error (EXIT_FAILURE, 0,
|
|
|
|
_("invalid expression; you have too many ')'"));
|
|
|
|
}
|
1996-02-04 20:35:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PRIMARY_TYPE:
|
|
|
|
next = *input;
|
|
|
|
*input = (*input)->pred_next;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNI_OP:
|
|
|
|
next = *input;
|
|
|
|
*input = (*input)->pred_next;
|
2005-12-20 19:22:28 +00:00
|
|
|
next->pred_right = get_expr (input, NEGATE_PREC, next);
|
1996-02-04 20:35:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPEN_PAREN:
|
2005-12-23 16:55:09 +00:00
|
|
|
if ( (NULL == (*input)->pred_next) || (*input)->pred_next->artificial )
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
/* user typed something like "find . (", and so the ) we are
|
|
|
|
* looking at is from the artificial "( ) -print" that we
|
|
|
|
* add.
|
|
|
|
*/
|
|
|
|
error (EXIT_FAILURE, 0,
|
|
|
|
_("invalid expression; expected to find a ')' but didn't see one. "
|
|
|
|
"Perhaps you need an extra predicate after '%s'"),
|
|
|
|
this_pred->p_name);
|
|
|
|
}
|
2005-12-20 19:22:28 +00:00
|
|
|
prev_pred = (*input);
|
1996-02-04 20:35:16 +00:00
|
|
|
*input = (*input)->pred_next;
|
2005-12-20 07:26:19 +00:00
|
|
|
if ( (*input)->p_type == CLOSE_PAREN )
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
if (prev_pred->artificial)
|
|
|
|
{
|
|
|
|
error (EXIT_FAILURE, 0,
|
|
|
|
_("invalid expression: expected expression before closing parentheses '%s'."),
|
|
|
|
(*input)->p_name);
|
|
|
|
}
|
|
|
|
error (EXIT_FAILURE, 0,
|
|
|
|
_("invalid expression; empty parentheses are not allowed."));
|
|
|
|
}
|
2005-12-20 19:22:28 +00:00
|
|
|
next = get_expr (input, NO_PREC, prev_pred);
|
1996-02-04 20:35:16 +00:00
|
|
|
if ((*input == NULL)
|
2024-05-26 11:12:59 +01:00
|
|
|
|| ((*input)->p_type != CLOSE_PAREN))
|
|
|
|
error (EXIT_FAILURE, 0,
|
|
|
|
_("invalid expression; I was expecting to find a ')' somewhere "
|
|
|
|
"but did not see one."));
|
2010-04-02 17:47:39 +01:00
|
|
|
|
2024-05-26 11:12:59 +01:00
|
|
|
*input = (*input)->pred_next; /* move over close */
|
1996-02-04 20:35:16 +00:00
|
|
|
break;
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
1996-02-04 20:35:16 +00:00
|
|
|
default:
|
2023-09-30 14:57:05 +02:00
|
|
|
error (EXIT_FAILURE, 0, _("oops -- invalid expression type!"));
|
1996-02-04 20:35:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We now have the first expression and are positioned to check
|
|
|
|
out the next operator. If NULL, all done. Otherwise, if
|
|
|
|
PREV_PREC < the current node precedence, we must continue;
|
|
|
|
the expression we just nabbed is more tightly bound to the
|
|
|
|
following expression than to the previous one. */
|
|
|
|
if (*input == NULL)
|
|
|
|
return (next);
|
|
|
|
if ((int) (*input)->p_prec > (int) prev_prec)
|
|
|
|
{
|
|
|
|
next = scan_rest (input, next, prev_prec);
|
|
|
|
if (next == NULL)
|
2024-05-26 11:12:59 +01:00
|
|
|
error (EXIT_FAILURE, 0, _("invalid expression"));
|
1996-02-04 20:35:16 +00:00
|
|
|
}
|
|
|
|
return (next);
|
|
|
|
}
|
2010-04-06 01:03:33 +01:00
|
|
|
|
1996-02-04 20:35:16 +00:00
|
|
|
/* Scan across the remainder of a predicate input list starting
|
|
|
|
at *INPUT, building the rest of the expression tree to return.
|
|
|
|
Stop at the first close parenthesis or the end of the input list.
|
|
|
|
Assumes that get_expr has been called to nab the first element
|
|
|
|
of the expression tree.
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
1996-02-04 20:35:16 +00:00
|
|
|
*INPUT points to the current input predicate list element.
|
|
|
|
It is updated as we move along the list to point to the
|
|
|
|
terminating input element.
|
|
|
|
HEAD points to the predicate element that was obtained
|
|
|
|
by the call to get_expr.
|
|
|
|
PREV_PREC is the precedence of the previous predicate element. */
|
|
|
|
|
|
|
|
static struct predicate *
|
2000-04-05 07:59:22 +00:00
|
|
|
scan_rest (struct predicate **input,
|
2024-05-26 11:12:59 +01:00
|
|
|
struct predicate *head,
|
|
|
|
short int prev_prec)
|
1996-02-04 20:35:16 +00:00
|
|
|
{
|
2024-05-26 11:12:59 +01:00
|
|
|
struct predicate *tree; /* The new tree we are building. */
|
1996-02-04 20:35:16 +00:00
|
|
|
|
|
|
|
if ((*input == NULL) || ((*input)->p_type == CLOSE_PAREN))
|
|
|
|
return (NULL);
|
|
|
|
tree = head;
|
|
|
|
while ((*input != NULL) && ((int) (*input)->p_prec > (int) prev_prec))
|
|
|
|
{
|
|
|
|
switch ((*input)->p_type)
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
case NO_TYPE:
|
|
|
|
case PRIMARY_TYPE:
|
|
|
|
case UNI_OP:
|
|
|
|
case OPEN_PAREN:
|
|
|
|
/* I'm not sure how we get here, so it is not obvious what
|
|
|
|
* sort of mistakes might give rise to this condition.
|
|
|
|
*/
|
|
|
|
error (EXIT_FAILURE, 0, _("invalid expression"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BI_OP:
|
|
|
|
{
|
|
|
|
struct predicate *prev = (*input);
|
|
|
|
(*input)->pred_left = tree;
|
|
|
|
tree = *input;
|
|
|
|
*input = (*input)->pred_next;
|
|
|
|
tree->pred_right = get_expr (input, tree->p_prec, prev);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CLOSE_PAREN:
|
|
|
|
return tree;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error (EXIT_FAILURE, 0,
|
|
|
|
_("oops -- invalid expression type (%d)!"),
|
|
|
|
(int)(*input)->p_type);
|
|
|
|
break;
|
|
|
|
}
|
1996-02-04 20:35:16 +00:00
|
|
|
}
|
2004-12-12 23:04:03 +00:00
|
|
|
return tree;
|
1996-02-04 20:35:16 +00:00
|
|
|
}
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
/* Returns true if the specified predicate is reorderable. */
|
2010-04-05 20:52:45 +01:00
|
|
|
static bool
|
2010-03-31 23:20:33 +01:00
|
|
|
predicate_is_cost_free (const struct predicate *p)
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
2007-04-23 09:17:37 +00:00
|
|
|
if (pred_is(p, pred_name) ||
|
|
|
|
pred_is(p, pred_path) ||
|
|
|
|
pred_is(p, pred_iname) ||
|
|
|
|
pred_is(p, pred_ipath))
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
/* Traditionally (at least 4.1.7 through 4.2.x) GNU find always
|
2024-05-27 20:11:31 +01:00
|
|
|
* optimized these cases.
|
2006-01-04 19:22:38 +00:00
|
|
|
*/
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (options.optimisation_level > 0)
|
|
|
|
{
|
2007-04-23 09:17:37 +00:00
|
|
|
if (pred_is(p, pred_and) ||
|
2024-05-26 11:12:59 +01:00
|
|
|
pred_is(p, pred_negate) ||
|
|
|
|
pred_is(p, pred_comma) ||
|
|
|
|
pred_is(p, pred_or))
|
|
|
|
return false;
|
2006-01-04 19:22:38 +00:00
|
|
|
else
|
2024-05-26 11:12:59 +01:00
|
|
|
return NeedsNothing == p->p_cost;
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
/* Prints a predicate */
|
2010-03-31 23:20:33 +01:00
|
|
|
void print_predicate (FILE *fp, const struct predicate *p)
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
Fix Savannah bug #27017: find -D opt / -fstype ext3 -print , -quit coredump (vs. 4.5.x)
Fix Savannah bug #27017: find -D opt / -fstype ext3 -print , -quit
coredumps.
* find/tree.c (set_new_parent): Initialise struct
predicate->arg_text to NULL (instead of leaving it uninitialised).
(get_new_pred_noarg): Likewise.
(get_new_pred): Initialise predicate->arg_text to
"ThisShouldBeSetToSomethingElse" to make it easier to notice
bugs.
(get_new_pred_chk_op): Use get_new_pred_noarg.
(print_predicate): Use an if statement instead of
two ternary operators.
* find/util.c (insert_primary_withpred): Accept new argument, arg,
being the argument (if any) of this predicate. Pass it to
get_new_pred_chk_op.
(insert_primary): Likewise (pass arg to insert_primary_withpred).
(insert_primary_noarg): New function; calls insert_primary with
arg=NULL.
* find/parser.c (collect_arg_stat_info): Add an output parameter;
the filename from which we collected the stat information.
(parse_closeparen, parse_delete, parse_and, parse_or,
parse_comma): Use get_new_pred_noarg.
(parse_cnewer, parse_newer, parse_anewer): Use new
collect_arg_stat_info and insert_primary interface.
(parse_print, parse_prune, parse_nouser, parse_empty): Use
insert_primary_noarg.
(parse_accesscheck, parse_false): Use insert_primary_noarg.
(parse_used, parse_iname, parse_fprint, insert_fprint,
parse_fstype, parse_ilname): Use new collect_arg and
insert_primary interfaces.
(parse_ipath, parse_lname, do_parse_xmin, parse_name, parse_path,
parse_perm, parse_size, parse_user, parse_time): Use new
collect_arg and insert_primary_withpred interface.
(parse_negate, parse_openparen): Use new get_new_pred_chk_op interface.
(parse_newerXY, parse_nogroup): Use new insert_primary interface.
(insert_regex, parse_samefile): Use new insert_primary_withpred
interface.
(insert_type, insert_fprintf, new_insert_exec_ok, insert_num): Use
new insert_primary_withpred interface.
* find/defs.h (struct predicate.arg_text): make const.
Add declarations for new function get_new_pred_noarg and
insert_primary_noarg. Add 'arg' parameter to get_new_pred_chk_op
and insert_primary_withpred.
2009-07-11 19:55:27 +01:00
|
|
|
if (p->arg_text)
|
|
|
|
{
|
|
|
|
fprintf (fp, "%s %s", p->p_name, p->arg_text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf (fp, "%s", p->p_name);
|
|
|
|
}
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
|
|
|
|
2010-04-06 01:03:33 +01:00
|
|
|
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
struct predlist
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
struct predicate *head;
|
|
|
|
struct predicate *tail;
|
|
|
|
};
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
static void
|
2010-03-31 23:20:33 +01:00
|
|
|
predlist_init (struct predlist *p)
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
p->head = p->tail = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-31 23:20:33 +01:00
|
|
|
predlist_insert (struct predlist *list,
|
2024-05-26 11:12:59 +01:00
|
|
|
struct predicate *curr,
|
|
|
|
struct predicate **pprev)
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
struct predicate **insertpos = &(list->head);
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
*pprev = curr->pred_left;
|
|
|
|
curr->pred_left = (*insertpos);
|
|
|
|
(*insertpos) = curr;
|
|
|
|
if (NULL == list->tail)
|
|
|
|
list->tail = list->head;
|
|
|
|
}
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
static int
|
2010-04-05 20:52:45 +01:00
|
|
|
pred_cost_compare (const struct predicate *p1, const struct predicate *p2, bool wantfailure)
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
if (p1->p_cost == p2->p_cost)
|
|
|
|
{
|
|
|
|
if (p1->est_success_rate == p2->est_success_rate)
|
2024-05-26 11:12:59 +01:00
|
|
|
return 0;
|
2006-01-04 19:22:38 +00:00
|
|
|
else if (wantfailure)
|
2024-05-26 11:12:59 +01:00
|
|
|
return p1->est_success_rate < p2->est_success_rate ? -1 : 1;
|
2006-01-04 19:22:38 +00:00
|
|
|
else
|
2024-05-26 11:12:59 +01:00
|
|
|
return p1->est_success_rate < p2->est_success_rate ? 1 : -1;
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
else
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
return p1->p_cost < p2->p_cost ? -1 : 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-06 01:03:33 +01:00
|
|
|
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
static void
|
2010-03-31 23:20:33 +01:00
|
|
|
predlist_merge_sort (struct predlist *list,
|
2024-05-26 11:12:59 +01:00
|
|
|
struct predicate **last)
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
struct predlist new_list;
|
|
|
|
struct predicate *p, *q;
|
|
|
|
|
|
|
|
if (NULL == list->head)
|
2024-05-26 11:12:59 +01:00
|
|
|
return; /* nothing to do */
|
2006-01-04 19:22:38 +00:00
|
|
|
|
|
|
|
if (options.debug_options & DebugTreeOpt)
|
|
|
|
{
|
2010-03-31 23:20:33 +01:00
|
|
|
fprintf (stderr, "%s:\n", "predlist before merge sort");
|
|
|
|
print_tree (stderr, list->head, 2);
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2010-03-31 23:20:33 +01:00
|
|
|
calculate_derived_rates (list->head);
|
|
|
|
predlist_init (&new_list);
|
2006-01-04 19:22:38 +00:00
|
|
|
while (list->head)
|
|
|
|
{
|
|
|
|
/* remove head of source list */
|
|
|
|
q = list->head;
|
|
|
|
list->head = list->head->pred_left;
|
|
|
|
q->pred_left = NULL;
|
|
|
|
|
|
|
|
/* insert it into the new list */
|
|
|
|
for (p=new_list.head; p; p=p->pred_left)
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
/* If these operations are OR operations, we want to get a
|
|
|
|
* successful test as soon as possible, to take advantage of
|
|
|
|
* the short-circuit evaluation. If they're AND, we want to
|
|
|
|
* get an unsuccessful result early for the same reason.
|
|
|
|
* Therefore we invert the sense of the comparison for the
|
|
|
|
* OR case. We only want to invert the sense of the success
|
|
|
|
* rate comparison, not the operation cost comparison. Hence we
|
|
|
|
* pass a flag into pred_cost_compare().
|
|
|
|
*/
|
|
|
|
const bool wantfailure = (OR_PREC != p->p_prec);
|
|
|
|
if (pred_cost_compare (p->pred_right, q->pred_right, wantfailure) >= 0)
|
|
|
|
break;
|
|
|
|
}
|
2006-01-04 19:22:38 +00:00
|
|
|
if (p)
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
/* insert into existing list */
|
|
|
|
q->pred_left = p->pred_left;
|
|
|
|
if (NULL == q->pred_left)
|
|
|
|
new_list.tail = q;
|
|
|
|
p->pred_left = q;
|
|
|
|
}
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
else
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
q->pred_left = new_list.head; /* prepend */
|
|
|
|
new_list.head = q;
|
|
|
|
if (NULL == new_list.tail)
|
|
|
|
new_list.tail = q; /* first item in new list */
|
|
|
|
}
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
|
|
|
if (options.debug_options & DebugTreeOpt)
|
|
|
|
{
|
2010-03-31 23:20:33 +01:00
|
|
|
fprintf (stderr, "%s:\n", "predlist after merge sort");
|
|
|
|
print_tree (stderr, new_list.head, 2);
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
calculate_derived_rates(new_list.head);
|
2010-03-31 23:20:33 +01:00
|
|
|
merge_pred (new_list.head, new_list.tail, last);
|
|
|
|
predlist_init (list);
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
2010-04-06 01:03:33 +01:00
|
|
|
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
static void
|
2010-03-31 23:20:33 +01:00
|
|
|
merge_lists (struct predlist lists[], int nlists,
|
2024-05-26 11:12:59 +01:00
|
|
|
struct predlist *name_list,
|
|
|
|
struct predlist *regex_list,
|
|
|
|
struct predicate **last)
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
static void (*mergefn)(struct predlist *, struct predicate**);
|
|
|
|
|
|
|
|
mergefn = predlist_merge_sort;
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2010-03-31 23:20:33 +01:00
|
|
|
mergefn (name_list, last);
|
|
|
|
mergefn (regex_list, last);
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
for (i=0; i<nlists; i++)
|
2010-03-31 23:20:33 +01:00
|
|
|
mergefn (&lists[i], last);
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2010-04-05 20:52:45 +01:00
|
|
|
static bool
|
2010-03-31 23:20:33 +01:00
|
|
|
subtree_has_side_effects (const struct predicate *p)
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
return p->side_effects
|
2024-05-26 11:12:59 +01:00
|
|
|
|| subtree_has_side_effects (p->pred_left)
|
|
|
|
|| subtree_has_side_effects (p->pred_right);
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
static int
|
|
|
|
worst_cost (const struct predicate *p)
|
|
|
|
{
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
unsigned int cost_r, cost_l, worst;
|
2010-03-31 23:20:33 +01:00
|
|
|
cost_l = worst_cost (p->pred_left);
|
|
|
|
cost_r = worst_cost (p->pred_right);
|
2006-01-04 19:22:38 +00:00
|
|
|
worst = (cost_l > cost_r) ? cost_l : cost_r;
|
|
|
|
if (worst < p->p_cost)
|
2024-05-26 11:12:59 +01:00
|
|
|
worst = p->p_cost;
|
2006-01-04 19:22:38 +00:00
|
|
|
return worst;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
static void
|
2010-03-31 23:20:33 +01:00
|
|
|
perform_arm_swap (struct predicate *p)
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
struct predicate *tmp = p->pred_left->pred_right;
|
|
|
|
p->pred_left->pred_right = p->pred_right;
|
|
|
|
p->pred_right = tmp;
|
|
|
|
}
|
2010-04-06 01:03:33 +01:00
|
|
|
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
/* Consider swapping p->pred_left->pred_right with p->pred_right,
|
|
|
|
* if that yields a faster evaluation. Normally the left predicate is
|
2006-01-04 19:22:38 +00:00
|
|
|
* evaluated first.
|
|
|
|
*
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
* If the operation is an OR, we want the left predicate to be the one that
|
|
|
|
* succeeds most often. If it is an AND, we want it to be the predicate that
|
2006-01-04 19:22:38 +00:00
|
|
|
* fails most often.
|
|
|
|
*
|
|
|
|
* We don't consider swapping arms of an operator where their cost is
|
|
|
|
* different or where they have side effects.
|
|
|
|
*
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
* A viable test case for this is
|
2006-01-04 19:22:38 +00:00
|
|
|
* ./find -D opt -O3 . \! -type f -o -type d
|
|
|
|
* Here, the ! -type f should be evaluated first,
|
|
|
|
* as we assume that 95% of inodes are vanilla files.
|
|
|
|
*/
|
2010-04-05 20:52:45 +01:00
|
|
|
static bool
|
2010-03-31 23:20:33 +01:00
|
|
|
consider_arm_swap (struct predicate *p)
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
int left_cost, right_cost;
|
|
|
|
const char *reason = NULL;
|
2024-05-19 22:23:19 +01:00
|
|
|
struct predicate **pl = NULL, **pr = NULL;
|
2006-01-04 19:22:38 +00:00
|
|
|
|
|
|
|
if (BI_OP != p->p_type)
|
|
|
|
reason = "Not a binary operation";
|
|
|
|
|
|
|
|
if (!reason)
|
|
|
|
{
|
|
|
|
if (NULL == p->pred_left || NULL == p->pred_right)
|
2024-05-26 11:12:59 +01:00
|
|
|
reason = "Doesn't have two arms";
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!reason)
|
|
|
|
{
|
|
|
|
if (NULL == p->pred_left->pred_right)
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
reason = "Left arm has no child on RHS";
|
|
|
|
}
|
2024-05-19 22:23:19 +01:00
|
|
|
else
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
pr = &p->pred_right;
|
|
|
|
pl = &p->pred_left->pred_right;
|
|
|
|
}
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
if (!reason)
|
|
|
|
{
|
2010-03-31 23:20:33 +01:00
|
|
|
if (subtree_has_side_effects (*pl))
|
2024-05-26 11:12:59 +01:00
|
|
|
reason = "Left subtree has side-effects";
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
|
|
|
if (!reason)
|
|
|
|
{
|
2010-03-31 23:20:33 +01:00
|
|
|
if (subtree_has_side_effects (*pr))
|
2024-05-26 11:12:59 +01:00
|
|
|
reason = "Right subtree has side-effects";
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!reason)
|
|
|
|
{
|
2010-03-31 23:20:33 +01:00
|
|
|
left_cost = worst_cost (*pl);
|
|
|
|
right_cost = worst_cost (*pr);
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
if (left_cost < right_cost)
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
reason = "efficient as-is";
|
|
|
|
}
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
|
|
|
if (!reason)
|
|
|
|
{
|
2010-04-05 20:52:45 +01:00
|
|
|
bool want_swap;
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
if (left_cost == right_cost)
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
/* it's a candidate */
|
|
|
|
float succ_rate_l = (*pl)->est_success_rate;
|
|
|
|
float succ_rate_r = (*pr)->est_success_rate;
|
|
|
|
|
|
|
|
if (options.debug_options & DebugTreeOpt)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Success rates: l=%f, r=%f\n", succ_rate_l, succ_rate_r);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pred_is (p, pred_or))
|
|
|
|
{
|
|
|
|
want_swap = succ_rate_r < succ_rate_l;
|
|
|
|
if (!want_swap)
|
|
|
|
reason = "Operation is OR; right success rate >= left";
|
|
|
|
}
|
|
|
|
else if (pred_is (p, pred_and))
|
|
|
|
{
|
|
|
|
want_swap = succ_rate_r > succ_rate_l;
|
|
|
|
if (!want_swap)
|
|
|
|
reason = "Operation is AND; right success rate <= left";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
want_swap = false;
|
|
|
|
reason = "Not 'AND' or 'OR'";
|
|
|
|
}
|
|
|
|
}
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
else
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
want_swap = true;
|
|
|
|
}
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
if (want_swap)
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
if (options.debug_options & DebugTreeOpt)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Performing arm swap on:\n");
|
|
|
|
print_tree (stderr, p, 0);
|
|
|
|
}
|
|
|
|
perform_arm_swap (p);
|
|
|
|
return true;
|
|
|
|
}
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
|
|
|
|
if (options.debug_options & DebugTreeOpt)
|
|
|
|
{
|
2010-03-31 23:20:33 +01:00
|
|
|
fprintf (stderr, "Not an arm swap candidate (%s):\n", reason);
|
2006-01-04 19:22:38 +00:00
|
|
|
print_tree (stderr, p, 0);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2010-04-05 20:52:45 +01:00
|
|
|
static bool
|
2010-03-31 23:20:33 +01:00
|
|
|
do_arm_swaps (struct predicate *p)
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
if (p)
|
|
|
|
{
|
2010-04-05 20:52:45 +01:00
|
|
|
bool swapped;
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
do
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
swapped = false;
|
|
|
|
if (consider_arm_swap (p)
|
|
|
|
|| do_arm_swaps (p->pred_left)
|
|
|
|
|| do_arm_swaps (p->pred_right))
|
|
|
|
{
|
|
|
|
swapped = true;
|
|
|
|
}
|
|
|
|
} while (swapped);
|
2006-01-04 19:22:38 +00:00
|
|
|
return swapped;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-06 01:03:33 +01:00
|
|
|
|
1996-02-04 20:35:16 +00:00
|
|
|
/* Optimize the ordering of the predicates in the tree. Rearrange
|
|
|
|
them to minimize work. Strategies:
|
|
|
|
* Evaluate predicates that don't need inode information first;
|
|
|
|
the predicates are divided into 1 or more groups separated by
|
|
|
|
predicates (if any) which have "side effects", such as printing.
|
|
|
|
The grouping implements the partial ordering on predicates which
|
|
|
|
those with side effects impose.
|
2000-10-09 21:02:00 +00:00
|
|
|
|
|
|
|
* Place -name, -iname, -path, -ipath, -regex and -iregex at the front
|
|
|
|
of a group, with -name, -iname, -path and -ipath ahead of
|
|
|
|
-regex and -iregex. Predicates which are moved to the front
|
|
|
|
of a group by definition do not have side effects. Both
|
|
|
|
-regex and -iregex both use pred_regex.
|
1996-02-04 20:35:16 +00:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
If higher optimisation levels have been selected, reordering also
|
|
|
|
occurs according to the p_cost member of each predicate (which
|
|
|
|
reflects the performance cost of the test). The ordering also
|
|
|
|
bears in mind whether these operations are more likely to succeed
|
2020-05-23 17:05:13 +02:00
|
|
|
or fail. When evaluating a chain of OR conditions, we prefer
|
2006-01-04 19:22:38 +00:00
|
|
|
tests likely to succeed at the front of the list. For AND, we
|
|
|
|
prefer tests likely to fail at the front of the list.
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2011-06-05 01:08:47 +01:00
|
|
|
This routine "normalizes" the predicate tree by ensuring that all
|
|
|
|
expression predicates have 'AND' (or 'OR' or 'COMMA') parent
|
|
|
|
nodes which are linked along the left edge of the expression
|
|
|
|
tree. This makes manipulation of subtrees easier.
|
1996-02-04 20:35:16 +00:00
|
|
|
|
|
|
|
EVAL_TREEP points to the root pointer of the predicate tree
|
|
|
|
to be rearranged. opt_expr may return a new root pointer there.
|
|
|
|
Return true if the tree contains side effects, false if not. */
|
|
|
|
|
2010-04-05 20:52:45 +01:00
|
|
|
static bool
|
2000-04-05 07:59:22 +00:00
|
|
|
opt_expr (struct predicate **eval_treep)
|
1996-02-04 20:35:16 +00:00
|
|
|
{
|
2006-01-04 19:22:38 +00:00
|
|
|
struct predlist regex_list={NULL,NULL}, name_list={NULL,NULL};
|
|
|
|
struct predlist cbo_list[NumEvaluationCosts];
|
|
|
|
int i;
|
1996-02-04 20:35:16 +00:00
|
|
|
struct predicate *curr;
|
2024-05-26 11:12:59 +01:00
|
|
|
struct predicate **prevp; /* Address of `curr' node. */
|
1996-02-04 20:35:16 +00:00
|
|
|
struct predicate **last_sidep; /* Last predicate with side effects. */
|
2005-06-07 20:38:56 +00:00
|
|
|
PRED_FUNC pred_func;
|
1996-02-04 20:35:16 +00:00
|
|
|
enum predicate_type p_type;
|
2010-04-05 20:52:45 +01:00
|
|
|
bool has_side_effects = false; /* Return value. */
|
1996-02-04 20:35:16 +00:00
|
|
|
enum predicate_precedence prev_prec, /* precedence of last BI_OP in branch */
|
2024-05-26 11:12:59 +01:00
|
|
|
biop_prec; /* topmost BI_OP precedence in branch */
|
1996-02-04 20:35:16 +00:00
|
|
|
|
|
|
|
if (eval_treep == NULL || *eval_treep == NULL)
|
|
|
|
return (false);
|
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
for (i=0; i<NumEvaluationCosts; i++)
|
2010-03-31 23:20:33 +01:00
|
|
|
predlist_init (&cbo_list[i]);
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
1996-02-04 20:35:16 +00:00
|
|
|
/* Set up to normalize tree as a left-linked list of ANDs or ORs.
|
|
|
|
Set `curr' to the leftmost node, `prevp' to its address, and
|
|
|
|
`pred_func' to the predicate type of its parent. */
|
|
|
|
prevp = eval_treep;
|
|
|
|
prev_prec = AND_PREC;
|
|
|
|
curr = *prevp;
|
|
|
|
while (curr->pred_left != NULL)
|
|
|
|
{
|
|
|
|
prevp = &curr->pred_left;
|
2024-05-26 11:12:59 +01:00
|
|
|
prev_prec = curr->p_prec; /* must be a BI_OP */
|
1996-02-04 20:35:16 +00:00
|
|
|
curr = curr->pred_left;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Link in the appropriate BI_OP for the last expression, if needed. */
|
|
|
|
if (curr->p_type != BI_OP)
|
|
|
|
set_new_parent (curr, prev_prec, prevp);
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
if (options.debug_options & (DebugExpressionTree|DebugTreeOpt))
|
|
|
|
{
|
|
|
|
/* Normalized tree. */
|
|
|
|
fprintf (stderr, "Normalized Eval Tree:\n");
|
|
|
|
print_tree (stderr, *eval_treep, 0);
|
|
|
|
}
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
1996-02-04 20:35:16 +00:00
|
|
|
/* Rearrange the predicates. */
|
|
|
|
prevp = eval_treep;
|
2004-10-30 15:08:20 +00:00
|
|
|
biop_prec = NO_PREC; /* not COMMA_PREC */
|
1996-02-04 20:35:16 +00:00
|
|
|
if ((*prevp) && (*prevp)->p_type == BI_OP)
|
|
|
|
biop_prec = (*prevp)->p_prec;
|
|
|
|
while ((curr = *prevp) != NULL)
|
|
|
|
{
|
|
|
|
/* If there is a BI_OP of different precedence from the first
|
2024-05-26 11:12:59 +01:00
|
|
|
in the pred_left chain, create a new parent of the
|
|
|
|
original precedence, link the new parent to the left of the
|
|
|
|
previous and link CURR to the right of the new parent.
|
|
|
|
This preserves the precedence of expressions in the tree
|
|
|
|
in case we rearrange them. */
|
1996-02-04 20:35:16 +00:00
|
|
|
if (curr->p_type == BI_OP)
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
1996-02-04 20:35:16 +00:00
|
|
|
if (curr->p_prec != biop_prec)
|
2024-05-26 11:12:59 +01:00
|
|
|
curr = set_new_parent (curr, biop_prec, prevp);
|
|
|
|
}
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
1996-02-04 20:35:16 +00:00
|
|
|
/* See which predicate type we have. */
|
|
|
|
p_type = curr->pred_right->p_type;
|
|
|
|
pred_func = curr->pred_right->pred_func;
|
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
|
1996-02-04 20:35:16 +00:00
|
|
|
switch (p_type)
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
case NO_TYPE:
|
|
|
|
case PRIMARY_TYPE:
|
|
|
|
/* Don't rearrange the arguments of the comma operator, it is
|
|
|
|
not commutative. */
|
|
|
|
if (biop_prec == COMMA_PREC)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* If this predicate has no side effects, consider reordering it. */
|
|
|
|
if (!curr->pred_right->side_effects)
|
|
|
|
{
|
|
|
|
bool reorder;
|
|
|
|
|
|
|
|
/* If it's one of our special primaries, move it to the
|
|
|
|
front of the list for that primary. */
|
|
|
|
if (predicate_is_cost_free (curr->pred_right))
|
|
|
|
{
|
|
|
|
if (options.debug_options & DebugTreeOpt)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "-O%d: promoting cheap predicate ",
|
|
|
|
(int)options.optimisation_level);
|
|
|
|
print_predicate (stderr, curr->pred_right);
|
|
|
|
fprintf (stderr, " into name_list\n");
|
|
|
|
}
|
|
|
|
predlist_insert (&name_list, curr, prevp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pred_func == pred_regex)
|
|
|
|
{
|
|
|
|
predlist_insert (®ex_list, curr, prevp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
reorder = ((options.optimisation_level > 1)
|
|
|
|
&& (NeedsType == curr->pred_right->p_cost
|
|
|
|
|| NeedsInodeNumber == curr->pred_right->p_cost)
|
|
|
|
&& !curr->pred_right->need_stat) ||
|
|
|
|
(options.optimisation_level > 2);
|
|
|
|
|
|
|
|
if (reorder)
|
|
|
|
{
|
|
|
|
if (options.debug_options & DebugTreeOpt)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "-O%d: categorising predicate ",
|
|
|
|
(int)options.optimisation_level);
|
|
|
|
print_predicate (stderr, curr->pred_right);
|
|
|
|
fprintf (stderr, " by cost (%s)\n",
|
|
|
|
cost_name(curr->pred_right->p_cost));
|
|
|
|
}
|
|
|
|
predlist_insert (&cbo_list[curr->pred_right->p_cost], curr, prevp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UNI_OP:
|
|
|
|
/* For NOT, check the expression trees below the NOT. */
|
|
|
|
curr->pred_right->side_effects
|
|
|
|
= opt_expr (&curr->pred_right->pred_right);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BI_OP:
|
|
|
|
/* For nested 'AND' or 'OR', recurse (AND/OR form layers on
|
|
|
|
the left of the tree), and continue scanning this level
|
|
|
|
of 'AND' or 'OR'. */
|
|
|
|
curr->pred_right->side_effects = opt_expr (&curr->pred_right);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* At this point, get_expr and scan_rest have already removed
|
|
|
|
all of the user's parentheses. */
|
|
|
|
|
|
|
|
default:
|
|
|
|
error (EXIT_FAILURE, 0, _("oops -- invalid expression type!"));
|
|
|
|
break;
|
|
|
|
}
|
1996-02-04 20:35:16 +00:00
|
|
|
|
|
|
|
if (curr->pred_right->side_effects == true)
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
last_sidep = prevp;
|
1996-02-04 20:35:16 +00:00
|
|
|
|
2024-05-26 11:12:59 +01:00
|
|
|
/* Incorporate lists and reset list pointers for this group. */
|
|
|
|
merge_lists (cbo_list, NumEvaluationCosts, &name_list, ®ex_list, last_sidep);
|
|
|
|
has_side_effects = true;
|
|
|
|
}
|
1996-02-04 20:35:16 +00:00
|
|
|
|
|
|
|
prevp = &curr->pred_left;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do final list merges. */
|
|
|
|
last_sidep = prevp;
|
2010-03-31 23:20:33 +01:00
|
|
|
merge_lists (cbo_list, NumEvaluationCosts, &name_list, ®ex_list, last_sidep);
|
2006-01-04 19:22:38 +00:00
|
|
|
return has_side_effects;
|
1996-02-04 20:35:16 +00:00
|
|
|
}
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
static float
|
2010-03-31 23:20:33 +01:00
|
|
|
constrain_rate (float rate)
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
if (rate > 1.0f)
|
|
|
|
return 1.0;
|
|
|
|
else if (rate < 0.0)
|
|
|
|
return 0.0;
|
|
|
|
else
|
|
|
|
return rate;
|
|
|
|
}
|
2010-04-06 01:03:33 +01:00
|
|
|
|
1996-02-04 20:35:16 +00:00
|
|
|
/* Link in a new parent BI_OP node for CURR, at *PREVP, with precedence
|
|
|
|
HIGH_PREC. */
|
|
|
|
|
|
|
|
static struct predicate *
|
2000-04-05 07:59:22 +00:00
|
|
|
set_new_parent (struct predicate *curr, enum predicate_precedence high_prec, struct predicate **prevp)
|
1996-02-04 20:35:16 +00:00
|
|
|
{
|
|
|
|
struct predicate *new_parent;
|
|
|
|
|
2016-06-30 01:18:17 +02:00
|
|
|
/* Allocate + initialize a new predicate. */
|
|
|
|
new_parent = xzalloc (sizeof (struct predicate));
|
1996-02-04 20:35:16 +00:00
|
|
|
new_parent->p_type = BI_OP;
|
|
|
|
new_parent->p_prec = high_prec;
|
2006-01-04 19:22:38 +00:00
|
|
|
new_parent->p_cost = NeedsNothing;
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
1996-02-04 20:35:16 +00:00
|
|
|
switch (high_prec)
|
|
|
|
{
|
|
|
|
case COMMA_PREC:
|
|
|
|
new_parent->pred_func = pred_comma;
|
2006-01-04 19:22:38 +00:00
|
|
|
new_parent->p_name = ",";
|
|
|
|
new_parent->est_success_rate = 1.0;
|
1996-02-04 20:35:16 +00:00
|
|
|
break;
|
|
|
|
case OR_PREC:
|
|
|
|
new_parent->pred_func = pred_or;
|
2006-01-04 19:22:38 +00:00
|
|
|
new_parent->p_name = "-o";
|
2010-03-31 23:20:33 +01:00
|
|
|
new_parent->est_success_rate = constrain_rate (curr->est_success_rate);
|
1996-02-04 20:35:16 +00:00
|
|
|
break;
|
|
|
|
case AND_PREC:
|
|
|
|
new_parent->pred_func = pred_and;
|
2006-01-04 19:22:38 +00:00
|
|
|
new_parent->p_name = "-a";
|
2010-03-31 23:20:33 +01:00
|
|
|
new_parent->est_success_rate = constrain_rate (curr->est_success_rate);
|
1996-02-04 20:35:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
2024-05-26 11:12:59 +01:00
|
|
|
; /* empty */
|
1996-02-04 20:35:16 +00:00
|
|
|
}
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
1996-02-04 20:35:16 +00:00
|
|
|
/* Link in new_parent.
|
|
|
|
Pushes rest of left branch down 1 level to new_parent->pred_right. */
|
|
|
|
new_parent->pred_right = curr;
|
|
|
|
*prevp = new_parent;
|
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
return new_parent;
|
1996-02-04 20:35:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Merge the predicate list that starts at BEG_LIST and ends at END_LIST
|
|
|
|
into the tree at LAST_P. */
|
|
|
|
|
|
|
|
static void
|
2000-04-05 07:59:22 +00:00
|
|
|
merge_pred (struct predicate *beg_list, struct predicate *end_list, struct predicate **last_p)
|
1996-02-04 20:35:16 +00:00
|
|
|
{
|
|
|
|
end_list->pred_left = *last_p;
|
|
|
|
*last_p = beg_list;
|
|
|
|
}
|
2010-04-06 01:03:33 +01:00
|
|
|
|
1996-02-04 20:35:16 +00:00
|
|
|
/* Find the first node in expression tree TREE that requires
|
|
|
|
a stat call and mark the operator above it as needing a stat
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
before calling the node. Since the expression precedences
|
1996-02-04 20:35:16 +00:00
|
|
|
are represented in the tree, some preds that need stat may not
|
|
|
|
get executed (because the expression value is determined earlier.)
|
|
|
|
So every expression needing stat must be marked as such, not just
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
the earliest, to be sure to obtain the stat. This still guarantees
|
|
|
|
that a stat is made as late as possible. Return true if the top node
|
1996-02-04 20:35:16 +00:00
|
|
|
in TREE requires a stat, false if not. */
|
|
|
|
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
struct pred_cost_lookup
|
|
|
|
{
|
2007-06-21 23:41:08 +00:00
|
|
|
PRED_FUNC fn;
|
2006-01-04 19:22:38 +00:00
|
|
|
enum EvaluationCost cost;
|
|
|
|
};
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
static struct pred_cost_lookup costlookup[] =
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
{ pred_amin , NeedsStatInfo },
|
|
|
|
{ pred_and , NeedsNothing, },
|
|
|
|
{ pred_anewer , NeedsStatInfo, },
|
|
|
|
{ pred_atime , NeedsStatInfo, },
|
2007-04-29 00:43:07 +00:00
|
|
|
{ pred_closeparen, NeedsNothing },
|
2006-01-04 19:22:38 +00:00
|
|
|
{ pred_cmin , NeedsStatInfo, },
|
|
|
|
{ pred_cnewer , NeedsStatInfo, },
|
|
|
|
{ pred_comma , NeedsNothing, },
|
2009-08-11 16:47:29 +02:00
|
|
|
{ pred_context , NeedsAccessInfo },
|
2006-01-04 19:22:38 +00:00
|
|
|
{ pred_ctime , NeedsStatInfo, },
|
|
|
|
{ pred_delete , NeedsSyncDiskHit },
|
|
|
|
{ pred_empty , NeedsStatInfo },
|
|
|
|
{ pred_exec , NeedsEventualExec },
|
|
|
|
{ pred_execdir , NeedsEventualExec },
|
|
|
|
{ pred_executable, NeedsAccessInfo },
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
{ pred_false , NeedsNothing },
|
|
|
|
{ pred_fprint , NeedsNothing },
|
|
|
|
{ pred_fprint0 , NeedsNothing },
|
|
|
|
{ pred_fprintf , NeedsNothing },
|
2006-01-04 19:22:38 +00:00
|
|
|
{ pred_fstype , NeedsStatInfo }, /* true for amortised cost */
|
|
|
|
{ pred_gid , NeedsStatInfo },
|
|
|
|
{ pred_group , NeedsStatInfo },
|
|
|
|
{ pred_ilname , NeedsLinkName },
|
|
|
|
{ pred_iname , NeedsNothing },
|
2009-03-07 20:16:49 +00:00
|
|
|
{ pred_inum , NeedsInodeNumber },
|
2006-01-04 19:22:38 +00:00
|
|
|
{ pred_ipath , NeedsNothing },
|
|
|
|
{ pred_links , NeedsStatInfo },
|
|
|
|
{ pred_lname , NeedsLinkName },
|
|
|
|
{ pred_ls , NeedsStatInfo },
|
2007-05-06 12:35:07 +00:00
|
|
|
{ pred_fls , NeedsStatInfo },
|
2024-05-26 11:12:59 +01:00
|
|
|
{ pred_mmin , NeedsStatInfo },
|
2006-01-04 19:22:38 +00:00
|
|
|
{ pred_mtime , NeedsStatInfo },
|
2024-05-26 11:12:59 +01:00
|
|
|
{ pred_name , NeedsNothing },
|
2006-01-04 19:22:38 +00:00
|
|
|
{ pred_negate , NeedsNothing, },
|
|
|
|
{ pred_newer , NeedsStatInfo, },
|
2007-03-07 23:18:38 +00:00
|
|
|
{ pred_newerXY , NeedsStatInfo, },
|
2006-01-04 19:22:38 +00:00
|
|
|
{ pred_nogroup , NeedsStatInfo }, /* true for amortised cost if caching is on */
|
|
|
|
{ pred_nouser , NeedsStatInfo }, /* true for amortised cost if caching is on */
|
|
|
|
{ pred_ok , NeedsUserInteraction },
|
|
|
|
{ pred_okdir , NeedsUserInteraction },
|
2007-04-29 00:43:07 +00:00
|
|
|
{ pred_openparen , NeedsNothing },
|
2006-01-04 19:22:38 +00:00
|
|
|
{ pred_or , NeedsNothing, },
|
2024-05-26 11:12:59 +01:00
|
|
|
{ pred_path , NeedsNothing },
|
|
|
|
{ pred_perm , NeedsStatInfo },
|
2006-01-04 19:22:38 +00:00
|
|
|
{ pred_print , NeedsNothing },
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
{ pred_print0 , NeedsNothing },
|
2006-01-04 19:22:38 +00:00
|
|
|
{ pred_prune , NeedsNothing },
|
2024-05-26 11:12:59 +01:00
|
|
|
{ pred_quit , NeedsNothing },
|
2006-01-04 19:22:38 +00:00
|
|
|
{ pred_readable , NeedsAccessInfo },
|
|
|
|
{ pred_regex , NeedsNothing },
|
|
|
|
{ pred_samefile , NeedsStatInfo },
|
|
|
|
{ pred_size , NeedsStatInfo },
|
2024-05-26 11:12:59 +01:00
|
|
|
{ pred_true , NeedsNothing },
|
2006-01-04 19:22:38 +00:00
|
|
|
{ pred_type , NeedsType },
|
|
|
|
{ pred_uid , NeedsStatInfo },
|
|
|
|
{ pred_used , NeedsStatInfo },
|
|
|
|
{ pred_user , NeedsStatInfo },
|
|
|
|
{ pred_writable , NeedsAccessInfo },
|
|
|
|
{ pred_xtype , NeedsType } /* roughly correct unless most files are symlinks */
|
|
|
|
};
|
|
|
|
static int pred_table_sorted = 0;
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2010-04-05 20:52:45 +01:00
|
|
|
static bool
|
2010-03-31 23:20:33 +01:00
|
|
|
check_sorted (void *base, size_t members, size_t membersize,
|
2024-05-26 11:12:59 +01:00
|
|
|
int (*cmpfn)(const void*, const void*))
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
const char *p = base;
|
|
|
|
size_t i;
|
|
|
|
for (i=1u; i<members; ++i)
|
|
|
|
{
|
2010-03-31 23:20:33 +01:00
|
|
|
int result = cmpfn (p+i*membersize, p+(i-1)*membersize);
|
2006-01-04 19:22:38 +00:00
|
|
|
if (result < 0)
|
2024-05-26 11:12:59 +01:00
|
|
|
return false;
|
2010-03-31 23:20:33 +01:00
|
|
|
result = cmpfn (p+(i-1)*membersize, p+i*membersize);
|
2007-06-26 08:24:19 +00:00
|
|
|
assert (result <= 0);
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
static int
|
2010-03-31 23:20:33 +01:00
|
|
|
cost_table_comparison (const void *p1, const void *p2)
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
/* We have to compare the function pointers with memcmp(),
|
|
|
|
* because ISO C does not allow magnitude comparison of
|
2007-06-30 12:21:46 +00:00
|
|
|
* function pointers (just equality testing).
|
|
|
|
*/
|
2006-01-04 19:22:38 +00:00
|
|
|
const struct pred_cost_lookup *pc1 = p1;
|
|
|
|
const struct pred_cost_lookup *pc2 = p2;
|
2007-06-30 12:21:46 +00:00
|
|
|
union {
|
|
|
|
PRED_FUNC pfn;
|
|
|
|
char mem[sizeof (PRED_FUNC)];
|
|
|
|
} u1, u2;
|
|
|
|
|
|
|
|
u1.pfn = pc1->fn;
|
|
|
|
u2.pfn = pc2->fn;
|
2010-03-31 23:20:33 +01:00
|
|
|
return memcmp (u1.mem, u2.mem, sizeof(u1.pfn));
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
static enum EvaluationCost
|
2010-03-31 23:20:33 +01:00
|
|
|
get_pred_cost (const struct predicate *p)
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
enum EvaluationCost data_requirement_cost = NeedsNothing;
|
|
|
|
enum EvaluationCost inherent_cost = NeedsUnknown;
|
|
|
|
|
|
|
|
if (p->need_stat)
|
|
|
|
{
|
|
|
|
data_requirement_cost = NeedsStatInfo;
|
|
|
|
}
|
2009-03-07 20:16:49 +00:00
|
|
|
else if (p->need_inum)
|
|
|
|
{
|
|
|
|
data_requirement_cost = NeedsInodeNumber;
|
|
|
|
}
|
2006-01-04 19:22:38 +00:00
|
|
|
else if (p->need_type)
|
|
|
|
{
|
|
|
|
data_requirement_cost = NeedsType;
|
|
|
|
}
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
else
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
data_requirement_cost = NeedsNothing;
|
|
|
|
}
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2024-05-13 21:56:21 +01:00
|
|
|
if (predicate_uses_exec (p))
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
if (p->args.exec_vec.multiple)
|
2024-05-26 11:12:59 +01:00
|
|
|
inherent_cost = NeedsEventualExec;
|
2006-01-04 19:22:38 +00:00
|
|
|
else
|
2024-05-26 11:12:59 +01:00
|
|
|
inherent_cost = NeedsImmediateExec;
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
2010-03-31 23:20:33 +01:00
|
|
|
else if (pred_is (p, pred_fprintf))
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
/* the parser calculated the cost for us. */
|
|
|
|
inherent_cost = p->p_cost;
|
|
|
|
}
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
else
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
struct pred_cost_lookup key;
|
|
|
|
void *entry;
|
2005-01-23 11:21:34 +00:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
if (!pred_table_sorted)
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
qsort (costlookup,
|
|
|
|
sizeof(costlookup)/sizeof(costlookup[0]),
|
|
|
|
sizeof(costlookup[0]),
|
|
|
|
cost_table_comparison);
|
|
|
|
|
|
|
|
if (!check_sorted (costlookup,
|
|
|
|
sizeof(costlookup)/sizeof(costlookup[0]),
|
|
|
|
sizeof(costlookup[0]),
|
|
|
|
cost_table_comparison))
|
|
|
|
{
|
|
|
|
error (EXIT_FAILURE, 0, _("failed to sort the costlookup array"));
|
|
|
|
}
|
|
|
|
pred_table_sorted = 1;
|
|
|
|
}
|
2006-01-04 19:22:38 +00:00
|
|
|
key.fn = p->pred_func;
|
2010-03-31 23:20:33 +01:00
|
|
|
entry = bsearch (&key, costlookup,
|
2024-05-26 11:12:59 +01:00
|
|
|
sizeof(costlookup)/sizeof(costlookup[0]),
|
|
|
|
sizeof(costlookup[0]),
|
|
|
|
cost_table_comparison);
|
2006-01-04 19:22:38 +00:00
|
|
|
if (entry)
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
inherent_cost = ((const struct pred_cost_lookup*)entry)->cost;
|
|
|
|
}
|
2006-01-04 19:22:38 +00:00
|
|
|
else
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
/* This message indicates a bug. If we issue the message, we
|
|
|
|
actually have two bugs: if find emits a diagnostic, its result
|
|
|
|
should be nonzero. However, not having an entry for a predicate
|
|
|
|
will not affect the output (just the performance) so I think it
|
|
|
|
would be confusing to exit with a nonzero status.
|
|
|
|
*/
|
|
|
|
error (0, 0,
|
|
|
|
_("warning: there is no entry in the predicate evaluation "
|
|
|
|
"cost table for predicate %s; please report this as a bug"),
|
|
|
|
p->p_name);
|
|
|
|
inherent_cost = NeedsUnknown;
|
|
|
|
}
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (inherent_cost > data_requirement_cost)
|
|
|
|
return inherent_cost;
|
|
|
|
else
|
|
|
|
return data_requirement_cost;
|
|
|
|
}
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
static void
|
|
|
|
estimate_costs (struct predicate *tree)
|
|
|
|
{
|
|
|
|
if (tree)
|
|
|
|
{
|
2010-03-31 23:20:33 +01:00
|
|
|
estimate_costs (tree->pred_right);
|
|
|
|
estimate_costs (tree->pred_left);
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
tree->p_cost = get_pred_cost(tree);
|
|
|
|
}
|
|
|
|
}
|
2005-12-23 17:34:28 +00:00
|
|
|
|
|
|
|
struct predicate*
|
2010-03-31 23:20:33 +01:00
|
|
|
get_eval_tree (void)
|
2005-12-23 17:34:28 +00:00
|
|
|
{
|
|
|
|
return eval_tree;
|
|
|
|
}
|
|
|
|
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
static float
|
2010-03-31 23:20:33 +01:00
|
|
|
getrate (const struct predicate *p)
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
if (p)
|
|
|
|
return p->est_success_rate;
|
|
|
|
else
|
2007-02-25 12:05:51 +00:00
|
|
|
return 1.0f;
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
float
|
2010-03-31 23:20:33 +01:00
|
|
|
calculate_derived_rates (struct predicate *p)
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
2007-06-26 08:24:19 +00:00
|
|
|
assert (NULL != p);
|
2006-01-04 19:22:38 +00:00
|
|
|
|
|
|
|
if (p->pred_right)
|
2010-03-31 23:20:33 +01:00
|
|
|
calculate_derived_rates (p->pred_right);
|
2006-01-04 19:22:38 +00:00
|
|
|
if (p->pred_left)
|
2010-03-31 23:20:33 +01:00
|
|
|
calculate_derived_rates (p->pred_left);
|
2006-01-04 19:22:38 +00:00
|
|
|
|
2007-06-26 08:24:19 +00:00
|
|
|
assert (p->p_type != CLOSE_PAREN);
|
|
|
|
assert (p->p_type != OPEN_PAREN);
|
2007-02-25 12:05:51 +00:00
|
|
|
|
|
|
|
switch (p->p_type)
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
2007-02-25 12:05:51 +00:00
|
|
|
case NO_TYPE:
|
2007-06-26 08:24:19 +00:00
|
|
|
assert (NULL == p->pred_right);
|
|
|
|
assert (NULL == p->pred_left);
|
2006-01-04 19:22:38 +00:00
|
|
|
return p->est_success_rate;
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2007-02-25 12:05:51 +00:00
|
|
|
case PRIMARY_TYPE:
|
2007-06-26 08:24:19 +00:00
|
|
|
assert (NULL == p->pred_right);
|
|
|
|
assert (NULL == p->pred_left);
|
2007-02-25 12:05:51 +00:00
|
|
|
return p->est_success_rate;
|
|
|
|
|
|
|
|
case UNI_OP:
|
2006-01-04 19:22:38 +00:00
|
|
|
/* Unary operators must have exactly one operand */
|
2010-03-31 23:20:33 +01:00
|
|
|
assert (pred_is (p, pred_negate));
|
2007-06-26 08:24:19 +00:00
|
|
|
assert (NULL == p->pred_left);
|
2007-02-25 12:05:51 +00:00
|
|
|
p->est_success_rate = (1.0 - p->pred_right->est_success_rate);
|
|
|
|
return p->est_success_rate;
|
|
|
|
|
|
|
|
case BI_OP:
|
|
|
|
{
|
2024-05-26 11:12:59 +01:00
|
|
|
float rate;
|
|
|
|
/* Binary operators must have two operands */
|
|
|
|
if (pred_is (p, pred_and))
|
|
|
|
{
|
|
|
|
rate = getrate (p->pred_right) * getrate(p->pred_left);
|
|
|
|
}
|
|
|
|
else if (pred_is (p, pred_comma))
|
|
|
|
{
|
|
|
|
rate = 1.0f;
|
|
|
|
}
|
|
|
|
else if (pred_is (p, pred_or))
|
|
|
|
{
|
|
|
|
rate = getrate (p->pred_right) + getrate(p->pred_left);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* only and, or and comma are BI_OP. */
|
|
|
|
assert (0);
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
p->est_success_rate = constrain_rate (rate);
|
2007-02-25 12:05:51 +00:00
|
|
|
}
|
|
|
|
return p->est_success_rate;
|
|
|
|
|
|
|
|
case OPEN_PAREN:
|
|
|
|
case CLOSE_PAREN:
|
|
|
|
p->est_success_rate = 1.0;
|
2006-01-04 19:22:38 +00:00
|
|
|
return p->est_success_rate;
|
|
|
|
}
|
2007-06-30 19:34:49 +00:00
|
|
|
assert (0);
|
|
|
|
abort ();
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
/* opt_expr() rearranges predicates such that each left subtree is
|
2011-06-05 01:08:47 +01:00
|
|
|
* rooted at a logical predicate (e.g. '-a' or '-o').
|
|
|
|
* check_normalization() asserts that this property still holds.
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
*
|
2006-01-04 19:22:38 +00:00
|
|
|
*/
|
2010-04-05 20:52:45 +01:00
|
|
|
static void
|
|
|
|
check_normalization (struct predicate *p, bool at_root)
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
if (at_root)
|
|
|
|
{
|
2007-06-26 08:24:19 +00:00
|
|
|
assert (BI_OP == p->p_type);
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (p->pred_left)
|
|
|
|
{
|
2007-06-26 08:24:19 +00:00
|
|
|
assert (BI_OP == p->pred_left->p_type);
|
2006-01-04 19:22:38 +00:00
|
|
|
check_normalization(p->pred_left, false);
|
|
|
|
}
|
|
|
|
if (p->pred_right)
|
|
|
|
{
|
2010-03-31 23:20:33 +01:00
|
|
|
check_normalization (p->pred_right, false);
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
|
|
|
}
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2005-12-23 17:34:28 +00:00
|
|
|
struct predicate*
|
2010-03-31 23:20:33 +01:00
|
|
|
build_expression_tree (int argc, char *argv[], int end_of_leading_options)
|
2005-12-23 17:34:28 +00:00
|
|
|
{
|
|
|
|
const struct parser_table *parse_entry; /* Pointer to the parsing table entry for this expression. */
|
2024-05-26 11:12:59 +01:00
|
|
|
char *predicate_name; /* Name of predicate being parsed. */
|
2005-12-23 17:34:28 +00:00
|
|
|
struct predicate *cur_pred;
|
|
|
|
const struct parser_table *entry_close, *entry_print, *entry_open;
|
2006-01-04 19:22:38 +00:00
|
|
|
int i, oldi;
|
2005-12-23 17:34:28 +00:00
|
|
|
|
|
|
|
predicates = NULL;
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2007-02-24 14:47:27 +00:00
|
|
|
/* Find where in ARGV the predicates begin by skipping the list of
|
Savannah bug #23920: warn about -path arguments ending in /.
Savannah bug #23920: warn about -path arguments ending in /.
* find/parser.c (insert_path_check): new function; abstracts the
common functionality of parse_path, parse_ipath, parse_wholename,
parse_iwholename. Also check for a trailing slash and warn about
it (unless $POSIXLY_CORRECT is set). Don't warn if the pattern
also happens to be a start_point, because those could be matched.
(parse_path, parse_ipath, parse_wholename, parse_iwholename): Use
insert_path_check.
* find/tree.c (is_start_point): new function; returns true if the
indidated string matches a start point.
(num_start_points, start_points): new variables, storing the
starting points listed on the command line.
(build_expression_tree): Set num_start_points and start_points.
* find/defs.h: Declare is_start_point.
* doc/find.texi (Full Name Patterns): Explain that candidate names
for -path, -regex etc. will never end in a slash, so "-path /tmp/"
will never match anything.
* find/find.1: Likewise.
2009-07-12 21:49:46 +01:00
|
|
|
* start points. As a side effect, also figure out which is the
|
|
|
|
* first and last start point.
|
2007-02-24 14:47:27 +00:00
|
|
|
*/
|
Savannah bug #23920: warn about -path arguments ending in /.
Savannah bug #23920: warn about -path arguments ending in /.
* find/parser.c (insert_path_check): new function; abstracts the
common functionality of parse_path, parse_ipath, parse_wholename,
parse_iwholename. Also check for a trailing slash and warn about
it (unless $POSIXLY_CORRECT is set). Don't warn if the pattern
also happens to be a start_point, because those could be matched.
(parse_path, parse_ipath, parse_wholename, parse_iwholename): Use
insert_path_check.
* find/tree.c (is_start_point): new function; returns true if the
indidated string matches a start point.
(num_start_points, start_points): new variables, storing the
starting points listed on the command line.
(build_expression_tree): Set num_start_points and start_points.
* find/defs.h: Declare is_start_point.
* doc/find.texi (Full Name Patterns): Explain that candidate names
for -path, -regex etc. will never end in a slash, so "-path /tmp/"
will never match anything.
* find/find.1: Likewise.
2009-07-12 21:49:46 +01:00
|
|
|
start_points = argv + end_of_leading_options;
|
2005-12-23 17:34:28 +00:00
|
|
|
for (i = end_of_leading_options; i < argc && !looks_like_expression(argv[i], true); i++)
|
|
|
|
{
|
Savannah bug #23920: warn about -path arguments ending in /.
Savannah bug #23920: warn about -path arguments ending in /.
* find/parser.c (insert_path_check): new function; abstracts the
common functionality of parse_path, parse_ipath, parse_wholename,
parse_iwholename. Also check for a trailing slash and warn about
it (unless $POSIXLY_CORRECT is set). Don't warn if the pattern
also happens to be a start_point, because those could be matched.
(parse_path, parse_ipath, parse_wholename, parse_iwholename): Use
insert_path_check.
* find/tree.c (is_start_point): new function; returns true if the
indidated string matches a start point.
(num_start_points, start_points): new variables, storing the
starting points listed on the command line.
(build_expression_tree): Set num_start_points and start_points.
* find/defs.h: Declare is_start_point.
* doc/find.texi (Full Name Patterns): Explain that candidate names
for -path, -regex etc. will never end in a slash, so "-path /tmp/"
will never match anything.
* find/find.1: Likewise.
2009-07-12 21:49:46 +01:00
|
|
|
++num_start_points;
|
2005-12-23 17:34:28 +00:00
|
|
|
}
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2005-12-23 17:34:28 +00:00
|
|
|
/* Enclose the expression in `( ... )' so a default -print will
|
|
|
|
apply to the whole expression. */
|
2010-03-31 23:20:33 +01:00
|
|
|
entry_open = find_parser ("(");
|
|
|
|
entry_close = find_parser (")");
|
|
|
|
entry_print = find_parser ("print");
|
2007-06-26 08:24:19 +00:00
|
|
|
assert (entry_open != NULL);
|
|
|
|
assert (entry_close != NULL);
|
|
|
|
assert (entry_print != NULL);
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2007-04-29 00:43:07 +00:00
|
|
|
parse_openparen (entry_open, argv, &argc);
|
2006-01-04 19:22:38 +00:00
|
|
|
last_pred->p_name = "(";
|
2005-12-23 17:34:28 +00:00
|
|
|
predicates->artificial = true;
|
2010-03-31 23:20:33 +01:00
|
|
|
parse_begin_user_args (argv, argc, last_pred, predicates);
|
|
|
|
pred_sanity_check (last_pred);
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2005-12-23 17:34:28 +00:00
|
|
|
/* Build the input order list. */
|
|
|
|
while (i < argc )
|
|
|
|
{
|
2010-04-04 17:14:31 +01:00
|
|
|
state.already_issued_stat_error_msg = false;
|
2010-03-31 23:20:33 +01:00
|
|
|
if (!looks_like_expression (argv[i], false))
|
2017-08-16 14:09:17 -06:00
|
|
|
{
|
|
|
|
error (0, 0, _("paths must precede expression: `%s'"), argv[i]);
|
|
|
|
if (access(argv[i], F_OK)==0)
|
|
|
|
error (0, 0, _("possible unquoted pattern after predicate `%s'?"),
|
|
|
|
last_pred->p_name);
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
2005-12-23 17:34:28 +00:00
|
|
|
|
|
|
|
predicate_name = argv[i];
|
|
|
|
parse_entry = find_parser (predicate_name);
|
|
|
|
if (parse_entry == NULL)
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
/* Command line option not recognized */
|
|
|
|
error (EXIT_FAILURE, 0, _("unknown predicate `%s'"), predicate_name);
|
|
|
|
}
|
2007-03-07 23:18:38 +00:00
|
|
|
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
/* We have recognised a test of the form -foo. Eat that,
|
2007-03-07 23:18:38 +00:00
|
|
|
* unless it is a predicate like -newerXY.
|
|
|
|
*/
|
|
|
|
if (parse_entry->type != ARG_SPECIAL_PARSE)
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
i++;
|
|
|
|
}
|
2006-01-04 19:22:38 +00:00
|
|
|
oldi = i;
|
2005-12-23 17:34:28 +00:00
|
|
|
if (!(*(parse_entry->parser_func)) (parse_entry, argv, &i))
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
if (argv[i])
|
|
|
|
{
|
|
|
|
if ( (ARG_SPECIAL_PARSE == parse_entry->type) && (i == oldi) )
|
|
|
|
{
|
|
|
|
/* The special parse function spat out the
|
|
|
|
* predicate. It must be invalid, or not tasty.
|
|
|
|
*/
|
|
|
|
error (EXIT_FAILURE, 0, _("invalid predicate `%s'"), predicate_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error (EXIT_FAILURE, 0, _("invalid argument `%s' to `%s'"),
|
|
|
|
argv[i], predicate_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Command line option requires an argument */
|
|
|
|
error (EXIT_FAILURE, 0, _("missing argument to `%s'"), predicate_name);
|
|
|
|
}
|
|
|
|
}
|
2005-12-23 17:34:28 +00:00
|
|
|
else
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
last_pred->p_name = predicate_name;
|
|
|
|
|
|
|
|
/* If the parser consumed an argument, save it. */
|
|
|
|
if (i != oldi)
|
|
|
|
last_pred->arg_text = argv[oldi];
|
|
|
|
else
|
|
|
|
last_pred->arg_text = NULL;
|
|
|
|
}
|
2005-12-23 17:34:28 +00:00
|
|
|
pred_sanity_check(last_pred);
|
|
|
|
pred_sanity_check(predicates); /* XXX: expensive */
|
|
|
|
}
|
2010-03-31 23:20:33 +01:00
|
|
|
parse_end_user_args (argv, argc, last_pred, predicates);
|
2005-12-23 17:34:28 +00:00
|
|
|
if (predicates->pred_next == NULL)
|
|
|
|
{
|
|
|
|
/* No predicates that do something other than set a global variable
|
2024-05-26 11:12:59 +01:00
|
|
|
were given; remove the unneeded initial `(' and add `-print'. */
|
2005-12-23 17:34:28 +00:00
|
|
|
cur_pred = predicates;
|
|
|
|
predicates = last_pred = predicates->pred_next;
|
2007-06-21 23:41:08 +00:00
|
|
|
free (cur_pred);
|
2005-12-23 17:34:28 +00:00
|
|
|
parse_print (entry_print, argv, &argc);
|
2006-01-04 19:22:38 +00:00
|
|
|
last_pred->p_name = "-print";
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
pred_sanity_check(last_pred);
|
2005-12-23 17:34:28 +00:00
|
|
|
pred_sanity_check(predicates); /* XXX: expensive */
|
|
|
|
}
|
|
|
|
else if (!default_prints (predicates->pred_next))
|
|
|
|
{
|
|
|
|
/* One or more predicates that produce output were given;
|
2024-05-26 11:12:59 +01:00
|
|
|
remove the unneeded initial `('. */
|
2005-12-23 17:34:28 +00:00
|
|
|
cur_pred = predicates;
|
|
|
|
predicates = predicates->pred_next;
|
2010-03-31 23:20:33 +01:00
|
|
|
pred_sanity_check (predicates); /* XXX: expensive */
|
2007-06-21 23:41:08 +00:00
|
|
|
free (cur_pred);
|
2005-12-23 17:34:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* `( user-supplied-expression ) -print'. */
|
2007-04-29 00:43:07 +00:00
|
|
|
parse_closeparen (entry_close, argv, &argc);
|
2006-01-04 19:22:38 +00:00
|
|
|
last_pred->p_name = ")";
|
2005-12-23 17:34:28 +00:00
|
|
|
last_pred->artificial = true;
|
2010-03-31 23:20:33 +01:00
|
|
|
pred_sanity_check (last_pred);
|
2005-12-23 17:34:28 +00:00
|
|
|
parse_print (entry_print, argv, &argc);
|
2006-01-04 19:22:38 +00:00
|
|
|
last_pred->p_name = "-print";
|
2005-12-23 17:34:28 +00:00
|
|
|
last_pred->artificial = true;
|
2010-03-31 23:20:33 +01:00
|
|
|
pred_sanity_check (last_pred);
|
|
|
|
pred_sanity_check (predicates); /* XXX: expensive */
|
2005-12-23 17:34:28 +00:00
|
|
|
}
|
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
if (options.debug_options & (DebugExpressionTree|DebugTreeOpt))
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Predicate List:\n");
|
|
|
|
print_list (stderr, predicates);
|
|
|
|
}
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2005-12-23 17:34:28 +00:00
|
|
|
/* do a sanity check */
|
2010-03-31 23:20:33 +01:00
|
|
|
check_option_combinations (predicates);
|
|
|
|
pred_sanity_check (predicates);
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2005-12-23 17:34:28 +00:00
|
|
|
/* Done parsing the predicates. Build the evaluation tree. */
|
|
|
|
cur_pred = predicates;
|
|
|
|
eval_tree = get_expr (&cur_pred, NO_PREC, NULL);
|
2010-03-31 23:20:33 +01:00
|
|
|
calculate_derived_rates (eval_tree);
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2005-12-23 17:34:28 +00:00
|
|
|
/* Check if we have any left-over predicates (this fixes
|
|
|
|
* Debian bug #185202).
|
|
|
|
*/
|
|
|
|
if (cur_pred != NULL)
|
|
|
|
{
|
|
|
|
/* cur_pred->p_name is often NULL here */
|
2010-03-31 23:20:33 +01:00
|
|
|
if (pred_is (cur_pred, pred_closeparen))
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
/* e.g. "find \( -true \) \)" */
|
|
|
|
error (EXIT_FAILURE, 0, _("you have too many ')'"));
|
|
|
|
}
|
2005-12-23 17:34:28 +00:00
|
|
|
else
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
if (cur_pred->p_name)
|
|
|
|
error (EXIT_FAILURE, 0,
|
|
|
|
_("unexpected extra predicate '%s'"), cur_pred->p_name);
|
|
|
|
else
|
|
|
|
error (EXIT_FAILURE, 0, _("unexpected extra predicate"));
|
|
|
|
}
|
2005-12-23 17:34:28 +00:00
|
|
|
}
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
if (options.debug_options & (DebugExpressionTree|DebugTreeOpt))
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Eval Tree:\n");
|
|
|
|
print_tree (stderr, eval_tree, 0);
|
|
|
|
}
|
2005-12-23 17:34:28 +00:00
|
|
|
|
2010-03-31 23:20:33 +01:00
|
|
|
estimate_costs (eval_tree);
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2005-12-23 17:34:28 +00:00
|
|
|
/* Rearrange the eval tree in optimal-predicate order. */
|
|
|
|
opt_expr (&eval_tree);
|
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
/* Check that the tree is in normalised order (opt_expr does this) */
|
2010-03-31 23:20:33 +01:00
|
|
|
check_normalization (eval_tree, true);
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2024-05-27 19:27:02 +01:00
|
|
|
if (options.optimisation_level > 1)
|
|
|
|
{
|
|
|
|
do_arm_swaps (eval_tree);
|
|
|
|
}
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
/* Check that the tree is still in normalised order */
|
2010-03-31 23:20:33 +01:00
|
|
|
check_normalization (eval_tree, true);
|
2007-04-23 09:17:37 +00:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
if (options.debug_options & (DebugExpressionTree|DebugTreeOpt))
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Optimized Eval Tree:\n");
|
|
|
|
print_tree (stderr, eval_tree, 0);
|
|
|
|
fprintf (stderr, "Optimized command line:\n");
|
2010-03-31 23:20:33 +01:00
|
|
|
print_optlist (stderr, eval_tree);
|
|
|
|
fprintf (stderr, "\n");
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
2005-12-23 17:34:28 +00:00
|
|
|
|
|
|
|
return eval_tree;
|
|
|
|
}
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2014-07-19 11:17:52 +01:00
|
|
|
/* Initialize the performance data for a predicate.
|
2007-04-23 09:17:37 +00:00
|
|
|
*/
|
|
|
|
static void
|
2010-03-31 23:20:33 +01:00
|
|
|
init_pred_perf (struct predicate *pred)
|
2007-04-23 09:17:37 +00:00
|
|
|
{
|
|
|
|
struct predicate_performance_info *p = &pred->perf;
|
|
|
|
p->visits = p->successes = 0;
|
|
|
|
}
|
|
|
|
|
Fix Savannah bug #27017: find -D opt / -fstype ext3 -print , -quit coredump (vs. 4.5.x)
Fix Savannah bug #27017: find -D opt / -fstype ext3 -print , -quit
coredumps.
* find/tree.c (set_new_parent): Initialise struct
predicate->arg_text to NULL (instead of leaving it uninitialised).
(get_new_pred_noarg): Likewise.
(get_new_pred): Initialise predicate->arg_text to
"ThisShouldBeSetToSomethingElse" to make it easier to notice
bugs.
(get_new_pred_chk_op): Use get_new_pred_noarg.
(print_predicate): Use an if statement instead of
two ternary operators.
* find/util.c (insert_primary_withpred): Accept new argument, arg,
being the argument (if any) of this predicate. Pass it to
get_new_pred_chk_op.
(insert_primary): Likewise (pass arg to insert_primary_withpred).
(insert_primary_noarg): New function; calls insert_primary with
arg=NULL.
* find/parser.c (collect_arg_stat_info): Add an output parameter;
the filename from which we collected the stat information.
(parse_closeparen, parse_delete, parse_and, parse_or,
parse_comma): Use get_new_pred_noarg.
(parse_cnewer, parse_newer, parse_anewer): Use new
collect_arg_stat_info and insert_primary interface.
(parse_print, parse_prune, parse_nouser, parse_empty): Use
insert_primary_noarg.
(parse_accesscheck, parse_false): Use insert_primary_noarg.
(parse_used, parse_iname, parse_fprint, insert_fprint,
parse_fstype, parse_ilname): Use new collect_arg and
insert_primary interfaces.
(parse_ipath, parse_lname, do_parse_xmin, parse_name, parse_path,
parse_perm, parse_size, parse_user, parse_time): Use new
collect_arg and insert_primary_withpred interface.
(parse_negate, parse_openparen): Use new get_new_pred_chk_op interface.
(parse_newerXY, parse_nogroup): Use new insert_primary interface.
(insert_regex, parse_samefile): Use new insert_primary_withpred
interface.
(insert_type, insert_fprintf, new_insert_exec_ok, insert_num): Use
new insert_primary_withpred interface.
* find/defs.h (struct predicate.arg_text): make const.
Add declarations for new function get_new_pred_noarg and
insert_primary_noarg. Add 'arg' parameter to get_new_pred_chk_op
and insert_primary_withpred.
2009-07-11 19:55:27 +01:00
|
|
|
|
|
|
|
struct predicate *
|
|
|
|
get_new_pred_noarg (const struct parser_table *entry)
|
|
|
|
{
|
2010-03-31 23:20:33 +01:00
|
|
|
struct predicate *p = get_new_pred (entry);
|
Fix Savannah bug #27017: find -D opt / -fstype ext3 -print , -quit coredump (vs. 4.5.x)
Fix Savannah bug #27017: find -D opt / -fstype ext3 -print , -quit
coredumps.
* find/tree.c (set_new_parent): Initialise struct
predicate->arg_text to NULL (instead of leaving it uninitialised).
(get_new_pred_noarg): Likewise.
(get_new_pred): Initialise predicate->arg_text to
"ThisShouldBeSetToSomethingElse" to make it easier to notice
bugs.
(get_new_pred_chk_op): Use get_new_pred_noarg.
(print_predicate): Use an if statement instead of
two ternary operators.
* find/util.c (insert_primary_withpred): Accept new argument, arg,
being the argument (if any) of this predicate. Pass it to
get_new_pred_chk_op.
(insert_primary): Likewise (pass arg to insert_primary_withpred).
(insert_primary_noarg): New function; calls insert_primary with
arg=NULL.
* find/parser.c (collect_arg_stat_info): Add an output parameter;
the filename from which we collected the stat information.
(parse_closeparen, parse_delete, parse_and, parse_or,
parse_comma): Use get_new_pred_noarg.
(parse_cnewer, parse_newer, parse_anewer): Use new
collect_arg_stat_info and insert_primary interface.
(parse_print, parse_prune, parse_nouser, parse_empty): Use
insert_primary_noarg.
(parse_accesscheck, parse_false): Use insert_primary_noarg.
(parse_used, parse_iname, parse_fprint, insert_fprint,
parse_fstype, parse_ilname): Use new collect_arg and
insert_primary interfaces.
(parse_ipath, parse_lname, do_parse_xmin, parse_name, parse_path,
parse_perm, parse_size, parse_user, parse_time): Use new
collect_arg and insert_primary_withpred interface.
(parse_negate, parse_openparen): Use new get_new_pred_chk_op interface.
(parse_newerXY, parse_nogroup): Use new insert_primary interface.
(insert_regex, parse_samefile): Use new insert_primary_withpred
interface.
(insert_type, insert_fprintf, new_insert_exec_ok, insert_num): Use
new insert_primary_withpred interface.
* find/defs.h (struct predicate.arg_text): make const.
Add declarations for new function get_new_pred_noarg and
insert_primary_noarg. Add 'arg' parameter to get_new_pred_chk_op
and insert_primary_withpred.
2009-07-11 19:55:27 +01:00
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
p->arg_text = NULL;
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2005-12-23 17:34:28 +00:00
|
|
|
/* Return a pointer to a new predicate structure, which has been
|
|
|
|
linked in as the last one in the predicates list.
|
|
|
|
|
|
|
|
Set `predicates' to point to the start of the predicates list.
|
|
|
|
Set `last_pred' to point to the new last predicate in the list.
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2005-12-23 17:34:28 +00:00
|
|
|
Set all cells in the new structure to the default values. */
|
|
|
|
|
|
|
|
struct predicate *
|
|
|
|
get_new_pred (const struct parser_table *entry)
|
|
|
|
{
|
|
|
|
register struct predicate *new_pred;
|
|
|
|
(void) entry;
|
|
|
|
|
|
|
|
/* Options should not be turned into predicates. */
|
2007-06-26 08:24:19 +00:00
|
|
|
assert (entry->type != ARG_OPTION);
|
|
|
|
assert (entry->type != ARG_POSITIONAL_OPTION);
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2016-06-30 01:18:17 +02:00
|
|
|
/* Allocate + initialize a new predicate. */
|
|
|
|
new_pred = xzalloc (sizeof (struct predicate));
|
2005-12-23 17:34:28 +00:00
|
|
|
if (predicates == NULL)
|
|
|
|
{
|
2016-06-30 01:18:17 +02:00
|
|
|
last_pred = predicates = new_pred;
|
2005-12-23 17:34:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
last_pred->pred_next = new_pred;
|
|
|
|
last_pred = new_pred;
|
|
|
|
}
|
|
|
|
last_pred->parser_entry = entry;
|
|
|
|
last_pred->p_type = NO_TYPE;
|
|
|
|
last_pred->p_prec = NO_PREC;
|
|
|
|
last_pred->need_stat = true;
|
|
|
|
last_pred->need_type = true;
|
Fix Savannah bug #27017: find -D opt / -fstype ext3 -print , -quit coredump (vs. 4.5.x)
Fix Savannah bug #27017: find -D opt / -fstype ext3 -print , -quit
coredumps.
* find/tree.c (set_new_parent): Initialise struct
predicate->arg_text to NULL (instead of leaving it uninitialised).
(get_new_pred_noarg): Likewise.
(get_new_pred): Initialise predicate->arg_text to
"ThisShouldBeSetToSomethingElse" to make it easier to notice
bugs.
(get_new_pred_chk_op): Use get_new_pred_noarg.
(print_predicate): Use an if statement instead of
two ternary operators.
* find/util.c (insert_primary_withpred): Accept new argument, arg,
being the argument (if any) of this predicate. Pass it to
get_new_pred_chk_op.
(insert_primary): Likewise (pass arg to insert_primary_withpred).
(insert_primary_noarg): New function; calls insert_primary with
arg=NULL.
* find/parser.c (collect_arg_stat_info): Add an output parameter;
the filename from which we collected the stat information.
(parse_closeparen, parse_delete, parse_and, parse_or,
parse_comma): Use get_new_pred_noarg.
(parse_cnewer, parse_newer, parse_anewer): Use new
collect_arg_stat_info and insert_primary interface.
(parse_print, parse_prune, parse_nouser, parse_empty): Use
insert_primary_noarg.
(parse_accesscheck, parse_false): Use insert_primary_noarg.
(parse_used, parse_iname, parse_fprint, insert_fprint,
parse_fstype, parse_ilname): Use new collect_arg and
insert_primary interfaces.
(parse_ipath, parse_lname, do_parse_xmin, parse_name, parse_path,
parse_perm, parse_size, parse_user, parse_time): Use new
collect_arg and insert_primary_withpred interface.
(parse_negate, parse_openparen): Use new get_new_pred_chk_op interface.
(parse_newerXY, parse_nogroup): Use new insert_primary interface.
(insert_regex, parse_samefile): Use new insert_primary_withpred
interface.
(insert_type, insert_fprintf, new_insert_exec_ok, insert_num): Use
new insert_primary_withpred interface.
* find/defs.h (struct predicate.arg_text): make const.
Add declarations for new function get_new_pred_noarg and
insert_primary_noarg. Add 'arg' parameter to get_new_pred_chk_op
and insert_primary_withpred.
2009-07-11 19:55:27 +01:00
|
|
|
last_pred->p_cost = NeedsUnknown;
|
|
|
|
last_pred->arg_text = "ThisShouldBeSetToSomethingElse";
|
2006-01-04 19:22:38 +00:00
|
|
|
last_pred->est_success_rate = 1.0;
|
2010-03-31 23:20:33 +01:00
|
|
|
init_pred_perf (last_pred);
|
2005-12-23 17:34:28 +00:00
|
|
|
return last_pred;
|
|
|
|
}
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2005-12-23 19:02:59 +00:00
|
|
|
/* Return a pointer to a new predicate, with operator check.
|
|
|
|
Like get_new_pred, but it checks to make sure that the previous
|
|
|
|
predicate is an operator. If it isn't, the AND operator is inserted. */
|
|
|
|
|
|
|
|
struct predicate *
|
Fix Savannah bug #27017: find -D opt / -fstype ext3 -print , -quit coredump (vs. 4.5.x)
Fix Savannah bug #27017: find -D opt / -fstype ext3 -print , -quit
coredumps.
* find/tree.c (set_new_parent): Initialise struct
predicate->arg_text to NULL (instead of leaving it uninitialised).
(get_new_pred_noarg): Likewise.
(get_new_pred): Initialise predicate->arg_text to
"ThisShouldBeSetToSomethingElse" to make it easier to notice
bugs.
(get_new_pred_chk_op): Use get_new_pred_noarg.
(print_predicate): Use an if statement instead of
two ternary operators.
* find/util.c (insert_primary_withpred): Accept new argument, arg,
being the argument (if any) of this predicate. Pass it to
get_new_pred_chk_op.
(insert_primary): Likewise (pass arg to insert_primary_withpred).
(insert_primary_noarg): New function; calls insert_primary with
arg=NULL.
* find/parser.c (collect_arg_stat_info): Add an output parameter;
the filename from which we collected the stat information.
(parse_closeparen, parse_delete, parse_and, parse_or,
parse_comma): Use get_new_pred_noarg.
(parse_cnewer, parse_newer, parse_anewer): Use new
collect_arg_stat_info and insert_primary interface.
(parse_print, parse_prune, parse_nouser, parse_empty): Use
insert_primary_noarg.
(parse_accesscheck, parse_false): Use insert_primary_noarg.
(parse_used, parse_iname, parse_fprint, insert_fprint,
parse_fstype, parse_ilname): Use new collect_arg and
insert_primary interfaces.
(parse_ipath, parse_lname, do_parse_xmin, parse_name, parse_path,
parse_perm, parse_size, parse_user, parse_time): Use new
collect_arg and insert_primary_withpred interface.
(parse_negate, parse_openparen): Use new get_new_pred_chk_op interface.
(parse_newerXY, parse_nogroup): Use new insert_primary interface.
(insert_regex, parse_samefile): Use new insert_primary_withpred
interface.
(insert_type, insert_fprintf, new_insert_exec_ok, insert_num): Use
new insert_primary_withpred interface.
* find/defs.h (struct predicate.arg_text): make const.
Add declarations for new function get_new_pred_noarg and
insert_primary_noarg. Add 'arg' parameter to get_new_pred_chk_op
and insert_primary_withpred.
2009-07-11 19:55:27 +01:00
|
|
|
get_new_pred_chk_op (const struct parser_table *entry,
|
2024-05-26 11:12:59 +01:00
|
|
|
const char *arg)
|
2005-12-23 19:02:59 +00:00
|
|
|
{
|
|
|
|
struct predicate *new_pred;
|
|
|
|
static const struct parser_table *entry_and = NULL;
|
|
|
|
|
|
|
|
/* Locate the entry in the parser table for the "and" operator */
|
|
|
|
if (NULL == entry_and)
|
2010-03-31 23:20:33 +01:00
|
|
|
entry_and = find_parser ("and");
|
2005-12-23 19:02:59 +00:00
|
|
|
|
|
|
|
/* Check that it's actually there. If not, that is a bug.*/
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
assert (entry_and != NULL);
|
2005-12-23 19:02:59 +00:00
|
|
|
|
|
|
|
if (last_pred)
|
|
|
|
switch (last_pred->p_type)
|
|
|
|
{
|
|
|
|
case NO_TYPE:
|
2024-05-26 11:12:59 +01:00
|
|
|
error (EXIT_FAILURE, 0, _("oops -- invalid default insertion of and!"));
|
|
|
|
break;
|
2005-12-23 19:02:59 +00:00
|
|
|
|
|
|
|
case PRIMARY_TYPE:
|
|
|
|
case CLOSE_PAREN:
|
2024-05-26 11:12:59 +01:00
|
|
|
/* We need to interpose the and operator. */
|
|
|
|
new_pred = get_new_pred_noarg (entry_and);
|
|
|
|
new_pred->pred_func = pred_and;
|
|
|
|
new_pred->p_name = "-a";
|
|
|
|
new_pred->p_type = BI_OP;
|
|
|
|
new_pred->p_prec = AND_PREC;
|
|
|
|
new_pred->need_stat = false;
|
|
|
|
new_pred->need_type = false;
|
|
|
|
new_pred->need_inum = false;
|
|
|
|
new_pred->arg_text = NULL;
|
|
|
|
new_pred->args.str = NULL;
|
|
|
|
new_pred->side_effects = false;
|
|
|
|
new_pred->no_default_print = false;
|
|
|
|
break;
|
2005-12-23 19:02:59 +00:00
|
|
|
|
|
|
|
default:
|
2024-05-26 11:12:59 +01:00
|
|
|
break;
|
2005-12-23 19:02:59 +00:00
|
|
|
}
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2005-12-23 19:02:59 +00:00
|
|
|
new_pred = get_new_pred (entry);
|
Fix Savannah bug #27017: find -D opt / -fstype ext3 -print , -quit coredump (vs. 4.5.x)
Fix Savannah bug #27017: find -D opt / -fstype ext3 -print , -quit
coredumps.
* find/tree.c (set_new_parent): Initialise struct
predicate->arg_text to NULL (instead of leaving it uninitialised).
(get_new_pred_noarg): Likewise.
(get_new_pred): Initialise predicate->arg_text to
"ThisShouldBeSetToSomethingElse" to make it easier to notice
bugs.
(get_new_pred_chk_op): Use get_new_pred_noarg.
(print_predicate): Use an if statement instead of
two ternary operators.
* find/util.c (insert_primary_withpred): Accept new argument, arg,
being the argument (if any) of this predicate. Pass it to
get_new_pred_chk_op.
(insert_primary): Likewise (pass arg to insert_primary_withpred).
(insert_primary_noarg): New function; calls insert_primary with
arg=NULL.
* find/parser.c (collect_arg_stat_info): Add an output parameter;
the filename from which we collected the stat information.
(parse_closeparen, parse_delete, parse_and, parse_or,
parse_comma): Use get_new_pred_noarg.
(parse_cnewer, parse_newer, parse_anewer): Use new
collect_arg_stat_info and insert_primary interface.
(parse_print, parse_prune, parse_nouser, parse_empty): Use
insert_primary_noarg.
(parse_accesscheck, parse_false): Use insert_primary_noarg.
(parse_used, parse_iname, parse_fprint, insert_fprint,
parse_fstype, parse_ilname): Use new collect_arg and
insert_primary interfaces.
(parse_ipath, parse_lname, do_parse_xmin, parse_name, parse_path,
parse_perm, parse_size, parse_user, parse_time): Use new
collect_arg and insert_primary_withpred interface.
(parse_negate, parse_openparen): Use new get_new_pred_chk_op interface.
(parse_newerXY, parse_nogroup): Use new insert_primary interface.
(insert_regex, parse_samefile): Use new insert_primary_withpred
interface.
(insert_type, insert_fprintf, new_insert_exec_ok, insert_num): Use
new insert_primary_withpred interface.
* find/defs.h (struct predicate.arg_text): make const.
Add declarations for new function get_new_pred_noarg and
insert_primary_noarg. Add 'arg' parameter to get_new_pred_chk_op
and insert_primary_withpred.
2009-07-11 19:55:27 +01:00
|
|
|
new_pred->arg_text = arg;
|
2005-12-23 19:02:59 +00:00
|
|
|
new_pred->parser_entry = entry;
|
|
|
|
return new_pred;
|
|
|
|
}
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
struct cost_assoc
|
|
|
|
{
|
|
|
|
enum EvaluationCost cost;
|
2011-06-14 23:14:21 +01:00
|
|
|
const char *name;
|
2006-01-04 19:22:38 +00:00
|
|
|
};
|
2024-09-17 01:07:53 +02:00
|
|
|
static struct cost_assoc cost_table[] =
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
{ NeedsNothing, "Nothing" },
|
2009-03-07 20:16:49 +00:00
|
|
|
{ NeedsInodeNumber, "InodeNumber" },
|
|
|
|
{ NeedsType, "Type" },
|
|
|
|
{ NeedsStatInfo, "StatInfo" },
|
|
|
|
{ NeedsLinkName, "LinkName" },
|
|
|
|
{ NeedsAccessInfo, "AccessInfo" },
|
|
|
|
{ NeedsSyncDiskHit, "SyncDiskHit" },
|
2006-01-04 19:22:38 +00:00
|
|
|
{ NeedsEventualExec, "EventualExec" },
|
|
|
|
{ NeedsImmediateExec, "ImmediateExec" },
|
|
|
|
{ NeedsUserInteraction, "UserInteraction" },
|
2009-03-07 20:16:49 +00:00
|
|
|
{ NeedsUnknown, "Unknown" }
|
2006-01-04 19:22:38 +00:00
|
|
|
};
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
struct prec_assoc
|
|
|
|
{
|
|
|
|
short prec;
|
2011-06-14 23:14:21 +01:00
|
|
|
const char *prec_name;
|
2006-01-04 19:22:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct prec_assoc prec_table[] =
|
|
|
|
{
|
|
|
|
{NO_PREC, "no"},
|
|
|
|
{COMMA_PREC, "comma"},
|
|
|
|
{OR_PREC, "or"},
|
|
|
|
{AND_PREC, "and"},
|
|
|
|
{NEGATE_PREC, "negate"},
|
|
|
|
{MAX_PREC, "max"},
|
|
|
|
{-1, "unknown "}
|
|
|
|
};
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
struct op_assoc
|
|
|
|
{
|
|
|
|
short type;
|
2011-06-14 23:14:21 +01:00
|
|
|
const char *type_name;
|
2006-01-04 19:22:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct op_assoc type_table[] =
|
|
|
|
{
|
|
|
|
{NO_TYPE, "no"},
|
|
|
|
{PRIMARY_TYPE, "primary"},
|
|
|
|
{UNI_OP, "uni_op"},
|
|
|
|
{BI_OP, "bi_op"},
|
|
|
|
{OPEN_PAREN, "open_paren "},
|
|
|
|
{CLOSE_PAREN, "close_paren "},
|
|
|
|
{-1, "unknown"}
|
|
|
|
};
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
static const char *
|
|
|
|
cost_name (enum EvaluationCost cost)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
2010-03-31 23:20:33 +01:00
|
|
|
unsigned int n = sizeof (cost_table)/sizeof(cost_table[0]);
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
for (i = 0; i<n; ++i)
|
|
|
|
if (cost_table[i].cost == cost)
|
|
|
|
return cost_table[i].name;
|
|
|
|
return "unknown";
|
|
|
|
}
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
|
2011-06-14 23:44:57 +01:00
|
|
|
static const char *
|
2011-06-14 23:14:21 +01:00
|
|
|
type_name (short type)
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; type_table[i].type != (short) -1; i++)
|
|
|
|
if (type_table[i].type == type)
|
|
|
|
break;
|
2011-06-14 23:14:21 +01:00
|
|
|
return type_table[i].type_name;
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2011-06-14 23:44:57 +01:00
|
|
|
static const char *
|
2011-06-14 23:14:21 +01:00
|
|
|
prec_name (short prec)
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; prec_table[i].prec != (short) -1; i++)
|
|
|
|
if (prec_table[i].prec == prec)
|
|
|
|
break;
|
2011-06-14 23:14:21 +01:00
|
|
|
return prec_table[i].prec_name;
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
|
|
|
|
2010-04-06 01:03:33 +01:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
/* Walk the expression tree NODE to stdout.
|
|
|
|
INDENT is the number of levels to indent the left margin. */
|
|
|
|
|
|
|
|
void
|
|
|
|
print_tree (FILE *fp, struct predicate *node, int indent)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
return;
|
|
|
|
for (i = 0; i < indent; i++)
|
|
|
|
fprintf (fp, " ");
|
|
|
|
fprintf (fp, "pred=[");
|
2010-03-31 23:20:33 +01:00
|
|
|
print_predicate (fp, node);
|
2006-01-04 19:22:38 +00:00
|
|
|
fprintf (fp, "] type=%s prec=%s",
|
2024-05-26 11:12:59 +01:00
|
|
|
type_name (node->p_type), prec_name (node->p_prec));
|
2016-01-01 09:35:05 +00:00
|
|
|
fprintf (fp, " cost=%s est_success_rate=%#.4g %sside effects ",
|
2024-05-26 11:12:59 +01:00
|
|
|
cost_name (node->p_cost),
|
|
|
|
node->est_success_rate,
|
|
|
|
(node->side_effects ? "" : "no "));
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2009-03-07 20:16:49 +00:00
|
|
|
if (node->need_stat || node->need_type || node->need_inum)
|
2006-01-04 19:22:38 +00:00
|
|
|
{
|
|
|
|
int comma = 0;
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
fprintf (fp, "Needs ");
|
|
|
|
if (node->need_stat)
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
fprintf (fp, "stat");
|
|
|
|
comma = 1;
|
|
|
|
}
|
2009-03-07 20:16:49 +00:00
|
|
|
if (node->need_inum)
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
fprintf (fp, "%sinode", comma ? "," : "");
|
|
|
|
comma = 1;
|
|
|
|
}
|
2006-01-04 19:22:38 +00:00
|
|
|
if (node->need_type)
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
fprintf (fp, "%stype", comma ? "," : "");
|
|
|
|
}
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
|
|
|
fprintf (fp, "\n");
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < indent; i++)
|
|
|
|
fprintf (fp, " ");
|
|
|
|
if (NULL == node->pred_left && NULL == node->pred_right)
|
|
|
|
{
|
|
|
|
fprintf (fp, "no children.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (node->pred_left)
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
fprintf (fp, "left:\n");
|
|
|
|
print_tree (fp, node->pred_left, indent + 1);
|
|
|
|
}
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
else
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
fprintf (fp, "no left.\n");
|
|
|
|
}
|
Removed trailing whitespace.
Removed trailing whitespace.
* Makefile.am: Removed trailing white space.
* NEWS, build-aux/check-testfiles.sh, build-aux/src-sniff.py,
doc/Makefile.am, doc/find-maint.texi, doc/find.texi, find/Makefile.am,
find/defs.h, find/find.1, find/find.c, find/finddata.c, find/fstype.c,
find/ftsfind.c, find/parser.c, find/pred.c, find/tree.c, find/util.c,
import-gnulib.sh, lib/Makefile.am, lib/buildcmd.c, lib/buildcmd.h,
lib/dircallback.c, lib/dircallback.h, lib/extendbuf.c,
lib/extendbuf.h, lib/findutils-version.c, lib/findutils-version.h,
lib/forcefindlib.c, lib/gnulib-version.h, lib/listfile.c,
lib/modetype.h, lib/nextelem.c, lib/nextelem.h, lib/printquoted.c,
lib/printquoted.h, lib/qmark.c, lib/regexprops.c, lib/regextype.c,
lib/savedirinfo.c, lib/savedirinfo.h, lib/strspn.c, lib/wait.h,
lib/waitpid.c, locate/bigram.c, locate/code.c, locate/locate.1,
locate/locate.c, locate/locatedb.5, locate/locatedb.h,
locate/updatedb.1, locate/updatedb.sh, locate/word_io.c,
m4/findlib.m4, m4/nullsort.m4, m4/withfts.m4, xargs/xargs.1: Likewise.
Signed-off-by: James Youngman <jay@gnu.org>
2009-03-04 10:49:59 +00:00
|
|
|
|
2006-01-04 19:22:38 +00:00
|
|
|
for (i = 0; i < indent; i++)
|
2024-05-26 11:12:59 +01:00
|
|
|
fprintf (fp, " ");
|
2006-01-04 19:22:38 +00:00
|
|
|
if (node->pred_right)
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
fprintf (fp, "right:\n");
|
|
|
|
print_tree (fp, node->pred_right, indent + 1);
|
|
|
|
}
|
2006-01-04 19:22:38 +00:00
|
|
|
else
|
2024-05-26 11:12:59 +01:00
|
|
|
{
|
|
|
|
fprintf (fp, "no right.\n");
|
|
|
|
}
|
2006-01-04 19:22:38 +00:00
|
|
|
}
|
|
|
|
}
|