aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2014-03-05 01:23:16 +0000
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2014-03-05 01:23:16 +0000
commit7909067ac05e885211dafa255da0526543bb87bf (patch)
tree2d15401753e27b30f5f9f264601499c04cd8d520
parent8aa5b7acb59eb815bc32b17dc0335dc7fc129910 (diff)
downloadtermo-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.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/termkey.c b/termkey.c
index 8a73683..db084cc 100644
--- a/termkey.c
+++ b/termkey.c
@@ -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;