bf-20041219ubuntu7/0000775000000000000000000000000014002200521010551 5ustar bf-20041219ubuntu7/Makefile0000664000000000000000000000174112031263150012223 0ustar # `make TTY=slang' will build with slang support # `make TTY=termios' or just `make' will build with termios support CC = gcc LINKER = gcc ifndef TTY TTY = termios endif ifeq "$(TTY)" "slang" LIBS = -lslang endif CFLAGS_F = -O3 -fno-builtin -funsigned-char CFLAGS_W = -Wno-sign-compare -Wpointer-arith -Wno-system-headers -Wshadow -Wbad-function-cast -Werror #-Wunreachable-code CFLAGS = $(CFLAGS_F) -ansi -Wall $(CFLAGS_W) #-march=$(shell uname -m) OBJ = tty_$(TTY).o bf.o errors.o BINARY = bf CLEAN = *~ *.bak *.o $(BINARY) LDFLAGS = -s .SUFFIXES: .c .o all: $(OBJ) $(LINKER) $(LDFLAGS) $(OBJ) -o "$(BINARY)" $(LIBS) %o: %c Makefile $(CC) $(CFLAGS) -c -o $@ $< tty_termios.c: tty.h bf.h tty_slang.c: tty.h errors.h bf.h bf.c: bf.h tty.h errors.h errors.c: errors.h clean: rm -f $(CLEAN) install: install -d $(DESTDIR)/usr/bin install $(BINARY) $(DESTDIR)/usr/bin deb: dpkg-buildpackage -rfakeroot deb-clean: rm -rf debian/bf debian/files debian/*substvars $(MAKE) clean bf-20041219ubuntu7/bf.10000664000000000000000000000440412031263150011233 0ustar .TH "bf" "1" "20041219" "Stephan Beyer " "devel" .SH "NAME" .LP bf \- yet another Brainfuck interpreter .SH "SYNTAX" .LP bf [\fB\-h\fR] [\fIoptions\fP] <\fIfilename\fP> .SH "DESCRIPTION" .LP bf ('Yet another Brainfuck interpreter') is a simple interpreter for the esoteric Brainfuck language. .SH "OPTIONS" .LP .TP \fB\-c\fR<\fInum\fP> Specify the number \fInum\fP of the last cell you are allowed to use in your Brainfuck program. So if you use \fI\-c0\fR (or just \fI\-c\fR), you'll have one cell (one byte in memory) to use on your tape. '>'ing and '<'ing will be impossible. The original Brainfuck interpreter by Urban Mueller used an array of 30000 bytes (\fI\-c29999\fR). .br Our default value is 9999. Usually you need less. .TP \fB\-i\fR Output Brainfuck code input to \fIstderr\fR. This feature is useful if you can't find out why some Brainfuck code doesn't work the way it should e.g. ignored loops, or a Brainfuck character within a comment. Note: Up to 32 +, \-, < and > are summarized and displayed as only one. This feature was introduced in version 20040423. .TP \fB\-n\fR Some Brainfuck contests specify a 0 byte as End Of Input. So -n translates a \\n byte input into a 0 byte input. Disadvantage: the input can only consist of one line. .TP \fB\-w\fR Disallow byte wrap\-around. This causes errors if you try to decrement ('\-') a 0x00 byte or to increment ('+') a 0xFF byte. This feature is useful if you want to take part in Brainfuck contests where such wrapping\-around is disallowed. .br By default (without \fI\-w\fR), incrementing 0xFF results in 0x00 and decrementing 0x00 results in 0xFF. .TP \fB\-,\fR<\fImode\fR> Specify input mode. <\fImode\fR> can be: \fI0\fR (zero) Normal input using \fIgetchar(3)\fR. .br \fI1\fR Single\-char input. You won't see what you type. .br \fI2\fR Single\-char input. You will see what you type. .br \fI3\fR The same as 1, but doesn't allow escape characters if compiled with slang. .br \fI4\fR The same as 2, but doesn't allow escape characters, if compiled with slang. (recommended) Default is 0. (In some versions the default was 4.) .SH "LIMITATIONS" .TP It's not allowed to '<' below the first cell. .TP It's not allowed to '>' beyond the last cell. .SH "AUTHORS" .LP Stephan Beyer bf-20041219ubuntu7/bf.c0000664000000000000000000002410214002201141011302 0ustar /* bf.c ****************************************************************************** Yet another Brainfuck interpreter Author: Stephan Beyer Copyright (C) GPL, 2003, 2004 Stephan Beyer - s-beyer@gmx.net Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************** */ #include #include /* malloc, atoi */ #include /* strlen, strchr */ #include /* signal */ #include "bf.h" #include "errors.h" #include "tty.h" #define ShowCode(c) if (opt.showinput) fputc(c, stderr); typedef struct __progr { char op; int plus; /* +- */ int step; /* <> */ int match; /* position of matching bracket (if [ or ]) */ } Progr; Opt opt; /* SIGINT, SIGTERM, SIGQUIT handler */ void ForceExit(int signum) { ttyRestore(); /* if signal during "," */ switch(signum) { case SIGINT: puts("Interrupted..."); break; case SIGTERM: puts("Terminated..."); break; case SIGQUIT: puts("Quit..."); break; } exit(errSIGNAL); } #if 0 /* efficienter(?) FindMatchingBrackets, but some are missing, * so it's #if 0'ed */ void FindMatchingBrackets(void) { typedef struct __loops { size_t begin, level, end; } Loops; int level = 0, /* bracket level */ b = 0, /* bracket index */ i = 0; /* program index */ Progr *px; Loops *loops; /* helping structure */ loops = (Loops*)calloc(brackets, sizeof(Loops)); DoAndErr(!loops, calloc, errMEMORY); for (i = 0; i < psize; i++) { px = program + i; if (px->op == '[') { level++; (loops+b)->begin = i; (loops+b)->level = level; b++; } else if (px->op == ']') { level--; if (level < 0) ErrorMsg(errBRACKET, "Unmatching ] bracket."); } } if (level) ErrorMsg(errBRACKET, "Unbalanced brackets. Too many [s."); for (b=brackets-1 /* equal --b */; b>=0; b--) { Loops *lx = loops+b; if ((b == brackets-1) || (lx->level >= (lx+1)->level)) { i = lx->begin; } else if (lx->level < (lx+1)->level) { int j; for (j = 2; (lx->level < (lx+j)->level) && (b+j < brackets); j++); i = (lx+j-1)->end; } for (px = program+i+1; px->op != ']' ; px++); lx->end = px - program; } /* now write it into program */ for (b = 0; b < brackets; b++) { (program+((loops+b)->begin))->match = (loops+b)->end; (program+((loops+b)->end))->match = (loops+b)->begin; } free(loops); } #endif /* find matching brackets (loop) */ void FindMatchingBrackets(Progr *program, size_t psize) { int i; for (i = 0; i < psize; i++) { register Progr *px = program + i; if(px->op == '[') { int j, l=0; for(j=i+1; jop == '[') l++; if((program+j)->op == ']') { if (l) l--; else break; } } if (l) ErrorMsg(errBRACKET, "Unbalanced brackets."); px->match = j; (program+j)->match = i; } } } /* read input file and write it into , return size of program */ size_t ReadProgram(Progr **program) { size_t psize = 0; FILE *fp; int i = 0, read = 0; char fbuf[BUFSIZ], *vbuf = NULL, *c; char oldc = 0; /* file opening banana */ fp = fopen(opt.filename, "rb"); DoAndErr(!fp, fopen, errFILE); /* read file */ while (!feof(fp)) { i = fread((char*)fbuf, 1, sizeof(fbuf), fp); vbuf = realloc(vbuf, read+=i); DoAndErr(!vbuf, realloc, errMEMORY); memcpy(vbuf+read-i, fbuf, i); } fclose(fp); /* determine program size */ for(c = vbuf; c < vbuf+read; c++) { if (strchr("+-<>.,[]", *c)) { if ((!oldc) || (!strchr("<>", oldc) && !strchr("+-<>", *c)) || (strchr("<>", oldc) && !strchr("<>", *c))) psize++; #if 0 if (*c=='[') brackets++; #endif oldc = *c; } } /* alloc *zeroed* memory for program */ *program = (Progr*)calloc(psize, sizeof(Progr)); DoAndErr(!*program, calloc, errMEMORY); oldc = 'X'; i = 0; /* read vbuf again and put into program */ for(c = vbuf; c < vbuf+read; c++) { if (strchr("+-<>.,[]", *c)) { Progr *x; if ((!strchr("<>X", oldc) && !strchr("+-<>", *c)) || (strchr("<>", oldc) && !strchr("<>", *c))) i++; x = *program+i; switch(*c) { case '+': x->plus++; break; case '-': x->plus--; break; case '>': x->step++; break; case '<': x->step--; break; default: x->op = *c; break; } oldc = *c; } } free(vbuf); /* cleanup */ return psize; } char GetInput(void) { char c; if (!opt.inputmode) c = getchar(); else c = ttyGetInput(); if (opt.null && (c == '\n')) /* translate \n to \0? */ c = 0; return c; } void Interprete(Progr *program, size_t psize) { register char *array; /* the Brainfuck array */ register char *p; /* and the array pointer */ register int i = 0; /* program position */ /* reset array and pointer */ array = calloc(opt.cells+1, sizeof(char)); DoAndErr(!array, malloc, errMEMORY); p = array; while (i < psize) { register Progr px = *(program + i); if (px.op) { ShowCode(px.op); switch (px.op) { case '[': if (!*p) { i = px.match; px = *(program+i); } break; case ']': if (*p) /* repeat */ { i = px.match; px = *(program+i); } break; case '.': putchar(*p); fflush(stdout); break; case ',': *p = GetInput(); break; } } if (px.plus) /* do +- */ { ShowCode(px.plus > 0 ?'+':'-'); if (!opt.wraparound) { if (*p+px.plus > 255) ErrorMsg(errWRAPAROUND, "Out of range! You wanted to '+' a 0xFF byte. See -w option."); else if(*p+px.plus < 0) ErrorMsg(errWRAPAROUND, "Out of range! You wanted to '-' a 0x00 byte. See -w option."); } *p += px.plus; } if (px.step) /* do <> */ { ShowCode(px.step > 0 ?'>':'<'); if (p+px.step > array+opt.cells) ErrorMsg(errOUTOFRANGE, "Out of range! You " "wanted to '>' beyond the last cell." "See -c option."); else if (p+px.step < array) ErrorMsg(errOUTOFRANGE, "Out of range! You" "wanted to '<' below the first cell.\n" "To solve, add some '>'s at the " "beginning, for example."); p += px.step; } i++; } free(array); /* cleanup */ } /* display usage information */ void Usage(char *bin) { printf( "bf - a Brainfuck interpreter version %s\n", VERSION); puts( "(C) 2003, 2004, Stephan Beyer, GPL, s-beyer@gmx.net\n\n" "Usage information: "); printf( "\t%s [-h] [options] inputfile\n\n", bin); puts( "Available options:"); printf( "\t-c specify number of cells [%d]\n", opt.cells); printf( "\t-i show used code input (stderr)\n" "\t-n translate input: 10 (\\n) to 0\n" "\t-w disallow decrementing 0 and incrementing 255\n" "\t-, set input mode: 0-4 [%d]\n", opt.inputmode); puts( "\nSee the bf(1) manpage for more information.\n" "Have fun!"); } void HandleOptions(int c, char **v) /* too lazy to use getopt this time ;) */ { int i; /* setting defaults */ opt.showinput = 0; opt.cells = CELLS; opt.inputmode = 0; opt.null = 0; opt.wraparound = 1; /* allow by default */ if (c <= 1) /* no filename given */ { Usage(*v); ErrorMsg(errOPT, "No input file given."); } char help[]="-h"; if (!strcmp(*(v+1), help)) /* is first argument '-h'? */ { Usage(*v); exit(0); } for(i = 1; i < c-1; i++) /* options? */ { if ((**(v+i) == '-') && (strlen(*(v+i)) >= 2)) { switch(*(*(v+i)+1)) { case 'c': opt.cells = atoi(*(v+i)+2); break; case 'i': opt.showinput = 1; break; case 'n': opt.null = 1; break; case 'w': opt.wraparound = 0; break; case ',': opt.inputmode = atoi(*(v+i)+2); break; default: Usage(*v); printf("Unable to handle option %s - ", *(v+i)); ErrorMsg(errOPT, "Unknown option."); } } else { Usage(*v); printf("Invalid argument %s - ", *(v+i)); ErrorMsg(errOPT, "Invalid argument(s)."); } } opt.filename = *(v+i); /* last option MUST be filename */ } #ifdef DEBUGCODE void debugPrintProgram(Progr *program, size_t psize) { int i,j; for (i = 0; iop) { case '[': putchar('['); printf(" %d ", (program+i)->match); break; case ']': putchar(']'); printf(" %d ", (program+i)->match); break; case ',': putchar(','); break; case '.': putchar('.'); break; } for (j=0; j < abs((program+i)->plus); j++) if ((program+i)->plus > 0) putchar('+'); else putchar('-'); for (j=0; j < abs((program+i)->step); j++) if ((program+i)->step > 0) putchar('>'); else putchar('<'); putchar('\n'); } } #endif int main(int argc, char **argv) { Progr* program; /* program structure */ size_t psize; /* program size */ HandleOptions(argc, argv); psize = ReadProgram(&program); FindMatchingBrackets(program, psize); #ifdef DEBUGCODE debugPrintProgram(program, psize); #endif ttyInit(); /* catch some signals */ /* TODO use sigaction? */ signal(SIGINT, ForceExit); signal(SIGTERM, ForceExit); signal(SIGQUIT, ForceExit); /* reading and interpreting */ Interprete(program, psize); /* cleanup */ free(program); return errNO; } bf-20041219ubuntu7/bf.h0000664000000000000000000000052414002201131011310 0ustar /* bf.h */ #ifndef BF_H #define BF_H #define VERSION "20041219" #define CELLS 9999 /* options */ typedef struct { char *filename; int cells; /* -c */ unsigned short inputmode; /* -, */ unsigned showinput : 1; /* -i */ unsigned wraparound : 1; /* -w */ unsigned null : 1; /* -n */ } Opt; extern Opt opt; /* bf options */ #endif bf-20041219ubuntu7/debian/0000775000000000000000000000000014002201150011772 5ustar bf-20041219ubuntu7/debian/changelog0000664000000000000000000000735014002201150013651 0ustar bf (20041219ubuntu7) hirsute; urgency=medium * bf.{c,h}: Fix FTBFS with GCC 10 due to multiple definitions. -- Logan Rosen Wed, 20 Jan 2021 23:26:16 -0500 bf (20041219ubuntu6) bionic; urgency=high * No change rebuild to pick up -fPIE compiler default -- Balint Reczey Tue, 03 Apr 2018 12:14:18 +0000 bf (20041219ubuntu5) quantal; urgency=low * debian/control: added ${misc:Depends} since debhelper is used. -- Benjamin Kerensa Mon, 24 Sep 2012 00:27:16 -0700 bf (20041219ubuntu4) oneiric; urgency=low * Makefile: fixing library order at the linker call (LP: #765951) -- Ricardo Salveti de Araujo Sun, 04 Sep 2011 20:30:17 -0300 bf (20041219ubuntu3) karmic; urgency=low * bf.c: work around to fix gcc warning (LP: #453469): http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35903 This fix a "array subscript is above array bounds" warning. * debian/control: - Fixed lithian debian-rules-ignores-make-clean-error, - debhelper Build-Depends changed to 6 * debian/compat: Changed to 6 -- Alfonso Cepeda Caballos Sun, 18 Oct 2009 18:19:38 +0200 bf (20041219ubuntu2) gutsy; urgency=low * debian/control: Update maintainer fields according to debian- maintainer-field spec. -- Martin Pitt Tue, 14 Aug 2007 10:51:54 +0000 bf (20041219ubuntu1) dapper; urgency=low * slang-transition: Update build-dependency slang1-dev | slang1-utf8-dev to libslang2-dev. -- Stefan Potyra Wed, 8 Feb 2006 02:09:24 +0100 bf (20041219) unstable; urgency=low * bf.c: rewrite of ReadProgram() and Interprete() to gain speed, removed PutIntoProgram(), added FindMatchingBrackets() and removed -d (debug) option; minor changes * errors.c: changes to get non-GNU-compatibility * stack.[ch]: removed, because useless * added examples/quine[123].b, examples/hello.b -- Stephan Beyer Sun, 19 Dec 2004 14:22:33 +0100 bf (20040828) unstable; urgency=low * stack.c, stack.h: added trivial stack implementation * bf.c: converted recursion to iteration using stack (advantages: faster, no stack overflows on deep loops) Note: stack.[ch] became useless, because we use a faster array stack now. -- Stephan Beyer Sat, 28 Aug 2004 09:12:36 +0200 bf (20040728) unstable; urgency=low * tty_termios.c is for usage without slang (TODO) * tty_slang.c is where slang-specific code went into * bf.c: added signal handler for SIGINT (C-c), SIGTERM (kill) and SIGQUIT (C-\), changed default input mode from 4 to 0 * Makefile: included gcc optimizations * added examples/* * compiled with Slang support (slang1, not slang1a-utf8) -- Stephan Beyer Thu, 29 Jul 2004 01:30:20 +0200 bf (20040704) unstable; urgency=low * "Bugfix" in manpage (unquoted minus) -- Stephan Beyer Sun, 4 Jul 2004 20:10:57 +0200 bf (20040430) unstable; urgency=low * Bugfix: -,1 to -,4 returned \r instead of \n * Added -n option to translate \n input to \0. -- Stephan Beyer Fri, 30 Apr 2004 12:59:22 +0200 bf (20040423) unstable; urgency=low * Optimized code, speeded up interpreting -- Stephan Beyer Fri, 23 Apr 2004 20:40:25 +0200 bf (20040408) unstable; urgency=low * Added -, option (0 to 4) to specify new input modes (using S-Lang library) and made 4 the default * Added -h... (help) and -w option * Wrote manual page -- Stephan Beyer Thu, 8 Apr 2004 13:46:31 +0200 bf (20031030) unstable; urgency=low * Initial Release. -- Stephan Beyer Wed, 10 Mar 2004 19:49:04 +0100 bf-20041219ubuntu7/debian/compat0000664000000000000000000000000212031263150013200 0ustar 6 bf-20041219ubuntu7/debian/control0000664000000000000000000000123212031263150013403 0ustar Source: bf Section: devel Priority: optional Maintainer: Ubuntu Developers XSBC-Original-Maintainer: Stephan Beyer Build-Depends: debhelper (>= 6), libslang2-dev Standards-Version: 3.6.1 Package: bf Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} Description: a fast Brainfuck interpreter bf ('a Brainfuck interpreter') is a simple and fast interpreter for the esoteric programming language Brainfuck. It offers some options to define special behavior, which is nice if you take part in Brainfuck programming contests with special rules. . This package is compiled with S-Lang support. bf-20041219ubuntu7/debian/copyright0000664000000000000000000000055112031263150013736 0ustar This package was debianized by Stephan Beyer , who is also the upstream author of 'bf', Copyright (C) 2003, 2004, by Stephan Beyer, too. You are free to distribute this software under the terms of the GNU General Public License. On Debian systems, the complete text of the GNU GPL can be found in the file /usr/share/common-licenses/GPL ... bf-20041219ubuntu7/debian/rules0000775000000000000000000000153012031263150013061 0ustar #!/usr/bin/make -f #export DH_VERBOSE=1 configure: # do nothing build: dh_testdir $(MAKE) TTY=slang clean: dh_testdir $(MAKE) clean dh_clean install: build dh_testdir dh_testroot dh_clean -k $(MAKE) install DESTDIR=$(CURDIR)/debian/bf # Build architecture-independent files here. binary-indep: build install # We have nothing to do by default. # Build architecture-dependent files here. binary-arch: build install dh_testdir dh_testroot dh_installchangelogs dh_installdocs dh_installexamples examples/INDEX examples/*.b # dh_install # dh_installmenu # dh_installmime dh_installman bf.1 dh_link dh_strip dh_compress dh_fixperms # dh_perl # dh_makeshlibs dh_installdeb dh_shlibdeps dh_gencontrol dh_md5sums dh_builddeb binary: binary-indep binary-arch .PHONY: build clean binary-indep binary-arch binary install configure bf-20041219ubuntu7/errors.c0000664000000000000000000000431612031263150012244 0ustar /* errors.c ****************************************************************************** Author: Stephan Beyer Description of this file: error handling Copyright (C) GPL, 2000,2001,2002,2003,2004 Stephan Beyer - s-beyer@gmx.net Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************** */ #include /* errno ... */ #include /* fprintf... */ #include /* exit ... */ #include /* strerror ... */ #include "errors.h" /* prints an error message to stderr and exits with given nr, * doesn't exit when nr==0 */ void ErrorMsg(signed int nr, const char *msg) { fprintf(stderr, "Error: %s\n", msg); if (nr) { puts(ERROCCMSG); exit(nr); } } /* Usage: HandleError("function", __FILE__, __LINE__, 0) * - nr specifies the exit code (if nonzero) * if zero, it won't exit... */ void HandleError(const char *def, char *file, unsigned int line, signed int nr) { char *separator; if (def == NULL || *def == '\0') def = separator = ""; else separator = " - "; fprintf(stderr, "%s%s%s (in file %s, line %d)\n", def, separator, strerror(errno), file, line); if (nr) { puts(ERROCCMSG); exit(nr); } } bf-20041219ubuntu7/errors.h0000664000000000000000000000075612031263150012255 0ustar /* errors.h * (C) Stephan Beyer, 2003, 2004, GPL */ #ifndef ERRORS_H #define ERRORS_H #define ERROCCMSG "an error occured" #define DoAndErr(COND,STR,ERR) if (COND) HandleError(#STR, __FILE__, __LINE__, ERR); enum errorcodes { errNO = 0, errMEMORY, errOPT, errFILE, errBRACKET, errOUTOFRANGE, errWRAPAROUND, errSLANG, errSIGNAL, errUNDEFINED }; void ErrorMsg(signed int nr, const char *msg); void HandleError(const char *def, char *file, unsigned int line, signed int nr); #endif bf-20041219ubuntu7/examples/0000775000000000000000000000000012031264170012401 5ustar bf-20041219ubuntu7/examples/INDEX0000664000000000000000000000116512031263150013173 0ustar cat.b a simple program which outputs its input. bf cat.b < file hello.b -- Hello world, source: Wikipedia mandelbrot.b -- by Erik Bosman size an x-terminal-emulator or your console to 130x48 chars and enjoy! prime.b -- author unknown? brainfuck find-primes-up-to...-algorithm - slow, but works ;) quine1.b -- by Jason Reed quine2.b -- by Brian Raiter quine3.b -- by Jeremy Bruestle ... all quines taken from http://www.nyx.net/~gthompso/self_brainf.txt A "quine" means self-producing code. Code showing itself. random.b -- by Daniel B Cristofani a replacement for /dev/random or /dev/urandom No, it's always the same ;) bf-20041219ubuntu7/examples/cat.b0000664000000000000000000000000712031263150013305 0ustar +[,.+] bf-20041219ubuntu7/examples/hello.b0000664000000000000000000000016112031263150013642 0ustar ++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<< +++++++++++++++.>.+++.------.--------.>+.>. bf-20041219ubuntu7/examples/mandelbrot.b0000664000000000000000000002662512031263150014703 0ustar A mandelbrot set fractal viewer in brainf*** written by Erik Bosman +++++++++++++[->++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[[ >>>>>>>>>]+[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-]>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>[-]+ <<<<<<<+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>>+>>>>>>>>>>>>>>>>>>>>>>>>>> >+<<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+[>>>>>>[>>>>>>>[-]>>]<<<<<<<<<[<<<<<<<<<]>> >>>>>[-]+<<<<<<++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<+++++++[-[->>> >>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[[-]>>>>>>[>>>>> >>[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>> [>>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<+<<]>>>>>>>>]<<<<<<<<<[<<<<<<< <<]>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[->>>>>>>> -<<[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>> >>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>[-]<<<++++ +[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>->>>>>>>>>>>>>>>>>>>>>>>>>>>-<<<<<<[<<<< <<<<<]]>>>] bf-20041219ubuntu7/examples/prime.b0000664000000000000000000001000412031263150013650 0ustar =================================================================== ======================== OUTPUT STRING ============================ =================================================================== >++++++++[<++++++++>-]<++++++++++++++++.[-] >++++++++++[<++++++++++>-]<++++++++++++++.[-] >++++++++++[<++++++++++>-]<+++++.[-] >++++++++++[<++++++++++>-]<+++++++++.[-] >++++++++++[<++++++++++>-]<+.[-] >++++++++++[<++++++++++>-]<+++++++++++++++.[-] >+++++[<+++++>-]<+++++++.[-] >++++++++++[<++++++++++>-]<+++++++++++++++++.[-] >++++++++++[<++++++++++>-]<++++++++++++.[-] >+++++[<+++++>-]<+++++++.[-] >++++++++++[<++++++++++>-]<++++++++++++++++.[-] >++++++++++[<++++++++++>-]<+++++++++++.[-] >+++++++[<+++++++>-]<+++++++++.[-] >+++++[<+++++>-]<+++++++.[-] =================================================================== ======================== INPUT NUMBER ============================ =================================================================== + cont=1 [ - cont=0 >, ======SUB10====== ---------- [ not 10 <+> cont=1 =====SUB38====== ---------- ---------- ---------- -------- > =====MUL10======= [>+>+<<-]>>[<<+>>-]< dup >>>+++++++++ [ <<< [>+>+<<-]>>[<<+>>-]< dup [<<+>>-] >>- ] <<<[-]< ======RMOVE1====== < [>+<-] ] < ] >>[<<+>>-]<< =================================================================== ======================= PROCESS NUMBER =========================== =================================================================== ==== ==== ==== ==== numd numu teid teiu ==== ==== ==== ==== >+<- [ >+ ======DUP====== [>+>+<<-]>>[<<+>>-]< >+<-- >>>>>>>>+<<<<<<<< isprime=1 [ >+ <- =====DUP3===== <[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<<< =====DUP2===== >[>>+>+<<<-]>>>[<<<+>>>-]<<< < >>> ====DIVIDES======= [>+>+<<-]>>[<<+>>-]< DUP i=div << [ >>>>>+ bool=1 <<< [>+>+<<-]>>[<<+>>-]< DUP [>>[-]<<-] IF i THEN bool=0 >> [ IF i=0 <<<< [>+>+<<-]>>[<<+>>-]< i=div >>> - bool=0 ] <<< - DEC i << - ] +>>[<<[-]>>-]<< >[-]< CLR div =====END DIVIDES==== [>>>>>>[-]<<<<<<-] if divides then isprime=0 << >>[-]>[-]<<< ] >>>>>>>> [ - <<<<<<<[-]<< [>>+>+<<<-]>>>[<<<+>>>-]<<< >> =================================================================== ======================== OUTPUT NUMBER =========================== =================================================================== [>+<-]> [ ======DUP====== [>+>+<<-]>>[<<+>>-]< ======MOD10==== >+++++++++< [ >>>+<< bool= 1 [>+>[-]<<-] bool= ten==0 >[<+>-] ten = tmp >[<<++++++++++>>-] if ten=0 ten=10 <<- dec ten <- dec num ] +++++++++ num=9 >[<->-]< dec num by ten =======RROT====== [>+<-] < [>+<-] < [>+<-] >>>[<<<+>>>-] < =======DIV10======== >+++++++++< [ >>>+<< bool= 1 [>+>[-]<<-] bool= ten==0 >[<+>-] ten = tmp >[<<++++++++++>>>+<-] if ten=0 ten=10 inc div <<- dec ten <- dec num ] >>>>[<<<<+>>>>-]<<<< copy div to num >[-]< clear ten =======INC1========= <+> ] < [ =======MOVER========= [>+<-] =======ADD48======== +++++++[<+++++++>-]<-> =======PUTC======= <.[-]> ======MOVEL2======== >[<<+>>-]< <- ] >++++[<++++++++>-]<.[-] =================================================================== =========================== END FOR =============================== =================================================================== >>>>>>> ] <<<<<<<< >[-]< [-] <<- ] ======LF======== ++++++++++.[-] bf-20041219ubuntu7/examples/quine1.b0000664000000000000000000000622412031263150013747 0ustar >>+>>+++++>>++>>+++>>+>>++++++>>++>>++>>++>>+++++>>+>>++++>> +>>+++>>+>>+>>++>>++>>+>>+>>+>>+++>>+>>++++++>>+++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++>>+>>++>>++ +++++>>+++++++++++++++++++>>++++>>+>>++>>+>>+++++>>+>>++++>> +>>+++>>+>>+++++++>>+>>++>>+>>++++++>>+>>+++>>+>>+++++>>+>>+ +++>>+>>++++++>>+>>+++>>+>>+++++>>+>>++++>>+>>++>>+>>+>>+>>+ ++>>+>>++++++>>+++>>++>>+>>++++++>>++>>+++>>+>>+++++>>+>>+++ +>>+>>+++>>+>>+>>+>>++>>+>>+++++>>+>>+++>>+>>++++>>+>>++++++ >>+>>++>>+>>+++++>>+>>++>>+>>++++++>>++>>+++>>+>>+++++>>+>>+ +>>+++++++++++++++++++++++++++++++++++++++++++++++++>>+>>+>> +++>>+>>++++>>+>>++++++>>+++>>+++>>+>>++++++>>++++>>++>>+>>+ ++++>>+>>++++>>+>>+++>>+>>+>>+>>++>>+>>+++++>>+>>+++>>+>>+++ +>>+>>++++++>>+>>++>>+>>+++++>>+>>++>>+>>++++++>>++>>+++>>+> >+++++>>+>>++>>+++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++>>+>>+>>+++>>+>>++++>>+>>++++++>>+++++ >>++>>+>>++++++>>++++>>+++>>+>>+++++>>+>>++++>>+>>+++>>+>>+> >+>>++>>+>>+++++>>+>>+++>>+>>++++>>+>>++++++>>+>>++>>+>>++++ +>>+>>++>>+>>++++++>>++>>+++>>+>>+++++>>+>>++>>+++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++>>+>>+>>+ ++>>+>>++++>>+>>++++++>>+++>>+++>>+>>++++++>>++++>>++>>+>>++ +++>>+>>++++>>+>>+++>>+>>+>>+>>++>>+>>+++++>>+>>+++>>+>>++++ >>+>>++++++>>+>>++>>+>>+++++>>+>>++>>+>>++++++>>++>>+++>>+>> +++++>>+>>++>>++++++++++++++++++++++++++++++++++++++++++++++ ++>>+>>+>>+++>>+>>++++>>+>>++++++>>+++++>>++>>+>>++++++>>+++ +>>+++>>+>>+++++>>+>>++++>>+>>+++>>+>>+>>+>>++>>+>>+++++>>+> >+++>>+>>++++>>+>>++++++>>+>>++>>+>>+++++>>+>>++>>+>>++++++> >++>>+++>>+>>+++++>>+>>++>>+++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >>+>>+>>+++>>+>>++++>>+>>++++++>>+++>>+++>>+>>++++++>>++++>> ++>>+>>+++++>>+>>++++>>+>>+++>>+>>+>>+>>++>>+>>+++++>>+>>+++ >>+>>++++>>+>>++++++>>+>>++>>+>>+++++>>+>>++>>+>>++++++>>++> >+++>>+>>+++++>>+>>++>>+++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>+ >>+>>+++>>+>>++++>>+>>++++++>>+++++>>++>>+>>++++++>>++++>>++ +>>+>>+++++>>+>>++++>>+>>+++>>+>>+>>+>>++>>+>>+++++>>+>>+++> >+>>++++>>+>>++++++>>+>>++>>+>>+++++>>+>>++>>+>>++++++>>++>> +++>>+>>+++++>>+>>++>>++++++++++++++++++++++++++++++++++++++ ++++++++>>+>>+>>+++>>+>>++++>>+>>++++++>>+++>>+++>>+>>++++++ >>++>>++>>++>>+++++>>+>>++++>>++>>++>>+>>+++++++>>++>>+++>>+ >>++++++>>++++>>++>>+>>++++++[<<]>>[[-<+>>+<]+++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++..----------- -------->[-<.>]<[-]<[->+<]>>>]<<[-<+>[<-]>[>]<<[>+++++++++++ ++++++++++++++++++++++++++++++++++++++<-]<<<]>>>>[-<+>[<-]>[ >]<<[>++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++<-]>>>>>]<<<<[-<+>[<-]>[>]<<[>+++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++<-]<<<]>>>>[- <+>[<-]>[>]<<[>+++++++++++++++++++++++++++++++++++++++++++++ +++<-]>>>>>]<<<<[-<+>[<-]>[>]<<[>+++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++<-]<<<]>>>>[-<+>[<-]>[>]<<[>++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++<-]>>>>>]<<<<[-<+>[<-]>[>]<<[>++++++++++++++++++++++ ++++++++++++++++++++++++<-]<<<]>>[[->>.<<]>>>>] bf-20041219ubuntu7/examples/quine2.b0000664000000000000000000000172312031263150013747 0ustar >>+++++++>>++>>++++>>+++++++>>+>>++++>>+>>+++>>+>>+++++>>+>>++>>+>>++++++>>++>>++++>>+++++++>>+>>+++++>>++>>+>>+>>++++>>+++++++>>+>>+++++>>+>>+>>+>>++++>>+++++++>>+>>+++++>>++++++++++++++>>+>>+>>++++>>+++++++>>+>>+++++>>++>>+>>+>>++++>>+++++++>>+>>+++++>>+++++++++++++++++++++++++++++>>+>>+>>++++>>+++++++>>+>>+++++>>++>>+>>+>>+++++>>+>>++++++>>+>>++>>+>>++++++>>+>>++>>+>>++++++>>+>>++>>+>>++++++>>+>>++>>+>>++++++>>+>>++>>+>>++++++>>+>>++>>+>>++++++>>++>>++++>>+++++++>>+>>+++++>>+++++++>>+>>+++++>>+>>+>>+>>++++>>+>>++>>+>>++++++>>+>>+++++>>+++++++>>+>>++++>>+>>+>>++>>+++++>>+>>+++>>+>>++++>>+>>++>>+>>++++++>>+>>+++++>>+++++++++++++++++++>>++>>++>>+++>>++>>+>>++>>++++>>+++++++>>++>>+++++>>++++++++++>>+>>++>>++++>>+>>++>>+>>++++++>>++++++>>+>>+>>+++++>>+>>++++++>>++>>+++++>>+++++++>>++>>++++>>+>>++++++[<<]>>[>++++++[-<<++++++++++>>]<<++..------------------->[-<.>>+<]>[-<+>]>]<<[-[-[-[-[-[-[>++>]<+++++++++++++++++++++++++++++>]<++>]<++++++++++++++>]<+>]<++>]<<[->.<]<<] bf-20041219ubuntu7/examples/quine3.b0000664000000000000000000000601112031263150013743 0ustar >+++++>+>+>+>+>+>+>++++++>++>+++++>+++++>+++++>+>+>+>+>+>+>+> ++++>++++>++++>+++++++>+++++>+++++>+++++>++++++>++>++++>+>++++> +>++++>+>+++++>+++++>+++++>+++++++>++++>++++>++++>+>+++++>+>+> +>+++++>+>+>+>+>+++++>+>+>+>+>+>+>+>+>+>+>++++++>++>+++++>+++++> +>+>+>+>+>+>++++>++++>+++++++>+++++>+++++>++++++>++>++++>+>++++> +>+++++>+++++>+++++++>++++>+>+>+++>+++++>+>+>+>+>+>+>+>+>+>++++++> ++>+++++>+++++>+>+>+>+>+>+>+>+>+>+>++++>++++>+++++++>+++++>+++++> ++++++>++>++++>+>++++>+>+++++>+++++>+++++++>++++>++++>+>+++++> +>+>+>++++++>++++>+++++++>++++>++++++>++++>+++++++>+++++>++++++> ++++++>+++++>+++++++>+++++>++++++>+++++>+++++++>+++++>+++++>++++++> +++++>+++++++>+>++++++>++++>+++++++>++++>++++>++++++>++++>+++++++> ++++>++++++>++++>+++++++>+++++>++++++>++++++>+++++>+++++++>+++++> +++>++++++>+++++>+++++++>+++++>+++++>++++++>+++++>+++++++>++++> +>++++++>++++>+++++++>++++>++++>++++++>++++>+++++++>++++>++++++> ++++>+++++++>+++++>++>+++++++>+++++>++++++>+++++>+++++++>+++++> +++++>+++++>+++++>+++++>+++>++++++>++++>+++++++>++++>++++++>++++> +++++++>+++++>+++++++>+++++>++++++>+++++>+++++++>+++++>+++++>++++++> ++>++>++++>+>+++++>++++++>++++>++>+++++++>++++>++++++>++++>+++++++> +++++>++++++>+++++>+>+>+>+>+>+>+>++++>++>++++>++++>++++++>++++> +++++++>+++++>+++>++++++>+++++>+++++++>+++++>+++++++>+++++>++>++++> +>+++++>++++++>++++>++>+++++++>++++>++++++>++++>+++++++>+++++>++++++> +++++>+>+>+>+>+>+>++++>++>++++>++++>++++++>++++>+++++++>+++++>+++++> +++>++++++>+++++>+++++++>+++++>+++++++>+++++>++>++++>+>+++++>++++++> ++++>++>+++++++>++++>++++++>++++>+++++++>+++++>++++++>+++++>+>+>+> +>+>++++>++>++++>++++>++++++>++++>+++++++>+++++>+++++>+++++>+++> ++++++>+++++>+++++++>+++++>+++++++>+++++>++>++++>+>+++++>++++++> ++++>++>+++++++>++++>++++++>++++>+++++++>+++++>++++++>+++++>+>+>+>+> ++++>++>++++>++++>++++++>++++>+++++++>+++++>+++++>+++++>+++++>+++> ++++++>+++++>+++++++>+++++>+++++++>+++++>++>++++>+>+++++>++++++>++++> ++>+++++++>++++>++++++>++++>+++++++>+++++>++++++>+++++>+>+>+>++++>++> ++++>++++>++++++>++++>+++++++>+++++>+++++>+++++>+++++>+++++>+++>++++++> +++++>+++++++>+++++>+++++++>+++++>++>++++>+>+++++>++++++>++++>++>+++++++> ++++>++++++>++++>+++++++>+++++>++++++>+++++>+>+>++++>++>++++>++++> ++++++>++++>+++++++>+++++>+++++>+++++>+++++>+++++>+++++>+++>++++++> +++++>+++++++>+++++>+++++++>+++++>++>++++>+>+++++>++++++>++++>++> +++++++>++++>++++++>++++>+++++++>+++++>++++++>+++++>+>++++>++>++++> ++++>++++++>++++>+++++++>+++++>+++++>+++++>+++++>+++++>+++++>+++++> +++>++++++>+++++>+++++++>+++++>+++++++>+++++>++++++>++>+++++++>++++> ++++>+>+++++>+++++>+++++>+++++++> >++++++[->>>+++++++<<<]>>>[-<+<+<+>>>]<<<+>+++>++++>++++++++++ [->>++++++<<]>>[-<+<+>>]<++.>+++++++++[->>++++++++++<<]>>[-<+<+>>] <<+>+++[<]<[<]>[[>]>[>]>>[>]+[<]<<[<]<[<]>[[>]>.[>]>>[>]<+[<]<<[<]< [<]>-]>[>]>>>>>.[<]<[<]>]>[>]>>[--<+>[<-]<[<]>[>+++++++<-<<[<]>.[>]> ]>-<+>[<-]<[<]>[>++++++<-<<[<]>>.[>]>]>-<+>[<-]<[<]>[>+++++<-<<[<]>>> .[>]>]>-<+>[<-]<[<]>[>++++<-<<[<]>>>>.[>]>]>-<+>[<-]<[<]>[>+++<-<<[<] >>>>>.[>]>]>-<+>[<-]<[<]>[>++<-<<[<]>>>>>>.[>]>]>-<+>[<-]<[<]>[>+<-<<[<]> >>>>>>.[>]>]>[-]<<+>>>] bf-20041219ubuntu7/examples/random.b0000664000000000000000000000064712031263150014030 0ustar >>>++[ <++++++++[ <[<++>-]>>[>>]+>>+[ -[->>+<<<[<[<<]<+>]>[>[>>]]] <[>>[-]]>[>[-<<]>[<+<]]+<< ]<[>+<-]>>- ]<.[-]>> ] "Random" byte generator using the Rule 30 automaton. Doesn't terminate; you will have to kill it. To get x bytes you need 32x+4 cells. Turn off any newline translation! Daniel B Cristofani (cristofdathevanetdotcom) http://www.hevanet.com/cristofd/brainfuck/ bf-20041219ubuntu7/tty.h0000664000000000000000000000016412031263150011552 0ustar /* tty.h */ #ifndef TTY_H #define TTY_H void ttyInit(void); char ttyGetInput(void); void ttyRestore(void); #endif bf-20041219ubuntu7/tty_slang.c0000664000000000000000000000477312031263150012743 0ustar /* tty_slang.c ****************************************************************************** This file is part of `bf', Yet another Brainfuck interpreter. Author: Stephan Beyer Description of this file: tty handling routines using S-Lang library Copyright (C) GPL, 2004 Stephan Beyer - s-beyer@gmx.net Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************** */ #include /* S-Lang library */ #include "tty.h" #include "bf.h" #include "errors.h" void ttyRestore(void) { SLang_reset_tty(); } /* implementations of the ',' operation */ char ttyGetInput(void) { char c; /* We init and restore the tty on each input (and not * once at start and end of program) to prevent bugs with * bf output... */ /* init slang terminal */ DoAndErr(SLang_init_tty(-1, 0, 1) == -1, SLang_init_tty, errSLANG); /* get any key */ if (opt.inputmode <= 2) /* 1 or 2 */ c = SLang_getkey(); else /* 3 or 4 */ { /* get key but no escape characters */ int tmp; do { tmp = SLkp_getkey(); } while(tmp > 255); c = (unsigned char)tmp; } if (c == '\r') /* slang returns \r, make \n */ c = '\n'; if (!(opt.inputmode % 2)) /* 2 and 4 */ { putchar(c); /* print them */ fflush(stdout); } /* and restore */ ttyRestore(); return c; } void ttyInit(void) { /* init slang kp if mode 3 or 4 */ if ((opt.inputmode == 3) || (opt.inputmode == 4)) { SLtt_get_terminfo(); DoAndErr(SLkp_init() == -1, SLkp_init, errSLANG); } } bf-20041219ubuntu7/tty_termios.c0000664000000000000000000000447512031263150013320 0ustar /* tty_termios.c ****************************************************************************** This file is part of `bf', Yet another Brainfuck interpreter. Author: Stephan Beyer Description of this file: tty handling routines using termios.h Copyright (C) GPL, 2004 Stephan Beyer - s-beyer@gmx.net Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************** */ #include /* getchar */ #include #include #include "tty.h" #include "bf.h" static struct termios *tty = NULL; /* save tty settings */ /* restore tty settings */ void ttyRestore(void) { if (tty) tcsetattr(STDIN_FILENO, TCSANOW, tty); } /* set handlers and init tty according to input mode */ void ttyInit(void) { static struct termios term; if (!tcgetattr(STDIN_FILENO, &term)) tty = &term; } /* ... */ void ttyFoo(void) { static struct termios term; term = *tty; /* copy saved tty */ term.c_lflag &= ~ICANON; /* disable eof */ term.c_lflag &= ~ICRNL; /* disable CR -> NL */ if (opt.inputmode == 1 || opt.inputmode == 3) term.c_lflag &= ~ECHO; /* disable output of input */ term.c_cc[VMIN] = 1; /* one character */ tcsetattr(STDIN_FILENO, TCSANOW, &term); } char ttyGetInput(void) { char c; if (tty) ttyFoo(); c = getchar(); ttyRestore(); return c; }