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.

Signed-off-by: Zachary T Welch <[email protected]>
---
 src/helper/command.c |   20 ++++++++++++++++++++
 src/helper/command.h |   14 ++++++++++++++
 2 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/src/helper/command.c b/src/helper/command.c
index 3df60b6..29e645b 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -302,6 +302,26 @@ struct command* register_command(struct command_context 
*context,
        return c;
 }
 
+int register_commands(struct command_context *cmd_ctx,
+               struct command *parent, unsigned ncmds,
+               const struct command_registration *cmds)
+{
+       unsigned i;
+       for (i = 0; i < ncmds; i++)
+       {
+               struct command *c = register_command(cmd_ctx, parent, cmds + i);
+               if (NULL == c)
+                       break;
+       }
+       if (i == ncmds)
+               return ERROR_OK;
+
+       for (unsigned j = 0; j < i; j++)
+               unregister_command(cmd_ctx, parent, cmds[j].name);
+
+       return ERROR_FAIL;
+}
+
 int unregister_all_commands(struct command_context *context,
                struct command *parent)
 {
diff --git a/src/helper/command.h b/src/helper/command.h
index 14ad73e..b16361e 100644
--- a/src/helper/command.h
+++ b/src/helper/command.h
@@ -219,6 +219,20 @@ struct command_registration {
  */
 struct command* register_command(struct command_context *cmd_ctx,
                struct command *parent, const struct command_registration *rec);
+/**
+ * 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.
+ * @returns ERROR_OK on success; ERROR_FAIL if any registration fails.
+ */
+int register_commands(struct command_context *cmd_ctx,
+               struct command *parent, unsigned ncmds,
+               const struct command_registration *cmds);
 
 #define COMMAND_REGISTER(_cmd_ctx, _parent, _name, _handler, _mode, _help) \
        ({ \
-- 
1.6.4.4

_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to