command context: fix errors when running certain commands on startup

Various commands, e.g. "arm mcr xxxx" would fail if invoked upon startup
since it there was no command context defined for the jim interpreter
in that case.

A Jim interpreter is now associated with a command context(telnet,
gdb server's) or the default global command context.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
This commit is contained in:
Øyvind Harboe
2010-05-03 17:01:53 +02:00
parent 7e33f87b3d
commit 91b9f3de0b
5 changed files with 30 additions and 23 deletions

View File

@@ -167,14 +167,18 @@ static const char **script_command_args_alloc(
return words;
}
static struct command_context *current_command_context(Jim_Interp *interp)
struct command_context *current_command_context(Jim_Interp *interp)
{
/* grab the command context from the associated data */
struct command_context *cmd_ctx = Jim_GetAssocData(interp, "context");
if (NULL == cmd_ctx)
{
/* Tcl can invoke commands directly instead of via command_run_line(). This would
* happen when the Jim Tcl interpreter is provided by eCos.
* happen when the Jim Tcl interpreter is provided by eCos or if we are running
* commands in a startup script.
*
* A telnet or gdb server would provide a non-default command context to
* handle piping of error output, have a separate current target, etc.
*/
cmd_ctx = global_cmd_ctx;
}