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
|
||||
|
||||
typedef struct CommandStruct {
|
||||
char** argv;
|
||||
char* argv[100]; // Max 100 commands
|
||||
int argc;
|
||||
} CommandStruct;
|
||||
|
||||
|
@ -6,6 +6,6 @@
|
||||
void Pish(void);
|
||||
void Execute(char* command);
|
||||
char* GetInput(void);
|
||||
void ParseInput(char* inputString, CommandStruct command);
|
||||
void ParseInput(char* inputString, CommandStruct* command);
|
||||
|
||||
#endif
|
||||
|
32
src/Pish.c
32
src/Pish.c
@ -9,13 +9,16 @@
|
||||
// Main function for Pish program
|
||||
void Pish(void)
|
||||
{
|
||||
CommandStruct command;
|
||||
command.argc = 0;
|
||||
CommandStruct commandObject = {"", 0};
|
||||
CommandStruct* command = &commandObject;
|
||||
char* inputStr;
|
||||
int forkPID;
|
||||
while (1)
|
||||
{
|
||||
ParseInput(GetInput(), command);
|
||||
IntegratedCheck(command.argv[0]);
|
||||
inputStr = GetInput();
|
||||
ParseInput(inputStr, command);
|
||||
IntegratedCheck(command->argv[0]);
|
||||
printf("Successfully passed input phase\n");
|
||||
forkPID = fork();
|
||||
// Child
|
||||
if (forkPID == 0)
|
||||
@ -24,9 +27,10 @@ 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
|
||||
Execute(command.argv[0]);
|
||||
printf("Executing in fork...\n");
|
||||
Execute(command->argv[0]);
|
||||
// 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);
|
||||
}
|
||||
// Parent
|
||||
@ -36,6 +40,7 @@ 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
|
||||
@ -61,14 +66,19 @@ char* GetInput(void)
|
||||
return commandLine;
|
||||
}
|
||||
|
||||
void ParseInput(char* inputString, CommandStruct command)
|
||||
void ParseInput(char* inputString, CommandStruct* command)
|
||||
{
|
||||
//Parse command
|
||||
int* count = &(command->argc);
|
||||
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
|
||||
//Will need modified
|
||||
token = strtok(NULL, " ");
|
||||
//This only holds 1 command at a time then it overrides
|
||||
//Will need modified
|
||||
token = strtok(NULL, " ");
|
||||
command->argv[*count] = token;
|
||||
command->argc++;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user