}
Jim_Interp *interp;
-command_context_t *active_cmd_ctx;
static int new_int_array_element(Jim_Interp * interp, const char *varname, int idx, u32 val)
{
static int Jim_Command_mem2array(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
target_t *target;
+ command_context_t *context;
long l;
u32 width;
u32 len;
return JIM_ERR;
}
- target = get_current_target(active_cmd_ctx);
+ context = Jim_GetAssocData(interp, "context");
+ if (context == NULL)
+ {
+ LOG_ERROR("mem2array: no command context");
+ return JIM_ERR;
+ }
+ target = get_current_target(context);
+ if (target == NULL)
+ {
+ LOG_ERROR("mem2array: no current target");
+ return JIM_ERR;
+ }
/* Transfer loop */
static int Jim_Command_array2mem(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
target_t *target;
+ command_context_t *context;
long l;
u32 width;
u32 len;
return JIM_ERR;
}
- target = get_current_target(active_cmd_ctx);
+ context = Jim_GetAssocData(interp, "context");
+ if (context == NULL)
+ {
+ LOG_ERROR("array2mem: no command context");
+ return JIM_ERR;
+ }
+ target = get_current_target(context);
+ if (target == NULL)
+ {
+ LOG_ERROR("array2mem: no current target");
+ return JIM_ERR;
+ }
/* Transfer loop */
{
if (argc != 2)
return JIM_ERR;
- char *str = (char*)Jim_GetString(argv[1], NULL);
+ const char *str = Jim_GetString(argv[1], NULL);
LOG_USER("%s", str);
return JIM_OK;
}
{
size_t nbytes;
const char *ptr;
+ Jim_Interp *interp;
+ command_context_t *context;
/* make it a char easier to read code */
ptr = _ptr;
-
+ interp = cookie;
nbytes = size * n;
- if (nbytes == 0) {
+ if (ptr == NULL || interp == NULL || nbytes == 0) {
return 0;
}
- if (!active_cmd_ctx) {
+ context = Jim_GetAssocData(interp, "context");
+ if (context == NULL)
+ {
+ LOG_ERROR("openocd_jim_fwrite: no command context");
/* TODO: Where should this go? */
return n;
}
/* do we have to chunk it? */
- if (ptr[nbytes] == 0) {
+ if (ptr[nbytes] == 0)
+ {
/* no it is a C style string */
- command_output_text(active_cmd_ctx, ptr);
+ command_output_text(context, ptr);
return strlen(ptr);
}
/* GRR we must chunk - not null terminated */
/* terminate it */
chunk[n] = 0;
/* output it */
- command_output_text(active_cmd_ctx, chunk);
+ command_output_text(context, chunk);
ptr += x;
nbytes -= x;
}
return n;
}
-static size_t openocd_jim_fread(void *ptr, size_t size, size_t n, void *cookie )
+static size_t openocd_jim_fread(void *ptr, size_t size, size_t n, void *cookie)
{
/* TCL wants to read... tell him no */
return 0;
{
char *cp;
int n;
-
+ Jim_Interp *interp;
+ command_context_t *context;
+
n = -1;
- if (active_cmd_ctx) {
- cp = alloc_vprintf(fmt, ap);
- if (cp) {
- command_output_text(active_cmd_ctx, cp);
- n = strlen(cp);
- free(cp);
- }
+ interp = cookie;
+ if (interp == NULL)
+ return n;
+
+ context = Jim_GetAssocData(interp, "context");
+ if (context == NULL)
+ {
+ LOG_ERROR("openocd_jim_vfprintf: no command context");
+ return n;
+ }
+
+ cp = alloc_vprintf(fmt, ap);
+ if (cp)
+ {
+ command_output_text(context, cp);
+ n = strlen(cp);
+ free(cp);
}
return n;
}
extern unsigned const char startup_tcl[];
void initJim(void)
-{
+{
Jim_CreateCommand(interp, "openocd_find", Jim_Command_find, NULL, NULL);
Jim_CreateCommand(interp, "echo", Jim_Command_echo, NULL, NULL);
Jim_CreateCommand(interp, "mem2array", Jim_Command_mem2array, NULL, NULL );
Jim_CreateCommand(interp, "array2mem", Jim_Command_array2mem, NULL, NULL );
/* Set Jim's STDIO */
- interp->cookie_stdin = NULL;
- interp->cookie_stdout = NULL;
- interp->cookie_stderr = NULL;
+ interp->cookie_stdin = interp;
+ interp->cookie_stdout = interp;
+ interp->cookie_stderr = interp;
interp->cb_fwrite = openocd_jim_fwrite;
interp->cb_fread = openocd_jim_fread ;
interp->cb_vfprintf = openocd_jim_vfprintf;
LOG_OUTPUT( OPENOCD_VERSION "\n" );
-
register_command(cmd_ctx, NULL, "init", handle_init_command,
COMMAND_ANY, "initializes target and servers - nop on subsequent invocations");