summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2002-03-29 08:53:42 +0000
committerJeffrey Stedfast <fejj@src.gnome.org>2002-03-29 08:53:42 +0000
commitff18904904e7fee3e2765a54589daa8c7a178609 (patch)
tree169e277629eea05fbb8bf3234cfce855a6d7e64f
parent2b9e17c357fef582b6316c22ee4576d36f17282c (diff)
downloadgmime-ff18904904e7fee3e2765a54589daa8c7a178609.tar.gz
Detect the iconv-friendly formats for iso charsets at configure time and
2002-03-29 Jeffrey Stedfast <fejj@ximian.com> * configure.in: Detect the iconv-friendly formats for iso charsets at configure time and dump them into iconv-detect.h for use in gmime-charset.c. * gmime-charset.c: Updated to use iconv-detect.h if it exists.
-rw-r--r--.cvsignore1
-rw-r--r--ChangeLog8
-rw-r--r--acconfig.h1
-rw-r--r--config.h.in1
-rw-r--r--configure.in16
-rw-r--r--gmime-charset.c58
-rw-r--r--gmime/gmime-charset.c58
-rw-r--r--iconv-detect.c184
8 files changed, 277 insertions, 50 deletions
diff --git a/.cvsignore b/.cvsignore
index df432170..c3bd6ce7 100644
--- a/.cvsignore
+++ b/.cvsignore
@@ -27,3 +27,4 @@ test-streams
test-html
test-iconv
gmime.spec
+iconv-detect.h
diff --git a/ChangeLog b/ChangeLog
index ceef48db..4a01bcf3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2002-03-29 Jeffrey Stedfast <fejj@ximian.com>
+
+ * configure.in: Detect the iconv-friendly formats for iso charsets
+ at configure time and dump them into iconv-detect.h for use in
+ gmime-charset.c.
+
+ * gmime-charset.c: Updated to use iconv-detect.h if it exists.
+
2002-03-23 Jeffrey Stedfast <fejj@ximian.com>
* gmime-param.c (rfc2184_decode): Don't bother using
diff --git a/acconfig.h b/acconfig.h
index d34272e8..f8c42b30 100644
--- a/acconfig.h
+++ b/acconfig.h
@@ -23,6 +23,7 @@
#undef HAVE_ICONV
#undef ICONV_CONST
+#undef HAVE_ICONV_DETECT_H
#undef HAVE_MMAP
#undef HAVE_MUNMAP
diff --git a/config.h.in b/config.h.in
index 013ae64f..8e13b8f7 100644
--- a/config.h.in
+++ b/config.h.in
@@ -24,6 +24,7 @@
#undef HAVE_ICONV
#undef ICONV_CONST
+#undef HAVE_ICONV_DETECT_H
#undef HAVE_MMAP
#undef HAVE_MUNMAP
diff --git a/configure.in b/configure.in
index db66a9b8..a567c3b8 100644
--- a/configure.in
+++ b/configure.in
@@ -117,6 +117,22 @@ AC_SUBST(glib_libs)
dnl Check for libiconv
AM_ICONV()
+AC_MSG_CHECKING(preferred charset formats for system iconv)
+AC_TRY_RUN([
+#include "iconv-detect.c"
+],[
+ AC_MSG_RESULT(found)
+ AC_DEFINE(HAVE_ICONV_DETECT_H)
+],[
+ AC_MSG_RESULT(not found)
+ AC_ERROR([
+ *** The iconv-detect program was unable to determine the
+ *** preferred charset formats recognized by your system
+ *** iconv library. It is suggested that you install a
+ *** working iconv library such as the one found at
+ *** ftp://ftp.gnu.org/pub/gnu/libiconv
+ ])
+])
dnl * Time zone stuff
AC_CACHE_CHECK(for timezone variable, ac_cv_var_timezone,
diff --git a/gmime-charset.c b/gmime-charset.c
index 2905ce2d..b4f108d8 100644
--- a/gmime-charset.c
+++ b/gmime-charset.c
@@ -39,20 +39,23 @@
#include "unicode.h"
#include "strlib.h"
-
+#ifdef HAVE_ICONV_DETECT_H
+#include "iconv-detect.h"
+#else /* use old-style detection */
#if defined (__aix__) || defined (__irix__) || defined (__sun__)
-#define CANONICAL_ISO_D_FORMAT "ISO%d-%d"
+#define ICONV_ISO_D_FORMAT "ISO%d-%d"
/* this one is for charsets like ISO-2022-JP, for which at least
Solaris wants a - after the ISO */
-#define CANONICAL_ISO_S_FORMAT "ISO-%d-%s"
+#define ICONV_ISO_S_FORMAT "ISO-%d-%s"
#elif defined (__hpux__)
-#define CANONICAL_ISO_D_FORMAT "iso%d%d"
-#define CANONICAL_ISO_S_FORMAT "iso%d%s"
+#define ICONV_ISO_D_FORMAT "iso%d%d"
+#define ICONV_ISO_S_FORMAT "iso%d%s"
#else
-#define CANONICAL_ISO_D_FORMAT "iso-%d-%d"
-#define CANONICAL_ISO_S_FORMAT "iso-%d-%s"
+#define ICONV_ISO_D_FORMAT "iso-%d-%d"
+#define ICONV_ISO_S_FORMAT "iso-%d-%s"
#endif /* __aix__, __irix__, __sun__ */
-
+#define ICONV_10646 "iso-10646"
+#endif /* USE_ICONV_DETECT */
struct {
char *charset;
@@ -227,25 +230,30 @@ g_mime_charset_name (const char *charset)
g_assert (p > buf);
- buf = p;
- if (*buf == '-' || *buf == '_')
- buf++;
-
- codepage = strtoul (buf, &p, 10);
-
- if (p > buf) {
- /* codepage is numeric */
+ if (iso == 10646) {
+ /* they all become ICONV_10646 */
+ iconv_name = g_strdup (ICONV_10646);
+ } else {
+ buf = p;
+ if (*buf == '-' || *buf == '_')
+ buf++;
+
+ codepage = strtoul (buf, &p, 10);
+
+ if (p > buf) {
+ /* codepage is numeric */
#ifdef __aix__
- if (codepage == 13)
- iconv_name = g_strdup ("IBM-921");
- else
+ if (codepage == 13)
+ iconv_name = g_strdup ("IBM-921");
+ else
#endif /* __aix__ */
- iconv_name = g_strdup_printf (CANONICAL_ISO_D_FORMAT,
- iso, codepage);
- } else {
- /* codepage is a string - probably iso-2022-jp or something */
- iconv_name = g_strdup_printf (CANONICAL_ISO_S_FORMAT,
- iso, p);
+ iconv_name = g_strdup_printf (ICONV_ISO_D_FORMAT,
+ iso, codepage);
+ } else {
+ /* codepage is a string - probably iso-2022-jp or something */
+ iconv_name = g_strdup_printf (ICONV_ISO_S_FORMAT,
+ iso, p);
+ }
}
} else if (!strncmp (name, "windows-", 8)) {
buf = name + 8;
diff --git a/gmime/gmime-charset.c b/gmime/gmime-charset.c
index 2905ce2d..b4f108d8 100644
--- a/gmime/gmime-charset.c
+++ b/gmime/gmime-charset.c
@@ -39,20 +39,23 @@
#include "unicode.h"
#include "strlib.h"
-
+#ifdef HAVE_ICONV_DETECT_H
+#include "iconv-detect.h"
+#else /* use old-style detection */
#if defined (__aix__) || defined (__irix__) || defined (__sun__)
-#define CANONICAL_ISO_D_FORMAT "ISO%d-%d"
+#define ICONV_ISO_D_FORMAT "ISO%d-%d"
/* this one is for charsets like ISO-2022-JP, for which at least
Solaris wants a - after the ISO */
-#define CANONICAL_ISO_S_FORMAT "ISO-%d-%s"
+#define ICONV_ISO_S_FORMAT "ISO-%d-%s"
#elif defined (__hpux__)
-#define CANONICAL_ISO_D_FORMAT "iso%d%d"
-#define CANONICAL_ISO_S_FORMAT "iso%d%s"
+#define ICONV_ISO_D_FORMAT "iso%d%d"
+#define ICONV_ISO_S_FORMAT "iso%d%s"
#else
-#define CANONICAL_ISO_D_FORMAT "iso-%d-%d"
-#define CANONICAL_ISO_S_FORMAT "iso-%d-%s"
+#define ICONV_ISO_D_FORMAT "iso-%d-%d"
+#define ICONV_ISO_S_FORMAT "iso-%d-%s"
#endif /* __aix__, __irix__, __sun__ */
-
+#define ICONV_10646 "iso-10646"
+#endif /* USE_ICONV_DETECT */
struct {
char *charset;
@@ -227,25 +230,30 @@ g_mime_charset_name (const char *charset)
g_assert (p > buf);
- buf = p;
- if (*buf == '-' || *buf == '_')
- buf++;
-
- codepage = strtoul (buf, &p, 10);
-
- if (p > buf) {
- /* codepage is numeric */
+ if (iso == 10646) {
+ /* they all become ICONV_10646 */
+ iconv_name = g_strdup (ICONV_10646);
+ } else {
+ buf = p;
+ if (*buf == '-' || *buf == '_')
+ buf++;
+
+ codepage = strtoul (buf, &p, 10);
+
+ if (p > buf) {
+ /* codepage is numeric */
#ifdef __aix__
- if (codepage == 13)
- iconv_name = g_strdup ("IBM-921");
- else
+ if (codepage == 13)
+ iconv_name = g_strdup ("IBM-921");
+ else
#endif /* __aix__ */
- iconv_name = g_strdup_printf (CANONICAL_ISO_D_FORMAT,
- iso, codepage);
- } else {
- /* codepage is a string - probably iso-2022-jp or something */
- iconv_name = g_strdup_printf (CANONICAL_ISO_S_FORMAT,
- iso, p);
+ iconv_name = g_strdup_printf (ICONV_ISO_D_FORMAT,
+ iso, codepage);
+ } else {
+ /* codepage is a string - probably iso-2022-jp or something */
+ iconv_name = g_strdup_printf (ICONV_ISO_S_FORMAT,
+ iso, p);
+ }
}
} else if (!strncmp (name, "windows-", 8)) {
buf = name + 8;
diff --git a/iconv-detect.c b/iconv-detect.c
new file mode 100644
index 00000000..edd7f74d
--- /dev/null
+++ b/iconv-detect.c
@@ -0,0 +1,184 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Authors: Jeffrey Stedfast <fejj@ximian.com>
+ *
+ * Copyright 2002 Ximian, Inc. (www.ximian.com)
+ *
+ * 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 of the License, 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 Street #330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+
+#include <stdio.h>
+#include <iconv.h>
+
+enum {
+ ISO_UNSUPPORTED = 0,
+
+ /* iso-8859-1 */
+ ISO_DASH_D_DASH_D_LOWER = (1 << 0),
+ ISO_DASH_D_DASH_D = (1 << 1),
+ ISO_D_DASH_D = (1 << 2),
+ ISO_D_D = (1 << 3),
+ ISO_UNDER_D_DASH_D = (1 << 4),
+ NO_ISO_D_DASH_D = (1 << 5),
+
+ /* iso-10646-1 */
+ /*ISO_DASH_D_DASH_D_LOWER = (1 << 0),*/
+ /*ISO_DASH_D_DASH_D = (1 << 1),*/
+ /*ISO_D_DASH_D = (1 << 2),*/
+ ISO_DASH_D_LOWER = (1 << 3),
+ ISO_DASH_D = (1 << 4),
+ ISO_D = (1 << 5),
+
+ /* iso-2022-jp */
+ ISO_DASH_D_DASH_S_LOWER = (1 << 0),
+ ISO_DASH_D_DASH_S = (1 << 1),
+ ISO_D_DASH_S = (1 << 2),
+};
+
+
+typedef struct {
+ char *charset;
+ char *format;
+ int id;
+} CharInfo;
+
+
+static CharInfo iso8859_tests[] = {
+ { "iso-8859-1", "iso-%d-%d", ISO_DASH_D_DASH_D_LOWER },
+ { "ISO-8859-1", "ISO-%d-%d", ISO_DASH_D_DASH_D },
+ { "ISO8859-1", "ISO%d-%d", ISO_D_DASH_D },
+ { "ISO88591", "ISO%d%d", ISO_D_D },
+ { "ISO_8859-1", "ISO_%d-%d", ISO_UNDER_D_DASH_D },
+ { "8859-1", "%d-%d", NO_ISO_D_DASH_D },
+};
+
+static int num_iso8859_tests = sizeof (iso8859_tests) / sizeof (CharInfo);
+
+static CharInfo iso2022_tests[] = {
+ { "iso-2022-jp", "iso-%d-%s", ISO_DASH_D_DASH_S_LOWER },
+ { "ISO-2022-JP", "ISO-%d-%s", ISO_DASH_D_DASH_S },
+ { "ISO2022-JP", "ISO%d-%s", ISO_D_DASH_S },
+};
+
+static int num_iso2022_tests = sizeof (iso2022_tests) / sizeof (CharInfo);
+
+static CharInfo iso10646_tests[] = {
+ { "iso-10646-1", "iso-%d-%d", ISO_DASH_D_DASH_D_LOWER },
+ { "ISO-10646-1", "ISO-%d-%d", ISO_DASH_D_DASH_D },
+ { "ISO10646-1", "ISO%d-%d", ISO_D_DASH_D },
+ { "iso-10646", "iso-%d\0%d", ISO_DASH_D_LOWER },
+ { "ISO-10646", "ISO-%d\0%d", ISO_DASH_D },
+ { "ISO10646", "ISO%d\0%d", ISO_D },
+};
+
+static int num_iso10646_tests = sizeof (iso10646_tests) / sizeof (CharInfo);
+
+
+int main (int argc, char **argv)
+{
+ unsigned int bits, iso8859, iso2022, iso10646;
+ CharInfo *info;
+ iconv_t cd;
+ FILE *fp;
+ int i;
+
+ fp = fopen ("iconv-detect.h", "w");
+ if (fp == NULL)
+ exit (255);
+
+ fprintf (fp, "/* This is an auto-generated header, DO NOT EDIT! */\n\n");
+
+ iso8859 = ISO_UNSUPPORTED;
+ info = iso8859_tests;
+ /*printf ("#define DEFAULT_ISO_FORMAT(iso,codepage)\t");*/
+ for (i = 0; i < num_iso8859_tests; i++) {
+ cd = iconv_open (info[i].charset, "UTF-8");
+ if (cd != (iconv_t) -1) {
+ iconv_close (cd);
+ /*printf ("(\"%s\", (iso), (codepage))\n", info[i].format);*/
+ fprintf (stderr, "System prefers %s\n", info[i].charset);
+ iso8859 = info[i].id;
+ break;
+ }
+ }
+
+ if (iso8859 == ISO_UNSUPPORTED) {
+ fprintf (stderr, "System doesn't support any ISO-8859-1 formats\n");
+ fprintf (fp, "#define ICONV_ISO_D_FORMAT \"%s\"\n", info[0].format);
+#ifdef CONFIGURE_IN
+ exit (1);
+#endif
+ } else {
+ fprintf (fp, "#define ICONV_ISO_D_FORMAT \"%s\"\n", info[i].format);
+ }
+
+ iso2022 = ISO_UNSUPPORTED;
+ info = iso2022_tests;
+ /*printf ("#define ISO_2022_FORMAT(iso,codepage)\t");*/
+ for (i = 0; i < num_iso2022_tests; i++) {
+ cd = iconv_open (info[i].charset, "UTF-8");
+ if (cd != (iconv_t) -1) {
+ iconv_close (cd);
+ /*printf ("(\"%s\", (iso), (codepage))\n", info[i].format);*/
+ fprintf (stderr, "System prefers %s\n", info[i].charset);
+ iso2022 = info[i].id;
+ break;
+ }
+ }
+
+ if (iso2022 == ISO_UNSUPPORTED) {
+ fprintf (stderr, "System doesn't support any ISO-2022 formats\n");
+ fprintf (fp, "#define ICONV_ISO_S_FORMAT \"%s\"\n", info[0].format);
+#ifdef CONFIGURE_IN
+ exit (3);
+#endif
+ } else {
+ fprintf (fp, "#define ICONV_ISO_S_FORMAT \"%s\"\n", info[i].format);
+ }
+
+ iso10646 = ISO_UNSUPPORTED;
+ info = iso10646_tests;
+ /*printf ("#define ISO_10646_FORMAT(iso,codepage)\t");*/
+ for (i = 0; i < num_iso10646_tests; i++) {
+ cd = iconv_open (info[i].charset, "UTF-8");
+ if (cd != (iconv_t) -1) {
+ iconv_close (cd);
+ /*if (info[i].id < ISO_DASH_D_LOWER)
+ printf ("(\"%s\", (iso), (codepage))\n", info[i].format);
+ else
+ printf ("(\"%s\", (iso))\n", info[i].format);*/
+ fprintf (stderr, "System prefers %s\n", info[i].charset);
+ iso10646 = info[i].id;
+ break;
+ }
+ }
+
+ /* we don't need a printf format for iso-10646 because there is only 1 */
+ if (iso10646 == ISO_UNSUPPORTED) {
+ fprintf (stderr, "System doesn't support any ISO-10646-1 formats\n");
+ fprintf (fp, "#define ICONV_10646 \"%s\"\n", info[0].charset);
+#ifdef CONFIGURE_IN
+ exit (2);
+#endif
+ } else {
+ fprintf (fp, "#define ICONV_10646 \"%s\"\n", info[i].charset);
+ }
+
+ fclose (fp);
+
+ exit (0);
+}