diff --git a/nbfi/Makefile b/nbfi/Makefile new file mode 100644 index 0000000..4cd7fa8 --- /dev/null +++ b/nbfi/Makefile @@ -0,0 +1,37 @@ +override CFLAGS+=-Werror -Wall -g -fPIC -O2 -DNDEBUG -std=c99 -ftrapv -Wfloat-equal -Wundef -Wwrite-strings -Wconversion -Wuninitialized +PREFIX=/usr/bin +BUILDDIR=bin/ +CC=gcc-mp-4.9 + +TARGET=nbfi +SOURCES=$(wildcard src/*.c) + +#Makes everything +all: + mkdir $(BUILDDIR) 2> /dev/null || true + $(CC) $(CFLAGS) $(SOURCES) -o $(BUILDDIR)$(TARGET) + @echo Running tests + ./test.sh + +#Uses picky extensions and makes everything(Extensions may break compiling) +dev: + make all CFLAGS+=-Wshadow -Wunreachable-code -Wswitch-enum -Wswitch-default -Wcast-align -Winit-self -Wpointer-arith -Weffc++ + +#Cleans directory(no uninstall!) +clean: + rm -rf bin + +#Installs into specified(or default) directory +install: + install -d $(PREFIX)/NBFI + install $(BUILDDIR)$(TARGET) $(PREFIX)/NBFI + +#Uninstalls from specified(or default)directory +uninstall: + rm -rf $(PREFIX)/NBFI + +#Checks for bad functions +BADFUNCS='[^_.>a-zA-Z0-9](str(n?cpy|n?cat|xfrm|n?dup|str|pbrk|tok|_)|stpn?cpy|a?sn?printf|byte_)' +check: + @echo Files with potentially dangerous functions: + @grep $(BADFUNCS) $(SOURCES) || echo None diff --git a/nbfi/helloworld.bf b/nbfi/helloworld.bf deleted file mode 100644 index f079b46..0000000 --- a/nbfi/helloworld.bf +++ /dev/null @@ -1,42 +0,0 @@ -++++++++++ -[ - > - +++++++ - > - ++++++++++ - > - +++ - > - + - <<<< - - -] -> -++ -. -> -+ -. -+++++++ -.. -+++ -. -> -++ -. -<< -+++++++++++++++ -. -> -. -+++ -. ------- -. --------- -. -> -+ -. -> -. diff --git a/nbfi/hw.bf b/nbfi/hw.bf deleted file mode 100644 index 265e751..0000000 --- a/nbfi/hw.bf +++ /dev/null @@ -1 +0,0 @@ -++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>. diff --git a/nbfi/main.c b/nbfi/main.c deleted file mode 100644 index fc073e0..0000000 --- a/nbfi/main.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main(){ - printf("Hello, world!\n"); - return 0; -} diff --git a/nbfi/nbfi b/nbfi/nbfi deleted file mode 100755 index 86346af..0000000 Binary files a/nbfi/nbfi and /dev/null differ diff --git a/nbfi/nbfi.c b/nbfi/src/nbfi.c similarity index 94% rename from nbfi/nbfi.c rename to nbfi/src/nbfi.c index 9ec8aee..1809e4b 100644 --- a/nbfi/nbfi.c +++ b/nbfi/src/nbfi.c @@ -20,8 +20,8 @@ #define STACK_EMPTY() (sp == 0) #define STACK_FULL() (sp == MAX_SIZE) -static inline void die(int code, char* message){ - fprintf(stderr, message); +static inline void die(int code, const char* message){ + fprintf(stderr, "%s", message); exit(code); } @@ -83,7 +83,7 @@ void execute(){ case OP_INC_VAL: data[ptr]++; break; case OP_DEC_VAL: data[ptr]--; break; case OP_OUT: putchar(data[ptr]); break; - case OP_IN: data[ptr] = (unsigned int)getchar(); break; + case OP_IN: data[ptr] = (short unsigned int)getchar(); break; case OP_JMP_FWD: if(!data[ptr]) { pc = program[pc].operand; } break; case OP_JMP_BCK: if(data[ptr]) { pc = program[pc].operand; } break; default: die(2, "Unknown instruction.");