1139776Simp/*	$NetBSD: find.h,v 1.28 2022/01/22 14:08:19 christos Exp $	*/
2130678Sphk
364880Sphk/*-
464880Sphk * Copyright (c) 1990, 1993
564880Sphk *	The Regents of the University of California.  All rights reserved.
664880Sphk *
764880Sphk * This code is derived from software contributed to Berkeley by
864880Sphk * Cimarron D. Taylor of the University of California, Berkeley.
964880Sphk *
1064880Sphk * Redistribution and use in source and binary forms, with or without
1164880Sphk * modification, are permitted provided that the following conditions
1264880Sphk * are met:
1364880Sphk * 1. Redistributions of source code must retain the above copyright
1464880Sphk *    notice, this list of conditions and the following disclaimer.
1564880Sphk * 2. Redistributions in binary form must reproduce the above copyright
1664880Sphk *    notice, this list of conditions and the following disclaimer in the
1764880Sphk *    documentation and/or other materials provided with the distribution.
1864880Sphk * 3. Neither the name of the University nor the names of its contributors
1964880Sphk *    may be used to endorse or promote products derived from this software
2064880Sphk *    without specific prior written permission.
2164880Sphk *
2264880Sphk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2364880Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2464880Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2564880Sphk * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2664880Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2764880Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2864880Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2964880Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3064880Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3164880Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3264880Sphk * SUCH DAMAGE.
3376166Smarkm *
3464880Sphk *	from: @(#)find.h	8.1 (Berkeley) 6/6/93
3576166Smarkm */
36150342Sphk
3776166Smarkm#include <regex.h>
3864880Sphk#include <time.h>
3976166Smarkm
40150342Sphk/* node type */
4165515Sphkenum ntype {
4276166Smarkm	N_AND = 1, 				/* must start > 0 */
4364880Sphk	N_AMIN, N_ANEWER, N_ASINCE, N_ATIME, N_CLOSEPAREN, N_CMIN, N_CNEWER,
44150342Sphk	N_CSINCE, N_CTIME, N_DEPTH, N_EMPTY, N_EXEC, N_EXECDIR, N_EXIT,
4565515Sphk	N_EXPR, N_FALSE, N_FLAGS, N_FOLLOW, N_FPRINT, N_FSTYPE, N_GROUP,
4664880Sphk	N_INAME, N_INUM, N_IREGEX, N_LINKS, N_LS, N_MINDEPTH, N_MAXDEPTH,
47149144Sphk	N_MMIN, N_MTIME, N_NAME, N_NEWER, N_NOGROUP, N_NOT, N_NOUSER, N_OK,
4864880Sphk	N_OPENPAREN, N_OR, N_PATH, N_PERM, N_PRINT, N_PRINT0, N_PRINTX,
49163606Srwatson	N_PRUNE, N_REGEX, N_SINCE, N_SIZE, N_TYPE, N_USER, N_XDEV, N_DELETE
50163606Srwatson};
51150342Sphk
52150342Sphk/* node definition */
53150342Sphktypedef struct _plandata {
54150342Sphk	struct _plandata *next;			/* next node */
55163481Skib	int (*eval)(struct _plandata *, FTSENT *);
5665515Sphk						/* node evaluation function */
57150342Sphk#define	F_EQUAL		1			/* [acm]time inum links size */
5869767Sphk#define	F_LESSTHAN	2
59150342Sphk#define	F_GREATER	3
60150342Sphk#define	F_NEEDOK	1			/* exec ok */
61150342Sphk#define	F_PLUSSET	2			/* -exec ... {} + */
62150342Sphk#define	F_MTFLAG	1			/* fstype */
63150342Sphk#define	F_MTTYPE	2
64141633Sphk#define	F_ATLEAST	1			/* perm */
65150342Sphk	int flags;				/* private flags */
66150342Sphk	enum ntype type;			/* plan node type */
6765515Sphk	union {
6865515Sphk		uint32_t _f_data;		/* flags */
6965515Sphk		gid_t _g_data;			/* gid */
70150147Sphk		ino_t _i_data;			/* inode */
71150147Sphk		mode_t _m_data;			/* mode mask */
72150342Sphk		nlink_t _l_data;		/* link count */
73150147Sphk		off_t _o_data;			/* file size */
74149146Sphk		time_t _t_data;			/* time value */
75203292Sed		struct timespec _ts_data;	/* time value */
76203292Sed		uid_t _u_data;			/* uid */
77149146Sphk		short _mt_data;			/* mount flags */
78149146Sphk		struct _plandata *_p_data[2];	/* PLAN trees */
79149146Sphk		struct _ex {
80149146Sphk			char **_e_argv;		/* argv array */
81149146Sphk			char **_e_orig;		/* original strings */
82149146Sphk			size_t *_e_len;		/* allocated length */
83150342Sphk			char **_ep_bxp;		/* ptr to 1st addt'l arg */
84203292Sed			char *_ep_p;		/* current buffer pointer */
85149146Sphk			char *_ep_bbp;		/* begin buffer pointer */
86149146Sphk			char *_ep_ebp;		/* end buffer pointer */
87149146Sphk			int _ep_maxargs;	/* max #args */
88149146Sphk			int _ep_narg;		/* # addt'l args */
89149146Sphk			int _ep_rval;		/* return value */
90203292Sed		} ex;
91203292Sed		char *_a_data[2];		/* array of char pointers */
92150342Sphk		char *_c_data;			/* char pointer */
93150342Sphk		int _exit_val;			/* exit value */
94203292Sed		int _max_data;			/* tree depth */
95203292Sed		int _min_data;			/* tree depth */
96203292Sed		regex_t _regexp_data;		/* compiled regexp */
97150342Sphk		FILE *_fprint_file;		/* file stream for -fprint */
98203292Sed	} p_un;
99150342Sphk} PLAN;
100203292Sed#define	a_data		p_un._a_data
101203292Sed#define	c_data		p_un._c_data
102203292Sed#define	i_data		p_un._i_data
103203292Sed#define	f_data		p_un._f_data
104149146Sphk#define	g_data		p_un._g_data
105149146Sphk#define	l_data		p_un._l_data
106149146Sphk#define	m_data		p_un._m_data
107187864Sed#define	mt_data		p_un._mt_data
108187864Sed#define	o_data		p_un._o_data
109187864Sed#define	p_data		p_un._p_data
110149146Sphk#define	t_data		p_un._t_data
111149146Sphk#define	ts_data		p_un._ts_data
112149146Sphk#define	u_data		p_un._u_data
113149146Sphk#define	e_argv		p_un.ex._e_argv
114150342Sphk#define	e_orig		p_un.ex._e_orig
115150342Sphk#define	e_len		p_un.ex._e_len
11665515Sphk#define	ep_p		p_un.ex._ep_p
117150342Sphk#define	ep_bbp		p_un.ex._ep_bbp
118207729Skib#define	ep_ebp		p_un.ex._ep_ebp
11965515Sphk#define	ep_bxp		p_un.ex._ep_bxp
120150342Sphk#define	ep_cnt		p_un.ex._ep_cnt
121150342Sphk#define	ep_maxargs	p_un.ex._ep_maxargs
122183230Sed#define	ep_nline	p_un.ex._ep_nline
12365515Sphk#define	ep_narg		p_un.ex._ep_narg
124207729Skib#define	ep_rval		p_un.ex._ep_rval
125207729Skib#define	exit_val	p_un._exit_val
126207729Skib#define	max_data	p_un._max_data
127207729Skib#define	min_data	p_un._min_data
12865515Sphk#define	regexp_data	p_un._regexp_data
129150342Sphk#define	fprint_file	p_un._fprint_file
130150342Sphk
131150342Sphktypedef struct _option {
132207729Skib	const char *name;			/* option name */
13365515Sphk	enum ntype token;			/* token type */
134150342Sphk	PLAN *(*create)(char ***, int, char *);	/* create function */
13565515Sphk	int arg;				/* function needs arg */
136150342Sphk} OPTION;
137150342Sphk
138183230Sed#include "extern.h"
139183230Sed