Skip to content

Commit

Permalink
Convert the readily convertible cases of ged_exec to wrappers
Browse files Browse the repository at this point in the history
For any cases in our code where we are using ged_exec simply to fire off
a pre-defined command, use the wrapper so we will get a compile time
breakage in the case of a command rename or removal.

Cases where we are still using ged_exec warrant scrutiny to make sure
it's a correct usage.  There are some (gsh and qged command lines, for
example) where the intent *is* general command execution, and a couple
cases where there are multiple potential command names coming in from
the caller that are passed through as-is (though the latter are
problematic in that we're still losing the compile time validation.)
There are definitely a few cases in libtclcad that are straight up
broken - I tried to label them as I encountered them.
  • Loading branch information
starseeker committed Nov 22, 2024
1 parent 4edadfd commit b254793
Show file tree
Hide file tree
Showing 27 changed files with 658 additions and 687 deletions.
2 changes: 1 addition & 1 deletion src/conv/bot_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ main(int argc, char *argv[])
print_usage(argv[0]);
}

(void)ged_exec(gedp, j, av);
(void)ged_exec_bot_dump(gedp, j, av);
if (bu_vls_strlen(gedp->ged_result_str) > 0)
bu_log("%s", bu_vls_addr(gedp->ged_result_str));
ged_close(gedp);
Expand Down
14 changes: 5 additions & 9 deletions src/conv/g-dot.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,8 @@ main(int ac, char *av[])
/* write out header */
{
struct bu_vls vp = BU_VLS_INIT_ZERO;
const char *title[2] = {"title", NULL};

ged_exec(gp, 1, title);
const char *title[1] = {"title"};
ged_exec_title(gp, 1, title);
bu_vls_printf(&vp, "%s\\n", bu_vls_addr(gp->ged_result_str));
if (!(av[0][0] == '-' && av[0][1] == '\0')) {
char base[MAXPATHLEN] = {0};
Expand All @@ -354,14 +353,11 @@ main(int ac, char *av[])

objs = bu_argv_dup(ac - 1, (const char **)(av + 1));
} else {
char **topobjs;
const char *tops[3] = {"tops", "-n", NULL};

/* all top-level objects */
const char *tops[2] = {"tops", "-n"};
ged_exec_tops(gp, 2, tops);

ged_exec(gp, 2, tops);

topobjs = (char **)bu_calloc(bu_vls_strlen(gp->ged_result_str) + 1, sizeof(char *), "alloc topobjs");
char **topobjs = (char **)bu_calloc(bu_vls_strlen(gp->ged_result_str) + 1, sizeof(char *), "alloc topobjs");
c = (int)bu_argv_from_string(topobjs, bu_vls_strlen(gp->ged_result_str), bu_vls_addr(gp->ged_result_str));
objs = bu_argv_dup(c, (const char **)topobjs);
bu_free(topobjs, "free topobjs");
Expand Down
4 changes: 2 additions & 2 deletions src/gtools/gchecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ main(int argc, const char **argv)
av[5] = bu_strdup("-q");
av[6] = bu_strdup(objs[i]->d_namep);
bu_vls_trunc(gedp->ged_result_str, 0);
if (ged_exec(gedp, 7, av) != BRLCAD_OK) {
if (ged_exec_check(gedp, 7, av) != BRLCAD_OK) {
bu_exit(1, "error running ged 'check' command\n");
}
for (int j = 0; j < 7; j++) bu_free((void *)av[j], "str");
Expand Down Expand Up @@ -284,7 +284,7 @@ main(int argc, const char **argv)
av[3] = bu_strdup("-q");
av[4] = bu_strdup(objs[i]->d_namep);
bu_vls_trunc(gedp->ged_result_str, 0);
if (ged_exec(gedp, 5, av) != BRLCAD_OK) {
if (ged_exec_check(gedp, 5, av) != BRLCAD_OK) {
bu_exit(1, "error running ged 'check' command\n");
}
for (int j = 0; j < 5; j++) bu_free((void *)av[j], "str");
Expand Down
26 changes: 12 additions & 14 deletions src/gtools/gist/InformationGatherer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ boundingBox
InformationGatherer::getBBData(std::string component)
{
// Gather bounding box dimensions
const char* cmd[4] = { "bb", "-q", component.c_str(), NULL };
ged_exec(g, 3, cmd);
const char* cmd[3] = { "bb", "-q", component.c_str()};
ged_exec_bb(g, 3, cmd);
std::istringstream ss(bu_vls_addr(g->ged_result_str));

/* interested in saving X, Y, Z, Volume from output
Expand Down Expand Up @@ -268,8 +268,8 @@ InformationGatherer::getMainComp()
if (!topcomp.empty()) {
const char *topname = topcomp.c_str();
// check if main comp exists
const char* cmd[3] = { "exists", topname, NULL };
ged_exec(g, 2, cmd);
const char* cmd[2] = { "exists", topname };
ged_exec_exists(g, 2, cmd);
std::string res = bu_vls_addr(g->ged_result_str);
if (res != "1") {
bu_exit(BRLCAD_ERROR, "Could not find component (%s), aborting.\n", topname);
Expand All @@ -282,9 +282,8 @@ InformationGatherer::getMainComp()
}

// get top level objects
const char* cmd[3] = { "tops", "-n", NULL };

ged_exec(g, 2, cmd);
const char* cmd[2] = { "tops", "-n" };
ged_exec_tops(g, 2, cmd);
std::istringstream ss(bu_vls_addr(g->ged_result_str));
std::string comp;
std::vector<ComponentData> topComponents;
Expand All @@ -306,9 +305,8 @@ InformationGatherer::getMainComp()
if (largestComponents.size() != 0) {
return;
} else {
const char* search_cmd[5] = { "search", ".", "-type", "comb", NULL };

ged_exec(g, 4, search_cmd);
const char* search_cmd[4] = { "search", ".", "-type", "comb" };
ged_exec_search(g, 4, search_cmd);
std::stringstream ss2(bu_vls_addr(g->ged_result_str));
std::string val2;
std::vector<ComponentData> topComponents2;
Expand Down Expand Up @@ -398,21 +396,21 @@ InformationGatherer::gatherInformation(std::string UNUSED(name))

//Gather title
const char* cmd[6] = { "title", NULL, NULL, NULL, NULL };
ged_exec(g, 1, cmd);
ged_exec_title(g, 1, cmd);
infoMap["title"] = bu_vls_addr(g->ged_result_str);


//Gather DB Version
cmd[0] = "dbversion";
cmd[1] = NULL;
ged_exec(g, 1, cmd);
ged_exec_dbversion(g, 1, cmd);
infoMap["version"] = bu_vls_addr(g->ged_result_str);

// CHECK
//Gather primitives, regions, total objects
/*
cmd[0] = "summary";
ged_exec(g, 1, cmd);
ged_exec_summary(g, 1, cmd);
char* res = strtok(bu_vls_addr(g->ged_result_str), " ");
int count = 0;
while (res != NULL) {
Expand All @@ -432,7 +430,7 @@ InformationGatherer::gatherInformation(std::string UNUSED(name))
// Gather units
cmd[0] = "units";
cmd[1] = NULL;
ged_exec(g, 1, cmd);
ged_exec_units(g, 1, cmd);
std::string result = bu_vls_addr(g->ged_result_str);
std::size_t first = result.find_first_of("\'");
std::size_t last = result.find_last_of("\'");
Expand Down
2 changes: 1 addition & 1 deletion src/gtools/gqa.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ main(int argc, char *argv[])
bu_exit(1, usage, argv[0]);
}

(void)ged_exec(gedp, j, av);
(void)ged_exec_gqa(gedp, j, av);
if (bu_vls_strlen(gedp->ged_result_str) > 0)
bu_log("%s", bu_vls_addr(gedp->ged_result_str));
ged_close(gedp);
Expand Down
8 changes: 4 additions & 4 deletions src/gtools/tests/bigdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,22 @@ main(int ac, char *av[])
/* validate */

struct ged *gedp = ged_open("db", filename, 1);
const char *tops_cmd[3] = {"tops", "-n", NULL};
const char *title_cmd[2] = {"title", NULL};
const char *id = NULL;
struct bu_vls vp = BU_VLS_INIT_ZERO;
char *base = bu_path_basename(av[0], NULL);
size_t idlen = 0;
int match = 0;

ged_exec(gedp, 2, tops_cmd);
const char *tops_cmd[2] = {"tops", "-n"};
ged_exec_tops(gedp, 2, tops_cmd);

bu_vls_trimspace(gedp->ged_result_str); /* trailing newline */
printf("%s_tops=\"%s\"\n", base, bu_vls_cstr(gedp->ged_result_str));
if (!BU_STR_EQUIV(bu_vls_cstr(gedp->ged_result_str), ORIGIN_SPHERE))
failures++;

ged_exec(gedp, 1, title_cmd);
const char *title_cmd[1] = {"title"};
ged_exec_title(gedp, 1, title_cmd);

id = bu_vls_cstr(gedp->ged_result_str);
idlen = bu_vls_strlen(gedp->ged_result_str);
Expand Down
4 changes: 2 additions & 2 deletions src/libqtcad/QgModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ QgModel::draw(const char *inst_path)
argv[1] = inst_path;

bu_setenv("GED_TEST_NEW_CMD_FORMS", "1", 1);
int ret = ged_exec(gedp, 2, argv);
int ret = ged_exec_draw(gedp, 2, argv);

emit view_change(QG_VIEW_DRAWN);
return ret;
Expand Down Expand Up @@ -926,7 +926,7 @@ QgModel::erase(const char *inst_path)
argv[1] = inst_path;

bu_setenv("GED_TEST_NEW_CMD_FORMS", "1", 1);
int ret = ged_exec(gedp, 2, argv);
int ret = ged_exec_erase(gedp, 2, argv);

emit view_change(QG_VIEW_DRAWN);
return ret;
Expand Down
6 changes: 3 additions & 3 deletions src/libqtcad/QgViewCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ QgViewCtrl::fbclear_cmd()
bu_setenv("GED_TEST_NEW_CMD_FORMS", "1", 1);
const char *av[2] = {NULL};
av[0] = "fbclear";
ged_exec(gedp, 1, (const char **)av);
ged_exec_fbclear(gedp, 1, (const char **)av);
emit view_changed(QG_VIEW_REFRESH);
}

Expand Down Expand Up @@ -177,12 +177,12 @@ QgViewCtrl::raytrace_cmd()
av[0] = "process";
av[1] = "pabort";
av[2] = bu_vls_cstr(&pid_str);
ged_exec(gedp, 3, (const char **)av);
ged_exec_process(gedp, 3, (const char **)av);
goto cmd_cleanup;
}

av[0] = "ert";
ged_exec(gedp, 1, (const char **)av);
ged_exec_ert(gedp, 1, (const char **)av);
emit view_changed(QG_VIEW_REFRESH);

cmd_cleanup:
Expand Down
10 changes: 5 additions & 5 deletions src/libqtcad/tests/qgmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ int main(int argc, char *argv[])
av[1] = "all.g";
av[2] = "ellipse.r";
av[3] = NULL;
ged_exec(g, ac, (const char **)av);
ged_exec_rm(g, ac, (const char **)av);
s->g_update(g->dbip);

std::cout << "\nRemoved ellipse.r from all.g:\n";
Expand All @@ -198,7 +198,7 @@ int main(int argc, char *argv[])
av[1] = "all.g";
av[2] = "ellipse.r";
av[3] = NULL;
ged_exec(g, ac, (const char **)av);
ged_exec_g(g, ac, (const char **)av);
s->g_update(g->dbip);

std::cout << "\nAdded ellipse.r back to the end of all.g, no call to open:\n";
Expand All @@ -213,7 +213,7 @@ int main(int argc, char *argv[])
av[1] = "tor.r";
av[2] = "tor";
av[3] = NULL;
ged_exec(g, ac, (const char **)av);
ged_exec_rm(g, ac, (const char **)av);
s->g_update(g->dbip);

std::cout << "\ntops tree after removing tor from tor.r:\n";
Expand All @@ -223,7 +223,7 @@ int main(int argc, char *argv[])
av[1] = "-f";
av[2] = "all.g";
av[3] = NULL;
ged_exec(g, ac, (const char **)av);
ged_exec_kill(g, ac, (const char **)av);
s->g_update(g->dbip);
std::cout << "\ntops tree after deleting all.g:\n";
print_tops(s);
Expand All @@ -240,7 +240,7 @@ int main(int argc, char *argv[])
av[1] = "-f";
av[2] = obj;
av[3] = NULL;
ged_exec(g, ac, (const char **)av);
ged_exec_kill(g, ac, (const char **)av);
i++;
obj = objs[i];
}
Expand Down
Loading

0 comments on commit b254793

Please sign in to comment.