]>
diplodocus.org Git - nmh/blob - sbr/check_charset.c
1 /* check_charset.c -- routines for character sets
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
12 /* Only get_charset() should use norm_charmap(), so hide its
14 char *norm_charmap(char *);
17 * Get the current character set
22 return norm_charmap(nl_langinfo (CODESET
));
27 * Check if we can display a given character set natively.
28 * We are passed the length of the initial part of the
29 * string to check, since we want to allow the name of the
30 * character set to be a substring of a larger string.
34 check_charset (char *str
, int len
)
36 static char *mm_charset
= NULL
;
37 static char *alt_charset
= NULL
;
41 /* Cache the name of our default character set */
43 if (!(mm_charset
= get_charset ()))
44 mm_charset
= "US-ASCII";
45 mm_len
= strlen (mm_charset
);
47 /* US-ASCII is a subset of the ISO-8859-X and UTF-8 character sets */
48 if (!strncasecmp("ISO-8859-", mm_charset
, 9) ||
49 !strcasecmp("UTF-8", mm_charset
)) {
50 alt_charset
= "US-ASCII";
51 alt_len
= strlen (alt_charset
);
55 /* Check if character set is OK */
56 if ((len
== mm_len
) && !strncasecmp(str
, mm_charset
, mm_len
))
58 if (alt_charset
&& (len
== alt_len
) && !strncasecmp(str
, alt_charset
, alt_len
))
66 * Return the name of the character set we are
67 * using for 8bit text.
70 write_charset_8bit (void)
72 static char *mm_charset
= NULL
;
75 * Cache the name of the character set to
78 if (!mm_charset
&& !(mm_charset
= get_charset ()))
79 mm_charset
= "x-unknown";