add register_commands for batch registration
authorZachary T Welch <zw@superlucidity.net>
Fri, 20 Nov 2009 20:46:06 +0000 (12:46 -0800)
committerZachary T Welch <zw@superlucidity.net>
Wed, 25 Nov 2009 05:37:29 +0000 (21:37 -0800)
The register_commands API takes multiple commands in one call, allowing
modules to declare and pass a much simpler (and more explicit) array of
command_registration records.

src/helper/command.c
src/helper/command.h

index 3df60b65a9c02b6ed0d75d631eee256c4024e72d..51b3f9f54d1c96aeaeae61e367e220a15edee283 100644 (file)
@@ -302,6 +302,23 @@ struct command* register_command(struct command_context *context,
        return c;
 }
 
+int register_commands(struct command_context *cmd_ctx, struct command *parent,
+               const struct command_registration *cmds)
+{
+       unsigned i;
+       for (i = 0; cmds[i].name; i++)
+       {
+               struct command *c = register_command(cmd_ctx, parent, cmds + i);
+               if (NULL != c)
+                       continue;
+
+               for (unsigned j = 0; j < i; j++)
+                       unregister_command(cmd_ctx, parent, cmds[j].name);
+               return ERROR_FAIL;
+       }
+       return ERROR_OK;
+}
+
 int unregister_all_commands(struct command_context *context,
                struct command *parent)
 {
index b57ca75d85a3df6ea80cf22d855e2f747b4c19a5..1afaeeaa0617b7d168e3fc40dcea1f276faf4c11 100644 (file)
@@ -201,6 +201,9 @@ struct command_registration {
        const char *help;
 };
 
+/// Use this as the last entry in an array of command_registration records.
+#define COMMAND_REGISTRATION_DONE { .name = NULL }
+
 /**
  * Register a command @c handler that can be called from scripts during
  * the execution @c mode specified.
@@ -230,6 +233,22 @@ struct command* register_command(struct command_context *cmd_ctx,
                register_command(_cmd_ctx, _parent, &cr); \
        })
 
+/**
+ * Register one or more commands in the specified context, as children
+ * of @c parent (or top-level commends, if NULL).
+ *
+ * @param cmd_ctx The command_context in which to register the command.
+ * @param parent Register this command as a child of this, or NULL to
+ * register a top-level command.
+ * @param cmds Pointer to an array of command_registration records that
+ * contains the desired command parameters.  The last record must have
+ * NULL for all fields.
+ * @returns ERROR_OK on success; ERROR_FAIL if any registration fails.
+ */
+int register_commands(struct command_context *cmd_ctx, struct command *parent,
+               const struct command_registration *cmds);
+
+
 /**
  * Unregisters command @c name from the given context, @c cmd_ctx.
  * @param cmd_ctx The context of the registered 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)