summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2007-12-10 23:14:35 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2007-12-10 23:14:35 +0000
commit4e5299ffc4753255b53ec542050761d07ae0f813 (patch)
tree342f9041b753e865bbe2f4cdbd215b4a165e86de /cpukit/libmisc
parent2007-12-10 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-4e5299ffc4753255b53ec542050761d07ae0f813.tar.bz2
2007-12-10 Joel Sherrill <joel.sherrill@oarcorp.com>
* ChangeLog, preinstall.am, libmisc/Makefile.am, libmisc/shell/cmds.c, libmisc/shell/shell.c, libmisc/shell/shell.h: Split shell commands into multiple files and add initial stages of command configuration. This seems to work but the monitor commands need to be integrated this way and the ability to configure user commands needs to be tested. * libmisc/shell/cat_file.c, libmisc/shell/cmd_alias.c, libmisc/shell/cmd_cat.c, libmisc/shell/cmd_cd.c, libmisc/shell/cmd_chdir.c, libmisc/shell/cmd_chmod.c, libmisc/shell/cmd_chroot.c, libmisc/shell/cmd_date.c, libmisc/shell/cmd_dir.c, libmisc/shell/cmd_exit.c, libmisc/shell/cmd_help.c, libmisc/shell/cmd_id.c, libmisc/shell/cmd_logoff.c, libmisc/shell/cmd_ls.c, libmisc/shell/cmd_mallocdump.c, libmisc/shell/cmd_mdump.c, libmisc/shell/cmd_medit.c, libmisc/shell/cmd_mfill.c, libmisc/shell/cmd_mkdir.c, libmisc/shell/cmd_mmove.c, libmisc/shell/cmd_mwdump.c, libmisc/shell/cmd_pwd.c, libmisc/shell/cmd_rm.c, libmisc/shell/cmd_rmdir.c, libmisc/shell/cmd_tty.c, libmisc/shell/cmd_umask.c, libmisc/shell/cmd_whoami.c, libmisc/shell/internal.h, libmisc/shell/shellconfig.c, libmisc/shell/shellconfig.h, libmisc/shell/str2int.c: New files.
Diffstat (limited to 'cpukit/libmisc')
-rw-r--r--cpukit/libmisc/Makefile.am10
-rw-r--r--cpukit/libmisc/shell/cat_file.c36
-rw-r--r--cpukit/libmisc/shell/cmd_alias.c45
-rw-r--r--cpukit/libmisc/shell/cmd_cat.c55
-rw-r--r--cpukit/libmisc/shell/cmd_cd.c26
-rw-r--r--cpukit/libmisc/shell/cmd_chdir.c50
-rw-r--r--cpukit/libmisc/shell/cmd_chmod.c52
-rw-r--r--cpukit/libmisc/shell/cmd_chroot.c49
-rw-r--r--cpukit/libmisc/shell/cmd_date.c44
-rw-r--r--cpukit/libmisc/shell/cmd_dir.c26
-rw-r--r--cpukit/libmisc/shell/cmd_exit.c26
-rw-r--r--cpukit/libmisc/shell/cmd_help.c145
-rw-r--r--cpukit/libmisc/shell/cmd_id.c62
-rw-r--r--cpukit/libmisc/shell/cmd_logoff.c42
-rw-r--r--cpukit/libmisc/shell/cmd_ls.c107
-rw-r--r--cpukit/libmisc/shell/cmd_mallocdump.c40
-rw-r--r--cpukit/libmisc/shell/cmd_mdump.c194
-rw-r--r--cpukit/libmisc/shell/cmd_medit.c56
-rw-r--r--cpukit/libmisc/shell/cmd_mfill.c55
-rw-r--r--cpukit/libmisc/shell/cmd_mkdir.c51
-rw-r--r--cpukit/libmisc/shell/cmd_mmove.c55
-rw-r--r--cpukit/libmisc/shell/cmd_mwdump.c65
-rw-r--r--cpukit/libmisc/shell/cmd_pwd.c41
-rw-r--r--cpukit/libmisc/shell/cmd_rm.c50
-rw-r--r--cpukit/libmisc/shell/cmd_rmdir.c49
-rw-r--r--cpukit/libmisc/shell/cmd_tty.c42
-rw-r--r--cpukit/libmisc/shell/cmd_umask.c52
-rw-r--r--cpukit/libmisc/shell/cmd_whoami.c46
-rw-r--r--cpukit/libmisc/shell/cmds.c513
-rw-r--r--cpukit/libmisc/shell/internal.h32
-rw-r--r--cpukit/libmisc/shell/shell.c409
-rw-r--r--cpukit/libmisc/shell/shell.h83
-rw-r--r--cpukit/libmisc/shell/shellconfig.c14
-rw-r--r--cpukit/libmisc/shell/shellconfig.h197
-rw-r--r--cpukit/libmisc/shell/str2int.c95
35 files changed, 2151 insertions, 763 deletions
diff --git a/cpukit/libmisc/Makefile.am b/cpukit/libmisc/Makefile.am
index 24ff9fdf8b..d6014117ec 100644
--- a/cpukit/libmisc/Makefile.am
+++ b/cpukit/libmisc/Makefile.am
@@ -64,7 +64,15 @@ libmw_fb_a_SOURCES = mw-fb/mw_fb.c mw-fb/mw_uid.c mw-fb/mw_fb.h \
if LIBSHELL
noinst_LIBRARIES += libshell.a
-libshell_a_SOURCES = shell/cmds.c shell/shell.c shell/shell.h
+libshell_a_SOURCES = shell/cat_file.c shell/cmd_alias.c shell/cmd_cat.c
+ shell/cmd_cd.c shell/cmd_chdir.c shell/cmd_chmod.c shell/cmd_chroot.c
+ shell/cmd_date.c shell/cmd_dir.c shell/cmd_exit.c shell/cmd_help.c
+ shell/cmd_id.c shell/cmd_logoff.c shell/cmd_ls.c shell/cmd_mallocdump.c
+ shell/cmd_mdump.c shell/cmd_medit.c shell/cmd_mfill.c shell/cmd_mkdir.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/shellconfig.h shell/shell.h shell/str2int.c
endif
EXTRA_DIST += shell/README
diff --git a/cpukit/libmisc/shell/cat_file.c b/cpukit/libmisc/shell/cat_file.c
new file mode 100644
index 0000000000..70de2bb6ce
--- /dev/null
+++ b/cpukit/libmisc/shell/cat_file.c
@@ -0,0 +1,36 @@
+/*
+ *
+ * Instantatiate a new terminal shell.
+ *
+ * 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>
+
+void cat_file(FILE * out,char * name) {
+ FILE * fd;
+ int c;
+
+ if (out) {
+ fd = fopen(name,"r");
+ if (fd) {
+ while ((c=fgetc(fd))!=EOF) fputc(c,out);
+ fclose(fd);
+ }
+ }
+}
+
+
diff --git a/cpukit/libmisc/shell/cmd_alias.c b/cpukit/libmisc/shell/cmd_alias.c
new file mode 100644
index 0000000000..e1efce84b5
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_alias.c
@@ -0,0 +1,45 @@
+/*
+ * ALIAS Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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 <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int main_alias(int argc, char **argv)
+{
+ if (argc<3) {
+ fprintf(stdout,"too few arguments\n");
+ return 1;
+ }
+
+ if (!shell_alias_cmd(argv[1],argv[2])) {
+ fprintf(stdout,"unable to make an alias(%s,%s)\n",argv[1],argv[2]);
+ }
+ return 0;
+}
+
+shell_cmd_t Shell_ALIAS_Command = {
+ "alias", /* name */
+ "alias old new", /* usage */
+ "misc", /* topic */
+ main_alias, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/cmd_cat.c b/cpukit/libmisc/shell/cmd_cat.c
new file mode 100644
index 0000000000..58e8de9c55
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_cat.c
@@ -0,0 +1,55 @@
+/*
+ * CAT Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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 <termios.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <dirent.h>
+#include <time.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <pwd.h>
+#include <grp.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <stddef.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int main_cat(int argc, char *argv[])
+{
+ int n;
+ n=1;
+
+ while (n<argc)
+ cat_file(stdout,argv[n++]);
+ return 0;
+}
+
+shell_cmd_t Shell_CAT_Command = {
+ "cat", /* name */
+ "cat n1 [n2 [n3...]] # show the ascii contents", /* usage */
+ "files", /* topic */
+ main_cat , /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/cmd_cd.c b/cpukit/libmisc/shell/cmd_cd.c
new file mode 100644
index 0000000000..31a7cfb075
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_cd.c
@@ -0,0 +1,26 @@
+/*
+ * CD Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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 <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+shell_alias_t Shell_CD_Alias = {
+ "chdir", /* command */
+ "cd" /* alias */
+};
diff --git a/cpukit/libmisc/shell/cmd_chdir.c b/cpukit/libmisc/shell/cmd_chdir.c
new file mode 100644
index 0000000000..64be1dd67c
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_chdir.c
@@ -0,0 +1,50 @@
+/*
+ * CHDIR Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int main_chdir (int argc, char *argv[]) {
+ char *dir;
+
+ dir = "/";
+
+ if (argc>1)
+ dir = argv[1];
+
+ if (chdir(dir)) {
+ fprintf(stdout, "chdir to '%s' failed:%s\n", dir,strerror(errno));
+ return errno;
+ }
+ return 0;
+}
+
+shell_cmd_t Shell_CHDIR_Command = {
+ "chdir", /* name */
+ "chdir [dir] # change the current directory", /* usage */
+ "files", /* topic */
+ main_chdir, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/cmd_chmod.c b/cpukit/libmisc/shell/cmd_chmod.c
new file mode 100644
index 0000000000..c3d0c5aade
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_chmod.c
@@ -0,0 +1,52 @@
+/*
+ * CHMOD Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <rtems.h>
+#include <rtems/monitor.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int main_chmod(int argc,char *argv[])
+{
+ int n;
+ mode_t mode;
+
+ if (argc > 2){
+ mode = str2int(argv[1])&0777;
+ n = 2;
+ while (n<argc)
+ chmod(argv[n++], mode);
+ }
+ return 0;
+}
+
+shell_cmd_t Shell_CHMOD_Command = {
+ "chmod", /* name */
+ "chmod 0777 n1 n2... # change filemode", /* usage */
+ "files", /* topic */
+ main_chmod, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/cmd_chroot.c b/cpukit/libmisc/shell/cmd_chroot.c
new file mode 100644
index 0000000000..e22e694ff0
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_chroot.c
@@ -0,0 +1,49 @@
+/*
+ * CHROOT Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int main_chroot(int argc,char * argv[]) {
+ char *new_root="/";
+
+ if (argc==2)
+ new_root=argv[1];
+
+ if (chroot(new_root)<0) {
+ fprintf(stdout,"error %s:chroot(%s);\n",strerror(errno),new_root);
+ return -1;
+ }
+
+ return 0;
+}
+
+shell_cmd_t Shell_CHROOT_Command = {
+ "chroot", /* name */
+ "chroot [dir] # change the root directory", /* usage */
+ "files", /* topic */
+ main_chroot, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/cmd_date.c b/cpukit/libmisc/shell/cmd_date.c
new file mode 100644
index 0000000000..7f6fdbb52b
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_date.c
@@ -0,0 +1,44 @@
+/*
+ * DATE Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int main_date(int argc,char *argv[])
+{
+ time_t t;
+
+ time(&t);
+ fprintf(stdout,"%s", ctime(&t));
+ return 0;
+}
+
+shell_cmd_t Shell_DATE_Command = {
+ "date", /* name */
+ "date", /* usage */
+ "misc", /* topic */
+ main_date, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/cmd_dir.c b/cpukit/libmisc/shell/cmd_dir.c
new file mode 100644
index 0000000000..a41de05fb1
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_dir.c
@@ -0,0 +1,26 @@
+/*
+ * DIR Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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 <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+shell_alias_t Shell_DIR_Alias = {
+ "ls", /* command */
+ "dir" /* alias */
+};
diff --git a/cpukit/libmisc/shell/cmd_exit.c b/cpukit/libmisc/shell/cmd_exit.c
new file mode 100644
index 0000000000..29225e0a11
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_exit.c
@@ -0,0 +1,26 @@
+/*
+ * exit Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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 <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+shell_alias_t Shell_EXIT_Alias = {
+ "logoff", /* command */
+ "exit" /* alias */
+};
diff --git a/cpukit/libmisc/shell/cmd_help.c b/cpukit/libmisc/shell/cmd_help.c
new file mode 100644
index 0000000000..4a3bc18f09
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_help.c
@@ -0,0 +1,145 @@
+/*
+ *
+ * Shell Help Command
+ *
+ * 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 <rtems.h>
+#include <rtems/error.h>
+#include <rtems/system.h>
+#include <rtems/shell.h>
+
+#include "internal.h"
+#include <string.h>
+
+/*
+ * show the help for one command.
+ */
+int shell_help_cmd(shell_cmd_t * shell_cmd) {
+ char * pc;
+ int col,line;
+
+ printf("%-10.10s - ",shell_cmd->name);
+ col = 12;
+ line = 1;
+ if (shell_cmd->alias) {
+ printf("is an <alias> for command '%s'",shell_cmd->alias->name);
+ } else if (shell_cmd->usage) {
+ pc = shell_cmd->usage;
+ while (*pc) {
+ switch(*pc) {
+ case '\r':
+ break;
+ case '\n':
+ putchar('\n');
+ col = 0;
+ break;
+ default:
+ putchar(*pc);
+ col++;
+ break;
+ }
+ pc++;
+ if (col>78) { /* What daring... 78?*/
+ if (*pc) {
+ putchar('\n');
+ col = 0;
+ }
+ }
+ if (!col && *pc) {
+ printf(" ");
+ col = 12;line++;
+ }
+ }
+ }
+ puts("");
+ return line;
+}
+
+/*
+ * show the help. The first command implemented.
+ * Can you see the header of routine? Known?
+ * The same with all the commands....
+ */
+int shell_help(int argc,char * argv[]) {
+ int col,line,arg;
+ shell_topic_t *topic;
+ shell_cmd_t * shell_cmd = shell_first_cmd;
+
+ if (argc<2) {
+ printf("help: ('r' repeat last cmd - 'e' edit last cmd)\n"
+ " TOPIC? The topics are\n");
+ topic = shell_first_topic;
+ col = 0;
+ while (topic) {
+ if (!col){
+ col = printf(" %s",topic->topic);
+ } else {
+ if ((col+strlen(topic->topic)+2)>78){
+ printf("\n");
+ col = printf(" %s",topic->topic);
+ } else {
+ col+= printf(", %s",topic->topic);
+ }
+ }
+ topic = topic->next;
+ }
+ printf("\n");
+ return 1;
+ }
+ line = 0;
+ for (arg = 1;arg<argc;arg++) {
+ if (line>16) {
+ printf("Press any key to continue...");getchar();
+ printf("\n");
+ line = 0;
+ }
+ topic = shell_lookup_topic(argv[arg]);
+ if (!topic){
+ if ((shell_cmd = shell_lookup_cmd(argv[arg])) == NULL) {
+ printf("help: topic or cmd '%s' not found. Try <help> alone for a list\n",
+ argv[arg]);
+ line++;
+ } else {
+ line+= shell_help_cmd(shell_cmd);
+ }
+ continue;
+ }
+ printf("help: list for the topic '%s'\n",argv[arg]);
+ line++;
+ while (shell_cmd) {
+ if (!strcmp(topic->topic,shell_cmd->topic))
+ line+= shell_help_cmd(shell_cmd);
+ if (line>16) {
+ printf("Press any key to continue...");
+ getchar();
+ printf("\n");
+ line = 0;
+ }
+ shell_cmd = shell_cmd->next;
+ }
+ }
+ puts("");
+ return 0;
+}
+
+shell_cmd_t Shell_HELP_Command = {
+ "help", /* name */
+ "help [topic] # list of usage of commands", /* usage */
+ "help", /* topic */
+ shell_help, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/cmd_id.c b/cpukit/libmisc/shell/cmd_id.c
new file mode 100644
index 0000000000..63db5a2c97
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_id.c
@@ -0,0 +1,62 @@
+/*
+ * Author: Fernando RUIZ CASAS
+ * 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>
+#include <errno.h>
+#include <pwd.h>
+#include <grp.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int main_id(int argc,char *argv[])
+{
+ struct passwd *pwd;
+ struct group *grp;
+
+ pwd = getpwuid(getuid());
+ grp = getgrgid(getgid());
+ printf(
+ "uid=%d(%s),gid=%d(%s),",
+ getuid(),
+ pwd?pwd->pw_name:"",
+ getgid(),
+ grp?grp->gr_name:""
+ );
+ pwd = getpwuid(geteuid());
+ grp = getgrgid(getegid());
+ printf(
+ "euid=%d(%s),egid=%d(%s)\n",
+ geteuid(),
+ pwd?pwd->pw_name:"",
+ getegid(),
+ grp?grp->gr_name:""
+ );
+ return 0;
+}
+
+shell_cmd_t Shell_ID_Command = {
+ "id", /* name */
+ "show uid, gid, euid, and egid", /* usage */
+ "misc", /* topic */
+ main_id , /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/cmd_logoff.c b/cpukit/libmisc/shell/cmd_logoff.c
new file mode 100644
index 0000000000..5653f7114b
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_logoff.c
@@ -0,0 +1,42 @@
+/*
+ * LOGOFF Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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 <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+/*-----------------------------------------------------------*/
+int main_logoff(int argc,char *argv[])
+{
+ printf("logoff from the system...");
+
+ current_shell_env->exit_shell=TRUE;
+
+ return 0;
+}
+
+shell_cmd_t Shell_LOGOFF_Command = {
+ "logoff", /* name */
+ "logoff from the system", /* usage */
+ "misc", /* topic */
+ main_logoff, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/cmd_ls.c b/cpukit/libmisc/shell/cmd_ls.c
new file mode 100644
index 0000000000..9e0befd101
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_ls.c
@@ -0,0 +1,107 @@
+/*
+ * LS Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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 <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <dirent.h>
+#include <time.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <pwd.h>
+#include <grp.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <stddef.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int main_ls(int argc, char *argv[])
+{
+ char *fname;
+ DIR *dirp;
+ struct dirent *dp;
+ struct stat stat_buf;
+ struct passwd *pwd;
+ struct group *grp;
+ char *user;
+ char *group;
+ char sbuf[256];
+ char nbuf[1024];
+ int n;
+ int size;
+
+ fname = ".";
+ if (argc>1)
+ fname = argv[1];
+
+ if ((dirp = opendir(fname)) == NULL) {
+ fprintf(stdout,"%s: No such file or directory.\n", fname);
+ return errno;
+ }
+ n = 0;
+ size = 0;
+ while ((dp = readdir(dirp)) != NULL) {
+ strcpy(nbuf,fname);
+ if (nbuf[strlen(nbuf)-1]!='/')
+ strcat(nbuf,"/");
+ strcat(nbuf,dp->d_name); /* always the fullpathname. Avoid ftpd problem.*/
+ if (stat(nbuf, &stat_buf) == 0) { /* AWFUL buts works...*/
+ strftime(sbuf,sizeof(sbuf)-1,"%b %d %H:%M",gmtime(&stat_buf.st_mtime));
+ pwd = getpwuid(stat_buf.st_uid);
+ user = pwd?pwd->pw_name:"nouser";
+ grp = getgrgid(stat_buf.st_gid);
+ group = grp?grp->gr_name:"nogrp";
+ fprintf(stdout,"%c%c%c%c%c%c%c%c%c%c %3d %6.6s %6.6s %11d %s %s%c\n",
+ (S_ISLNK(stat_buf.st_mode)?('l'):
+ (S_ISDIR(stat_buf.st_mode)?('d'):('-'))),
+ (stat_buf.st_mode & S_IRUSR)?('r'):('-'),
+ (stat_buf.st_mode & S_IWUSR)?('w'):('-'),
+ (stat_buf.st_mode & S_IXUSR)?('x'):('-'),
+ (stat_buf.st_mode & S_IRGRP)?('r'):('-'),
+ (stat_buf.st_mode & S_IWGRP)?('w'):('-'),
+ (stat_buf.st_mode & S_IXGRP)?('x'):('-'),
+ (stat_buf.st_mode & S_IROTH)?('r'):('-'),
+ (stat_buf.st_mode & S_IWOTH)?('w'):('-'),
+ (stat_buf.st_mode & S_IXOTH)?('x'):('-'),
+ (int)stat_buf.st_nlink,
+ user,group,
+ (int)stat_buf.st_size,
+ sbuf,
+ dp->d_name,
+ S_ISDIR(stat_buf.st_mode)?'/':' ');
+ n++;
+ size += stat_buf.st_size;
+ }
+ }
+ fprintf(stdout,"%d files %d bytes occupied\n",n,size);
+ closedir(dirp);
+ return 0;
+}
+
+shell_cmd_t Shell_LS_Command = {
+ "ls", /* name */
+ "ls [dir] # list files in the directory", /* usage */
+ "files", /* topic */
+ main_ls , /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/cmd_mallocdump.c b/cpukit/libmisc/shell/cmd_mallocdump.c
new file mode 100644
index 0000000000..e8050bc247
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_mallocdump.c
@@ -0,0 +1,40 @@
+/*
+ * MALLOC_DUMP Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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 <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+/*----------------------------------------------------------------------------*/
+int main_malloc_dump(int argc,char * argv[]) {
+ #ifdef MALLOC_STATS /* /rtems/s/src/lib/libc/malloc.c */
+ void malloc_dump(void);
+ malloc_dump();
+ #endif
+ return 0;
+}
+
+shell_cmd_t Shell_MALLOC_DUMP_Command = {
+ "malloc", /* name */
+ "mem show memory malloc'ed", /* usage */
+ "mem", /* topic */
+ main_malloc_dump, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
+
diff --git a/cpukit/libmisc/shell/cmd_mdump.c b/cpukit/libmisc/shell/cmd_mdump.c
new file mode 100644
index 0000000000..efb57303fc
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_mdump.c
@@ -0,0 +1,194 @@
+/*
+ * MDUMP Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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 <ctype.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+/*----------------------------------------------------------------------------*
+ * RAM MEMORY COMMANDS
+ *----------------------------------------------------------------------------*/
+
+int main_mdump(int argc,char * argv[]) {
+ unsigned char n,m,max=0;
+ uintptr_t addr;
+ unsigned char *pb;
+
+ addr = current_shell_env->mdump_addr;
+ if (argc>1)
+ addr = str2int(argv[1]);
+ if (argc>2)
+ max = str2int(argv[2]);
+
+ max /= 16;
+
+ if (!max)
+ max = 20;
+
+ for (m=0;m<max;m++) {
+ fprintf(stdout,"0x%08X ",addr);
+ pb = (unsigned char*) addr;
+ for (n=0;n<16;n++)
+ fprintf(stdout,"%02X%c",pb[n],n==7?'-':' ');
+ for (n=0;n<16;n++) {
+ fprintf(stdout,"%c",isprint(pb[n])?pb[n]:'.');
+ }
+ fprintf(stdout,"\n");
+ addr += 16;
+ }
+ current_shell_env->mdump_addr = addr;
+ return 0;
+}
+
+shell_cmd_t Shell_MDUMP_Command = {
+ "mdump", /* name */
+ "mdump [addr [size]]", /* usage */
+ "mem", /* topic */
+ main_mdump, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
+
+
+/*----------------------------------------------------------------------------*/
+int main_mwdump(int argc,char * argv[]) {
+ unsigned char n,m,max=0;
+ int addr=current_shell_env->mdump_addr;
+ unsigned short * pw;
+
+ if (argc>1)
+ addr = str2int(argv[1]);
+ if (argc>2)
+ max = str2int(argv[2]);
+
+ max /= 16;
+
+ if (!max)
+ max = 20;
+
+ for (m=0;m<max;m++) {
+ fprintf(stdout,"0x%08X ",addr);
+ pw = (unsigned short*) addr;
+ for (n=0;n<8;n++)
+ fprintf(stdout,"%02X %02X%c",pw[n]/0x100,pw[n]%0x100,n==3?'-':' ');
+ for (n=0;n<8;n++) {
+ fprintf(stdout,"%c",isprint(pw[n]/0x100)?pw[n]/0x100:'.');
+ fprintf(stdout,"%c",isprint(pw[n]%0x100)?pw[n]%0x100:'.');
+ }
+ fprintf(stdout,"\n");
+ addr += 16;
+ }
+ current_shell_env->mdump_addr = addr;
+ return 0;
+}
+
+shell_cmd_t Shell_WDUMP_Command = {
+ "wdump", /* name */
+ "wdump [addr [size]]", /* usage */
+ "mem", /* topic */
+ main_mwdump, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
+
+/*----------------------------------------------------------------------------*/
+int main_medit(int argc,char * argv[]) {
+ unsigned char * pb;
+ int n,i;
+
+ if (argc<3) {
+ fprintf(stdout,"too few arguments\n");
+ return 0;
+ }
+
+ pb = (unsigned char*)str2int(argv[1]);
+ i = 2;
+ n = 0;
+ while (i<=argc) {
+ pb[n++] = str2int(argv[i++])%0x100;
+ }
+ current_shell_env->mdump_addr = (int)pb;
+ return main_mdump(0,NULL);
+}
+
+shell_cmd_t Shell_MEDIT_Command = {
+ "medit", /* name */
+ "medit addr value [value ...]", /* usage */
+ "mem", /* topic */
+ main_medit, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
+
+/*----------------------------------------------------------------------------*/
+int main_mfill(int argc,char * argv[]) {
+ int addr;
+ int size;
+ unsigned char value;
+
+ if (argc<4) {
+ fprintf(stdout,"too few arguments\n");
+ return 0;
+ }
+ addr = str2int(argv[1]);
+ size = str2int(argv[2]);
+ value= str2int(argv[3]) % 0x100;
+ memset((unsigned char*)addr,size,value);
+ current_shell_env->mdump_addr = addr;
+ return main_mdump(0,NULL);
+}
+
+shell_cmd_t Shell_MFILL_Command = {
+ "mfill", /* name */
+ "mfill addr size value", /* usage */
+ "mem", /* topic */
+ main_mfill, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
+
+/*----------------------------------------------------------------------------*/
+int main_mmove(int argc,char * argv[]) {
+ int src;
+ int dst;
+ int size;
+
+ if (argc<4) {
+ fprintf(stdout,"too few arguments\n");
+ return 0;
+ }
+ dst = str2int(argv[1]);
+ src = str2int(argv[2]);
+ size = str2int(argv[3]);
+ memcpy((unsigned char*)dst,(unsigned char*)src,size);
+ current_shell_env->mdump_addr = dst;
+ return main_mdump(0,NULL);
+}
+
+shell_cmd_t Shell_MMOVE_Command = {
+ "mmove", /* name */
+ "mmove dst src size", /* usage */
+ "mem", /* topic */
+ main_mmove, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/cmd_medit.c b/cpukit/libmisc/shell/cmd_medit.c
new file mode 100644
index 0000000000..ba59d0d8d8
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_medit.c
@@ -0,0 +1,56 @@
+/*
+ * MEDIT Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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 <ctype.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+extern int main_mdump(int, char *);
+
+int main_medit(int argc,char * argv[]) {
+ unsigned char * pb;
+ int n,i;
+
+ if (argc<3) {
+ fprintf(stdout,"too few arguments\n");
+ return 0;
+ }
+
+ pb = (unsigned char*)str2int(argv[1]);
+ i = 2;
+ n = 0;
+ while (i<=argc) {
+ pb[n++] = str2int(argv[i++])%0x100;
+ }
+ current_shell_env->mdump_addr = (int)pb;
+
+ return main_mdump(0,NULL);
+}
+
+shell_cmd_t Shell_MEDIT_Command = {
+ "medit", /* name */
+ "medit addr value [value ...]", /* usage */
+ "mem", /* topic */
+ main_medit, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/cmd_mfill.c b/cpukit/libmisc/shell/cmd_mfill.c
new file mode 100644
index 0000000000..4a8f3a4b3c
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_mfill.c
@@ -0,0 +1,55 @@
+/*
+ * MFILL Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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 <ctype.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+extern int main_mdump(int, char *);
+
+int main_mfill(int argc,char * argv[]) {
+ uintptr_t addr;
+ size_t size;
+ unsigned char value;
+
+ if (argc<4) {
+ fprintf(stdout,"too few arguments\n");
+ return 0;
+ }
+
+ addr = str2int(argv[1]);
+ size = str2int(argv[2]);
+ value= str2int(argv[3]) % 0x100;
+ memset((unsigned char*)addr,size,value);
+ current_shell_env->mdump_addr = addr;
+
+ return main_mdump(0,NULL);
+}
+
+shell_cmd_t Shell_MFILL_Command = {
+ "mfill", /* name */
+ "mfill addr size value", /* usage */
+ "mem", /* topic */
+ main_mfill, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/cmd_mkdir.c b/cpukit/libmisc/shell/cmd_mkdir.c
new file mode 100644
index 0000000000..5c9f365226
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_mkdir.c
@@ -0,0 +1,51 @@
+/*
+ * MKDIR Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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 <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int main_mkdir(int argc, char *argv[]) {
+ char *dir;
+
+ int n;
+ n = 1;
+ while (n<argc) {
+ dir = argv[n++];
+ if (mkdir(dir,S_IRWXU|S_IRWXG|S_IRWXO)) {
+ fprintf(stdout, "mkdir '%s' failed:%s\n", dir, strerror(errno));
+ }
+ }
+ return errno;
+}
+
+shell_cmd_t Shell_MKDIR_Command = {
+ "mkdir", /* name */
+ "mkdir dir # make a directory", /* usage */
+ "files", /* topic */
+ main_mkdir, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/cmd_mmove.c b/cpukit/libmisc/shell/cmd_mmove.c
new file mode 100644
index 0000000000..522f6f69c3
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_mmove.c
@@ -0,0 +1,55 @@
+/*
+ * MMOVE Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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 <ctype.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+extern int main_mdump(int, char *);
+
+int main_mmove(int argc,char * argv[]) {
+ uintptr_t src;
+ uintptr_t dst;
+ size_t size;
+
+ if (argc<4) {
+ fprintf(stdout,"too few arguments\n");
+ return 0;
+ }
+
+ dst = str2int(argv[1]);
+ src = str2int(argv[2]);
+ size = str2int(argv[3]);
+ memcpy((unsigned char*)dst, (unsigned char*)src, size);
+ current_shell_env->mdump_addr = dst;
+
+ return main_mdump(0,NULL);
+}
+
+shell_cmd_t Shell_MMOVE_Command = {
+ "mmove", /* name */
+ "mmove dst src size", /* usage */
+ "mem", /* topic */
+ main_mmove, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/cmd_mwdump.c b/cpukit/libmisc/shell/cmd_mwdump.c
new file mode 100644
index 0000000000..9ba9fbb4f7
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_mwdump.c
@@ -0,0 +1,65 @@
+/*
+ * MWDUMP Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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 <ctype.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int main_mwdump(int argc,char * argv[]) {
+ unsigned char n,m,max=0;
+ int addr=current_shell_env->mdump_addr;
+ unsigned short * pw;
+
+ if (argc>1)
+ addr = str2int(argv[1]);
+ if (argc>2)
+ max = str2int(argv[2]);
+
+ max /= 16;
+
+ if (!max)
+ max = 20;
+
+ for (m=0;m<max;m++) {
+ fprintf(stdout,"0x%08X ",addr);
+ pw = (unsigned short*) addr;
+ for (n=0;n<8;n++)
+ fprintf(stdout,"%02X %02X%c",pw[n]/0x100,pw[n]%0x100,n==3?'-':' ');
+ for (n=0;n<8;n++) {
+ fprintf(stdout,"%c",isprint(pw[n]/0x100)?pw[n]/0x100:'.');
+ fprintf(stdout,"%c",isprint(pw[n]%0x100)?pw[n]%0x100:'.');
+ }
+ fprintf(stdout,"\n");
+ addr += 16;
+ }
+ current_shell_env->mdump_addr = addr;
+ return 0;
+}
+
+shell_cmd_t Shell_WDUMP_Command = {
+ "wdump", /* name */
+ "wdump [addr [size]]", /* usage */
+ "mem", /* topic */
+ main_mwdump, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/cmd_pwd.c b/cpukit/libmisc/shell/cmd_pwd.c
new file mode 100644
index 0000000000..b33cef290e
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_pwd.c
@@ -0,0 +1,41 @@
+/*
+ * PWD Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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 <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int main_pwd (int argc, char *argv[]) {
+ char dir[1024];
+
+ getcwd(dir,1024);
+ fprintf(stdout,"%s\n",dir);
+ return 0;
+}
+
+shell_cmd_t Shell_PWD_Command = {
+ "pwd", /* name */
+ "pwd # print work directory", /* usage */
+ "files", /* topic */
+ main_pwd , /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/cmd_rm.c b/cpukit/libmisc/shell/cmd_rm.c
new file mode 100644
index 0000000000..400521042e
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_rm.c
@@ -0,0 +1,50 @@
+/*
+ * RM Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int main_rm(int argc, char *argv[])
+{
+ int n;
+ n = 1;
+
+ while (n<argc) {
+ if (unlink(argv[n])) {
+ fprintf(stdout,"error %s:rm %s\n",strerror(errno),argv[n]);
+ return -1;
+ }
+ n++;
+ }
+ return 0;
+}
+
+shell_cmd_t Shell_RM_Command = {
+ "rm", /* name */
+ "rm n1 [n2 [n3...]] # remove files", /* usage */
+ "files", /* topic */
+ main_rm, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/cmd_rmdir.c b/cpukit/libmisc/shell/cmd_rmdir.c
new file mode 100644
index 0000000000..1525a450fe
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_rmdir.c
@@ -0,0 +1,49 @@
+/*
+ * RMDIR Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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 <string.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int main_rmdir (int argc, char *argv[])
+{
+ char *dir;
+ int n;
+
+ n=1;
+ while (n<argc) {
+ dir=argv[n++];
+ if (rmdir(dir))
+ fprintf(stdout, "rmdir '%s' failed:%s\n", dir, strerror(errno));
+ }
+ return errno;
+}
+
+shell_cmd_t Shell_RMDIR_Command = {
+ "rmdir", /* name */
+ "rmdir dir # remove directory", /* usage */
+ "files", /* topic */
+ main_rmdir, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/cmd_tty.c b/cpukit/libmisc/shell/cmd_tty.c
new file mode 100644
index 0000000000..7e1a4848e6
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_tty.c
@@ -0,0 +1,42 @@
+/*
+ * TTY Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/monitor.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int main_tty(int argc,char *argv[])
+{
+ printf("%s\n",ttyname(fileno(stdin)));
+ return 0;
+}
+
+shell_cmd_t Shell_TTY_Command = {
+ "tty", /* name */
+ "show ttyname", /* usage */
+ "misc", /* topic */
+ main_tty , /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/cmd_umask.c b/cpukit/libmisc/shell/cmd_umask.c
new file mode 100644
index 0000000000..677ded5ee4
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_umask.c
@@ -0,0 +1,52 @@
+/*
+ * UMASK Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <rtems.h>
+#include <rtems/monitor.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int main_umask(int argc,char *argv[])
+{
+ mode_t msk = umask(0);
+
+ if (argc == 2)
+ msk = str2int(argv[1]);
+ umask(msk);
+
+ msk = umask(0);
+ printf("0%o\n", (unsigned int) msk);
+ umask(msk);
+ return 0;
+}
+
+shell_cmd_t Shell_UMASK_Command = {
+ "umask", /* name */
+ "umask [new_umask]", /* usage */
+ "misc", /* topic */
+ main_umask , /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/cmd_whoami.c b/cpukit/libmisc/shell/cmd_whoami.c
new file mode 100644
index 0000000000..1105772887
--- /dev/null
+++ b/cpukit/libmisc/shell/cmd_whoami.c
@@ -0,0 +1,46 @@
+/*
+ * WHOAMI Shell Command Implmentation
+ *
+ * Author: Fernando RUIZ CASAS
+ * 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>
+#include <errno.h>
+#include <pwd.h>
+
+#include <rtems.h>
+#include <rtems/monitor.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int main_whoami(int argc,char *argv[])
+{
+ struct passwd *pwd;
+
+ pwd = getpwuid(getuid());
+ printf("%s\n",pwd?pwd->pw_name:"nobody");
+ return 0;
+}
+
+shell_cmd_t Shell_WHOAMI_Command = {
+ "whoami", /* name */
+ "show current user", /* usage */
+ "misc", /* topic */
+ main_whoami, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/cmds.c b/cpukit/libmisc/shell/cmds.c
index ba3a4b030e..9c823c693e 100644
--- a/cpukit/libmisc/shell/cmds.c
+++ b/cpukit/libmisc/shell/cmds.c
@@ -1,24 +1,11 @@
/*
- * Author: Fernando RUIZ CASAS
- *
+ * Author: Fernando RUIZ CASAS
* Work: fernando.ruiz@ctv.es
* Home: correo@fernando-ruiz.com
*
- * This file is inspired in rtems_monitor & Chris John MyRightBoot
- *
- * But I want to make it more user friendly
- * A 'monitor' command is added to adapt the call rtems monitor commands
- * at my call procedure
- *
- * TODO: A lot of improvements of course.
- * cp, mv, ...
- * hexdump,
- *
- * More? Say me it, please...
- *
- * The BSP Specific are not welcome here.
- *
- * C&S welcome...
+ * 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$
*/
@@ -28,499 +15,45 @@
#endif
#include <stdio.h>
-#include <termios.h>
#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <dirent.h>
-#include <time.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <pwd.h>
-#include <grp.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <stddef.h>
#include <rtems.h>
#include <rtems/monitor.h>
-#include <rtems/score/tod.h>
-
-#include <rtems/imfs.h>
#include <rtems/shell.h>
+#include "internal.h"
-/* ----------------------------------------------- *
- - str to int "0xaffe" "0b010010" "0123" "192939"
- * ----------------------------------------------- */
-int str2int(char * s) {
- int sign=1;
- int base=10;
- int value=0;
- int digit;
- if (!s) return 0;
- if (*s) {
- if (*s=='-') {
- sign=-1;
- s++;
- if (!*s) return 0;
- };
- if (*s=='0') {
- s++;
- switch(*s) {
- case 'x':
- case 'X':s++;
- base=16;
- break;
- case 'b':
- case 'B':s++;
- base=2;
- break;
- default :base=8;
- break;
- }
- };
- while (*s) {
- switch(*s) {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':digit=*s-'0';
- break;
- case 'A':
- case 'B':
- case 'C':
- case 'D':
- case 'E':
- case 'F':digit=*s-'A'+10;
- break;
- case 'a':
- case 'b':
- case 'c':
- case 'd':
- case 'e':
- case 'f':digit=*s-'a'+10;
- break;
- default:return value*sign;
- };
- if (digit>base) return value*sign;
- value=value*base+digit;
- s++;
- };
- };
- return value*sign;
-}
-/*----------------------------------------------------------------------------*
- * RAM MEMORY COMMANDS
- *----------------------------------------------------------------------------*/
-
-#define mdump_adr (current_shell_env->mdump_adr) /* static value */
-
-int main_mdump(int argc,char * argv[]) {
- unsigned char n,m,max=0;
- int adr=mdump_adr;
- unsigned char * pb;
- if (argc>1) adr=str2int(argv[1]);
- if (argc>2) max=str2int(argv[2]);
- max/=16;
- if (!max) max=20;
- for (m=0;m<max;m++) {
- fprintf(stdout,"0x%08X ",adr);
- pb=(unsigned char*) adr;
- for (n=0;n<16;n++)
- fprintf(stdout,"%02X%c",pb[n],n==7?'-':' ');
- for (n=0;n<16;n++) {
- fprintf(stdout,"%c",isprint(pb[n])?pb[n]:'.');
- };
- fprintf(stdout,"\n");
- adr+=16;
- };
- mdump_adr=adr;
- return 0;
-}
-/*----------------------------------------------------------------------------*/
-int main_mwdump(int argc,char * argv[]) {
- unsigned char n,m,max=0;
- int adr=mdump_adr;
- unsigned short * pw;
- if (argc>1) adr=str2int(argv[1]);
- if (argc>2) max=str2int(argv[2]);
- max/=16;
- if (!max) max=20;
- for (m=0;m<max;m++) {
- fprintf(stdout,"0x%08X ",adr);
- pw=(unsigned short*) adr;
- for (n=0;n<8;n++)
- fprintf(stdout,"%02X %02X%c",pw[n]/0x100,pw[n]%0x100,n==3?'-':' ');
- for (n=0;n<8;n++) {
- fprintf(stdout,"%c",isprint(pw[n]/0x100)?pw[n]/0x100:'.');
- fprintf(stdout,"%c",isprint(pw[n]%0x100)?pw[n]%0x100:'.');
- };
- fprintf(stdout,"\n");
- adr+=16;
- };
- mdump_adr=adr;
- return 0;
-}
-/*----------------------------------------------------------------------------*/
-int main_medit(int argc,char * argv[]) {
- unsigned char * pb;
- int n,i;
- if (argc<3) {
- fprintf(stdout,"too few arguments\n");
- return 0;
- };
- pb=(unsigned char*)str2int(argv[1]);
- i=2;
- n=0;
- while (i<=argc) {
- pb[n++]=str2int(argv[i++])%0x100;
- }
- mdump_adr=(int)pb;
- return main_mdump(0,NULL);
-}
-/*----------------------------------------------------------------------------*/
-int main_mfill(int argc,char * argv[]) {
- int adr;
- int size;
- unsigned char value;
- if (argc<4) {
- fprintf(stdout,"too few arguments\n");
- return 0;
- };
- adr =str2int(argv[1]);
- size =str2int(argv[2]);
- value=str2int(argv[3])%0x100;
- memset((unsigned char*)adr,size,value);
- mdump_adr=adr;
- return main_mdump(0,NULL);
-}
-/*----------------------------------------------------------------------------*/
-int main_mmove(int argc,char * argv[]) {
- int src;
- int dst;
- int size;
- if (argc<4) {
- fprintf(stdout,"too few arguments\n");
- return 0;
- };
- dst =str2int(argv[1]);
- src =str2int(argv[2]);
- size =str2int(argv[3]);
- memcpy((unsigned char*)dst,(unsigned char*)src,size);
- mdump_adr=dst;
- return main_mdump(0,NULL);
-}
-/*----------------------------------------------------------------------------*/
-#ifdef MALLOC_STATS /* /rtems/s/src/lib/libc/malloc.c */
-int main_malloc_dump(int argc,char * argv[]) {
- void malloc_dump(void);
- malloc_dump();
- return 0;
-}
-#endif
-/*----------------------------------------------------------------------------
- * Reset. Assumes that the watchdog is present.
- *----------------------------------------------------------------------------*/
-int main_reset (int argc, char **argv)
-{
- rtems_interrupt_level level;
- fprintf(stdout,"Waiting for watchdog ... ");
- tcdrain(fileno(stdout));
-
- rtems_interrupt_disable (level);
- for (;;)
- ;
- return 0;
-}
-/*----------------------------------------------------------------------------
- * Alias. make an alias
- *----------------------------------------------------------------------------*/
-int main_alias (int argc, char **argv)
-{
- if (argc<3) {
- fprintf(stdout,"too few arguments\n");
- return 1;
- };
- if (!shell_alias_cmd(argv[1],argv[2])) {
- fprintf(stdout,"unable to make an alias(%s,%s)\n",argv[1],argv[2]);
- };
- return 0;
-}
/*-----------------------------------------------------------*
- * Directory commands
+ * with this you can call at all the rtems monitor commands.
+ * Not all work fine but you can show the rtems status and more.
*-----------------------------------------------------------*/
-int main_ls(int argc, char *argv[])
-{
- char * fname;
- DIR *dirp;
- struct dirent *dp;
- struct stat stat_buf;
- struct passwd * pwd;
- struct group * grp;
- char * user;
- char * group;
- char sbuf[256];
- char nbuf[1024];
- int n,size;
+int main_monitor(int argc,char * argv[]) {
+ rtems_monitor_command_entry_t *command;
- fname=".";
- if (argc>1) fname=argv[1];
+ rtems_task_ident(RTEMS_SELF,0,&rtems_monitor_task_id);
- if ((dirp = opendir(fname)) == NULL)
- {
- fprintf(stdout,"%s: No such file or directory.\n", fname);
- return errno;
- }
- n=0;
- size=0;
- while ((dp = readdir(dirp)) != NULL)
- {
- strcpy(nbuf,fname);
- if (nbuf[strlen(nbuf)-1]!='/') strcat(nbuf,"/");
- strcat(nbuf,dp->d_name); /* always the fullpathname. Avoid ftpd problem.*/
- if (stat(nbuf, &stat_buf) == 0)
- { /* AWFUL buts works...*/
- strftime(sbuf,sizeof(sbuf)-1,"%b %d %H:%M",gmtime(&stat_buf.st_mtime));
- pwd=getpwuid(stat_buf.st_uid);
- user=pwd?pwd->pw_name:"nouser";
- grp=getgrgid(stat_buf.st_gid);
- group=grp?grp->gr_name:"nogrp";
- fprintf(stdout,"%c%c%c%c%c%c%c%c%c%c %3d %6.6s %6.6s %11d %s %s%c\n",
- (S_ISLNK(stat_buf.st_mode)?('l'):
- (S_ISDIR(stat_buf.st_mode)?('d'):('-'))),
- (stat_buf.st_mode & S_IRUSR)?('r'):('-'),
- (stat_buf.st_mode & S_IWUSR)?('w'):('-'),
- (stat_buf.st_mode & S_IXUSR)?('x'):('-'),
- (stat_buf.st_mode & S_IRGRP)?('r'):('-'),
- (stat_buf.st_mode & S_IWGRP)?('w'):('-'),
- (stat_buf.st_mode & S_IXGRP)?('x'):('-'),
- (stat_buf.st_mode & S_IROTH)?('r'):('-'),
- (stat_buf.st_mode & S_IWOTH)?('w'):('-'),
- (stat_buf.st_mode & S_IXOTH)?('x'):('-'),
- (int)stat_buf.st_nlink,
- user,group,
- (int)stat_buf.st_size,
- sbuf,
- dp->d_name,
- S_ISDIR(stat_buf.st_mode)?'/':' ');
- n++;
- size+=stat_buf.st_size;
- }
- }
- fprintf(stdout,"%d files %d bytes occupied\n",n,size);
- closedir(dirp);
- return 0;
-}
-/*-----------------------------------------------------------*/
-int main_pwd (int argc, char *argv[]) {
- char dir[1024];
- getcwd(dir,1024);
- fprintf(stdout,"%s\n",dir);
- return 0;
-}
-/*-----------------------------------------------------------*/
-int main_chdir (int argc, char *argv[]) {
- char *dir;
- dir="/";
- if (argc>1) dir=argv[1];
- if (chdir(dir)) {
- fprintf(stdout,"chdir to '%s' failed:%s\n",dir,strerror(errno));
- return errno;
- };
- return 0;
-}
-/*-----------------------------------------------------------*/
-int main_mkdir (int argc, char *argv[]) {
- char *dir;
- int n;
- n=1;
- while (n<argc) {
- dir=argv[n++];
- if (mkdir(dir,S_IRWXU|S_IRWXG|S_IRWXO)) {
- fprintf(stdout,"mkdir '%s' failed:%s\n",dir,strerror(errno));
- };
- };
- return errno;
-}
-/*-----------------------------------------------------------*/
-int main_rmdir (int argc, char *argv[])
-{
- char *dir;
- int n;
- n=1;
- while (n<argc) {
- dir=argv[n++];
- if (rmdir(dir)) fprintf(stdout,"rmdir '%s' failed:%s\n",dir,strerror(errno));
- };
- return errno;
-}
-/*-----------------------------------------------------------*/
-int main_chroot(int argc,char * argv[]) {
- char * new_root="/";
- if (argc==2) new_root=argv[1];
- if (chroot(new_root)<0) {
- fprintf(stdout,"error %s:chroot(%s);\n",strerror(errno),new_root);
- return -1;
- };
- return 0;
-}
-/*-----------------------------------------------------------*/
-int main_cat (int argc, char *argv[])
-{
- int n;
- n=1;
- while (n<argc) cat_file(stdout,argv[n++]);
- return 0;
-}
-/*-----------------------------------------------------------*/
-int main_rm (int argc, char *argv[])
-{
- int n;
- n=1;
- while (n<argc) {
- if (unlink(argv[n])) {
- fprintf(stdout,"error %s:rm %s\n",strerror(errno),argv[n]);
- return -1;
- };
- n++;
- };
- return 0;
-}
-/*-----------------------------------------------------------*/
-/* date - print time and date */
+ 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);
-int main_date(int argc,char *argv[])
-{
- time_t t;
- time(&t);
- fprintf(stdout,"%s", ctime(&t));
- return 0;
-}
-/*-----------------------------------------------------------*/
-int main_logoff(int argc,char *argv[])
-{
- fprintf(stdout,"logoff from the system...");
- current_shell_env->exit_shell=TRUE;
- return 0;
-}
-/*-----------------------------------------------------------*/
-int main_tty (int argc,char *argv[])
-{
- fprintf(stdout,"%s\n",ttyname(fileno(stdin)));
return 0;
}
-/*-----------------------------------------------------------*/
-int main_whoami(int argc,char *argv[])
-{
- struct passwd * pwd;
- pwd=getpwuid(getuid());
- fprintf(stdout,"%s\n",pwd?pwd->pw_name:"nobody");
- return 0;
-}
-/*-----------------------------------------------------------*/
-int main_id (int argc,char *argv[])
-{
- struct passwd * pwd;
- struct group * grp;
- pwd=getpwuid(getuid());
- grp=getgrgid(getgid());
- fprintf(stdout,"uid=%d(%s),gid=%d(%s),",
- getuid(),pwd?pwd->pw_name:"",
- getgid(),grp?grp->gr_name:"");
- pwd=getpwuid(geteuid());
- grp=getgrgid(getegid());
- fprintf(stdout,"euid=%d(%s),egid=%d(%s)\n",
- geteuid(),pwd?pwd->pw_name:"",
- getegid(),grp?grp->gr_name:"");
- return 0;
-}
-/*-----------------------------------------------------------*/
-int main_umask(int argc,char *argv[])
-{
- mode_t msk=umask(0);
- if (argc == 2) msk=str2int(argv[1]);
- umask(msk);
- msk=umask(0);
- fprintf(stdout,"0%o\n", (unsigned int) msk);
- umask(msk);
- return 0;
-}
-/*-----------------------------------------------------------*/
-int main_chmod(int argc,char *argv[])
-{
- int n;
- mode_t mode;
- if (argc > 2){
- mode=str2int(argv[1])&0777;
- n=2;
- while (n<argc) chmod(argv[n++],mode);
- };
- return 0;
-}
-/*-----------------------------------------------------------*
- * with this you can call at all the rtems monitor commands.
- * Not all work fine but you can show the rtems status and more.
- *-----------------------------------------------------------*/
-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) {
rtems_monitor_command_entry_t *command;
/* monitor topic */
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;
- };
- /* dir[ectories] topic */
- shell_add_cmd ("ls" ,"dir","ls [dir] # list files in the directory" ,main_ls );
- shell_add_cmd ("chdir" ,"dir","chdir [dir] # change the current directory",main_chdir);
- shell_add_cmd ("rmdir" ,"dir","rmdir dir # remove directory" ,main_rmdir);
- shell_add_cmd ("mkdir" ,"dir","mkdir dir # make a directory" ,main_mkdir);
- shell_add_cmd ("pwd" ,"dir","pwd # print work directory" ,main_pwd );
- shell_add_cmd ("chroot","dir","chroot [dir] # change the root directory" ,main_chroot);
- shell_add_cmd ("cat" ,"dir","cat n1 [n2 [n3...]]# show the ascii contents",main_cat );
- shell_add_cmd ("rm" ,"dir","rm n1 [n2 [n3...]]# remove files" ,main_rm );
- shell_add_cmd ("chmod" ,"dir","chmod 0777 n1 n2... #change filemode" ,main_chmod);
-
- shell_alias_cmd("ls" ,"dir");
- shell_alias_cmd("chdir" ,"cd");
+ if (strcmp("exit",command->command)) /* Exclude EXIT (alias quit)*/
+ shell_add_cmd(command->command,"monitor",
+ command->usage ,main_monitor);
+ command=command->next;
+ }
- /* misc. topic */
- shell_add_cmd ("logoff","misc","logoff from the system" ,main_logoff);
- shell_alias_cmd("logoff","exit");
- shell_add_cmd ("date" ,"misc","date" ,main_date);
- shell_add_cmd ("reset","misc","reset the BSP" ,main_reset);
- shell_add_cmd ("alias","misc","alias old new" ,main_alias);
- shell_add_cmd ("tty" ,"misc","show ttyname" ,main_tty );
- shell_add_cmd ("whoami","misc","show current user" ,main_whoami);
- shell_add_cmd ("id" ,"misc","show uid,gid,euid,egid" ,main_id );
- shell_add_cmd ("umask" ,"misc","umask [new_umask]" ,main_umask );
+
-
- /* memory topic */
- shell_add_cmd ("mdump","mem" ,"mdump [adr [size]]" ,main_mdump);
- shell_add_cmd ("wdump","mem" ,"wdump [adr [size]]" ,main_mwdump);
- shell_add_cmd ("medit","mem" ,"medit adr value [value ...]" ,main_medit);
- shell_add_cmd ("mfill","mem" ,"mfill adr size value" ,main_mfill);
- shell_add_cmd ("mmove","mem" ,"mmove dst src size" ,main_mmove);
-#ifdef MALLOC_STATS /* /rtems/s/src/lib/libc/malloc.c */
- shell_add_cmd ("malloc","mem","mem show memory malloc'ed" ,main_mem);
-#endif
}
/*-----------------------------------------------------------*/
diff --git a/cpukit/libmisc/shell/internal.h b/cpukit/libmisc/shell/internal.h
new file mode 100644
index 0000000000..706bfc42af
--- /dev/null
+++ b/cpukit/libmisc/shell/internal.h
@@ -0,0 +1,32 @@
+/*
+ * Shell Internal Information
+ *
+ * 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$
+ */
+
+#ifndef _RTEMS_SHELL_INTERNAL_h
+#define _RTEMS_SHELL_INTERNAL_h
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+struct shell_topic_tt;
+typedef struct shell_topic_tt shell_topic_t;
+
+struct shell_topic_tt {
+ char *topic;
+ shell_topic_t *next;
+};
+
+
+extern shell_cmd_t * shell_first_cmd;
+extern shell_topic_t * shell_first_topic;
+
+shell_topic_t * shell_lookup_topic(char * topic);
+
+#endif
diff --git a/cpukit/libmisc/shell/shell.c b/cpukit/libmisc/shell/shell.c
index 6eff7adaae..d4008b14d8 100644
--- a/cpukit/libmisc/shell/shell.c
+++ b/cpukit/libmisc/shell/shell.c
@@ -7,8 +7,9 @@
* WORK: fernando.ruiz@ctv.es
* HOME: correo@fernando-ruiz.com
*
- * Thanks at:
- * Chris John
+ * 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$
*/
@@ -25,6 +26,8 @@
#include <rtems/libio_.h>
#include <rtems/system.h>
#include <rtems/shell.h>
+#include <rtems/shellconfig.h>
+#include "internal.h"
#include <termios.h>
#include <string.h>
@@ -35,74 +38,68 @@
#include <errno.h>
#include <pwd.h>
-/* ----------------------------------------------- *
- * This is a stupidity but is cute.
- * ----------------------------------------------- */
-uint32_t new_rtems_name(char * rtems_name) {
- static char b[5];
- sprintf(b,"%-4.4s",rtems_name);
- return rtems_build_name(b[0],b[1],b[2],b[3]);
-}
-/* **************************************************************
- * common linked list of shell commands.
- * Because the help report is very long
- * I have a topic for each command.
+/*
+ * 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
- * Can you see help rtems monitor report?
- * ************************************************************** */
-
-struct shell_topic_tt;
-typedef struct shell_topic_tt shell_topic_t;
-
-struct shell_topic_tt {
- char * topic;
- shell_topic_t * next;
-};
-
+ * help [topic] list the commands for the topic
+ * help [command] help for the command
+ *
+ */
-static shell_cmd_t * shell_first_cmd;
-static shell_topic_t * shell_first_topic;
+shell_cmd_t * shell_first_cmd;
+shell_topic_t * shell_first_topic;
shell_env_t *shell_init_env(shell_env_t *);
-/* ----------------------------------------------- *
- * Using Chain I can reuse the rtems code.
- * I am more comfortable with this, sorry.
- * ----------------------------------------------- */
+/*
+ * 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;
- };
+ 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;
- } else {
+ 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;
+ 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;
+ 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;
@@ -112,37 +109,73 @@ shell_cmd_t * shell_lookup_cmd(char * cmd) {
};
return (shell_cmd_t *) NULL;
}
-/* ----------------------------------------------- */
-shell_cmd_t * shell_add_cmd(char * cmd,
- char * topic,
- char * usage,
- shell_command_t command) {
- int shell_help(int argc,char * argv[]);
- shell_cmd_t * shell_cmd,*shell_pvt;
- if (!shell_first_cmd) {
- shell_first_cmd=(shell_cmd_t *) malloc(sizeof(shell_cmd_t));
- shell_first_cmd->name ="help";
- shell_first_cmd->topic ="help";
- shell_first_cmd->usage ="help [topic] # list of usage of commands";
- shell_first_cmd->command=shell_help;
- shell_first_cmd->alias =(shell_cmd_t *) NULL;
- shell_first_cmd->next =(shell_cmd_t *) NULL;
- shell_add_topic(shell_first_cmd->topic);
- register_cmds();
- };
- 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;
- shell_add_topic(shell_cmd->topic);
- shell_pvt=shell_first_cmd;
- while (shell_pvt->next) shell_pvt=shell_pvt->next;
- return shell_pvt->next=shell_cmd;
+
+/*
+ * 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 ( !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 );
+ }
+
+ register_cmds();
+ }
+
+ 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 );
}
/* ----------------------------------------------- *
* you can make an alias for every command.
@@ -177,111 +210,7 @@ int shell_make_args(char * cmd,
argv[argc]=(char*)NULL;
return *pargc=argc;
}
-/* ----------------------------------------------- *
- * show the help for one command.
- * ----------------------------------------------- */
-int shell_help_cmd(shell_cmd_t * shell_cmd) {
- char * pc;
- int col,line;
- printf("%-10.10s -",shell_cmd->name);
- col=12;
- line=1;
- if (shell_cmd->alias) {
- printf("is an <alias> for command '%s'",shell_cmd->alias->name);
- } else
- if (shell_cmd->usage) {
- pc=shell_cmd->usage;
- while (*pc) {
- switch(*pc) {
- case '\r':break;
- case '\n':putchar('\n');
- col=0;
- break;
- default :putchar(*pc);
- col++;
- break;
- };
- pc++;
- if(col>78) { /* What daring... 78?*/
- if (*pc) {
- putchar('\n');
- col=0;
- };
- };
- if (!col && *pc) {
- printf(" ");
- col=12;line++;
- };
- };
- };
- puts("");
- return line;
-}
-/* ----------------------------------------------- *
- * show the help. The first command implemented.
- * Can you see the header of routine? Known?
- * The same with all the commands....
- * ----------------------------------------------- */
-int shell_help(int argc,char * argv[]) {
- int col,line,arg;
- shell_topic_t *topic;
- shell_cmd_t * shell_cmd=shell_first_cmd;
- if (argc<2) {
- printf("help: ('r' repeat last cmd - 'e' edit last cmd)\n"
- " TOPIC? The topics are\n");
- topic=shell_first_topic;
- col=0;
- while (topic) {
- if (!col){
- col=printf(" %s",topic->topic);
- } else {
- if ((col+strlen(topic->topic)+2)>78){
- printf("\n");
- col=printf(" %s",topic->topic);
- } else {
- col+=printf(", %s",topic->topic);
- };
- };
- topic=topic->next;
- };
- printf("\n");
- return 1;
- };
- line=0;
- for (arg=1;arg<argc;arg++) {
- if (line>16) {
- printf("Press any key to continue...");getchar();
- printf("\n");
- line=0;
- };
- topic=shell_lookup_topic(argv[arg]);
- if (!topic){
- if ((shell_cmd=shell_lookup_cmd(argv[arg]))==NULL) {
- printf("help: topic or cmd '%s' not found. Try <help> alone for a list\n",
- argv[arg]);
- line++;
- } else {
- line+=shell_help_cmd(shell_cmd);
- }
- continue;
- };
- printf("help: list for the topic '%s'\n",argv[arg]);
- line++;
- while (shell_cmd) {
- if (!strcmp(topic->topic,shell_cmd->topic))
- line+=shell_help_cmd(shell_cmd);
- if (line>16) {
- printf("Press any key to continue...");
- getchar();
- printf("\n");
- line=0;
- };
- shell_cmd=shell_cmd->next;
- };
- };
- puts("");
- return 0;
-}
+
/* ----------------------------------------------- *
* TODO: Add improvements. History, edit vi or emacs, ...
* ----------------------------------------------- */
@@ -295,44 +224,52 @@ int shell_scanline(char * line,int size,FILE * in,FILE * out) {
tcdrain(fileno(in));
if (out) tcdrain(fileno(out));
for (;;) {
- line[col]=0;
- c = fgetc(in);
- switch (c) {
- case 0x04:/*Control-d*/
- if (col) break;
- case EOF :return 0;
- case '\n':break;
- case '\f':if (out) fputc('\f',out);
- case 0x03:/*Control-C*/
+ line[col]=0;
+ c = fgetc(in);
+ switch (c) {
+ case 0x04:/*Control-d*/
+ if (col)
+ break;
+ case EOF:
+ return 0;
+ case '\f':
+ if (out)
+ fputc('\f',out);
+ case 0x03:/*Control-C*/
line[0]=0;
- case '\r':if (out) fputc('\n',out);
+ case '\n':
+ case '\r':
+ if (out)
+ fputc('\n',out);
return 1;
- case 127:
- case '\b':if (col) {
- if (out) {
- fputc('\b',out);
- fputc(' ',out);
- fputc('\b',out);
- };
- col--;
+ case 127:
+ case '\b':
+ if (col) {
+ if (out) {
+ fputc('\b',out);
+ fputc(' ',out);
+ fputc('\b',out);
+ }
+ col--;
} else {
- if (out) fputc('\a',out);
- };
+ if (out) fputc('\a',out);
+ }
break;
- default :if (!iscntrl(c)) {
- if (col<size-1) {
- line[col++]=c;
+ default:
+ if (!iscntrl(c)) {
+ if (col<size-1) {
+ line[col++]=c;
if (out) fputc(c,out);
- } else {
- if (out) fputc('\a',out);
- };
- } else {
- if (out)
- if (c=='\a') fputc('\a',out);
- };
- break;
- };
- };
+ } else {
+ if (out) fputc('\a',out);
+ }
+ } else {
+ if (out)
+ if (c=='\a') fputc('\a',out);
+ }
+ break;
+ }
+ }
}
/* ----------------------------------------------- *
* - The shell TASK
@@ -344,18 +281,6 @@ shell_env_t *current_shell_env;
extern char **environ;
-void cat_file(FILE * out,char * name) {
- FILE * fd;
- int c;
- if (out) {
- fd=fopen(name,"r");
- if (fd) {
- while ((c=fgetc(fd))!=EOF) fputc(c,out);
- fclose(fd);
- };
- };
-}
-
void write_file(char * name,char * content) {
FILE * fd;
fd=fopen(name,"w");
@@ -702,11 +627,17 @@ rtems_status_code shell_init (
rtems_id task_id;
rtems_status_code sc;
shell_env_t *shell_env;
+ rtems_name name;
+
+ if ( task_name )
+ 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' );
sc = rtems_task_create(
- new_rtems_name(task_name),
+ name,
task_priority,
- task_stacksize?task_stacksize:RTEMS_MINIMUM_STACK_SIZE,
+ task_stacksize,
RTEMS_DEFAULT_MODES,
RTEMS_LOCAL | RTEMS_FLOATING_POINT,
&task_id
@@ -744,8 +675,8 @@ shell_env_t *shell_init_env(
return NULL;
}
- if (global_shell_env.magic != new_rtems_name("SENV")) {
- global_shell_env.magic = new_rtems_name("SENV");
+ 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;
diff --git a/cpukit/libmisc/shell/shell.h b/cpukit/libmisc/shell/shell.h
index 4e4cb96044..e901cb9c5d 100644
--- a/cpukit/libmisc/shell/shell.h
+++ b/cpukit/libmisc/shell/shell.h
@@ -29,41 +29,46 @@ extern "C" {
typedef int (*shell_command_t)(int argc,char * argv[]);
-struct shell_cmd_tt ;
+struct shell_cmd_tt;
typedef struct shell_cmd_tt shell_cmd_t;
struct shell_cmd_tt {
- char *name;
- char *usage;
- char *topic;
- shell_command_t command;
- shell_cmd_t *alias;
- shell_cmd_t *next;
+ char *name;
+ char *usage;
+ char *topic;
+ shell_command_t command;
+ shell_cmd_t *alias;
+ shell_cmd_t *next;
};
-uint32_t new_rtems_name(char * rtems_name);
+typedef struct {
+ char *name;
+ char *alias;
+} shell_alias_t;
+
shell_cmd_t * shell_lookup_cmd(char * cmd);
-shell_cmd_t * shell_add_cmd(char * cmd,
- char * topic,
- char * usage,
- shell_command_t command);
-shell_cmd_t * shell_alias_cmd(char * cmd, char * alias);
-int shell_make_args(char * cmd,
- int * pargc,
- char * argv[]);
+shell_cmd_t *shell_add_cmd_struct(
+ shell_cmd_t *shell_cmd
+);
-typedef struct {
- rtems_name magic; /* 'S','E','N','V': Shell Environment */
- char * devname;
- char * taskname;
- tcflag_t tcflag;
- /* user extensions */
- int exit_shell; /* logout */
- int forever ; /* repeat login */
- int errorlevel;
- int mdump_adr;
-} shell_env_t;
+shell_cmd_t * shell_add_cmd(
+ char *cmd,
+ char *topic,
+ char *usage,
+ shell_command_t command
+);
+
+shell_cmd_t * shell_alias_cmd(
+ char *cmd,
+ char *alias
+);
+
+int shell_make_args(
+ char * cmd,
+ int * pargc,
+ char * argv[]
+);
int shell_scanline(char * line,int size,FILE * in,FILE * out) ;
void cat_file(FILE * out,char *name);
@@ -93,6 +98,24 @@ rtems_status_code shell_init(
int forever
);
+/*
+ * Things that are useful to external entities developing commands and plugging
+ * them in.
+ */
+int str2int(char * s);
+
+typedef struct {
+ rtems_name magic; /* 'S','E','N','V': Shell Environment */
+ char *devname;
+ char *taskname;
+ tcflag_t tcflag;
+ /* user extensions */
+ int exit_shell; /* logout */
+ int forever ; /* repeat login */
+ int errorlevel;
+ uintptr_t mdump_addr;
+} shell_env_t;
+
rtems_boolean shell_shell_loop(
shell_env_t *shell_env
);
@@ -100,12 +123,6 @@ rtems_boolean shell_shell_loop(
extern shell_env_t global_shell_env;
extern shell_env_t *current_shell_env;
-/*--------*/
-/* cmds.c */
-/*--------*/
-int str2int(char * s);
-void register_cmds(void);
-
#ifdef __cplusplus
}
#endif
diff --git a/cpukit/libmisc/shell/shellconfig.c b/cpukit/libmisc/shell/shellconfig.c
new file mode 100644
index 0000000000..f3448ee693
--- /dev/null
+++ b/cpukit/libmisc/shell/shellconfig.c
@@ -0,0 +1,14 @@
+/*
+ * RTEMS Shell Command Set -- DEFAULT Configuration
+ *
+ * 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$
+ */
+
+#define CONFIGURE_SHELL_COMMANDS_INIT
+#define CONFIGURE_SHELL_COMMANDS_ALL
+
+#include <rtems/shellconfig.h>
diff --git a/cpukit/libmisc/shell/shellconfig.h b/cpukit/libmisc/shell/shellconfig.h
new file mode 100644
index 0000000000..27ca834c25
--- /dev/null
+++ b/cpukit/libmisc/shell/shellconfig.h
@@ -0,0 +1,197 @@
+/*
+ * RTEMS Shell Command Set Configuration
+ *
+ * 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$
+ */
+
+#ifndef _RTEMS_SHELL_CONFIG_h
+#define _RTEMS_SHELL_CONFIG_h
+
+#include <rtems/shell.h>
+
+/*
+ * Externs for all command definition structures
+ */
+extern shell_cmd_t Shell_HELP_Command;
+extern shell_cmd_t Shell_ALIAS_Command;
+extern shell_cmd_t Shell_LOGOFF_Command;
+
+extern shell_cmd_t Shell_MDUMP_Command;
+extern shell_cmd_t Shell_WDUMP_Command;
+extern shell_cmd_t Shell_MEDIT_Command;
+extern shell_cmd_t Shell_MFILL_Command;
+extern shell_cmd_t Shell_MMOVE_Command;
+
+extern shell_cmd_t Shell_DATE_Command;
+extern shell_cmd_t Shell_ID_Command;
+extern shell_cmd_t Shell_TTY_Command;
+extern shell_cmd_t Shell_WHOAMI_Command;
+
+extern shell_cmd_t Shell_PWD_Command;
+extern shell_cmd_t Shell_LS_Command;
+extern shell_cmd_t Shell_CHDIR_Command;
+extern shell_cmd_t Shell_MKDIR_Command;
+extern shell_cmd_t Shell_RMDIR_Command;
+extern shell_cmd_t Shell_CHROOT_Command;
+extern shell_cmd_t Shell_CHMOD_Command;
+extern shell_cmd_t Shell_CAT_Command;
+extern shell_cmd_t Shell_RM_Command;
+extern shell_cmd_t Shell_UMASK_Command;
+
+extern shell_cmd_t Shell_MALLOC_DUMP_Command;
+
+extern shell_cmd_t *Shell_Initial_commands[];
+
+/*
+ * Extern for alias commands
+ */
+extern shell_alias_t Shell_DIR_Alias;
+extern shell_alias_t Shell_CD_Alias;
+extern shell_alias_t Shell_EXIT_Alias;
+
+extern shell_alias_t *Shell_Initial_aliases[];
+
+/*
+ * If we are configured to alias a command, then make sure the underlying command
+ * is configured.
+ */
+
+#if !defined(CONFIGURE_SHELL_COMMANDS_ALL)
+ #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)
+ #define CONFIGURE_SHELL_COMMANDS_CHDIR
+ #endif
+
+ #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)
+ &Shell_DIR_Alias,
+ #endif
+ #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)
+ &Shell_EXIT_Alias,
+ #endif
+
+ /*
+ * User defined shell aliases
+ */
+ #if defined(CONFIGURE_SHELL_USER_ALIASES)
+ CONFIGURE_SHELL_USER_ALIASES
+ #endif
+ NULL
+ };
+
+ shell_cmd_t *Shell_Initial_commands[] = {
+ /*
+ * General comamnds that should be present
+ */
+ &Shell_HELP_Command,
+ &Shell_ALIAS_Command,
+
+ /*
+ * Common commands that can be optional
+ */
+ #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)
+ &Shell_ID_Command,
+ #endif
+ #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)
+ &Shell_WHOAMI_Command,
+ #endif
+ #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)
+ &Shell_MDUMP_Command,
+ #endif
+ #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)
+ &Shell_MEDIT_Command,
+ #endif
+ #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)
+ &Shell_MMOVE_Command,
+ #endif
+
+ /*
+ * File and directory commands
+ */
+ #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)
+ &Shell_LS_Command,
+ #endif
+ #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)
+ &Shell_MKDIR_Command,
+ #endif
+ #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)
+ &Shell_CHROOT_Command,
+ #endif
+ #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)
+ &Shell_CAT_Command,
+ #endif
+ #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)
+ &Shell_UMASK_Command,
+ #endif
+
+ /*
+ * Malloc family commands
+ */
+ #if defined(CONFIGURE_SHELL_COMMANDS_ALL) || defined(CONFIGURE_SHELL_COMMAND_MALLOC_DUMP)
+ &Shell_MALLOC_DUMP_Command,
+ #endif
+
+ /*
+ * User defined shell commands
+ */
+ #if defined(CONFIGURE_SHELL_USER_COMMANDS)
+ CONFIGURE_SHELL_USER_COMMANDS
+ #endif
+ NULL
+ };
+#endif
+
+#endif
diff --git a/cpukit/libmisc/shell/str2int.c b/cpukit/libmisc/shell/str2int.c
new file mode 100644
index 0000000000..851e9224ad
--- /dev/null
+++ b/cpukit/libmisc/shell/str2int.c
@@ -0,0 +1,95 @@
+/*
+ * Author: Fernando RUIZ CASAS
+ * 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 <rtems/shell.h>
+#include "internal.h"
+
+/*
+ * str to int "0xaffe" "0b010010" "0123" "192939"
+ */
+int str2int(char * s) {
+ int sign=1;
+ int base=10;
+ int value=0;
+ int digit;
+
+ if (!s) return 0;
+ if (*s) {
+ if (*s=='-') {
+ sign=-1;
+ s++;
+ if (!*s) return 0;
+ }
+ if (*s=='0') {
+ s++;
+ switch(*s) {
+ case 'x':
+ case 'X':
+ s++;
+ base=16;
+ break;
+ case 'b':
+ case 'B':
+ s++;
+ base=2;
+ break;
+ default:
+ base=8;
+ break;
+ }
+ }
+ while (*s) {
+ switch(*s) {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ digit=*s-'0';
+ break;
+ case 'A':
+ case 'B':
+ case 'C':
+ case 'D':
+ case 'E':
+ case 'F':
+ digit=*s-'A'+10;
+ break;
+ case 'a':
+ case 'b':
+ case 'c':
+ case 'd':
+ case 'e':
+ case 'f':
+ digit=*s-'a'+10;
+ break;
+ default:
+ return value*sign;
+ }
+ if (digit>base)
+ return value*sign;
+ value=value*base+digit;
+ s++;
+ }
+ }
+ return value*sign;
+}