Be a little more lenient in locale env.var. testing for UTF-8ness

This commit is contained in:
Paul LeoNerd Evans 2014-03-05 01:23:16 +00:00
parent 8aa5b7acb5
commit 7909067ac0
1 changed files with 8 additions and 1 deletions

View File

@ -6,9 +6,12 @@
#include <poll.h> #include <poll.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <strings.h>
#include <stdio.h> #include <stdio.h>
#define strcaseeq(a,b) (strcasecmp(a,b) == 0)
void termkey_check_version(int major, int minor) void termkey_check_version(int major, int minor)
{ {
if(major != TERMKEY_VERSION_MAJOR) { if(major != TERMKEY_VERSION_MAJOR) {
@ -384,8 +387,12 @@ TermKey *termkey_new(int fd, int flags)
if(!(flags & (TERMKEY_FLAG_RAW|TERMKEY_FLAG_UTF8))) { if(!(flags & (TERMKEY_FLAG_RAW|TERMKEY_FLAG_UTF8))) {
char *e; 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"))) && 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; flags |= TERMKEY_FLAG_UTF8;
else else
flags |= TERMKEY_FLAG_RAW; flags |= TERMKEY_FLAG_RAW;