--- /dev/null
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+struct nest {
+ long pos;
+ struct nest *next;
+};
+
+int main(int argc, char *argv[])
+{
+ size_t offset, stacksize = 1;
+ char *b = malloc(stacksize);
+ b[0] = 0;
+ char *ptr = b;
+ struct nest *t, *callstack = NULL;
+ FILE *in;
+
+ if(argc != 2){
+ fprintf(stderr, "Usage: %s PROGRAM\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ if((in = fopen(argv[1], "r")) == NULL){
+ perror("fopen");
+ return EXIT_FAILURE;
+ }
+
+ while(1){
+ switch(fgetc(in)){
+ case EOF:
+ return EXIT_SUCCESS;
+ case '>':
+ ++ptr;
+ if(ptr > b+stacksize){
+ offset = ptr-b;
+ b = realloc(b, stacksize *= 2);
+ ptr = b+offset;
+ memset(ptr, 0, stacksize/2);
+ }
+ break;
+ case '<':
+ if(ptr == b){
+ fprintf(stderr, "There is no stack position -1...\n");
+ return EXIT_FAILURE;
+ }
+ --ptr;
+ break;
+ case '+':
+ ++*ptr;
+ break;
+ case '-':
+ --*ptr;
+ break;
+ case '.':
+ putchar(*ptr);
+ break;
+ case ',':
+ *ptr = getchar();
+ break;
+ case '[':
+ if(*ptr){
+ t = callstack;
+ callstack = malloc(sizeof(struct nest));
+ callstack->next = t;
+ if((callstack->pos = ftell(in)) == -1){
+ perror("ftell");
+ return EXIT_FAILURE;
+ }
+ } else {
+ while(fgetc(in) != ']');
+ }
+ break;
+ case ']':
+ if(fseek(in, callstack->pos-1, SEEK_SET) == -1){
+ perror("fseek");
+ return EXIT_FAILURE;
+ }
+ t = callstack;
+ callstack = callstack->next;
+ free(t);
+ break;
+ default:
+ break;
+ }
+ }
+}