]> git.sur5r.net Git - openocd/blobdiff - src/helper/command.c
found two more gaffes for reset wip
[openocd] / src / helper / command.c
index aa71f0ba18c1b2af47436423181638143ab0dd20..7a7cbcbb61932fecb8c3741e87881f50480dacfb 100644 (file)
@@ -142,10 +142,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 +267,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 +284,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 +298,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 +322,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 +332,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 +355,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 +380,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,10 +452,10 @@ 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];
-       int i;
        
        if (indent)
        {
@@ -473,12 +481,12 @@ 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)
 {
        command_t * c;
-       int i;
 
        for (c = c_first; c; c = c->next)
        {
@@ -572,12 +580,13 @@ int handle_sleep_command(struct command_context_s *cmd_ctx, char *cmd, char **ar
 
 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);
        
@@ -585,7 +594,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);