standard input not a tty
Ross Paterson
ross@soi.city.ac.uk
Thu, 18 Jul 2002 17:23:09 +0100
When hugs's standard input is not a tty, this patch stops it prompting
or attempting to use readline. It also disables $$ in that situation;
this could be changed if desired, but is probably the right thing.
If it is put it in, the --with-readline option of configure can probably
be ditched (i.e. set USE_READLINE if editline or readline is available).
Index: src/input.c
===================================================================
RCS file: /home/cvs/root/hugs98/src/input.c,v
retrieving revision 1.43
diff -u -r1.43 input.c
--- src/input.c 2002/06/14 14:41:10 1.43
+++ src/input.c 2002/07/18 15:58:05
@@ -264,6 +264,7 @@
#define SCRIPTFILE 2 /* - script file */
#define PROJFILE 3 /* - project file */
#define STRING 4 /* - string buffer? */
+#define NOKEYBOARD 5 /* - standard input, but not a tty */
static Int reading = NOTHING;
@@ -322,6 +323,12 @@
hereState = START;
#endif
+#ifdef HAVE_ISATTY
+ if (!isatty(fileno(stdin))) { /* not reading from a tty: */
+ reading = NOKEYBOARD; /* don't prompt or try readline */
+ return;
+ }
+#endif
#if USE_READLINE
/* Paranoid freeing code supplied by Sverker Nilsson (sverker@opq.se)
* avoids accidentally freeing currentLine twice.
@@ -607,6 +614,9 @@
c1 = ' ';
}
}
+ }
+ else if (reading==NOKEYBOARD) {
+ c1 = c0=='\n' ? EOF : getc(stdin);
}
else if (reading==STRING) {
c1 = (unsigned char) *nextStringChar++;