]> granicus.if.org Git - neomutt/commitdiff
Fix up the value returned by nl_langinfo(CODESET).
authorThomas Roessler <roessler@does-not-exist.org>
Thu, 8 Jun 2000 18:36:13 +0000 (18:36 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Thu, 8 Jun 2000 18:36:13 +0000 (18:36 +0000)
charset.c
charset.h
init.c

index e575936828009fbad80035c9bb245304ab29d38e..90088d02c6526d9fd1f9417d7c52126f38a2f08f 100644 (file)
--- a/charset.c
+++ b/charset.c
 #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)
 {
index 894cdecd37ffea3f1fd60426446738332fd2717a..cac2afae74325f016849852d771c9ed197496457 100644 (file)
--- a/charset.h
+++ b/charset.h
@@ -66,4 +66,8 @@ FGETCONV *fgetconv_open (FILE *, const char *, const char *);
 int fgetconv (FGETCONV *);
 void fgetconv_close (FGETCONV *);
 
+#ifdef HAVE_LANGINFO_CODESET
+void mutt_set_langinfo_charset (void);
+#endif
+
 #endif /* _CHARSET_H */
diff --git a/init.c b/init.c
index 7f0bef29d871fa428e08543d694f29adc7e2e2c5..83a30911d5edec599025020a6b57a1803c8f47b1 100644 (file)
--- a/init.c
+++ b/init.c
 #include <errno.h>
 #include <sys/wait.h>
 
-#ifdef HAVE_LANGINFO_CODESET
-#include <langinfo.h>
-#endif
-
 void toggle_quadoption (int opt)
 {
   int n = opt/4;
@@ -1814,7 +1810,7 @@ void mutt_init (int skip_sys_rc, LIST *commands)
   }
 
 #ifdef HAVE_LANGINFO_CODESET
-  Charset = safe_strdup (nl_langinfo (CODESET));
+  mutt_set_langinfo_charset ();
 #else
   Charset = safe_strdup ("iso-8859-1");
 #endif