*** empty log message ***
[findutils.git] / find / defs.h
blob074cbdd350fb66b8db274a66467fcecc1c710d36
1 /* defs.h -- data types and declarations.
2 Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
18 #if defined(HAVE_STRING_H) || defined(STDC_HEADERS)
19 #include <string.h>
20 #else
21 #include <strings.h>
22 #ifndef strchr
23 #define strchr index
24 #endif
25 #ifndef strrchr
26 #define strrchr rindex
27 #endif
28 #endif
30 #include <errno.h>
31 #ifndef errno
32 extern int errno;
33 #endif
35 #ifdef STDC_HEADERS
36 #include <stdlib.h>
37 #endif
39 #ifdef HAVE_UNISTD_H
40 #include <unistd.h>
41 #endif
43 #include <time.h>
45 #include "regex.h"
47 #if __STDC__
48 # define P_(s) s
49 #else
50 # define P_(s) ()
51 #endif
53 /* Not char because of type promotion; NeXT gcc can't handle it. */
54 typedef int boolean;
55 #define true 1
56 #define false 0
58 /* Pointer to function returning boolean. */
59 typedef boolean (*PFB)();
61 /* The number of seconds in a day. */
62 #define DAYSECS 86400
64 /* Argument structures for predicates. */
66 enum comparison_type
68 COMP_GT,
69 COMP_LT,
70 COMP_EQ
73 enum predicate_type
75 NO_TYPE,
76 PRIMARY_TYPE,
77 UNI_OP,
78 BI_OP,
79 OPEN_PAREN,
80 CLOSE_PAREN
83 enum predicate_precedence
85 NO_PREC,
86 COMMA_PREC,
87 OR_PREC,
88 AND_PREC,
89 NEGATE_PREC,
90 MAX_PREC
93 struct long_val
95 enum comparison_type kind;
96 unsigned long l_val;
99 struct size_val
101 enum comparison_type kind;
102 int blocksize;
103 unsigned long size;
106 struct path_arg
108 short offset; /* Offset in `vec' of this arg. */
109 short count; /* Number of path replacements in this arg. */
110 char *origarg; /* Arg with "{}" intact. */
113 struct exec_val
115 struct path_arg *paths; /* Array of args with path replacements. */
116 char **vec; /* Array of args to pass to program. */
119 /* The format string for a -printf or -fprintf is chopped into one or
120 more `struct segment', linked together into a list.
121 Each stretch of plain text is a segment, and
122 each \c and `%' conversion is a segment. */
124 /* Special values for the `kind' field of `struct segment'. */
125 #define KIND_PLAIN 0 /* Segment containing just plain text. */
126 #define KIND_STOP 1 /* \c -- stop printing and flush output. */
128 struct segment
130 int kind; /* Format chars or KIND_{PLAIN,STOP}. */
131 char *text; /* Plain text or `%' format string. */
132 int text_len; /* Length of `text'. */
133 struct segment *next; /* Next segment for this predicate. */
136 struct format_val
138 struct segment *segment; /* Linked list of segments. */
139 FILE *stream; /* Output stream to print on. */
142 struct predicate
144 /* Pointer to the function that implements this predicate. */
145 PFB pred_func;
147 /* Only used for debugging, but defined unconditionally so individual
148 modules can be compiled with -DDEBUG. */
149 char *p_name;
151 /* The type of this node. There are two kinds. The first is real
152 predicates ("primaries") such as -perm, -print, or -exec. The
153 other kind is operators for combining predicates. */
154 enum predicate_type p_type;
156 /* The precedence of this node. Only has meaning for operators. */
157 enum predicate_precedence p_prec;
159 /* True if this predicate node produces side effects. */
160 boolean side_effects;
162 /* True if this predicate node requires a stat system call to execute. */
163 boolean need_stat;
165 /* Information needed by the predicate processor.
166 Next to each member are listed the predicates that use it. */
167 union
169 char *str; /* fstype [i]lname [i]name [i]path */
170 struct re_pattern_buffer *regex; /* regex */
171 struct exec_val exec_vec; /* exec ok */
172 struct long_val info; /* atime ctime mtime inum links */
173 struct size_val size; /* size */
174 uid_t uid; /* user */
175 gid_t gid; /* group */
176 time_t time; /* newer */
177 unsigned long perm; /* perm */
178 unsigned long type; /* type */
179 FILE *stream; /* fprint fprint0 */
180 struct format_val printf_vec; /* printf fprintf */
181 } args;
183 /* The next predicate in the user input sequence,
184 which repesents the order in which the user supplied the
185 predicates on the command line. */
186 struct predicate *pred_next;
188 /* The right and left branches from this node in the expression
189 tree, which represents the order in which the nodes should be
190 processed. */
191 struct predicate *pred_left;
192 struct predicate *pred_right;
195 /* find library function declarations. */
197 /* dirname.c */
198 char *dirname P_((char *path));
200 /* error.c */
201 void error P_((int status, int errnum, char *message, ...));
203 /* listfile.c */
204 void list_file P_((char *name, char *relname, struct stat *statp, FILE *stream));
205 char *get_link_name P_((char *name, char *relname));
207 /* savedir.c */
208 char *savedir P_((char *dir, unsigned name_size));
210 /* stpcpy.c */
211 #if !HAVE_STPCPY
212 char *stpcpy P_((char *dest, const char *src));
213 #endif
215 /* xgetcwd.c */
216 char *xgetcwd P_((void));
218 /* xmalloc.c */
219 #if __STDC__
220 #define VOID void
221 #else
222 #define VOID char
223 #endif
225 VOID *xmalloc P_((size_t n));
226 VOID *xrealloc P_((VOID *p, size_t n));
228 /* xstrdup.c */
229 char *xstrdup P_((char *string));
231 /* find global function declarations. */
233 /* fstype.c */
234 char *filesystem_type P_((char *path, char *relpath, struct stat *statp));
236 /* parser.c */
237 PFB find_parser P_((char *search_name));
238 boolean parse_close P_((char *argv[], int *arg_ptr));
239 boolean parse_open P_((char *argv[], int *arg_ptr));
240 boolean parse_print P_((char *argv[], int *arg_ptr));
242 /* pred.c */
243 boolean pred_amin P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
244 boolean pred_and P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
245 boolean pred_anewer P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
246 boolean pred_atime P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
247 boolean pred_close P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
248 boolean pred_cmin P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
249 boolean pred_cnewer P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
250 boolean pred_comma P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
251 boolean pred_ctime P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
252 boolean pred_empty P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
253 boolean pred_exec P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
254 boolean pred_false P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
255 boolean pred_fls P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
256 boolean pred_fprint P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
257 boolean pred_fprint0 P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
258 boolean pred_fprintf P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
259 boolean pred_fstype P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
260 boolean pred_gid P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
261 boolean pred_group P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
262 boolean pred_ilname P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
263 boolean pred_iname P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
264 boolean pred_inum P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
265 boolean pred_ipath P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
266 boolean pred_links P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
267 boolean pred_lname P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
268 boolean pred_ls P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
269 boolean pred_mmin P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
270 boolean pred_mtime P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
271 boolean pred_name P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
272 boolean pred_negate P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
273 boolean pred_newer P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
274 boolean pred_nogroup P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
275 boolean pred_nouser P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
276 boolean pred_ok P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
277 boolean pred_open P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
278 boolean pred_or P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
279 boolean pred_path P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
280 boolean pred_perm P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
281 boolean pred_print P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
282 boolean pred_print0 P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
283 boolean pred_prune P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
284 boolean pred_regex P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
285 boolean pred_size P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
286 boolean pred_true P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
287 boolean pred_type P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
288 boolean pred_uid P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
289 boolean pred_used P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
290 boolean pred_user P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
291 boolean pred_xtype P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
292 char *find_pred_name P_((PFB pred_func));
293 #ifdef DEBUG
294 void print_tree P_((struct predicate *node, int indent));
295 void print_list P_((struct predicate *node));
296 #endif /* DEBUG */
298 /* tree.c */
299 struct predicate *get_expr P_((struct predicate **input, int prev_prec));
300 boolean opt_expr P_((struct predicate **eval_treep));
301 boolean mark_stat P_((struct predicate *tree));
303 /* util.c */
304 #ifndef __linux__
305 char *basename P_((char *fname));
306 #endif /* not __linux__ */
307 struct predicate *get_new_pred P_((void));
308 struct predicate *get_new_pred_chk_op P_((void));
309 struct predicate *insert_primary P_((boolean (*pred_func )()));
310 void usage P_((char *msg));
312 extern char *program_name;
313 extern struct predicate *predicates;
314 extern struct predicate *last_pred;
315 extern boolean do_dir_first;
316 extern int maxdepth;
317 extern int mindepth;
318 extern int curdepth;
319 extern time_t cur_day_start;
320 extern boolean full_days;
321 extern boolean no_leaf_check;
322 extern boolean stay_on_filesystem;
323 extern boolean stop_at_current_level;
324 extern boolean have_stat;
325 extern char *rel_pathname;
326 #ifndef HAVE_FCHDIR
327 extern char *starting_dir;
328 #else
329 extern int starting_desc;
330 #endif
331 extern int exit_status;
332 extern int path_length;
333 extern int (*xstat) ();
334 extern boolean dereference;