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