int ged_wcodes(struct ged *gedp, int argc, const char *argv[]) { int i; int status; FILE *fp; struct directory *dp; static const char *usage = "filename object(s)"; 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; } if (argc == 2) { bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); return GED_ERROR; } if ((fp = fopen(argv[1], "w")) == NULL) { bu_vls_printf(gedp->ged_result_str, "%s: Failed to open file - %s", argv[0], argv[1]); return GED_ERROR; } path = (struct directory **)bu_calloc(PATH_STEP, sizeof(struct directory *), "alloc initial path"); path_capacity = PATH_STEP; for (i = 2; i < argc; ++i) { if ((dp = db_lookup(gedp->ged_wdbp->dbip, argv[i], LOOKUP_NOISY)) != RT_DIR_NULL) { status = wcodes_printcodes(gedp, fp, dp, 0); if (status == GED_ERROR) { (void)fclose(fp); return GED_ERROR; } } } (void)fclose(fp); bu_free(path, "dealloc path"); path = NULL; path_capacity = 0; return GED_OK; }
HIDDEN void wcodes_printnode(struct db_i *dbip, struct rt_comb_internal *UNUSED(comb), union tree *comb_leaf, void *user_ptr1, void *user_ptr2, void *user_ptr3, void *UNUSED(user_ptr4)) { FILE *fp; size_t *pathpos; struct directory *nextdp; struct ged *gedp; RT_CK_DBI(dbip); RT_CK_TREE(comb_leaf); if ((nextdp=db_lookup(dbip, comb_leaf->tr_l.tl_name, LOOKUP_NOISY)) == RT_DIR_NULL) return; fp = (FILE *)user_ptr1; pathpos = (size_t *)user_ptr2; gedp = (struct ged *)user_ptr3; /* recurse on combinations */ if (nextdp->d_flags & RT_DIR_COMB) (void)wcodes_printcodes(gedp, fp, nextdp, (*pathpos)+1); }