From fbe0ca3c4a6a4427efcfd700e338df7ad189c6b1 Mon Sep 17 00:00:00 2001 From: ache Date: Tue, 26 Jun 2001 01:43:52 +0000 Subject: Convert to nl_langinfo(CODESET) --- games/morse/morse.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'games/morse/morse.c') diff --git a/games/morse/morse.c b/games/morse/morse.c index 6579e8d..832228d 100644 --- a/games/morse/morse.c +++ b/games/morse/morse.c @@ -54,6 +54,7 @@ static const char rcsid[] = #include #include +#include #include #include #include @@ -228,13 +229,13 @@ tone_t sound; "usage: morse [-s] [-p] [-e] [-d device] [-w speed] [-f frequency] [string ...]\n" #endif -static const struct morsetab *hightab = iso8859tab; +static const struct morsetab *hightab; int main(int argc, char **argv) { int ch, lflags; - char *p; + char *p, *codeset; while ((ch = getopt(argc, argv, GETOPTOPTS)) != -1) switch ((char) ch) { @@ -318,14 +319,14 @@ main(int argc, char **argv) argc -= optind; argv += optind; - if(((p = getenv("LC_ALL")) && *p) || - ((p = getenv("LC_CTYPE")) && *p) || - ((p = getenv("LANG")) && *p)) { - if(strlen(p) >= sizeof(".KOI8-R") && - strcasecmp(&p[strlen(p) + 1 - sizeof(".KOI8-R")], ".KOI8-R") == 0) + if (setlocale(LC_CTYPE, "") != NULL && + *(codeset = nl_langinfo(CODESET)) != '\0') { + if (strcmp(codeset, "KOI8-R") == 0) hightab = koi8rtab; + else if (strcmp(codeset, "ISO8859-1") == 0 || + strcmp(codeset, "ISO8859-15") == 0) + hightab = iso8859tab; } - (void) setlocale(LC_CTYPE, ""); if (*argv) { do { @@ -372,7 +373,7 @@ morse(char c) } } for (m = ((unsigned char)c < 0x80? mtab: hightab); - m->inchar != '\0'; + m != NULL && m->inchar != '\0'; m++) { if (m->inchar == c) { if (pflag) { -- cgit v1.1