From: openocd-gerrit <ope...@us...> - 2025-04-19 09:18:34
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 339763ed2d9a00ac1f2418403bd29c324d1c7e6e (commit) from 6834f022b96fb1c7f5829166578e01a0ac223cb0 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 339763ed2d9a00ac1f2418403bd29c324d1c7e6e Author: Antonio Borneo <bor...@gm...> Date: Sat Dec 2 17:06:17 2023 +0100 command: rewrite command 'command mode' as COMMAND_HANDLER Another step to drop jim_handler. Change-Id: I85cb567386a5aceb36aa273f8b66cbfd4a637c3f Signed-off-by: Antonio Borneo <bor...@gm...> Reviewed-on: https://review.openocd.org/c/openocd/+/8586 Tested-by: jenkins Reviewed-by: Evgeniy Naydanov <evg...@sy...> diff --git a/src/helper/command.c b/src/helper/command.c index 3d4379d06..923b091a8 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -843,22 +843,19 @@ COMMAND_HANDLER(handle_help_command) return retval; } -static char *alloc_concatenate_strings(int argc, Jim_Obj * const *argv) +static char *alloc_concatenate_strings(int argc, const char **argv) { - char *prev, *all; - int i; - assert(argc >= 1); - all = strdup(Jim_GetString(argv[0], NULL)); + char *all = strdup(argv[0]); if (!all) { LOG_ERROR("Out of memory"); return NULL; } - for (i = 1; i < argc; ++i) { - prev = all; - all = alloc_printf("%s %s", all, Jim_GetString(argv[i], NULL)); + for (int i = 1; i < argc; ++i) { + char *prev = all; + all = alloc_printf("%s %s", all, argv[i]); free(prev); if (!all) { LOG_ERROR("Out of memory"); @@ -944,17 +941,16 @@ static enum command_mode get_command_mode(Jim_Interp *interp, const char *cmd_na return c->mode; } -static int jim_command_mode(Jim_Interp *interp, int argc, Jim_Obj *const *argv) +COMMAND_HANDLER(handle_command_mode) { - struct command_context *cmd_ctx = current_command_context(interp); - enum command_mode mode = cmd_ctx->mode; + enum command_mode mode = CMD_CTX->mode; - if (argc > 1) { - char *full_name = alloc_concatenate_strings(argc - 1, argv + 1); + if (CMD_ARGC) { + char *full_name = alloc_concatenate_strings(CMD_ARGC, CMD_ARGV); if (!full_name) - return JIM_ERR; + return ERROR_FAIL; - mode = get_command_mode(interp, full_name); + mode = get_command_mode(CMD_CTX->interp, full_name); free(full_name); } @@ -975,8 +971,8 @@ static int jim_command_mode(Jim_Interp *interp, int argc, Jim_Obj *const *argv) mode_str = "unknown"; break; } - Jim_SetResultString(interp, mode_str, -1); - return JIM_OK; + command_print(CMD, "%s", mode_str); + return ERROR_OK; } int help_del_all_commands(struct command_context *cmd_ctx) @@ -1115,7 +1111,7 @@ static const struct command_registration command_subcommand_handlers[] = { { .name = "mode", .mode = COMMAND_ANY, - .jim_handler = jim_command_mode, + .handler = handle_command_mode, .usage = "[command_name ...]", .help = "Returns the command modes allowed by a command: " "'any', 'config', or 'exec'. If no command is " ----------------------------------------------------------------------- Summary of changes: src/helper/command.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) hooks/post-receive -- Main OpenOCD repository |