Fixed mistake
This commit is contained in:
15
Makefile
15
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)
|
||||
|
||||
17
bfckr.c
17
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user