mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-03 22:56:33 +02:00
added more stuff
This commit is contained in:
parent
4d2636eafe
commit
b7bdef0834
23 changed files with 639 additions and 224 deletions
|
@ -450,6 +450,7 @@ iobuf_push_filter( IOBUF a,
|
|||
/* remove the filter stuff from the new stream */
|
||||
a->filter = NULL;
|
||||
a->filter_ov = NULL;
|
||||
a->filter_eof = 0;
|
||||
if( a->usage == 2 ) { /* allocate a fresh buffer for the original stream */
|
||||
b->d.buf = m_alloc( a->d.size );
|
||||
b->d.len = 0;
|
||||
|
@ -539,7 +540,7 @@ iobuf_pop_filter( IOBUF a, int (*f)(void *opaque, int control,
|
|||
m_free(b);
|
||||
}
|
||||
else if( !b->chain ) { /* remove the last iobuf from the chain */
|
||||
log_bug("Ohh jeee, trying to a head filter\n");
|
||||
log_bug("Ohh jeee, trying to remove a head filter\n");
|
||||
}
|
||||
else { /* remove an intermediate iobuf from the chain */
|
||||
log_bug("Ohh jeee, trying to remove an intermediate filter\n");
|
||||
|
@ -833,13 +834,13 @@ iobuf_set_block_mode( IOBUF a, size_t n )
|
|||
|
||||
|
||||
/****************
|
||||
* checks wether the stream is in block mode
|
||||
* Checks wether the stream is in block mode
|
||||
* Note: This does not work if other filters are pushed on the stream.
|
||||
*/
|
||||
int
|
||||
iobuf_in_block_mode( IOBUF a )
|
||||
{
|
||||
for(; a; a = a->chain )
|
||||
if( a->filter == block_filter )
|
||||
if( a && a->filter == block_filter )
|
||||
return 1; /* yes */
|
||||
return 0; /* no */
|
||||
}
|
||||
|
|
|
@ -26,10 +26,10 @@
|
|||
#include "util.h"
|
||||
|
||||
static char pidstring[15];
|
||||
|
||||
static int errorcount;
|
||||
|
||||
void
|
||||
set_log_pid( int pid )
|
||||
log_set_pid( int pid )
|
||||
{
|
||||
if( pid )
|
||||
sprintf(pidstring,"[%u]", (unsigned)pid );
|
||||
|
@ -37,6 +37,15 @@ set_log_pid( int pid )
|
|||
*pidstring = 0;
|
||||
}
|
||||
|
||||
int
|
||||
log_get_errorcount( int clear)
|
||||
{
|
||||
int n = errorcount;
|
||||
if( clear )
|
||||
errorcount = 0;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
/****************
|
||||
* General interface for printing a line
|
||||
|
@ -90,6 +99,7 @@ log_error( const char *fmt, ... )
|
|||
va_start( arg_ptr, fmt ) ;
|
||||
vfprintf(stderr,fmt,arg_ptr) ;
|
||||
va_end(arg_ptr);
|
||||
errorcount++;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
106
util/ttyio.c
106
util/ttyio.c
|
@ -30,41 +30,19 @@
|
|||
#include "memory.h"
|
||||
#include "ttyio.h"
|
||||
|
||||
static FILE *ttyfp = NULL;
|
||||
static int last_prompt_len;
|
||||
|
||||
static FILE *
|
||||
open_tty(struct termios *termsave )
|
||||
{
|
||||
struct termios term;
|
||||
|
||||
FILE *tty = fopen("/dev/tty", "r");
|
||||
if( !tty )
|
||||
log_fatal("cannot open /dev/tty: %s\n", strerror(errno) );
|
||||
|
||||
if( termsave ) { /* hide input */
|
||||
if( tcgetattr(fileno(tty), termsave) )
|
||||
log_fatal("tcgetattr() failed: %s\n", strerror(errno) );
|
||||
term = *termsave;
|
||||
term.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
|
||||
if( tcsetattr( fileno(tty), TCSAFLUSH, &term ) )
|
||||
log_fatal("tcsetattr() failed: %s\n", strerror(errno) );
|
||||
}
|
||||
|
||||
|
||||
return tty;
|
||||
}
|
||||
|
||||
static void
|
||||
close_tty( FILE *tty, struct termios *termsave )
|
||||
init_ttyfp()
|
||||
{
|
||||
if( termsave ) {
|
||||
if( tcsetattr(fileno(tty), TCSAFLUSH, termsave) )
|
||||
log_error("tcsetattr() failed: %s\n", strerror(errno) );
|
||||
putc('\n', stderr);
|
||||
}
|
||||
fclose(tty);
|
||||
}
|
||||
if( ttyfp )
|
||||
return;
|
||||
|
||||
ttyfp = fopen("/dev/tty", "r+");
|
||||
if( !ttyfp )
|
||||
log_fatal("cannot open /dev/tty: %s\n", strerror(errno) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
|
@ -72,10 +50,13 @@ tty_printf( const char *fmt, ... )
|
|||
{
|
||||
va_list arg_ptr;
|
||||
|
||||
if( !ttyfp )
|
||||
init_ttyfp();
|
||||
|
||||
va_start( arg_ptr, fmt ) ;
|
||||
last_prompt_len += vfprintf(stderr,fmt,arg_ptr) ;
|
||||
last_prompt_len += vfprintf(ttyfp,fmt,arg_ptr) ;
|
||||
va_end(arg_ptr);
|
||||
fflush(stderr);
|
||||
fflush(ttyfp);
|
||||
}
|
||||
|
||||
|
||||
|
@ -85,18 +66,21 @@ tty_printf( const char *fmt, ... )
|
|||
void
|
||||
tty_print_string( byte *p, size_t n )
|
||||
{
|
||||
if( !ttyfp )
|
||||
init_ttyfp();
|
||||
|
||||
for( ; n; n--, p++ )
|
||||
if( iscntrl( *p ) ) {
|
||||
putc('\\', stderr);
|
||||
putc('\\', ttyfp);
|
||||
if( *p == '\n' )
|
||||
putc('n', stderr);
|
||||
putc('n', ttyfp);
|
||||
else if( !*p )
|
||||
putc('0', stderr);
|
||||
putc('0', ttyfp);
|
||||
else
|
||||
fprintf(stderr, "x%02x", *p );
|
||||
fprintf(ttyfp, "x%02x", *p );
|
||||
}
|
||||
else
|
||||
putc(*p, stderr);
|
||||
putc(*p, ttyfp);
|
||||
}
|
||||
|
||||
|
||||
|
@ -107,17 +91,36 @@ static char *
|
|||
do_get( const char *prompt, int hidden )
|
||||
{
|
||||
char *buf;
|
||||
byte cbuf[1];
|
||||
int c, n, i;
|
||||
FILE *fp;
|
||||
struct termios termsave;
|
||||
|
||||
if( !ttyfp )
|
||||
init_ttyfp();
|
||||
|
||||
last_prompt_len = 0;
|
||||
tty_printf( prompt );
|
||||
buf = m_alloc(n=50);
|
||||
i = 0;
|
||||
fp = open_tty(hidden? &termsave: NULL);
|
||||
while( (c=getc(fp)) != EOF && c != '\n' ) {
|
||||
last_prompt_len++;
|
||||
|
||||
if( hidden ) {
|
||||
struct termios term;
|
||||
|
||||
if( tcgetattr(fileno(ttyfp), &termsave) )
|
||||
log_fatal("tcgetattr() failed: %s\n", strerror(errno) );
|
||||
term = termsave;
|
||||
term.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
|
||||
if( tcsetattr( fileno(ttyfp), TCSAFLUSH, &term ) )
|
||||
log_fatal("tcsetattr() failed: %s\n", strerror(errno) );
|
||||
}
|
||||
|
||||
/* fixme: How can we avoid that the \n is echoed w/o disabling
|
||||
* canonical mode - w/o this kill_prompt can't work */
|
||||
while( read(fileno(ttyfp), cbuf, 1) == 1 && *cbuf != '\n' ) {
|
||||
if( !hidden )
|
||||
last_prompt_len++;
|
||||
c = *cbuf;
|
||||
if( c == '\t' )
|
||||
c = ' ';
|
||||
else if( iscntrl(c) )
|
||||
|
@ -128,7 +131,11 @@ do_get( const char *prompt, int hidden )
|
|||
}
|
||||
buf[i++] = c;
|
||||
}
|
||||
close_tty(fp, hidden? &termsave: NULL);
|
||||
|
||||
if( hidden ) {
|
||||
if( tcsetattr(fileno(ttyfp), TCSAFLUSH, &termsave) )
|
||||
log_error("tcsetattr() failed: %s\n", strerror(errno) );
|
||||
}
|
||||
buf[i] = 0;
|
||||
return buf;
|
||||
}
|
||||
|
@ -151,15 +158,16 @@ void
|
|||
tty_kill_prompt()
|
||||
{
|
||||
int i;
|
||||
#if 0
|
||||
|
||||
if( !ttyfp )
|
||||
init_ttyfp();
|
||||
if( !last_prompt_len )
|
||||
return;
|
||||
fputc('\r', ttyfp);
|
||||
for(i=0; i < last_prompt_len; i ++ )
|
||||
fputc('\b', stderr);
|
||||
for(i=0; i < last_prompt_len; i ++ )
|
||||
fputc(' ', stderr);
|
||||
for(i=0; i < last_prompt_len; i ++ )
|
||||
fputc('\b', stderr);
|
||||
#endif
|
||||
fputc(' ', ttyfp);
|
||||
fputc('\r', ttyfp);
|
||||
last_prompt_len = 0;
|
||||
fflush(stderr);
|
||||
fflush(ttyfp);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue