fix broken -c/f options where it would silently terminate for scripts that did not...
[openocd.git] / src / helper / command.c
index cccf60e560b367b929177d19882e34326f236d1d..bc1fb348941681918bb12d58c655400967169046 100644 (file)
@@ -229,9 +229,9 @@ command_t* register_command(command_context_t *context, command_t *parent, char
        free((void *)override_name);
 
        /* accumulate help text in Tcl helptext list.  */
-    Jim_Obj *helptext=Jim_GetGlobalVariableStr(interp, "ocd_helptext", JIM_ERRMSG);
-    if (Jim_IsShared(helptext))
-        helptext = Jim_DuplicateObj(interp, helptext);
+       Jim_Obj *helptext=Jim_GetGlobalVariableStr(interp, "ocd_helptext", JIM_ERRMSG);
+       if (Jim_IsShared(helptext))
+               helptext = Jim_DuplicateObj(interp, helptext);
        Jim_Obj *cmd_entry=Jim_NewListObj(interp, NULL, 0);
 
        Jim_Obj *cmd_list=Jim_NewListObj(interp, NULL, 0);
@@ -289,7 +289,9 @@ int unregister_command(command_context_t *context, char *name)
                return ERROR_INVALID_ARGUMENTS;
 
        /* find command */
-       for (c = context->commands; c; c = c->next)
+       c = context->commands;
+
+       while(NULL != c)
        {
                if (strcmp(name, c->name) == 0)
                {
@@ -300,26 +302,32 @@ int unregister_command(command_context_t *context, char *name)
                        }
                        else
                        {
+                               /* first element in command list */
                                context->commands = c->next;
                        }
 
                        /* unregister children */
-                       if (c->children)
+                       while(NULL != c->children)
                        {
-                               for (c2 = c->children; c2; c2 = c2->next)
-                               {
-                                       free(c2->name);
-                                       free(c2);
-                               }
+                               c2 = c->children;
+                               c->children = c->children->next;
+                               free(c2->name);
+                               c2->name = NULL;
+                               free(c2);
+                               c2 = NULL;
                        }
 
                        /* delete command */
                        free(c->name);
+                       c->name = NULL;
                        free(c);
+                       c = NULL;
+                       return ERROR_OK;
                }
 
                /* remember the last command for unlinking */
                p = c;
+               c = c->next;
        }
 
        return ERROR_OK;
@@ -348,8 +356,8 @@ void command_print_n(command_context_t *context, char *format, ...)
                 * The latter bit isn't precisely neat, but will do for now.
                 */
                LOG_USER_N("%s", string);
-               // We already printed it above
-               //command_output_text(context, string);
+               /* We already printed it above */
+               /* command_output_text(context, string); */
                free(string);
        }
 
@@ -373,8 +381,8 @@ void command_print(command_context_t *context, char *format, ...)
                 * The latter bit isn't precisely neat, but will do for now.
                 */
                LOG_USER_N("%s", string);
-               // We already printed it above
-               //command_output_text(context, string);
+               /* We already printed it above */
+               /* command_output_text(context, string); */
                free(string);
        }
 
@@ -471,21 +479,20 @@ int command_run_line(command_context_t *context, char *line)
                int reslen;
 
                result = Jim_GetString(Jim_GetResult(interp), &reslen);
-               if (reslen) {
-                       int i;
-                       char buff[256+1];
-                       for (i = 0; i < reslen; i += 256)
-                       {
-                               int chunk;
-                               chunk = reslen - i;
-                               if (chunk > 256)
-                                       chunk = 256;
-                               strncpy(buff, result+i, chunk);
-                               buff[chunk] = 0;
-                               LOG_USER_N("%s", buff);
-                       }
-                       LOG_USER_N("%s", "\n");
+               int i;
+               char buff[256+1];
+               for (i = 0; i < reslen; i += 256)
+               {
+                       int chunk;
+                       chunk = reslen - i;
+                       if (chunk > 256)
+                               chunk = 256;
+                       strncpy(buff, result+i, chunk);
+                       buff[chunk] = 0;
+                       LOG_USER_N("%s", buff);
                }
+               LOG_USER_N("%s", "\n");
+               retval=ERROR_OK;
        }
        return retval;
 }
@@ -636,7 +643,6 @@ static char* openocd_jim_fgets(char *s, int size, void *cookie)
        return NULL;
 }
 
-
 static int jim_capture(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 {
        if (argc != 2)
@@ -793,7 +799,7 @@ void register_jim(struct command_context_s *cmd_ctx, const char *name, int (*cmd
        Jim_CreateCommand(interp, name, cmd, NULL, NULL);
 
        /* FIX!!! it would be prettier to invoke add_help_text...
-          accumulate help text in Tcl helptext list.  */
+        * accumulate help text in Tcl helptext list.  */
        Jim_Obj *helptext=Jim_GetGlobalVariableStr(interp, "ocd_helptext", JIM_ERRMSG);
        if (Jim_IsShared(helptext))
                helptext = Jim_DuplicateObj(interp, helptext);
@@ -808,7 +814,6 @@ void register_jim(struct command_context_s *cmd_ctx, const char *name, int (*cmd
        Jim_ListAppendElement(interp, helptext, cmd_entry);
 }
 
-
 /* return global variable long value or 0 upon failure */
 long jim_global_long(const char *variable)
 {

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)