Adjusted a little bit of syntax (personal)

This commit is contained in:
TriantaTV 2022-10-27 23:23:02 -05:00
parent 702b77073f
commit 94f2c4fcb8

View File

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