Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added CHANGELOG, version numbering, updated Makefile to produce optim…

…ised code :) and updated code
  • Loading branch information...
commit 38a0bb374a3f21f236ea1288688314b3ef8eb6b2 1 parent 446396a
@aliclubb aliclubb authored
Showing with 24 additions and 13 deletions.
  1. +10 −0 CHANGELOG
  2. +3 −3 Makefile
  3. +2 −0  src/brainfuck.c
  4. +9 −10 src/brainfuck_shell.c
View
10 CHANGELOG
@@ -0,0 +1,10 @@
+Version 0.2
+===========
+Supports (in theory) many brainfuck programs already out there (But not LostKingdom.bf)
+Added interactive console mode (Thanks to aliclubb)
+Added Makefile and UNIX man pages
+Optimised code slightly
+
+Version 0.1
+===========
+First release
View
6 Makefile
@@ -4,13 +4,13 @@ OS := $(shell uname)
all:
mkdir -p bin
ifeq ($(OS), Darwin)
- $(CC) -o bin/brainfuck src/*
+ $(CC) -O3 -Wall -o bin/brainfuck src/*
endif
ifeq ($(OS), Linux)
- $(CC) -o bin/brainfuck src/*
+ $(CC) -O3 -Wall -o bin/brainfuck src/*
endif
ifeq ($(OS), CYGWIN_NT-5.1)
- $(CC) -c src/* -o bin/brainfuck
+ $(CC) -O3 -Wall -c src/* -o bin/brainfuck
endif
install:
cp bin/brainfuck /usr/local/bin/brainfuck
View
2  src/brainfuck.c
@@ -1,3 +1,4 @@
+/* This is the brainfuck 'backend'. It does all the interpretation :) */
#include <stdio.h>
#include <string.h>
#ifndef BRAINFUCK_H
@@ -57,4 +58,5 @@ void brainfuck_eval(char chars[]) {
break;
}
}
+ putchar(10);
}
View
19 src/brainfuck_shell.c
@@ -1,15 +1,12 @@
#include "brainfuck.h"
#include <stdio.h>
-#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
-#if defined __WIN32__ || defined _WIN32_ || defined _WIN32
-#include <windows.h>
-#elif defined __APPLE__ || defined __unix__ || defined unix || defined _unix || defined __unix
+#ifdef __APPLE__ || defined __unix__ || defined unix || defined _unix || defined __unix
#include <unistd.h>
#endif
-
+/* Read the file and pass it to the brainfuck_eval() function */
void brainfuck_file(char filename[]) {
FILE *file;
char c;
@@ -25,10 +22,13 @@ void brainfuck_file(char filename[]) {
size = ftell(file);
fseek(file, 0, SEEK_SET);
char chars[size];
+ /* Strange fix required in order to run most brainfuck programs... */
chars[pointer++] = ' ';
+ /* Place each character from the file into the array */
while ((c = fgetc(file)) != EOF)
chars[pointer++] = (char) c;
fclose(file);
+ /* Run the code */
brainfuck_eval(chars);
}
@@ -38,16 +38,15 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
} else if(strcmp(argv[1], "-i") == 0) {
printf("Entering interactive mode...\n");
- printf("Welcome to the Brainfuck Interpreter!\n");
+ printf("Welcome to the Brainfuck Interpreter v0.2!\n");
+ char c;
+ int pointer = 0;
for(;;) {
printf("brainfuck> ");
- char c;
- int pointer = 0;
- /* Put every character in character array */
int size = 36000;
char chars[size];
chars[pointer++] = ' ';
- while ((c = getchar()) != '\n')
+ while ((c = getchar()) != 10)
chars[pointer++] = (char) c;
/* Run the code */
brainfuck_eval(chars);
Please sign in to comment.
Something went wrong with that request. Please try again.