add jim_handler to command_registration
[openocd.git] / src / helper / command.c
index 8d710c9986e465beb6b80214e1515994aeed377e..3cb36ea27590850c4f18131f10d265604b6af7d4 100644 (file)
@@ -252,6 +252,8 @@ static struct command *command_new(struct command_context *cmd_ctx,
                c->usage = strdup(cr->usage);
        c->parent = parent;
        c->handler = cr->handler;
                c->usage = strdup(cr->usage);
        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);
        c->mode = cr->mode;
 
        command_add_child(command_list_for_parent(cmd_ctx, parent), c);
@@ -327,16 +329,22 @@ struct command* register_command(struct command_context *context,
        }
 
        c = command_new(context, parent, cr);
        }
 
        c = command_new(context, parent, cr);
-       /* if allocation failed or it is a placeholder (no handler), we're done */
-       if (NULL == c || NULL == c->handler)
-               return c;
+       if (NULL == c)
+               return NULL;
 
 
-       int retval = register_command_handler(c);
-       if (ERROR_OK != retval)
+       if (NULL != c->handler)
        {
        {
-               unregister_command(context, parent, name);
-               c = NULL;
+               int retval = register_command_handler(c);
+               if (ERROR_OK != retval)
+               {
+                       unregister_command(context, parent, name);
+                       return NULL;
+               }
        }
        }
+
+       if (NULL != cr->jim_handler && NULL == parent)
+               Jim_CreateCommand(interp, cr->name, cr->jim_handler, cr->jim_handler_data, NULL);
+
        return c;
 }
 
        return c;
 }
 
@@ -882,7 +890,7 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        bool found = true;
        Jim_Obj *const *start;
        unsigned count;
        bool found = true;
        Jim_Obj *const *start;
        unsigned count;
-       if (c->handler)
+       if (c->handler || c->jim_handler)
        {
                // include the command name in the list
                count = remaining + 1;
        {
                // include the command name in the list
                count = remaining + 1;
@@ -900,6 +908,12 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                start = argv;
                found = false;
        }
                start = argv;
                found = false;
        }
+       // pass the command through to the intended handler
+       if (c->jim_handler)
+       {
+               interp->cmdPrivData = c->jim_handler_data;
+               return (*c->jim_handler)(interp, count, start);
+       }
 
        unsigned nwords;
        const char **words = script_command_args_alloc(count, start, &nwords);
 
        unsigned nwords;
        const char **words = script_command_args_alloc(count, start, &nwords);
@@ -1149,18 +1163,6 @@ void process_jim_events(void)
 #endif
 }
 
 #endif
 }
 
-void register_jim(struct command_context *cmd_ctx, const char *name,
-               Jim_CmdProc cmd, const char *help)
-{
-       Jim_CreateCommand(interp, name, cmd, NULL, NULL);
-
-       Jim_Obj *cmd_list = Jim_NewListObj(interp, NULL, 0);
-       Jim_ListAppendElement(interp, cmd_list,
-                       Jim_NewStringObj(interp, name, -1));
-
-       help_add_command(cmd_ctx, NULL, name, help, NULL);
-}
-
 #define DEFINE_PARSE_NUM_TYPE(name, type, func, min, max) \
        int parse##name(const char *str, type *ul) \
        { \
 #define DEFINE_PARSE_NUM_TYPE(name, type, func, min, max) \
        int parse##name(const char *str, type *ul) \
        { \

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)