[libgda] Improved gda-sql password prompt:
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Improved gda-sql password prompt:
- Date: Fri, 11 Jun 2010 19:38:59 +0000 (UTC)
commit 822606085051eff0ca2e4ef4ef2f7797331beb5e
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 0e32803..f9f446f 100644
--- a/configure.in
+++ b/configure.in
@@ -1659,6 +1659,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 5c4da5b..c836709 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>
@@ -1517,7 +1517,7 @@ read_hidden_passwd (void)
{
gchar *p, password [100];
-#ifndef G_OS_WIN32
+#ifdef HAVE_TERMIOS_H
int fail;
struct termios termio;
@@ -1529,13 +1529,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]