Revision: 56360
http://sourceforge.net/p/brlcad/code/56360
Author: starseeker
Date: 2013-07-30 20:44:01 +0000 (Tue, 30 Jul 2013)
Log Message:
-----------
Make a stab at adding the ability to look at booleans in the tree as part of
the search command - for example, 'search /all.g -bool + ! -type arb8' will
find all objects in the tree of all.g that are intersected as part of a comb
and are not arb8 primitives. Needs more thought and testing - this may not
even be the final approach - but it seems to be a step in the right direction.
Modified Paths:
--------------
brlcad/trunk/src/librt/search.c
brlcad/trunk/src/librt/search.h
Modified: brlcad/trunk/src/librt/search.c
===================================================================
--- brlcad/trunk/src/librt/search.c 2013-07-30 20:21:32 UTC (rev 56359)
+++ brlcad/trunk/src/librt/search.c 2013-07-30 20:44:01 UTC (rev 56360)
@@ -106,6 +106,7 @@
{ "-and", N_AND, NULL, O_NONE },
{ "-attr", N_ATTR, c_attr, O_ARGV },
{ "-below", N_BELOW, c_below, O_ZERO },
+ { "-bool", N_BOOL, c_bool, O_ARGV },
{ "-bl", N_BELOW, c_below, O_ZERO },
{ "-iname", N_INAME, c_iname, O_ARGV },
{ "-iregex", N_IREGEX, c_iregex, O_ARGV },
@@ -147,26 +148,26 @@
*/
void
db_fullpath_traverse_subtree(union tree *tp,
- void (*traverse_func) (struct db_i *, struct
rt_wdb *, struct db_full_path_list *, struct db_full_path *,
- void (*) (struct db_i *,
struct rt_wdb *, struct db_full_path_list *, struct db_full_path *, genptr_t),
- void (*) (struct db_i *,
struct rt_wdb *, struct db_full_path_list *, struct db_full_path *, genptr_t),
+ void (*traverse_func) (struct db_i *, struct
rt_wdb *, struct db_full_path_list *, struct db_node_t *,
+ void (*) (struct db_i *,
struct rt_wdb *, struct db_full_path_list *, struct db_node_t *, genptr_t),
+ void (*) (struct db_i *,
struct rt_wdb *, struct db_full_path_list *, struct db_node_t *, genptr_t),
struct resource *,
genptr_t),
struct db_i *dbip,
struct rt_wdb *wdbp,
struct db_full_path_list *results,
- struct db_full_path *dfp,
- void (*comb_func) (struct db_i *, struct rt_wdb *,
struct db_full_path_list *, struct db_full_path *, genptr_t),
- void (*leaf_func) (struct db_i *, struct rt_wdb *,
struct db_full_path_list *, struct db_full_path *, genptr_t),
+ struct db_node_t *dfp,
+ void (*comb_func) (struct db_i *, struct rt_wdb *,
struct db_full_path_list *, struct db_node_t *, genptr_t),
+ void (*leaf_func) (struct db_i *, struct rt_wdb *,
struct db_full_path_list *, struct db_node_t *, genptr_t),
struct resource *resp,
genptr_t client_data)
{
struct directory *dp;
-
+
if (!tp)
return;
- RT_CK_FULL_PATH(dfp);
+ RT_CK_FULL_PATH(dfp->entry);
RT_CHECK_DBI(dbip);
RT_CK_TREE(tp);
RT_CK_RESOURCE(resp);
@@ -177,14 +178,29 @@
if ((dp=db_lookup(dbip, tp->tr_l.tl_name, LOOKUP_QUIET)) ==
RT_DIR_NULL) {
return;
} else {
- db_add_node_to_full_path(dfp, dp);
+ db_add_node_to_full_path(dfp->entry, dp);
traverse_func(dbip, wdbp, results, dfp, comb_func, leaf_func,
resp, client_data);
- DB_FULL_PATH_POP(dfp);
+ DB_FULL_PATH_POP(dfp->entry);
break;
}
case OP_UNION:
+ dfp->bool_type = 2;
+ db_fullpath_traverse_subtree(tp->tr_b.tb_left, traverse_func, dbip,
wdbp, results, dfp, comb_func, leaf_func, resp, client_data);
+ dfp->bool_type = 2;
+ db_fullpath_traverse_subtree(tp->tr_b.tb_right, traverse_func,
dbip, wdbp, results, dfp, comb_func, leaf_func, resp, client_data);
+ break;
case OP_INTERSECT:
+ dfp->bool_type = 2;
+ db_fullpath_traverse_subtree(tp->tr_b.tb_left, traverse_func, dbip,
wdbp, results, dfp, comb_func, leaf_func, resp, client_data);
+ dfp->bool_type = 3;
+ db_fullpath_traverse_subtree(tp->tr_b.tb_right, traverse_func,
dbip, wdbp, results, dfp, comb_func, leaf_func, resp, client_data);
+ break;
case OP_SUBTRACT:
+ dfp->bool_type = 2;
+ db_fullpath_traverse_subtree(tp->tr_b.tb_left, traverse_func, dbip,
wdbp, results, dfp, comb_func, leaf_func, resp, client_data);
+ dfp->bool_type = 4;
+ db_fullpath_traverse_subtree(tp->tr_b.tb_right, traverse_func,
dbip, wdbp, results, dfp, comb_func, leaf_func, resp, client_data);
+ break;
case OP_XOR:
db_fullpath_traverse_subtree(tp->tr_b.tb_left, traverse_func, dbip,
wdbp, results, dfp, comb_func, leaf_func, resp, client_data);
db_fullpath_traverse_subtree(tp->tr_b.tb_right, traverse_func,
dbip, wdbp, results, dfp, comb_func, leaf_func, resp, client_data);
@@ -210,18 +226,18 @@
db_fullpath_traverse(struct db_i *dbip,
struct rt_wdb *wdbp,
struct db_full_path_list *results,
- struct db_full_path *dfp,
- void (*comb_func) (struct db_i *, struct rt_wdb *, struct
db_full_path_list *, struct db_full_path *, genptr_t),
- void (*leaf_func) (struct db_i *, struct rt_wdb *, struct
db_full_path_list *, struct db_full_path *, genptr_t),
+ struct db_node_t *dfp,
+ void (*comb_func) (struct db_i *, struct rt_wdb *, struct
db_full_path_list *, struct db_node_t *, genptr_t),
+ void (*leaf_func) (struct db_i *, struct rt_wdb *, struct
db_full_path_list *, struct db_node_t *, genptr_t),
struct resource *resp,
genptr_t client_data)
{
struct directory *dp;
size_t i;
- RT_CK_FULL_PATH(dfp);
+ RT_CK_FULL_PATH(dfp->entry);
RT_CK_DBI(dbip);
- dp = DB_FULL_PATH_CUR_DIR(dfp);
+ dp = DB_FULL_PATH_CUR_DIR(dfp->entry);
if (!dp)
return;
@@ -244,9 +260,9 @@
LOOKUP_QUIET)) == RT_DIR_NULL) {
continue;
} else {
- db_add_node_to_full_path(dfp, mdp);
+ db_add_node_to_full_path(dfp->entry, mdp);
db_fullpath_traverse(dbip, wdbp, results, dfp, comb_func,
leaf_func, resp, client_data);
- DB_FULL_PATH_POP(dfp);
+ DB_FULL_PATH_POP(dfp->entry);
}
}
bu_free((char *)rp, "db_preorder_traverse[]");
@@ -273,7 +289,7 @@
static struct db_plan_t *
-palloc(enum db_search_ntype t, int (*f)(struct db_plan_t *, struct
db_full_path *, struct db_i *, struct rt_wdb *, struct db_full_path_list *))
+palloc(enum db_search_ntype t, int (*f)(struct db_plan_t *, struct db_node_t
*, struct db_i *, struct rt_wdb *, struct db_full_path_list *))
{
struct db_plan_t *newplan;
@@ -290,7 +306,7 @@
* True if expression is true.
*/
HIDDEN int
-f_expr(struct db_plan_t *plan, struct db_full_path *entry, struct db_i *dbip,
struct rt_wdb *wdbp, struct db_full_path_list *results)
+f_expr(struct db_plan_t *plan, struct db_node_t *entry, struct db_i *dbip,
struct rt_wdb *wdbp, struct db_full_path_list *results)
{
struct db_plan_t *p = NULL;
int state = 0;
@@ -310,7 +326,7 @@
HIDDEN int
c_openparen(char *UNUSED(ignore), char ***UNUSED(ignored), int UNUSED(unused),
struct db_plan_t **resultplan, int *UNUSED(db_search_isoutput))
{
- (*resultplan) = (palloc(N_OPENPAREN, (int (*)(struct db_plan_t *, struct
db_full_path *, struct db_i *, struct rt_wdb *, struct db_full_path_list
*))-1));
+ (*resultplan) = (palloc(N_OPENPAREN, (int (*)(struct db_plan_t *, struct
db_node_t *, struct db_i *, struct rt_wdb *, struct db_full_path_list *))-1));
return BRLCAD_OK;
}
@@ -318,7 +334,7 @@
HIDDEN int
c_closeparen(char *UNUSED(ignore), char ***UNUSED(ignored), int
UNUSED(unused), struct db_plan_t **resultplan, int *UNUSED(db_search_isoutput))
{
- (*resultplan) = (palloc(N_CLOSEPAREN, (int (*)(struct db_plan_t *, struct
db_full_path *, struct db_i *, struct rt_wdb *, struct db_full_path_list
*))-1));
+ (*resultplan) = (palloc(N_CLOSEPAREN, (int (*)(struct db_plan_t *, struct
db_node_t *, struct db_i *, struct rt_wdb *, struct db_full_path_list *))-1));
return BRLCAD_OK;
}
@@ -329,7 +345,7 @@
* Negation of a primary; the unary NOT operator.
*/
HIDDEN int
-f_not(struct db_plan_t *plan, struct db_full_path *entry, struct db_i *dbip,
struct rt_wdb *wdbp, struct db_full_path_list *results)
+f_not(struct db_plan_t *plan, struct db_node_t *entry, struct db_i *dbip,
struct rt_wdb *wdbp, struct db_full_path_list *results)
{
struct db_plan_t *p = NULL;
int state = 0;
@@ -350,7 +366,7 @@
HIDDEN int
-find_execute_nested_plans(struct db_i *dbip, struct rt_wdb *wdbp, struct
db_full_path_list *results, struct db_full_path *entry, genptr_t inputplan) {
+find_execute_nested_plans(struct db_i *dbip, struct rt_wdb *wdbp, struct
db_full_path_list *results, struct db_node_t *entry, genptr_t inputplan) {
struct db_plan_t *p = NULL;
struct db_plan_t *plan = (struct db_plan_t *)inputplan;
int state = 0;
@@ -371,15 +387,17 @@
* objects at any level above the current object depth.
*/
HIDDEN int
-f_above(struct db_plan_t *plan, struct db_full_path *entry, struct db_i *dbip,
struct rt_wdb *wdbp, struct db_full_path_list *results)
+f_above(struct db_plan_t *plan, struct db_node_t *entry, struct db_i *dbip,
struct rt_wdb *wdbp, struct db_full_path_list *results)
{
int state = 0;
+ struct db_node_t curr_node;
struct db_full_path abovepath;
db_full_path_init(&abovepath);
- db_dup_full_path(&abovepath, entry);
+ db_dup_full_path(&abovepath, entry->entry);
DB_FULL_PATH_POP(&abovepath);
+ curr_node.entry = &abovepath;
while ((abovepath.fp_len > 0) && (state == 0)) {
- state = find_execute_nested_plans(dbip, wdbp, results, &abovepath,
plan->ab_data[0]);
+ state = find_execute_nested_plans(dbip, wdbp, results, &curr_node,
plan->ab_data[0]);
DB_FULL_PATH_POP(&abovepath);
}
db_free_full_path(&abovepath);
@@ -404,15 +422,15 @@
*/
HIDDEN int
db_fullpath_stateful_traverse_subtree(union tree *tp,
- int (*traverse_func) (struct db_i *,
struct rt_wdb *, struct db_full_path_list *results, struct db_full_path *,
- int (*) (struct
db_i *, struct rt_wdb *, struct db_full_path_list *, struct db_full_path *,
genptr_t),
- int (*) (struct
db_i *, struct rt_wdb *, struct db_full_path_list *, struct db_full_path *,
genptr_t),
+ int (*traverse_func) (struct db_i *,
struct rt_wdb *, struct db_full_path_list *results, struct db_node_t *,
+ int (*) (struct
db_i *, struct rt_wdb *, struct db_full_path_list *, struct db_node_t *,
genptr_t),
+ int (*) (struct
db_i *, struct rt_wdb *, struct db_full_path_list *, struct db_node_t *,
genptr_t),
struct resource *,
genptr_t),
struct db_i *dbip, struct rt_wdb *wdbp,
struct db_full_path_list *results,
- struct db_full_path *dfp,
- int (*comb_func) (struct db_i *, struct
rt_wdb *, struct db_full_path_list *, struct db_full_path *, genptr_t),
- int (*leaf_func) (struct db_i *, struct
rt_wdb *, struct db_full_path_list *, struct db_full_path *, genptr_t),
+ struct db_node_t *dfp,
+ int (*comb_func) (struct db_i *, struct
rt_wdb *, struct db_full_path_list *, struct db_node_t *, genptr_t),
+ int (*leaf_func) (struct db_i *, struct
rt_wdb *, struct db_full_path_list *, struct db_node_t *, genptr_t),
struct resource *resp,
genptr_t client_data)
{
@@ -421,7 +439,7 @@
if (!tp)
return 0;
- RT_CK_FULL_PATH(dfp);
+ RT_CK_FULL_PATH(dfp->entry);
RT_CHECK_DBI(dbip);
RT_CK_TREE(tp);
RT_CK_RESOURCE(resp);
@@ -432,9 +450,9 @@
if ((dp=db_lookup(dbip, tp->tr_l.tl_name, LOOKUP_QUIET)) ==
RT_DIR_NULL) {
return 0;
} else {
- db_add_node_to_full_path(dfp, dp);
+ db_add_node_to_full_path(dfp->entry, dp);
state = traverse_func(dbip, wdbp, results, dfp, comb_func,
leaf_func, resp, client_data);
- DB_FULL_PATH_POP(dfp);
+ DB_FULL_PATH_POP(dfp->entry);
if (state == 1) {
return 1;
} else {
@@ -443,8 +461,44 @@
}
break;
case OP_UNION:
+ dfp->bool_type = 2;
+ state = db_fullpath_stateful_traverse_subtree(tp->tr_b.tb_left,
traverse_func, dbip, wdbp, results, dfp, comb_func, leaf_func, resp,
client_data);
+ if (state == 1) return 1;
+ dfp->bool_type = 2;
+ state = db_fullpath_stateful_traverse_subtree(tp->tr_b.tb_right,
traverse_func, dbip, wdbp, results, dfp, comb_func, leaf_func, resp,
client_data);
+ if (state == 1) {
+ return 1;
+ } else {
+ return 0;
+ }
+ break;
+
case OP_INTERSECT:
+ dfp->bool_type = 2;
+ state = db_fullpath_stateful_traverse_subtree(tp->tr_b.tb_left,
traverse_func, dbip, wdbp, results, dfp, comb_func, leaf_func, resp,
client_data);
+ if (state == 1) return 1;
+ dfp->bool_type = 3;
+ state = db_fullpath_stateful_traverse_subtree(tp->tr_b.tb_right,
traverse_func, dbip, wdbp, results, dfp, comb_func, leaf_func, resp,
client_data);
+ if (state == 1) {
+ return 1;
+ } else {
+ return 0;
+ }
+ break;
+
case OP_SUBTRACT:
+ dfp->bool_type = 2;
+ state = db_fullpath_stateful_traverse_subtree(tp->tr_b.tb_left,
traverse_func, dbip, wdbp, results, dfp, comb_func, leaf_func, resp,
client_data);
+ if (state == 1) return 1;
+ dfp->bool_type = 4;
+ state = db_fullpath_stateful_traverse_subtree(tp->tr_b.tb_right,
traverse_func, dbip, wdbp, results, dfp, comb_func, leaf_func, resp,
client_data);
+ if (state == 1) {
+ return 1;
+ } else {
+ return 0;
+ }
+ break;
+
case OP_XOR:
state = db_fullpath_stateful_traverse_subtree(tp->tr_b.tb_left,
traverse_func, dbip, wdbp, results, dfp, comb_func, leaf_func, resp,
client_data);
if (state == 1) return 1;
@@ -480,19 +534,19 @@
*/
HIDDEN int
db_fullpath_stateful_traverse(struct db_i *dbip, struct rt_wdb *wdbp, struct
db_full_path_list *results,
- struct db_full_path *dfp,
- int (*comb_func) (struct db_i *, struct rt_wdb *,
struct db_full_path_list *, struct db_full_path *, genptr_t),
- int (*leaf_func) (struct db_i *, struct rt_wdb *,
struct db_full_path_list *, struct db_full_path *, genptr_t),
+ struct db_node_t *dfp,
+ int (*comb_func) (struct db_i *, struct rt_wdb *,
struct db_full_path_list *, struct db_node_t *, genptr_t),
+ int (*leaf_func) (struct db_i *, struct rt_wdb *,
struct db_full_path_list *, struct db_node_t *, genptr_t),
struct resource *resp,
genptr_t client_data)
{
struct directory *dp;
size_t i;
int state = 0;
- RT_CK_FULL_PATH(dfp);
+ RT_CK_FULL_PATH(dfp->entry);
RT_CK_DBI(dbip);
- dp = DB_FULL_PATH_CUR_DIR(dfp);
+ dp = DB_FULL_PATH_CUR_DIR(dfp->entry);
if (!dp)
return 0;
@@ -515,9 +569,9 @@
LOOKUP_QUIET)) == RT_DIR_NULL) {
continue;
} else {
- db_add_node_to_full_path(dfp, mdp);
+ db_add_node_to_full_path(dfp->entry, mdp);
state = db_fullpath_stateful_traverse(dbip, wdbp, results,
dfp, comb_func, leaf_func, resp, client_data);
- DB_FULL_PATH_POP(dfp);
+ DB_FULL_PATH_POP(dfp->entry);
if (state == 1) {
return 1;
} else {
@@ -567,8 +621,9 @@
* below the current object in the tree.
*/
HIDDEN int
-f_below(struct db_plan_t *plan, struct db_full_path *entry, struct db_i *dbip,
struct rt_wdb *wdbp, struct db_full_path_list *results)
+f_below(struct db_plan_t *plan, struct db_node_t *entry, struct db_i *dbip,
struct rt_wdb *wdbp, struct db_full_path_list *results)
{
+ struct db_node_t curr_node;
struct db_full_path belowpath;
struct rt_db_internal in;
struct rt_comb_internal *comb;
@@ -576,9 +631,9 @@
int state = 0;
db_full_path_init(&belowpath);
- db_dup_full_path(&belowpath, entry);
+ db_dup_full_path(&belowpath, entry->entry);
- dp = DB_FULL_PATH_CUR_DIR(entry);
+ dp = DB_FULL_PATH_CUR_DIR(entry->entry);
if (!dp)
return 0;
@@ -587,9 +642,10 @@
return 0;
comb = (struct rt_comb_internal *)in.idb_ptr;
+
+ curr_node.entry = &belowpath;
+ state = db_fullpath_stateful_traverse_subtree(comb->tree,
db_fullpath_stateful_traverse, dbip, wdbp, results, &curr_node,
find_execute_nested_plans, find_execute_nested_plans, wdbp->wdb_resp,
plan->bl_data[0]);
- state = db_fullpath_stateful_traverse_subtree(comb->tree,
db_fullpath_stateful_traverse, dbip, wdbp, results, &belowpath,
find_execute_nested_plans, find_execute_nested_plans, wdbp->wdb_resp,
plan->bl_data[0]);
-
rt_db_free_internal(&in);
}
db_free_full_path(&belowpath);
@@ -617,7 +673,7 @@
* not evaluated if the first expression is true.
*/
HIDDEN int
-f_or(struct db_plan_t *plan, struct db_full_path *entry, struct db_i *dbip,
struct rt_wdb *wdbp, struct db_full_path_list *results)
+f_or(struct db_plan_t *plan, struct db_node_t *entry, struct db_i *dbip,
struct rt_wdb *wdbp, struct db_full_path_list *results)
{
struct db_plan_t *p = NULL;
int state = 0;
@@ -650,10 +706,10 @@
* matches pattern using Pattern Matching Notation S3.14
*/
HIDDEN int
-f_name(struct db_plan_t *plan, struct db_full_path *entry, struct db_i
*UNUSED(dbip), struct rt_wdb *UNUSED(wdbp), struct db_full_path_list
*UNUSED(results))
+f_name(struct db_plan_t *plan, struct db_node_t *entry, struct db_i
*UNUSED(dbip), struct rt_wdb *UNUSED(wdbp), struct db_full_path_list
*UNUSED(results))
{
struct directory *dp;
- dp = DB_FULL_PATH_CUR_DIR(entry);
+ dp = DB_FULL_PATH_CUR_DIR(entry->entry);
if (!dp)
return 0;
return !bu_fnmatch(plan->c_data, dp->d_namep, 0);
@@ -679,10 +735,10 @@
* matches pattern using case insensitive Pattern Matching Notation S3.14
*/
HIDDEN int
-f_iname(struct db_plan_t *plan, struct db_full_path *entry, struct db_i
*UNUSED(dbip), struct rt_wdb *UNUSED(wdbp), struct db_full_path_list
*UNUSED(results))
+f_iname(struct db_plan_t *plan, struct db_node_t *entry, struct db_i
*UNUSED(dbip), struct rt_wdb *UNUSED(wdbp), struct db_full_path_list
*UNUSED(results))
{
struct directory *dp;
- dp = DB_FULL_PATH_CUR_DIR(entry);
+ dp = DB_FULL_PATH_CUR_DIR(entry->entry);
if (!dp)
return 0;
return !bu_fnmatch(plan->c_data, dp->d_namep, BU_FNMATCH_CASEFOLD);
@@ -709,9 +765,9 @@
* For -iregex, regexp is a case-insensitive (basic) regular expression.
*/
HIDDEN int
-f_regex(struct db_plan_t *plan, struct db_full_path *entry, struct db_i
*UNUSED(dbip), struct rt_wdb *UNUSED(wdbp), struct db_full_path_list
*UNUSED(results))
+f_regex(struct db_plan_t *plan, struct db_node_t *entry, struct db_i
*UNUSED(dbip), struct rt_wdb *UNUSED(wdbp), struct db_full_path_list
*UNUSED(results))
{
- return !(regexec(&plan->regexp_data, db_path_to_string(entry), 0, NULL,
0));
+ return !(regexec(&plan->regexp_data, db_path_to_string(entry->entry), 0,
NULL, 0));
}
@@ -761,7 +817,7 @@
* supplied to the attr option
*/
HIDDEN int
-f_attr(struct db_plan_t *plan, struct db_full_path *entry, struct db_i *dbip,
struct rt_wdb *UNUSED(wdbp), struct db_full_path_list *UNUSED(results))
+f_attr(struct db_plan_t *plan, struct db_node_t *entry, struct db_i *dbip,
struct rt_wdb *UNUSED(wdbp), struct db_full_path_list *UNUSED(results))
{
struct bu_vls attribname = BU_VLS_INIT_ZERO;
struct bu_vls value = BU_VLS_INIT_ZERO;
@@ -824,7 +880,7 @@
/* Get attributes for object.
*/
- dp = DB_FULL_PATH_CUR_DIR(entry);
+ dp = DB_FULL_PATH_CUR_DIR(entry->entry);
if (!dp)
return 0;
@@ -1019,7 +1075,7 @@
* associated with an object.
*/
HIDDEN int
-f_stdattr(struct db_plan_t *UNUSED(plan), struct db_full_path *entry, struct
db_i *dbip, struct rt_wdb *UNUSED(wdbp), struct db_full_path_list
*UNUSED(results))
+f_stdattr(struct db_plan_t *UNUSED(plan), struct db_node_t *entry, struct db_i
*dbip, struct rt_wdb *UNUSED(wdbp), struct db_full_path_list *UNUSED(results))
{
struct bu_attribute_value_pair *avpp;
struct bu_attribute_value_set avs;
@@ -1034,7 +1090,7 @@
* return failure, otherwise success.
*/
- dp = DB_FULL_PATH_CUR_DIR(entry);
+ dp = DB_FULL_PATH_CUR_DIR(entry->entry);
if (!dp)
return 0;
@@ -1088,14 +1144,14 @@
* region.
*/
HIDDEN int
-f_type(struct db_plan_t *plan, struct db_full_path *entry, struct db_i *dbip,
struct rt_wdb *wdbp, struct db_full_path_list *UNUSED(results))
+f_type(struct db_plan_t *plan, struct db_node_t *entry, struct db_i *dbip,
struct rt_wdb *wdbp, struct db_full_path_list *UNUSED(results))
{
struct rt_db_internal intern;
struct directory *dp;
int type_match = 0;
int type;
- dp = DB_FULL_PATH_CUR_DIR(entry);
+ dp = DB_FULL_PATH_CUR_DIR(entry->entry);
if (!dp)
return 0;
@@ -1254,7 +1310,37 @@
return BRLCAD_OK;
}
+/*
+ * -bool function --
+ *
+ * True if the boolean operation combining the object into the tree matches
+ * the supplied boolean flag.
+ *
+ */
+HIDDEN int
+f_bool(struct db_plan_t *plan, struct db_node_t *entry, struct db_i
*UNUSED(dbip), struct rt_wdb *UNUSED(wdbp), struct db_full_path_list
*UNUSED(results))
+{
+ int bool_match = 0;
+ if (plan->bool_data == entry->bool_type) bool_match = 1;
+ return bool_match;
+}
+HIDDEN int
+c_bool(char *pattern, char ***UNUSED(ignored), int UNUSED(unused), struct
db_plan_t **resultplan, int *UNUSED(db_search_isoutput))
+{
+ int bool_type = 0;
+ struct db_plan_t *newplan;
+ newplan = palloc(N_BOOL, f_bool);
+
+ if (!bu_fnmatch(pattern, "u", 0) || !bu_fnmatch(pattern, "U", 0))
bool_type = 2;
+ if (!bu_fnmatch(pattern, "+", 0)) bool_type = 3;
+ if (!bu_fnmatch(pattern, "-", 0)) bool_type = 4;
+
+ newplan->bool_data = bool_type;
+ (*resultplan) = newplan;
+ return BRLCAD_OK;
+}
+
/*
* -maxdepth function --
*
@@ -1263,12 +1349,12 @@
*
*/
HIDDEN int
-f_maxdepth(struct db_plan_t *plan, struct db_full_path *entry, struct db_i
*UNUSED(dbip), struct rt_wdb *UNUSED(wdbp), struct db_full_path_list
*UNUSED(results))
+f_maxdepth(struct db_plan_t *plan, struct db_node_t *entry, struct db_i
*UNUSED(dbip), struct rt_wdb *UNUSED(wdbp), struct db_full_path_list
*UNUSED(results))
{
struct db_full_path depthtest;
int depthcount = -1;
db_full_path_init(&depthtest);
- db_dup_full_path(&depthtest, entry);
+ db_dup_full_path(&depthtest, entry->entry);
while (depthtest.fp_len > 0) {
depthcount++;
DB_FULL_PATH_POP(&depthtest);
@@ -1298,12 +1384,12 @@
*
*/
HIDDEN int
-f_mindepth(struct db_plan_t *plan, struct db_full_path *entry, struct db_i
*UNUSED(dbip), struct rt_wdb *UNUSED(wdbp), struct db_full_path_list
*UNUSED(results))
+f_mindepth(struct db_plan_t *plan, struct db_node_t *entry, struct db_i
*UNUSED(dbip), struct rt_wdb *UNUSED(wdbp), struct db_full_path_list
*UNUSED(results))
{
struct db_full_path depthtest;
int depthcount = -1;
db_full_path_init(&depthtest);
- db_dup_full_path(&depthtest, entry);
+ db_dup_full_path(&depthtest, entry->entry);
while (depthtest.fp_len > 0) {
depthcount++;
DB_FULL_PATH_POP(&depthtest);
@@ -1336,7 +1422,7 @@
*
*/
HIDDEN int
-f_nnodes(struct db_plan_t *plan, struct db_full_path *entry, struct db_i
*dbip, struct rt_wdb *UNUSED(wdbp), struct db_full_path_list *UNUSED(results))
+f_nnodes(struct db_plan_t *plan, struct db_node_t *entry, struct db_i *dbip,
struct rt_wdb *UNUSED(wdbp), struct db_full_path_list *UNUSED(results))
{
int dogreaterthan = 0;
int dolessthan = 0;
@@ -1383,7 +1469,7 @@
* argument string.
*/
- dp = DB_FULL_PATH_CUR_DIR(entry);
+ dp = DB_FULL_PATH_CUR_DIR(entry->entry);
if (!dp)
return 0;
@@ -1439,9 +1525,9 @@
* with this option.
*/
HIDDEN int
-f_path(struct db_plan_t *plan, struct db_full_path *entry, struct db_i
*UNUSED(dbip), struct rt_wdb *UNUSED(wdbp), struct db_full_path_list
*UNUSED(results))
+f_path(struct db_plan_t *plan, struct db_node_t *entry, struct db_i
*UNUSED(dbip), struct rt_wdb *UNUSED(wdbp), struct db_full_path_list
*UNUSED(results))
{
- return !bu_fnmatch(plan->path_data, db_path_to_string(entry), 0);
+ return !bu_fnmatch(plan->path_data, db_path_to_string(entry->entry), 0);
}
@@ -1464,7 +1550,7 @@
* list.
*/
HIDDEN int
-f_print(struct db_plan_t *UNUSED(plan), struct db_full_path *entry, struct
db_i *UNUSED(dbip), struct rt_wdb *UNUSED(wdbp), struct db_full_path_list
*results)
+f_print(struct db_plan_t *UNUSED(plan), struct db_node_t *entry, struct db_i
*UNUSED(dbip), struct rt_wdb *UNUSED(wdbp), struct db_full_path_list *results)
{
struct db_full_path_list *new_entry;
@@ -1472,7 +1558,7 @@
BU_ALLOC(new_entry->path, struct db_full_path);
db_full_path_init(new_entry->path);
- db_dup_full_path(new_entry->path, (const struct db_full_path *)entry);
+ db_dup_full_path(new_entry->path, (const struct db_full_path
*)(entry->entry));
BU_LIST_PUSH(&(results->l), &(new_entry->l));
return 1;
}
@@ -1582,7 +1668,7 @@
struct db_plan_t *node; /* pointer to returned node or
expression */
struct db_plan_t *tail; /* pointer to tail of subplan */
struct db_plan_t *subplan; /* pointer to head of () expression */
- extern int f_expr(struct db_plan_t *, struct db_full_path *, struct db_i
*, struct rt_wdb *, struct db_full_path_list *);
+ extern int f_expr(struct db_plan_t *, struct db_node_t *, struct db_i *,
struct rt_wdb *, struct db_full_path_list *);
int error_return = BRLCAD_OK;
/* first pull the top node from the plan */
@@ -2010,7 +2096,7 @@
HIDDEN void
-find_execute_plans(struct db_i *dbip, struct rt_wdb *wdbp, struct
db_full_path_list *results, struct db_full_path *dfp, genptr_t inputplan) {
+find_execute_plans(struct db_i *dbip, struct rt_wdb *wdbp, struct
db_full_path_list *results, struct db_node_t *dfp, genptr_t inputplan) {
struct db_plan_t *p;
struct db_plan_t *plan = (struct db_plan_t *)inputplan;
for (p = plan; p && (p->eval)(p, dfp, dbip, wdbp, results); p = p->next)
@@ -2068,7 +2154,9 @@
db_free_full_path(&dfp);
}
for (BU_LIST_FOR(currentpath, db_full_path_list, &(pathnames->l))) {
- db_fullpath_traverse(dbip, wdbp, searchresults, currentpath->path,
find_execute_plans, find_execute_plans, wdbp->wdb_resp, (struct db_plan_t
*)searchplan);
+ struct db_node_t curr_node;
+ curr_node.entry = currentpath->path;
+ db_fullpath_traverse(dbip, wdbp, searchresults, &curr_node,
find_execute_plans, find_execute_plans, wdbp->wdb_resp, (struct db_plan_t
*)searchplan);
}
return searchresults;
}
Modified: brlcad/trunk/src/librt/search.h
===================================================================
--- brlcad/trunk/src/librt/search.h 2013-07-30 20:21:32 UTC (rev 56359)
+++ brlcad/trunk/src/librt/search.h 2013-07-30 20:44:01 UTC (rev 56360)
@@ -55,6 +55,12 @@
#include "regex.h"
#include "raytrace.h"
+/* node struct - holds data specific to each node under consideration */
+struct db_node_t {
+ struct db_full_path *entry;
+ int bool_type;
+};
+
/* search node type */
enum db_search_ntype {
N_ABOVE = 1, /* must start > 0 */
@@ -62,13 +68,13 @@
N_CLOSEPAREN, N_DEPTH, N_EXEC, N_EXECDIR, N_EXPR,
N_FLAGS, N_INAME, N_IREGEX, N_LS, N_MAXDEPTH,
N_MINDEPTH, N_NAME, N_NNODES, N_NOT, N_OK, N_OPENPAREN, N_OR, N_PATH,
- N_PRINT, N_PRUNE, N_REGEX, N_STDATTR, N_TYPE
+ N_PRINT, N_PRUNE, N_REGEX, N_STDATTR, N_TYPE, N_BOOL
};
struct db_plan_t {
struct db_plan_t *next; /* next node */
- int (*eval)(struct db_plan_t *, struct db_full_path *, struct db_i *dbip,
struct rt_wdb *wdbp, struct db_full_path_list *results);
+ int (*eval)(struct db_plan_t *, struct db_node_t *, struct db_i *dbip,
struct rt_wdb *wdbp, struct db_full_path_list *results);
/* node evaluation function */
#define F_EQUAL 1 /* [acm]time inum links size */
#define F_LESSTHAN 2
@@ -101,6 +107,7 @@
char *_node_data; /* char pointer */
char *_type_data;
regex_t _regex_data; /* compiled regexp */
+ int _bool_data;
int _max_data; /* tree depth */
int _min_data; /* tree depth */
} p_un;
@@ -123,6 +130,7 @@
#define ab_data p_un._ab_data
#define bl_data p_un._bl_data
#define type_data p_un._type_data
+#define bool_data p_un._bool_data
#define e_argv p_un.ex._e_argv
#define e_orig p_un.ex._e_orig
#define e_len p_un.ex._e_len
@@ -153,6 +161,7 @@
static int c_print(char *, char ***, int, struct db_plan_t **, int *);
static int c_stdattr(char *, char ***, int, struct db_plan_t **, int *);
static int c_type(char *, char ***, int, struct db_plan_t **, int *);
+static int c_bool(char *, char ***, int, struct db_plan_t **, int *);
static int c_openparen(char *, char ***, int, struct db_plan_t **, int *);
static int c_closeparen(char *, char ***, int, struct db_plan_t **, int *);
static int c_not(char *, char ***, int, struct db_plan_t **, int *);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent
caught up. So what steps can you take to put your SQL databases under
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits