summaryrefslogtreecommitdiffstats
path: root/charset.c
diff options
context:
space:
mode:
authorThomas Roessler <roessler@does-not-exist.org>2000-06-08 18:36:13 +0000
committerThomas Roessler <roessler@does-not-exist.org>2000-06-08 18:36:13 +0000
commitefcc33d442b9510295277204025d661c6e804fda (patch)
tree2598e1d30ee606841fddab22ae9c86ff6e454572 /charset.c
parent339a10de61a79439154d60643efc738192a9ff90 (diff)
Fix up the value returned by nl_langinfo(CODESET).
Diffstat (limited to 'charset.c')
-rw-r--r--charset.c54
1 files changed, 53 insertions, 1 deletions
diff --git a/charset.c b/charset.c
index e5759368..90088d02 100644
--- a/charset.c
+++ b/charset.c
@@ -35,9 +35,61 @@
#include "charset.h"
#ifndef EILSEQ
-#define EILSEQ EINVAL
+# define EILSEQ EINVAL
#endif
+#ifdef HAVE_LANGINFO_CODESET
+# include <langinfo.h>
+
+/*
+ * Try to convert nl_langinfo's return value to something we can
+ * use for MIME's purposes.
+ *
+ * Note that the algorithm used here is quite different from the
+ * one in mutt_canonical_charset.
+ */
+
+void mutt_set_langinfo_charset (void)
+{
+ char buff[LONG_STRING];
+ char buff2[LONG_STRING];
+ char *s, *d, *cp;
+
+ strfcpy (buff, nl_langinfo (CODESET), sizeof (buff));
+ strfcpy (buff2, buff, sizeof (buff2));
+
+ /* compactify the character set name returned */
+ for (d = s = buff; *s; s++)
+ {
+ if (!strstr ("-_.", *s))
+ *d++ = *s;
+ }
+ *d = '\0';
+
+ /* look for common prefixes which may have been done wrong */
+ if (!strncasecmp (buff, "iso8859", 7))
+ {
+ snprintf (buff2, sizeof (buff2), "iso-8859-%s", buff + 7);
+ if ((cp = strchr (buff2, ':'))) /* strip :yyyy suffixes */
+ *cp = '\0';
+ }
+ else if (!strncasecmp (buff, "koi8", 4))
+ {
+ snprintf (buff2, sizeof (buff2), "koi8-%s", buff + 4);
+ }
+ else if (!strncasecmp (buff, "windows", 7))
+ {
+ snprintf (buff2, sizeof (buff2), "windows-%s" buff + 7);
+ }
+
+ /* fix the spelling */
+ mutt_canonical_charset (buff, sizeof (buff), buff2);
+
+ /* finally, set $charset */
+ Charset = safe_strdup (buff);
+}
+
+#endif
void mutt_canonical_charset (char *dest, size_t dlen, const char *name)
{