mirror of
https://https.git.savannah.gnu.org/git/findutils.git
synced 2026-01-26 15:39:06 +00:00
* find/util.c (get_new_pred):
* find/tree.c (set_new_parent): * find/parser.c (various parse functions): * find/find.c (main): (default_prints): new function * find/defs.h (struct predicate): added no_default_print side_effects are no separated from no_default_print. predicates which cause side effects should not be reordered (optimized). predicates which cause printing should have printing turned off. Printing statements also cause side effects.
This commit is contained in:
parent
f39deaf11a
commit
1b9525aaa6
@ -238,9 +238,14 @@ struct predicate
|
||||
/* The precedence of this node. Only has meaning for operators. */
|
||||
enum predicate_precedence p_prec;
|
||||
|
||||
/* True if this predicate node produces side effects. */
|
||||
/* True if this predicate node produces side effects.
|
||||
If side_effects are produced
|
||||
then optimization will not be performed */
|
||||
boolean side_effects;
|
||||
|
||||
/* True if this predicate node requires default print be turned off. */
|
||||
boolean no_default_print;
|
||||
|
||||
/* True if this predicate node requires a stat system call to execute. */
|
||||
boolean need_stat;
|
||||
|
||||
|
||||
21
find/find.c
21
find/find.c
@ -58,6 +58,7 @@ static void process_top_path PARAMS((char *pathname));
|
||||
static int process_path PARAMS((char *pathname, char *name, boolean leaf, char *parent));
|
||||
static void process_dir PARAMS((char *pathname, char *name, int pathlen, struct stat *statp, char *parent));
|
||||
static boolean no_side_effects PARAMS((struct predicate *pred));
|
||||
static boolean default_prints PARAMS((struct predicate *pred));
|
||||
|
||||
/* Name this program was run with. */
|
||||
char *program_name;
|
||||
@ -150,7 +151,7 @@ int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
PFB parse_function; /* Pointer to who is to do the parsing. */
|
||||
PFB parse_function; /* Pointer to the function which parses. */
|
||||
struct predicate *cur_pred;
|
||||
char *predicate_name; /* Name of predicate being parsed. */
|
||||
|
||||
@ -222,7 +223,7 @@ main (int argc, char **argv)
|
||||
free ((char *) cur_pred);
|
||||
parse_print (argv, &argc);
|
||||
}
|
||||
else if (!no_side_effects (predicates->pred_next))
|
||||
else if (!default_prints (predicates->pred_next))
|
||||
{
|
||||
/* One or more predicates that produce output were given;
|
||||
remove the unneeded initial `('. */
|
||||
@ -559,3 +560,19 @@ no_side_effects (struct predicate *pred)
|
||||
}
|
||||
return (true);
|
||||
}
|
||||
|
||||
/* Return true if there are no predicates with no_default_print in
|
||||
predicate list PRED, false if there are any.
|
||||
Returns true if default print should be performed */
|
||||
|
||||
static boolean
|
||||
default_prints (struct predicate *pred)
|
||||
{
|
||||
while (pred != NULL)
|
||||
{
|
||||
if (pred->no_default_print)
|
||||
return (false);
|
||||
pred = pred->pred_next;
|
||||
}
|
||||
return (true);
|
||||
}
|
||||
|
||||
@ -437,6 +437,7 @@ parse_fls (char **argv, int *arg_ptr)
|
||||
our_pred = insert_primary (pred_fls);
|
||||
our_pred->args.stream = open_output_file (argv[*arg_ptr]);
|
||||
our_pred->side_effects = true;
|
||||
our_pred->no_default_print = true;
|
||||
(*arg_ptr)++;
|
||||
return (true);
|
||||
}
|
||||
@ -478,6 +479,7 @@ parse_fprint (char **argv, int *arg_ptr)
|
||||
our_pred = insert_primary (pred_fprint);
|
||||
our_pred->args.stream = open_output_file (argv[*arg_ptr]);
|
||||
our_pred->side_effects = true;
|
||||
our_pred->no_default_print = true;
|
||||
our_pred->need_stat = false;
|
||||
(*arg_ptr)++;
|
||||
return (true);
|
||||
@ -493,6 +495,7 @@ parse_fprint0 (char **argv, int *arg_ptr)
|
||||
our_pred = insert_primary (pred_fprint0);
|
||||
our_pred->args.stream = open_output_file (argv[*arg_ptr]);
|
||||
our_pred->side_effects = true;
|
||||
our_pred->no_default_print = true;
|
||||
our_pred->need_stat = false;
|
||||
(*arg_ptr)++;
|
||||
return (true);
|
||||
@ -653,6 +656,7 @@ parse_ls (char **argv, int *arg_ptr)
|
||||
|
||||
our_pred = insert_primary (pred_ls);
|
||||
our_pred->side_effects = true;
|
||||
our_pred->no_default_print = true;
|
||||
return (true);
|
||||
}
|
||||
|
||||
@ -963,6 +967,7 @@ parse_print (char **argv, int *arg_ptr)
|
||||
from doing undesired multiple printing when the user has
|
||||
already specified -print. */
|
||||
our_pred->side_effects = true;
|
||||
our_pred->no_default_print = true;
|
||||
our_pred->need_stat = false;
|
||||
return (true);
|
||||
}
|
||||
@ -977,6 +982,7 @@ parse_print0 (char **argv, int *arg_ptr)
|
||||
from doing undesired multiple printing when the user has
|
||||
already specified -print0. */
|
||||
our_pred->side_effects = true;
|
||||
our_pred->no_default_print = true;
|
||||
our_pred->need_stat = false;
|
||||
return (true);
|
||||
}
|
||||
@ -1265,6 +1271,7 @@ insert_fprintf (FILE *fp, boolean (*func) (/* ??? */), char **argv, int *arg_ptr
|
||||
fprintf_stat_needed = false; /* Might be overridden later. */
|
||||
our_pred = insert_primary (func);
|
||||
our_pred->side_effects = true;
|
||||
our_pred->no_default_print = true;
|
||||
our_pred->args.printf_vec.stream = fp;
|
||||
segmentp = &our_pred->args.printf_vec.segment;
|
||||
*segmentp = NULL;
|
||||
@ -1446,6 +1453,7 @@ make_segment (struct segment **segment, char *format, int len, int kind)
|
||||
return (&(*segment)->next);
|
||||
}
|
||||
|
||||
/* handles both exec and ok predicate */
|
||||
static boolean
|
||||
insert_exec_ok (boolean (*func) (/* ??? */), char **argv, int *arg_ptr)
|
||||
{
|
||||
@ -1476,6 +1484,7 @@ insert_exec_ok (boolean (*func) (/* ??? */), char **argv, int *arg_ptr)
|
||||
|
||||
our_pred = insert_primary (func);
|
||||
our_pred->side_effects = true;
|
||||
our_pred->no_default_print = true;
|
||||
execp = &our_pred->args.exec_vec;
|
||||
execp->paths =
|
||||
(struct path_arg *) xmalloc (sizeof (struct path_arg) * (num_paths + 1));
|
||||
|
||||
@ -372,6 +372,7 @@ set_new_parent (struct predicate *curr, enum predicate_precedence high_prec, str
|
||||
}
|
||||
|
||||
new_parent->side_effects = false;
|
||||
new_parent->no_default_print = false;
|
||||
new_parent->args.str = NULL;
|
||||
new_parent->pred_next = NULL;
|
||||
|
||||
|
||||
@ -62,6 +62,7 @@ get_new_pred (void)
|
||||
last_pred->p_type = NO_TYPE;
|
||||
last_pred->p_prec = NO_PREC;
|
||||
last_pred->side_effects = false;
|
||||
last_pred->no_default_print = false;
|
||||
last_pred->need_stat = true;
|
||||
last_pred->args.str = NULL;
|
||||
last_pred->pred_next = NULL;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user