2011-08-27 17:03:39 -04:00
|
|
|
#include <stdio.h>
|
2011-09-21 14:52:29 -04:00
|
|
|
#include <libmaxsi/platform.h>
|
2011-08-27 17:03:39 -04:00
|
|
|
#include <libmaxsi/process.h>
|
|
|
|
#include <libmaxsi/sortix-keyboard.h>
|
2011-09-21 14:52:29 -04:00
|
|
|
#include <libmaxsi/string.h>
|
2011-08-27 17:03:39 -04:00
|
|
|
|
|
|
|
using namespace Maxsi;
|
|
|
|
|
|
|
|
void command()
|
|
|
|
{
|
|
|
|
printf("root@sortix / # ");
|
|
|
|
|
|
|
|
const size_t commandsize = 128;
|
|
|
|
char command[commandsize + 1];
|
|
|
|
size_t commandused = 0;
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
unsigned method = System::Keyboard::POLL;
|
2011-10-26 18:05:20 -04:00
|
|
|
uint32_t codepoint = System::Keyboard::ReceiveKeystroke(method);
|
2011-08-27 17:03:39 -04:00
|
|
|
|
|
|
|
if ( codepoint == 0 ) { continue; }
|
|
|
|
if ( codepoint & Maxsi::Keyboard::DEPRESSED ) { continue; }
|
|
|
|
if ( codepoint >= 0x80 ) { continue; }
|
|
|
|
|
|
|
|
if ( codepoint == '\b' )
|
|
|
|
{
|
|
|
|
if ( 0 < commandused ) { printf("\b"); commandused--; }
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( commandsize <= commandused && codepoint != '\n' ) { continue; }
|
|
|
|
|
|
|
|
char msg[2]; msg[0] = codepoint; msg[1] = '\0';
|
|
|
|
printf(msg);
|
|
|
|
|
|
|
|
if ( codepoint == '\n' ) { command[commandused] = '\0'; break; }
|
|
|
|
|
|
|
|
command[commandused++] = codepoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( command[0] == '\0' ) { return; }
|
|
|
|
|
2011-09-21 14:52:29 -04:00
|
|
|
if ( String::Compare(command, "$$") == 0 ) { printf("%u\n", Process::GetPID()); return; }
|
|
|
|
if ( String::Compare(command, "$PPID") == 0 ) { printf("%u\n", Process::GetParentPID()); return; }
|
|
|
|
|
2011-08-27 17:03:39 -04:00
|
|
|
// Replace the current process with another process image.
|
|
|
|
Process::Execute(command, 0, NULL);
|
|
|
|
|
|
|
|
// This is clever. This only happens if the program didn't change.
|
|
|
|
printf("%s: command not found\n", command);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
while ( true ) { command(); }
|
|
|
|
}
|
|
|
|
|