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.cpp
- Committer:
- shimniok
- Date:
- 2018-12-02
- Revision:
- 1:998a7ed04f10
- Parent:
- 0:49820d5a38c9
- Child:
- 2:4f0affdb7db9
File content as of revision 1:998a7ed04f10:
#include "SimpleShell.h"
SimpleShell::SimpleShell()
{
}
void SimpleShell::run()
{
bool done=false;
strcpy(_cwd, "/log");
printf("Type help for assistance.\n");
while (!done) {
printPrompt();
readCommand();
//this.doCommand(cmdline);
}
puts("exiting shell\n");
return;
}
void SimpleShell::attach(Callback<void()> cb, char *command) {
}
void SimpleShell::printPrompt()
{
fputc('(', stdout);
fputs(_cwd, stdout);
fputs(")# ", stdout);
}
void SimpleShell::readCommand()
{
int i=0;
char c;
bool done = false;
memset(cmd, 0, MAXBUF);
do {
cmd[i] = 0;
c = fgetc(stdin);
if (c == '\r') { // if return is hit, we're done, don't add \r to cmd
done = true;
} else if (i < MAXBUF-1) {
if (c == 0x7f || c == '\b') { // backspace or delete
if (i > 0) { // if we're at the beginning, do nothing
i--;
fputs("\b \b", stdout);
}
} else {
fputc(c, stdout);
cmd[i++] = c;
}
}
} while (!done);
fputc('\n', stdout);
}