[PATCH 3/6] psql: Create table format

Roger Leigh <rleigh@debian.org>

From: Roger Leigh <rleigh@debian.org>
To: pgsql-hackers@postgresql.org
Cc: Roger Leigh <rleigh@debian.org>
Date: 2009-08-22T15:59:47Z
Lists: pgsql-hackers
Default to using the ASCII table.  However, if a UTF-8
locale codeset is in use, switch to the UTF-8 table.

Signed-off-by: Roger Leigh <rleigh@debian.org>
---
 src/bin/psql/print.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c
index 9dec77d..6f5dcd4 100644
--- a/src/bin/psql/print.c
+++ b/src/bin/psql/print.c
@@ -21,6 +21,9 @@
 #endif
 
 #include <locale.h>
+#ifdef HAVE_LANGINFO_H
+#include <langinfo.h>
+#endif
 
 #include "catalog/pg_type.h"
 #include "pqsignal.h"
@@ -2232,7 +2235,13 @@ IsPagerNeeded(const printTableContent *cont, const int extra_lines, FILE **fout,
 void
 printTable(const printTableContent *cont, FILE *fout, FILE *flog)
 {
-	bool		is_pager = false;
+	bool			is_pager = false;
+	const printTextFormat	*text_format = &asciiformat;
+
+#if (defined(HAVE_LANGINFO_H) && defined(CODESET))
+	if (!strcmp(nl_langinfo(CODESET), "UTF-8"))
+		text_format = &utf8format;
+#endif
 
 	if (cancel_pressed)
 		return;
-- 
1.6.3.3