c->parent = parent;
c->handler = cr->handler;
c->jim_handler = cr->jim_handler;
- c->jim_handler_data = cr->jim_handler_data;
c->mode = cr->mode;
command_add_child(command_list_for_parent(cmd_ctx, parent), c);
int retval = ERROR_OK;
if (NULL != cr->jim_handler && NULL == parent) {
retval = Jim_CreateCommand(context->interp, cr->name,
- cr->jim_handler, cr->jim_handler_data, NULL);
+ cr->jim_handler, NULL, NULL);
} else if (NULL != cr->handler || NULL != parent)
retval = register_command_handler(context, command_root(c));
}
} else if (retval == ERROR_COMMAND_CLOSE_CONNECTION) {
/* just fall through for a shutdown request */
- } else if (retval != ERROR_OK) {
- /* we do not print out an error message because the command *should*
- * have printed out an error
- */
- char *full_name = command_name(c, ' ');
- LOG_DEBUG("Command '%s' failed with error code %d",
- full_name ? full_name : c->name, retval);
- free(full_name);
} else {
+ if (retval != ERROR_OK) {
+ char *full_name = command_name(c, ' ');
+ LOG_DEBUG("Command '%s' failed with error code %d",
+ full_name ? full_name : c->name, retval);
+ free(full_name);
+ }
/* Use the command output as the Tcl result */
Jim_SetResult(context->interp, cmd.output);
}
* happen when the Jim Tcl interpreter is provided by eCos for
* instance.
*/
+ struct target *saved_target_override = context->current_target_override;
context->current_target_override = NULL;
Jim_Interp *interp = context->interp;
+ struct command_context *old_context = Jim_GetAssocData(interp, "context");
Jim_DeleteAssocData(interp, "context");
retcode = Jim_SetAssocData(interp, "context", NULL, context);
if (retcode == JIM_OK) {
Jim_DeleteAssocData(interp, "retval");
}
Jim_DeleteAssocData(interp, "context");
+ int inner_retcode = Jim_SetAssocData(interp, "context", NULL, old_context);
+ if (retcode == JIM_OK)
+ retcode = inner_retcode;
}
+ context->current_target_override = saved_target_override;
if (retcode == JIM_OK) {
const char *result;
int reslen;
static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
const char *cmd_name = Jim_GetString(argv[0], NULL);
- if (strcmp(cmd_name, "unknown") == 0) {
- if (argc == 1)
- return JIM_OK;
- argc--;
- argv++;
- }
script_debug(interp, cmd_name, argc, argv);
struct command_context *cmd_ctx = current_command_context(interp);
.mode = COMMAND_ANY,
.jim_handler = jim_command_mode,
.usage = "[command_name ...]",
- .help = "Returns the command modes allowed by a command:"
- "'any', 'config', or 'exec'. If no command is"
- "specified, returns the current command mode. "
+ .help = "Returns the command modes allowed by a command: "
+ "'any', 'config', or 'exec'. If no command is "
+ "specified, returns the current command mode. "
"Returns 'unknown' if an unknown command is given. "
"Command can be multiple tokens.",
},
};
static const struct command_registration command_builtin_handlers[] = {
+ {
+ .name = "ocd_find",
+ .mode = COMMAND_ANY,
+ .jim_handler = jim_find,
+ .help = "find full path to file",
+ .usage = "file",
+ },
+ {
+ .name = "capture",
+ .mode = COMMAND_ANY,
+ .jim_handler = jim_capture,
+ .help = "Capture progress output and return as tcl return value. If the "
+ "progress output was empty, return tcl return value.",
+ .usage = "command",
+ },
{
.name = "echo",
.handler = jim_echo,
Jim_SetGlobalVariableStr(interp, "ocd_HOSTOS",
Jim_NewStringObj(interp, HostOs, strlen(HostOs)));
- Jim_CreateCommand(interp, "ocd_find", jim_find, NULL, NULL);
- Jim_CreateCommand(interp, "capture", jim_capture, NULL, NULL);
-
register_commands(context, NULL, command_builtin_handlers);
Jim_SetAssocData(interp, "context", NULL, context);
return ERROR_COMMAND_ARGUMENT_INVALID; \
} \
char *end; \
+ errno = 0; \
*ul = func(str, &end, 0); \
if (*end) { \
LOG_ERROR("Invalid command argument"); \