git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] gettext: use libcharset when available

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Sep 28, 2010, 17:07 UTC
Message-ID
<AANLkTin_fu02QN0cUX15+02iO7xJ+tii5aVBqR2V_AVc@mail.gmail.com>
In-Reply-To
<1285689926-5048-1-git-send-email-kusmabite@gmail.com>
On Tue, Sep 28, 2010 at 16:05, Erik Faye-Lund <kusmabite@gmail.com> wrote:
Show 72 quoted lines
> 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.
>
> Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
> ---
>
> 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(-)
>
> diff --git a/configure.ac b/configure.ac
> index 1821d89..d3139cd 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -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=],
> diff --git a/gettext.c b/gettext.c
> index 8644098..902268c 100644
> --- a/gettext.c
> +++ b/gettext.c
> @@ -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");
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.

Previous: Erik Faye-LundNext: Erik Faye-Lund
Message 2 of 12 in “gettext: use libcharset when available”
  1. gettext: use libcharset when availableErik Faye-Lund, Sep 28, 2010
  2. Ævar Arnfjörð BjarmasonSep 28, 2010
  3. Erik Faye-LundSep 28, 2010
  4. 0/2 use libcharset.h with gettext if availableÆvar Arnfjörð Bjarmason, Sep 28, 2010
  5. Erik Faye-LundSep 28, 2010
  6. Ævar Arnfjörð BjarmasonSep 29, 2010
  7. Erik Faye-LundSep 29, 2010
  8. gettext: use libcharset when availableÆvar Arnfjörð Bjarmason, Sep 29, 2010
  9. Erik Faye-LundSep 29, 2010
  10. gettext: use libcharset when availableÆvar Arnfjörð Bjarmason, Sep 29, 2010
  11. gettext: use libcharset when availableÆvar Arnfjörð Bjarmason, Sep 29, 2010
  12. 1/2 gettext: use const char* instead of char*Ævar Arnfjörð Bjarmason, Sep 28, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.