35#include "ruby/missing.h"
38#if defined _WIN32 || defined __CYGWIN__
40#if defined _WIN32 && !defined strncasecmp
41#define strncasecmp strnicmp
48#define C_CODESET "US-ASCII"
52#if defined _WIN32 || defined __CYGWIN__
53#define JA_CODESET "Windows-31J"
55#define JA_CODESET "EUC-JP"
58#define digit(x) ((x) >= '0' && (x) <= '9')
59#define strstart(s, n) (strncasecmp((s), (n), strlen(n)) == 0)
64nl_langinfo_codeset(
void)
69 if (((l = getenv(
"LC_ALL")) && *l) ||
70 ((l = getenv(
"LC_CTYPE")) && *l) ||
71 ((l = getenv(
"LANG")) && *l)) {
73 if (!strcmp(l,
"C") || !strcmp(l,
"POSIX"))
78 if (strstart(p,
"UTF"))
80 if ((n = 5, strstart(p,
"8859-")) || (n = 9, strstart(p,
"ISO-8859-"))) {
83 memcpy(buf,
"ISO-8859-\0\0", 12);
85 if (digit(*p)) buf[10] = *p++;
89 if (strstart(p,
"KOI8-R"))
return "KOI8-R";
90 if (strstart(p,
"KOI8-U"))
return "KOI8-U";
91 if (strstart(p,
"620"))
return "TIS-620";
92 if (strstart(p,
"2312"))
return "GB2312";
93 if (strstart(p,
"HKSCS"))
return "Big5HKSCS";
94 if (strstart(p,
"BIG5"))
return "Big5";
95 if (strstart(p,
"GBK"))
return "GBK";
96 if (strstart(p,
"18030"))
return "GB18030";
97 if (strstart(p,
"Shift_JIS") || strstart(p,
"SJIS"))
return "Windows-31J";
99 if (strstart(p,
"euro"))
return "ISO-8859-15";
101 if (strstart(l,
"zh_TW"))
return "Big5";
102 if (strstart(l,
"zh_HK"))
return "Big5HKSCS";
103 if (strstart(l,
"zh"))
return "GB2312";
104 if (strstart(l,
"ja"))
return JA_CODESET;
105 if (strstart(l,
"ko"))
return "EUC-KR";
106 if (strstart(l,
"ru"))
return "KOI8-R";
107 if (strstart(l,
"uk"))
return "KOI8-U";
108 if (strstart(l,
"pl") || strstart(l,
"hr") ||
109 strstart(l,
"hu") || strstart(l,
"cs") ||
110 strstart(l,
"sk") || strstart(l,
"sl"))
return "ISO-8859-2";
111 if (strstart(l,
"eo") || strstart(l,
"mt"))
return "ISO-8859-3";
112 if (strstart(l,
"el"))
return "ISO-8859-7";
113 if (strstart(l,
"he"))
return "ISO-8859-8";
114 if (strstart(l,
"tr"))
return "ISO-8859-9";
115 if (strstart(l,
"th"))
return "TIS-620";
116 if (strstart(l,
"lt"))
return "ISO-8859-13";
117 if (strstart(l,
"cy"))
return "ISO-8859-14";
118 if (strstart(l,
"ro"))
return "ISO-8859-2";
119 if (strstart(l,
"am") || strstart(l,
"vi"))
return "UTF-8";
127#ifdef HAVE_LANGINFO_H
128char *nl_langinfo(nl_item item)
133 codeset = nl_langinfo_codeset();
134 if (!codeset) codeset = C_CODESET;
135 return (
char *)codeset;
145 printf(
"%s\n", nl_langinfo(CODESET));