summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc/shell/shell_cmdset.c
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2007-12-12 10:10:38 +0000
committerChris Johns <chrisj@rtems.org>2007-12-12 10:10:38 +0000
commit06bd7c74b111323995ebd9167f472b610e46b551 (patch)
tree77f3741e7208882f1e21484eca0dd103767f094c /cpukit/libmisc/shell/shell_cmdset.c
parent2007-12-11 Till Straumann <strauman@slac.stanford.edu> (diff)
downloadrtems-06bd7c74b111323995ebd9167f472b610e46b551.tar.bz2
2007-12-12 Chris Johns <chrisj@rtems.org>
* Makefile.am: Added libmisc/shell/shellconfig.h to the installed header list. * libmisc/shell/shell_cmdset.c: Let the Initial command add occur in any order rather than before any commands have been added. Also made the command's strings be copies rather than references. * sapi/src/ioregisterdriver.c: Return the I/O initialise calls result.
Diffstat (limited to 'cpukit/libmisc/shell/shell_cmdset.c')
-rw-r--r--cpukit/libmisc/shell/shell_cmdset.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/cpukit/libmisc/shell/shell_cmdset.c b/cpukit/libmisc/shell/shell_cmdset.c
index dddff4e8ad..daade2bb03 100644
--- a/cpukit/libmisc/shell/shell_cmdset.c
+++ b/cpukit/libmisc/shell/shell_cmdset.c
@@ -111,6 +111,13 @@ shell_cmd_t *shell_add_cmd_struct(
)
{
shell_cmd_t *shell_pvt;
+
+ shell_pvt = shell_first_cmd;
+ while (shell_pvt) {
+ if (strcmp(shell_pvt->name, shell_cmd->name) == 0)
+ return NULL;
+ shell_pvt = shell_pvt->next;
+ }
if ( !shell_first_cmd ) {
shell_first_cmd = shell_cmd;
@@ -135,25 +142,30 @@ shell_cmd_t * shell_add_cmd(
shell_command_t command
)
{
- extern void register_cmds(void);
-
shell_cmd_t *shell_cmd;
-
if (!cmd)
return (shell_cmd_t *) NULL;
if (!command)
return (shell_cmd_t *) NULL;
shell_cmd = (shell_cmd_t *) malloc(sizeof(shell_cmd_t));
- shell_cmd->name = cmd;
- shell_cmd->topic = topic;
- shell_cmd->usage = usage;
+ shell_cmd->name = strdup( cmd );
+ shell_cmd->topic = strdup( topic );
+ shell_cmd->usage = strdup( usage );
shell_cmd->command = command;
shell_cmd->alias = (shell_cmd_t *) NULL;
shell_cmd->next = (shell_cmd_t *) NULL;
- return shell_add_cmd_struct( shell_cmd );
+ if (shell_add_cmd_struct( shell_cmd ) == NULL) {
+ free( shell_cmd->usage );
+ free( shell_cmd->topic );
+ free( shell_cmd->name );
+ free( shell_cmd );
+ shell_cmd = NULL;
+ }
+
+ return shell_cmd;
}
@@ -162,9 +174,6 @@ void shell_initialize_command_set(void)
shell_cmd_t **c;
shell_alias_t **a;
- if ( shell_first_cmd )
- return;
-
for ( c = Shell_Initial_commands ; *c ; c++ ) {
shell_add_cmd_struct( *c );
}