summaryrefslogtreecommitdiff
path: root/src/helper/command.c
diff options
context:
space:
mode:
authorZachary T Welch <zw@superlucidity.net>2009-11-20 11:23:34 -0800
committerZachary T Welch <zw@superlucidity.net>2009-11-24 21:37:29 -0800
commit69076057dde9f4336b54fb4da677da8fe5da66bd (patch)
tree839cc6881d7a8ed26c82635b640ebc9fe93c98ad /src/helper/command.c
parent833e7f5248778bcb31b4db1a1b91160995415203 (diff)
downloadopenocd+libswd-69076057dde9f4336b54fb4da677da8fe5da66bd.tar.gz
openocd+libswd-69076057dde9f4336b54fb4da677da8fe5da66bd.tar.bz2
openocd+libswd-69076057dde9f4336b54fb4da677da8fe5da66bd.tar.xz
openocd+libswd-69076057dde9f4336b54fb4da677da8fe5da66bd.zip
add struct command_registration
Add a structure to encapsulate command registration information, rather than passing them all as parameters. Enables further API changes that require additional required or optional parameters. Updates the register_command API and COMMAND_REGISTER macro to use it, along with their documentation.
Diffstat (limited to 'src/helper/command.c')
-rw-r--r--src/helper/command.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/helper/command.c b/src/helper/command.c
index 0561c6c5..3df60b65 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -263,13 +263,12 @@ static void command_free(struct command *c)
}
struct command* register_command(struct command_context *context,
- struct command *parent, const char *name,
- command_handler_t handler, enum command_mode mode,
- const char *help)
+ struct command *parent, const struct command_registration *cr)
{
- if (!context || !name)
+ if (!context || !cr->name)
return NULL;
+ const char *name = cr->name;
struct command **head = command_list_for_parent(context, parent);
struct command *c = command_find(*head, name);
if (NULL != c)
@@ -279,7 +278,7 @@ struct command* register_command(struct command_context *context,
return c;
}
- c = command_new(context, parent, name, handler, mode, help);
+ c = command_new(context, parent, name, cr->handler, cr->mode, cr->help);
/* if allocation failed or it is a placeholder (no handler), we're done */
if (NULL == c || NULL == c->handler)
return c;
@@ -762,8 +761,12 @@ int help_add_command(struct command_context *cmd_ctx, struct command *parent,
if (NULL == nc)
{
// add a new command with help text
- nc = register_command(cmd_ctx, parent, cmd_name,
- NULL, COMMAND_ANY, help_text);
+ struct command_registration cr = {
+ .name = cmd_name,
+ .mode = COMMAND_ANY,
+ .help = help_text,
+ };
+ nc = register_command(cmd_ctx, parent, &cr);
if (NULL == nc)
{
LOG_ERROR("failed to add '%s' help text", cmd_name);