aboutsummaryrefslogtreecommitdiff
path: root/src/textadept.c
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2012-06-12 20:34:48 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2012-06-12 20:34:48 -0400
commitd21a96d6ab4228b47a677cebc17d21624ad9b178 (patch)
tree370e11bc15c367ca18a7af37b9bce40462536371 /src/textadept.c
parentbc2a28a07df27893f0303bacd1a6e4caff637f4d (diff)
downloadtextadept-d21a96d6ab4228b47a677cebc17d21624ad9b178.tar.gz
textadept-d21a96d6ab4228b47a677cebc17d21624ad9b178.zip
Identify charset in ncurses; src/textadept.c
Diffstat (limited to 'src/textadept.c')
-rw-r--r--src/textadept.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/textadept.c b/src/textadept.c
index a37471de..9a4a7e3b 100644
--- a/src/textadept.c
+++ b/src/textadept.c
@@ -1475,15 +1475,24 @@ static int lL_init(lua_State *L, int argc, char **argv, int reinit) {
lua_pushboolean(L, 1), lua_setglobal(L, "WIN32");
#elif __OSX__
lua_pushboolean(L, 1), lua_setglobal(L, "OSX");
+#elif NCURSES
+ lua_pushboolean(L, 1), lua_setglobal(L, "NCURSES");
#endif
-#if GTK
const char *charset = 0;
+#if GTK
g_get_charset(&charset);
- lua_pushstring(L, charset), lua_setglobal(L, "_CHARSET");
#elif NCURSES
- lua_pushboolean(L, 1), lua_setglobal(L, "NCURSES");
- lua_pushstring(L, "UTF-8"), lua_setglobal(L, "_CHARSET"); // TODO: get charset
+ charset = getenv("CHARSET");
+ if (!charset || !*charset) {
+ char *locale = getenv("LC_ALL");
+ if (!locale || !*locale) locale = getenv("LANG");
+ if (locale && (charset = strchr(locale, '.'))) charset++;
+ }
+ // Note: __WIN32__ uses GetACP() to determine codepage.
+ // If __WIN32__ is ever supported, use a codepage -> charset look-up table
+ // like glib's `libcharset/localecharset.c`.
#endif
+ lua_pushstring(L, charset), lua_setglobal(L, "_CHARSET");
if (lL_dofile(L, "core/init.lua")) {
lua_getglobal(L, "_SCINTILLA");