Enable checking of support for --version and --help
[findutils.git] / find / defs.h
blob72207e2306a171d7f007c251fb022b3b5f938ffc
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., 59 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 int optionl_stat PARAMS((const char *name, struct stat *p));
81 int optionp_stat PARAMS((const char *name, struct stat *p));
82 int optionh_stat PARAMS((const char *name, struct stat *p));
84 #ifndef S_ISUID
85 # define S_ISUID 0004000
86 #endif
87 #ifndef S_ISGID
88 # define S_ISGID 0002000
89 #endif
90 #ifndef S_ISVTX
91 # define S_ISVTX 0001000
92 #endif
93 #ifndef S_IRUSR
94 # define S_IRUSR 0000400
95 #endif
96 #ifndef S_IWUSR
97 # define S_IWUSR 0000200
98 #endif
99 #ifndef S_IXUSR
100 # define S_IXUSR 0000100
101 #endif
102 #ifndef S_IRGRP
103 # define S_IRGRP 0000040
104 #endif
105 #ifndef S_IWGRP
106 # define S_IWGRP 0000020
107 #endif
108 #ifndef S_IXGRP
109 # define S_IXGRP 0000010
110 #endif
111 #ifndef S_IROTH
112 # define S_IROTH 0000004
113 #endif
114 #ifndef S_IWOTH
115 # define S_IWOTH 0000002
116 #endif
117 #ifndef S_IXOTH
118 # define S_IXOTH 0000001
119 #endif
121 #define MODE_WXUSR (S_IWUSR | S_IXUSR)
122 #define MODE_R (S_IRUSR | S_IRGRP | S_IROTH)
123 #define MODE_RW (S_IWUSR | S_IWGRP | S_IWOTH | MODE_R)
124 #define MODE_RWX (S_IXUSR | S_IXGRP | S_IXOTH | MODE_RW)
125 #define MODE_ALL (S_ISUID | S_ISGID | S_ISVTX | MODE_RWX)
127 #if 1
128 #include <stdbool.h>
129 typedef bool boolean;
130 #else
131 /* Not char because of type promotion; NeXT gcc can't handle it. */
132 typedef int boolean;
133 #define true 1
134 #define false 0
135 #endif
137 /* Pointer to function returning boolean. */
138 typedef boolean (*PFB)();
140 /* The number of seconds in a day. */
141 #define DAYSECS 86400
143 /* Argument structures for predicates. */
145 enum comparison_type
147 COMP_GT,
148 COMP_LT,
149 COMP_EQ
152 enum permissions_type
154 PERM_AT_LEAST,
155 PERM_ANY,
156 PERM_EXACT
159 enum predicate_type
161 NO_TYPE,
162 PRIMARY_TYPE,
163 UNI_OP,
164 BI_OP,
165 OPEN_PAREN,
166 CLOSE_PAREN
169 enum predicate_precedence
171 NO_PREC,
172 COMMA_PREC,
173 OR_PREC,
174 AND_PREC,
175 NEGATE_PREC,
176 MAX_PREC
179 struct long_val
181 enum comparison_type kind;
182 boolean negative; /* Defined only when representing time_t. */
183 uintmax_t l_val;
186 struct perm_val
188 enum permissions_type kind;
189 mode_t val;
192 struct size_val
194 enum comparison_type kind;
195 int blocksize;
196 uintmax_t size;
199 struct path_arg
201 short offset; /* Offset in `vec' of this arg. */
202 short count; /* Number of path replacements in this arg. */
203 char *origarg; /* Arg with "{}" intact. */
206 struct exec_val
208 struct path_arg *paths; /* Array of args with path replacements. */
209 char **vec; /* Array of args to pass to program. */
212 /* The format string for a -printf or -fprintf is chopped into one or
213 more `struct segment', linked together into a list.
214 Each stretch of plain text is a segment, and
215 each \c and `%' conversion is a segment. */
217 /* Special values for the `kind' field of `struct segment'. */
218 #define KIND_PLAIN 0 /* Segment containing just plain text. */
219 #define KIND_STOP 1 /* \c -- stop printing and flush output. */
221 struct segment
223 int kind; /* Format chars or KIND_{PLAIN,STOP}. */
224 char *text; /* Plain text or `%' format string. */
225 int text_len; /* Length of `text'. */
226 struct segment *next; /* Next segment for this predicate. */
229 struct format_val
231 struct segment *segment; /* Linked list of segments. */
232 FILE *stream; /* Output stream to print on. */
235 struct predicate
237 /* Pointer to the function that implements this predicate. */
238 PFB pred_func;
240 /* Only used for debugging, but defined unconditionally so individual
241 modules can be compiled with -DDEBUG. */
242 char *p_name;
244 /* The type of this node. There are two kinds. The first is real
245 predicates ("primaries") such as -perm, -print, or -exec. The
246 other kind is operators for combining predicates. */
247 enum predicate_type p_type;
249 /* The precedence of this node. Only has meaning for operators. */
250 enum predicate_precedence p_prec;
252 /* True if this predicate node produces side effects.
253 If side_effects are produced
254 then optimization will not be performed */
255 boolean side_effects;
257 /* True if this predicate node requires default print be turned off. */
258 boolean no_default_print;
260 /* True if this predicate node requires a stat system call to execute. */
261 boolean need_stat;
263 /* Information needed by the predicate processor.
264 Next to each member are listed the predicates that use it. */
265 union
267 char *str; /* fstype [i]lname [i]name [i]path */
268 struct re_pattern_buffer *regex; /* regex */
269 struct exec_val exec_vec; /* exec ok */
270 struct long_val info; /* atime ctime gid inum links mtime
271 size uid */
272 struct size_val size; /* size */
273 uid_t uid; /* user */
274 gid_t gid; /* group */
275 time_t time; /* newer */
276 struct perm_val perm; /* perm */
277 mode_t type; /* type */
278 FILE *stream; /* fprint fprint0 */
279 struct format_val printf_vec; /* printf fprintf */
280 } args;
282 /* The next predicate in the user input sequence,
283 which repesents the order in which the user supplied the
284 predicates on the command line. */
285 struct predicate *pred_next;
287 /* The right and left branches from this node in the expression
288 tree, which represents the order in which the nodes should be
289 processed. */
290 struct predicate *pred_left;
291 struct predicate *pred_right;
294 /* find library function declarations. */
296 /* dirname.c */
297 char *dirname PARAMS((char *path));
299 /* error.c */
300 void error PARAMS((int status, int errnum, char *message, ...));
302 /* listfile.c */
303 void list_file PARAMS((char *name, char *relname, struct stat *statp, time_t current_time, int output_block_size, FILE *stream));
304 char *get_link_name PARAMS((char *name, char *relname));
306 /* stpcpy.c */
307 #if !HAVE_STPCPY
308 char *stpcpy PARAMS((char *dest, const char *src));
309 #endif
311 /* xgetcwd.c */
312 char *xgetcwd PARAMS((void));
314 /* xmalloc.c */
315 #if __STDC__
316 #define VOID void
317 #else
318 #define VOID char
319 #endif
321 VOID *xmalloc PARAMS((size_t n));
322 VOID *xrealloc PARAMS((VOID *p, size_t n));
324 /* xstrdup.c */
325 char *xstrdup PARAMS((char *string));
327 /* find global function declarations. */
329 /* find.c */
330 /* SymlinkOption represents the choice of
331 * -P, -L or -P (default) on the command line.
333 enum SymlinkOption
335 SYMLINK_ALWAYS_DEREF, /* Option -L */
336 SYMLINK_NEVER_DEREF, /* Option -P */
337 SYMLINK_DEREF_ARGSONLY /* Option -H */
339 extern enum SymlinkOption symlink_handling; /* defined in find.c. */
341 void set_follow_state PARAMS((enum SymlinkOption opt));
343 /* fstype.c */
344 char *filesystem_type PARAMS((const char *path, const char *relpath, const struct stat *statp));
345 char * get_mounted_filesystems (void);
347 /* parser.c */
348 PFB find_parser PARAMS((char *search_name));
349 boolean parse_close PARAMS((char *argv[], int *arg_ptr));
350 boolean parse_open PARAMS((char *argv[], int *arg_ptr));
351 boolean parse_print PARAMS((char *argv[], int *arg_ptr));
353 /* pred.c */
354 boolean pred_amin PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
355 boolean pred_and PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
356 boolean pred_anewer PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
357 boolean pred_atime PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
358 boolean pred_close PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
359 boolean pred_cmin PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
360 boolean pred_cnewer PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
361 boolean pred_comma PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
362 boolean pred_ctime PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
363 boolean pred_delete PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
364 boolean pred_empty PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
365 boolean pred_exec PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
366 boolean pred_false PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
367 boolean pred_fls PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
368 boolean pred_fprint PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
369 boolean pred_fprint0 PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
370 boolean pred_fprintf PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
371 boolean pred_fstype PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
372 boolean pred_gid PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
373 boolean pred_group PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
374 boolean pred_ilname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
375 boolean pred_iname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
376 boolean pred_inum PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
377 boolean pred_ipath PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
378 boolean pred_links PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
379 boolean pred_lname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
380 boolean pred_ls PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
381 boolean pred_mmin PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
382 boolean pred_mtime PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
383 boolean pred_name PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
384 boolean pred_negate PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
385 boolean pred_newer PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
386 boolean pred_nogroup PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
387 boolean pred_nouser PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
388 boolean pred_ok PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
389 boolean pred_open PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
390 boolean pred_or PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
391 boolean pred_path PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
392 boolean pred_perm PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
393 boolean pred_print PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
394 boolean pred_print0 PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
395 boolean pred_prune PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
396 boolean pred_quit PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
397 boolean pred_regex PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
398 boolean pred_size PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
399 boolean pred_true PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
400 boolean pred_type PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
401 boolean pred_uid PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
402 boolean pred_used PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
403 boolean pred_user PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
404 boolean pred_xtype PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
405 char *find_pred_name PARAMS((PFB pred_func));
406 #ifdef DEBUG
407 void print_tree PARAMS((struct predicate *node, int indent));
408 void print_list PARAMS((struct predicate *node));
409 #endif /* DEBUG */
411 /* tree.c */
412 struct predicate *
413 get_expr PARAMS((struct predicate **input, short int prev_prec));
414 boolean opt_expr PARAMS((struct predicate **eval_treep));
415 boolean mark_stat PARAMS((struct predicate *tree));
417 /* util.c */
418 struct predicate *get_new_pred PARAMS((void));
419 struct predicate *get_new_pred_chk_op PARAMS((void));
420 struct predicate *insert_primary PARAMS((boolean (*pred_func )()));
421 void usage PARAMS((char *msg));
423 extern char *program_name;
424 extern struct predicate *predicates;
425 extern struct predicate *last_pred;
426 extern boolean do_dir_first;
427 extern int maxdepth;
428 extern int mindepth;
429 extern int curdepth;
430 extern int output_block_size;
431 extern time_t start_time;
432 extern time_t cur_day_start;
433 extern boolean full_days;
434 extern boolean no_leaf_check;
435 extern boolean stay_on_filesystem;
436 extern boolean ignore_readdir_race;
437 extern boolean stop_at_current_level;
438 extern boolean have_stat;
439 extern char *rel_pathname;
440 extern char const *starting_dir;
441 extern int starting_desc;
442 #if ! defined HAVE_FCHDIR && ! defined fchdir
443 # define fchdir(fd) (-1)
444 #endif
445 extern int exit_status;
446 extern int path_length;
447 extern int (*xstat) ();
448 extern boolean dereference;
449 extern boolean warnings;