From fc89c83d9c018253ec27d4ca7111dce4517c5547 Mon Sep 17 00:00:00 2001 From: Skylar Date: Tue, 29 Mar 2022 19:31:51 +1300 Subject: [PATCH] Added ampersand for piping --- ash.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/ash.c b/ash.c index 1c3ef8e..6dd80bf 100644 --- a/ash.c +++ b/ash.c @@ -354,7 +354,7 @@ void executeWithPipes(char ***userArgs, int amper, int pipeNum, char *constantFu } -char ***createPipeArgInput(char **userArgs, int amper, char *constantFullCommand) +char ***createPipeArgInput(char **userArgs, int amper, char *constantFullCommand, char **jobCommandsAmper, pid_t *jobIDs) { int buffsize1 = 10; int buffsize2 = 10; @@ -420,6 +420,31 @@ char ***createPipeArgInput(char **userArgs, int amper, char *constantFullCommand int errorMsg; waitpid(runningPipeCommand, &errorMsg, 0); } + else + { + if (jobsRunning == 0) + { + processCounter = 1; + jobsRunning++; + jobCommandsAmper[processCounter] = strdup(constantFullCommand); + jobIDs[processCounter] = runningPipeCommand; + printf("[%d] %d\n", processCounter, runningPipeCommand); + } + else + { + jobsRunning++; + processCounter++; + int countdown = processCounter; + while (jobIDs[countdown] == '\0') + { + countdown--; + } + countdown++; + jobCommandsAmper[countdown] = strdup(constantFullCommand); + jobIDs[countdown] = runningPipeCommand; + printf("[%d] %d\n", processCounter, runningPipeCommand); + } + } } } @@ -462,7 +487,7 @@ char **historyCommands, char **jobCommandsAmper, pid_t *jobIDs) { if (pipeExists == 1) { - createPipeArgInput(userArgs, amperValue, constantFullCommand); + createPipeArgInput(userArgs, amperValue, constantFullCommand, jobCommandsAmper, jobIDs); } else if (amperValue == 1) {