test 4 working+ test scripts nearly setup for tracking

This commit is contained in:
shockrah 2019-09-21 16:10:09 -07:00
parent a85dffe4da
commit c02a7905b2
3 changed files with 19 additions and 5 deletions

3
334/.gitignore vendored
View File

@ -1 +1,4 @@
bin
msh
*txt
*sh

View File

@ -1,7 +1,7 @@
# Single make file for everything becauz lazy
object=homework/msh/msh.c
cc=gcc
output=bin
output=msh
default:
$(cc) $(object) -o $(output)

View File

@ -21,12 +21,22 @@ void remove_newline(char*);
void exit_branch(const char*);
int builtin_response(char*);
int main(void) {
int main(int argc, char** argv) {
FILE* file = NULL;
if(argc == 2) {
file = fopen(argv[1], "r");
}
char buffer[MAX_BUF];
while(1) {
printf("%s", PROMPT);
fgets(buffer, MAX_BUF, stdin);
// determine if we're reading from stdin or a stream of some sort
if(file == NULL && isatty(STDIN_FILENO)) {
printf("%s", PROMPT);
fgets(buffer, MAX_BUF, stdin);
}
else {
fgets(buffer, MAX_BUF, file);
}
// Deal with EOF input
if(!strlen(buffer)) {
exit(0);
@ -109,3 +119,4 @@ int builtin_response(char* buffer) {
}
}