[pure-lang-svn] SF.net SVN: pure-lang: [268] pure/trunk
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-06-20 01:54:46
|
Revision: 268 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=268&view=rev Author: agraef Date: 2008-06-19 18:54:54 -0700 (Thu, 19 Jun 2008) Log Message: ----------- Fake interactive mode when we're not connected to a terminal but -i is specified. Modified Paths: -------------- pure/trunk/lexer.ll pure/trunk/pure.cc Modified: pure/trunk/lexer.ll =================================================================== --- pure/trunk/lexer.ll 2008-06-19 00:15:28 UTC (rev 267) +++ pure/trunk/lexer.ll 2008-06-20 01:54:54 UTC (rev 268) @@ -824,18 +824,41 @@ static char *my_buf = NULL, *my_bufptr = NULL; static int len = 0; +bool using_readline = false; + void my_readline(const char *prompt, char *buf, int &result, int max_size) { if (!my_buf) { - // read a new line using readline() - my_bufptr = my_buf = readline(prompt); - if (!my_buf) { - // EOF, bail out - result = 0; - return; + if (using_readline) { + // read a new line using readline() + my_bufptr = my_buf = readline(prompt); + if (!my_buf) { + // EOF, bail out + result = 0; + return; + } + add_history(my_buf); + } else { + // read a new line from stdin + char s[10000]; + fputs(prompt, stdout); fflush(stdout); + if (!fgets(s, 10000, stdin)) { + // EOF, bail out + result = 0; + return; + } + // get rid of the trailing newline + size_t l = strlen(s); + if (l>0 && s[l-1] == '\n') + s[l-1] = 0; + my_bufptr = my_buf = strdup(s); + if (!my_buf) { + // memory allocation error, bail out + result = 0; + return; + } } len = strlen(my_buf); - add_history(my_buf); } // how many chars we got int l = len-(my_bufptr-my_buf); Modified: pure/trunk/pure.cc =================================================================== --- pure/trunk/pure.cc 2008-06-19 00:15:28 UTC (rev 267) +++ pure/trunk/pure.cc 2008-06-20 01:54:54 UTC (rev 268) @@ -273,22 +273,28 @@ interp.symtab.init_builtins(); // enter the interactive command loop interp.interactive = true; - if (isatty(fileno(stdin))) { - // connected to a terminal, print sign-on and initialize readline + if (isatty(fileno(stdin)) || force_interactive) { + // We're connected to a terminal (or pretend that we are), print the + // sign-on message. if (!quiet) { cout << "Pure " << PACKAGE_VERSION << " (" << HOST << ") " << COPYRIGHT << endl << LICENSE; if (have_prelude) cout << "Loaded prelude from " << prelude << ".\n\n"; } + interp.compile(); + interp.ttymode = true; + } + if (isatty(fileno(stdin))) { + // initialize readline + extern bool using_readline; + using_readline = true; rl_readline_name = "Pure"; rl_attempted_completion_function = pure_completion; using_history(); read_history(interp.histfile.c_str()); stifle_history(600); histfile = strdup(interp.histfile.c_str()); - interp.compile(); - interp.ttymode = true; } interp.temp = 1; interp.run(""); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |