diff options
author | Øyvind Harboe <oyvind.harboe@zylin.com> | 2009-12-01 08:41:41 +0100 |
---|---|---|
committer | Øyvind Harboe <oyvind.harboe@zylin.com> | 2009-12-01 09:53:23 +0100 |
commit | 5576a6240a103879e1a8d9d4c2b6ff4aee0d23fa (patch) | |
tree | 7f817159a2a8c6dea9dee3cb9f0cc84b90b8eb86 /src | |
parent | 63dc352876259562948b5d814de197ba534897b9 (diff) | |
download | riscv-openocd-5576a6240a103879e1a8d9d4c2b6ff4aee0d23fa.zip riscv-openocd-5576a6240a103879e1a8d9d4c2b6ff4aee0d23fa.tar.gz riscv-openocd-5576a6240a103879e1a8d9d4c2b6ff4aee0d23fa.tar.bz2 |
command: the Jim interpreter can now be provided rather than created
In embedded hosts, the Jim interpreter can come from the
existing context rather than be created by OpenOCD.
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/helper/command.c | 18 | ||||
-rw-r--r-- | src/helper/command.h | 6 | ||||
-rw-r--r-- | src/openocd.c | 6 |
3 files changed, 18 insertions, 12 deletions
diff --git a/src/helper/command.c b/src/helper/command.c index dcad6a1..d657668 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -1272,7 +1272,7 @@ static const struct command_registration command_builtin_handlers[] = { COMMAND_REGISTRATION_DONE }; -struct command_context* command_init(const char *startup_tcl) +struct command_context* command_init(const char *startup_tcl, Jim_Interp *interp) { struct command_context* context = malloc(sizeof(struct command_context)); const char *HostOs; @@ -1284,14 +1284,18 @@ struct command_context* command_init(const char *startup_tcl) context->output_handler_priv = NULL; #if !BUILD_ECOSBOARD - Jim_InitEmbedded(); - /* Create an interpreter */ - context->interp = Jim_CreateInterp(); - /* Add all the Jim core commands */ - Jim_RegisterCoreCommands(context->interp); + /* Create a jim interpreter if we were not handed one */ + if (interp == NULL) + { + Jim_InitEmbedded(); + /* Create an interpreter */ + interp = Jim_CreateInterp(); + /* Add all the Jim core commands */ + Jim_RegisterCoreCommands(interp); + } #endif + context->interp = interp; - Jim_Interp *interp = context->interp; #if defined(_MSC_VER) /* WinXX - is generic, the forward * looking problem is this: diff --git a/src/helper/command.h b/src/helper/command.h index 611db87..8d68c18 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -323,9 +323,11 @@ void command_set_output_handler(struct command_context* context, int command_context_mode(struct command_context *context, enum command_mode mode); /** - * Creates a new command context using the startup TCL provided. + * Creates a new command context using the startup TCL provided and + * the existing Jim interpreter, if any. If interp == NULL, then command_init + * creates a command interpreter. */ -struct command_context* command_init(const char *startup_tcl); +struct command_context* command_init(const char *startup_tcl, Jim_Interp *interp); /** * Creates a copy of an existing command context. This does not create * a deep copy of the command list, so modifications in one context will diff --git a/src/openocd.c b/src/openocd.c index 22d4582..44e0292 100644 --- a/src/openocd.c +++ b/src/openocd.c @@ -188,14 +188,14 @@ static const struct command_registration openocd_command_handlers[] = { struct command_context *global_cmd_ctx; /* NB! this fn can be invoked outside this file for non PC hosted builds */ -struct command_context *setup_command_handler(void) +struct command_context *setup_command_handler(Jim_Interp *interp) { log_init(); LOG_DEBUG("log_init: complete"); struct command_context *cmd_ctx; - global_cmd_ctx = cmd_ctx = command_init(openocd_startup_tcl); + global_cmd_ctx = cmd_ctx = command_init(openocd_startup_tcl, interp); register_commands(cmd_ctx, NULL, openocd_command_handlers); /* register subsystem commands */ @@ -242,7 +242,7 @@ int openocd_main(int argc, char *argv[]) /* initialize commandline interface */ struct command_context *cmd_ctx; - cmd_ctx = setup_command_handler(); + cmd_ctx = setup_command_handler(NULL); #if BUILD_IOUTIL if (ioutil_init(cmd_ctx) != ERROR_OK) |