Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
SimpleShell Class Reference
A simple, flexible, embedded shell with dynamically added shell commands. More...
#include <SimpleShell.h>
Public Types | |
| typedef Callback< void(int, char **) | callback_t ) |
| Callback type used for shell commands. | |
Public Member Functions | |
| SimpleShell (char *home) | |
| Create a new shell instance. | |
| void | run () |
| Call this to run the shell. | |
| void | command (callback_t cb, char *command) |
| Adds a shell command. | |
| bool | haswildcard (char *s) |
| Determine if the specified string includes a shell wildcard. | |
| char * | canon (char *path) |
| Canonicalize path following unix-style convention. | |
| char * | basename (char *path) |
| Get the basename of specified path. | |
| char * | dirname (char *path) |
| Get the parent directory of specified path. | |
| char * | foreach (char *pattern) |
| Runs a callback on each matching file in the specified pattern. | |
Detailed Description
A simple, flexible, embedded shell with dynamically added shell commands.
Shell commands must be: void(int argc, char **argv) Built-in shell commands include: help: display list of commands cd: Change current directory pwd: print working directory ls: list files in directory rm: remove a file touch: create a file cat: display contents of file send: send a file with a simple file transfer protocol.
#include "SimpleShell.h" void helloworld(int argc, char **argv) { printf("Hello world!\n"); } int main() { SimpleShell sh; sh.attach(helloworld, "test"); sh.run(); }
Definition at line 32 of file SimpleShell.h.
Member Typedef Documentation
| typedef Callback<void(int,char**) callback_t) |
Callback type used for shell commands.
Definition at line 36 of file SimpleShell.h.
Constructor & Destructor Documentation
| SimpleShell | ( | char * | home ) |
Create a new shell instance.
Definition at line 20 of file SimpleShell.cpp.
Member Function Documentation
| char * basename | ( | char * | path ) |
Get the basename of specified path.
For example, basename("/foo/bar/whee") returns "whee"
- Parameters:
-
path is the path specification, assumed to be canonicalized
- Returns:
- the basename of the path
Definition at line 106 of file SimpleShell.cpp.
| char * canon | ( | char * | path ) |
Canonicalize path following unix-style convention.
The specified path can be absolute or relative path names. If relative, the path is appended to cwd.
- Parameters:
-
path is the specified path
- Returns:
- canonicalized path name
Definition at line 51 of file SimpleShell.cpp.
| void command | ( | callback_t | cb, |
| char * | command | ||
| ) |
Adds a shell command.
- Parameters:
-
cb is the callback function that implements the command command is the string used to invoke the command in the shell sh.attach(helloworld, "test");
Definition at line 425 of file SimpleShell.cpp.
| char * dirname | ( | char * | path ) |
Get the parent directory of specified path.
For example, basename("/foo/bar/whee") returns "/foo/bar"
- Parameters:
-
path is the path specification, assumed to be canonicalized
- Returns:
- the parent directory of the path
Definition at line 188 of file SimpleShell.cpp.
| char * foreach | ( | char * | pattern ) |
Runs a callback on each matching file in the specified pattern.
- Parameters:
-
pattern is a filename pattern ala Linux fnmatch(3) cb is the int(char*) function on which each file match is called
- Returns:
- false if cb returns non-zero on any file, true otherwise
if (foreach("/test/\*.txt", callback(remove)) { printf("error!\n"); }
Definition at line 257 of file SimpleShell.cpp.
| bool haswildcard | ( | char * | s ) |
Determine if the specified string includes a shell wildcard.
- Parameters:
-
s is the string to check for a wildcard character
- Returns:
- true or false
Definition at line 42 of file SimpleShell.cpp.
| void run | ( | ) |
Call this to run the shell.
- Note:
- The shell can be run in a new thread. Be sure to give it enough stack space.
SimpleShell sh; sh.run(); thread.start(callback(&sh, &SimpleShell::run));
Definition at line 399 of file SimpleShell.cpp.
Generated on Wed Jul 13 2022 20:07:23 by
1.7.2