[brlcad-commits] SF.net SVN: brlcad:[32573] brlcad/trunk
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <sta...@us...> - 2008-09-04 20:57:19
|
Revision: 32573 http://brlcad.svn.sourceforge.net/brlcad/?rev=32573&view=rev Author: starseeker Date: 2008-09-04 20:57:29 +0000 (Thu, 04 Sep 2008) Log Message: ----------- Now able to print the full path string for a returned match. Requires db_fullpath_traverse tree walker, so adding that in this commit as well. Modified Paths: -------------- brlcad/trunk/include/raytrace.h brlcad/trunk/src/libged/nfind.c brlcad/trunk/src/libged/nfind.h brlcad/trunk/src/librt/db_walk.c Modified: brlcad/trunk/include/raytrace.h =================================================================== --- brlcad/trunk/include/raytrace.h 2008-09-04 19:33:25 UTC (rev 32572) +++ brlcad/trunk/include/raytrace.h 2008-09-04 20:57:29 UTC (rev 32573) @@ -3251,6 +3251,18 @@ struct resource *resp, genptr_t client_data)); +RT_EXPORT BU_EXTERN(void db_fullpath_traverse, + (struct db_i *dbip, + struct db_full_path *dfp, + void (*comb_func)(struct db_i *, + struct db_full_path *, + genptr_t), + void (*leaf_func)(struct db_i *, + struct db_full_path *, + genptr_t), + struct resource *resp, + genptr_t client_data)); + /* mirror.c */ RT_EXPORT BU_EXTERN(struct directory *rt_mirror, (struct db_i *dpip, Modified: brlcad/trunk/src/libged/nfind.c =================================================================== --- brlcad/trunk/src/libged/nfind.c 2008-09-04 19:33:25 UTC (rev 32572) +++ brlcad/trunk/src/libged/nfind.c 2008-09-04 20:57:29 UTC (rev 32573) @@ -77,7 +77,7 @@ }; static PLAN * -palloc(enum ntype t, int (*f)(PLAN *, struct directory *)) +palloc(enum ntype t, int (*f)(PLAN *, struct db_full_path *)) { PLAN *new; @@ -96,7 +96,7 @@ * True if expression is true. */ int -f_expr(PLAN *plan, struct directory *entry) +f_expr(PLAN *plan, struct db_full_path *entry) { PLAN *p; int state; @@ -115,13 +115,13 @@ PLAN * c_openparen(char *ignore, char ***ignored, int unused) { - return (palloc(N_OPENPAREN, (int (*)(PLAN *, struct directory *))-1)); + return (palloc(N_OPENPAREN, (int (*)(PLAN *, struct db_full_path *))-1)); } PLAN * c_closeparen(char *ignore, char ***ignored, int unused) { - return (palloc(N_CLOSEPAREN, (int (*)(PLAN *, struct directory *))-1)); + return (palloc(N_CLOSEPAREN, (int (*)(PLAN *, struct db_full_path *))-1)); } @@ -131,7 +131,7 @@ * Negation of a primary; the unary NOT operator. */ int -f_not(PLAN *plan, struct directory *entry) +f_not(PLAN *plan, struct db_full_path *entry) { PLAN *p; int state; @@ -154,7 +154,7 @@ * not evaluated if the first expression is true. */ int -f_or(PLAN *plan, struct directory *entry) +f_or(PLAN *plan, struct db_full_path *entry) { PLAN *p; int state; @@ -184,9 +184,9 @@ * matches pattern using Pattern Matching Notation S3.14 */ int -f_name(PLAN *plan, struct directory *entry) +f_name(PLAN *plan, struct db_full_path *entry) { - return (!fnmatch(plan->c_data, entry->d_namep, 0)); + return (!fnmatch(plan->c_data, DB_FULL_PATH_CUR_DIR(entry)->d_namep, 0)); } PLAN * @@ -207,18 +207,18 @@ * standard output. */ int -f_print(PLAN *plan, struct directory *entry) +f_print(PLAN *plan, struct db_full_path *entry) { - bu_log("%s\n", entry->d_namep); + bu_log("%s\n", db_path_to_string(entry)); isoutput = 0; return(1); } /* ARGSUSED */ int -f_print0(PLAN *plan, struct directory *entry) +f_print0(PLAN *plan, struct db_full_path *entry) { - (void)fputs(entry->d_namep, stdout); + (void)fputs(db_path_to_string(entry), stdout); (void)fputc('\0', stdout); return(1); } @@ -333,7 +333,7 @@ PLAN *node; /* pointer to returned node or expression */ PLAN *tail; /* pointer to tail of subplan */ PLAN *subplan; /* pointer to head of ( ) expression */ - extern int f_expr(PLAN *, struct directory *); + extern int f_expr(PLAN *, struct db_full_path *); /* first pull the top node from the plan */ if ((node = yanknode(planp)) == NULL) @@ -618,85 +618,28 @@ } void -find_execute_plans(struct db_i *dbip, struct directory *dp, genptr_t inputplan) { +find_execute_plans(struct db_i *dbip, struct db_full_path *dfp, genptr_t inputplan) { PLAN *p; - PLAN *plan = (PLAN *)inputplan; - for (p = plan; p && (p->eval)(p, dp); p = p->next) - ; + PLAN *plan = (PLAN *)inputplan; + for (p = plan; p && (p->eval)(p, dfp); p = p->next) + ; } void find_execute(PLAN *plan, /* search plan */ - char *pathname, /* array of pathnames to traverse */ + struct db_full_path *pathname, /* array of pathnames to traverse */ struct rt_wdb *wdbp) { - struct directory *dp; + struct directory *dp; int i; - if (strcmp(pathname, "/") != 0) { - dp = db_lookup(wdbp->dbip, pathname, LOOKUP_NOISY); - db_functree(wdbp->dbip, dp, find_execute_plans, find_execute_plans, wdbp->wdb_resp, plan); - } else { - for (i = 0; i < RT_DBNHASH; i++) { - for (dp = wdbp->dbip->dbi_Head[i]; dp != DIR_NULL; dp = dp->d_forw) { - if (dp->d_nref == 0 && !(dp->d_flags & DIR_HIDDEN) && (dp->d_addr != RT_DIR_PHONY_ADDR)) { - db_functree(wdbp->dbip, dp, find_execute_plans, find_execute_plans, wdbp->wdb_resp, plan); - } - } - } - } + db_fullpath_traverse(wdbp->dbip, pathname, find_execute_plans, find_execute_plans, wdbp->wdb_resp, plan); } -static void -ged_find_ref(struct db_i *dbip, - struct rt_comb_internal *comb, - union tree *comb_leaf, - genptr_t object, - genptr_t comb_name_ptr, - genptr_t user_ptr3) -{ - char *obj_name; - char *comb_name; - struct ged *gedp = (struct ged *)user_ptr3; - - RT_CK_TREE(comb_leaf); - - obj_name = (char *)object; - if (strcmp(comb_leaf->tr_l.tl_name, obj_name)) - return; - - comb_name = (char *)comb_name_ptr; - - bu_vls_printf(&gedp->ged_result_str, "%s", comb_name); -} - int isoutput; int -ged_find(struct ged *gedp, int argc, char *argv[]) -{ - register int i, k; - register struct directory *dp; - struct rt_db_internal intern; - register struct rt_comb_internal *comb=(struct rt_comb_internal *)NULL; - int c; - int aflag = 0; - static const char *usage = "<objects>"; - struct ged_find_ref *gfref; - - GED_CHECK_DATABASE_OPEN(gedp, BRLCAD_ERROR); - GED_CHECK_ARGC_GT_0(gedp, argc, BRLCAD_ERROR); - bu_vls_trunc(&gedp->ged_result_str, 0); - gedp->ged_result = GED_RESULT_NULL; - - - find_execute(find_formplan(argv), "/", gedp); - - return BRLCAD_OK; -} - -int wdb_find_cmd2(struct rt_wdb *wdbp, Tcl_Interp *interp, int argc, @@ -708,13 +651,29 @@ register struct rt_comb_internal *comb=(struct rt_comb_internal *)NULL; struct bu_vls vls; int aflag = 0; /* look at all objects */ - char *defaultdir = "/"; - isoutput = 0; - if (!(argv[1][0] == '-')) { - find_execute(find_formplan(&argv[2]), argv[1], wdbp); + struct db_full_path dfp; + db_full_path_init(&dfp); + db_update_nref(wdbp->dbip, &rt_uniresource); + if (!(argv[1][0] == '-') && (strcmp(argv[1],"/") != 0)) { + db_string_to_path(&dfp, wdbp->dbip, argv[1]); + isoutput = 0; + find_execute(find_formplan(&argv[2]), &dfp, wdbp); } else { - find_execute(find_formplan(&argv[1]), defaultdir, wdbp); + for (i = 0; i < RT_DBNHASH; i++) { + for (dp = wdbp->dbip->dbi_Head[i]; dp != DIR_NULL; dp = dp->d_forw) { + if (dp->d_nref == 0 && !(dp->d_flags & DIR_HIDDEN) && (dp->d_addr != RT_DIR_PHONY_ADDR)) { + db_string_to_path(&dfp, wdbp->dbip, dp->d_namep); + isoutput = 0; + if (argv[1][0] == '-') { + find_execute(find_formplan(&argv[1]), &dfp, wdbp); + } else { + find_execute(find_formplan(&argv[2]), &dfp, wdbp); + } + } + } + } } + db_free_full_path(&dfp); return TCL_OK; } Modified: brlcad/trunk/src/libged/nfind.h =================================================================== --- brlcad/trunk/src/libged/nfind.h 2008-09-04 19:33:25 UTC (rev 32572) +++ brlcad/trunk/src/libged/nfind.h 2008-09-04 20:57:29 UTC (rev 32573) @@ -67,7 +67,7 @@ /* node definition */ typedef struct _plandata { struct _plandata *next; /* next node */ - int (*eval)(struct _plandata *, struct directory *); + int (*eval)(struct _plandata *, struct db_full_path *); /* node evaluation function */ #define F_EQUAL 1 /* [acm]time inum links size */ #define F_LESSTHAN 2 @@ -122,7 +122,7 @@ void brace_subst(char *, char **, char *, int); PLAN *find_create(char ***); -void find_execute(PLAN *, char *, struct rt_wdb *); +void find_execute(PLAN *, struct db_full_path *, struct rt_wdb *); PLAN *find_formplan(char **); PLAN *not_squish(PLAN *); OPTION *option(char *); Modified: brlcad/trunk/src/librt/db_walk.c =================================================================== --- brlcad/trunk/src/librt/db_walk.c 2008-09-04 19:33:25 UTC (rev 32572) +++ brlcad/trunk/src/librt/db_walk.c 2008-09-04 20:57:29 UTC (rev 32573) @@ -149,6 +149,141 @@ } + +/* + * D B _ F U L L P A T H _ T R A V E R S E _ S U B T R E E + * + * A generic traversal function maintaining awareness of + * the full path to a given object. + */ +void +db_fullpath_traverse_subtree(union tree *tp, + void (*traverse_func) ( struct db_i *, struct db_full_path *, + void (*) (struct db_i *, struct db_full_path *, genptr_t), + void (*) (struct db_i *, struct db_full_path *, genptr_t), + struct resource *, + genptr_t), + struct db_i *dbip, + struct db_full_path *dfp, + void (*comb_func) (struct db_i *, struct db_full_path *, genptr_t), + void (*leaf_func) (struct db_i *, struct db_full_path *, genptr_t), + struct resource *resp, + genptr_t client_data) +{ + struct directory *dp; + + if ( !tp ) + return; + + RT_CK_FULL_PATH( dfp ); + RT_CHECK_DBI( dbip ); + RT_CK_TREE( tp ); + RT_CK_RESOURCE( resp ); + + switch ( tp->tr_op ) { + + case OP_DB_LEAF: + if ( (dp=db_lookup( dbip, tp->tr_l.tl_name, LOOKUP_NOISY )) == DIR_NULL ) { + return; + } else { + db_add_node_to_full_path( dfp, dp); + traverse_func( dbip, dfp, comb_func, leaf_func, resp, client_data ); + DB_FULL_PATH_POP(dfp); + break; + } + case OP_UNION: + case OP_INTERSECT: + case OP_SUBTRACT: + case OP_XOR: + db_fullpath_traverse_subtree( tp->tr_b.tb_left, traverse_func, dbip, dfp, comb_func, leaf_func, resp, client_data ); + db_fullpath_traverse_subtree( tp->tr_b.tb_right, traverse_func, dbip, dfp, comb_func, leaf_func, resp, client_data ); + break; + default: + bu_log( "db_functree_subtree: unrecognized operator %d\n", tp->tr_op ); + bu_bomb( "db_functree_subtree: unrecognized operator\n" ); + } +} + +/* + * D B _ F U L L P A T H _ T R A V E R S E + * + * This subroutine is called for a no-frills tree-walk, + * with the provided subroutines being called when entering and + * exiting combinations and at leaf (solid) nodes. + * + * This routine is recursive, so no variables may be declared static. + * + * Unlike db_preorder_traverse, this routine and its subroutines + * use db_full_path structures instead of directory structures. + */ +void +db_fullpath_traverse( struct db_i *dbip, + struct db_full_path *dfp, + void (*comb_func) (struct db_i *, struct db_full_path *, genptr_t), + void (*leaf_func) (struct db_i *, struct db_full_path *, genptr_t), + struct resource *resp, + genptr_t client_data ) +{ + struct directory *dp; + register int i; + RT_CK_FULL_PATH(dfp); + RT_CK_DBI(dbip); + + dp = DB_FULL_PATH_CUR_DIR(dfp); + + if ( dp->d_flags & DIR_COMB ) { + /* entering region */ + if ( comb_func ) + comb_func( dbip, dfp, client_data ); + if ( dbip->dbi_version < 5 ) { + register union record *rp; + register struct directory *mdp; + /* + * Load the combination into local record buffer + * This is in external v4 format. + */ + if ( (rp = db_getmrec( dbip, dp )) == (union record *)0 ) + return; + /* recurse */ + for ( i=1; i < dp->d_len; i++ ) { + if ( (mdp = db_lookup( dbip, rp[i].M.m_instname, + LOOKUP_NOISY )) == DIR_NULL ) { + continue; + } else { + db_add_node_to_full_path(dfp, mdp); + db_fullpath_traverse(dbip, dfp, comb_func, leaf_func, resp, client_data); + DB_FULL_PATH_POP(dfp); + } + } + bu_free( (char *)rp, "db_preorder_traverse[]" ); + } else { + struct rt_db_internal in; + struct rt_comb_internal *comb; + struct directory *ndp; + + if ( rt_db_get_internal5( &in, dp, dbip, NULL, resp ) < 0 ) + return; + + comb = (struct rt_comb_internal *)in.idb_ptr; + + db_fullpath_traverse_subtree( comb->tree, db_fullpath_traverse, dbip, dfp, comb_func, leaf_func, resp, client_data ); + + rt_db_free_internal( &in, resp ); + } + } + if ( dp->d_flags & DIR_SOLID || dp->d_major_type & DB5_MAJORTYPE_BINARY_MASK ) { + /* at leaf */ + if ( leaf_func ) + leaf_func( dbip, dfp, client_data ); + } +} + + + + + + + /* D B _ F U N C T R E E _ S U B T R E E * * The only reason for this to be broken out is that This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |