#include #include #include #include #include #include "Integrated.h" #include "Pish.h" // Main function for Pish program void Pish(void) { CommandStruct command; command.argc = 0; int forkPID; while (1) { ParseInput(GetInput(), command); IntegratedCheck(command.argv[0]); forkPID = fork(); // Child if (forkPID == 0) { // This is the child process // Setup the child's process environment here // E.g., where is standard I/O, how to handle signals? // TODO: Adjust Execute() to handle CommandStruct Execute(command.argv[0]); // exec does not return if it succeeds printf("ERROR: Could not execute %s\n", command.argv[0]); exit(1); } // Parent else { // This is the parent process; Wait for the child to finish // Removed due to potentially useless // int pid = forkPID; // wait(&pid); wait(&forkPID); } // TODO: Remove break when while loop doesn't break program break; } } // Executes a command to the system void Execute(char* command) { system(command); } // Prints a prompt and then reads a command from the terminal char* GetInput(void) { char prompt = '$'; char *commandLine; printf("%c ", prompt); scanf("%[^\n]", commandLine); return commandLine; } void ParseInput(char* inputString, CommandStruct command) { //Parse command char* token = strtok(inputString, " "); while(token != NULL) { //This only holds 1 command at a time then it overrides //Will need modified token = strtok(NULL, " "); } }