standard input not a tty

Sigbjorn Finne sof@galois.com
Thu, 18 Jul 2002 17:05:18 -0700


Thanks very much; patch applied.

--sigbjorn

----- Original Message -----
From: "Ross Paterson" <ross@soi.city.ac.uk>
To: <hugs-bugs@haskell.org>
Sent: Thursday, July 18, 2002 09:23
Subject: standard input not a tty


> 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++;