Added the $? command to the shell.
This commit is contained in:
parent
29a1b68933
commit
8b7188e6a4
|
@ -1,6 +1,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <libmaxsi/platform.h>
|
#include <libmaxsi/platform.h>
|
||||||
#include <libmaxsi/process.h>
|
#include <libmaxsi/process.h>
|
||||||
|
@ -9,6 +10,8 @@
|
||||||
|
|
||||||
using namespace Maxsi;
|
using namespace Maxsi;
|
||||||
|
|
||||||
|
int status = 0;
|
||||||
|
|
||||||
void command()
|
void command()
|
||||||
{
|
{
|
||||||
printf("root@sortix / # ");
|
printf("root@sortix / # ");
|
||||||
|
@ -44,24 +47,15 @@ void command()
|
||||||
|
|
||||||
if ( command[0] == '\0' ) { return; }
|
if ( command[0] == '\0' ) { return; }
|
||||||
|
|
||||||
if ( String::Compare(command, "$$") == 0 ) { printf("%u\n", Process::GetPID()); return; }
|
if ( String::Compare(command, "$?") == 0 ) { printf("%u\n", status); status = 0; return; }
|
||||||
if ( String::Compare(command, "$PPID") == 0 ) { printf("%u\n", Process::GetParentPID()); return; }
|
if ( String::Compare(command, "$$") == 0 ) { printf("%u\n", Process::GetPID()); status = 0; return; }
|
||||||
if ( String::Compare(command, "exit") == 0 ) { exit(0); return; }
|
if ( String::Compare(command, "$PPID") == 0 ) { printf("%u\n", Process::GetParentPID()); status = 0; return; }
|
||||||
|
|
||||||
pid_t child = fork();
|
|
||||||
if ( child < 0 ) { printf("fork failed\n"); return; }
|
|
||||||
if ( child != 0 )
|
|
||||||
{
|
|
||||||
int status;
|
|
||||||
pid_t childpid = wait(&status);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
const char* argv[256];
|
const char* argv[256];
|
||||||
argv[argc++] = command;
|
argv[0] = NULL;
|
||||||
|
|
||||||
bool lastwasspace = false;
|
bool lastwasspace = true;
|
||||||
for ( size_t i = 0; i <= commandused; i++ )
|
for ( size_t i = 0; i <= commandused; i++ )
|
||||||
{
|
{
|
||||||
switch ( command[i] )
|
switch ( command[i] )
|
||||||
|
@ -78,6 +72,23 @@ void command()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !argv[0] ) { return; }
|
||||||
|
|
||||||
|
if ( strcmp(argv[0], "exit") == 0 )
|
||||||
|
{
|
||||||
|
const char* status = "1";
|
||||||
|
if ( 1 < argc ) { status = argv[1]; }
|
||||||
|
exit(atoi(status));
|
||||||
|
}
|
||||||
|
|
||||||
|
pid_t child = fork();
|
||||||
|
if ( child < 0 ) { printf("fork failed\n"); return; }
|
||||||
|
if ( child != 0 )
|
||||||
|
{
|
||||||
|
pid_t childpid = wait(&status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Replace the current process with another process image.
|
// Replace the current process with another process image.
|
||||||
Process::Execute(argv[0], argc, argv);
|
Process::Execute(argv[0], argc, argv);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue