Program now runs once, input seems to not work, added debug in makefile for debugging
This commit is contained in:
		
							parent
							
								
									66794db902
								
							
						
					
					
						commit
						68e9985c18
					
				
							
								
								
									
										14
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								Makefile
									
									
									
									
									
								
							@ -10,6 +10,20 @@ compile:
 | 
			
		||||
link:
 | 
			
		||||
	gcc -o bin/pish.out build/*.o
 | 
			
		||||
 | 
			
		||||
exec: compile link
 | 
			
		||||
	./bin/pish.out
 | 
			
		||||
 | 
			
		||||
debug: debugCompile debugLink
 | 
			
		||||
 | 
			
		||||
debugCompile:
 | 
			
		||||
	gcc $(INC) -g -c -o build/main.o src/main.c
 | 
			
		||||
	gcc $(INC) -g -c -o build/Integrated.o src/Integrated.c
 | 
			
		||||
	gcc $(INC) -g -c -o build/Pish.o src/Pish.c
 | 
			
		||||
 | 
			
		||||
debugLink:
 | 
			
		||||
	gcc -g -o bin/pish.out build/*.o
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
clean:
 | 
			
		||||
	rm build/*.o
 | 
			
		||||
	rm bin/*.out
 | 
			
		||||
 | 
			
		||||
@ -5,7 +5,7 @@
 | 
			
		||||
 | 
			
		||||
void Pish(void);
 | 
			
		||||
void Execute(char* command);
 | 
			
		||||
char* GetInput(void);
 | 
			
		||||
void GetInput(char* inputString);
 | 
			
		||||
void ParseInput(char* inputString, CommandStruct* command);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										28
									
								
								src/Pish.c
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								src/Pish.c
									
									
									
									
									
								
							@ -11,14 +11,13 @@ void Pish(void)
 | 
			
		||||
{
 | 
			
		||||
    CommandStruct commandObject = {"", 0};
 | 
			
		||||
    CommandStruct* command = &commandObject;
 | 
			
		||||
    char* inputStr;
 | 
			
		||||
    char inputString[1000]; // Max 1000 characters
 | 
			
		||||
    int forkPID;
 | 
			
		||||
    while (1)
 | 
			
		||||
    {
 | 
			
		||||
        inputStr = GetInput();
 | 
			
		||||
        ParseInput(inputStr, command);
 | 
			
		||||
        GetInput(inputString);
 | 
			
		||||
        ParseInput(inputString, command);
 | 
			
		||||
	    IntegratedCheck(command->argv[0]);
 | 
			
		||||
        printf("Successfully passed input phase\n");
 | 
			
		||||
        forkPID = fork();
 | 
			
		||||
        // Child
 | 
			
		||||
        if (forkPID == 0)
 | 
			
		||||
@ -27,10 +26,9 @@ void Pish(void)
 | 
			
		||||
            // Setup the child's process environment here
 | 
			
		||||
            // E.g., where is standard I/O, how to handle signals?
 | 
			
		||||
            // TODO: Adjust Execute() to handle CommandStruct
 | 
			
		||||
            printf("Executing in fork...\n");
 | 
			
		||||
            Execute(command->argv[0]);
 | 
			
		||||
            Execute(inputString);
 | 
			
		||||
            // exec does not return if it succeeds
 | 
			
		||||
            printf("ERROR: Could not execute %s\n", command->argv[0]);
 | 
			
		||||
            printf("ERROR: Could not execute %s\n", inputString);
 | 
			
		||||
            exit(1);
 | 
			
		||||
        }
 | 
			
		||||
        // Parent
 | 
			
		||||
@ -40,7 +38,6 @@ void Pish(void)
 | 
			
		||||
            // Removed due to potentially useless
 | 
			
		||||
            // int pid = forkPID;
 | 
			
		||||
            // wait(&pid);
 | 
			
		||||
            printf("Waiting for fork...\n");
 | 
			
		||||
            wait(&forkPID);
 | 
			
		||||
        }
 | 
			
		||||
        // TODO: Remove break when while loop doesn't break program
 | 
			
		||||
@ -51,19 +48,18 @@ void Pish(void)
 | 
			
		||||
// Executes a command to the system
 | 
			
		||||
void Execute(char* command)
 | 
			
		||||
{
 | 
			
		||||
    printf("%s\n", command);
 | 
			
		||||
    system(command);
 | 
			
		||||
    exit(0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Prints a prompt and then reads a command from the terminal
 | 
			
		||||
char* GetInput(void)
 | 
			
		||||
void GetInput(char* inputString)
 | 
			
		||||
{
 | 
			
		||||
    char prompt = '$';
 | 
			
		||||
    char *commandLine;
 | 
			
		||||
 | 
			
		||||
    printf("%c ", prompt);
 | 
			
		||||
    scanf("%[^\n]", commandLine);
 | 
			
		||||
 | 
			
		||||
    return commandLine;
 | 
			
		||||
    scanf("%[^\n]", inputString);
 | 
			
		||||
    return;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ParseInput(char* inputString, CommandStruct* command)
 | 
			
		||||
@ -72,13 +68,13 @@ void ParseInput(char* inputString, CommandStruct* command)
 | 
			
		||||
    int* count = &(command->argc);
 | 
			
		||||
	char* token = strtok(inputString, " ");
 | 
			
		||||
    command->argv[*count] = token;
 | 
			
		||||
    *count++;
 | 
			
		||||
    (*count)++;
 | 
			
		||||
	while (token != NULL)
 | 
			
		||||
    {
 | 
			
		||||
	    //This only holds 1 command at a time then it overrides
 | 
			
		||||
	    //Will need modified
 | 
			
		||||
	    token = strtok(NULL, " ");
 | 
			
		||||
        command->argv[*count] = token;
 | 
			
		||||
        command->argc++;
 | 
			
		||||
        (*count)++;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user