From 7909067ac05e885211dafa255da0526543bb87bf Mon Sep 17 00:00:00 2001 From: Paul LeoNerd Evans Date: Wed, 5 Mar 2014 01:23:16 +0000 Subject: Be a little more lenient in locale env.var. testing for UTF-8ness --- termkey.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/termkey.c b/termkey.c index 8a73683..db084cc 100644 --- a/termkey.c +++ b/termkey.c @@ -6,9 +6,12 @@ #include #include #include +#include #include +#define strcaseeq(a,b) (strcasecmp(a,b) == 0) + void termkey_check_version(int major, int minor) { if(major != TERMKEY_VERSION_MAJOR) { @@ -384,8 +387,12 @@ TermKey *termkey_new(int fd, int flags) if(!(flags & (TERMKEY_FLAG_RAW|TERMKEY_FLAG_UTF8))) { char *e; + /* Most OSes will set .UTF-8. Some will set .utf8. Try to be fairly + * generous in parsing these + */ if(((e = getenv("LANG")) || (e = getenv("LC_MESSAGES")) || (e = getenv("LC_ALL"))) && - (strstr(e, ".UTF-8") || strstr(e, ".utf8"))) + (e = strchr(e, '.')) && e++ && + (strcaseeq(e, "UTF-8") || strcaseeq(e, "UTF8"))) flags |= TERMKEY_FLAG_UTF8; else flags |= TERMKEY_FLAG_RAW; -- cgit v1.2.3-70-g09d2