2 ** check_charset.c -- routines for character sets
4 ** This code is Copyright (c) 2002, by the authors of nmh. See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
10 #ifdef HAVE_LANGINFO_H
11 # include <langinfo.h>
16 ** Get the current character set
21 char *charset = getenv("MM_CHARSET");
22 #if defined(HAVE_NL_LANGINFO) && defined(CODESET)
24 charset = norm_charmap(nl_langinfo(CODESET));
31 ** Check if we can display a given character set natively.
32 ** We are passed the length of the initial part of the
33 ** string to check, since we want to allow the name of the
34 ** character set to be a substring of a larger string.
38 check_charset(char *str, int len)
40 static char *mm_charset = NULL;
41 static char *alt_charset = NULL;
45 /* Cache the name of our default character set */
47 if (!(mm_charset = get_charset()))
48 mm_charset = "US-ASCII";
49 mm_len = strlen(mm_charset);
51 /* US-ASCII is a subset of the ISO-8859-X and UTF-8 character sets */
52 if (!strncasecmp("ISO-8859-", mm_charset, 9) ||
53 !mh_strcasecmp("UTF-8", mm_charset)) {
54 alt_charset = "US-ASCII";
55 alt_len = strlen(alt_charset);
59 /* Check if character set is OK */
60 if ((len == mm_len) && !strncasecmp(str, mm_charset, mm_len))
62 if (alt_charset && (len == alt_len) && !strncasecmp(str, alt_charset, alt_len))
70 ** Return the name of the character set we are
71 ** using for 8bit text.
74 write_charset_8bit(void)
76 static char *mm_charset = NULL;
79 ** Cache the name of the character set to
82 if (!mm_charset && !(mm_charset = get_charset()))
83 mm_charset = "x-unknown";