Skip to content

Commit

Permalink
First successful use of a cmd-specific registered callback function t…
Browse files Browse the repository at this point in the history
…o run search -exec
  • Loading branch information
starseeker committed Nov 25, 2024
1 parent c159834 commit 45265e4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
1 change: 0 additions & 1 deletion include/ged/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ struct ged {
void *ged_ctx; /* Temporary - do not rely on when designing new functionality */

void *ged_interp; /* Temporary - do not rely on when designing new functionality */
bu_clbk_t ged_interp_eval; /* FIXME: broke the rule written on the previous line */

};

Expand Down
10 changes: 8 additions & 2 deletions src/libged/search/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,16 @@ ged_search_core(struct ged *gedp, int argc, const char *argv_orig[])
const char *usage = "[-a] [-v[v..]] [-Q] [-h] [path] [expressions...]\n";
/* COPY argv_orig to argv; */
char **argv = NULL;
bu_clbk_t clbk = gedp->ged_interp_eval;
void *u1 = (void *)gedp->ged_interp;


bu_clbk_t clbk = NULL;
void *u1 = (void *)gedp;
void *u2 = NULL;

if (ged_clbk_get(&clbk, &u2, gedp, argv_orig[0], 0) == BRLCAD_ERROR) {
bu_log("search cmd callback retrieval error\n");
return BRLCAD_ERROR;
}

/* Find how many options we have. Once we get support
* for long options, this logic will have to get more sophisticated
Expand Down
8 changes: 4 additions & 4 deletions src/mged/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ mged_pr_output(Tcl_Interp *interp)


int
mged_db_search_callback(int argc, const char *argv[], void *userdata, void *UNUSED(d2))
mged_db_search_callback(int argc, const char *argv[], void *UNUSED(u1), void *u2)
{
/* FIXME: pretty much copied from tclcad, ideally this should call
* tclcad's eval instead of doing its own thing but this is probably
Expand All @@ -213,15 +213,15 @@ mged_db_search_callback(int argc, const char *argv[], void *userdata, void *UNUS
for (i = 1; i < argc; ++i)
Tcl_DStringAppendElement(&script, argv[i]);

ret = Tcl_Eval((Tcl_Interp *)userdata, Tcl_DStringValue(&script));
ret = Tcl_Eval((Tcl_Interp *)u2, Tcl_DStringValue(&script));
Tcl_DStringFree(&script);

result = Tcl_GetStringResult((Tcl_Interp *)userdata);
result = Tcl_GetStringResult((Tcl_Interp *)u2);
len = strlen(result);
if (len > 0)
bu_log("%s%s", result, result[len-1] == '\n' ? "" : "\n");

Tcl_ResetResult((Tcl_Interp *)userdata);
Tcl_ResetResult((Tcl_Interp *)u2);

/* NOTE: Tcl_Eval saves the last -exec result to GEDP->ged_result_str
this causes a duplicate print of the last 'search -exec' in mged (since
Expand Down
6 changes: 4 additions & 2 deletions src/mged/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,10 @@ mged_setup(Tcl_Interp **interpreter)
GEDP->ged_post_closedb_callback = &mged_post_closedb_clbk;
GEDP->ged_db_callback_udata = &mged_global_db_ctx;
GEDP->ged_interp = (void *)interpreter;
GEDP->ged_interp_eval = &mged_db_search_callback;

// Register during-execution callback function for search command
ged_clbk_set(GEDP, "search", 0, &mged_db_search_callback, (void *)*interpreter);

struct tclcad_io_data *t_iod = tclcad_create_io_data();
t_iod->io_mode = TCL_READABLE;
t_iod->interp = *interpreter;
Expand Down Expand Up @@ -525,7 +528,6 @@ mged_setup(Tcl_Interp **interpreter)
mged_global_variable_setup(*interpreter);
mged_variable_setup(*interpreter);
GEDP->ged_interp = (void *)*interpreter;
GEDP->ged_interp_eval = &mged_db_search_callback;

/* Tcl needs to write nulls onto subscripted variable names */
bu_vls_printf(&str, "%s(state)", MGED_DISPLAY_VAR);
Expand Down

0 comments on commit 45265e4

Please sign in to comment.