Simple embedded shell with runtime pluggable commands.
Implements a simple unix-like shell for embedded systems with a pluggable command architecture.
Diff: SimpleShell.cpp
- Revision:
- 5:8f486f4d29d3
- Parent:
- 4:8b8fa59d0015
- Child:
- 8:41b7274a9753
- Child:
- 10:c3faa7ffd23b
--- 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