return cmd->isproc;
}
-static inline bool jimcmd_is_ocd_command(Jim_Cmd *cmd)
+bool jimcmd_is_oocd_command(Jim_Cmd *cmd)
{
return !cmd->isproc && cmd->u.native.cmdProc == jim_command_dispatch;
}
-static inline void *jimcmd_privdata(Jim_Cmd *cmd)
+void *jimcmd_privdata(Jim_Cmd *cmd)
{
return cmd->isproc ? NULL : cmd->u.native.privData;
}
{
/* capture log output and return it. A garbage collect can
* happen, so we need a reference count to this object */
- Jim_Obj *tclOutput = Jim_NewStringObj(interp, "", 0);
- if (NULL == tclOutput)
+ Jim_Obj *jim_output = Jim_NewStringObj(interp, "", 0);
+ if (!jim_output)
return NULL;
+ Jim_IncrRefCount(jim_output);
+
struct log_capture_state *state = malloc(sizeof(*state));
- if (NULL == state)
+ if (!state) {
+ LOG_ERROR("Out of memory");
+ Jim_DecrRefCount(interp, jim_output);
return NULL;
+ }
state->interp = interp;
- Jim_IncrRefCount(tclOutput);
- state->output = tclOutput;
+ state->output = jim_output;
log_add_callback(tcl_output, state);
* Use the internal jimtcl API Jim_CreateCommandObj, not exported by jim.h,
* and override the bugged API through preprocessor's macro.
* This workaround works only when jimtcl is compiled as OpenOCD submodule.
+ * It's broken on macOS, so it's currently restricted on Linux only.
* If jimtcl is linked-in from a precompiled library, either static or dynamic,
* the symbol Jim_CreateCommandObj is not exported and the build will use the
* bugged API.
* To be removed when OpenOCD will switch to jimtcl 0.81
*/
-#if JIM_VERSION == 80
+#if JIM_VERSION == 80 && defined __linux__
static int workaround_createcommand(Jim_Interp *interp, const char *cmdName,
Jim_CmdProc *cmdProc, void *privData, Jim_DelCmdProc *delProc);
int Jim_CreateCommandObj(Jim_Interp *interp, Jim_Obj *cmdNameObj,
return retval;
}
#define Jim_CreateCommand workaround_createcommand
-#endif /* JIM_VERSION == 80 */
+#endif /* JIM_VERSION == 80 && defined __linux__*/
/* FIXME: end of workaround for memory leak in jimtcl 0.80 */
static int command_retval_set(Jim_Interp *interp, int retval)
Jim_IncrRefCount(jim_name);
Jim_Cmd *cmd = Jim_GetCommand(interp, jim_name, JIM_NONE);
Jim_DecrRefCount(interp, jim_name);
- if (!cmd || jimcmd_is_proc(cmd) || !jimcmd_is_ocd_command(cmd))
+ if (!cmd || jimcmd_is_proc(cmd) || !jimcmd_is_oocd_command(cmd))
return NULL;
return jimcmd_privdata(cmd);
return NULL;
}
- LOG_DEBUG("registering '%s'...", full_name);
+ if (false) /* too noisy with debug_level 3 */
+ LOG_DEBUG("registering '%s'...", full_name);
int retval = Jim_CreateCommand(context->interp, full_name,
jim_command_dispatch, c, command_free);
if (retval != JIM_OK) {
Jim_DecrRefCount(interp, elem);
continue;
}
- LOG_DEBUG("delete command \"%s\"", name);
+ if (false) /* too noisy with debug_level 3 */
+ LOG_DEBUG("delete command \"%s\"", name);
+#if JIM_VERSION >= 80
Jim_DeleteCommand(interp, elem);
+#else
+ Jim_DeleteCommand(interp, name);
+#endif
help_del_command(cmd_ctx, name);
((c->help != NULL) && (strstr(c->help, cmd_match) != NULL));
if (is_match) {
- command_help_show_indent(n);
- LOG_USER_N("%s", c->cmd_name);
-
if (c->usage && strlen(c->usage) > 0) {
- LOG_USER_N(" ");
- command_help_show_wrap(c->usage, 0, n + 5);
- } else
- LOG_USER_N("\n");
+ char *msg = alloc_printf("%s %s", c->cmd_name, c->usage);
+ command_help_show_wrap(msg, n, n + 5);
+ free(msg);
+ } else {
+ command_help_show_wrap(c->cmd_name, n, n + 5);
+ }
}
if (is_match && show_help) {
stage_msg = " (?mode error?)";
break;
}
- msg = alloc_printf("%s%s", c->help ? : "", stage_msg);
+ msg = alloc_printf("%s%s", c->help ? c->help : "", stage_msg);
} else
- msg = alloc_printf("%s", c->help ? : "");
+ msg = alloc_printf("%s", c->help ? c->help : "");
if (NULL != msg) {
command_help_show_wrap(msg, n + 3, n + 3);
Jim_Cmd *cmd = Jim_GetCommand(interp, s, JIM_NONE);
Jim_DecrRefCount(interp, s);
free(full_name);
- if (!cmd || !(jimcmd_is_proc(cmd) || jimcmd_is_ocd_command(cmd))) {
+ if (!cmd || !(jimcmd_is_proc(cmd) || jimcmd_is_oocd_command(cmd))) {
Jim_SetResultString(interp, "unknown", -1);
return JIM_OK;
}
.handler = jim_echo,
.mode = COMMAND_ANY,
.help = "Logs a message at \"user\" priority. "
- "Output message to stdout. "
"Option \"-n\" suppresses trailing newline",
.usage = "[-n] string",
},
struct command_context *command_init(const char *startup_tcl, Jim_Interp *interp)
{
struct command_context *context = calloc(1, sizeof(struct command_context));
- const char *HostOs;
context->mode = COMMAND_EXEC;
context->interp = interp;
- /* Stick to lowercase for HostOS strings. */
-#if defined(_MSC_VER)
- /* WinXX - is generic, the forward
- * looking problem is this:
- *
- * "win32" or "win64"
- *
- * "winxx" is generic.
- */
- HostOs = "winxx";
-#elif defined(__linux__)
- HostOs = "linux";
-#elif defined(__APPLE__) || defined(__DARWIN__)
- HostOs = "darwin";
-#elif defined(__CYGWIN__)
- HostOs = "cygwin";
-#elif defined(__MINGW32__)
- HostOs = "mingw32";
-#elif defined(__ECOS)
- HostOs = "ecos";
-#elif defined(__FreeBSD__)
- HostOs = "freebsd";
-#elif defined(__NetBSD__)
- HostOs = "netbsd";
-#elif defined(__OpenBSD__)
- HostOs = "openbsd";
-#else
-#warning "Unrecognized host OS..."
- HostOs = "other";
-#endif
- Jim_SetGlobalVariableStr(interp, "ocd_HOSTOS",
- Jim_NewStringObj(interp, HostOs, strlen(HostOs)));
-
register_commands(context, NULL, command_builtin_handlers);
Jim_SetAssocData(interp, "context", NULL, context);