standard input not a tty

Ross Paterson <[email protected]>
Newsgroups gmane.comp.lang.haskell.hugs.bugs
Message-ID <[email protected]>
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 ([email protected]) 
      * 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++;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.