Merge pull request #3 from TriantaTV/development

Development
This commit is contained in:
TriantaTV 2022-10-19 21:48:53 -05:00 committed by GitHub
commit 4c7cf3bd3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 99 additions and 12 deletions

View File

@ -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/*

View File

@ -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

BIN
bin/pish

Binary file not shown.

0
include/.keep Normal file
View File

6
include/Integrated.h Executable file
View File

@ -0,0 +1,6 @@
#ifndef INTEGRATED_H
#define INTEGRATED_H
void IntegratedCheck(char* command);
#endif

8
include/Pish.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef PISH_H
#define PISH_H
char* getcmd(void);
void exec(char* command);
void Pish(void);
#endif

14
src/Integrated.c Executable file
View File

@ -0,0 +1,14 @@
#include <stdlib.h>
#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;
}

51
src/Pish.c Normal file
View File

@ -0,0 +1,51 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#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;
}
}

View File

@ -1,6 +1,6 @@
#include <stdio.h>
#include "Pish.h"
int main()
{
printf("Hello world\n");
Pish();
}