diff --git a/Makefile b/Makefile index f7fa246..081960f 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC=gcc -CFLAGS=-std=c99 -Wall -O2 -static -g +CFLAGS=-std=c99 -Wall -O0 -static CLIBS=-lm PRGNAME=bfckr CFILES=$(shell find . -name '*.c') @@ -9,17 +9,24 @@ RUN=valgrind --leak-check=full DEBUG=gdb --args ARGS="examples/rot13.bf" -all: build run +all: build clean: $(STYLE) $(CFILES) rm -f *.o rm -f $(PRGNAME) + build: $(CC) $(CFLAGS) $(CLIBS) -o $(PRGNAME) -Isrc $(CFILES) + +debug: + $(CC) $(CFLAGS) -g $(CLIBS) -o $(PRGNAME) -Isrc $(CFILES) + +run_debug: + $(DEBUG) ./$(PRGNAME) $(ARGS) + run: ./$(PRGNAME) $(ARGS) + memtest: $(RUN) ./$(PRGNAME) $(ARGS) -debug: - $(DEBUG) ./$(PRGNAME) $(ARGS) diff --git a/bfckr.c b/bfckr.c index 298aa4b..ca611e6 100644 --- a/bfckr.c +++ b/bfckr.c @@ -30,7 +30,7 @@ void die(const char *message) if(errno) { perror(message); } else { - printf("[:-(] Error: %s\n", message); + printf("[:(] Error: %s\n", message); } exit(EXIT_FAILURE); @@ -71,8 +71,7 @@ void bfuck_parser(char *input) if(*p == 0) { // if the byte at the data pointer is zero // jump forward to the command after the next ] loop = 1; - // jump back to the command after the matching [ - while(loop > 0) { + while(loop > 0) { // count nested loops and make sure to get the matching ] i++; if(input[i] == '[') { loop++; @@ -88,9 +87,9 @@ void bfuck_parser(char *input) case ']': if(*p != 0) { // if the byte at the data pointer is nonzero - loop = 1; // jump back to the command after the matching [ - while(loop > 0) { + loop = 1; + while(loop > 0) { // count nested loops and make sure to get the matching [ i--; if(input[i] == '[') { loop--; @@ -129,15 +128,17 @@ int main(int argc, char* argv[]) die("Couldn't open file."); } - // read the whole file and store it in the input buffer + // read the file and store it in the input buffer while((c = getc(fp)) != EOF) { input[i++] = c; } + // close file after reading + fclose(fp); + // try to interpret it bfuck_parser(input); - // close and exit - fclose(fp); + // exit exit(EXIT_SUCCESS); }