git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Erik Faye-Lund" <kusmabite@gmail.com>,
	"Junio C Hamano" <gitster@pobox.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH v3] gettext: use libcharset when available
Date: Wed, 29 Sep 2010 13:43:34 +0000	[thread overview]
Message-ID: <1285767814-25857-1-git-send-email-avarab@gmail.com> (raw)
In-Reply-To: <1285767632-24852-1-git-send-email-avarab@gmail.com>

From: Erik Faye-Lund <kusmabite@gmail.com>

Change the git_setup_gettext function to use libcharset to query the
character set of the current locale if it's available. I.e. use it
instead of nl_langinfo if HAVE_LIBCHARSET_H is set.

The GNU gettext manual recommends using langinfo.h's
nl_langinfo(CODESET) to acquire the current character set, but on
systems that have libcharset.h's locale_charset() using the latter is
either saner, or the only option on those systems.

GNU and Solaris have a nl_langinfo(CODESET), FreeBSD can use either,
but MinGW and some others need to use libcharset.h's locale_charset()
instead.

Since locale_charset returns a const char* instead of char* as
nl_langinfo does the type of the variable we're using to store the
charset in git_setup_gettext has been changed.

Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---

On Wed, Sep 29, 2010 at 13:40, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
> From: Erik Faye-Lund <kusmabite@gmail.com>
> On Wed, Sep 29, 2010 at 13:34, Erik Faye-Lund <kusmabite@gmail.com> wrote:
>> Very minor nit: It's officially spelled MinGW, with an upper-case G.
>
> Did s/MingW/MinGW/ in the content & message in this v2.

Discard that one, I accidentally changed some unrelated mention of
MingW to MinGW.

 Makefile      |   17 +++++++++++++++++
 config.mak.in |    1 +
 configure.ac  |    6 ++++++
 gettext.c     |   10 +++++++++-
 4 files changed, 33 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index 680e578..49a3386 100644
--- a/Makefile
+++ b/Makefile
@@ -43,6 +43,12 @@ all::
 # on platforms where we don't expect glibc (Linux, Hurd,
 # GNU/kFreeBSD), which includes libintl.
 #
+# Define HAVE_LIBCHARSET_H if you haven't set NO_GETTEXT and you can't
+# trust the langinfo.h's nl_langinfo(CODESET) function to return the
+# current character set. GNU and Solaris have a nl_langinfo(CODESET),
+# FreeBSD can use either, but MinGW and some others need to use
+# libcharset.h's locale_charset() instead.
+#
 # Define GNU_GETTEXT if you're using the GNU implementation of
 # libintl. We define this everywhere except on Solaris, which has its
 # own gettext implementation. If GNU_GETTEXT is set we'll use GNU
@@ -792,6 +798,10 @@ ifndef NO_GETTEXT
 	# Systems that don't use GNU gettext are the exception. Only
 	# Solaris has a mature non-GNU gettext implementation.
 	GNU_GETTEXT = YesPlease
+
+	# Since we assume a GNU gettext by default we also assume a
+	# GNU-like langinfo.h by default
+	HAVE_LIBCHARSET_H =
 endif
 
 # We choose to avoid "if .. else if .. else .. endif endif"
@@ -1180,6 +1190,9 @@ ifneq (,$(wildcard ../THIS_IS_MSYSGIT))
 	EXTLIBS += /mingw/lib/libz.a
 	NO_R_TO_GCC_LINKER = YesPlease
 	INTERNAL_QSORT = YesPlease
+ifndef NO_GETTEXT
+	HAVE_LIBCHARSET_H = YesPlease
+endif
 else
 	NO_CURL = YesPlease
 endif
@@ -1964,6 +1977,10 @@ config.s config.o: EXTRA_CPPFLAGS = -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"'
 
 http.s http.o: EXTRA_CPPFLAGS = -DGIT_HTTP_USER_AGENT='"git/$(GIT_VERSION)"'
 
+ifdef HAVE_LIBCHARSET_H
+gettext.s gettext.o: EXTRA_CPPFLAGS = -DHAVE_LIBCHARSET_H
+endif
+
 ifdef NO_EXPAT
 http-walker.s http-walker.o: EXTRA_CPPFLAGS = -DNO_EXPAT
 endif
diff --git a/config.mak.in b/config.mak.in
index 9f47aa5..969cbaa 100644
--- a/config.mak.in
+++ b/config.mak.in
@@ -34,6 +34,7 @@ NO_CURL=@NO_CURL@
 NO_EXPAT=@NO_EXPAT@
 NO_LIBGEN_H=@NO_LIBGEN_H@
 HAVE_PATHS_H=@HAVE_PATHS_H@
+HAVE_LIBCHARSET_H=@HAVE_LIBCHARSET_H@
 NO_GETTEXT=@NO_GETTEXT@
 NEEDS_LIBICONV=@NEEDS_LIBICONV@
 NEEDS_SOCKET=@NEEDS_SOCKET@
diff --git a/configure.ac b/configure.ac
index 1821d89..b06bad1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -810,6 +810,12 @@ AC_CHECK_HEADER([libintl.h],
 [NO_GETTEXT=YesPlease])
 AC_SUBST(NO_GETTEXT)
 #
+# Define HAVE_LIBCHARSET_H if have libcharset.h
+AC_CHECK_HEADER([libcharset.h],
+[HAVE_LIBCHARSET_H=YesPlease],
+[HAVE_LIBCHARSET_H=])
+AC_SUBST(HAVE_LIBCHARSET_H)
+#
 # Define NO_STRCASESTR if you don't have strcasestr.
 GIT_CHECK_FUNC(strcasestr,
 [NO_STRCASESTR=],
diff --git a/gettext.c b/gettext.c
index 8644098..9bdac56 100644
--- a/gettext.c
+++ b/gettext.c
@@ -1,13 +1,17 @@
 #include "exec_cmd.h"
 #include <locale.h>
 #include <libintl.h>
+#ifdef HAVE_LIBCHARSET_H
+#include <libcharset.h>
+#else
 #include <langinfo.h>
+#endif
 #include <stdlib.h>
 
 extern void git_setup_gettext(void) {
 	char *podir;
 	char *envdir = getenv("GIT_TEXTDOMAINDIR");
-	char *charset;
+	const char *charset;
 
 	if (envdir) {
 		(void)bindtextdomain("git", envdir);
@@ -20,7 +24,11 @@ extern void git_setup_gettext(void) {
 
 	(void)setlocale(LC_MESSAGES, "");
 	(void)setlocale(LC_CTYPE, "");
+#ifdef HAVE_LIBCHARSET_H
+	charset = locale_charset();
+#else
 	charset = nl_langinfo(CODESET);
+#endif
 	(void)bind_textdomain_codeset("git", charset);
 	(void)setlocale(LC_CTYPE, "C");
 	(void)textdomain("git");
-- 
1.7.3.159.g610493

  reply	other threads:[~2010-09-29 13:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-28 16:05 [PATCH] gettext: use libcharset when available Erik Faye-Lund
2010-09-28 17:07 ` Ævar Arnfjörð Bjarmason
2010-09-28 17:42   ` Erik Faye-Lund
2010-09-28 18:29     ` [PATCH/RFC 0/2] use libcharset.h with gettext if available Ævar Arnfjörð Bjarmason
2010-09-28 21:47       ` Erik Faye-Lund
2010-09-29 10:00         ` Ævar Arnfjörð Bjarmason
2010-09-29 11:41           ` Erik Faye-Lund
2010-09-29 13:07             ` [PATCH] gettext: use libcharset when available Ævar Arnfjörð Bjarmason
2010-09-29 13:34               ` Erik Faye-Lund
2010-09-29 13:40                 ` [PATCH v2] " Ævar Arnfjörð Bjarmason
2010-09-29 13:43                   ` Ævar Arnfjörð Bjarmason [this message]
2010-09-28 18:29     ` [PATCH/RFC 1/2] gettext: use const char* instead of char* Ævar Arnfjörð Bjarmason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1285767814-25857-1-git-send-email-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=kusmabite@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).