diff --git a/Makefile b/Makefile index 024bf96..ed958b4 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,14 @@ -# -# Pish -# -# Authors: Gregory -# Samantha -# Readme: README.md -# +INC := -I include all: main exec main: - gcc -c -o build/main.o src/main.c + gcc $(INC) -c -o build/main.o src/main.c + gcc $(INC) -c -o build/Integrated.o src/Integrated.c + gcc $(INC) -c -o build/Pish.o src/Pish.c exec: - gcc -o bin/pish build/*.o - ./bin/pish + gcc -o bin/pish.out build/*.o clean: rm build/* diff --git a/README.md b/README.md index ae5845e..ce7378f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,15 @@ # Pish A simple bash shell implemented in C. + +# Authors: +Gregory Crawford +Samantha Boyer + + +# Instructions +## Compiling +Run `make` in the base folder +Program is then compiled into bin/ + +## Running +Run `pish` in bin/ to run the program \ No newline at end of file diff --git a/bin/pish b/bin/pish deleted file mode 100755 index c701370..0000000 Binary files a/bin/pish and /dev/null differ diff --git a/include/.keep b/include/.keep new file mode 100644 index 0000000..e69de29 diff --git a/include/Integrated.h b/include/Integrated.h new file mode 100755 index 0000000..fe2509b --- /dev/null +++ b/include/Integrated.h @@ -0,0 +1,6 @@ +#ifndef INTEGRATED_H +#define INTEGRATED_H + +void IntegratedCheck(char* command); + +#endif \ No newline at end of file diff --git a/include/Pish.h b/include/Pish.h new file mode 100644 index 0000000..fd60acd --- /dev/null +++ b/include/Pish.h @@ -0,0 +1,8 @@ +#ifndef PISH_H +#define PISH_H + +char* getcmd(void); +void exec(char* command); +void Pish(void); + +#endif diff --git a/src/Integrated.c b/src/Integrated.c new file mode 100755 index 0000000..00103c8 --- /dev/null +++ b/src/Integrated.c @@ -0,0 +1,14 @@ +#include +#include "Integrated.h" + +// Checks for commands that are built into Pish +void IntegratedCheck(char* command) +{ + if (command == "exit") + exit(0); + // If there is an argument, change to argument location + // Else, change to home directory + if (command[0] == 'c' && command[1] == 'd') + ; + return; +} \ No newline at end of file diff --git a/src/Pish.c b/src/Pish.c new file mode 100644 index 0000000..cac9605 --- /dev/null +++ b/src/Pish.c @@ -0,0 +1,51 @@ +#include +#include +#include +#include +#include "Integrated.h" +#include "Pish.h" + +// Prints a prompt and then reads a command from the terminal +char* getInput(void) +{ + return "echo hello world"; +} + +// Executes a command to the system +void exec(char* command) +{ + system(command); +} + +// Main function for Pish program +void Pish(void) +{ + char* command; + int retval; + while (1) + { + command = getInput(); + IntegratedCheck(command); + retval = fork(); + // Child + if (retval == 0) + { + // This is the child process + // Setup the child's process environment here + // E.g., where is standard I/O, how to handle signals? + exec(command); + // exec does not return if it succeeds + printf("ERROR: Could not execute %s\n", command); + exit(1); + } + // Parent + else + { + // This is the parent process; Wait for the child to finish + int pid = retval; + wait(pid); + } + // TODO: Remove break when while loop doesn't break program + break; + } +} diff --git a/src/main.c b/src/main.c index 49d012e..3b80286 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,6 @@ -#include +#include "Pish.h" int main() { - printf("Hello world\n"); + Pish(); }