summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cpukit/ChangeLog10
-rw-r--r--cpukit/libmisc/Makefile.am1
-rw-r--r--cpukit/libmisc/shell/cmd_help.c6
-rw-r--r--cpukit/libmisc/shell/cmds.c20
-rw-r--r--cpukit/libmisc/shell/internal.h4
-rw-r--r--cpukit/libmisc/shell/shell.c361
-rw-r--r--cpukit/libmisc/shell/shell.h7
-rw-r--r--cpukit/libmisc/shell/shell_cmdset.c209
-rw-r--r--cpukit/libmisc/shell/shell_makeargs.c47
-rw-r--r--cpukit/libmisc/shell/shellconfig.h85
-rw-r--r--cpukit/libmisc/shell/write_file.c39
11 files changed, 481 insertions, 308 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog
index 315b68ccc1..e651ac48b1 100644
--- a/cpukit/ChangeLog
+++ b/cpukit/ChangeLog
@@ -1,5 +1,15 @@
2007-12-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+ * libmisc/Makefile.am, libmisc/shell/cmd_help.c, libmisc/shell/cmds.c,
+ libmisc/shell/internal.h, libmisc/shell/shell.c,
+ libmisc/shell/shell.h, libmisc/shell/shellconfig.h: Command set
+ processing now separated from main command loop. Addition of user
+ commands and aliases tested. Monitor registration now explicit.
+ * libmisc/shell/shell_cmdset.c, libmisc/shell/shell_makeargs.c,
+ libmisc/shell/write_file.c: New files.
+
+2007-12-11 Joel Sherrill <joel.sherrill@oarcorp.com>
+
* libmisc/Makefile.am: Fix typo.
2007-12-10 Joel Sherrill <joel.sherrill@oarcorp.com>
diff --git a/cpukit/libmisc/Makefile.am b/cpukit/libmisc/Makefile.am
index d1444d90e9..ae1e2dd1dd 100644
--- a/cpukit/libmisc/Makefile.am
+++ b/cpukit/libmisc/Makefile.am
@@ -72,6 +72,7 @@ libshell_a_SOURCES = shell/cat_file.c shell/cmd_alias.c shell/cmd_cat.c \
shell/cmd_mmove.c shell/cmd_mwdump.c shell/cmd_pwd.c shell/cmd_rm.c \
shell/cmd_rmdir.c shell/cmds.c shell/cmd_tty.c shell/cmd_umask.c \
shell/cmd_whoami.c shell/internal.h shell/shell.c shell/shellconfig.c \
+ shell/shell_makeargs.c shell/shell_cmdset.c shell/write_file.c \
shell/shellconfig.h shell/shell.h shell/str2int.c
endif
diff --git a/cpukit/libmisc/shell/cmd_help.c b/cpukit/libmisc/shell/cmd_help.c
index 4a3bc18f09..964b511b2b 100644
--- a/cpukit/libmisc/shell/cmd_help.c
+++ b/cpukit/libmisc/shell/cmd_help.c
@@ -73,7 +73,11 @@ int shell_help_cmd(shell_cmd_t * shell_cmd) {
* Can you see the header of routine? Known?
* The same with all the commands....
*/
-int shell_help(int argc,char * argv[]) {
+int shell_help(
+ int argc,
+ char * argv[]
+)
+{
int col,line,arg;
shell_topic_t *topic;
shell_cmd_t * shell_cmd = shell_first_cmd;
diff --git a/cpukit/libmisc/shell/cmds.c b/cpukit/libmisc/shell/cmds.c
index 9c823c693e..d40839ad1e 100644
--- a/cpukit/libmisc/shell/cmds.c
+++ b/cpukit/libmisc/shell/cmds.c
@@ -1,4 +1,6 @@
/*
+ * XXX -- Just monitor commands until those can be integrated better
+ *
* Author: Fernando RUIZ CASAS
* Work: fernando.ruiz@ctv.es
* Home: correo@fernando-ruiz.com
@@ -29,31 +31,21 @@
int main_monitor(int argc,char * argv[]) {
rtems_monitor_command_entry_t *command;
- rtems_task_ident(RTEMS_SELF,0,&rtems_monitor_task_id);
-
- rtems_monitor_node = rtems_get_node(rtems_monitor_task_id);
-
- rtems_monitor_default_node = rtems_monitor_node;
-
if ((command=rtems_monitor_command_lookup(rtems_monitor_commands,argc,argv)))
command->command_function(argc, argv, &command->command_arg, 0);
return 0;
}
-/*-----------------------------------------------------------*/
-void register_cmds(void) {
+void shell_register_monitor_commands(void)
+{
rtems_monitor_command_entry_t *command;
/* monitor topic */
- command=rtems_monitor_commands;
+ command = rtems_monitor_commands;
while (command) {
if (strcmp("exit",command->command)) /* Exclude EXIT (alias quit)*/
shell_add_cmd(command->command,"monitor",
command->usage ,main_monitor);
- command=command->next;
+ command = command->next;
}
-
-
-
}
-/*-----------------------------------------------------------*/
diff --git a/cpukit/libmisc/shell/internal.h b/cpukit/libmisc/shell/internal.h
index 706bfc42af..c33909c619 100644
--- a/cpukit/libmisc/shell/internal.h
+++ b/cpukit/libmisc/shell/internal.h
@@ -29,4 +29,8 @@ extern shell_topic_t * shell_first_topic;
shell_topic_t * shell_lookup_topic(char * topic);
+
+void shell_register_monitor_commands(void);
+void shell_initialize_command_set(void);
+
#endif
diff --git a/cpukit/libmisc/shell/shell.c b/cpukit/libmisc/shell/shell.c
index d4008b14d8..c6d4dae1b8 100644
--- a/cpukit/libmisc/shell/shell.c
+++ b/cpukit/libmisc/shell/shell.c
@@ -13,6 +13,7 @@
*
* $Id$
*/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -38,193 +39,58 @@
#include <errno.h>
#include <pwd.h>
-/*
- * Common linked list of shell commands.
- *
- * Because the help report is very long, there is a topic for each command.
- *
- * Help list the topics
- * help [topic] list the commands for the topic
- * help [command] help for the command
- *
- */
-
-shell_cmd_t * shell_first_cmd;
-shell_topic_t * shell_first_topic;
-
-shell_env_t *shell_init_env(shell_env_t *);
-
-/*
- * Find the topic from the set of topics registered.
- */
-shell_topic_t * shell_lookup_topic(char * topic) {
- shell_topic_t * shell_topic;
- shell_topic=shell_first_topic;
-
- while (shell_topic) {
- if (!strcmp(shell_topic->topic,topic))
- return shell_topic;
- shell_topic=shell_topic->next;
- }
- return (shell_topic_t *) NULL;
-}
-
-/*
- * Add a new topic to the list of topics
- */
-shell_topic_t * shell_add_topic(char * topic) {
- shell_topic_t * current,*aux;
-
- if (!shell_first_topic) {
- aux = malloc(sizeof(shell_topic_t));
- aux->topic = topic;
- aux->next = (shell_topic_t*)NULL;
- return shell_first_topic = aux;
- }
- current=shell_first_topic;
- if (!strcmp(topic,current->topic))
- return current;
-
- while (current->next) {
- if (!strcmp(topic,current->next->topic))
- return current->next;
- current=current->next;
- }
- aux = malloc(sizeof(shell_topic_t));
- aux->topic = topic;
- aux->next = (shell_topic_t*)NULL;
- current->next = aux;
- return aux;
-}
-
-/*
- * Find the command in the set
- */
-shell_cmd_t * shell_lookup_cmd(char * cmd) {
- shell_cmd_t * shell_cmd;
- shell_cmd=shell_first_cmd;
- while (shell_cmd) {
- if (!strcmp(shell_cmd->name,cmd)) return shell_cmd;
- shell_cmd=shell_cmd->next;
- };
- return (shell_cmd_t *) NULL;
-}
-
-/*
- * Add a command structure to the set of known commands
- */
-shell_cmd_t *shell_add_cmd_struct(
- shell_cmd_t *shell_cmd
-)
-{
- shell_cmd_t *shell_pvt;
-
- if ( !shell_first_cmd ) {
- shell_first_cmd = shell_cmd;
- } else {
- shell_pvt = shell_first_cmd;
- while (shell_pvt->next)
- shell_pvt = shell_pvt->next;
- shell_pvt->next = shell_cmd;
- }
- shell_add_topic( shell_cmd->topic );
- return shell_cmd;
-}
+shell_env_t global_shell_env;
+shell_env_t *current_shell_env;
/*
- * Add a command as a set of arguments to the set and
- * allocate the command structure on the fly.
+ * Initialize the shell user/process environment information
*/
-shell_cmd_t * shell_add_cmd(
- char *cmd,
- char *topic,
- char *usage,
- shell_command_t command
+shell_env_t *shell_init_env(
+ shell_env_t *shell_env_arg
)
{
- extern void register_cmds(void);
-
- shell_cmd_t *shell_cmd;
-
- if ( !shell_first_cmd ) {
- shell_cmd_t **c;
- shell_alias_t **a;
-
- shell_first_cmd = NULL;
- for ( c = Shell_Initial_commands ; *c ; c++ ) {
- shell_add_cmd_struct( *c );
- }
-
- for ( a = Shell_Initial_aliases ; *a ; a++ ) {
- shell_alias_cmd( (*a)->name, (*a)->alias );
- }
+ shell_env_t *shell_env;
+
+ shell_env = shell_env_arg;
- register_cmds();
+ if ( !shell_env ) {
+ shell_env = malloc(sizeof(shell_env_t));
+ if ( !shell_env )
+ return NULL;
}
- if (!cmd)
- return (shell_cmd_t *) NULL;
- if (!command)
- return (shell_cmd_t *) NULL;
+ if (global_shell_env.magic != 0x600D600d) {
+ global_shell_env.magic = 0x600D600d;
+ global_shell_env.devname = "";
+ global_shell_env.taskname = "GLOBAL";
+ global_shell_env.tcflag = 0;
+ global_shell_env.exit_shell = 0;
+ global_shell_env.forever = TRUE;
+ }
- shell_cmd = (shell_cmd_t *) malloc(sizeof(shell_cmd_t));
- shell_cmd->name = cmd;
- shell_cmd->topic = topic;
- shell_cmd->usage = usage;
- shell_cmd->command = command;
- shell_cmd->alias = (shell_cmd_t *) NULL;
- shell_cmd->next = (shell_cmd_t *) NULL;
+ *shell_env = global_shell_env;
+ shell_env->taskname = NULL;
+ shell_env->forever = FALSE;
- return shell_add_cmd_struct( shell_cmd );
-}
-/* ----------------------------------------------- *
- * you can make an alias for every command.
- * ----------------------------------------------- */
-shell_cmd_t * shell_alias_cmd(char * cmd, char * alias) {
- shell_cmd_t * shell_cmd,* shell_aux;
- shell_aux=(shell_cmd_t *) NULL;
- if (alias) {
- if ((shell_aux=shell_lookup_cmd(alias))!=NULL) {
- return NULL;
- };
- if ((shell_cmd=shell_lookup_cmd(cmd))!=NULL) {
- shell_aux=shell_add_cmd(alias,shell_cmd->topic,
- shell_cmd->usage,shell_cmd->command);
- if (shell_aux) shell_aux->alias=shell_cmd;
- };
- };
- return shell_aux;
-}
-/* ----------------------------------------------- *
- * Poor but enough..
- * TODO: Redirection capture. "" evaluate, ... C&S welcome.
- * ----------------------------------------------- */
-int shell_make_args(char * cmd,
- int * pargc,
- char * argv[]) {
- int argc=0;
- while ((cmd=strtok(cmd," \t\r\n"))!=NULL) {
- argv[argc++]=cmd;
- cmd=(char*)NULL;
- };
- argv[argc]=(char*)NULL;
- return *pargc=argc;
+ return shell_env;
}
-/* ----------------------------------------------- *
- * TODO: Add improvements. History, edit vi or emacs, ...
- * ----------------------------------------------- */
+/*
+ * Get a line of user input with modest features
+ */
int shell_scanline(char * line,int size,FILE * in,FILE * out) {
int c,col;
- col=0;
+
+ col = 0;
if (*line) {
- col=strlen(line);
- if (out) fprintf(out,"%s",line);
- };
+ col = strlen(line);
+ if (out) fprintf(out,"%s",line);
+ }
tcdrain(fileno(in));
- if (out) tcdrain(fileno(out));
+ if (out)
+ tcdrain(fileno(out));
for (;;) {
- line[col]=0;
+ line[col] = 0;
c = fgetc(in);
switch (c) {
case 0x04:/*Control-d*/
@@ -236,7 +102,7 @@ int shell_scanline(char * line,int size,FILE * in,FILE * out) {
if (out)
fputc('\f',out);
case 0x03:/*Control-C*/
- line[0]=0;
+ line[0] = 0;
case '\n':
case '\r':
if (out)
@@ -258,10 +124,10 @@ int shell_scanline(char * line,int size,FILE * in,FILE * out) {
default:
if (!iscntrl(c)) {
if (col<size-1) {
- line[col++]=c;
- if (out) fputc(c,out);
+ line[col++] = c;
+ if (out) fputc(c,out);
} else {
- if (out) fputc('\a',out);
+ if (out) fputc('\a',out);
}
} else {
if (out)
@@ -271,39 +137,35 @@ int shell_scanline(char * line,int size,FILE * in,FILE * out) {
}
}
}
+
/* ----------------------------------------------- *
* - The shell TASK
* Poor but enough..
* TODO: Redirection. Tty Signals. ENVVARs. Shell language.
* ----------------------------------------------- */
-shell_env_t global_shell_env;
-shell_env_t *current_shell_env;
-extern char **environ;
+void init_issue(void) {
+ static char issue_inited=FALSE;
+ struct stat buf;
-void write_file(char * name,char * content) {
- FILE * fd;
- fd=fopen(name,"w");
- if (fd) {
- fwrite(content,1,strlen(content),fd);
- fclose(fd);
- };
-}
+ if (issue_inited)
+ return;
+ issue_inited = TRUE;
-void init_issue(void) {
- static char issue_inited=FALSE;
- struct stat buf;
- if (issue_inited) return;
- issue_inited=TRUE;
- getpwnam("root"); /* dummy call to init /etc dir */
- if (stat("/etc/issue",&buf))
- write_file("/etc/issue",
- "Welcome to @V\\n"
- "Login into @S\\n");
- if (stat("/etc/issue.net",&buf))
- write_file("/etc/issue.net",
- "Welcome to %v\n"
- "running on %m\n");
+ /* dummy call to init /etc dir */
+ getpwnam("root");
+
+ if (stat("/etc/issue",&buf)) {
+ write_file("/etc/issue",
+ "Welcome to @V\\n"
+ "Login into @S\\n");
+ }
+
+ if (stat("/etc/issue.net",&buf)) {
+ write_file("/etc/issue.net",
+ "Welcome to %v\n"
+ "running on %m\n");
+ }
}
int shell_login(FILE * in,FILE * out) {
@@ -433,16 +295,16 @@ int shell_login(FILE * in,FILE * out) {
setuid(passwd->pw_uid);
setgid(passwd->pw_gid);
rtems_current_user_env->euid =
- rtems_current_user_env->egid =0;
+ rtems_current_user_env->egid = 0;
chown(current_shell_env->devname,passwd->pw_uid,0);
rtems_current_user_env->euid = passwd->pw_uid;
rtems_current_user_env->egid = passwd->pw_gid;
if (!strcmp(passwd->pw_passwd,"*")) {
- /* /etc/shadow */
- return 0;
+ /* /etc/shadow */
+ return 0;
} else {
- /* crypt() */
- return 0;
+ /* crypt() */
+ return 0;
}
}
}
@@ -454,7 +316,7 @@ int shell_login(FILE * in,FILE * out) {
return -1;
}
-#if 0
+#if defined(SHELL_DEBUG)
void shell_print_env(
shell_env_t * shell_env
)
@@ -488,6 +350,7 @@ rtems_task shell_shell(rtems_task_argument task_argument)
rtems_task_delete( RTEMS_SELF );
}
+#define SHELL_MAXIMUM_ARGUMENTS 128
rtems_boolean shell_shell_loop(
shell_env_t *shell_env_arg
@@ -501,13 +364,15 @@ rtems_boolean shell_shell_loop(
char cmd[256];
char last_cmd[256]; /* to repeat 'r' */
int argc;
- char *argv[128];
+ char *argv[SHELL_MAXIMUM_ARGUMENTS];
+
+ shell_initialize_command_set();
sc = rtems_task_variable_add(RTEMS_SELF,(void*)&current_shell_env,free);
if (sc != RTEMS_SUCCESSFUL) {
rtems_error(sc,"rtems_task_variable_add(current_shell_env):");
return FALSE;
- };
+ }
shell_env =
current_shell_env = shell_init_env( shell_env_arg );
@@ -519,24 +384,24 @@ rtems_boolean shell_shell_loop(
setvbuf(stdin,NULL,_IONBF,0); /* Not buffered*/
/* make a raw terminal,Linux Manuals */
- if (tcgetattr (fileno(stdin), &term)>=0) {
- term.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
- term.c_oflag &= ~OPOST;
- term.c_oflag |= (OPOST|ONLCR); /* But with cr+nl on output */
- term.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
- if (shell_env->tcflag)
- term.c_cflag = shell_env->tcflag;
- term.c_cflag |= CLOCAL | CREAD;
- term.c_cc[VMIN] = 1;
- term.c_cc[VTIME] = 0;
- if (tcsetattr (fileno(stdin), TCSADRAIN, &term) < 0) {
- fprintf(stderr,
- "shell:cannot set terminal attributes(%s)\n",shell_env->devname);
- };
- setvbuf(stdout,NULL,_IONBF,0); /* Not buffered*/
+ if (tcgetattr(fileno(stdin), &term) >= 0) {
+ term.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
+ term.c_oflag &= ~OPOST;
+ term.c_oflag |= (OPOST|ONLCR); /* But with cr+nl on output */
+ term.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
+ if (shell_env->tcflag)
+ term.c_cflag = shell_env->tcflag;
+ term.c_cflag |= CLOCAL | CREAD;
+ term.c_cc[VMIN] = 1;
+ term.c_cc[VTIME] = 0;
+ if (tcsetattr (fileno(stdin), TCSADRAIN, &term) < 0) {
+ fprintf(stderr,
+ "shell:cannot set terminal attributes(%s)\n",shell_env->devname);
+ }
+ setvbuf(stdout,NULL,_IONBF,0); /* Not buffered*/
}
- shell_add_cmd(NULL,NULL,NULL,NULL); /* init the chain list*/
+ shell_initialize_command_set();
do {
/* Set again root user and root filesystem, side effect of set_priv..*/
sc = rtems_libio_set_private_env();
@@ -552,7 +417,7 @@ rtems_boolean shell_shell_loop(
"RTEMS SHELL (Ver.1.0-FRC):%s. "__DATE__". 'help' to list commands.\n",
shell_env->devname);
chdir("/"); /* XXX: chdir to getpwent homedir */
- shell_env->exit_shell=FALSE;
+ shell_env->exit_shell = FALSE;
for (;;) {
/* Prompt section */
/* XXX: show_prompt user adjustable */
@@ -591,12 +456,15 @@ rtems_boolean shell_shell_loop(
* Run in a new shell task background. (unix &)
* Resuming. A little bash.
*/
- if (shell_make_args(cmd,&argc,argv)) {
- if ((shell_cmd=shell_lookup_cmd(argv[0]))!=NULL) {
- shell_env->errorlevel=shell_cmd->command(argc,argv);
+ if (!shell_make_args(cmd, &argc, argv, SHELL_MAXIMUM_ARGUMENTS)) {
+ shell_cmd = shell_lookup_cmd(argv[0]);
+ if ( argv[0] == NULL ) {
+ shell_env->errorlevel = -1;
+ } else if ( shell_cmd == NULL ) {
+ printf("shell:%s command not found\n", argv[0]);
+ shell_env->errorlevel = -1;
} else {
- printf("shell:%s command not found\n",argv[0]);
- shell_env->errorlevel=-1;
+ shell_env->errorlevel = shell_cmd->command(argc, argv);
}
}
/* end exec cmd section */
@@ -604,7 +472,7 @@ rtems_boolean shell_shell_loop(
if (shell_env->exit_shell)
break;
strcpy(last_cmd, cmd);
- cmd[0]=0;
+ cmd[0] = 0;
}
printf("\nGoodbye from RTEMS SHELL :-(\n");
fflush( stdout );
@@ -630,7 +498,8 @@ rtems_status_code shell_init (
rtems_name name;
if ( task_name )
- name = rtems_build_name(task_name[0], task_name[1], task_name[2], task_name[3]);
+ name = rtems_build_name(
+ task_name[0], task_name[1], task_name[2], task_name[3]);
else
name = rtems_build_name( 'S', 'E', 'N', 'V' );
@@ -660,33 +529,3 @@ rtems_status_code shell_init (
return rtems_task_start(task_id,shell_shell,(rtems_task_argument) shell_env);
}
-
-shell_env_t *shell_init_env(
- shell_env_t *shell_env_arg
-)
-{
- shell_env_t *shell_env;
-
- shell_env = shell_env_arg;
-
- if ( !shell_env ) {
- shell_env = malloc(sizeof(shell_env_t));
- if ( !shell_env )
- return NULL;
- }
-
- if (global_shell_env.magic != 0x600D600d) {
- global_shell_env.magic = 0x600D600d;
- global_shell_env.devname = "";
- global_shell_env.taskname = "GLOBAL";
- global_shell_env.tcflag = 0;
- global_shell_env.exit_shell = 0;
- global_shell_env.forever = TRUE;
- }
-
- *shell_env = global_shell_env;
- shell_env->taskname = NULL;
- shell_env->forever = FALSE;
-
- return shell_env;
-}
diff --git a/cpukit/libmisc/shell/shell.h b/cpukit/libmisc/shell/shell.h
index e901cb9c5d..19e1d97917 100644
--- a/cpukit/libmisc/shell/shell.h
+++ b/cpukit/libmisc/shell/shell.h
@@ -65,9 +65,10 @@ shell_cmd_t * shell_alias_cmd(
);
int shell_make_args(
- char * cmd,
- int * pargc,
- char * argv[]
+ char *commandLine,
+ int *argc_p,
+ char **argv_p,
+ int max_args
);
int shell_scanline(char * line,int size,FILE * in,FILE * out) ;
diff --git a/cpukit/libmisc/shell/shell_cmdset.c b/cpukit/libmisc/shell/shell_cmdset.c
new file mode 100644
index 0000000000..dddff4e8ad
--- /dev/null
+++ b/cpukit/libmisc/shell/shell_cmdset.c
@@ -0,0 +1,209 @@
+/*
+ *
+ * Shell Command Set Management
+ *
+ * Author:
+ * WORK: fernando.ruiz@ctv.es
+ * HOME: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <time.h>
+#include <termios.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include <rtems/shellconfig.h>
+#include "internal.h"
+
+/*
+ * Common linked list of shell commands.
+ *
+ * Because the help report is very long, there is a topic for each command.
+ *
+ * Help list the topics
+ * help [topic] list the commands for the topic
+ * help [command] help for the command
+ *
+ */
+
+shell_cmd_t * shell_first_cmd;
+shell_topic_t * shell_first_topic;
+
+/*
+ * Find the topic from the set of topics registered.
+ */
+shell_topic_t * shell_lookup_topic(char * topic) {
+ shell_topic_t * shell_topic;
+ shell_topic=shell_first_topic;
+
+ while (shell_topic) {
+ if (!strcmp(shell_topic->topic,topic))
+ return shell_topic;
+ shell_topic=shell_topic->next;
+ }
+ return (shell_topic_t *) NULL;
+}
+
+/*
+ * Add a new topic to the list of topics
+ */
+shell_topic_t * shell_add_topic(char * topic) {
+ shell_topic_t * current,*aux;
+
+ if (!shell_first_topic) {
+ aux = malloc(sizeof(shell_topic_t));
+ aux->topic = topic;
+ aux->next = (shell_topic_t*)NULL;
+ return shell_first_topic = aux;
+ }
+ current=shell_first_topic;
+ if (!strcmp(topic,current->topic))
+ return current;
+
+ while (current->next) {
+ if (!strcmp(topic,current->next->topic))
+ return current->next;
+ current=current->next;
+ }
+ aux = malloc(sizeof(shell_topic_t));
+ aux->topic = topic;
+ aux->next = (shell_topic_t*)NULL;
+ current->next = aux;
+ return aux;
+}
+
+/*
+ * Find the command in the set
+ */
+shell_cmd_t * shell_lookup_cmd(char * cmd) {
+ shell_cmd_t * shell_cmd;
+ shell_cmd=shell_first_cmd;
+ while (shell_cmd) {
+ if (!strcmp(shell_cmd->name,cmd)) return shell_cmd;
+ shell_cmd=shell_cmd->next;
+ };
+ return (shell_cmd_t *) NULL;
+}
+
+/*
+ * Add a command structure to the set of known commands
+ */
+shell_cmd_t *shell_add_cmd_struct(
+ shell_cmd_t *shell_cmd
+)
+{
+ shell_cmd_t *shell_pvt;
+
+ if ( !shell_first_cmd ) {
+ shell_first_cmd = shell_cmd;
+ } else {
+ shell_pvt = shell_first_cmd;
+ while (shell_pvt->next)
+ shell_pvt = shell_pvt->next;
+ shell_pvt->next = shell_cmd;
+ }
+ shell_add_topic( shell_cmd->topic );
+ return shell_cmd;
+}
+
+/*
+ * Add a command as a set of arguments to the set and
+ * allocate the command structure on the fly.
+ */
+shell_cmd_t * shell_add_cmd(
+ char *cmd,
+ char *topic,
+ char *usage,
+ 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->command = command;
+ shell_cmd->alias = (shell_cmd_t *) NULL;
+ shell_cmd->next = (shell_cmd_t *) NULL;
+
+ return shell_add_cmd_struct( shell_cmd );
+}
+
+
+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 );
+ }
+
+ for ( a = Shell_Initial_aliases ; *a ; a++ ) {
+ shell_alias_cmd( (*a)->name, (*a)->alias );
+ }
+
+ shell_register_monitor_commands();
+}
+
+/* ----------------------------------------------- *
+ * you can make an alias for every command.
+ * ----------------------------------------------- */
+shell_cmd_t *shell_alias_cmd(
+ char *cmd,
+ char *alias
+)
+{
+ shell_cmd_t *shell_cmd, *shell_aux;
+
+ shell_aux = (shell_cmd_t *) NULL;
+
+ if (alias) {
+ shell_aux = shell_lookup_cmd(alias);
+ if (shell_aux != NULL) {
+ return NULL;
+ }
+ shell_cmd = shell_lookup_cmd(cmd);
+ if (shell_cmd != NULL) {
+ shell_aux = shell_add_cmd(
+ alias,
+ shell_cmd->topic,
+ shell_cmd->usage,
+ shell_cmd->command
+ );
+ if (shell_aux)
+ shell_aux->alias = shell_cmd;
+ }
+ }
+ return shell_aux;
+}
diff --git a/cpukit/libmisc/shell/shell_makeargs.c b/cpukit/libmisc/shell/shell_makeargs.c
new file mode 100644
index 0000000000..c73ff25745
--- /dev/null
+++ b/cpukit/libmisc/shell/shell_makeargs.c
@@ -0,0 +1,47 @@
+/*
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+
+int shell_make_args(
+ char *commandLine,
+ int *argc_p,
+ char **argv_p,
+ int max_args
+)
+{
+ int argc;
+ char *command;
+ int status = 0;
+
+ argc = 0;
+ command = commandLine;
+
+ while ( 1 ) {
+ command = strtok( command, " \t\r\n" );
+ if ( command == NULL )
+ break;
+ argv_p[ argc++ ] = command;
+ command = '\0';
+ if ( argc == (max_args-1) ) {
+ status = -1;
+ break;
+ }
+ }
+ argv_p[ argc ] = NULL;
+ *argc_p = argc;
+ return status;
+}
+
diff --git a/cpukit/libmisc/shell/shellconfig.h b/cpukit/libmisc/shell/shellconfig.h
index 27ca834c25..c0275a3f00 100644
--- a/cpukit/libmisc/shell/shellconfig.h
+++ b/cpukit/libmisc/shell/shellconfig.h
@@ -64,28 +64,34 @@ extern shell_alias_t *Shell_Initial_aliases[];
*/
#if !defined(CONFIGURE_SHELL_COMMANDS_ALL)
- #if defined(CONFIGURE_SHELL_COMMANDS_DIR) && !defined(CONFIGURE_SHELL_COMMANDS_LS)
+ #if defined(CONFIGURE_SHELL_COMMANDS_DIR) && \
+ !defined(CONFIGURE_SHELL_COMMANDS_LS)
#define CONFIGURE_SHELL_COMMANDS_LS
#endif
- #if defined(CONFIGURE_SHELL_COMMANDS_CD) && !defined(CONFIGURE_SHELL_COMMANDS_CHDIR)
+ #if defined(CONFIGURE_SHELL_COMMANDS_CD) && \
+ !defined(CONFIGURE_SHELL_COMMANDS_CHDIR)
#define CONFIGURE_SHELL_COMMANDS_CHDIR
#endif
- #if defined(CONFIGURE_SHELL_COMMANDS_EXIT) && !defined(CONFIGURE_SHELL_COMMANDS_LOGOFF)
+ #if defined(CONFIGURE_SHELL_COMMANDS_EXIT) && \
+ !defined(CONFIGURE_SHELL_COMMANDS_LOGOFF)
#define CONFIGURE_SHELL_COMMANDS_LOGOFF
#endif
#endif
#if defined(CONFIGURE_SHELL_COMMANDS_INIT)
shell_alias_t *Shell_Initial_aliases[] = {
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMANDS_DIR)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMANDS_DIR)
&Shell_DIR_Alias,
#endif
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMANDS_CD)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMANDS_CD)
&Shell_CD_Alias,
#endif
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMANDS_EXIT)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMANDS_EXIT)
&Shell_EXIT_Alias,
#endif
@@ -93,7 +99,7 @@ extern shell_alias_t *Shell_Initial_aliases[];
* User defined shell aliases
*/
#if defined(CONFIGURE_SHELL_USER_ALIASES)
- CONFIGURE_SHELL_USER_ALIASES
+ CONFIGURE_SHELL_USER_ALIASES,
#endif
NULL
};
@@ -108,79 +114,100 @@ extern shell_alias_t *Shell_Initial_aliases[];
/*
* Common commands that can be optional
*/
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMAND_DATE)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMAND_DATE)
&Shell_DATE_Command,
#endif
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMAND_ID)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMAND_ID)
&Shell_ID_Command,
#endif
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMAND_TTY)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMAND_TTY)
&Shell_TTY_Command,
#endif
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMAND_WHOAMI)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMAND_WHOAMI)
&Shell_WHOAMI_Command,
#endif
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMAND_LOGOFF)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMAND_LOGOFF)
&Shell_LOGOFF_Command,
#endif
/*
* Memory printing/modification family commands
*/
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMAND_MDUMP)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMAND_MDUMP)
&Shell_MDUMP_Command,
#endif
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMAND_WDUMP)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMAND_WDUMP)
&Shell_WDUMP_Command,
#endif
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMAND_MEDIT)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMAND_MEDIT)
&Shell_MEDIT_Command,
#endif
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMAND_MFILL)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMAND_MFILL)
&Shell_MFILL_Command,
#endif
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMAND_MMOVE)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMAND_MMOVE)
&Shell_MMOVE_Command,
#endif
/*
* File and directory commands
*/
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMAND_PWD)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMAND_PWD)
&Shell_PWD_Command,
#endif
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMAND_LS)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMAND_LS)
&Shell_LS_Command,
#endif
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMAND_CHDIR)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMAND_CHDIR)
&Shell_CHDIR_Command,
#endif
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMAND_MKDIR)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMAND_MKDIR)
&Shell_MKDIR_Command,
#endif
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMAND_RMDIR)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMAND_RMDIR)
&Shell_RMDIR_Command,
#endif
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMAND_CHROOT)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMAND_CHROOT)
&Shell_CHROOT_Command,
#endif
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMAND_CHMOD)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMAND_CHMOD)
&Shell_CHMOD_Command,
#endif
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMAND_CAT)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMAND_CAT)
&Shell_CAT_Command,
#endif
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMAND_RM)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMAND_RM)
&Shell_RM_Command,
#endif
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMAND_UMASK)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMAND_UMASK)
&Shell_UMASK_Command,
#endif
/*
* Malloc family commands
*/
- #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMAND_MALLOC_DUMP)
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || \
+ defined(CONFIGURE_SHELL_COMMAND_MALLOC_DUMP)
&Shell_MALLOC_DUMP_Command,
#endif
@@ -188,7 +215,7 @@ extern shell_alias_t *Shell_Initial_aliases[];
* User defined shell commands
*/
#if defined(CONFIGURE_SHELL_USER_COMMANDS)
- CONFIGURE_SHELL_USER_COMMANDS
+ CONFIGURE_SHELL_USER_COMMANDS,
#endif
NULL
};
diff --git a/cpukit/libmisc/shell/write_file.c b/cpukit/libmisc/shell/write_file.c
new file mode 100644
index 0000000000..33f1d5ae02
--- /dev/null
+++ b/cpukit/libmisc/shell/write_file.c
@@ -0,0 +1,39 @@
+/*
+ *
+ * Write buffer to a file
+ *
+ * Author:
+ *
+ * WORK: fernando.ruiz@ctv.es
+ * HOME: correo@fernando-ruiz.com
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+
+void write_file(
+ char *name,
+ char * content
+)
+{
+ FILE * fd;
+
+ fd = fopen(name,"w");
+ if (fd) {
+ fwrite(content,1,strlen(content),fd);
+ fclose(fd);
+ }
+}
+
+