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 bin
msh
*txt
*sh

View File

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

View File

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