Simple embedded shell with runtime pluggable commands.
Implements a simple unix-like shell for embedded systems with a pluggable command architecture.
Revision 4:8b8fa59d0015, committed 2018-12-02
- Comitter:
- shimniok
- Date:
- Sun Dec 02 17:20:15 2018 +0000
- Parent:
- 3:ebb4893f033d
- Child:
- 5:8f486f4d29d3
- Commit message:
- Initial implementation of command lookup
Changed in this revision
SimpleShell.cpp | Show annotated file Show diff for this revision Revisions of this file |
SimpleShell.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SimpleShell.cpp Sun Dec 02 17:14:28 2018 +0000 +++ b/SimpleShell.cpp Sun Dec 02 17:20:15 2018 +0000 @@ -8,17 +8,21 @@ void SimpleShell::run() { bool done=false; + Callback<void()> cb; + strcpy(_cwd, "/log"); printf("Type help for assistance.\n"); while (!done) { printPrompt(); readCommand(); - //cb = findCommand(); - //if cb - // status = cb.call(); - // done = status == EXIT - //else error not found + if (cb = findCommand()) { + printf("found\n"); + // status = cb.call(); + // done = status == EXIT + } else { + printf("command not found\n"); + } } puts("exiting shell\n"); @@ -46,6 +50,13 @@ { Callback<void()> cb=NULL; + for (int i=0; i < lookupEnd; i++) { + if (strncmp(cmd, lookup[i].command, MAXBUF) == 0) { + cb = lookup[i].cb; + break; + } + } + return cb; }
--- a/SimpleShell.h Sun Dec 02 17:14:28 2018 +0000 +++ b/SimpleShell.h Sun Dec 02 17:20:15 2018 +0000 @@ -15,7 +15,7 @@ Callback<void()> findCommand(); private: - static const int MAXBUF=128; + static const int MAXBUF=32; static const int MAXLOOKUP=32; void printPrompt(void); void readCommand();