diff --git a/334/Makefile b/334/Makefile index 5a2856f..f67c39b 100644 --- a/334/Makefile +++ b/334/Makefile @@ -1,3 +1,10 @@ # Single make file for everything becauz lazy -1: - gcc bindec.c -o bin +object=hw.c +cc=gcc +output=bin + +default: + $(cc) $(object) -o $(output) + +clean: + rm -f $(output) diff --git a/334/bin b/334/bin deleted file mode 100755 index c1564b3..0000000 Binary files a/334/bin and /dev/null differ diff --git a/334/bindec.c b/334/homework/1/bindec.c similarity index 100% rename from 334/bindec.c rename to 334/homework/1/bindec.c diff --git a/334/responses/binhex.txt b/334/homework/1/binhex.txt similarity index 100% rename from 334/responses/binhex.txt rename to 334/homework/1/binhex.txt diff --git a/334/responses/os-intro.txt b/334/homework/1/os-intro.txt similarity index 100% rename from 334/responses/os-intro.txt rename to 334/homework/1/os-intro.txt diff --git a/334/homework/2/msh.c b/334/homework/2/msh.c new file mode 100644 index 0000000..53f5725 --- /dev/null +++ b/334/homework/2/msh.c @@ -0,0 +1,44 @@ +#include +#include +#include + +#define PROMPT "msh> " +#define EXIT_CMD "exit" +// Accounting for the \n +#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); + // 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 +} diff --git a/334/homework/2/processes.txt b/334/homework/2/processes.txt new file mode 100644 index 0000000..117ecdb --- /dev/null +++ b/334/homework/2/processes.txt @@ -0,0 +1,22 @@ +# Instructions: edit this file to provide your homework answers. +# +# Problem numbers are shown on lines that begin with #@. +# Please put your solution to a problem on the line *after* the +# line with the problem number. +# +# Do not modify this file *except* to add lines as needed after each problem. +# Blank lines are ignored. You don't need to put your name in the file. +# +# No points will be awarded to incorrectly-formatted files. +# + +#@ 1 -- enter 'a', 'b', or 'c' (don't use quotes in any answer) +b +#@ 2 -- enter 'a', 'b', or 'c' +c +#@ 3 -- enter 'a' or 'b' +b +#@ 4 -- enter 'a' or 'b' +b +#@ 5 -- enter 'a', 'b', or 'c' +c diff --git a/334/homework/2/puzzle.txt b/334/homework/2/puzzle.txt new file mode 100644 index 0000000..2f0daeb --- /dev/null +++ b/334/homework/2/puzzle.txt @@ -0,0 +1,32 @@ +# Instructions: edit this file to provide your homework answers. +# +# Problem numbers are shown on lines that begin with #@. +# Please put your solution to a problem on the line *after* the +# line with the problem number. +# +# Do not modify this file *except* to add lines as needed after each problem. +# Blank lines are ignored. You don't need to put your name in the file. +# +# No points will be awarded to incorrectly-formatted files. +# + +#@ 1 -- enter a single number +1 +#@ 2 -- enter 'Y' or 'N' +2 +#@ 3 -- enter 'Y' or 'N' +Y +#@ 4 -- enter 'Y' or 'N' +N +#@ 5 -- enter text on a single line +some stuff +#@ 6 -- enter 'Y' or 'N' +Y +#@ 7 -- enter text on a single line +stuff +#@ 8 -- enter 'Y' or 'N' +N +#@ 9 -- enter text on a single line +some stuff +#@ 10 -- enter 'Y' or 'N' +Y