Jim_Interp *interp = NULL;
static int run_command(command_context_t *context,
- command_t *c, char *words[], unsigned num_words);
+ command_t *c, const char *words[], unsigned num_words);
static void tcl_output(void *privData, const char *file, unsigned line,
const char *function, const char *string)
script_debug(interp, c->name, argc, argv);
- words = malloc(sizeof(char *) * argc);
+ words = malloc(sizeof(char *) * (argc + 1));
+ words[0] = c->name;
for (i = 0; i < argc; i++)
{
int len;
/* hit an end of line comment */
break;
}
- words[i] = strdup(w);
- if (words[i] == NULL)
+ words[i + 1] = strdup(w);
+ if (words[i + 1] == NULL)
{
int j;
for (j = 0; j < i; j++)
- free(words[j]);
+ free(words[j + 1]);
free(words);
return JIM_ERR;
}
log_add_callback(tcl_output, tclOutput);
- retval = run_command(context, c, words, nwords);
+ // turn words[0] into args[-1] with this cast
+ retval = run_command(context, c, (const char **)words + 1, nwords);
log_remove_callback(tcl_output, tclOutput);
Jim_DecrRefCount(interp, tclOutput);
for (i = 0; i < nwords; i++)
- free(words[i]);
+ free(words[i + 1]);
free(words);
int *return_retval = Jim_GetAssocData(interp, "retval");
}
static int run_command(command_context_t *context,
- command_t *c, char *words[], unsigned num_words)
+ command_t *c, const char *words[], unsigned num_words)
{
int start_word = 0;
if (!((context->mode == COMMAND_CONFIG) || (c->mode == COMMAND_ANY) || (c->mode == context->mode)))
return ERROR_FAIL;
}
- int retval = c->handler(context, c->name, words + start_word + 1, num_words - start_word - 1);
+ unsigned argc = num_words - start_word - 1;
+ const char **args = words + start_word + 1;
+ int retval = c->handler(context, args, argc);
if (retval == ERROR_COMMAND_SYNTAX_ERROR)
{
/* Print help for command */
/* sleep command sleeps for <n> miliseconds
* this is useful in target startup scripts
*/
-static int handle_sleep_command(struct command_context_s *cmd_ctx,
- char *cmd, char **args, int argc)
+COMMAND_HANDLER(handle_sleep_command)
{
bool busy = false;
if (argc == 2)
return ERROR_OK;
}
-static int handle_fast_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+COMMAND_HANDLER(handle_fast_command)
{
if (argc != 1)
return ERROR_COMMAND_SYNTAX_ERROR;