X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Fhelper%2Fcommand.c;h=31666e3a798a1ac7e9f8167fe374ac7d8ca26589;hb=6510be8b8b0ffbe6c3d577625f7485775c69a99a;hp=5df12901566b85b545802b9ef27094a08a15070a;hpb=6d95014674415e3b9ea9d46d5148d3410f96bbfd;p=openocd.git diff --git a/src/helper/command.c b/src/helper/command.c index 5df1290156..31666e3a79 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -38,10 +38,13 @@ #include #include +int fast_and_dangerous = 0; + void command_print_help_line(command_context_t* context, struct command_s *command, int indent); int handle_sleep_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); int handle_time_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); +int handle_fast_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); int build_unique_lengths(command_context_t *context, command_t *commands) { @@ -142,10 +145,10 @@ command_t* register_command(command_context_t *context, command_t *parent, char 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; @@ -267,7 +270,7 @@ void command_print_n(command_context_t *context, char *format, ...) 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); @@ -284,10 +287,10 @@ void command_print(command_context_t *context, char *format, ...) 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); } @@ -298,6 +301,7 @@ void command_print(command_context_t *context, char *format, ...) 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) { @@ -321,6 +325,7 @@ int find_and_run_command(command_context_t *context, command_t *commands, char * if (!c->handler) { command_print(context, "No handler for command"); + retval = ERROR_COMMAND_SYNTAX_ERROR; break; } else @@ -330,6 +335,12 @@ int find_and_run_command(command_context_t *context, command_t *commands, char * { 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; } @@ -347,7 +358,7 @@ int find_and_run_command(command_context_t *context, command_t *commands, char * } 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) @@ -372,7 +383,7 @@ 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])); @@ -444,7 +455,8 @@ int command_run_file(command_context_t *context, FILE *file, enum command_mode m 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]; @@ -472,6 +484,7 @@ void command_print_help_line(command_context_t* context, struct command_s *comma 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) @@ -549,6 +562,9 @@ command_context_t* command_init() register_command(context, NULL, "time", handle_time_command, COMMAND_ANY, "time - execute and print time it took"); + register_command(context, NULL, "fast", handle_fast_command, + COMMAND_ANY, "fast - place at beginning of config files. Sets defaults to fast and dangerous."); + return context; } @@ -568,14 +584,26 @@ int handle_sleep_command(struct command_context_s *cmd_ctx, char *cmd, char **ar return ERROR_OK; } -int handle_time_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +int handle_fast_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) { - if (argc<1) + if (argc!=1) return ERROR_COMMAND_SYNTAX_ERROR; + fast_and_dangerous = strcmp("enable", args[0])==0; + + return ERROR_OK; +} + + +int handle_time_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +{ duration_t duration; char *duration_text; int retval; + float t; + + if (argc<1) + return ERROR_COMMAND_SYNTAX_ERROR; duration_start_measure(&duration); @@ -583,7 +611,7 @@ int handle_time_command(struct command_context_s *cmd_ctx, char *cmd, char **arg 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);