diff --git a/bin/.keep b/bin/.keep new file mode 100644 index 0000000..e69de29 diff --git a/include/Integrated.h b/include/Integrated.h index 136d418..ca25509 100755 --- a/include/Integrated.h +++ b/include/Integrated.h @@ -4,14 +4,15 @@ #include "Common.h" const char* GetHomeDir(void); -void CheckRedirection(char *inputString, CommandStruct *command); +void CheckRedirection(CommandStruct* command); int IntegratedCheck(CommandStruct* command); void GetInput(char* inputString); void append(char *input, char *file); void input(char *command); void ExecPipe(); void output(char *command); +void SplitInput(char* inputString, CommandStruct* command); void ParseInput(char* inputString, CommandStruct* command, char *symbol); void ReadPishrc(CommandStruct* command, char* inputString); -void ioRedirection(CommandStruct *command); +void ioRedirection(CommandStruct* command); #endif diff --git a/src/Integrated.c b/src/Integrated.c index 3fe09fa..8e5b051 100755 --- a/src/Integrated.c +++ b/src/Integrated.c @@ -43,7 +43,7 @@ void GetInput(char *inputString) printf("%s ", prompt); // assert(scanf("%[^\n]s", inputString) == 1); scanf("%1000[^\n]s", inputString); - while ((c = getchar()) != '\n' && c != EOF) + while ((c = getchar()) != '\n' && c != EOF) // Cleans input /* discard */; return; } @@ -95,40 +95,54 @@ void ReadPishrc(CommandStruct *command, char *inputString) assert(close(fd) >= 0); } +// Splits a string separated by spaces into an array of strings +void SplitInput(char *inputString, CommandStruct *command) +{ + // Parse command + int *argc = &(command->argc); + char *token = strtok(inputString, " "); + command->argv[*argc] = token; + (*argc)++; + while (token != NULL) + { + // This only holds 1 command at a time then it overrides + // Will need modified + token = strtok(NULL, " "); + command->argv[*argc] = token; + (*argc)++; + } + (*argc)--; +} + // Checking redirection // TODO: Work on one symbol at a time // inputString may not be useful here, only *command // Try to add a layer of abstraction where possible // I.E. think about using function instead for checking -void CheckRedirection(char *inputString, CommandStruct *command) +void CheckRedirection(CommandStruct* command) { // check command standard output // TODO: Check command->argv[] for symbol instead - // for(int i = 0; i < sizeof(inputString); i++) - // { - if (strpbrk(inputString, ">>") != NULL) - { - ParseInput(inputString, command, ">>"); - } - else if (strchr(inputString, '<') != NULL) - { - ParseInput(inputString, command, "<"); - } - else if (strchr(inputString, '|')!= NULL) - { - ParseInput(inputString, command, "|"); - } - else if (strchr(inputString, '>')!= NULL) - { - ParseInput(inputString, command, ">"); - } - else - { - ParseInput(inputString, command, " "); - } - // } + for (int i = 0; i < command->argc; i++) + { + 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] == '>') + printf("> was found.\n"); + // ParseInput(inputString, command, ">"); + if (command->argv[i][0] == '|') + printf("| was found.\n"); + // ParseInput(inputString, command, "|"); + // else + // ParseInput(inputString, command, " "); + } + return; } -void ioRedirection(CommandStruct *command) +void ioRedirection(CommandStruct* command) { for (int i = 0; i