aboutsummaryrefslogtreecommitdiffstats
path: root/util/ttyio.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/ttyio.c')
-rw-r--r--util/ttyio.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/util/ttyio.c b/util/ttyio.c
index b5d0a1302..0f0f144ef 100644
--- a/util/ttyio.c
+++ b/util/ttyio.c
@@ -57,6 +57,7 @@ static FILE *ttyfp = NULL;
static int initialized;
static int last_prompt_len;
+static int batchmode;
#ifdef HAVE_TCGETATTR
static struct termios termsave;
@@ -108,9 +109,11 @@ init_ttyfp(void)
#elif defined(__EMX__)
ttyfp = stdout; /* Fixme: replace by the real functions: see wklib */
#else
- ttyfp = fopen("/dev/tty", "r+");
- if( !ttyfp )
- log_fatal("cannot open /dev/tty: %s\n", strerror(errno) );
+ ttyfp = batchmode? stderr : fopen("/dev/tty", "r+");
+ if( !ttyfp ) {
+ log_error("cannot open /dev/tty: %s\n", strerror(errno) );
+ exit(2);
+ }
#endif
#ifdef HAVE_TCGETATTR
atexit( cleanup );
@@ -118,6 +121,14 @@ init_ttyfp(void)
initialized = 1;
}
+int
+tty_batchmode( int onoff )
+{
+ int old = batchmode;
+ if( onoff != -1 )
+ batchmode = onoff;
+ return old;
+}
void
tty_printf( const char *fmt, ... )
@@ -220,6 +231,11 @@ do_get( const char *prompt, int hidden )
byte cbuf[1];
int c, n, i;
+ if( batchmode ) {
+ log_error("Sorry, we are in batchmode - can't get input\n");
+ exit(2);
+ }
+
if( !initialized )
init_ttyfp();
@@ -336,6 +352,8 @@ tty_kill_prompt()
if( !initialized )
init_ttyfp();
+ if( batchmode )
+ last_prompt_len = 0;
if( !last_prompt_len )
return;
#if __MINGW32__