diff --git a/include/Integrated.h b/include/Integrated.h index 8fa09a7..abb848b 100755 --- a/include/Integrated.h +++ b/include/Integrated.h @@ -4,7 +4,7 @@ #include "Common.h" const char* GetHomeDir(void); -void IntegratedCheck(char* command); +void IntegratedCheck(CommandStruct* command); void ReadPishrc(CommandStruct* command, char* inputString); #endif \ No newline at end of file diff --git a/src/Integrated.c b/src/Integrated.c index 3753902..7d16273 100755 --- a/src/Integrated.c +++ b/src/Integrated.c @@ -20,13 +20,13 @@ const char* GetHomeDir(void) // Checks for commands that are built into Pish -void IntegratedCheck(char* command) +void IntegratedCheck(CommandStruct* command) { - if (command == "exit") + if (strcmp(command->argv[0], "exit") == 0) exit(0); // If there is an argument, change to argument location // Else, change to home directory - if (command[0] == 'c' && command[1] == 'd') + if (command->argv[0][0] == 'c' && command->argv[0][1] == 'd') ; return; } @@ -34,21 +34,20 @@ void IntegratedCheck(char* command) // Reads ~/.pishrc and runs each command in the file void ReadPishrc(CommandStruct* command, char* inputString) { - char buffer; + char buffer[1]; int forkID; int* argc = &(command->argc); int fd = open(GetHomeDir(), O_RDONLY | O_CREAT); assert(fd > -1); - while (read(fd, &buffer, 1) > 0) + while (read(fd, buffer, 1) > 0) { - printf("%c", buffer); - if (buffer == ' ') + if (buffer[0] == ' ') { command->argv[*argc] = inputString; strcpy(inputString, ""); *argc++; } - if (buffer == '\n') + if (buffer[0] == '\n') { command->argv[*argc] = inputString; strcpy(inputString, ""); @@ -58,7 +57,7 @@ void ReadPishrc(CommandStruct* command, char* inputString) wait(&forkID); ResetCommandStruct(command); } - strcat(inputString, &buffer); + strcat(inputString, buffer); } assert(close(fd) >= 0); } \ No newline at end of file diff --git a/src/Pish.c b/src/Pish.c index 3874824..8f583cc 100644 --- a/src/Pish.c +++ b/src/Pish.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -17,10 +18,10 @@ void Pish(void) while (1) { ResetCommandStruct(command); // Clean command - memset(inputString, 0, sizeof(inputString)); // Clean inputString + strcpy(inputString, ""); // Clean inputString GetInput(inputString); ParseInput(inputString, command); - IntegratedCheck(command->argv[0]); + IntegratedCheck(command); forkPID = fork(); // Child if (forkPID == 0) @@ -36,21 +37,20 @@ void Pish(void) } // Parent // 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; } } // Prints a prompt and then reads a command from the terminal void GetInput(char* inputString) { + char c; char* prompt = "pish%>"; printf("%s ", prompt); - scanf("%[^\n]", inputString); + // assert(scanf("%[^\n]s", inputString) == 1); + scanf("%1000[^\n]s", inputString); + while((c = getchar()) != '\n' && c != EOF) + /* discard */ ; return; }