Doc fix: echo writes to the log, and not to stdout
[openocd.git] / src / helper / command.c
index 80e297b1f8baea7e5dd28761a11caad74971da82..8ea805bd9eb6e425748fd5070ab4cbf1efed65e4 100644 (file)
@@ -62,12 +62,12 @@ static inline bool jimcmd_is_proc(Jim_Cmd *cmd)
        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;
 }
@@ -83,17 +83,21 @@ static struct log_capture_state *command_log_capture_start(Jim_Interp *interp)
 {
        /* 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);
 
@@ -140,12 +144,13 @@ static void command_log_capture_finish(struct log_capture_state *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,
@@ -164,7 +169,7 @@ static int workaround_createcommand(Jim_Interp *interp, const char *cmdName,
        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)
@@ -256,7 +261,7 @@ static struct command *command_find_from_name(Jim_Interp *interp, const char *na
        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);
@@ -338,7 +343,8 @@ static struct command *register_command(struct command_context *context,
                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) {
@@ -436,8 +442,13 @@ int unregister_commands_match(struct command_context *cmd_ctx, const char *forma
                        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);
 
@@ -809,14 +820,13 @@ static COMMAND_HELPER(command_help_show, struct help_entry *c,
                ((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) {
@@ -856,9 +866,9 @@ static COMMAND_HELPER(command_help_show, struct help_entry *c,
                                        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);
@@ -1010,7 +1020,7 @@ static int jim_command_mode(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                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;
                }
@@ -1212,7 +1222,6 @@ static const struct command_registration command_builtin_handlers[] = {
                .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",
        },
@@ -1269,7 +1278,6 @@ static const struct command_registration command_builtin_handlers[] = {
 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;
 
@@ -1288,39 +1296,6 @@ struct command_context *command_init(const char *startup_tcl, Jim_Interp *interp
 
        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);

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)