diff --git a/include/Common.h b/include/Common.h index c88b51b..7b217a3 100755 --- a/include/Common.h +++ b/include/Common.h @@ -2,7 +2,7 @@ #define COMMON_H typedef struct CommandStruct { - char** argv; + char* argv[100]; // Max 100 commands int argc; } CommandStruct; diff --git a/include/Pish.h b/include/Pish.h index 8242c08..baca03e 100644 --- a/include/Pish.h +++ b/include/Pish.h @@ -6,6 +6,6 @@ void Pish(void); void Execute(char* command); char* GetInput(void); -void ParseInput(char* inputString, CommandStruct command); +void ParseInput(char* inputString, CommandStruct* command); #endif diff --git a/src/Pish.c b/src/Pish.c index adfbba9..7566cce 100644 --- a/src/Pish.c +++ b/src/Pish.c @@ -9,13 +9,16 @@ // Main function for Pish program void Pish(void) { - CommandStruct command; - command.argc = 0; + CommandStruct commandObject = {"", 0}; + CommandStruct* command = &commandObject; + char* inputStr; int forkPID; while (1) { - ParseInput(GetInput(), command); - IntegratedCheck(command.argv[0]); + inputStr = GetInput(); + ParseInput(inputStr, command); + IntegratedCheck(command->argv[0]); + printf("Successfully passed input phase\n"); forkPID = fork(); // Child if (forkPID == 0) @@ -24,9 +27,10 @@ void Pish(void) // 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]); + printf("Executing in fork...\n"); + Execute(command->argv[0]); // exec does not return if it succeeds - printf("ERROR: Could not execute %s\n", command.argv[0]); + printf("ERROR: Could not execute %s\n", command->argv[0]); exit(1); } // Parent @@ -36,6 +40,7 @@ void Pish(void) // Removed due to potentially useless // int pid = forkPID; // wait(&pid); + printf("Waiting for fork...\n"); wait(&forkPID); } // TODO: Remove break when while loop doesn't break program @@ -61,14 +66,19 @@ char* GetInput(void) return commandLine; } -void ParseInput(char* inputString, CommandStruct command) +void ParseInput(char* inputString, CommandStruct* command) { //Parse command + int* count = &(command->argc); char* token = strtok(inputString, " "); - while(token != NULL) + command->argv[*count] = token; + *count++; + while (token != NULL) { - //This only holds 1 command at a time then it overrides - //Will need modified - token = strtok(NULL, " "); + //This only holds 1 command at a time then it overrides + //Will need modified + token = strtok(NULL, " "); + command->argv[*count] = token; + command->argc++; } }