X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fhelper%2Fcommand.c;h=a775c730b88f8d5d499369b64091911531e68b17;hp=8860cf81fdd9859bede598d2f2c3ef7d3a409ea2;hb=HEAD;hpb=f9ea9ce24cf4423111a7fa033f8ceff61d17aa5b diff --git a/src/helper/command.c b/src/helper/command.c index 8860cf81fd..a775c730b8 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -489,15 +489,29 @@ static bool command_can_run(struct command_context *cmd_ctx, struct command *c, return false; } -static int run_command(struct command_context *context, - struct command *c, const char **words, unsigned num_words) +static int exec_command(Jim_Interp *interp, struct command_context *context, + struct command *c, int argc, Jim_Obj * const *argv) { + if (c->jim_handler) + return c->jim_handler(interp, argc, argv); + + /* use c->handler */ + const char **words = malloc(argc * sizeof(char *)); + if (!words) { + LOG_ERROR("Out of memory"); + return JIM_ERR; + } + + for (int i = 0; i < argc; i++) + words[i] = Jim_GetString(argv[i], NULL); + struct command_invocation cmd = { .ctx = context, .current = c, .name = c->name, - .argc = num_words - 1, + .argc = argc - 1, .argv = words + 1, + .jimtcl_argv = argv + 1, }; cmd.output = Jim_NewEmptyStringObj(context->interp); @@ -526,7 +540,8 @@ static int run_command(struct command_context *context, } Jim_DecrRefCount(context->interp, cmd.output); - return retval; + free(words); + return command_retval_set(interp, retval); } int command_run_line(struct command_context *context, char *line) @@ -867,27 +882,6 @@ static char *alloc_concatenate_strings(int argc, Jim_Obj * const *argv) return all; } -static int exec_command(Jim_Interp *interp, struct command_context *cmd_ctx, - struct command *c, int argc, Jim_Obj * const *argv) -{ - if (c->jim_handler) - return c->jim_handler(interp, argc, argv); - - /* use c->handler */ - const char **words = malloc(argc * sizeof(char *)); - if (!words) { - LOG_ERROR("Out of memory"); - return JIM_ERR; - } - - for (int i = 0; i < argc; i++) - words[i] = Jim_GetString(argv[i], NULL); - - int retval = run_command(cmd_ctx, c, words, argc); - free(words); - return command_retval_set(interp, retval); -} - static int jim_command_dispatch(Jim_Interp *interp, int argc, Jim_Obj * const *argv) { /* check subcommands */