From 0062cd1cc55243eefc0d021cec21c113cc800b66 Mon Sep 17 00:00:00 2001 From: Samantha Boyer Date: Sat, 29 Oct 2022 22:55:36 -0500 Subject: [PATCH] added EV , fixed input and output --- include/Common.h | 3 ++- src/Integrated.c | 13 ++++++------- src/Pish.c | 2 ++ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/Common.h b/include/Common.h index 7120cfc..bda50d1 100755 --- a/include/Common.h +++ b/include/Common.h @@ -6,9 +6,10 @@ const char* GetHomeDir(void); typedef struct CommandStruct { char* argv[100]; // Max 100 commands int argc; + char* envp[20]; // Enviroment Varibles } CommandStruct; void CopyCommandStruct(CommandStruct* oldCommand, CommandStruct* newCommand, int start, int end); void ResetCommandStruct(CommandStruct* command); -#endif \ No newline at end of file +#endif diff --git a/src/Integrated.c b/src/Integrated.c index 0fa1ff0..f72b4ff 100755 --- a/src/Integrated.c +++ b/src/Integrated.c @@ -98,13 +98,12 @@ void CheckRedirection(CommandStruct* command) // TODO: Check command->argv[] for symbol instead for (int i = 0; i < command->argc; i++) { - if ((command->argv[i][0] == '>') && (command->argv[i][1] == '>')) - printf(">> was found.\n"); + if ((command->argv[i][0] == '>') && (command->argv[i][1] == '>')) printf(">> was found.\n"); // ParseInput(inputString, command, ">>"); if (command->argv[i][0] == '<') printf("< was found.\n"); // ParseInput(inputString, command, "<"); - if (command->argv[i][0] == '>') + if (command->argv[i][0] == '>' && command->argv[i][1] != '>') printf("> was found.\n"); // ParseInput(inputString, command, ">"); if (command->argv[i][0] == '|') @@ -133,7 +132,7 @@ void ioRedirection(CommandStruct* command) { append(command->argv[i-1], command->argv[i+1]); } - else if (strchr(command->argv[i], '<')!= NULL)//input + else if (command->argv[i][0] =='<')//input { input(command->argv[i+1]); } @@ -141,7 +140,7 @@ void ioRedirection(CommandStruct* command) { //ExecPipe(); } - else if (strchr(command->argv[i], '>')!= NULL)//output + else if (command->argv[i][0] == '>')//output { output(command->argv[i+1]); } @@ -152,7 +151,7 @@ void ioRedirection(CommandStruct* command) void output(char *command){ int newfd; - if (newfd = open(command, O_CREAT | O_TRUNC | O_WRONLY, 0644) < 0) + if (newfd = open(command, O_CREAT | O_CREAT, 0666) < 0) { perror(command); exit(1); @@ -163,7 +162,7 @@ void output(char *command){ void input(char *command) { int newfd; - if (newfd = open(command, O_RDONLY) < 0) + if (newfd = open(command, O_RDONLY | O_CREAT) < 0) { perror(command); exit(1); diff --git a/src/Pish.c b/src/Pish.c index fad10b0..2c9f7fd 100644 --- a/src/Pish.c +++ b/src/Pish.c @@ -86,6 +86,8 @@ void RunChild(CommandStruct* commandChild, int* pipefd) dup2(pipefd[1], 1); close(pipefd[1]); // execve() is recommended, execvpe() may be better + CheckRedirection(commandChild); + ioRedirection(commandChild); execvp(commandChild->argv[0], commandChild->argv); // exec does not return if it succeeds printf("ERROR: Could not execute %s\n", commandChild->argv[0]);