msh in its own long standing directory now

This commit is contained in:
shockrah 2019-09-21 12:58:31 -07:00
parent 1fdd54e80f
commit a85dffe4da
3 changed files with 5 additions and 47 deletions

View File

@ -1,10 +1,14 @@
# Single make file for everything becauz lazy # Single make file for everything becauz lazy
object=hw.c object=homework/msh/msh.c
cc=gcc cc=gcc
output=bin output=bin
default: default:
$(cc) $(object) -o $(output) $(cc) $(object) -o $(output)
run:
./bin
clean: clean:
rm -f $(output) rm -f $(output)

View File

@ -1,46 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define PROMPT "msh> "
#define EXIT_CMD "exit"
#define MAX_BUF 121
void echo(const char*);
void remove_newline(char*);
void exit_branch(const char*);
int main(void) {
char buffer[MAX_BUF];
while(1) {
printf("%s", PROMPT);
fgets(buffer, MAX_BUF, stdin);
if(!strlen(buffer)) {
return 0;
}
// process the input
remove_newline(buffer);
exit_branch(buffer);
echo(buffer);
}
return 0;
}
void echo(const char* buf) {
printf("%s\n", buf);
}
void remove_newline(char* buf) {
char* c = buf;
while(*c != '\n') { c++; }
*c='\0';
}
void exit_branch(const char* buf) {
if(strcmp(buf, EXIT_CMD)) {
return;
}
exit(0);
return; // just for gcc but exit shouldn't fail
}