From 01625790bdf476c84efef7b378cc04e362577038 Mon Sep 17 00:00:00 2001 From: TriantaTV Date: Sat, 29 Oct 2022 23:11:35 -0500 Subject: [PATCH] Final cleanup before submitting --- src/Integrated.c | 18 +++--------------- src/Pish.c | 11 +---------- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/src/Integrated.c b/src/Integrated.c index 2e99e9d..c676849 100755 --- a/src/Integrated.c +++ b/src/Integrated.c @@ -60,15 +60,12 @@ void ParseInput(char *inputString, CommandStruct *command, char *symbol) // 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)++; @@ -88,17 +85,14 @@ int CheckSymbol(CommandStruct* command, char symbol, int start) } // 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(CommandStruct* command) { // check command standard output // 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"); @@ -115,6 +109,7 @@ void CheckRedirection(CommandStruct* command) return; } +// Count number of appearances of a symbol in a CommandStruct int CountSymbol(CommandStruct* command, char symbol) { int count = 0; @@ -182,19 +177,12 @@ int ExecPipe(CommandStruct* commandParent, CommandStruct* commandChild, int* pip pipe(pipefd); for (int i = 0; i < pipeAmount; i++) { - - // if (pipeLocation > 0) - // startArgc = pipeLocation + 1; pipeLocation = CheckSymbol(commandParent, '|', startArgc); - // if (pipeLocation >= 0) endArgc = pipeLocation; - // if (pipeLocation < 0) - // endArgc = commandParent->argc; CopyCommandStruct(commandParent, commandChild, startArgc, endArgc); forkPID = fork(); if (forkPID == 0) return forkPID; - // if (forkPID != 0) close(pipefd[0]); close(pipefd[1]); wait(&forkPID); diff --git a/src/Pish.c b/src/Pish.c index b864c1c..c65d5d9 100644 --- a/src/Pish.c +++ b/src/Pish.c @@ -10,15 +10,6 @@ #include "Integrated.h" #include "Pish.h" -// Example command: ps aux | grep 'Z' -// Pipe left: [ps aux] -// argv: [ps, aux] -// Pipe right: [grep 'Z'] -// argv: [grep, 'Z'] - -// check for first pipe, split into before and after pipe, -// connect left and right execs - // Main function for Pish program void Pish(void) { @@ -93,7 +84,7 @@ void RunChild(CommandStruct* commandChild, int* pipefd) close(pipefd[1]); // execve() is recommended, execvpe() may be better CheckRedirection(commandChild); - ioRedirection(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]);