Simple embedded shell with runtime pluggable commands.

Dependents:   DataBus2018

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

Files at this revision

API Documentation at this revision

Comitter:
shimniok
Date:
Sun Dec 02 17:33:07 2018 +0000
Parent:
4:8b8fa59d0015
Child:
6:4da092220ba8
Commit message:
ignore blank command

Changed in this revision

SimpleShell.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/SimpleShell.cpp	Sun Dec 02 17:20:15 2018 +0000
+++ b/SimpleShell.cpp	Sun Dec 02 17:33:07 2018 +0000
@@ -1,4 +1,5 @@
 #include "SimpleShell.h"
+#include <ctype.h>
 
 SimpleShell::SimpleShell()
 {
@@ -9,6 +10,7 @@
 {
     bool done=false;
     Callback<void()> cb;
+    int status; // TODO implement command status return
     
     strcpy(_cwd, "/log");
 
@@ -16,12 +18,12 @@
     while (!done) {
         printPrompt();
         readCommand();
-        if (cb = findCommand()) {
-            printf("found\n");
-            //  status = cb.call();
-            //  done = status == EXIT
-        } else {
-            printf("command not found\n");
+        if (cmd[0]) { // skip blank command
+            if (cb = findCommand()) {
+                cb.call();
+            } else {
+                printf("command <%s> not found\n", cmd);
+            }
         }
     }
     puts("exiting shell\n");
@@ -98,5 +100,12 @@
     } while (!done);
     fputc('\n', stdout);
 
+    // chomp
+    for (int j=i; j >= 0; j--) {
+        if (isspace(cmd[j])) {
+            cmd[j] = '\0';
+        }
+    }
+
     return;
 }
\ No newline at end of file