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:
- 16:f2b9b7b2c71e
- Parent:
- 15:242626d8d104
- Child:
- 17:0739cb2f1930
--- a/SimpleShell.cpp Wed Dec 19 18:25:12 2018 +0000 +++ b/SimpleShell.cpp Wed Dec 19 18:42:25 2018 +0000 @@ -22,6 +22,7 @@ // Built-in shell commands attach(callback(this, &SimpleShell::help), "help"); attach(callback(this, &SimpleShell::pwd), "pwd"); + attach(callback(this, &SimpleShell::cat), "cat"); } @@ -42,6 +43,32 @@ } +void SimpleShell::cat(int argc, char **argv) +{ + FILE *fp; + //int status=0; + char *buf = new char[MAXBUF]; + + for (int i=1; i < argc; i++) { + //resolveDirectory(path, arg); + if ((fp = fopen(argv[i], "r")) != NULL) { + while (!feof(fp)) { + fgets(buf, MAXBUF-1, fp); + fputs(buf, stdout); + } + fclose(fp); + } else { + fputs(argv[i], stdout); + fputs(": No such file\n", stdout); + //status = 1; + } + } + delete[] buf; + + return; +} + + void SimpleShell::run() { bool done=false;