[libgda/LIBGDA_4.0] Improved gda-sql password prompt:
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda/LIBGDA_4.0] Improved gda-sql password prompt:
- Date: Fri, 11 Jun 2010 20:51:40 +0000 (UTC)
commit 01d4b8d8e760bfae748c0af312e68d13af28566d
Author: Vivien Malerba <malerba gnome-db org>
Date: Fri Jun 11 19:10:45 2010 +0200
Improved gda-sql password prompt:
* detect termios.h presence
* implemented for WIN32
configure.in | 4 ++++
tools/gda-sql.c | 27 ++++++++++++++++++++++++---
2 files changed, 28 insertions(+), 3 deletions(-)
---
diff --git a/configure.in b/configure.in
index 784a1ed..e44eb78 100644
--- a/configure.in
+++ b/configure.in
@@ -1402,6 +1402,10 @@ AC_SUBST(LIB_PREFIX)
AC_SUBST(LIB_SONAME)
AC_SUBST(LIB_SUFFIX)
+dnl
+dnl TERMIOS.H
+dnl
+AC_CHECK_HEADERS([termios.h])
dnl
dnl where to install DTD files
diff --git a/tools/gda-sql.c b/tools/gda-sql.c
index 1870dc5..6cef89b 100644
--- a/tools/gda-sql.c
+++ b/tools/gda-sql.c
@@ -31,7 +31,7 @@
#include "tools-input.h"
#include "command-exec.h"
#include <unistd.h>
-#ifndef G_OS_WIN32
+#ifdef HAVE_TERMIOS_H
#include <termios.h>
#endif
#include <sys/types.h>
@@ -1507,7 +1507,7 @@ read_hidden_passwd (void)
{
gchar *p, password [100];
-#ifndef G_OS_WIN32
+#ifdef HAVE_TERMIOS_H
int fail;
struct termios termio;
@@ -1519,13 +1519,34 @@ read_hidden_passwd (void)
fail = tcsetattr (0, TCSANOW, &termio);
if (fail)
return NULL;
+#else
+ #ifdef G_OS_WIN32
+ HANDLE t = NULL;
+ LPDWORD t_orig = NULL;
+
+ /* get a new handle to turn echo off */
+ t_orig = (LPDWORD) malloc (sizeof (DWORD));
+ t = GetStdHandle (STD_INPUT_HANDLE);
+
+ /* save the old configuration first */
+ GetConsoleMode (t, t_orig);
+
+ /* set to the new mode */
+ SetConsoleMode (t, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT);
+ #endif
#endif
p = fgets (password, sizeof (password) - 1, stdin);
-#ifndef G_OS_WIN32
+#ifdef HAVE_TERMIOS_H
termio.c_lflag |= ECHO;
tcsetattr (0, TCSANOW, &termio);
+#else
+ #ifdef G_OS_WIN32
+ SetConsoleMode (t, *t_orig);
+ fflush (stdout);
+ free (t_orig);
+ #endif
#endif
if (!p)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]