gettext: use libcharset when available
PATCH 1/1 gettext: use libcharset when available
libcharset provides an even more portable way of quering the charset of the current locale.
Use that instead of nl_langinfo unless NO_LIBCHARSET is set.
---
Windows doesn't have langinfo.h and nl_langinfo(), but libcharset was invented for this very purpose. With this patch on top, ab/i18n compiles without errors in msysGit.
There's still a bunch of lower-level issues on Windows, like gettext ending up overloading our winansi-wrappings for printf and friends, but let's take thinks one step at the time :)
configure.ac | 6 ++++++ gettext.c | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletions(-)
configure.ac +6 -0
@@ -810,6 +810,12 @@ AC_CHECK_HEADER([libintl.h], [NO_GETTEXT=YesPlease]) AC_SUBST(NO_GETTEXT) # +# Define NO_LIBCHARSET if you don't have libcharset.h +AC_CHECK_HEADER([libcharset.h], +[NO_LIBCHARSET=], +[NO_LIBCHARSET=YesPlease]) +AC_SUBST(NO_LIBCHARSET) +# # Define NO_STRCASESTR if you don't have strcasestr. GIT_CHECK_FUNC(strcasestr, [NO_STRCASESTR=],
gettext.c +9 -1
@@ -1,13 +1,17 @@#include "exec_cmd.h" #include <locale.h> #include <libintl.h> +#ifndef NO_LIBCHARSET +#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 ,"" ); +#ifndef NO_LIBCHARSET + charset =locale_charset (); +#else charset =nl_langinfo (CODESET ); +#endif (void )bind_textdomain_codeset ("git" , charset); (void )setlocale (LC_CTYPE ,"C" ); (void )textdomain ("git" );
Signature · 1 line
1.7.3.165.gdfe39.dirty
Quoted 62 lines · Erik Faye-Lund
libcharset provides an even more portable way of quering the charset of the current locale.
Use that instead of
nl_langinfounlessNO_LIBCHARSETis set.Signed-off-by Erik Faye-Lund <[email protected]>---
Windows doesn't have
langinfo.handnl_langinfo(), but libcharset was invented for this very purpose. With this patch on top, ab/i18n compiles without errors in msysGit.There's still a bunch of lower-level issues on Windows, like gettext ending up overloading our winansi-wrappings for printf and friends, but let's take thinks one step at the time :)
configure.ac | 6 ++++++
gettext.c | 10 +++++++++-2 files changed, 15 insertions(+), 1 deletions(-)configure.ac +6
-0@@ -810,6 +810,12 @@ AC_CHECK_HEADER([libintl.h], [NO_GETTEXT=YesPlease]) AC_SUBST(NO_GETTEXT) # +# Define NO_LIBCHARSET if you don't have libcharset.h +AC_CHECK_HEADER([libcharset.h], +[NO_LIBCHARSET=], +[NO_LIBCHARSET=YesPlease]) +AC_SUBST(NO_LIBCHARSET) +# # Define NO_STRCASESTR if you don't have strcasestr. GIT_CHECK_FUNC(strcasestr, [NO_STRCASESTR=],gettext.c +5
-1@@ -1,13 +1,17 @@ #include "exec_cmd.h" #include <locale.h> #include <libintl.h> +#ifndef NO_LIBCHARSET +#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) {
gettext.c extern void git_setup_gettext(void) { · line 34
Quoted 10 lines
gettext.c +4
-0(void)setlocale(LC_MESSAGES, ""); (void)setlocale(LC_CTYPE, ""); +#ifndef NO_LIBCHARSET + charset = locale_charset(); +#else charset = nl_langinfo(CODESET); +#endif (void)bind_textdomain_codeset("git", charset); (void)setlocale(LC_CTYPE, "C"); (void)textdomain("git");
Thanks for porting it to Windows. Some points:
* Nit: Should be NEEDS_LIBCHARSET instead of NO_LIBCHARSET, all the variables that set library inclusions in the Makefile use the NEED_* names.
* GHC had a patch like this, it seems it affects NetBSD and OpenBSD too, can anyone with these systems confirm:
http://hackage.haskell.org/trac/ghc/ticket/4080
* Their patch compiles a program that includes libcharset.h and compiles "const char* charset = locale_charset();". I don't know if this is needed, or whether just checking the header name like you've done will do.
* They also have a HAVE_LANGINFO_H define and fall back on just returning "", which works on GNU iconv. Maybe we should do this too?
I'm not sure about any of this, since I've just been testing on Solaris, Linux and FreeBSD.
Quoted 76 lines · Ævar Arnfjörð Bjarmason
Quoted 62 lines · Erik Faye-Lund
libcharset provides an even more portable way of quering the charset of the current locale.
Use that instead of
nl_langinfounlessNO_LIBCHARSETis set.Signed-off-by Erik Faye-Lund <[email protected]>---
Windows doesn't have
langinfo.handnl_langinfo(), but libcharset was invented for this very purpose. With this patch on top, ab/i18n compiles without errors in msysGit.There's still a bunch of lower-level issues on Windows, like gettext ending up overloading our winansi-wrappings for printf and friends, but let's take thinks one step at the time :)
configure.ac | 6 ++++++
gettext.c | 10 +++++++++-2 files changed, 15 insertions(+), 1 deletions(-)configure.ac +6
-0@@ -810,6 +810,12 @@ AC_CHECK_HEADER([libintl.h], [NO_GETTEXT=YesPlease]) AC_SUBST(NO_GETTEXT) # +# Define NO_LIBCHARSET if you don't have libcharset.h +AC_CHECK_HEADER([libcharset.h], +[NO_LIBCHARSET=], +[NO_LIBCHARSET=YesPlease]) +AC_SUBST(NO_LIBCHARSET) +# # Define NO_STRCASESTR if you don't have strcasestr. GIT_CHECK_FUNC(strcasestr, [NO_STRCASESTR=],gettext.c +5
-1@@ -1,13 +1,17 @@ #include "exec_cmd.h" #include <locale.h> #include <libintl.h> +#ifndef NO_LIBCHARSET +#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) {gettext.c extern void git_setup_gettext(void) { · line 34
Quoted 10 lines
gettext.c +4
-0(void)setlocale(LC_MESSAGES, ""); (void)setlocale(LC_CTYPE, ""); +#ifndef NO_LIBCHARSET + charset = locale_charset(); +#else charset = nl_langinfo(CODESET); +#endif (void)bind_textdomain_codeset("git", charset); (void)setlocale(LC_CTYPE, "C"); (void)textdomain("git");Thanks for porting it to Windows. Some points:
Quoted 4 lines
* Nit: Should be
NEEDS_LIBCHARSETinstead ofNO_LIBCHARSET, all the variables that set library inclusions in theMakefileuse the NEED_* names.
That's not true, at least NO_OPENSSL, NO_PTHREADS, NO_ICONV, NO_LIBGEN_H, NO_MMAP and NO_SYS_SELECT_H use the NO_-prefix to include libraries (as opposed to the NEEDS_-prefix). And to be honest, I think the NEEDS_-prefix would be a lie in this case; we don't NEED it, we take advantage of it if it's there.
To be honest, I just mimicked what was done for detection of gettext. Perhaps HAVE_LIBCHARSET_H would be the appropriate define? It's what we use for paths.h (HAVE_PATHS_H)...
Quoted 5 lines
* Their patch compiles a program that includes
libcharset.hand compiles "const char* charset =locale_charset();". I don't know if this is needed, or whether just checking the header name like you've done will do.
I don't think there's any point to it - libcharset.h is pretty much just about that one function. And if it turns out I'm wrong, we can add a check like that in the future.
Quoted 4 lines
* They also have a
HAVE_LANGINFO_Hdefine and fall back on just returning "", which works on GNU iconv. Maybe we should do this too?
Perhaps, but can't that wait until we encounter a system that needs it?
What's interesting there is what you say about GNU iconv handling "". This means that the minimal fix for Windows could be even smaller - we're using GNU iconv :)
Quoted 2 lines
I'm not sure about any of this, since I've just been testing on Solaris, Linux and FreeBSD.
I think Solaris, Linux, FreeBSD and Windows is a pretty wide selection of platforms, so I hope it should be pretty painless once this hits 'next'. Sure, there might be some platforms that needs a fix-up, but there always is with new code. And besides, there's even time to test more platforms before merging to 'next', no? :)
cover use libcharset.h with gettext if available
Quoted 89 lines · Erik Faye-Lund
Quoted 76 lines · Ævar Arnfjörð Bjarmason
Quoted 62 lines · Erik Faye-Lund
libcharset provides an even more portable way of quering the charset of the current locale.
Use that instead of
nl_langinfounlessNO_LIBCHARSETis set.Signed-off-by Erik Faye-Lund <[email protected]>---
Windows doesn't have
langinfo.handnl_langinfo(), but libcharset was invented for this very purpose. With this patch on top, ab/i18n compiles without errors in msysGit.There's still a bunch of lower-level issues on Windows, like gettext ending up overloading our winansi-wrappings for printf and friends, but let's take thinks one step at the time :)
configure.ac | 6 ++++++
gettext.c | 10 +++++++++-2 files changed, 15 insertions(+), 1 deletions(-)configure.ac +6
-0@@ -810,6 +810,12 @@ AC_CHECK_HEADER([libintl.h], [NO_GETTEXT=YesPlease]) AC_SUBST(NO_GETTEXT) # +# Define NO_LIBCHARSET if you don't have libcharset.h +AC_CHECK_HEADER([libcharset.h], +[NO_LIBCHARSET=], +[NO_LIBCHARSET=YesPlease]) +AC_SUBST(NO_LIBCHARSET) +# # Define NO_STRCASESTR if you don't have strcasestr. GIT_CHECK_FUNC(strcasestr, [NO_STRCASESTR=],gettext.c +5
-1@@ -1,13 +1,17 @@ #include "exec_cmd.h" #include <locale.h> #include <libintl.h> +#ifndef NO_LIBCHARSET +#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) {gettext.c extern void git_setup_gettext(void) { · line 34
Quoted 10 lines
gettext.c +4
-0(void)setlocale(LC_MESSAGES, ""); (void)setlocale(LC_CTYPE, ""); +#ifndef NO_LIBCHARSET + charset = locale_charset(); +#else charset = nl_langinfo(CODESET); +#endif (void)bind_textdomain_codeset("git", charset); (void)setlocale(LC_CTYPE, "C"); (void)textdomain("git");Thanks for porting it to Windows. Some points:
Quoted 4 lines
* Nit: Should be
NEEDS_LIBCHARSETinstead ofNO_LIBCHARSET, all the variables that set library inclusions in theMakefileuse the NEED_* names.That's not true, at least
NO_OPENSSL,NO_PTHREADS,NO_ICONV,NO_LIBGEN_H,NO_MMAPandNO_SYS_SELECT_Huse the NO_-prefix to include libraries (as opposed to the NEEDS_-prefix). And to be honest, I think the NEEDS_-prefix would be a lie in this case; we don't NEED it, we take advantage of it if it's there.
Quoted 3 lines
To be honest, I just mimicked what was done for detection of gettext. Perhaps
HAVE_LIBCHARSET_Hwould be the appropriate define? It's what we use forpaths.h(HAVE_PATHS_H)...
You're right, a NO_* makes more sense here.
Quoted 10 lines
Quoted 5 lines
* Their patch compiles a program that includes
libcharset.hand compiles "const char* charset =locale_charset();". I don't know if this is needed, or whether just checking the header name like you've done will do.I don't think there's any point to it -
libcharset.his pretty much just about that one function. And if it turns out I'm wrong, we can add a check like that in the future.
Quoted 6 lines
Quoted 4 lines
* They also have a
HAVE_LANGINFO_Hdefine and fall back on just returning "", which works on GNU iconv. Maybe we should do this too?Perhaps, but can't that wait until we encounter a system that needs it?
To both of the above: It's completely reasonable as-is, I just wanted to mention it in case a list member knew of a reason to do it like GHC did it. But just checking for the header will do fine until we encounter issues with that.
Quoted 3 lines
What's interesting there is what you say about GNU iconv handling "". This means that the minimal fix for Windows could be even smaller - we're using GNU iconv :)
Yeah, but probably better to do it by using libcharset.h instead.
Quoted 8 lines
Quoted 2 lines
I'm not sure about any of this, since I've just been testing on Solaris, Linux and FreeBSD.
I think Solaris, Linux, FreeBSD and Windows is a pretty wide selection of platforms, so I hope it should be pretty painless once this hits 'next'. Sure, there might be some platforms that needs a fix-up, but there always is with new code. And besides, there's even time to test more platforms before merging to 'next', no? :)
Yeah, I'm hoping it'll get into next soon so we can get more reports/fixes like these. Anyway, I amended your patches a bit, here are the changes:
* Split up the s/char*/const char*/ change into its own patch, or is there a reason for why this needs to be there along with the libcharset.h change?
* Added docs about the define to the Makefile
* Added defaults for NO_LIBCHARSET to the default, I only changed the defaults for the MINGW entry, maybe it should be changed on Cygwin and Windows too? And probably on OpenBSD and NetBSD too.
Erik Faye-Lund (2):
gettext: use const char* instead of char*
gettext: use libcharset when available
Makefile | 17 +++++++++++++++++ configure.ac | 6 ++++++ gettext.c | 10 +++++++++- 3 files changed, 32 insertions(+), 1 deletions(-)
Signature · 1 line
1.7.3.159.g610493
Re: [PATCH/RFC 0/2] use libcharset.h with gettext if available
Quoted 8 lines · Ævar Arnfjörð Bjarmason
Yeah, I'm hoping it'll get into next soon so we can get more reports/fixes like these. Anyway, I amended your patches a bit, here are the changes:
* Split up the s/char*/const char*/ change into its own patch, or is there a reason for why this needs to be there along with the
libcharset.hchange?
The reason was that my version of locale_charset() returns a const char *, so I got a warning if I didn't. nl_langinfo() returns a char *, so I don't think that constness-fix patch makes sense in itself. But what might make more sense would be to squash it into the original commit for that line.
Quoted 2 lines
* Added docs about the define to the
Makefile
Nice!
Quoted 4 lines
* Added defaults for
NO_LIBCHARSETto the default, I only changed the defaults for the MINGW entry, maybe it should be changed on Cygwin and Windows too? And probably on OpenBSD and NetBSD too.
I don't think NO_LIBCHARSET should be the default. libcharset is reported to be a bit better than nl_langinfo at normalizing the encoding, and GNU gettext depends on libcharset (through libiconv, which libcharset is distributed with). So in the case of a GNU gettext, libcharset should really be present.
Quoted 17 lines
Erik Faye-Lund (2):
gettext: use const char* instead of char*
gettext: use libcharset when availableMakefile | 17 +++++++++++++++++
configure.ac | 6 ++++++
gettext.c | 10 +++++++++-3 files changed, 32 insertions(+), 1 deletions(-)--
1.7.3.159.g610493--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH/RFC 0/2] use libcharset.h with gettext if available
Quoted 11 lines · Erik Faye-Lund
Quoted 8 lines · Ævar Arnfjörð Bjarmason
Yeah, I'm hoping it'll get into next soon so we can get more reports/fixes like these. Anyway, I amended your patches a bit, here are the changes:
* Split up the s/char*/const char*/ change into its own patch, or is there a reason for why this needs to be there along with the
libcharset.hchange?
Quoted 5 lines
The reason was that my version of
locale_charset()returns a const char *, so I got a warning if I didn't.nl_langinfo()returns a char *, so I don't think that constness-fix patch makes sense in itself. But what might make more sense would be to squash it into the original commit for that line.
Ah, then it should be part of the patch. I'll add a note about the different prototypes to it.
Quoted 10 lines
Quoted 2 lines
* Added docs about the define to the
MakefileNice!
Quoted 4 lines
* Added defaults for
NO_LIBCHARSETto the default, I only changed the defaults for the MINGW entry, maybe it should be changed on Cygwin and Windows too? And probably on OpenBSD and NetBSD too.
Quoted 5 lines
I don't think
NO_LIBCHARSETshould be the default. libcharset is reported to be a bit better thannl_langinfoat normalizing the encoding, and GNU gettext depends on libcharset (through libiconv, which libcharset is distributed with). So in the case of a GNU gettext, libcharset should really be present.
I can't find any package (with apt-file) on Debian or Ubuntu that provides libcharset.h, but I have langinfo.h on those systems.
The GNU gettext manual also reccomends the use of nl_langinfo in "11.2.4 How to specify the output character set `gettext' uses", so it seems that using that and not libiconv is the default way of doing things on GNU gettext + GNU libc systems.
Re: [PATCH/RFC 0/2] use libcharset.h with gettext if available
Quoted 7 lines · Ævar Arnfjörð Bjarmason
Quoted 6 lines · Erik Faye-Lund
On Tue, Sep 28, 2010 at 8:29 PM, Ævar Arnfjörð Bjarmason
Quoted 4 lines
* Added defaults for
NO_LIBCHARSETto the default, I only changed the defaults for the MINGW entry, maybe it should be changed on Cygwin and Windows too? And probably on OpenBSD and NetBSD too.
Quoted 9 lines
Quoted 5 lines
I don't think
NO_LIBCHARSETshould be the default. libcharset is reported to be a bit better thannl_langinfoat normalizing the encoding, and GNU gettext depends on libcharset (through libiconv, which libcharset is distributed with). So in the case of a GNU gettext, libcharset should really be present.I can't find any package (with apt-file) on Debian or Ubuntu that provides
libcharset.h, but I havelanginfo.hon those systems.
Strange. A 'make install' on libiconv installed libcharset.h to $prefix/include on my system. But looking a bit deeper, it seems that glibc supplies it's own iconv implementation (perhaps based on libiconv, I don't know). So yes, I tend to agree with you. GNU platforms should not be expected to have libcharset.
Quoted 5 lines
The GNU gettext manual also reccomends the use of
nl_langinfoin "11.2.4 How to specify the output character set `gettext' uses", so it seems that using that and not libiconv is the default way of doing things on GNU gettext + GNU libc systems.
OK, fair enough. I based my comment on some comment by the GNU gettext maintainer (who is also the libcharset maintainer - libcharset does in fact use nl_langinfo if present), but since this is in the manual I fully withdraw my comment.
Then again, if this is an opt-in rather than an opt-out, perhaps we should change the switch to HAVE_LIBCHARSET? I don't mean to go in circles here, but it sounds more self-documenting to me.
PATCH 1/1 gettext: use libcharset when available
From: Erik Faye-Lund <[email protected]>
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.
---
Junio, this goes on top of ab/i18n.
Quoted 19 lines · Erik Faye-Lund
Quoted 7 lines · Ævar Arnfjörð Bjarmason
Quoted 6 lines · Erik Faye-Lund
On Tue, Sep 28, 2010 at 8:29 PM, Ævar Arnfjörð Bjarmason
Quoted 4 lines
* Added defaults for
NO_LIBCHARSETto the default, I only changed the defaults for the MINGW entry, maybe it should be changed on Cygwin and Windows too? And probably on OpenBSD and NetBSD too.Quoted 9 lines
Quoted 5 lines
I don't think
NO_LIBCHARSETshould be the default. libcharset is reported to be a bit better thannl_langinfoat normalizing the encoding, and GNU gettext depends on libcharset (through libiconv, which libcharset is distributed with). So in the case of a GNU gettext, libcharset should really be present.I can't find any package (with apt-file) on Debian or Ubuntu that provides
libcharset.h, but I havelanginfo.hon those systems.
Quoted 5 lines
Strange. A 'make install' on libiconv installed
libcharset.hto $prefix/include on my system. But looking a bit deeper, it seems that glibc supplies it's own iconv implementation (perhaps based on libiconv, I don't know). So yes, I tend to agree with you. GNU platforms should not be expected to have libcharset.
I asked around and none of Debian/Ubuntu/Fedora and other Linux systems have libcharset.h, and using the gettext branch without libcharset.h on FreeBSD works fine.
Quoted 6 lines
Quoted 5 lines
The GNU gettext manual also reccomends the use of
nl_langinfoin "11.2.4 How to specify the output character set `gettext' uses", so it seems that using that and not libiconv is the default way of doing things on GNU gettext + GNU libc systems.
Quoted 8 lines
OK, fair enough. I based my comment on some comment by the GNU gettext maintainer (who is also the libcharset maintainer - libcharset does in fact use
nl_langinfoif present), but since this is in the manual I fully withdraw my comment.Then again, if this is an opt-in rather than an opt-out, perhaps we should change the switch to
HAVE_LIBCHARSET? I don't mean to go in circles here, but it sounds more self-documenting to me.
Agreed, changed in this version. I also added a bit to config.mak.in to make the configure.ac change actually do something, and changed the docs & commit message.
Makefile | 17 +++++++++++++++++ config.mak.in | 1 + configure.ac | 6 ++++++ gettext.c | 10 +++++++++- 4 files changed, 33 insertions(+), 1 deletions(-)
Makefile +17 -0
@@ -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
config.mak.in +1 -0
@@ -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@
configure.ac +6 -0
@@ -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=],
gettext.c +9 -1
@@ -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" );
Signature · 1 line
1.7.3.159.g610493
Quoted 6 lines · Ævar Arnfjörð Bjarmason
From: Erik Faye-Lund <[email protected]>
Change the
git_setup_gettextfunction to use libcharset to query the character set of the current locale if it's available. I.e. use it instead ofnl_langinfoifHAVE_LIBCHARSET_His set.
Quoted 8 lines
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'slocale_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'slocale_charset()instead.
Very minor nit: It's officially spelled MinGW, with an upper-case G.
Quoted 11 lines
Since
locale_charsetreturns a const char* instead of char* asnl_langinfodoes the type of the variable we're using to store the charset ingit_setup_gettexthas been changed.Signed-off-by Erik Faye-Lund <[email protected]>Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>---
Junio, this goes on top of ab/i18n.
Wow, thanks for taking care of this!
PATCH v2 1/1 gettext: use libcharset when available
From: Erik Faye-Lund <[email protected]>
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.
---
Quoted 1 line · Erik Faye-Lund
Very minor nit: It's officially spelled MinGW, with an upper-case G.
Did s/MingW/MinGW/ in the content & message in this v2.
Makefile | 19 ++++++++++++++++++- config.mak.in | 1 + configure.ac | 6 ++++++ gettext.c | 10 +++++++++- 4 files changed, 34 insertions(+), 2 deletions(-)
Makefile +18 -1
@@ -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
@@ -268,7 +274,7 @@ uname_P := $(shell sh -c 'uname -p 2>/dev/null || echo not') uname_V := $(shell sh -c 'uname -v 2>/dev/null || echo not') ifdef MSVC - # avoid the MingW and Cygwin configuration sections + # avoid the MinGW and Cygwin configuration sections uname_S := Windows uname_O := Windows endif
@@ -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
config.mak.in +1 -0
@@ -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@
configure.ac +6 -0
@@ -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=],
gettext.c +9 -1
@@ -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" );
Signature · 1 line
1.7.3.159.g610493
PATCH v3 1/1 gettext: use libcharset when available
From: Erik Faye-Lund <[email protected]>
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.
---
Quoted 5 lines · Ævar Arnfjörð Bjarmason
From: Erik Faye-Lund <[email protected]>
Quoted 1 line · Erik Faye-Lund
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(-)
Makefile +17 -0
@@ -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
config.mak.in +1 -0
@@ -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@
configure.ac +6 -0
@@ -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=],
gettext.c +9 -1
@@ -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" );
Signature · 1 line
1.7.3.159.g610493
PATCH 1/2 gettext: use const char* instead of char*
In reply to Erik Faye-LundFrom: Erik Faye-Lund <[email protected]>
Change the charset variable in git_setup_gettext from char* to const char*.
--- gettext.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
gettext.c +1 -1
@@ -7,7 +7,7 @@extern void git_setup_gettext (void ) {char *podir;char *envdir =getenv ("GIT_TEXTDOMAINDIR" ); -char *charset; +const char *charset;if (envdir) { (void )bindtextdomain ("git" , envdir);
Signature · 1 line
1.7.3.159.g610493