1 // Copyright © Tavian Barnes <tavianator@tavianator.com>
2 // SPDX-License-Identifier: 0BSD
5 * The expression tree representation.
16 #include <sys/types.h>
20 * Integer comparison modes.
25 /** Less than N (-N). */
27 /** Greater than N (+N). */
32 * Permission comparison modes.
35 /** Mode is an exact match (MODE). */
37 /** Mode has all these bits (-MODE). */
39 /** Mode has any of these bits (/MODE). */
44 * Possible time units.
56 * Possible file size units.
59 /** 512-byte blocks. */
63 /** Two-byte words. */
78 * A command line expression.
81 /** The function that evaluates this expression. */
84 /** The number of command line arguments for this expression. */
86 /** The command line arguments comprising this expression. */
89 /** The number of files this expression keeps open between evaluations. */
91 /** The number of files this expression opens during evaluation. */
94 /** Whether this expression has no side effects. */
96 /** Whether this expression always evaluates to true. */
98 /** Whether this expression always evaluates to false. */
101 /** Estimated cost. */
103 /** Estimated probability of success. */
105 /** Number of times this predicate was evaluated. */
107 /** Number of times this predicate succeeded. */
109 /** Total time spent running this predicate. */
110 struct timespec elapsed;
112 /** Auxilliary data for the evaluation function. */
114 /** Child expressions. */
116 /** The left hand side of the expression. */
117 struct bfs_expr *lhs;
118 /** The right hand side of the expression. */
119 struct bfs_expr *rhs;
122 /** Integer comparisons. */
124 /** Integer for this comparison. */
126 /** The comparison mode. */
127 enum bfs_int_cmp int_cmp;
129 /** Optional extra data. */
132 enum bfs_size_unit size_unit;
134 /** Timestamp comparison data. */
136 /** The stat field to look at. */
137 enum bfs_stat_field stat_field;
138 /** The reference time. */
139 struct timespec reftime;
140 /** The time unit. */
141 enum bfs_time_unit time_unit;
146 /** String comparisons. */
148 /** String pattern. */
150 /** fnmatch() flags. */
152 /** Whether strcmp() can be used instead of fnmatch(). */
156 /** Printing actions. */
158 /** The output stream. */
160 /** Optional file path. */
162 /** Optional -printf format. */
163 struct bfs_printf *printf;
167 struct bfs_exec *exec;
171 /** The comparison mode. */
172 enum bfs_mode_cmp flags_cmp;
173 /** Flags that should be set. */
174 unsigned long long set_flags;
175 /** Flags that should be cleared. */
176 unsigned long long clear_flags;
181 /** The comparison mode. */
182 enum bfs_mode_cmp mode_cmp;
183 /** Mode to use for files. */
185 /** Mode to use for directories (different due to X). */
190 struct bfs_regex *regex;
192 /** -samefile data. */
194 /** Device number of the target file. */
196 /** Inode number of the target file. */
203 * Create a new expression.
205 struct bfs_expr *bfs_expr_new(bfs_eval_fn *eval, size_t argc, char **argv);
208 * @return Whether the expression has child expressions.
210 bool bfs_expr_is_parent(const struct bfs_expr *expr);
213 * @return Whether expr is known to always quit.
215 bool bfs_expr_never_returns(const struct bfs_expr *expr);
218 * @return The result of the integer comparison for this expression.
220 bool bfs_expr_cmp(const struct bfs_expr *expr, long long n);
223 * Free an expression tree.
225 void bfs_expr_free(struct bfs_expr *expr);