'cvs status' should ignore Makefile.in
[findutils.git] / find / defs.h
blob21d0a715de66c62ebecac4eb1473da013b7f7ff4
1 /* defs.h -- data types and declarations.
2 Copyright (C) 1990, 91, 92, 93, 94, 2000 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., 9 Temple Place - Suite 330, Boston, MA 02111-1307,
17 USA.
20 #include <config.h>
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <stdio.h>
25 #if defined(HAVE_STRING_H) || defined(STDC_HEADERS)
26 #include <string.h>
27 #else
28 #include <strings.h>
29 #ifndef strchr
30 #define strchr index
31 #endif
32 #ifndef strrchr
33 #define strrchr rindex
34 #endif
35 #endif
37 #include <errno.h>
38 #ifndef errno
39 extern int errno;
40 #endif
42 #ifdef STDC_HEADERS
43 #include <stdlib.h>
44 #endif
46 #ifdef HAVE_UNISTD_H
47 #include <unistd.h>
48 #endif
50 #include <time.h>
52 #if HAVE_LIMITS_H
53 # include <limits.h>
54 #endif
55 #ifndef CHAR_BIT
56 # define CHAR_BIT 8
57 #endif
59 #if HAVE_INTTYPES_H
60 # include <inttypes.h>
61 #endif
63 #include "regex.h"
65 #ifndef S_IFLNK
66 #define lstat stat
67 #endif
69 # ifndef PARAMS
70 # if defined PROTOTYPES || (defined __STDC__ && __STDC__)
71 # define PARAMS(Args) Args
72 # else
73 # define PARAMS(Args) ()
74 # endif
75 # endif
77 int lstat PARAMS((const char *__path, struct stat *__statbuf));
78 int stat PARAMS((const char *__path, struct stat *__statbuf));
80 #ifndef S_ISUID
81 # define S_ISUID 0004000
82 #endif
83 #ifndef S_ISGID
84 # define S_ISGID 0002000
85 #endif
86 #ifndef S_ISVTX
87 # define S_ISVTX 0001000
88 #endif
89 #ifndef S_IRUSR
90 # define S_IRUSR 0000400
91 #endif
92 #ifndef S_IWUSR
93 # define S_IWUSR 0000200
94 #endif
95 #ifndef S_IXUSR
96 # define S_IXUSR 0000100
97 #endif
98 #ifndef S_IRGRP
99 # define S_IRGRP 0000040
100 #endif
101 #ifndef S_IWGRP
102 # define S_IWGRP 0000020
103 #endif
104 #ifndef S_IXGRP
105 # define S_IXGRP 0000010
106 #endif
107 #ifndef S_IROTH
108 # define S_IROTH 0000004
109 #endif
110 #ifndef S_IWOTH
111 # define S_IWOTH 0000002
112 #endif
113 #ifndef S_IXOTH
114 # define S_IXOTH 0000001
115 #endif
117 #define MODE_WXUSR (S_IWUSR | S_IXUSR)
118 #define MODE_R (S_IRUSR | S_IRGRP | S_IROTH)
119 #define MODE_RW (S_IWUSR | S_IWGRP | S_IWOTH | MODE_R)
120 #define MODE_RWX (S_IXUSR | S_IXGRP | S_IXOTH | MODE_RW)
121 #define MODE_ALL (S_ISUID | S_ISGID | S_ISVTX | MODE_RWX)
123 #if 1
124 #include <stdbool.h>
125 typedef bool boolean;
126 #else
127 /* Not char because of type promotion; NeXT gcc can't handle it. */
128 typedef int boolean;
129 #define true 1
130 #define false 0
131 #endif
133 /* Pointer to function returning boolean. */
134 typedef boolean (*PFB)();
136 /* The number of seconds in a day. */
137 #define DAYSECS 86400
139 /* Argument structures for predicates. */
141 enum comparison_type
143 COMP_GT,
144 COMP_LT,
145 COMP_EQ
148 enum permissions_type
150 PERM_AT_LEAST,
151 PERM_ANY,
152 PERM_EXACT
155 enum predicate_type
157 NO_TYPE,
158 PRIMARY_TYPE,
159 UNI_OP,
160 BI_OP,
161 OPEN_PAREN,
162 CLOSE_PAREN
165 enum predicate_precedence
167 NO_PREC,
168 COMMA_PREC,
169 OR_PREC,
170 AND_PREC,
171 NEGATE_PREC,
172 MAX_PREC
175 struct long_val
177 enum comparison_type kind;
178 boolean negative; /* Defined only when representing time_t. */
179 uintmax_t l_val;
182 struct perm_val
184 enum permissions_type kind;
185 mode_t val;
188 struct size_val
190 enum comparison_type kind;
191 int blocksize;
192 uintmax_t size;
195 struct path_arg
197 short offset; /* Offset in `vec' of this arg. */
198 short count; /* Number of path replacements in this arg. */
199 char *origarg; /* Arg with "{}" intact. */
202 struct exec_val
204 struct path_arg *paths; /* Array of args with path replacements. */
205 char **vec; /* Array of args to pass to program. */
208 /* The format string for a -printf or -fprintf is chopped into one or
209 more `struct segment', linked together into a list.
210 Each stretch of plain text is a segment, and
211 each \c and `%' conversion is a segment. */
213 /* Special values for the `kind' field of `struct segment'. */
214 #define KIND_PLAIN 0 /* Segment containing just plain text. */
215 #define KIND_STOP 1 /* \c -- stop printing and flush output. */
217 struct segment
219 int kind; /* Format chars or KIND_{PLAIN,STOP}. */
220 char *text; /* Plain text or `%' format string. */
221 int text_len; /* Length of `text'. */
222 struct segment *next; /* Next segment for this predicate. */
225 struct format_val
227 struct segment *segment; /* Linked list of segments. */
228 FILE *stream; /* Output stream to print on. */
231 struct predicate
233 /* Pointer to the function that implements this predicate. */
234 PFB pred_func;
236 /* Only used for debugging, but defined unconditionally so individual
237 modules can be compiled with -DDEBUG. */
238 char *p_name;
240 /* The type of this node. There are two kinds. The first is real
241 predicates ("primaries") such as -perm, -print, or -exec. The
242 other kind is operators for combining predicates. */
243 enum predicate_type p_type;
245 /* The precedence of this node. Only has meaning for operators. */
246 enum predicate_precedence p_prec;
248 /* True if this predicate node produces side effects.
249 If side_effects are produced
250 then optimization will not be performed */
251 boolean side_effects;
253 /* True if this predicate node requires default print be turned off. */
254 boolean no_default_print;
256 /* True if this predicate node requires a stat system call to execute. */
257 boolean need_stat;
259 /* Information needed by the predicate processor.
260 Next to each member are listed the predicates that use it. */
261 union
263 char *str; /* fstype [i]lname [i]name [i]path */
264 struct re_pattern_buffer *regex; /* regex */
265 struct exec_val exec_vec; /* exec ok */
266 struct long_val info; /* atime ctime gid inum links mtime
267 size uid */
268 struct size_val size; /* size */
269 uid_t uid; /* user */
270 gid_t gid; /* group */
271 time_t time; /* newer */
272 struct perm_val perm; /* perm */
273 mode_t type; /* type */
274 FILE *stream; /* fprint fprint0 */
275 struct format_val printf_vec; /* printf fprintf */
276 } args;
278 /* The next predicate in the user input sequence,
279 which repesents the order in which the user supplied the
280 predicates on the command line. */
281 struct predicate *pred_next;
283 /* The right and left branches from this node in the expression
284 tree, which represents the order in which the nodes should be
285 processed. */
286 struct predicate *pred_left;
287 struct predicate *pred_right;
290 /* find library function declarations. */
292 /* dirname.c */
293 char *dirname PARAMS((char *path));
295 /* error.c */
296 void error PARAMS((int status, int errnum, char *message, ...));
298 /* listfile.c */
299 void list_file PARAMS((char *name, char *relname, struct stat *statp, time_t current_time, int output_block_size, FILE *stream));
300 char *get_link_name PARAMS((char *name, char *relname));
302 /* stpcpy.c */
303 #if !HAVE_STPCPY
304 char *stpcpy PARAMS((char *dest, const char *src));
305 #endif
307 /* xgetcwd.c */
308 char *xgetcwd PARAMS((void));
310 /* xmalloc.c */
311 #if __STDC__
312 #define VOID void
313 #else
314 #define VOID char
315 #endif
317 VOID *xmalloc PARAMS((size_t n));
318 VOID *xrealloc PARAMS((VOID *p, size_t n));
320 /* xstrdup.c */
321 char *xstrdup PARAMS((char *string));
323 /* find global function declarations. */
325 /* fstype.c */
326 char *filesystem_type PARAMS((char *path, char *relpath, struct stat *statp));
328 /* parser.c */
329 PFB find_parser PARAMS((char *search_name));
330 boolean parse_close PARAMS((char *argv[], int *arg_ptr));
331 boolean parse_open PARAMS((char *argv[], int *arg_ptr));
332 boolean parse_print PARAMS((char *argv[], int *arg_ptr));
334 /* pred.c */
335 boolean pred_amin PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
336 boolean pred_and PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
337 boolean pred_anewer PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
338 boolean pred_atime PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
339 boolean pred_close PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
340 boolean pred_cmin PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
341 boolean pred_cnewer PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
342 boolean pred_comma PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
343 boolean pred_ctime PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
344 boolean pred_empty PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
345 boolean pred_exec PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
346 boolean pred_false PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
347 boolean pred_fls PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
348 boolean pred_fprint PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
349 boolean pred_fprint0 PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
350 boolean pred_fprintf PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
351 boolean pred_fstype PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
352 boolean pred_gid PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
353 boolean pred_group PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
354 boolean pred_ilname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
355 boolean pred_iname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
356 boolean pred_inum PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
357 boolean pred_ipath PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
358 boolean pred_links PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
359 boolean pred_lname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
360 boolean pred_ls PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
361 boolean pred_mmin PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
362 boolean pred_mtime PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
363 boolean pred_name PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
364 boolean pred_negate PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
365 boolean pred_newer PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
366 boolean pred_nogroup PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
367 boolean pred_nouser PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
368 boolean pred_ok PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
369 boolean pred_open PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
370 boolean pred_or PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
371 boolean pred_path PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
372 boolean pred_perm PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
373 boolean pred_print PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
374 boolean pred_print0 PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
375 boolean pred_prune PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
376 boolean pred_regex PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
377 boolean pred_size PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
378 boolean pred_true PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
379 boolean pred_type PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
380 boolean pred_uid PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
381 boolean pred_used PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
382 boolean pred_user PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
383 boolean pred_xtype PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
384 char *find_pred_name PARAMS((PFB pred_func));
385 #ifdef DEBUG
386 void print_tree PARAMS((struct predicate *node, int indent));
387 void print_list PARAMS((struct predicate *node));
388 #endif /* DEBUG */
390 /* tree.c */
391 struct predicate *
392 get_expr PARAMS((struct predicate **input, short int prev_prec));
393 boolean opt_expr PARAMS((struct predicate **eval_treep));
394 boolean mark_stat PARAMS((struct predicate *tree));
396 /* util.c */
397 struct predicate *get_new_pred PARAMS((void));
398 struct predicate *get_new_pred_chk_op PARAMS((void));
399 struct predicate *insert_primary PARAMS((boolean (*pred_func )()));
400 void usage PARAMS((char *msg));
402 extern char *program_name;
403 extern struct predicate *predicates;
404 extern struct predicate *last_pred;
405 extern boolean do_dir_first;
406 extern int maxdepth;
407 extern int mindepth;
408 extern int curdepth;
409 extern int output_block_size;
410 extern time_t start_time;
411 extern time_t cur_day_start;
412 extern boolean full_days;
413 extern boolean no_leaf_check;
414 extern boolean stay_on_filesystem;
415 extern boolean ignore_readdir_race;
416 extern boolean stop_at_current_level;
417 extern boolean have_stat;
418 extern char *rel_pathname;
419 extern char const *starting_dir;
420 extern int starting_desc;
421 #if ! defined HAVE_FCHDIR && ! defined fchdir
422 # define fchdir(fd) (-1)
423 #endif
424 extern int exit_status;
425 extern int path_length;
426 extern int (*xstat) ();
427 extern boolean dereference;