From d678ab80b2987ddd696519a27dad5571c379b511 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 15 Jul 2012 02:01:41 -0700 Subject: Print UTF8_STRING properties as text if locale uses UTF-8 charset Signed-off-by: Alan Coopersmith Reviewed-by: Mark Kettenis --- scope.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'scope.c') diff --git a/scope.c b/scope.c index c20deba..96f0464 100644 --- a/scope.c +++ b/scope.c @@ -68,6 +68,11 @@ #include /* struct servent * and struct hostent * */ #include /* for EINTR, EADDRINUSE, ... */ +#include +#ifdef HAVE_LANGINFO_H +#include +#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; @@ -665,6 +671,21 @@ Usage(void) exit(1); } +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) { @@ -795,6 +816,7 @@ ScanArgs(int argc, char **argv) int main(int argc, char **argv) { + InitializeLocale(); ScanArgs(argc, argv); InitializeFD(); InitializeX11(); -- cgit v1.2.1