BRL-CAD
search.h
Go to the documentation of this file.
1 /* S E A R C H . H
2  * BRL-CAD
3  *
4  * Copyright (c) 2008-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 
21 /* Includes code from OpenBSD's find command:
22  *
23  * Copyright (c) 1990, 1993
24  * The Regents of the University of California. All rights reserved.
25  *
26  * This code is derived from software contributed to Berkeley by
27  * Cimarron D. Taylor of the University of California, Berkeley.
28  *
29  * Redistribution and use in source and binary forms, with or without
30  * modification, are permitted provided that the following conditions
31  * are met:
32  * 1. Redistributions of source code must retain the above copyright
33  * notice, this list of conditions and the following disclaimer.
34  * 2. Redistributions in binary form must reproduce the above copyright
35  * notice, this list of conditions and the following disclaimer in the
36  * documentation and/or other materials provided with the distribution.
37  * 3. Neither the name of the University nor the names of its contributors
38  * may be used to endorse or promote products derived from this software
39  * without specific prior written permission.
40  *
41  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
42  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
45  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  *
53  */
54 
55 #ifndef LIBRT_SEARCH_H
56 #define LIBRT_SEARCH_H
57 
58 #include "common.h"
59 
60 #include "regex.h"
61 #include "raytrace.h"
62 
63 /* node struct - holds data specific to each node under consideration */
64 struct db_node_t {
65  struct db_full_path *path;
67  int flags;
69 };
70 
71 /* search node type */
73  N_ABOVE = 1, /* must start > 0 */
79 };
80 
81 
82 struct db_plan_t {
83  struct db_plan_t *next; /* next node */
84  int (*eval)(struct db_plan_t *, struct db_node_t *, struct db_i *dbip, struct bu_ptbl *results);
85  /* node evaluation function */
86 #define F_EQUAL 1 /* [acm]time inum links size */
87 #define F_LESSTHAN 2
88 #define F_GREATER 3
89 #define F_NEEDOK 1 /* exec ok */
90 #define F_MTFLAG 1 /* fstype */
91 #define F_MTTYPE 2
92 #define F_ATLEAST 1 /* perm */
93  int min_depth;
94  int max_depth;
95  int flags; /* private flags */
96  enum db_search_ntype type; /* plan node type */
97  union {
98  gid_t _g_data; /* gid */
99  struct {
100  unsigned int _f_flags;
101  unsigned int _f_mask;
102  } fl;
103  struct db_plan_t *_p_data[2]; /* PLAN trees */
104  struct _ex {
105  char **_e_argv; /* argv array */
106  char **_e_orig; /* original strings */
107  int *_e_len; /* allocated length */
108  } ex;
109  struct db_plan_t *_ab_data[2]; /* PLAN trees */
110  struct db_plan_t *_bl_data[2]; /* PLAN trees */
111  char *_a_data[2]; /* array of char pointers */
112  char *_c_data; /* char pointer */
113  char *_ci_data; /* char pointer */
114  char *_path_data; /* char pointer */
115  char *_attr_data; /* char pointer */
116  char *_param_data; /* char pointer */
117  char *_depth_data; /* char pointer */
118  char *_node_data; /* char pointer */
119  char *_type_data;
120  regex_t _regex_data; /* compiled regexp */
122  int _max_data; /* tree depth */
123  int _min_data; /* tree depth */
124  } p_un;
125 };
126 
127 
128 #define a_data p_un._a_data
129 #define c_data p_un._c_data
130 #define ci_data p_un._ci_data
131 #define path_data p_un._path_data
132 #define regexp_data p_un._regex_data
133 #define attr_data p_un._attr_data
134 #define param_data p_un._param_data
135 #define depth_data p_un._depth_data
136 #define node_data p_un._node_data
137 #define fl_flags p_un.fl._f_flags
138 #define fl_mask p_un.fl._f_mask
139 #define g_data p_un._g_data
140 #define max_data p_un._max_data
141 #define min_data p_un._min_data
142 #define p_data p_un._p_data
143 #define ab_data p_un._ab_data
144 #define bl_data p_un._bl_data
145 #define type_data p_un._type_data
146 #define bool_data p_un._bool_data
147 #define e_argv p_un.ex._e_argv
148 #define e_orig p_un.ex._e_orig
149 #define e_len p_un.ex._e_len
150 
151 typedef struct _option {
152  char *name; /* option name */
153  enum db_search_ntype token; /* token type */
154  int (*create)(char *, char ***, int, struct db_plan_t **, int *); /* create function */
155 #define O_NONE 0x01 /* no call required */
156 #define O_ZERO 0x02 /* pass: nothing */
157 #define O_ARGV 0x04 /* pass: argv, increment argv */
158 #define O_ARGVP 0x08 /* pass: *argv, N_OK || N_EXEC || N_EXECDIR */
159  int flags;
160 } OPTION;
161 
162 extern int isdepth, isoutput;
163 
165 
166 static int c_attr(char *, char ***, int, struct db_plan_t **, int *);
167 static int c_objparam(char *, char ***, int, struct db_plan_t **, int *);
168 static int c_iname(char *, char ***, int, struct db_plan_t **, int *);
169 static int c_maxdepth(char *, char ***, int, struct db_plan_t **, int *);
170 static int c_mindepth(char *, char ***, int, struct db_plan_t **, int *);
171 static int c_depth(char *, char ***, int, struct db_plan_t **, int *);
172 static int c_name(char *, char ***, int, struct db_plan_t **, int *);
173 static int c_nnodes(char *, char ***, int, struct db_plan_t **, int *);
174 static int c_regex(char *, char ***, int, struct db_plan_t **, int *);
175 static int c_iregex(char *, char ***, int, struct db_plan_t **, int *);
176 static int c_path(char *, char ***, int, struct db_plan_t **, int *);
177 static int c_print(char *, char ***, int, struct db_plan_t **, int *);
178 static int c_stdattr(char *, char ***, int, struct db_plan_t **, int *);
179 static int c_type(char *, char ***, int, struct db_plan_t **, int *);
180 static int c_bool(char *, char ***, int, struct db_plan_t **, int *);
181 static int c_openparen(char *, char ***, int, struct db_plan_t **, int *);
182 static int c_closeparen(char *, char ***, int, struct db_plan_t **, int *);
183 static int c_not(char *, char ***, int, struct db_plan_t **, int *);
184 static int c_or(char *, char ***, int, struct db_plan_t **, int *);
185 static int c_above(char *, char ***, int, struct db_plan_t **, int *);
186 static int c_below(char *, char ***, int, struct db_plan_t **, int *);
187 
189 
190 #endif /* LIBRT_SEARCH_H */
191 
192 /*
193  * Local Variables:
194  * tab-width: 8
195  * mode: C
196  * indent-tabs-mode: t
197  * c-file-style: "stroustrup"
198  * End:
199  * ex: shiftwidth=4 tabstop=8
200  */
char * name
Definition: search.h:152
Definition: search.h:74
Definition: raytrace.h:800
HIDDEN int c_bool(char *pattern, char ***ignored, int unused, struct db_plan_t **resultplan, int *db_search_isoutput)
Definition: search.c:1115
unsigned int _f_mask
Definition: search.h:101
enum db_search_ntype type
Definition: search.h:96
struct db_plan_t * _p_data[2]
Definition: search.h:103
int _min_data
Definition: search.h:123
Definition: search.h:77
Definition: search.h:78
int _bool_data
Definition: search.h:121
struct _option OPTION
Definition: search.h:78
Definition: search.h:76
char * _node_data
Definition: search.h:118
struct db_plan_t * next
Definition: search.h:83
HIDDEN int c_regex(char *pattern, char ***ignored, int unused, struct db_plan_t **resultplan, int *db_search_isoutput)
Definition: search.c:595
HIDDEN int c_objparam(char *pattern, char ***ignored, int unused, struct db_plan_t **resultplan, int *db_search_isoutput)
Definition: search.c:824
Definition: search.h:78
Definition: search.h:77
HIDDEN int c_mindepth(char *pattern, char ***ignored, int unused, struct db_plan_t **resultplan, int *db_search_isoutput)
Definition: search.c:1178
db_search_ntype
Definition: search.h:72
Definition: search.h:75
Header file for the BRL-CAD common definitions.
Definition: search.h:74
HIDDEN int c_openparen(char *ignore, char ***ignored, int unused, struct db_plan_t **resultplan, int *db_search_isoutput)
Definition: search.c:298
struct db_plan_t::@13::_ex ex
HIDDEN int c_maxdepth(char *pattern, char ***ignored, int unused, struct db_plan_t **resultplan, int *db_search_isoutput)
Definition: search.c:1149
HIDDEN int c_or(char *ignore, char ***ignored, int unused, struct db_plan_t **resultplan, int *db_search_isoutput)
Definition: search.c:469
int isdepth
gid_t _g_data
Definition: search.h:98
char * _c_data
Definition: search.h:112
int max_depth
Definition: search.h:94
Definition: ptbl.h:62
int(* create)(char *, char ***, int, struct db_plan_t **, int *)
Definition: search.h:154
HIDDEN int c_above(char *ignore, char ***ignored, int unused, struct db_plan_t **resultplan, int *db_search_isoutput)
Definition: search.c:435
HIDDEN int c_nnodes(char *pattern, char ***ignored, int unused, struct db_plan_t **resultplan, int *db_search_isoutput)
Definition: search.c:1359
HIDDEN int c_below(char *ignore, char ***ignored, int unused, struct db_plan_t **resultplan, int *db_search_isoutput)
Definition: search.c:387
Definition: search.h:73
HIDDEN int c_print(char *ignore, char ***ignored, int unused, struct db_plan_t **resultplan, int *db_search_isoutput)
Definition: search.c:1424
#define __BEGIN_DECLS
Definition: common.h:73
Definition: search.h:77
HIDDEN int c_iregex(char *pattern, char ***ignored, int unused, struct db_plan_t **resultplan, int *db_search_isoutput)
Definition: search.c:602
HIDDEN int c_not(char *ignore, char ***ignored, int unused, struct db_plan_t **resultplan, int *db_search_isoutput)
Definition: search.c:333
int flags
Definition: search.h:67
HIDDEN int c_attr(char *pattern, char ***ignored, int unused, struct db_plan_t **resultplan, int *db_search_isoutput)
Definition: search.c:898
struct db_plan_t * _bl_data[2]
Definition: search.h:110
HIDDEN int c_name(char *pattern, char ***ignored, int unused, struct db_plan_t **resultplan, int *db_search_isoutput)
Definition: search.c:502
Definition: search.h:77
int * _e_len
Definition: search.h:107
HIDDEN int c_iname(char *pattern, char ***ignored, int unused, struct db_plan_t **resultplan, int *db_search_isoutput)
Definition: search.c:539
char * _a_data[2]
Definition: search.h:111
Definition: search.h:77
char ** _e_orig
Definition: search.h:106
union db_plan_t::@13 p_un
HIDDEN int c_type(char *pattern, char ***ignored, int unused, struct db_plan_t **resultplan, int *db_search_isoutput)
Definition: search.c:1084
Definition: search.h:75
Definition: search.h:78
char * _path_data
Definition: search.h:114
char * _type_data
Definition: search.h:119
struct bu_ptbl * full_paths
Definition: search.h:66
Definition: search.h:76
int(* eval)(struct db_plan_t *, struct db_node_t *, struct db_i *dbip, struct bu_ptbl *results)
Definition: search.h:84
char ** _e_argv
Definition: search.h:105
HIDDEN int c_path(char *pattern, char ***ignored, int unused, struct db_plan_t **resultplan, int *db_search_isoutput)
Definition: search.c:1387
Definition: search.h:74
struct db_plan_t * _ab_data[2]
Definition: search.h:109
int min_depth
Definition: search.h:93
Definition: search.h:76
int _max_data
Definition: search.h:122
Definition: search.h:78
#define __END_DECLS
Definition: common.h:74
Definition: search.h:75
regex_t _regex_data
Definition: search.h:120
struct db_plan_t::@13::@14 fl
Definition: search.h:78
HIDDEN int c_depth(char *pattern, char ***ignored, int unused, struct db_plan_t **resultplan, int *db_search_isoutput)
Definition: search.c:1249
unsigned int _f_flags
Definition: search.h:100
int matched_filters
Definition: search.h:68
struct db_full_path * path
Definition: search.h:65
char * _ci_data
Definition: search.h:113
enum db_search_ntype token
Definition: search.h:153
int flags
Definition: search.h:95
char * _depth_data
Definition: search.h:117
HIDDEN int c_stdattr(char *pattern, char ***ignored, int unused, struct db_plan_t **resultplan, int *db_search_isoutput)
Definition: search.c:972
int flags
Definition: search.h:159
HIDDEN int c_closeparen(char *ignore, char ***ignored, int unused, struct db_plan_t **resultplan, int *db_search_isoutput)
Definition: search.c:306
char * _attr_data
Definition: search.h:115
char * _param_data
Definition: search.h:116
int isoutput