diff options
author | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2014-03-05 01:23:16 +0000 |
---|---|---|
committer | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2014-03-05 01:23:16 +0000 |
commit | 7909067ac05e885211dafa255da0526543bb87bf (patch) | |
tree | 2d15401753e27b30f5f9f264601499c04cd8d520 | |
parent | 8aa5b7acb59eb815bc32b17dc0335dc7fc129910 (diff) | |
download | termo-7909067ac05e885211dafa255da0526543bb87bf.tar.gz termo-7909067ac05e885211dafa255da0526543bb87bf.tar.xz termo-7909067ac05e885211dafa255da0526543bb87bf.zip |
Be a little more lenient in locale env.var. testing for UTF-8ness
-rw-r--r-- | termkey.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -6,9 +6,12 @@ #include <poll.h> #include <unistd.h> #include <string.h> +#include <strings.h> #include <stdio.h> +#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; |