diff -uNr a/tinyscheme/scheme.c b/tinyscheme/scheme.c --- a/tinyscheme/scheme.c 2016-01-26 22:39:28.654412439 -0500 18f898021406900232dbb00c9e04516c8a3baeb7281bd28b51eb1a2801fc9f311fe883681cf3efc0a8d7f9822c1ad3c508ca640ec3419d05592548767299e2af +++ b/tinyscheme/scheme.c 2016-01-26 22:48:53.663437711 -0500 95002ba17e220c4ffc0b69170b7639377e890c462681a0f83bb45b1616f30dc0af6927472145a5f95929d042bbe047974366139088bde45f86409223d8492b89 @@ -1,5 +1,6 @@ /* This version de-crudded for therealbitcoin.org. + Applied interactive REPL fixups for port redirect mode. */ /* T I N Y S C H E M E 1 . 4 1 @@ -18,7 +19,10 @@ #define _SCHEME_SOURCE #include "scheme-private.h" + #include +#include + #if USE_MATH # include #endif @@ -32,6 +36,8 @@ #define stricmp strcasecmp #endif +const char* tiny_scheme_version = PACKAGE_VERSION; + /* Used for documentation purposes, to signal functions in 'interface' */ #define INTERFACE @@ -1339,7 +1345,7 @@ } static int file_interactive(scheme *sc) { - return sc->file_i==0 && sc->load_stack[0].rep.stdio.file==stdin + return sc->file_i==0 && sc->load_stack[0].rep.stdio.interactive /* sc->load_stack[0].rep.stdio.file==stdin */ && sc->inport->_object._port->kind&port_file; } @@ -1360,6 +1366,7 @@ } pt=port_rep_from_file(sc,f,prop); pt->rep.stdio.closeit=1; + pt->rep.stdio.interactive=0; #if SHOW_ERROR_LINE if(fn) @@ -1390,6 +1397,7 @@ pt->kind = port_file | prop; pt->rep.stdio.file = f; pt->rep.stdio.closeit = 0; + pt->rep.stdio.interactive=sc->interactive_repl; return pt; } @@ -1545,6 +1553,8 @@ port *pt=sc->outport->_object._port; if(pt->kind&port_file) { fputs(s,pt->rep.stdio.file); + if( pt->rep.stdio.interactive ) + fflush( pt->rep.stdio.file ); } else { for(;*s;s++) { if(pt->rep.string.curr!=pt->rep.string.past_the_end) { @@ -4615,6 +4625,9 @@ int i, n=sizeof(dispatch_table)/sizeof(dispatch_table[0]); pointer x; + /* fix unitialized free under Mac OS X */ + memset( sc->load_stack, 0, sizeof(port) * MAXFIL ); + num_zero.is_fixnum=1; num_zero.value.ivalue=0; num_one.is_fixnum=1; @@ -4781,15 +4794,17 @@ { scheme_load_named_file(sc,fin,0); } void scheme_load_named_file(scheme *sc, FILE *fin, const char *filename) { + int interactive_repl = sc->interactive_repl && !filename; dump_stack_reset(sc); sc->envir = sc->global_env; sc->file_i=0; sc->load_stack[0].kind=port_input|port_file; sc->load_stack[0].rep.stdio.file=fin; + sc->load_stack[0].rep.stdio.interactive=interactive_repl; sc->loadport=mk_port(sc,sc->load_stack); sc->retcode=0; - if(fin==stdin) { - sc->interactive_repl=1; + if(interactive_repl) { + sc->interactive_repl=interactive_repl; } #if SHOW_ERROR_LINE diff -uNr a/tinyscheme/scheme-private.h b/tinyscheme/scheme-private.h --- a/tinyscheme/scheme-private.h 2016-01-26 22:36:42.054404987 -0500 cfd3ed45f7a9fd06fc15908f04d951f3c5e6d4bdf67f0d34a05dbb62dd4948952f771071f0baadb050c3094ad20ba58042c677585c5ee6988e6725e227934fe2 +++ b/tinyscheme/scheme-private.h 2016-01-26 22:46:42.394431839 -0500 c74450e18ab91f7c226108e76075162d2dd9b111b10d42af58fbfe5c2f18c71667e42cd865138daa7339bacf158411642d62e742b208aa5133316b879081bb90 @@ -26,6 +26,7 @@ union { struct { FILE *file; + int interactive; int closeit; #if SHOW_ERROR_LINE int curr_line;