summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8b458d6)
raw | patch | inline | side by side (parent: 8b458d6)
author | Erik Faye-Lund <kusmabite@gmail.com> | |
Tue, 28 Sep 2010 16:05:26 +0000 (18:05 +0200) | ||
committer | Ævar Arnfjörð Bjarmason <avarab@gmail.com> | |
Sat, 30 Oct 2010 07:10:06 +0000 (07:10 +0000) |
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.
The locale_charset function returns a `const char*', instead of
`char*` as nl_langinfo does. Change the declaration of the variable
we're using to store the `charset' in `git_setup_gettext' accordingly.
Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
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.
The locale_charset function returns a `const char*', instead of
`char*` as nl_langinfo does. Change the declaration of the variable
we're using to store the `charset' in `git_setup_gettext' accordingly.
Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Makefile | patch | blob | history | |
config.mak.in | patch | blob | history | |
configure.ac | patch | blob | history | |
gettext.c | patch | blob | history |
diff --git a/Makefile b/Makefile
index 0b265452781dec2d1b7dc7562b8c8446fa864dd3..2d6d8242d77dc9129151a7c470cf8fd0c73385b7 100644 (file)
--- a/Makefile
+++ b/Makefile
# 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 EXPATDIR=/foo/bar if your expat header and library files are in
# /foo/bar/include and /foo/bar/lib directories.
#
ifndef NO_GETTEXT
# Systems that use GNU gettext and glibc are the exception
NEEDS_LIBINTL = 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"
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
@@ -1949,6 +1962,10 @@ attr.s attr.o: EXTRA_CPPFLAGS = -DETC_GITATTRIBUTES='"$(ETC_GITATTRIBUTES_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 9f47aa5e1079b1e55b74f74cd77f0d4b6f796075..969cbaa0286f493cd4b283dcb17f2c4f3268ac58 100644 (file)
--- a/config.mak.in
+++ b/config.mak.in
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 28c2c37dc0b9d17aa7a6343db0d1d6205f77f65a..9074cc96ef50d9c88093b480ae8ffe72173119a1 100644 (file)
--- a/configure.ac
+++ b/configure.ac
[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 8644098b55b89ebbf4e7d19eebde6a879acffde3..9bdac56931741393b5c9443a4ec213daf2cd6d7a 100644 (file)
--- a/gettext.c
+++ b/gettext.c
#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);
(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");