Simple embedded shell with runtime pluggable commands.
Implements a simple unix-like shell for embedded systems with a pluggable command architecture.
Revision 17:0739cb2f1930, committed 2018-12-19
- Comitter:
- shimniok
- Date:
- Wed Dec 19 19:02:17 2018 +0000
- Parent:
- 16:f2b9b7b2c71e
- Child:
- 18:2b5ed529ab37
- Commit message:
- implemented built-in change dir (cd)
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Path.h Wed Dec 19 19:02:17 2018 +0000 @@ -0,0 +1,25 @@ +#ifndef __PATH_H +#define __PATH_H + +class Path { +public: + /// Create new path object from C string + Path(char *s); + + /// Set new path from C string + char *set(char *s); // make operator + + /// Change path to its parent directory + char *up(); + + /// Change path to a subdirectory + char *down(char *); + + /// Return C string representation of path + char *c_str(); + +private: + list<char *> p; +}; + +#endif \ No newline at end of file
--- a/SimpleShell.cpp Wed Dec 19 18:42:25 2018 +0000 +++ b/SimpleShell.cpp Wed Dec 19 19:02:17 2018 +0000 @@ -23,6 +23,7 @@ attach(callback(this, &SimpleShell::help), "help"); attach(callback(this, &SimpleShell::pwd), "pwd"); attach(callback(this, &SimpleShell::cat), "cat"); + attach(callback(this, &SimpleShell::cd), "cd"); } @@ -36,6 +37,17 @@ } +void SimpleShell::cd(int argc, char **argv) +{ + if (argc == 2) { + strncpy(_cwd, argv[1], MAXBUF); + } else { + puts("usage: cd <directory>"); + } + return; +} + + void SimpleShell::pwd(int argc, char **argv) { puts(_cwd);
--- a/SimpleShell.h Wed Dec 19 18:42:25 2018 +0000 +++ b/SimpleShell.h Wed Dec 19 19:02:17 2018 +0000 @@ -68,6 +68,9 @@ /// Built-in shell command to display list of commands void help(int argc, char **argv); + /// Change current directory + void cd(int argc, char **argv); + /// Built-in shell command to print working directory void pwd(int argc, char **argv);