aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2003-09-18 15:51:01 +0000
committerWerner Koch <[email protected]>2003-09-18 15:51:01 +0000
commit210b7257483b4cbed1eccce8afb50a142f085f52 (patch)
treec5be93cc4d7f041279c9d59305909f9ca6eb949d
parentPost release version number update (diff)
downloadgnupg-210b7257483b4cbed1eccce8afb50a142f085f52.tar.gz
gnupg-210b7257483b4cbed1eccce8afb50a142f085f52.zip
(tty_fprintf): New.
(tty_print_string, tty_print_utf8_string2) (tty_print_utf8_string): Made P argument const byte*.
-rw-r--r--common/ChangeLog6
-rw-r--r--common/ttyio.c53
-rw-r--r--common/ttyio.h12
3 files changed, 64 insertions, 7 deletions
diff --git a/common/ChangeLog b/common/ChangeLog
index ee363f83e..66e935b28 100644
--- a/common/ChangeLog
+++ b/common/ChangeLog
@@ -1,3 +1,9 @@
+2003-09-18 Werner Koch <[email protected]>
+
+ * ttyio.c (tty_fprintf): New.
+ (tty_print_string, tty_print_utf8_string2)
+ (tty_print_utf8_string): Made P argument const byte*.
+
2003-08-20 Marcus Brinkmann <[email protected]>
* maperror.c (map_ksba_err): Map -1. Use gpg_err_make to set
diff --git a/common/ttyio.c b/common/ttyio.c
index fd748009e..c77b4a85a 100644
--- a/common/ttyio.c
+++ b/common/ttyio.c
@@ -219,11 +219,58 @@ tty_printf( const char *fmt, ... )
}
+/* Same as tty_printf but if FP is not NULL, behave like a regualr
+ fprintf. */
+void
+tty_fprintf (FILE *fp, const char *fmt, ... )
+{
+ va_list arg_ptr;
+
+ if (fp)
+ {
+ va_start (arg_ptr, fmt) ;
+ vfprintf (fp, fmt, arg_ptr );
+ va_end (arg_ptr);
+ return;
+ }
+
+ if (no_terminal)
+ return;
+
+ if( !initialized )
+ init_ttyfp();
+
+ va_start( arg_ptr, fmt ) ;
+#ifdef __MINGW32__
+ {
+ char *buf = NULL;
+ int n;
+ DWORD nwritten;
+
+ n = vasprintf(&buf, fmt, arg_ptr);
+ if( !buf )
+ log_bug("vasprintf() failed\n");
+
+ if( !WriteConsoleA( con.out, buf, n, &nwritten, NULL ) )
+ log_fatal("WriteConsole failed: rc=%d", (int)GetLastError() );
+ if( n != nwritten )
+ log_fatal("WriteConsole failed: %d != %d\n", n, (int)nwritten );
+ last_prompt_len += n;
+ xfree (buf);
+ }
+#else
+ last_prompt_len += vfprintf(ttyfp,fmt,arg_ptr) ;
+ fflush(ttyfp);
+#endif
+ va_end(arg_ptr);
+}
+
+
/****************
* Print a string, but filter all control characters out.
*/
void
-tty_print_string( byte *p, size_t n )
+tty_print_string ( const byte *p, size_t n )
{
if (no_terminal)
return;
@@ -261,7 +308,7 @@ tty_print_string( byte *p, size_t n )
}
void
-tty_print_utf8_string2( byte *p, size_t n, size_t max_n )
+tty_print_utf8_string2( const byte *p, size_t n, size_t max_n )
{
size_t i;
char *buf;
@@ -292,7 +339,7 @@ tty_print_utf8_string2( byte *p, size_t n, size_t max_n )
}
void
-tty_print_utf8_string( byte *p, size_t n )
+tty_print_utf8_string( const byte *p, size_t n )
{
tty_print_utf8_string2( p, n, 0 );
}
diff --git a/common/ttyio.h b/common/ttyio.h
index b3ca7dcaf..6fa7400a9 100644
--- a/common/ttyio.h
+++ b/common/ttyio.h
@@ -23,13 +23,17 @@
const char *tty_get_ttyname (void);
int tty_batchmode (int onoff);
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )
-void tty_printf (const char *fmt, ... ) __attribute__ ((format (printf,1,2)));
+void tty_printf (const char *fmt, ... )
+ __attribute__ ((format (printf,1,2)));
+void tty_fprintf (FILE *fp, const char *fmt, ... )
+ __attribute__ ((format (printf,2,3)));
#else
void tty_printf (const char *fmt, ... );
+void tty_fprintf (FILE *fp, const char *fmt, ... );
#endif
-void tty_print_string (unsigned char *p, size_t n);
-void tty_print_utf8_string (unsigned char *p, size_t n);
-void tty_print_utf8_string2 (unsigned char *p, size_t n, size_t max_n);
+void tty_print_string (const unsigned char *p, size_t n);
+void tty_print_utf8_string (const unsigned char *p, size_t n);
+void tty_print_utf8_string2 (const unsigned char *p, size_t n, size_t max_n);
char *tty_get (const char *prompt);
char *tty_get_hidden (const char *prompt);
void tty_kill_prompt (void);