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