Fixed Pish errors, prompt now prints, core dump after prompt input still
This commit is contained in:
		
							parent
							
								
									52aeeb02e5
								
							
						
					
					
						commit
						66794db902
					
				@ -2,7 +2,7 @@
 | 
				
			|||||||
#define COMMON_H
 | 
					#define COMMON_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct CommandStruct {
 | 
					typedef struct CommandStruct {
 | 
				
			||||||
    char** argv;
 | 
					    char* argv[100]; // Max 100 commands
 | 
				
			||||||
    int argc;
 | 
					    int argc;
 | 
				
			||||||
} CommandStruct;
 | 
					} CommandStruct;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -6,6 +6,6 @@
 | 
				
			|||||||
void Pish(void);
 | 
					void Pish(void);
 | 
				
			||||||
void Execute(char* command);
 | 
					void Execute(char* command);
 | 
				
			||||||
char* GetInput(void);
 | 
					char* GetInput(void);
 | 
				
			||||||
void ParseInput(char* inputString, CommandStruct command);
 | 
					void ParseInput(char* inputString, CommandStruct* command);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										26
									
								
								src/Pish.c
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								src/Pish.c
									
									
									
									
									
								
							@ -9,13 +9,16 @@
 | 
				
			|||||||
// Main function for Pish program
 | 
					// Main function for Pish program
 | 
				
			||||||
void Pish(void)
 | 
					void Pish(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    CommandStruct command;
 | 
					    CommandStruct commandObject = {"", 0};
 | 
				
			||||||
    command.argc = 0;
 | 
					    CommandStruct* command = &commandObject;
 | 
				
			||||||
 | 
					    char* inputStr;
 | 
				
			||||||
    int forkPID;
 | 
					    int forkPID;
 | 
				
			||||||
    while (1)
 | 
					    while (1)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        ParseInput(GetInput(), command);
 | 
					        inputStr = GetInput();
 | 
				
			||||||
	    IntegratedCheck(command.argv[0]);
 | 
					        ParseInput(inputStr, command);
 | 
				
			||||||
 | 
						    IntegratedCheck(command->argv[0]);
 | 
				
			||||||
 | 
					        printf("Successfully passed input phase\n");
 | 
				
			||||||
        forkPID = fork();
 | 
					        forkPID = fork();
 | 
				
			||||||
        // Child
 | 
					        // Child
 | 
				
			||||||
        if (forkPID == 0)
 | 
					        if (forkPID == 0)
 | 
				
			||||||
@ -24,9 +27,10 @@ void Pish(void)
 | 
				
			|||||||
            // Setup the child's process environment here
 | 
					            // Setup the child's process environment here
 | 
				
			||||||
            // E.g., where is standard I/O, how to handle signals?
 | 
					            // E.g., where is standard I/O, how to handle signals?
 | 
				
			||||||
            // TODO: Adjust Execute() to handle CommandStruct
 | 
					            // TODO: Adjust Execute() to handle CommandStruct
 | 
				
			||||||
            Execute(command.argv[0]);
 | 
					            printf("Executing in fork...\n");
 | 
				
			||||||
 | 
					            Execute(command->argv[0]);
 | 
				
			||||||
            // exec does not return if it succeeds
 | 
					            // exec does not return if it succeeds
 | 
				
			||||||
            printf("ERROR: Could not execute %s\n", command.argv[0]);
 | 
					            printf("ERROR: Could not execute %s\n", command->argv[0]);
 | 
				
			||||||
            exit(1);
 | 
					            exit(1);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        // Parent
 | 
					        // Parent
 | 
				
			||||||
@ -36,6 +40,7 @@ void Pish(void)
 | 
				
			|||||||
            // Removed due to potentially useless
 | 
					            // Removed due to potentially useless
 | 
				
			||||||
            // int pid = forkPID;
 | 
					            // int pid = forkPID;
 | 
				
			||||||
            // wait(&pid);
 | 
					            // wait(&pid);
 | 
				
			||||||
 | 
					            printf("Waiting for fork...\n");
 | 
				
			||||||
            wait(&forkPID);
 | 
					            wait(&forkPID);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        // TODO: Remove break when while loop doesn't break program
 | 
					        // TODO: Remove break when while loop doesn't break program
 | 
				
			||||||
@ -61,14 +66,19 @@ char* GetInput(void)
 | 
				
			|||||||
    return commandLine;
 | 
					    return commandLine;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ParseInput(char* inputString, CommandStruct command)
 | 
					void ParseInput(char* inputString, CommandStruct* command)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    //Parse command
 | 
					    //Parse command
 | 
				
			||||||
 | 
					    int* count = &(command->argc);
 | 
				
			||||||
	char* token = strtok(inputString, " ");
 | 
						char* token = strtok(inputString, " ");
 | 
				
			||||||
	while(token != NULL)
 | 
					    command->argv[*count] = token;
 | 
				
			||||||
 | 
					    *count++;
 | 
				
			||||||
 | 
						while (token != NULL)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
	    //This only holds 1 command at a time then it overrides
 | 
						    //This only holds 1 command at a time then it overrides
 | 
				
			||||||
	    //Will need modified
 | 
						    //Will need modified
 | 
				
			||||||
	    token = strtok(NULL, " ");
 | 
						    token = strtok(NULL, " ");
 | 
				
			||||||
 | 
					        command->argv[*count] = token;
 | 
				
			||||||
 | 
					        command->argc++;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user