test 4 working+ test scripts nearly setup for tracking
This commit is contained in:
parent
a85dffe4da
commit
c02a7905b2
3
334/.gitignore
vendored
3
334/.gitignore
vendored
@ -1 +1,4 @@
|
||||
bin
|
||||
msh
|
||||
*txt
|
||||
*sh
|
||||
|
@ -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)
|
||||
|
@ -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) {
|
||||
// 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) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user