diff --git a/src/Integrated.c b/src/Integrated.c index 3c14943..b003a34 100755 --- a/src/Integrated.c +++ b/src/Integrated.c @@ -100,30 +100,30 @@ void ioRedirection(CommandStruct *command) // TODO: Check command->argv[] for symbol instead for(int i = 0; i < sizeof(command); i++) { - if (strchr(command->argv[i], '>') != NULL) - { - output(command->argv[i+1]); - // Check if targeting a specific string in command->argv works - } - if (strchr(command->argv[i], '<') != NULL) - { - input(command->argv[i+1]); - } - if (strchr(command->argv[i], '|')!= NULL) - { - // not sure if i + 1 correct - // pipe(command->argv[i+1]); - } - if (strpbrk(command->argv[i], ">>")!= NULL) - { - append(command->argv[i-1], command->argv[i+1]); - } + if (strchr(command->argv[i], '>') != NULL) + { + output(command->argv[i+1]); + // Check if targeting a specific string in command->argv works + } + if (strchr(command->argv[i], '<') != NULL) + { + input(command->argv[i+1]); + } + if (strchr(command->argv[i], '|')!= NULL) + { + // not sure if i + 1 correct + // pipe(command->argv[i+1]); + } + if (strpbrk(command->argv[i], ">>")!= NULL) + { + append(command->argv[i-1], command->argv[i+1]); + } } } 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_TRUNC | O_WRONLY, 0644) < 0) { perror(command); exit(1); @@ -133,13 +133,13 @@ void output(char *command){ void input(char *command) { - int newfd; - if(newfd = open(command, O_RDONLY)<0) - { - perror(command); - exit(1); - } - dup2(newfd,0); + int newfd; + if (newfd = open(command, O_RDONLY) < 0) + { + perror(command); + exit(1); + } + dup2(newfd,0); } void ExecPipe() @@ -149,58 +149,57 @@ void ExecPipe() void append(char *input, char *file) { - FILE *fp; - - fp = fopen(file, "a+"); - - fputs(input, fp); - fclose(fp); + FILE *fp; + fp = fopen(file, "a+"); + fputs(input, fp); + fclose(fp); } - // check command standard input - // if (strchr(inputString, '<') != NULL) - // { - // newfd = open((command, O_CREAT |O_TRUNC | O_WRONLY, 0644)) < 0); - // // No if statement for fail checking, brackets just exist here - // { - // // failed - // perror(command); - // exit(1); - // } - // dup2(newfd, 0); - // } - // check pipe - // TODO: Check for pipe symbol - // Check in command->argv[] instead - // if (strchr(command, '|') != NULL) - // { - // ; - // } - // check append - // TODO: Implement append - // if (strpbrk(command, ">>") != NULL) - // { - // newfd = open((command, O_CREAT |O_TRUNC | O_WRONLY, 0644)) < 0); - // // No if statement for fail checking, brackets just exist here - // { - // // failed - // perror(command); - // exit(1); - // } - // dup2(newfd, 0); - // } - // check pipe - // TODO: Check pipe already exists above, maybe loop? - // if (strchr(command, '|') != NULL) - // { - // ; - // } - // check append - // TODO: Check append already exists above, maybe loop? - // if (strpbrk(command, ">>") != NULL) - // { - // ; - // } +// check command standard input +// if (strchr(inputString, '<') != NULL) +// { +// newfd = open((command, O_CREAT |O_TRUNC | O_WRONLY, 0644)) < 0); +// // No if statement for fail checking, brackets just exist here +// { +// // failed +// perror(command); +// exit(1); +// } +// dup2(newfd, 0); +// } + +// check pipe +// TODO: Check for pipe symbol +// Check in command->argv[] instead +// if (strchr(command, '|') != NULL) +// { +// ; +// } +// check append +// TODO: Implement append +// if (strpbrk(command, ">>") != NULL) +// { +// newfd = open((command, O_CREAT |O_TRUNC | O_WRONLY, 0644)) < 0); +// // No if statement for fail checking, brackets just exist here +// { +// // failed +// perror(command); +// exit(1); +// } +// dup2(newfd, 0); +// } +// check pipe +// TODO: Check pipe already exists above, maybe loop? +// if (strchr(command, '|') != NULL) +// { +// ; +// } +// check append +// TODO: Check append already exists above, maybe loop? +// if (strpbrk(command, ">>") != NULL) +// { +// ; +// } // Environment varibles // TODO: Add this function to CommandStruct