bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gettext 0.10.37 msgfmt charset naming compatibility on Solaris 8


From: Paul Eggert
Subject: gettext 0.10.37 msgfmt charset naming compatibility on Solaris 8
Date: Tue, 15 May 2001 15:14:11 -0700 (PDT)

After installing gettext 0.10.37 on Solaris 8 I ran into problems like this:

$ msgfmt es.po
es.po: warning: Charset "ISO-8859-1" is not supported. msgfmt relies on iconv(),
                and iconv() does not support "ISO-8859-1".
                Installing GNU libiconv and then reinstalling GNU gettext
                would fix this problem.
                Continuing anyway.

I had already installed five packages that day, so instead of
installing yet another one I thought it nicer to remove GNU gettext's
dependency on GNU libiconv, on this platform anyway.  Here's a patch.
It's a bit of a hack, but it requires few changes to existing code.
If you prefer it written some other way I can rewrite it.  It is handy
to not have to worry about installing the extra package and getting
everything linked up correctly.

This patch does not affect behavior in the cases where GNU gettext
currently succeeds; it is a pure extension.

2001-05-15  Paul Eggert  <address@hidden>

        Add support for using native iconv on hosts like Solaris 8
        where the native codeset names differ from the GNU names.

        * lib/localcharset.c (get_charset_aliases): Make it STATIC,
        not static, so that ../src/iconvariant.c can use it.

        * src/Makefile.am (noinst_HEADERS): Add iconvariant.h.
        (msgcmp_SOURCES, msgfmt_SOURCES, msgmerge_SOURCES, msgunfmt_SOURCES,
        msgcomm_SOURCES): Add iconvariant.c.

        * src/po.c, src/write-po.c: Include iconvariant.h.
        * src/po.c (po_callback_message): Use iconvariant_open,
        not iconv_open.
        * src/write-po.c (wrap): Likewise.

        * src/iconvariant.c, src/iconvariant.h: New files.

===================================================================
RCS file: lib/localcharset.c,v
retrieving revision 0.10
retrieving revision 0.10.37.1
diff -pu -r0.10 -r0.10.37.1
--- lib/localcharset.c  2001/03/11 15:52:12     0.10
+++ lib/localcharset.c  2001/05/15 21:33:43     0.10.37.1
@@ -78,7 +78,10 @@
 static char * volatile charset_aliases;
 
 /* Return a pointer to the contents of the charset.alias file.  */
-static const char *
+#ifdef STATIC
+STATIC
+#endif
+const char *
 get_charset_aliases ()
 {
   char *cp;
===================================================================
RCS file: src/Makefile.am,v
retrieving revision 0.10
retrieving revision 0.10.37.1
diff -pu -r0.10 -r0.10.37.1
--- src/Makefile.am     2001/03/20 15:01:38     0.10
+++ src/Makefile.am     2001/05/15 21:33:43     0.10.37.1
@@ -22,6 +22,7 @@ AUTOMAKE_OPTIONS = 1.2 gnits
 bin_PROGRAMS = gettext ngettext msgcmp msgfmt msgmerge msgunfmt xgettext 
msgcomm
 
 noinst_HEADERS = pos.h message.h po-gram.h po-hash.h po-lex.h po.h open-po.h \
+iconvariant.h \
 str-list.h write-po.h xget-lex.h dir-list.h po-gram-gen.h po-hash-gen.h
 
 EXTRA_DIST = FILES
@@ -41,20 +42,19 @@ YACC = @YACC@ -d
 gettext_SOURCES = gettext.c
 ngettext_SOURCES = ngettext.c
 msgcmp_SOURCES = message.c msgcmp.c open-po.c po-gram-gen.y po-hash-gen.y \
-po-lex.c po.c str-list.c dir-list.c
+po-lex.c po.c str-list.c dir-list.c iconvariant.c
 msgfmt_SOURCES = msgfmt.c open-po.c po-gram-gen.y po-hash-gen.y po-lex.c po.c \
-str-list.c message.c dir-list.c
+str-list.c message.c dir-list.c iconvariant.c
 msgmerge_SOURCES = message.c msgmerge.c open-po.c po-gram-gen.y po-hash-gen.y \
-po-lex.c po.c str-list.c dir-list.c write-po.c
-msgunfmt_SOURCES = message.c msgunfmt.c str-list.c write-po.c
+po-lex.c po.c str-list.c dir-list.c write-po.c iconvariant.c
+msgunfmt_SOURCES = message.c msgunfmt.c str-list.c write-po.c iconvariant.c
 xgettext_SOURCES = message.c open-po.c po-gram-gen.y po-hash-gen.y po-lex.c \
-po.c str-list.c xget-lex.c xgettext.c dir-list.c write-po.c
+po.c str-list.c xget-lex.c xgettext.c dir-list.c write-po.c iconvariant.c
 msgcomm_SOURCES = msgcomm.c message.c po-gram-gen.y po-hash-gen.y po-lex.c \
-open-po.c po.c str-list.c dir-list.c write-po.c
+open-po.c po.c str-list.c dir-list.c write-po.c iconvariant.c
 
 # Link dependencies.
-# po-lex.c and po.c may need -liconv.
-# write-po.c pulls in linebreak.c which may need -liconv.
+# po-lex.c, po.c and write-po.c may need -liconv.
 msgcmp_LDADD = ../lib/libnlsut.a @INTLLIBS@ @LIBICONV@
 msgfmt_LDADD = ../lib/libnlsut.a @INTLLIBS@ @LIBICONV@
 msgmerge_LDADD = ../lib/libnlsut.a @INTLLIBS@ @LIBICONV@
===================================================================
RCS file: src/po.c,v
retrieving revision 0.10
retrieving revision 0.10.37.1
diff -pu -r0.10 -r0.10.37.1
--- src/po.c    2001/04/18 20:26:14     0.10
+++ src/po.c    2001/05/15 21:42:07     0.10.37.1
@@ -31,6 +31,7 @@ Foundation, Inc., 59 Temple Place - Suit
 #include "system.h"
 #include "mbswidth.h"
 #include "libgettext.h"
+#include "iconvariant.h"
 
 extern const char *program_name;
 
@@ -356,7 +357,7 @@ Message conversion to user's charset mig
                    po_lex_iconv = (iconv_t)(-1);
                  else
 # endif
-                 po_lex_iconv = iconv_open ("UTF-8", po_lex_charset);
+                 po_lex_iconv = iconvariant_open ("UTF-8", po_lex_charset);
                  if (po_lex_iconv == (iconv_t)(-1))
                    {
                      const char *note;
===================================================================
RCS file: src/write-po.c,v
retrieving revision 0.10
retrieving revision 0.10.37.2
diff -pu -r0.10 -r0.10.37.2
--- src/write-po.c      2001/04/18 20:26:14     0.10
+++ src/write-po.c      2001/05/15 22:09:31     0.10.37.2
@@ -34,6 +34,7 @@ Foundation, Inc., 59 Temple Place - Suit
 #include <iconv.h>
 #endif
 
+#include "iconvariant.h"
 #include "write-po.h"
 #include "c-ctype.h"
 #include "linebreak.h"
@@ -212,7 +213,7 @@ wrap (fp, line_prefix, name, value, do_w
     conv = (iconv_t)(-1);
   else
     /* Use iconv() to parse multibyte characters.  */
-    conv = iconv_open ("UTF-8", charset);
+    conv = iconvariant_open ("UTF-8", charset);
 #endif
 
   /* Loop over the '\n' delimited portions of value.  */
--- /dev/null   Tue May 15 22:08:25 2001
+++ src/iconvariant.h   Tue May 15 22:01:10 2001
@@ -0,0 +1,29 @@
+/* GNU gettext - iconv wrapper for hosts that don't use GNU standard names
+   Copyright (C) 2001 Free Software Foundation, Inc.
+
+   This file was written by Paul Eggert <address@hidden>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+#ifndef SRC_ICONVARIANT_H
+#define SRC_ICONVARIANT_H
+
+#if HAVE_ICONV
+
+/* Return a conversion descriptor for translating.  */
+iconv_t iconvariant_open PARAMS ((const char *__to, const char *__from));
+
+#endif
+#endif
--- /dev/null   Tue May 15 22:08:25 2001
+++ src/iconvariant.c   Tue May 15 22:01:25 2001
@@ -0,0 +1,77 @@
+/* GNU gettext - iconv wrapper for hosts that don't use GNU standard names
+   Copyright (C) 2001 Free Software Foundation, Inc.
+
+   This file was written by Paul Eggert <address@hidden>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#if !HAVE_ICONV
+static char dummy;
+#else
+
+#include <iconv.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include "iconvariant.h"
+
+extern char *get_charset_aliases PARAMS ((void));
+
+/* Return a variant name for CODESET, if there is a plausible candidate
+   that differs from CODESET; otherwise return NULL.  */
+static const char *
+variant_name_for_codeset (codeset)
+     const char *codeset;
+{
+  const char *p = get_charset_aliases ();
+
+  while (*p)
+    {
+      const char *variant_name = p;
+      const char *canonical_name = p += strlen (p) + 1;
+      if (*variant_name != '*' && strcmp (codeset, canonical_name) == 0)
+       return strcmp (variant_name, codeset) == 0 ? NULL : variant_name;
+      p += strlen (p) + 1;
+    }
+
+  return NULL;
+}
+
+/* Return a conversion descriptor for translating to TO from FROM.
+   This acts like iconv_open, except it looks for variant names.  */
+iconv_t
+iconvariant_open (to, from)
+     const char *to;
+     const char *from;
+{
+  iconv_t r = iconv_open (to, from);
+
+  if (r == (iconv_t) -1)
+    {
+      const char *vto = variant_name_for_codeset (to);
+      const char *vfrom = variant_name_for_codeset (from);
+      if (vto || vfrom)
+       r = iconv_open (vto ? vto : to, vfrom ? vfrom : from);
+    }
+
+  return r;
+}
+
+#endif



reply via email to

[Prev in Thread] Current Thread [Next in Thread]