*** empty log message ***
[findutils.git] / find / defs.h
blob4066bfe859baa367ed7ca9bd97eb12411634d483
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 #ifndef S_IFLNK
48 #define lstat stat
49 #endif
51 # ifndef PARAMS
52 # if defined PROTOTYPES || (defined __STDC__ && __STDC__)
53 # define PARAMS(Args) Args
54 # else
55 # define PARAMS(Args) ()
56 # endif
57 # endif
59 int lstat PARAMS((const char *__path, struct stat *__statbuf));
60 int stat PARAMS((const char *__path, struct stat *__statbuf));
62 /* Not char because of type promotion; NeXT gcc can't handle it. */
63 typedef int boolean;
64 #define true 1
65 #define false 0
67 /* Pointer to function returning boolean. */
68 typedef boolean (*PFB)();
70 /* The number of seconds in a day. */
71 #define DAYSECS 86400
73 /* Argument structures for predicates. */
75 enum comparison_type
77 COMP_GT,
78 COMP_LT,
79 COMP_EQ
82 enum predicate_type
84 NO_TYPE,
85 PRIMARY_TYPE,
86 UNI_OP,
87 BI_OP,
88 OPEN_PAREN,
89 CLOSE_PAREN
92 enum predicate_precedence
94 NO_PREC,
95 COMMA_PREC,
96 OR_PREC,
97 AND_PREC,
98 NEGATE_PREC,
99 MAX_PREC
102 struct long_val
104 enum comparison_type kind;
105 unsigned long l_val;
108 struct size_val
110 enum comparison_type kind;
111 int blocksize;
112 unsigned long size;
115 struct path_arg
117 short offset; /* Offset in `vec' of this arg. */
118 short count; /* Number of path replacements in this arg. */
119 char *origarg; /* Arg with "{}" intact. */
122 struct exec_val
124 struct path_arg *paths; /* Array of args with path replacements. */
125 char **vec; /* Array of args to pass to program. */
128 /* The format string for a -printf or -fprintf is chopped into one or
129 more `struct segment', linked together into a list.
130 Each stretch of plain text is a segment, and
131 each \c and `%' conversion is a segment. */
133 /* Special values for the `kind' field of `struct segment'. */
134 #define KIND_PLAIN 0 /* Segment containing just plain text. */
135 #define KIND_STOP 1 /* \c -- stop printing and flush output. */
137 struct segment
139 int kind; /* Format chars or KIND_{PLAIN,STOP}. */
140 char *text; /* Plain text or `%' format string. */
141 int text_len; /* Length of `text'. */
142 struct segment *next; /* Next segment for this predicate. */
145 struct format_val
147 struct segment *segment; /* Linked list of segments. */
148 FILE *stream; /* Output stream to print on. */
151 struct predicate
153 /* Pointer to the function that implements this predicate. */
154 PFB pred_func;
156 /* Only used for debugging, but defined unconditionally so individual
157 modules can be compiled with -DDEBUG. */
158 char *p_name;
160 /* The type of this node. There are two kinds. The first is real
161 predicates ("primaries") such as -perm, -print, or -exec. The
162 other kind is operators for combining predicates. */
163 enum predicate_type p_type;
165 /* The precedence of this node. Only has meaning for operators. */
166 enum predicate_precedence p_prec;
168 /* True if this predicate node produces side effects. */
169 boolean side_effects;
171 /* True if this predicate node requires a stat system call to execute. */
172 boolean need_stat;
174 /* Information needed by the predicate processor.
175 Next to each member are listed the predicates that use it. */
176 union
178 char *str; /* fstype [i]lname [i]name [i]path */
179 struct re_pattern_buffer *regex; /* regex */
180 struct exec_val exec_vec; /* exec ok */
181 struct long_val info; /* atime ctime mtime inum links */
182 struct size_val size; /* size */
183 uid_t uid; /* user */
184 gid_t gid; /* group */
185 time_t time; /* newer */
186 unsigned long perm; /* perm */
187 unsigned long type; /* type */
188 FILE *stream; /* fprint fprint0 */
189 struct format_val printf_vec; /* printf fprintf */
190 } args;
192 /* The next predicate in the user input sequence,
193 which repesents the order in which the user supplied the
194 predicates on the command line. */
195 struct predicate *pred_next;
197 /* The right and left branches from this node in the expression
198 tree, which represents the order in which the nodes should be
199 processed. */
200 struct predicate *pred_left;
201 struct predicate *pred_right;
204 /* find library function declarations. */
206 /* dirname.c */
207 char *dirname PARAMS((char *path));
209 /* error.c */
210 void error PARAMS((int status, int errnum, char *message, ...));
212 /* listfile.c */
213 void list_file PARAMS((char *name, char *relname, struct stat *statp, FILE *stream));
214 char *get_link_name PARAMS((char *name, char *relname));
216 /* savedir.c */
217 char *savedir PARAMS((char *dir, unsigned name_size));
219 /* stpcpy.c */
220 #if !HAVE_STPCPY
221 char *stpcpy PARAMS((char *dest, const char *src));
222 #endif
224 /* xgetcwd.c */
225 char *xgetcwd PARAMS((void));
227 /* xmalloc.c */
228 #if __STDC__
229 #define VOID void
230 #else
231 #define VOID char
232 #endif
234 VOID *xmalloc PARAMS((size_t n));
235 VOID *xrealloc PARAMS((VOID *p, size_t n));
237 /* xstrdup.c */
238 char *xstrdup PARAMS((char *string));
240 /* find global function declarations. */
242 /* fstype.c */
243 char *filesystem_type PARAMS((char *path, char *relpath, struct stat *statp));
245 /* parser.c */
246 PFB find_parser PARAMS((char *search_name));
247 boolean parse_close PARAMS((char *argv[], int *arg_ptr));
248 boolean parse_open PARAMS((char *argv[], int *arg_ptr));
249 boolean parse_print PARAMS((char *argv[], int *arg_ptr));
251 /* pred.c */
252 boolean pred_amin PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
253 boolean pred_and PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
254 boolean pred_anewer PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
255 boolean pred_atime PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
256 boolean pred_close PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
257 boolean pred_cmin PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
258 boolean pred_cnewer PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
259 boolean pred_comma PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
260 boolean pred_ctime PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
261 boolean pred_empty PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
262 boolean pred_exec PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
263 boolean pred_false PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
264 boolean pred_fls PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
265 boolean pred_fprint PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
266 boolean pred_fprint0 PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
267 boolean pred_fprintf PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
268 boolean pred_fstype PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
269 boolean pred_gid PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
270 boolean pred_group PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
271 boolean pred_ilname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
272 boolean pred_iname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
273 boolean pred_inum PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
274 boolean pred_ipath PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
275 boolean pred_links PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
276 boolean pred_lname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
277 boolean pred_ls PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
278 boolean pred_mmin PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
279 boolean pred_mtime PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
280 boolean pred_name PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
281 boolean pred_negate PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
282 boolean pred_newer PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
283 boolean pred_nogroup PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
284 boolean pred_nouser PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
285 boolean pred_ok PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
286 boolean pred_open PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
287 boolean pred_or PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
288 boolean pred_path PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
289 boolean pred_perm PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
290 boolean pred_print PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
291 boolean pred_print0 PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
292 boolean pred_prune PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
293 boolean pred_regex PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
294 boolean pred_size PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
295 boolean pred_true PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
296 boolean pred_type PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
297 boolean pred_uid PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
298 boolean pred_used PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
299 boolean pred_user PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
300 boolean pred_xtype PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
301 char *find_pred_name PARAMS((PFB pred_func));
302 #ifdef DEBUG
303 void print_tree PARAMS((struct predicate *node, int indent));
304 void print_list PARAMS((struct predicate *node));
305 #endif /* DEBUG */
307 /* tree.c */
308 struct predicate *
309 get_expr (struct predicate **input, short int prev_prec);
310 boolean opt_expr PARAMS((struct predicate **eval_treep));
311 boolean mark_stat PARAMS((struct predicate *tree));
313 /* util.c */
314 char *base_name PARAMS((const char *fname));
315 struct predicate *get_new_pred PARAMS((void));
316 struct predicate *get_new_pred_chk_op PARAMS((void));
317 struct predicate *insert_primary PARAMS((boolean (*pred_func )()));
318 void usage PARAMS((char *msg));
320 extern char *program_name;
321 extern struct predicate *predicates;
322 extern struct predicate *last_pred;
323 extern boolean do_dir_first;
324 extern int maxdepth;
325 extern int mindepth;
326 extern int curdepth;
327 extern time_t cur_day_start;
328 extern boolean full_days;
329 extern boolean no_leaf_check;
330 extern boolean stay_on_filesystem;
331 extern boolean stop_at_current_level;
332 extern boolean have_stat;
333 extern char *rel_pathname;
334 #ifndef HAVE_FCHDIR
335 extern char *starting_dir;
336 #else
337 extern int starting_desc;
338 #endif
339 extern int exit_status;
340 extern int path_length;
341 extern int (*xstat) ();
342 extern boolean dereference;