summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc/shell
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2009-11-18 00:09:21 +0000
committerChris Johns <chrisj@rtems.org>2009-11-18 00:09:21 +0000
commit05404983e2eedd4801abc7433de57db59a51ad85 (patch)
tree2500c9f71eaaf7bbb83469604de22190e60e95d9 /cpukit/libmisc/shell
parent2009-11-17 Ralf Corsépius <ralf.corsepius@rtems.org> (diff)
downloadrtems-05404983e2eedd4801abc7433de57db59a51ad85.tar.bz2
2009-11-18 Chris Johns <chrisj@rtems.org>
* libmisc/shell/main_getenv.c, libmisc/shell/main_setenv.c, libmisc/shell/main_unsetenv.c: New. The shell can now play with environment variables. * libmisc/Makefile.am, libmisc/shell/shellconfig.h: Add setenv, getenv, and unsetenv to the shell.
Diffstat (limited to 'cpukit/libmisc/shell')
-rw-r--r--cpukit/libmisc/shell/main_getenv.c49
-rw-r--r--cpukit/libmisc/shell/main_setenv.c75
-rw-r--r--cpukit/libmisc/shell/main_unsetenv.c43
-rw-r--r--cpukit/libmisc/shell/shellconfig.h18
4 files changed, 185 insertions, 0 deletions
diff --git a/cpukit/libmisc/shell/main_getenv.c b/cpukit/libmisc/shell/main_getenv.c
new file mode 100644
index 0000000000..d18c301ee3
--- /dev/null
+++ b/cpukit/libmisc/shell/main_getenv.c
@@ -0,0 +1,49 @@
+/*
+ * Get an environment vairable.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_getenv(int argc, char *argv[])
+{
+ char* string;
+
+ if (argc != 2)
+ {
+ printf ("error: only argument is the variable name\n");
+ return 1;
+ }
+
+ string = getenv (argv[1]);
+
+ if (!string)
+ {
+ printf ("error: %s not found\n", argv[1]);
+ return 1;
+ }
+
+ printf ("%s\n", string);
+
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_GETENV_Command = {
+ "getenv", /* name */
+ "getenv [var]", /* usage */
+ "misc", /* topic */
+ rtems_shell_main_getenv, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_setenv.c b/cpukit/libmisc/shell/main_setenv.c
new file mode 100644
index 0000000000..7164c27f9a
--- /dev/null
+++ b/cpukit/libmisc/shell/main_setenv.c
@@ -0,0 +1,75 @@
+/*
+ * Set an environment vairable.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_setenv(int argc, char *argv[])
+{
+ char* env = NULL;
+ char* string = NULL;
+ int len = 0;
+ int arg;
+ char* p;
+
+ if (argc <= 2)
+ {
+ printf ("error: no variable or string\n");
+ return 1;
+ }
+
+ env = argv[1];
+
+ for (arg = 2; arg < argc; arg++)
+ len += strlen (argv[arg]);
+
+ len += argc - 2 - 1;
+
+ string = malloc (len + 1);
+
+ if (!string)
+ {
+ printf ("error: no memory\n");
+ return 1;
+ }
+
+ for (arg = 2, p = string; arg < argc; arg++)
+ {
+ strcpy (p, argv[arg]);
+ p += strlen (argv[arg]);
+ if (arg < (argc - 1))
+ {
+ *p = ' ';
+ p++;
+ }
+ }
+
+ if (setenv (env, string, 1) < 0)
+ {
+ printf ("error: %s\n", strerror (errno));
+ return 1;
+ }
+
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_SETENV_Command = {
+ "setenv", /* name */
+ "setenv [var] [string]", /* usage */
+ "misc", /* topic */
+ rtems_shell_main_setenv, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/main_unsetenv.c b/cpukit/libmisc/shell/main_unsetenv.c
new file mode 100644
index 0000000000..91d9dac7a4
--- /dev/null
+++ b/cpukit/libmisc/shell/main_unsetenv.c
@@ -0,0 +1,43 @@
+/*
+ * Unset an environment vairable.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/shell.h>
+#include "internal.h"
+
+int rtems_shell_main_unsetenv(int argc, char *argv[])
+{
+ if (argc != 2)
+ {
+ printf ("error: only argument is the variable name\n");
+ return 1;
+ }
+
+ if (unsetenv (argv[1]) < 0)
+ {
+ printf ("error: %s\n", strerror (errno));
+ return 1;
+ }
+
+ return 0;
+}
+
+rtems_shell_cmd_t rtems_shell_UNSETENV_Command = {
+ "unsetenv", /* name */
+ "unsetenv [var]", /* usage */
+ "misc", /* topic */
+ rtems_shell_main_unsetenv, /* command */
+ NULL, /* alias */
+ NULL /* next */
+};
diff --git a/cpukit/libmisc/shell/shellconfig.h b/cpukit/libmisc/shell/shellconfig.h
index 1410430440..3d731aa0ef 100644
--- a/cpukit/libmisc/shell/shellconfig.h
+++ b/cpukit/libmisc/shell/shellconfig.h
@@ -23,6 +23,9 @@ extern rtems_shell_cmd_t rtems_shell_HELP_Command;
extern rtems_shell_cmd_t rtems_shell_ALIAS_Command;
extern rtems_shell_cmd_t rtems_shell_TIME_Command;
extern rtems_shell_cmd_t rtems_shell_LOGOFF_Command;
+extern rtems_shell_cmd_t rtems_shell_SETENV_Command;
+extern rtems_shell_cmd_t rtems_shell_GETENV_Command;
+extern rtems_shell_cmd_t rtems_shell_UNSETENV_Command;
extern rtems_shell_cmd_t rtems_shell_MDUMP_Command;
extern rtems_shell_cmd_t rtems_shell_WDUMP_Command;
@@ -195,6 +198,21 @@ extern rtems_shell_filesystems_t *rtems_shell_Mount_filesystems[];
defined(CONFIGURE_SHELL_COMMAND_LOGOFF)
&rtems_shell_LOGOFF_Command,
#endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_SETENV)) || \
+ defined(CONFIGURE_SHELL_COMMAND_SETENV)
+ &rtems_shell_SETENV_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_GETENV)) || \
+ defined(CONFIGURE_SHELL_COMMAND_GETENV)
+ &rtems_shell_GETENV_Command,
+ #endif
+ #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+ !defined(CONFIGURE_SHELL_NO_COMMAND_CRLENV)) || \
+ defined(CONFIGURE_SHELL_COMMAND_UNSETENV)
+ &rtems_shell_UNSETENV_Command,
+ #endif
/*
* Memory printing/modification family commands