[rtems commit] shell: Simplify rtems_shell_add_cmd_struct()
Sebastian Huber
sebh at rtems.org
Thu Nov 20 13:53:25 UTC 2014
Module: rtems
Branch: master
Commit: 7a2c30faeef83e875f3b674a526a1a3806063eb0
Changeset: http://git.rtems.org/rtems/commit/?id=7a2c30faeef83e875f3b674a526a1a3806063eb0
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Mon Nov 17 15:58:26 2014 +0100
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 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;
}
More information about the vc
mailing list