don't turn on editing if stdout is not a tty.

This commit is contained in:
christos 2011-01-27 23:11:40 +00:00
parent e5a2e2b285
commit b2ce31d086
3 changed files with 20 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: el.c,v 1.60 2010/08/28 15:44:59 christos Exp $ */
/* $NetBSD: el.c,v 1.61 2011/01/27 23:11:40 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94";
#else
__RCSID("$NetBSD: el.c,v 1.60 2010/08/28 15:44:59 christos Exp $");
__RCSID("$NetBSD: el.c,v 1.61 2011/01/27 23:11:40 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@ -72,6 +72,8 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
el->el_errfile = ferr;
el->el_infd = fileno(fin);
el->el_outfd = fileno(fout);
el->el_errfd = fileno(ferr);
el->el_prog = Strdup(ct_decode_string(prog, &el->el_scratch));
if (el->el_prog == NULL) {
@ -333,9 +335,11 @@ FUN(el,set)(EditLine *el, int op, ...)
break;
case 1:
el->el_outfile = fp;
el->el_outfd = fileno(fp);
break;
case 2:
el->el_errfile = fp;
el->el_errfd = fileno(fp);
break;
default:
rv = -1;

View File

@ -1,4 +1,4 @@
/* $NetBSD: el.h,v 1.21 2009/12/31 15:58:26 christos Exp $ */
/* $NetBSD: el.h,v 1.22 2011/01/27 23:11:40 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -119,6 +119,8 @@ struct editline {
FILE *el_outfile; /* Stdio stuff */
FILE *el_errfile; /* Stdio stuff */
int el_infd; /* Input file descriptor */
int el_outfd; /* Output file descriptor */
int el_errfd; /* Error file descriptor */
int el_flags; /* Various flags. */
int el_errno; /* Local copy of errno */
coord_t el_cursor; /* Cursor location */

View File

@ -1,4 +1,4 @@
/* $NetBSD: tty.c,v 1.33 2010/04/18 21:17:22 christos Exp $ */
/* $NetBSD: tty.c,v 1.34 2011/01/27 23:11:40 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: tty.c,v 1.33 2010/04/18 21:17:22 christos Exp $");
__RCSID("$NetBSD: tty.c,v 1.34 2011/01/27 23:11:40 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@ -46,6 +46,7 @@ __RCSID("$NetBSD: tty.c,v 1.33 2010/04/18 21:17:22 christos Exp $");
*/
#include <assert.h>
#include <errno.h>
#include <unistd.h> /* for isatty */
#include <strings.h> /* for ffs */
#include "el.h"
#include "tty.h"
@ -496,6 +497,14 @@ tty_setup(EditLine *el)
if (el->el_flags & EDIT_DISABLED)
return (0);
if (!isatty(el->el_outfd)) {
#ifdef DEBUG_TTY
(void) fprintf(el->el_errfile,
"tty_setup: isatty: %s\n", strerror(errno));
#endif /* DEBUG_TTY */
return (-1);
}
&el->el_tty.t_ed) == -1) {
if (tty_getty(el, &el->el_tty.t_ed) == -1) {
#ifdef DEBUG_TTY
(void) fprintf(el->el_errfile,