command mode: return "any" for tcl proc 69/5669/6
authorAntonio Borneo <borneo.antonio@gmail.com>
Sat, 9 May 2020 00:00:45 +0000 (02:00 +0200)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sun, 18 Apr 2021 14:33:37 +0000 (15:33 +0100)
A tcl proc can be executed anytime, in any command mode.

Let the command "command mode" to detect a tcl proc and return the
string "any".

Change-Id: I0559076c3063632ee0ea9a57a25f91060209b77f
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5669
Tested-by: jenkins
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
src/helper/command.c

index 114d0732866a8cd1f3a1db26acb2b65d88571e43..288ba99aa874ba53518e40eb64ab8dfb98757d6f 100644 (file)
@@ -53,6 +53,12 @@ static int unregister_command(struct command_context *context,
        struct command *parent, const char *name);
 static char *command_name(struct command *c, char delim);
 
+/* wrap jimtcl internal data */
+static inline bool jimcmd_is_proc(Jim_Cmd *cmd)
+{
+       return cmd->isproc;
+}
+
 static void tcl_output(void *privData, const char *file, unsigned line,
        const char *function, const char *string)
 {
@@ -1076,6 +1082,18 @@ static int jim_command_mode(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        enum command_mode mode;
 
        if (argc > 1) {
+               char *full_name = alloc_concatenate_strings(argc - 1, argv + 1);
+               if (!full_name)
+                       return JIM_ERR;
+               Jim_Obj *s = Jim_NewStringObj(interp, full_name, -1);
+               Jim_IncrRefCount(s);
+               Jim_Cmd *cmd = Jim_GetCommand(interp, s, JIM_NONE);
+               Jim_DecrRefCount(interp, s);
+               free(full_name);
+               if (cmd && jimcmd_is_proc(cmd)) {
+                       Jim_SetResultString(interp, "any", -1);
+                       return JIM_OK;
+               }
                struct command *c = cmd_ctx->commands;
                int remaining = command_unknown_find(argc - 1, argv + 1, c, &c);
                /* if nothing could be consumed, then it's an unknown command */

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)