diff options
author | Zachary T Welch <zw@superlucidity.net> | 2009-11-23 15:01:12 -0800 |
---|---|---|
committer | Zachary T Welch <zw@superlucidity.net> | 2009-11-24 21:37:37 -0800 |
commit | cd7e76ebf0e09466aeb3c61498360c45a1a3ad39 (patch) | |
tree | 5fcd06410c32361cafc18921adfd8223380b86ae /src/helper | |
parent | f74e2e033a2ad082e5bef67d0ddedd1db3f58300 (diff) | |
download | openocd+libswd-cd7e76ebf0e09466aeb3c61498360c45a1a3ad39.tar.gz openocd+libswd-cd7e76ebf0e09466aeb3c61498360c45a1a3ad39.tar.bz2 openocd+libswd-cd7e76ebf0e09466aeb3c61498360c45a1a3ad39.tar.xz openocd+libswd-cd7e76ebf0e09466aeb3c61498360c45a1a3ad39.zip |
refactor command_new to use command_registration
Save stack space: use a struct. Makes it easier to add new parameters.
Diffstat (limited to 'src/helper')
-rw-r--r-- | src/helper/command.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/helper/command.c b/src/helper/command.c index dd109657..8d710c99 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -238,23 +238,21 @@ static struct command **command_list_for_parent( } static struct command *command_new(struct command_context *cmd_ctx, - struct command *parent, const char *name, - command_handler_t handler, enum command_mode mode, - const char *help, const char *usage) + struct command *parent, const struct command_registration *cr) { - assert(name); + assert(cr->name); struct command *c = malloc(sizeof(struct command)); memset(c, 0, sizeof(struct command)); - c->name = strdup(name); - if (help) - c->help = strdup(help); - if (usage) - c->usage = strdup(usage); + c->name = strdup(cr->name); + if (cr->help) + c->help = strdup(cr->help); + if (cr->usage) + c->usage = strdup(cr->usage); c->parent = parent; - c->handler = handler; - c->mode = mode; + c->handler = cr->handler; + c->mode = cr->mode; command_add_child(command_list_for_parent(cmd_ctx, parent), c); @@ -328,7 +326,7 @@ struct command* register_command(struct command_context *context, return c; } - c = command_new(context, parent, name, cr->handler, cr->mode, cr->help, cr->usage); + 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; |