1 /* @(#)find.h	1.27 18/08/30 Copyright 2005-2018 J. Schilling */
2 /*
3  *	Definitions for libfind users.
4  *
5  *	Copyright (c) 2004-2018 J. Schilling
6  */
7 /*
8  * The contents of this file are subject to the terms of the
9  * Common Development and Distribution License, Version 1.0 only
10  * (the "License").  You may not use this file except in compliance
11  * with the License.
12  *
13  * See the file CDDL.Schily.txt in this distribution for details.
14  * A copy of the CDDL is also available via the Internet at
15  * http://www.opensource.org/licenses/cddl1.txt
16  *
17  * When distributing Covered Code, include this CDDL HEADER in each
18  * file and include the License file CDDL.Schily.txt from this distribution.
19  */
20 
21 #ifndef	_SCHILY_FIND_H
22 #define	_SCHILY_FIND_H
23 
24 #ifndef _SCHILY_MCONFIG_H
25 #include <schily/mconfig.h>
26 #endif
27 
28 #ifndef _SCHILY_STDIO_H
29 #include <schily/stdio.h>
30 #endif
31 
32 #ifndef _SCHILY_STANDARD_H
33 #include <schily/standard.h>
34 #endif
35 #ifndef	_SCHILY_INTTYPES_H
36 #include <schily/inttypes.h>
37 #endif
38 #ifndef _SCHILY_STAT_H
39 #include <schily/stat.h>
40 #endif
41 
42 #ifdef	__cplusplus
43 extern "C" {
44 #endif
45 
46 #ifndef	__sqfun_t_defined
47 typedef	int	(*sqfun_t)	__PR((void *arg));
48 #define	__sqfun_t_defined
49 #endif
50 
51 #ifndef	__cbfun_t_defined
52 typedef	int	(*cbfun_t)	__PR((int ac, char  **argv));
53 #define	__cbfun_t_defined
54 #endif
55 
56 typedef struct find_args {
57 	int	Argc;		/* A copy of argc		*/
58 	char	**Argv;		/* A copy of argv		*/
59 	FILE	*std[3];	/* To redirect stdin/stdout/err	*/
60 	char	*primarg;	/* If != 0 arg for last primary	*/
61 	char	*primname;	/* The name of the last primary	*/
62 	int	primtype;	/* The type of the last primary	*/
63 	BOOL	found_action;	/* -print/-ls/-exec found	*/
64 	int	patlen;		/* strlen() for longest pattern	*/
65 	int	walkflags;	/* Walkflags modifed by parser	*/
66 	int	maxdepth;	/* -mindepth arg		*/
67 	int	mindepth;	/* -maxdepth arg		*/
68 	struct plusargs *plusp;	/* List of -exec {} + commands	*/
69 	void	*jmp;		/* Used internally by parser	*/
70 	int	error;		/* Error code from find_parse()	*/
71 	int	argsize;	/* Argument size for this cmd	*/
72 	cbfun_t	callfun;	/* Callback function for -call	*/
73 	void	*__reserved[16]; /* For future extensions	*/
74 } finda_t;
75 
76 /*
77  * finda_t->primtype is set to ENDARGS by find_parse() if a complete expression
78  * could be parsed.
79  */
80 #define	FIND_ENDARGS	1000	/* Found End of Arg Vector		*/
81 #define	FIND_ERRARG	1001	/* Parser abort by -help or error	*/
82 
83 /*
84  * Flags used for struct WALK->pflags:
85  */
86 #define	PF_ACL		0x00001	/* Check ACL from struct WALK->pflags	*/
87 #define	PF_HAS_ACL	0x10000	/* This file has ACL			*/
88 #define	PF_XATTR	0x00002	/* Check XATTR from struct WALK->pflags	*/
89 #define	PF_HAS_XATTR	0x20000	/* This file has XATTR			*/
90 
91 #ifndef	FIND_NODE
92 #define	findn_t	void
93 #endif
94 
95 #ifndef	__squit_t_defined
96 
97 typedef struct {
98 	sqfun_t	quitfun;	/* Function to query for shell signal quit   */
99 	void	*qfarg;		/* Generic arg for shell builtin quit fun    */
100 	Int32_t	flags;		/* Flags to identify data beyond qfarg	    */
101 	cbfun_t	callfun;	/* Callback function for -call		    */
102 	void	*__reserved[16]; /* For future extensions		    */
103 } squit_t;
104 
105 #define	SQ_CALL	0x01		/* Use call feature */
106 
107 #define	__squit_t_defined
108 #endif
109 
110 
111 extern	void	find_argsinit	__PR((finda_t *fap));
112 extern	void	find_sqinit	__PR((squit_t *quit));
113 extern	void	find_timeinit	__PR((time_t __now));
114 extern	findn_t	*find_printnode	__PR((void));
115 extern	findn_t	*find_addprint	__PR((findn_t *np, finda_t *fap));
116 extern	void	find_free	__PR((findn_t *t, finda_t *fap));
117 extern	int	find_token	__PR((char *__word));
118 extern	char	*find_tname	__PR((int op));
119 extern	findn_t	*find_parse	__PR((finda_t *fap));
120 extern	void	find_firstprim	__PR((int *pac, char *const **pav));
121 
122 extern	BOOL	find_primary	__PR((findn_t *t, int op));
123 extern	BOOL	find_pname	__PR((findn_t *t, char *__word));
124 extern	BOOL	find_hasprint	__PR((findn_t *t));
125 extern	BOOL	find_hasexec	__PR((findn_t *t));
126 extern	BOOL	find_expr	__PR((char *f, char *ff, struct stat *fs,
127 					struct WALK *state, findn_t *t));
128 
129 extern	int	find_plusflush	__PR((void *p, struct WALK *state));
130 extern	void	find_usage	__PR((FILE *f));
131 extern	char	*find_strvers	__PR((void));
132 extern	int	find_vers	__PR((void));
133 extern	int	find_main	__PR((int ac, char **av, char **ev,
134 					FILE *std[3], squit_t *__quit));
135 
136 #ifdef	__cplusplus
137 }
138 #endif
139 
140 #endif	/* _SCHILY_FIND_H */
141