diff options
author | Werner Koch <[email protected]> | 1999-04-18 08:18:52 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 1999-04-18 08:18:52 +0000 |
commit | 1feae2011ccd122ffb9a8f28013a13e57fc0b4fd (patch) | |
tree | 981a2000ffe3b4349bf3f2b8dbe845a60c15c95a /util/ttyio.c | |
parent | See ChangeLog: Fri Apr 9 12:26:25 CEST 1999 Werner Koch (diff) | |
download | gnupg-1feae2011ccd122ffb9a8f28013a13e57fc0b4fd.tar.gz gnupg-1feae2011ccd122ffb9a8f28013a13e57fc0b4fd.zip |
See ChangeLog: Sun Apr 18 10:11:28 CEST 1999 Werner Koch
Diffstat (limited to 'util/ttyio.c')
-rw-r--r-- | util/ttyio.c | 24 |
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__ |