int unregister_command(command_context_t *context, char *name)
{
- unique_length_dirty = 1;
-
command_t *c, *p = NULL, *c2;
+ unique_length_dirty = 1;
+
if ((!context) || (!name))
return ERROR_INVALID_ARGUMENTS;
va_list ap;
va_start(ap, format);
- string = alloc_printf(format, ap);
+ string = alloc_vprintf(format, ap);
if (string != NULL)
{
context->output_handler(context, string);
va_list ap;
va_start(ap, format);
- string = alloc_printf(format, ap);
+ string = alloc_vprintf(format, ap);
if (string != NULL)
{
- strcat(string, "\n"); /* alloc_printf guaranteed the buffer to be at least one char longer */
+ strcat(string, "\n"); /* alloc_vprintf guaranteed the buffer to be at least one char longer */
context->output_handler(context, string);
free(string);
}
int find_and_run_command(command_context_t *context, command_t *commands, char *words[], int num_words, int start_word)
{
command_t *c;
+ int retval = ERROR_COMMAND_SYNTAX_ERROR;
if (unique_length_dirty)
{
if (!c->handler)
{
command_print(context, "No handler for command");
+ retval = ERROR_COMMAND_SYNTAX_ERROR;
break;
}
else
{
command_print(context, "Syntax error:");
command_print_help_line(context, c, 0);
+ } else if (retval != ERROR_OK)
+ {
+ /* we do not print out an error message because the command *should*
+ * have printed out an error
+ */
+ LOG_DEBUG("Command failed with error code %d", retval);
}
return retval;
}
}
command_print(context, "Command %s not found", words[start_word]);
- return ERROR_OK;
+ return retval;
}
int command_run_line(command_context_t *context, char *line)
if (*line && (line[0] == '#'))
return ERROR_OK;
- DEBUG("%s", line);
+ LOG_DEBUG("%s", line);
nwords = parse_line(line, words, sizeof(words) / sizeof(words[0]));
void command_print_help_line(command_context_t* context, struct command_s *command, int indent)
{
command_t *c;
- char indent_text[indent + 2];
+ char *indent_text=malloc(indent + 2);
+
char *help = "no help available";
char name_buf[64];
command_print_help_line(context, c, indent + 1);
}
}
+ free(indent_text);
}
int command_print_help_match(command_context_t* context, command_t* c_first, char* name, char** args, int argc)
int handle_time_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
- if (argc<1)
- return ERROR_COMMAND_SYNTAX_ERROR;
-
duration_t duration;
char *duration_text;
int retval;
+ float t;
+
+ if (argc<1)
+ return ERROR_COMMAND_SYNTAX_ERROR;
duration_start_measure(&duration);
duration_stop_measure(&duration, &duration_text);
- float t=duration.duration.tv_sec;
+ t=duration.duration.tv_sec;
t+=((float)duration.duration.tv_usec / 1000000.0);
command_print(cmd_ctx, "%s took %fs", args[0], t);