add script_command_run helper
Eliminates duplicated code in script_command and handle_unknown_command. Fixes bug with duplicated help output generated by placeholder commands.__archive__
parent
9e5d8a94f1
commit
d89c631014
|
@ -150,33 +150,41 @@ static struct command_context *current_command_context(void)
|
||||||
return cmd_ctx;
|
return cmd_ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int script_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
|
static int script_command_run(Jim_Interp *interp,
|
||||||
|
int argc, Jim_Obj *const *argv, struct command *c, bool capture)
|
||||||
{
|
{
|
||||||
/* the private data is stashed in the interp structure */
|
|
||||||
|
|
||||||
struct command *c = interp->cmdPrivData;
|
|
||||||
assert(c);
|
|
||||||
|
|
||||||
target_call_timer_callbacks_now();
|
target_call_timer_callbacks_now();
|
||||||
LOG_USER_N("%s", ""); /* Keep GDB connection alive*/
|
LOG_USER_N("%s", ""); /* Keep GDB connection alive*/
|
||||||
|
|
||||||
script_debug(interp, c->name, argc, argv);
|
|
||||||
|
|
||||||
unsigned nwords;
|
unsigned nwords;
|
||||||
const char **words = script_command_args_alloc(argc, argv, &nwords);
|
const char **words = script_command_args_alloc(argc, argv, &nwords);
|
||||||
if (NULL == words)
|
if (NULL == words)
|
||||||
return JIM_ERR;
|
return JIM_ERR;
|
||||||
|
|
||||||
Jim_Obj *tclOutput = command_log_capture_start(interp);
|
Jim_Obj *tclOutput = NULL;
|
||||||
|
if (capture)
|
||||||
|
tclOutput = command_log_capture_start(interp);
|
||||||
|
|
||||||
struct command_context *cmd_ctx = current_command_context();
|
struct command_context *cmd_ctx = current_command_context();
|
||||||
int retval = run_command(cmd_ctx, c, (const char **)words, nwords);
|
int retval = run_command(cmd_ctx, c, (const char **)words, nwords);
|
||||||
|
|
||||||
|
if (capture)
|
||||||
command_log_capture_finish(interp, tclOutput);
|
command_log_capture_finish(interp, tclOutput);
|
||||||
|
|
||||||
script_command_args_free(words, nwords);
|
script_command_args_free(words, nwords);
|
||||||
return command_retval_set(interp, retval);
|
return command_retval_set(interp, retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int script_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
|
||||||
|
{
|
||||||
|
/* the private data is stashed in the interp structure */
|
||||||
|
|
||||||
|
struct command *c = interp->cmdPrivData;
|
||||||
|
assert(c);
|
||||||
|
script_debug(interp, c->name, argc, argv);
|
||||||
|
return script_command_run(interp, argc, argv, c, true);
|
||||||
|
}
|
||||||
|
|
||||||
/* nice short description of source file */
|
/* nice short description of source file */
|
||||||
#define __THIS__FILE__ "command.c"
|
#define __THIS__FILE__ "command.c"
|
||||||
|
|
||||||
|
@ -922,22 +930,7 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
|
||||||
return (*c->jim_handler)(interp, count, start);
|
return (*c->jim_handler)(interp, count, start);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned nwords;
|
return script_command_run(interp, count, start, c, found);
|
||||||
const char **words = script_command_args_alloc(count, start, &nwords);
|
|
||||||
if (NULL == words)
|
|
||||||
return JIM_ERR;
|
|
||||||
|
|
||||||
Jim_Obj *tclOutput = command_log_capture_start(interp);
|
|
||||||
|
|
||||||
int retval = run_command(cmd_ctx, c, words, nwords);
|
|
||||||
|
|
||||||
command_log_capture_finish(interp, tclOutput);
|
|
||||||
script_command_args_free(words, nwords);
|
|
||||||
|
|
||||||
if (!found && ERROR_OK == retval)
|
|
||||||
retval = ERROR_FAIL;
|
|
||||||
|
|
||||||
return command_retval_set(interp, retval);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int help_add_command(struct command_context *cmd_ctx, struct command *parent,
|
int help_add_command(struct command_context *cmd_ctx, struct command *parent,
|
||||||
|
|
Loading…
Reference in New Issue