This is an automated email from Gerrit.

Antonio Borneo ([email protected]) just uploaded a new patch set to 
Gerrit, which you can find at http://openocd.zylin.com/5668

-- gerrit

commit f6118595b1d94bff3a3d350f348b9ded77eed79f
Author: Antonio Borneo <[email protected]>
Date:   Sun May 10 19:35:56 2020 +0200

    helper/command: pass command prefix to command registration
    
    Replace the "struct command *parent" parameter with a string that
    contains the command prefix.
    This abstracts the openocd code from the knowledge of the tree of
    struct command.
    This also makes unused the function command_find_in_context(), so
    remove it.
    
    Change-Id: I598d60719cfdc1811ee6f6edfff8a116f82c7ed6
    Signed-off-by: Antonio Borneo <[email protected]>

diff --git a/src/flash/nand/tcl.c b/src/flash/nand/tcl.c
index 5480e0d..8a6c3bd 100644
--- a/src/flash/nand/tcl.c
+++ b/src/flash/nand/tcl.c
@@ -479,8 +479,8 @@ static int nand_init(struct command_context *cmd_ctx)
 {
        if (!nand_devices)
                return ERROR_OK;
-       struct command *parent = command_find_in_context(cmd_ctx, "nand");
-       return register_commands(cmd_ctx, parent, nand_exec_command_handlers);
+
+       return register_commands(cmd_ctx, "nand", nand_exec_command_handlers);
 }
 
 COMMAND_HANDLER(handle_nand_init_command)
diff --git a/src/flash/nor/esirisc_flash.c b/src/flash/nor/esirisc_flash.c
index 3bed065..b30f84b 100644
--- a/src/flash/nor/esirisc_flash.c
+++ b/src/flash/nor/esirisc_flash.c
@@ -109,7 +109,6 @@ static const struct command_registration 
esirisc_flash_command_handlers[];
 FLASH_BANK_COMMAND_HANDLER(esirisc_flash_bank_command)
 {
        struct esirisc_flash_bank *esirisc_info;
-       struct command *esirisc_cmd;
 
        if (CMD_ARGC < 9)
                return ERROR_COMMAND_SYNTAX_ERROR;
@@ -123,8 +122,7 @@ FLASH_BANK_COMMAND_HANDLER(esirisc_flash_bank_command)
        bank->driver_priv = esirisc_info;
 
        /* register commands using existing esirisc context */
-       esirisc_cmd = command_find_in_context(CMD_CTX, "esirisc");
-       register_commands(CMD_CTX, esirisc_cmd, esirisc_flash_command_handlers);
+       register_commands(CMD_CTX, "esirisc", esirisc_flash_command_handlers);
 
        return ERROR_OK;
 }
diff --git a/src/flash/nor/tcl.c b/src/flash/nor/tcl.c
index fb2053b..b1aab56 100644
--- a/src/flash/nor/tcl.c
+++ b/src/flash/nor/tcl.c
@@ -1190,8 +1190,7 @@ static int flash_init_drivers(struct command_context 
*cmd_ctx)
        if (!flash_bank_list())
                return ERROR_OK;
 
-       struct command *parent = command_find_in_context(cmd_ctx, "flash");
-       return register_commands(cmd_ctx, parent, flash_exec_command_handlers);
+       return register_commands(cmd_ctx, "flash", flash_exec_command_handlers);
 }
 
 COMMAND_HANDLER(handle_flash_bank_command)
diff --git a/src/helper/command.c b/src/helper/command.c
index 8b84b44..d9a021c 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -210,12 +210,6 @@ static struct command *command_find(struct command *head, 
const char *name)
        return NULL;
 }
 
-struct command *command_find_in_context(struct command_context *cmd_ctx,
-       const char *name)
-{
-       return command_find(cmd_ctx->commands, name);
-}
-
 /**
  * Add the command into the linked list, sorted by name.
  * @param head Address to head of command list pointer, which may be
@@ -355,7 +349,7 @@ static struct command *register_command(struct 
command_context *context,
        return c;
 }
 
-int __register_commands(struct command_context *cmd_ctx, struct command 
*parent,
+static int ___register_commands(struct command_context *cmd_ctx, struct 
command *parent,
        const struct command_registration *cmds, void *data,
        struct target *override_target)
 {
@@ -376,7 +370,7 @@ int __register_commands(struct command_context *cmd_ctx, 
struct command *parent,
                }
                if (NULL != cr->chain) {
                        struct command *p = c ? : parent;
-                       retval = __register_commands(cmd_ctx, p, cr->chain, 
data, override_target);
+                       retval = ___register_commands(cmd_ctx, p, cr->chain, 
data, override_target);
                        if (ERROR_OK != retval)
                                break;
                }
@@ -388,6 +382,18 @@ int __register_commands(struct command_context *cmd_ctx, 
struct command *parent,
        return retval;
 }
 
+int __register_commands(struct command_context *cmd_ctx, const char 
*cmd_prefix,
+       const struct command_registration *cmds, void *data,
+       struct target *override_target)
+{
+       struct command *parent = NULL;
+
+       if (cmd_prefix)
+               parent = command_find(cmd_ctx->commands, cmd_prefix);
+
+       return ___register_commands(cmd_ctx, parent, cmds, data, 
override_target);
+}
+
 int unregister_all_commands(struct command_context *context,
        struct command *parent)
 {
diff --git a/src/helper/command.h b/src/helper/command.h
index eb7b6fc..008dce5 100644
--- a/src/helper/command.h
+++ b/src/helper/command.h
@@ -231,7 +231,7 @@ struct command_registration {
 /** Use this as the last entry in an array of command_registration records. */
 #define COMMAND_REGISTRATION_DONE { .name = NULL, .chain = NULL }
 
-int __register_commands(struct command_context *cmd_ctx, struct command 
*parent,
+int __register_commands(struct command_context *cmd_ctx, const char 
*cmd_prefix,
                const struct command_registration *cmds, void *data,
                struct target *override_target);
 
@@ -243,17 +243,17 @@ int __register_commands(struct command_context *cmd_ctx, 
struct command *parent,
  * Otherwise, the chained commands are added as children of the command.
  *
  * @param cmd_ctx The command_context in which to register the command.
- * @param parent Register this command as a child of this, or NULL to
+ * @param cmd_prefix Register this command as a child of this, or NULL to
  * register a top-level command.
  * @param cmds Pointer to an array of command_registration records that
  * contains the desired command parameters.  The last record must have
  * NULL for all fields.
  * @returns ERROR_OK on success; ERROR_FAIL if any registration fails.
  */
-static inline int register_commands(struct command_context *cmd_ctx, struct 
command *parent,
+static inline int register_commands(struct command_context *cmd_ctx, const 
char *cmd_prefix,
                const struct command_registration *cmds)
 {
-       return __register_commands(cmd_ctx, parent, cmds, NULL, NULL);
+       return __register_commands(cmd_ctx, cmd_prefix, cmds, NULL, NULL);
 }
 
 /**
@@ -261,7 +261,7 @@ static inline int register_commands(struct command_context 
*cmd_ctx, struct comm
  * that command should override the current target
  *
  * @param cmd_ctx The command_context in which to register the command.
- * @param parent Register this command as a child of this, or NULL to
+ * @param cmd_prefix Register this command as a child of this, or NULL to
  * register a top-level command.
  * @param cmds Pointer to an array of command_registration records that
  * contains the desired command parameters.  The last record must have
@@ -270,10 +270,10 @@ static inline int register_commands(struct 
command_context *cmd_ctx, struct comm
  * @returns ERROR_OK on success; ERROR_FAIL if any registration fails.
  */
 static inline int register_commands_override_target(struct command_context 
*cmd_ctx,
-               struct command *parent, const struct command_registration *cmds,
+               const char *cmd_prefix, const struct command_registration *cmds,
                struct target *target)
 {
-       return __register_commands(cmd_ctx, parent, cmds, NULL, target);
+       return __register_commands(cmd_ctx, cmd_prefix, cmds, NULL, target);
 }
 
 /**
@@ -283,7 +283,7 @@ static inline int register_commands_override_target(struct 
command_context *cmd_
  * is unregistered.
  *
  * @param cmd_ctx The command_context in which to register the command.
- * @param parent Register this command as a child of this, or NULL to
+ * @param cmd_prefix Register this command as a child of this, or NULL to
  * register a top-level command.
  * @param cmds Pointer to an array of command_registration records that
  * contains the desired command parameters.  The last record must have
@@ -292,10 +292,10 @@ static inline int 
register_commands_override_target(struct command_context *cmd_
  * @returns ERROR_OK on success; ERROR_FAIL if any registration fails.
  */
 static inline int register_commands_with_data(struct command_context *cmd_ctx,
-               struct command *parent, const struct command_registration *cmds,
+               const char *cmd_prefix, const struct command_registration *cmds,
                void *data)
 {
-       return __register_commands(cmd_ctx, parent, cmds, data, NULL);
+       return __register_commands(cmd_ctx, cmd_prefix, cmds, data, NULL);
 }
 
 /**
@@ -307,9 +307,6 @@ static inline int register_commands_with_data(struct 
command_context *cmd_ctx,
 int unregister_all_commands(struct command_context *cmd_ctx,
                struct command *parent);
 
-struct command *command_find_in_context(struct command_context *cmd_ctx,
-               const char *name);
-
 void command_set_output_handler(struct command_context *context,
                command_output_handler_t output_handler, void *priv);
 
diff --git a/src/pld/pld.c b/src/pld/pld.c
index ef7993c..9e8c07d 100644
--- a/src/pld/pld.c
+++ b/src/pld/pld.c
@@ -187,8 +187,7 @@ static int pld_init(struct command_context *cmd_ctx)
        if (!pld_devices)
                return ERROR_OK;
 
-       struct command *parent = command_find_in_context(cmd_ctx, "pld");
-       return register_commands(cmd_ctx, parent, pld_exec_command_handlers);
+       return register_commands(cmd_ctx, "pld", pld_exec_command_handlers);
 }
 
 COMMAND_HANDLER(handle_pld_init_command)
diff --git a/src/target/etm.c b/src/target/etm.c
index 5218a9e..f8bb8b8 100644
--- a/src/target/etm.c
+++ b/src/target/etm.c
@@ -2116,6 +2116,5 @@ static const struct command_registration 
etm_exec_command_handlers[] = {
 
 static int etm_register_user_commands(struct command_context *cmd_ctx)
 {
-       struct command *etm_cmd = command_find_in_context(cmd_ctx, "etm");
-       return register_commands(cmd_ctx, etm_cmd, etm_exec_command_handlers);
+       return register_commands(cmd_ctx, "etm", etm_exec_command_handlers);
 }

-- 


_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to