summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2014-11-17 15:58:26 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2014-11-20 10:30:24 +0100
commit7a2c30faeef83e875f3b674a526a1a3806063eb0 (patch)
treec4a9fe21ff3c33ea64c2869c6d943cac375808bb
parentshell: Rename HALT to SHUTDOWN command (diff)
downloadrtems-7a2c30faeef83e875f3b674a526a1a3806063eb0.tar.bz2
shell: Simplify rtems_shell_add_cmd_struct()
-rw-r--r--cpukit/libmisc/shell/shell_cmdset.c29
1 files 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;
}