summaryrefslogtreecommitdiff
path: root/src/helper/command.c
diff options
context:
space:
mode:
authorZachary T Welch <zw@superlucidity.net>2009-11-23 15:03:04 -0800
committerZachary T Welch <zw@superlucidity.net>2009-11-24 21:37:37 -0800
commit17a9dea53a71e9d7e241262725f3dd707b620d37 (patch)
tree863bbe082bfb4eeb61dcab0b952de506703391d6 /src/helper/command.c
parentcd7e76ebf0e09466aeb3c61498360c45a1a3ad39 (diff)
downloadopenocd+libswd-17a9dea53a71e9d7e241262725f3dd707b620d37.tar.gz
openocd+libswd-17a9dea53a71e9d7e241262725f3dd707b620d37.tar.bz2
openocd+libswd-17a9dea53a71e9d7e241262725f3dd707b620d37.tar.xz
openocd+libswd-17a9dea53a71e9d7e241262725f3dd707b620d37.zip
add jim_handler to command_registration
Adding jim_handler field to command_registration allows removing the register_jim helper. All command registrations now go through the register_command{,s}() functions.
Diffstat (limited to 'src/helper/command.c')
-rw-r--r--src/helper/command.c42
1 files changed, 22 insertions, 20 deletions
diff --git a/src/helper/command.c b/src/helper/command.c
index 8d710c99..3cb36ea2 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -252,6 +252,8 @@ static struct command *command_new(struct command_context *cmd_ctx,
c->usage = strdup(cr->usage);
c->parent = parent;
c->handler = cr->handler;
+ c->jim_handler = cr->jim_handler;
+ c->jim_handler_data = cr->jim_handler_data;
c->mode = cr->mode;
command_add_child(command_list_for_parent(cmd_ctx, parent), c);
@@ -327,16 +329,22 @@ struct command* register_command(struct command_context *context,
}
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;
+ if (NULL == c)
+ return NULL;
- int retval = register_command_handler(c);
- if (ERROR_OK != retval)
+ if (NULL != c->handler)
{
- unregister_command(context, parent, name);
- c = NULL;
+ int retval = register_command_handler(c);
+ if (ERROR_OK != retval)
+ {
+ unregister_command(context, parent, name);
+ return NULL;
+ }
}
+
+ if (NULL != cr->jim_handler && NULL == parent)
+ Jim_CreateCommand(interp, cr->name, cr->jim_handler, cr->jim_handler_data, NULL);
+
return c;
}
@@ -882,7 +890,7 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
bool found = true;
Jim_Obj *const *start;
unsigned count;
- if (c->handler)
+ if (c->handler || c->jim_handler)
{
// include the command name in the list
count = remaining + 1;
@@ -900,6 +908,12 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
start = argv;
found = false;
}
+ // pass the command through to the intended handler
+ if (c->jim_handler)
+ {
+ interp->cmdPrivData = c->jim_handler_data;
+ return (*c->jim_handler)(interp, count, start);
+ }
unsigned nwords;
const char **words = script_command_args_alloc(count, start, &nwords);
@@ -1149,18 +1163,6 @@ void process_jim_events(void)
#endif
}
-void register_jim(struct command_context *cmd_ctx, const char *name,
- Jim_CmdProc cmd, const char *help)
-{
- Jim_CreateCommand(interp, name, cmd, NULL, NULL);
-
- Jim_Obj *cmd_list = Jim_NewListObj(interp, NULL, 0);
- Jim_ListAppendElement(interp, cmd_list,
- Jim_NewStringObj(interp, name, -1));
-
- help_add_command(cmd_ctx, NULL, name, help, NULL);
-}
-
#define DEFINE_PARSE_NUM_TYPE(name, type, func, min, max) \
int parse##name(const char *str, type *ul) \
{ \