summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/interact.cc
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/utils/asymptote/interact.cc')
-rw-r--r--Build/source/utils/asymptote/interact.cc30
1 files changed, 25 insertions, 5 deletions
diff --git a/Build/source/utils/asymptote/interact.cc b/Build/source/utils/asymptote/interact.cc
index dd0bfd68a20..7f30b7034bc 100644
--- a/Build/source/utils/asymptote/interact.cc
+++ b/Build/source/utils/asymptote/interact.cc
@@ -72,7 +72,7 @@ void init_completion() {
char *(*Readline)(const char *prompt);
-char *verbatimreadline(const char *prompt)
+char *readverbatimline(const char *prompt)
{
if(!cin.good()) {cin.clear(); return NULL;}
cout << prompt;
@@ -81,14 +81,34 @@ char *verbatimreadline(const char *prompt)
return StrdupMalloc(s);
}
+FILE *fin=NULL;
+
+char *readpipeline(const char *prompt)
+{
+ const int max_size=256;
+ static char buf[max_size];
+ ostringstream s;
+ do {
+ if(fgets(buf,max_size-1,fin) == NULL) break;
+ s << buf;
+ } while(buf[strlen(buf)-1] != '\n');
+ return StrdupMalloc(s.str());
+}
+
void pre_readline()
{
+ int fd=intcast(settings::getSetting<Int>("inpipe"));
+ if(fd >= 0) {
+ if(!fin) fin=fdopen(fd,"r");
+ Readline=readpipeline;
+ } else {
#if defined(HAVE_LIBREADLINE) && defined(HAVE_LIBCURSES)
- if(tty) {
- Readline=readline;
- } else
+ if(tty) {
+ Readline=readline;
+ } else
#endif
- Readline=verbatimreadline;
+ Readline=readverbatimline;
+ }
}
void init_interactive()