int rt_db_flip_endian(struct db_i *dbip) { struct counter cnt = {0, 0}; char *v4flip; RT_CK_DBI(dbip); /* does not apply to v5 geometry database */ if (db_version(dbip) > 4) return 0; /* provide the user some means to override this automatic behavior */ v4flip = getenv("LIBRT_V4FLIP"); if (v4flip) return bu_str_true(v4flip); /* iterate over all database objects looking for signs of * corruption keeping a tally of whether flipping the record fixed * the problem. */ db_scan(dbip, db_corrupt_handler, 0, &cnt); /* it has to help more than it hurts */ if (cnt.found > 0 && (double)cnt.fixed > ((double)cnt.found / 2.0)) { if (cnt.fixed != cnt.found) bu_log("%zu of %zu objects were NOT fixed by flipping endian interpretation. Manual inspection and repair required.\n", cnt.found - cnt.fixed, cnt.found); return 1; } return 0; }
int ged_dup(struct ged *gedp, int argc, const char *argv[]) { struct db_i *newdbp = DBI_NULL; struct directory **dirp0 = (struct directory **)NULL; struct dir_check_stuff dcs; static const char *usage = "file.g prefix"; 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 > 3) { bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); return GED_ERROR; } bu_vls_trunc(&gedp->ged_wdbp->wdb_prestr, 0); if (argc == 3) (void)bu_vls_strcpy(&gedp->ged_wdbp->wdb_prestr, argv[2]); gedp->ged_wdbp->wdb_num_dups = 0; if (db_version(gedp->ged_wdbp->dbip) < 5) { if ((gedp->ged_wdbp->wdb_ncharadd = bu_vls_strlen(&gedp->ged_wdbp->wdb_prestr)) > 12) { gedp->ged_wdbp->wdb_ncharadd = 12; bu_vls_trunc(&gedp->ged_wdbp->wdb_prestr, 12); } } else { gedp->ged_wdbp->wdb_ncharadd = bu_vls_strlen(&gedp->ged_wdbp->wdb_prestr); } /* open the input file */ if ((newdbp = db_open(argv[1], DB_OPEN_READONLY)) == DBI_NULL) { perror(argv[1]); bu_vls_printf(gedp->ged_result_str, "dup: Cannot open geometry database file %s", argv[1]); return GED_ERROR; } bu_vls_printf(gedp->ged_result_str, "\n*** Comparing %s with %s for duplicate names\n", gedp->ged_wdbp->dbip->dbi_filename, argv[1]); if (gedp->ged_wdbp->wdb_ncharadd) { bu_vls_printf(gedp->ged_result_str, " For comparison, all names in %s were prefixed with: %s\n", argv[1], bu_vls_addr(&gedp->ged_wdbp->wdb_prestr)); } /* Get array to hold names of duplicates */ if ((dirp0 = _ged_getspace(gedp->ged_wdbp->dbip, 0)) == (struct directory **) 0) { bu_vls_printf(gedp->ged_result_str, "f_dup: unable to get memory\n"); db_close(newdbp); return GED_ERROR; } /* Scan new database for overlaps */ dcs.main_dbip = gedp->ged_wdbp->dbip; dcs.wdbp = gedp->ged_wdbp; dcs.dup_dirp = dirp0; if (db_version(newdbp) < 5) { if (db_scan(newdbp, dup_dir_check, 0, (void *)&dcs) < 0) { bu_vls_printf(gedp->ged_result_str, "dup: db_scan failure"); bu_free((void *)dirp0, "_ged_getspace array"); db_close(newdbp); return GED_ERROR; } } else { if (db5_scan(newdbp, dup_dir_check5, (void *)&dcs) < 0) { bu_vls_printf(gedp->ged_result_str, "dup: db_scan failure"); bu_free((void *)dirp0, "_ged_getspace array"); db_close(newdbp); return GED_ERROR; } } rt_mempurge(&(newdbp->dbi_freep)); /* didn't really build a directory */ _ged_vls_col_pr4v(gedp->ged_result_str, dirp0, (int)(dcs.dup_dirp - dirp0), 0); bu_vls_printf(gedp->ged_result_str, "\n ----- %d duplicate names found -----", gedp->ged_wdbp->wdb_num_dups); bu_free((void *)dirp0, "_ged_getspace array"); db_close(newdbp); return GED_OK; }