command: check command mode for native jim commands
The command mode was checked only for simple type of commands. Native commands (handled by jim_handler) was treated as they had mode COMMAND_ANY Change-Id: Iab1d8cbb0b8c6f6b9f3cf942600432dec9a703ff Signed-off-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-on: http://openocd.zylin.com/4841 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>log_output
parent
d479020950
commit
877cec20dc
|
@ -579,13 +579,9 @@ char *command_name(struct command *c, char delim)
|
||||||
|
|
||||||
static bool command_can_run(struct command_context *cmd_ctx, struct command *c)
|
static bool command_can_run(struct command_context *cmd_ctx, struct command *c)
|
||||||
{
|
{
|
||||||
return c->mode == COMMAND_ANY || c->mode == cmd_ctx->mode;
|
if (c->mode == COMMAND_ANY || c->mode == cmd_ctx->mode)
|
||||||
}
|
return true;
|
||||||
|
|
||||||
static int run_command(struct command_context *context,
|
|
||||||
struct command *c, const char *words[], unsigned num_words)
|
|
||||||
{
|
|
||||||
if (!command_can_run(context, c)) {
|
|
||||||
/* Many commands may be run only before/after 'init' */
|
/* Many commands may be run only before/after 'init' */
|
||||||
const char *when;
|
const char *when;
|
||||||
switch (c->mode) {
|
switch (c->mode) {
|
||||||
|
@ -600,11 +596,19 @@ static int run_command(struct command_context *context,
|
||||||
when = "if Cthulhu is summoned by";
|
when = "if Cthulhu is summoned by";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
char *full_name = command_name(c, ' ');
|
||||||
LOG_ERROR("The '%s' command must be used %s 'init'.",
|
LOG_ERROR("The '%s' command must be used %s 'init'.",
|
||||||
c->name, when);
|
full_name ? full_name : c->name, when);
|
||||||
return ERROR_FAIL;
|
free(full_name);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int run_command(struct command_context *context,
|
||||||
|
struct command *c, const char *words[], unsigned num_words)
|
||||||
|
{
|
||||||
|
if (!command_can_run(context, c))
|
||||||
|
return ERROR_FAIL;
|
||||||
|
|
||||||
struct command_invocation cmd = {
|
struct command_invocation cmd = {
|
||||||
.ctx = context,
|
.ctx = context,
|
||||||
.current = c,
|
.current = c,
|
||||||
|
@ -1032,6 +1036,9 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
|
||||||
}
|
}
|
||||||
/* pass the command through to the intended handler */
|
/* pass the command through to the intended handler */
|
||||||
if (c->jim_handler) {
|
if (c->jim_handler) {
|
||||||
|
if (!command_can_run(cmd_ctx, c))
|
||||||
|
return ERROR_FAIL;
|
||||||
|
|
||||||
interp->cmdPrivData = c->jim_handler_data;
|
interp->cmdPrivData = c->jim_handler_data;
|
||||||
return (*c->jim_handler)(interp, count, start);
|
return (*c->jim_handler)(interp, count, start);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue