X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Fhelper%2Fcommand.c;h=968a8e4b7eeb0c2dcd785e3cf41b0659919619f4;hb=d52d7f69beb2b313d92c79e45b5d71a1729e43a4;hp=ec7cc6bb7cd2e962d2f9b95ddcd0cc39ae6629eb;hpb=2585fc34200938fb3fa55a450ea37f68012aafa7;p=openocd.git diff --git a/src/helper/command.c b/src/helper/command.c index ec7cc6bb7c..968a8e4b7e 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) { @@ -140,6 +143,45 @@ command_t* register_command(command_context_t *context, command_t *parent, char return c; } +int unregister_all_commands(command_context_t *context) +{ + command_t *c, *c2; + + unique_length_dirty = 1; + + if (context == NULL) + return ERROR_OK; + + + while(NULL != context->commands) + { + c = context->commands; + + while(NULL != c->children) + { + c2 = c->children; + c->children = c->children->next; + free(c2->name); + c2->name = NULL; + free(c2->help); + c2->help = NULL; + free(c2); + c2 = NULL; + } + + context->commands = context->commands->next; + + free(c->name); + c->name = NULL; + free(c->help); + c->help = NULL; + free(c); + c = NULL; + } + + return ERROR_OK; +} + int unregister_command(command_context_t *context, char *name) { command_t *c, *p = NULL, *c2; @@ -332,7 +374,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) + } + else if (retval == ERROR_COMMAND_CLOSE_CONNECTION) + { + /* just fall through for a shutdown request */ + } + else if (retval != ERROR_OK) { /* we do not print out an error message because the command *should* * have printed out an error @@ -364,6 +411,8 @@ int command_run_line(command_context_t *context, char *line) char *words[128] = {0}; int retval; int i; + + LOG_USER_N("%s", ""); /* Keep GDB connection alive*/ if ((!context) || (!line)) return ERROR_INVALID_ARGUMENTS; @@ -452,11 +501,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; - #ifdef HAVE_C_VARRAYS - char indent_text[indent + 2]; - #else - char indent_text[68]; - #endif + char *indent_text=malloc(indent + 2); + char *help = "no help available"; char name_buf[64]; @@ -484,6 +530,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) @@ -518,7 +565,6 @@ int command_print_help(command_context_t* context, char* name, char** args, int return command_print_help_match(context, context->commands, name, args, argc); } - void command_set_output_handler(command_context_t* context, int (*output_handler)(struct command_context_s *context, char* line), void *priv) { context->output_handler = output_handler; @@ -561,6 +607,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; } @@ -580,6 +629,17 @@ int handle_sleep_command(struct command_context_s *cmd_ctx, char *cmd, char **ar return ERROR_OK; } +int handle_fast_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +{ + 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;