commit
4c7cf3bd3b
15
Makefile
15
Makefile
@ -1,19 +1,14 @@
|
|||||||
#
|
INC := -I include
|
||||||
# Pish
|
|
||||||
#
|
|
||||||
# Authors: Gregory
|
|
||||||
# Samantha
|
|
||||||
# Readme: README.md
|
|
||||||
#
|
|
||||||
|
|
||||||
all: main exec
|
all: main exec
|
||||||
|
|
||||||
main:
|
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:
|
exec:
|
||||||
gcc -o bin/pish build/*.o
|
gcc -o bin/pish.out build/*.o
|
||||||
./bin/pish
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm build/*
|
rm build/*
|
||||||
|
13
README.md
13
README.md
@ -1,2 +1,15 @@
|
|||||||
# Pish
|
# Pish
|
||||||
A simple bash shell implemented in C.
|
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
|
0
include/.keep
Normal file
0
include/.keep
Normal file
6
include/Integrated.h
Executable file
6
include/Integrated.h
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef INTEGRATED_H
|
||||||
|
#define INTEGRATED_H
|
||||||
|
|
||||||
|
void IntegratedCheck(char* command);
|
||||||
|
|
||||||
|
#endif
|
8
include/Pish.h
Normal file
8
include/Pish.h
Normal 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
14
src/Integrated.c
Executable 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
51
src/Pish.c
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
#include <stdio.h>
|
#include "Pish.h"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
printf("Hello world\n");
|
Pish();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user