summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2012-07-15 02:01:41 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2012-09-06 23:22:21 -0700
commit72499abeb74bf924fe2eb68946c8fbee814ca356 (patch)
tree14c505e0a1a7d01be8b6015c84c55b83b04c1d70
parente2ea9f4c3647e9f77027fb59a9ada7c964c1f62d (diff)
Print UTF8_STRING properties as text if locale uses UTF-8 charset
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com> Reviewed-by: Mark Kettenis <kettenis@openbsd.org>
-rw-r--r--configure.ac2
-rw-r--r--prtype.c19
-rw-r--r--scope.c24
-rw-r--r--scope.h3
4 files changed, 42 insertions, 6 deletions
diff --git a/configure.ac b/configure.ac
index 74d0d53..dee7b66 100644
--- a/configure.ac
+++ b/configure.ac
@@ -70,7 +70,7 @@ fi
PKG_CHECK_MODULES(XSCOPE, [xproto >= 7.0.17 $XTRANS_PKG])
AC_CHECK_FUNCS([getdtablesize])
-AC_CHECK_HEADERS([sys/filio.h])
+AC_CHECK_HEADERS([sys/filio.h langinfo.h])
dnl Allow checking code with lint, sparse, etc.
XORG_WITH_LINT
diff --git a/prtype.c b/prtype.c
index e5d26a7..04f36cf 100644
--- a/prtype.c
+++ b/prtype.c
@@ -1038,9 +1038,22 @@ PrintPropertyValues(const unsigned char *buf, uint32_t type /* atom */,
uint8_t unit, uint32_t num, const char *name)
{
if (type == 31 /* string */)
- PrintString8(buf, num * unit, name);
- else
- PrintBytes(buf, num * unit, name);
+ return PrintString8(buf, num * unit, name);
+ else {
+ const char *typename = FindAtomName(type);
+
+ if (typename) {
+ if (strcmp(typename, "UTF8_STRING") == 0) {
+ if (IsUTF8locale)
+ return PrintString8(buf, num * unit, name);
+ else
+ return PrintBytes(buf, num * unit, name);
+ }
+ }
+ }
+
+ /* When all else fails, print raw bytes */
+ return PrintBytes(buf, num * unit, name);
}
/* ************************************************************ */
diff --git a/scope.c b/scope.c
index d97b316..f3574cc 100644
--- a/scope.c
+++ b/scope.c
@@ -68,6 +68,11 @@
#include <netdb.h> /* struct servent * and struct hostent * */
#include <errno.h> /* for EINTR, EADDRINUSE, ... */
+#include <locale.h>
+#ifdef HAVE_LANGINFO_H
+#include <langinfo.h>
+#endif
+
/* ********************************************** */
/* */
@@ -86,7 +91,8 @@ static FD ConnectToClient(FD ConnectionSocket);
static void DataFromClient(FD fd);
static void SetUpStdin(void);
-long TranslateText = 0;
+char TranslateText = 0;
+char IsUTF8locale = 0;
char ScopeEnabled = 1;
char HandleSIGUSR1 = 0;
char DoAudio = 0;
@@ -661,6 +667,21 @@ Usage(void)
}
static void
+InitializeLocale(void)
+{
+ setlocale(LC_CTYPE, "");
+
+#ifdef HAVE_LANGINFO_H
+ {
+ const char *charmap = nl_langinfo (CODESET);
+
+ if (charmap != NULL && strcmp(charmap, "UTF-8") == 0)
+ IsUTF8locale = 1;
+ }
+#endif
+}
+
+static void
ScanArgs(int argc, char **argv)
{
XVerbose = 1; /* default verbose-ness level */
@@ -790,6 +811,7 @@ ScanArgs(int argc, char **argv)
int
main(int argc, char **argv)
{
+ InitializeLocale();
ScanArgs(argc, argv);
InitializeFD();
InitializeX11();
diff --git a/scope.h b/scope.h
index 2fb627d..8dc6b31 100644
--- a/scope.h
+++ b/scope.h
@@ -121,7 +121,8 @@ extern char HandleSIGUSR1;
extern char Leader[];
extern long ServerBasePort;
extern char ScopeEnabled;
-extern long TranslateText;
+extern char TranslateText;
+extern char IsUTF8locale;
#include "proto.h"