Simple embedded shell with runtime pluggable commands.
Implements a simple unix-like shell for embedded systems with a pluggable command architecture.
Diff: SimpleShell.h
- Revision:
- 35:1a8c5fce8895
- Parent:
- 31:27e8130a0d8f
--- a/SimpleShell.h Fri Dec 28 20:34:58 2018 +0000 +++ b/SimpleShell.h Mon Dec 31 23:34:17 2018 +0000 @@ -2,6 +2,7 @@ #define __SIMPLESHELL_H #include "mbed.h" +#include <vector> /** A simple, flexible, embedded shell with dynamically added shell commands. * Shell commands must be: void(int argc, char **argv) @@ -72,10 +73,31 @@ char *canon(char *path); /** Get the basename of specified path. + * For example, basename("/foo/bar/whee") returns "whee" * @param path is the path specification, assumed to be canonicalized * @returns the basename of the path */ char *basename(char *path); + + /** Get the parent directory of specified path. + * For example, basename("/foo/bar/whee") returns "/foo/bar" + * @param path is the path specification, assumed to be canonicalized + * @returns the parent directory of the path + */ + char *dirname(char *path); + + /** Runs a callback on each matching file in the specified pattern + * @param pattern is a filename pattern ala Linux fnmatch(3) + * @param cb is the int(char*) function on which each file match is called + * @return false if cb returns non-zero on any file, true otherwise + * + * @code + * if (foreach("/test/\*.txt", callback(remove)) { + * printf("error!\n"); + * } + * @endcode + */ + char *foreach(char *pattern); private: /// Maximum number of commands @@ -83,6 +105,9 @@ /// Maximum command line buffer size static const int MAXBUF=64; + + /// Maximum filename size + static const int MAXNAMESIZE=64; /// internal struct to contain a single command typedef struct { @@ -90,6 +115,9 @@ callback_t cb; } command_entry_t; + /// internal file list for wildcards + typedef vector<char*> filelist_t; + /** finds and eturns the callback for a command * @return Callback to a function returning void */