Program now runs once, input seems to not work, added debug in makefile for debugging

This commit is contained in:
TriantaTV 2022-10-25 02:12:07 -05:00
parent 66794db902
commit 68e9985c18
3 changed files with 27 additions and 17 deletions

View File

@ -10,6 +10,20 @@ compile:
link: link:
gcc -o bin/pish.out build/*.o 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: clean:
rm build/*.o rm build/*.o
rm bin/*.out rm bin/*.out

View File

@ -5,7 +5,7 @@
void Pish(void); void Pish(void);
void Execute(char* command); void Execute(char* command);
char* GetInput(void); void GetInput(char* inputString);
void ParseInput(char* inputString, CommandStruct* command); void ParseInput(char* inputString, CommandStruct* command);
#endif #endif

View File

@ -11,14 +11,13 @@ void Pish(void)
{ {
CommandStruct commandObject = {"", 0}; CommandStruct commandObject = {"", 0};
CommandStruct* command = &commandObject; CommandStruct* command = &commandObject;
char* inputStr; char inputString[1000]; // Max 1000 characters
int forkPID; int forkPID;
while (1) while (1)
{ {
inputStr = GetInput(); GetInput(inputString);
ParseInput(inputStr, command); ParseInput(inputString, command);
IntegratedCheck(command->argv[0]); IntegratedCheck(command->argv[0]);
printf("Successfully passed input phase\n");
forkPID = fork(); forkPID = fork();
// Child // Child
if (forkPID == 0) if (forkPID == 0)
@ -27,10 +26,9 @@ 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
printf("Executing in fork...\n"); Execute(inputString);
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", inputString);
exit(1); exit(1);
} }
// Parent // Parent
@ -40,7 +38,6 @@ 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
@ -51,19 +48,18 @@ void Pish(void)
// Executes a command to the system // Executes a command to the system
void Execute(char* command) void Execute(char* command)
{ {
printf("%s\n", command);
system(command); system(command);
exit(0);
} }
// Prints a prompt and then reads a command from the terminal // Prints a prompt and then reads a command from the terminal
char* GetInput(void) void GetInput(char* inputString)
{ {
char prompt = '$'; char prompt = '$';
char *commandLine;
printf("%c ", prompt); printf("%c ", prompt);
scanf("%[^\n]", commandLine); scanf("%[^\n]", inputString);
return;
return commandLine;
} }
void ParseInput(char* inputString, CommandStruct* command) void ParseInput(char* inputString, CommandStruct* command)
@ -72,13 +68,13 @@ void ParseInput(char* inputString, CommandStruct* command)
int* count = &(command->argc); int* count = &(command->argc);
char* token = strtok(inputString, " "); char* token = strtok(inputString, " ");
command->argv[*count] = token; command->argv[*count] = token;
*count++; (*count)++;
while (token != NULL) 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->argv[*count] = token;
command->argc++; (*count)++;
} }
} }