trying to push
This commit is contained in:
		
						commit
						8e61e04e05
					
				@ -179,6 +179,7 @@ int ExecPipe(CommandStruct* commandParent, CommandStruct* commandChild, int* pip
 | 
				
			|||||||
	int pipeLocation = 0;
 | 
						int pipeLocation = 0;
 | 
				
			||||||
	int startArgc = 0;
 | 
						int startArgc = 0;
 | 
				
			||||||
	int endArgc = commandParent->argc;
 | 
						int endArgc = commandParent->argc;
 | 
				
			||||||
 | 
						pipe(pipefd);
 | 
				
			||||||
	for (int i = 0; i < pipeAmount; i++)
 | 
						for (int i = 0; i < pipeAmount; i++)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
@ -190,24 +191,27 @@ int ExecPipe(CommandStruct* commandParent, CommandStruct* commandChild, int* pip
 | 
				
			|||||||
		// if (pipeLocation < 0)
 | 
							// if (pipeLocation < 0)
 | 
				
			||||||
		// 	endArgc = commandParent->argc;
 | 
							// 	endArgc = commandParent->argc;
 | 
				
			||||||
		CopyCommandStruct(commandParent, commandChild, startArgc, endArgc);
 | 
							CopyCommandStruct(commandParent, commandChild, startArgc, endArgc);
 | 
				
			||||||
		pipe(pipefd);
 | 
					 | 
				
			||||||
		forkPID = fork();
 | 
							forkPID = fork();
 | 
				
			||||||
		if (forkPID == 0)
 | 
							if (forkPID == 0)
 | 
				
			||||||
			return forkPID;
 | 
								return forkPID;
 | 
				
			||||||
		// if (forkPID != 0)
 | 
							// if (forkPID != 0)
 | 
				
			||||||
		wait(&forkPID);
 | 
							close(pipefd[0]);
 | 
				
			||||||
		close(pipefd[1]);
 | 
							close(pipefd[1]);
 | 
				
			||||||
		while (read(pipefd[0], buffer, sizeof(buffer)) != 0)
 | 
							wait(&forkPID);
 | 
				
			||||||
			printf("%s", buffer);
 | 
					 | 
				
			||||||
		startArgc = pipeLocation + 1;
 | 
							startArgc = pipeLocation + 1;
 | 
				
			||||||
        ResetCommandStruct(commandChild); // Clean command
 | 
					        ResetCommandStruct(commandChild); // Clean command
 | 
				
			||||||
 | 
							pipe(pipefd);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	endArgc = commandParent->argc;
 | 
						endArgc = commandParent->argc;
 | 
				
			||||||
	forkPID = fork();
 | 
						forkPID = fork();
 | 
				
			||||||
	CopyCommandStruct(commandParent, commandChild, startArgc, endArgc);
 | 
						CopyCommandStruct(commandParent, commandChild, startArgc, endArgc);
 | 
				
			||||||
	if (forkPID == 0)
 | 
						if (forkPID == 0)
 | 
				
			||||||
		return forkPID;
 | 
							return forkPID;
 | 
				
			||||||
 | 
						close(pipefd[1]);
 | 
				
			||||||
	wait(&forkPID);
 | 
						wait(&forkPID);
 | 
				
			||||||
 | 
						while (read(pipefd[0], buffer, sizeof(buffer)) != 0)
 | 
				
			||||||
 | 
							printf("%s", buffer);
 | 
				
			||||||
 | 
						close(pipefd[0]);
 | 
				
			||||||
	ResetCommandStruct(commandChild); // Clean command
 | 
						ResetCommandStruct(commandChild); // Clean command
 | 
				
			||||||
	return 1;
 | 
						return 1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,6 @@
 | 
				
			|||||||
#include <assert.h>
 | 
					#include <assert.h>
 | 
				
			||||||
#include <fcntl.h>
 | 
					#include <fcntl.h>
 | 
				
			||||||
 | 
					#include <signal.h>
 | 
				
			||||||
#include <stdio.h>
 | 
					#include <stdio.h>
 | 
				
			||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
#include <unistd.h>
 | 
					#include <unistd.h>
 | 
				
			||||||
@ -27,6 +28,9 @@ void Pish(void)
 | 
				
			|||||||
    CommandStruct* commandChild = &commandChildObject;
 | 
					    CommandStruct* commandChild = &commandChildObject;
 | 
				
			||||||
    char inputString[1000]; // Max 1000 characters
 | 
					    char inputString[1000]; // Max 1000 characters
 | 
				
			||||||
    int forkPID;
 | 
					    int forkPID;
 | 
				
			||||||
 | 
						signal(SIGINT, SIG_IGN);
 | 
				
			||||||
 | 
						signal(SIGQUIT, SIG_IGN);
 | 
				
			||||||
 | 
						signal(SIGTERM, SIG_IGN);
 | 
				
			||||||
    ReadPishrc(commandParent, commandChild, inputString);
 | 
					    ReadPishrc(commandParent, commandChild, inputString);
 | 
				
			||||||
    while (1)
 | 
					    while (1)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -34,6 +38,8 @@ void Pish(void)
 | 
				
			|||||||
        ResetCommandStruct(commandParent); // Clean command
 | 
					        ResetCommandStruct(commandParent); // Clean command
 | 
				
			||||||
        strcpy(inputString, "");    // Clean inputString
 | 
					        strcpy(inputString, "");    // Clean inputString
 | 
				
			||||||
        GetInput(inputString);
 | 
					        GetInput(inputString);
 | 
				
			||||||
 | 
							if (strcmp(inputString, "") == 0)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
        SplitInput(inputString, commandParent);
 | 
					        SplitInput(inputString, commandParent);
 | 
				
			||||||
        if (IntegratedCheck(commandParent))
 | 
					        if (IntegratedCheck(commandParent))
 | 
				
			||||||
            continue;
 | 
					            continue;
 | 
				
			||||||
@ -58,7 +64,7 @@ void ReadPishrc(CommandStruct *commandParent, CommandStruct *commandChild, char
 | 
				
			|||||||
	int *argc = &(commandParent->argc);
 | 
						int *argc = &(commandParent->argc);
 | 
				
			||||||
	char* pishLocation = GetHomeDir();
 | 
						char* pishLocation = GetHomeDir();
 | 
				
			||||||
	strcat(pishLocation, "/.pishrc");
 | 
						strcat(pishLocation, "/.pishrc");
 | 
				
			||||||
	int fd = open(pishLocation, O_RDONLY | O_CREAT);
 | 
						int fd = open(pishLocation, O_RDONLY | O_CREAT, 0644);
 | 
				
			||||||
	assert(fd > -1);
 | 
						assert(fd > -1);
 | 
				
			||||||
	while (read(fd, buffer, 1) > 0)
 | 
						while (read(fd, buffer, 1) > 0)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user