command: rewrite command 'command mode' as COMMAND_HANDLER
Another step to drop jim_handler. Change-Id: I85cb567386a5aceb36aa273f8b66cbfd4a637c3f Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/8586 Tested-by: jenkins Reviewed-by: Evgeniy Naydanov <evgeniy.naydanov@syntacore.com>
This commit is contained in:
+14
-18
@@ -843,22 +843,19 @@ COMMAND_HANDLER(handle_help_command)
|
|||||||
return retval;
|
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);
|
assert(argc >= 1);
|
||||||
|
|
||||||
all = strdup(Jim_GetString(argv[0], NULL));
|
char *all = strdup(argv[0]);
|
||||||
if (!all) {
|
if (!all) {
|
||||||
LOG_ERROR("Out of memory");
|
LOG_ERROR("Out of memory");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
prev = all;
|
char *prev = all;
|
||||||
all = alloc_printf("%s %s", all, Jim_GetString(argv[i], NULL));
|
all = alloc_printf("%s %s", all, argv[i]);
|
||||||
free(prev);
|
free(prev);
|
||||||
if (!all) {
|
if (!all) {
|
||||||
LOG_ERROR("Out of memory");
|
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;
|
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) {
|
if (CMD_ARGC) {
|
||||||
char *full_name = alloc_concatenate_strings(argc - 1, argv + 1);
|
char *full_name = alloc_concatenate_strings(CMD_ARGC, CMD_ARGV);
|
||||||
if (!full_name)
|
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);
|
free(full_name);
|
||||||
}
|
}
|
||||||
@@ -975,8 +971,8 @@ static int jim_command_mode(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
|
|||||||
mode_str = "unknown";
|
mode_str = "unknown";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Jim_SetResultString(interp, mode_str, -1);
|
command_print(CMD, "%s", mode_str);
|
||||||
return JIM_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int help_del_all_commands(struct command_context *cmd_ctx)
|
int help_del_all_commands(struct command_context *cmd_ctx)
|
||||||
@@ -1115,7 +1111,7 @@ static const struct command_registration command_subcommand_handlers[] = {
|
|||||||
{
|
{
|
||||||
.name = "mode",
|
.name = "mode",
|
||||||
.mode = COMMAND_ANY,
|
.mode = COMMAND_ANY,
|
||||||
.jim_handler = jim_command_mode,
|
.handler = handle_command_mode,
|
||||||
.usage = "[command_name ...]",
|
.usage = "[command_name ...]",
|
||||||
.help = "Returns the command modes allowed by a command: "
|
.help = "Returns the command modes allowed by a command: "
|
||||||
"'any', 'config', or 'exec'. If no command is "
|
"'any', 'config', or 'exec'. If no command is "
|
||||||
|
|||||||
Reference in New Issue
Block a user