[PATCH 13/22] shell: Simplify rtems_shell_add_cmd_struct()

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Nov 18 14:37:19 UTC 2014


---
 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 23125b8..e291e74 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;
 }
 
-- 
1.8.4.5




More information about the devel mailing list