aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/src/sgml/ref/psql-ref.sgml15
-rw-r--r--src/bin/psql/describe.c29
-rw-r--r--src/bin/psql/input.c15
-rw-r--r--src/bin/psql/mbprint.c14
-rw-r--r--src/bin/psql/sprompt.c37
-rw-r--r--src/interfaces/libpq/fe-connect.c18
6 files changed, 122 insertions, 6 deletions
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index b0e13a85d20..9e9c60ecc47 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -1,5 +1,5 @@
<!--
-$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.91 2003/07/23 15:05:42 tgl Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.92 2003/07/27 03:32:26 momjian Exp $
PostgreSQL documentation
-->
@@ -2076,6 +2076,19 @@ bar
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><varname>WIN32_CONSOLE</varname></term>
+ <listitem>
+ <para>
+ This variable is only useful when working under the Win32 command
+ console. As the Win32 command console uses a different encoding than
+ the rest of the Windows system. Eight-bit characters (e.g. German Umlauts)
+ are corrupted. When this variable is set the command console encoding will
+ be translated into ASCII encoding for input and output.
+ </para>
+ </listitem>
+ </varlistentry>
+
</variablelist>
</refsect3>
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));