From 7a2c30faeef83e875f3b674a526a1a3806063eb0 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 17 Nov 2014 15:58:26 +0100 Subject: shell: Simplify rtems_shell_add_cmd_struct() --- cpukit/libmisc/shell/shell_cmdset.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/cpukit/libmisc/shell/shell_cmdset.c b/cpukit/libmisc/shell/shell_cmdset.c index 23125b84ad..e291e7449c 100644 --- a/cpukit/libmisc/shell/shell_cmdset.c +++ b/cpukit/libmisc/shell/shell_cmdset.c @@ -108,24 +108,25 @@ rtems_shell_cmd_t *rtems_shell_add_cmd_struct( rtems_shell_cmd_t *shell_cmd ) { - rtems_shell_cmd_t *shell_pvt; - - shell_pvt = rtems_shell_first_cmd; - while (shell_pvt) { - if (strcmp(shell_pvt->name, shell_cmd->name) == 0) + rtems_shell_cmd_t **next_ptr = &rtems_shell_first_cmd; + rtems_shell_cmd_t *existing; + + /* + * Iterate through all commands and check if a command with this name is + * already present. + */ + while ((existing = *next_ptr) != NULL) { + if (strcmp(existing->name, shell_cmd->name) == 0) return NULL; - shell_pvt = shell_pvt->next; - } - if ( !rtems_shell_first_cmd ) { - rtems_shell_first_cmd = shell_cmd; - } else { - shell_pvt = rtems_shell_first_cmd; - while (shell_pvt->next) - shell_pvt = shell_pvt->next; - shell_pvt->next = shell_cmd; + next_ptr = &existing->next; } + + /* Append */ + *next_ptr = shell_cmd; + rtems_shell_add_topic( shell_cmd->topic ); + return shell_cmd; } -- cgit v1.2.3