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 | |
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')
-rw-r--r-- | src/bin/psql/describe.c | 29 | ||||
-rw-r--r-- | src/bin/psql/input.c | 15 | ||||
-rw-r--r-- | src/bin/psql/mbprint.c | 14 | ||||
-rw-r--r-- | src/bin/psql/sprompt.c | 37 | ||||
-rw-r--r-- | src/interfaces/libpq/fe-connect.c | 18 |
5 files changed, 108 insertions, 5 deletions
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index c44b527bb05..70264a4487c 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -3,7 +3,7 @@ * * Copyright 2000-2002 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.80 2003/07/25 21:42:26 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.81 2003/07/27 03:32:26 momjian Exp $ */ #include "postgres_fe.h" #include "describe.h" @@ -18,6 +18,16 @@ #include <ctype.h> +#ifdef WIN32 +/* + * mbvalidate() is used in function describeOneTableDetails() to make sure + * all characters of the cells will be printed to the DOS console in a + * correct way + */ +#include "mbprint.h" +#endif + + #define _(x) gettext((x)) static bool describeOneTableDetails(const char *schemaname, @@ -754,11 +764,20 @@ describeOneTableDetails(const char *schemaname, for (i = 0; i < numrows; i++) { /* Name */ +#ifdef WIN32 + cells[i * cols + 0] = mbvalidate(PQgetvalue(res, i, 0)); +#else cells[i * cols + 0] = PQgetvalue(res, i, 0); /* don't free this * afterwards */ +#endif + /* Type */ +#ifdef WIN32 + cells[i * cols + 1] = mbvalidate(PQgetvalue(res, i, 1)); +#else cells[i * cols + 1] = PQgetvalue(res, i, 1); /* don't free this * either */ +#endif /* Extra: not null and default */ if (show_modifiers) @@ -777,12 +796,20 @@ describeOneTableDetails(const char *schemaname, PQgetvalue(res, i, 2)); } +#ifdef WIN32 + cells[i * cols + 2] = xstrdup(mbvalidate(tmpbuf.data)); +#else cells[i * cols + 2] = xstrdup(tmpbuf.data); +#endif } /* Description */ if (verbose) +#ifdef WIN32 + cells[i * cols + cols - 1] = mbvalidate(PQgetvalue(res, i, 5)); +#else cells[i * cols + cols - 1] = PQgetvalue(res, i, 5); +#endif } /* Make title */ diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c index 26fe7659e2a..b220ed89418 100644 --- a/src/bin/psql/input.c +++ b/src/bin/psql/input.c @@ -3,13 +3,17 @@ * * Copyright 2000 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/input.c,v 1.25 2003/07/25 19:27:06 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/input.c,v 1.26 2003/07/27 03:32:26 momjian Exp $ */ #include "postgres_fe.h" #include "input.h" #include <errno.h> +#ifdef WIN32 +#include <windows.h> +#endif + #include "pqexpbuffer.h" #include "settings.h" #include "tab-complete.h" @@ -42,6 +46,15 @@ static void finishInput(int, void *); #define PSQLHISTORY ".psql_history" +#ifdef WIN32 + /* + * translate DOS console character set into ANSI, needed e.g. for + * German umlauts + */ + if (GetVariableBool(pset.vars, "WIN32_CONSOLE")) + OemToChar(s, s); +#endif + #ifdef USE_READLINE static enum histcontrol GetHistControlConfig(void) diff --git a/src/bin/psql/mbprint.c b/src/bin/psql/mbprint.c index 692f60bf775..437d7271c0d 100644 --- a/src/bin/psql/mbprint.c +++ b/src/bin/psql/mbprint.c @@ -3,7 +3,7 @@ * * Copyright 2000 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/mbprint.c,v 1.6 2003/03/18 22:15:44 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/mbprint.c,v 1.7 2003/07/27 03:32:26 momjian Exp $ */ #include "postgres_fe.h" @@ -11,6 +11,10 @@ #include "mb/pg_wchar.h" +#ifdef WIN32 +#include <windows.h> +#endif + /* * This is an implementation of wcwidth() and wcswidth() as defined in * "The Single UNIX Specification, Version 2, The Open Group, 1997" @@ -330,6 +334,14 @@ mbvalidate(unsigned char *pwcs, int encoding) return mb_utf_validate(pwcs); else { +#ifdef WIN32 + /* + * translate characters to DOS console encoding, e.g. needed + * for German umlauts + */ + if (GetVariableBool(pset.vars, "WIN32_CONSOLE")) + CharToOem(pwcs, pwcs); +#endif /* * other encodings needing validation should add their own * routines here 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) diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 6688e570381..af526a8f041 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.254 2003/07/26 13:50:02 momjian Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.255 2003/07/27 03:32:26 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -1970,9 +1970,25 @@ makeEmptyPGconn(void) { PGconn *conn = (PGconn *) malloc(sizeof(PGconn)); +/* needed to use the static libpq under windows as well */ +#ifdef WIN32 + WSADATA wsaData; +#endif + if (conn == NULL) return conn; +#ifdef WIN32 + if (WSAStartup(MAKEWORD(1, 1), &wsaData)) + { + free(conn); + return (PGconn*) NULL; + } + + WSASetLastError(0); + +#endif + /* Zero all pointers and booleans */ MemSet((char *) conn, 0, sizeof(PGconn)); |