Simple embedded shell with runtime pluggable commands.

Dependents:   DataBus2018

Implements a simple unix-like shell for embedded systems with a pluggable command architecture.

Revision:
29:8d4132274445
Parent:
28:753db82debb1
Child:
30:35522ea06236
--- a/SimpleShell.cpp	Wed Dec 26 15:51:42 2018 +0000
+++ b/SimpleShell.cpp	Wed Dec 26 15:56:05 2018 +0000
@@ -16,10 +16,16 @@
 #define TAIL    0x7e
 
 
-SimpleShell::SimpleShell()
+SimpleShell::SimpleShell(char *home)
 {
     lookupEnd = 0;
 
+    // Set home directory
+    strncpy(_home, canon(home), MAXBUF);
+
+    // Set current working directory
+    strncpy(_cwd, _home, MAXBUF);
+
     // Built-in shell commands
     command(callback(this, &SimpleShell::help), "help");
     command(callback(this, &SimpleShell::pwd), "pwd");
@@ -117,7 +123,9 @@
 
 void SimpleShell::cd(int argc, char **argv)
 {
-    if (argc == 2) {
+    if (argc == 1) {
+        strncpy(_cwd, _home, MAXBUF);
+    } else if (argc == 2) {
         strncpy(_cwd, canon(argv[1]), MAXBUF);
     } else {
         puts("usage: cd directory");
@@ -282,9 +290,6 @@
     //int status; // TODO implement command status return
     std::string x;
 
-    // Set current working directory
-    strncpy(_cwd, "/etc", MAXBUF);
-
     printf("Type help for assistance.\n");
     help(0, NULL);
     while (!done) {