void count_refs(struct db_i *dbip, struct directory *dp, void *UNUSED(ptr)) { struct rt_db_internal intern; struct rt_comb_internal *comb; int id; if (!(dp->d_flags & RT_DIR_COMB)) return; id = rt_db_get_internal(&intern, dp, dbip, (matp_t)NULL, &rt_uniresource); if (id < 0) { bu_log("Cannot get internal form of %s\n", dp->d_namep); return; } comb = (struct rt_comb_internal *)intern.idb_ptr; RT_CK_COMB(comb); if (!comb->tree) { bu_log("Warning: empty combination (%s)\n", dp->d_namep); dp->d_uses = 0; return; } comb_form = 0; db_tree_funcleaf(dbip, comb, comb->tree, incr_refs, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL); }
HIDDEN int printcodes(FILE *fp, struct directory *dp, int pathpos) { int i; struct rt_db_internal intern; struct rt_comb_internal *comb; int id; CHECK_DBI_NULL; if (pathpos >= MAX_LEVELS) { regflag = ABORTED; return TCL_ERROR; } if (!(dp->d_flags & RT_DIR_COMB)) return 0; if ((id=rt_db_get_internal(&intern, dp, dbip, (matp_t)NULL, &rt_uniresource)) < 0) { Tcl_AppendResult(INTERP, "printcodes: Cannot get records for ", dp->d_namep, "\n", (char *)NULL); return TCL_ERROR; } if (id != ID_COMBINATION) return TCL_OK; comb = (struct rt_comb_internal *)intern.idb_ptr; RT_CK_COMB(comb); if (comb->region_flag) { fprintf(fp, "%-6ld %-3ld %-3ld %-4ld ", comb->region_id, comb->aircode, comb->GIFTmater, comb->los); for (i=0; i < pathpos; i++) fprintf(fp, "/%s", path[i]->d_namep); fprintf(fp, "/%s\n", dp->d_namep); intern.idb_meth->ft_ifree(&intern); return TCL_OK; } if (comb->tree) { path[pathpos] = dp; db_tree_funcleaf(dbip, comb, comb->tree, Do_printnode, (void *)fp, (void *)&pathpos, (void *)NULL, (void *)NULL); } intern.idb_meth->ft_ifree(&intern); return TCL_OK; }
HIDDEN int wcodes_printcodes(struct ged *gedp, FILE *fp, struct directory *dp, size_t pathpos) { size_t i; struct rt_db_internal intern; struct rt_comb_internal *comb; int id; if (!(dp->d_flags & RT_DIR_COMB)) return GED_OK; if ((id=rt_db_get_internal(&intern, dp, gedp->ged_wdbp->dbip, (matp_t)NULL, &rt_uniresource)) < 0) { bu_vls_printf(gedp->ged_result_str, "Cannot get records for %s\n", dp->d_namep); return GED_ERROR; } if (id != ID_COMBINATION) { intern.idb_meth->ft_ifree(&intern); return GED_OK; } comb = (struct rt_comb_internal *)intern.idb_ptr; RT_CK_COMB(comb); if (comb->region_flag) { fprintf(fp, "%-6ld %-3ld %-3ld %-4ld ", comb->region_id, comb->aircode, comb->GIFTmater, comb->los); for (i =0 ; i < pathpos; i++) fprintf(fp, "/%s", path[i]->d_namep); fprintf(fp, "/%s\n", dp->d_namep); intern.idb_meth->ft_ifree(&intern); return GED_OK; } if (comb->tree) { if (pathpos >= path_capacity) { path_capacity += PATH_STEP; path = (struct directory **)bu_realloc(path, sizeof(struct directory *) * path_capacity, "realloc path bigger"); } path[pathpos] = dp; db_tree_funcleaf(gedp->ged_wdbp->dbip, comb, comb->tree, wcodes_printnode, (void *)fp, (void *)&pathpos, (void *)gedp, (void *)gedp); } intern.idb_meth->ft_ifree(&intern); return GED_OK; }
HIDDEN int edcodes_collect_regnames(struct ged *gedp, struct directory *dp, int pathpos) { int id; int status = 0; struct rt_db_internal intern; struct rt_comb_internal *comb; if (!(dp->d_flags & RT_DIR_COMB)) return EDCODES_OK; if ((id=rt_db_get_internal(&intern, dp, gedp->ged_wdbp->dbip, (matp_t)NULL, &rt_uniresource)) < 0) { bu_vls_printf(gedp->ged_result_str, "Cannot get records for %s\n", dp->d_namep); return EDCODES_NOTOK; } if (id != ID_COMBINATION) { intern.idb_meth->ft_ifree(&intern); return EDCODES_OK; } comb = (struct rt_comb_internal *)intern.idb_ptr; RT_CK_COMB(comb); if (comb->region_flag) { bu_vls_printf(gedp->ged_result_str, " %s", dp->d_namep); intern.idb_meth->ft_ifree(&intern); return EDCODES_OK; } if (comb->tree) { db_tree_funcleaf(gedp->ged_wdbp->dbip, comb, comb->tree, edcodes_traverse_node, (void *)&pathpos, (void *)gedp, (void *)&status, (void *)NULL); } intern.idb_meth->ft_ifree(&intern); if (status == EDCODES_HALT) return EDCODES_HALT; return EDCODES_OK; }
void db_update_nref( struct db_i *dbip, struct resource *resp ) { register int i; register struct directory *dp; struct rt_db_internal intern; struct rt_comb_internal *comb; RT_CK_DBI( dbip ); RT_CK_RESOURCE(resp); /* First, clear any existing counts */ for ( i = 0; i < RT_DBNHASH; i++ ) for ( dp = dbip->dbi_Head[i]; dp != DIR_NULL; dp = dp->d_forw ) dp->d_nref = 0; /* Examine all COMB nodes */ for ( i = 0; i < RT_DBNHASH; i++ ) { for ( dp = dbip->dbi_Head[i]; dp != DIR_NULL; dp = dp->d_forw ) { /* handle non-combination objects that reference other objects */ if ( dp->d_major_type == DB5_MAJORTYPE_BRLCAD ) { struct directory *dp2; if ( dp->d_minor_type == DB5_MINORTYPE_BRLCAD_EXTRUDE ) { struct rt_extrude_internal *extr; if ( rt_db_get_internal(&intern, dp, dbip, (fastf_t *)NULL, resp) < 0 ) continue; extr = (struct rt_extrude_internal *)intern.idb_ptr; RT_EXTRUDE_CK_MAGIC( extr ); if ( extr->sketch_name ) { dp2 = db_lookup( dbip, extr->sketch_name, LOOKUP_QUIET ); if ( dp2 != DIR_NULL ) { dp2->d_nref++; } } rt_db_free_internal( &intern, resp ); } else if ( dp->d_minor_type == DB5_MINORTYPE_BRLCAD_DSP ) { struct rt_dsp_internal *dsp; if ( rt_db_get_internal(&intern, dp, dbip, (fastf_t *)NULL, resp) < 0 ) continue; dsp = (struct rt_dsp_internal *)intern.idb_ptr; RT_DSP_CK_MAGIC( dsp ); if ( dsp->dsp_datasrc == RT_DSP_SRC_OBJ && bu_vls_strlen( &dsp->dsp_name) > 0 ) { dp2 = db_lookup( dbip, bu_vls_addr( &dsp->dsp_name ), LOOKUP_QUIET ); if ( dp2 != DIR_NULL ) { dp2->d_nref++; } } rt_db_free_internal( &intern, resp ); } } if ( !(dp->d_flags & DIR_COMB) ) continue; if ( rt_db_get_internal(&intern, dp, dbip, (fastf_t *)NULL, resp) < 0 ) continue; if ( intern.idb_type != ID_COMBINATION ) { bu_log("NOTICE: %s was marked a combination, but isn't one? Clearing flag\n", dp->d_namep); dp->d_flags &= ~DIR_COMB; rt_db_free_internal( &intern, resp ); continue; } comb = (struct rt_comb_internal *)intern.idb_ptr; db_tree_funcleaf( dbip, comb, comb->tree, db_count_refs, (genptr_t)NULL, (genptr_t)NULL, (genptr_t)NULL ); rt_db_free_internal( &intern, resp ); } } }
int ged_find(struct ged *gedp, int argc, const char *argv[]) { int i, k; struct directory *dp; struct rt_db_internal intern; struct rt_comb_internal *comb=(struct rt_comb_internal *)NULL; int c; int aflag = 0; /* look at all objects */ static const char *usage = "<objects>"; GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR); GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR); /* initialize result */ bu_vls_trunc(gedp->ged_result_str, 0); /* must be wanting help */ if (argc == 1) { bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); return GED_HELP; } bu_optind = 1; /* re-init bu_getopt() */ while ((c = bu_getopt(argc, (char * const *)argv, "a")) != -1) { switch (c) { case 'a': aflag = 1; break; default: bu_vls_printf(gedp->ged_result_str, "Unrecognized option - %c", c); return GED_ERROR; } } argc -= (bu_optind - 1); argv += (bu_optind - 1); /* Examine all COMB nodes */ for (i = 0; i < RT_DBNHASH; i++) { for (dp = gedp->ged_wdbp->dbip->dbi_Head[i]; dp != RT_DIR_NULL; dp = dp->d_forw) { if (!(dp->d_flags & RT_DIR_COMB) || (!aflag && (dp->d_flags & RT_DIR_HIDDEN))) continue; if (rt_db_get_internal(&intern, dp, gedp->ged_wdbp->dbip, (fastf_t *)NULL, &rt_uniresource) < 0) { bu_vls_printf(gedp->ged_result_str, "Database read error, aborting"); return GED_ERROR; } comb = (struct rt_comb_internal *)intern.idb_ptr; for (k = 1; k < argc; k++) db_tree_funcleaf(gedp->ged_wdbp->dbip, comb, comb->tree, find_ref, (void *)argv[k], (void *)dp->d_namep, (void *)gedp, (void *)NULL); rt_db_free_internal(&intern); } } return GED_OK; }