Commit efcc33d4 authored by Thomas Roessler's avatar Thomas Roessler

Fix up the value returned by nl_langinfo(CODESET).

parent 339a10de
......@@ -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)
{
......
......@@ -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 */
......@@ -50,10 +50,6 @@
#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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment