diff options
author | Bruce Momjian <bruce@momjian.us> | 2003-07-27 03:32:26 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2003-07-27 03:32:26 +0000 |
commit | 9df48371c20869ac63a63b45550dbf4b045aa4bf (patch) | |
tree | d01352587f18c4d1ba7827295a5a9aa06ffe5feb /src/bin/psql/sprompt.c | |
parent | e7fe89d57ddda6ad35c68bfcf1d78c2fe0caac4e (diff) | |
download | postgresql-9df48371c20869ac63a63b45550dbf4b045aa4bf.tar.gz postgresql-9df48371c20869ac63a63b45550dbf4b045aa4bf.zip |
here are the patches for psql on Win32:
psql4win32.patch - changes in the psql source code
psql-ref.patch - changes in the documentation psql-ref.sgml
(for new builtin variable WIN32_CONSOLE)
To apply them use "patch -p 1" in the root directory of the
postgres source directory.
These patches fix the following problems of psql on Win32
(all changes only have effect #ifdef WIN32):
a) Problem: Static library libpq.a did not work
Solution: Added WSAStartup() in fe-connect.c
b) Problem: Secret Password was echoed by psql
Solution: Password echoing disabled in sprompt.c
c) Problem: 8bit characters were displayed/interpreted wrong in psql
This is due to the fact that the Win32 "console" uses a
different encoding than the rest of the Windows system
Solution: Introduced a new psql variable WIN32_CONSOLE
When set with "\set WIN32_console", the function OemToChar()
is applied after reading input and CharToOem() before
displaying Output
Christoph Dalitz
Diffstat (limited to 'src/bin/psql/sprompt.c')
-rw-r--r-- | src/bin/psql/sprompt.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/bin/psql/sprompt.c b/src/bin/psql/sprompt.c index 46ac2d97ba6..0a9eed182bf 100644 --- a/src/bin/psql/sprompt.c +++ b/src/bin/psql/sprompt.c @@ -3,7 +3,7 @@ * * Copyright 2000 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/Attic/sprompt.c,v 1.4 2003/03/18 22:09:37 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/Attic/sprompt.c,v 1.5 2003/07/27 03:32:26 momjian Exp $ */ @@ -26,6 +26,10 @@ #ifdef HAVE_TERMIOS_H #include <termios.h> +#else +#ifdef WIN32 +#include <windows.h> +#endif #endif bool prompt_state = false; @@ -42,6 +46,11 @@ simple_prompt(const char *prompt, int maxlen, bool echo) #ifdef HAVE_TERMIOS_H struct termios t_orig, t; +#else +#ifdef WIN32 + HANDLE t; + LPDWORD t_orig; +#endif #endif destination = (char *) malloc(maxlen + 1); @@ -74,6 +83,21 @@ simple_prompt(const char *prompt, int maxlen, bool echo) t.c_lflag &= ~ECHO; tcsetattr(fileno(termin), TCSAFLUSH, &t); } +#else +#ifdef WIN32 + if (!echo) + { + /* 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 if (prompt) @@ -111,6 +135,17 @@ simple_prompt(const char *prompt, int maxlen, bool echo) fputs("\n", termout); fflush(termout); } +#else +#ifdef WIN32 + if (!echo) + { + /* reset to the original console mode */ + SetConsoleMode(t, *t_orig); + fputs("\n", termout); + fflush(termout); + free(t_orig); + } +#endif #endif if (termin != stdin) |