From efcc33d442b9510295277204025d661c6e804fda Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Thu, 8 Jun 2000 18:36:13 +0000 Subject: [PATCH] Fix up the value returned by nl_langinfo(CODESET). --- charset.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- charset.h | 4 ++++ init.c | 6 +----- 3 files changed, 58 insertions(+), 6 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 + +/* + * 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) { diff --git a/charset.h b/charset.h index 894cdecd..cac2afae 100644 --- 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 7f0bef29..83a30911 100644 --- a/init.c +++ b/init.c @@ -50,10 +50,6 @@ #include #include -#ifdef HAVE_LANGINFO_CODESET -#include -#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 -- 2.40.0