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;
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:
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
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 */
/* 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)