Simple embedded shell with runtime pluggable commands.

Dependents:   DataBus2018

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

Revision:
19:bf5f5ea4e762
Parent:
18:2b5ed529ab37
Child:
20:53f0b5dc30f9
--- a/SimpleShell.cpp	Fri Dec 21 20:02:56 2018 +0000
+++ b/SimpleShell.cpp	Sat Dec 22 20:27:54 2018 +0000
@@ -37,6 +37,8 @@
     attach(callback(this, &SimpleShell::pwd), "pwd");
     attach(callback(this, &SimpleShell::cat), "cat");
     attach(callback(this, &SimpleShell::cd), "cd");
+    attach(callback(this, &SimpleShell::rm), "rm");
+    attach(callback(this, &SimpleShell::touch), "touch");
     attach(callback(this, &SimpleShell::ls), "ls");
 }
 
@@ -107,6 +109,39 @@
     return;
 }
 
+
+void SimpleShell::rm(int argc, char **argv)
+{
+    if (argc >= 2) {
+        for (int i=1; i < argc; i++) {
+            if (remove(canon(argv[i]))) {
+                printf("%s: cannot remove\n", argv[i]);
+            }
+        }
+    } else {
+        puts("usage: rm [file1 [file2 ...]]");
+    }
+}
+
+
+void SimpleShell::touch(int argc, char **argv)
+{
+    FILE *fp;
+
+    if (argc >= 2) {
+        for (int i=1; i < argc; i++) {
+            if ((fp = fopen(canon(argv[i]), "w")) != NULL) {
+                fclose(fp);
+            } else {
+                printf("%s: cannot touch\n", argv[1]);
+            }
+        }
+    } else {
+        puts("usage: touch [file1 [file2 ...]]");
+    }
+}
+
+
 void SimpleShell::cat(int argc, char **argv)
 {
     FILE *fp;