Convert to nl_langinfo(CODESET)
This commit is contained in:
parent
8fce7fd44f
commit
b031f22d4a
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=78793
@ -137,18 +137,20 @@ minor glitch that is generated during program startup.
|
||||
speaker device file
|
||||
.El
|
||||
.Sh ENVIRONMENT
|
||||
.Bl -tag -width LC_CTYPE -compact
|
||||
.It Ev LC_ALL
|
||||
.It Ev LC_CTYPE
|
||||
.It Ev LANG
|
||||
If one of these variables (in this priority) is set to a locale ending in
|
||||
.Pp
|
||||
If your
|
||||
.Ev LC_CTYPE
|
||||
locale codeset is
|
||||
.Ql KOI8-R ,
|
||||
characters with the high-order bit set are being interpreted as
|
||||
Cyrillic characters. In all other cases, they are being interpreted
|
||||
Cyrillic characters. If your
|
||||
.Ev LC_CTYPE
|
||||
locale codeset is
|
||||
.Ql ISO8859-1
|
||||
compatible, they are being interpreted
|
||||
as belonging to the
|
||||
.Ql ISO-8859-1
|
||||
character set.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr speaker 4
|
||||
.Sh HISTORY
|
||||
|
@ -54,6 +54,7 @@ static const char rcsid[] =
|
||||
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <langinfo.h>
|
||||
#include <locale.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user