summaryrefslogtreecommitdiff
path: root/src/helper/command.c
diff options
context:
space:
mode:
authorZachary T Welch <zw@superlucidity.net>2009-11-21 13:59:51 -0800
committerZachary T Welch <zw@superlucidity.net>2009-11-24 21:37:30 -0800
commit60ba4641d61ba65943ac7a8c800e82d6665ee11f (patch)
tree8670f3bfebaefd2c62c948292da9f0991dc39bc5 /src/helper/command.c
parent607634f967cf25630860794847dea770eb17a8f4 (diff)
downloadopenocd+libswd-60ba4641d61ba65943ac7a8c800e82d6665ee11f.tar.gz
openocd+libswd-60ba4641d61ba65943ac7a8c800e82d6665ee11f.tar.bz2
openocd+libswd-60ba4641d61ba65943ac7a8c800e82d6665ee11f.tar.xz
openocd+libswd-60ba4641d61ba65943ac7a8c800e82d6665ee11f.zip
add command registration chaining
Adds the ability to chain registration structures. Modules can define a command with the 'chain' and 'num_chain' fields defined in their registration table, and the register_commands() function will initialize these commands. If the registration record creates a new command, then the chained commands are created under it; otherwise, they are created in the same context as the other commands (i.e. the parent argument).
Diffstat (limited to 'src/helper/command.c')
-rw-r--r--src/helper/command.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/helper/command.c b/src/helper/command.c
index 9cc996c2..b81d2d19 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -331,18 +331,36 @@ struct command* register_command(struct command_context *context,
int register_commands(struct command_context *cmd_ctx, struct command *parent,
const struct command_registration *cmds)
{
+ int retval = ERROR_OK;
unsigned i;
- for (i = 0; cmds[i].name; i++)
+ for (i = 0; cmds[i].name || cmds[i].chain; i++)
{
- struct command *c = register_command(cmd_ctx, parent, cmds + i);
- if (NULL != c)
- continue;
+ const struct command_registration *cr = cmds + i;
+ struct command *c = NULL;
+ if (NULL != cr->name)
+ {
+ c = register_command(cmd_ctx, parent, cr);
+ if (NULL == c)
+ {
+ retval = ERROR_FAIL;
+ break;
+ }
+ }
+ if (NULL != cr->chain)
+ {
+ struct command *p = c ? : parent;
+ retval = register_commands(cmd_ctx, p, cr->chain);
+ if (ERROR_OK != retval)
+ break;
+ }
+ }
+ if (ERROR_OK != retval)
+ {
for (unsigned j = 0; j < i; j++)
unregister_command(cmd_ctx, parent, cmds[j].name);
- return ERROR_FAIL;
}
- return ERROR_OK;
+ return retval;
}
int unregister_all_commands(struct command_context *context,