Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/finger Add back locale support for data display.



details:   https://anonhg.NetBSD.org/src/rev/7224eb719969
branches:  trunk
changeset: 536164:7224eb719969
user:      kim <kim%NetBSD.org@localhost>
date:      Tue Sep 10 03:02:40 2002 +0000

description:
Add back locale support for data display.

We only enable 8-bit output for known single-byte locales, currently
ISO8859-*.  For all other locales the program output is unchanged.

RFC-1288 recommends that administrators have a mechanism to enable
characters greater than ASCII 126.  A suggested solution is an
environment variable.  The environment variables of choice here are
LC_CTYPE and LANG.

Thanks to Martin Husemann <martin%duskware.de@localhost> for the idea on checking
for known single-byte locales, to Johan Danielsson <joda%pdc.kth.se@localhost> for
checking RFC-1288, and to Jun-ichiro itojun Hagino <itojun%iijlab.net@localhost>
for insisting on retaining security for multi-byte locales.

If you experience any problems with these changes, please send me email
describing the problem and how to repeat it.  I'd rather try to fix the
problem than have this change reverted.  Thanks!

diffstat:

 usr.bin/finger/finger.c |  17 +++++++++++++++--
 usr.bin/finger/lprint.c |  10 +++++++---
 usr.bin/finger/net.c    |  20 ++++++++++----------
 3 files changed, 32 insertions(+), 15 deletions(-)

diffs (135 lines):

diff -r 5779244992e7 -r 7224eb719969 usr.bin/finger/finger.c
--- a/usr.bin/finger/finger.c   Tue Sep 10 02:52:40 2002 +0000
+++ b/usr.bin/finger/finger.c   Tue Sep 10 03:02:40 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: finger.c,v 1.19 2002/08/20 00:27:59 itojun Exp $       */
+/*     $NetBSD: finger.c,v 1.20 2002/09/10 03:02:40 kim Exp $  */
 
 /*
  * Copyright (c) 1989, 1993
@@ -56,7 +56,7 @@
 #if 0
 static char sccsid[] = "@(#)finger.c   8.5 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: finger.c,v 1.19 2002/08/20 00:27:59 itojun Exp $");
+__RCSID("$NetBSD: finger.c,v 1.20 2002/09/10 03:02:40 kim Exp $");
 #endif
 #endif /* not lint */
 
@@ -87,6 +87,9 @@
 #include <time.h>
 #include <unistd.h>
 
+#include <locale.h>
+#include <langinfo.h>
+
 #include "utmpentry.h"
 
 #include "finger.h"
@@ -109,6 +112,16 @@
 {
        int ch;
 
+       /* Allow user's locale settings to affect character output. */
+       (void *) setlocale(LC_CTYPE, "");
+
+       /*
+        * Reset back to the C locale, unless we are using a known
+        * single-byte 8-bit locale.
+        */
+       if (strncmp(nl_langinfo(CODESET), "ISO8859-", 8))
+           (void *) setlocale(LC_CTYPE, "C");
+
        oflag = 1;              /* default to old "office" behavior */
 
        while ((ch = getopt(argc, argv, "lmpshog")) != -1)
diff -r 5779244992e7 -r 7224eb719969 usr.bin/finger/lprint.c
--- a/usr.bin/finger/lprint.c   Tue Sep 10 02:52:40 2002 +0000
+++ b/usr.bin/finger/lprint.c   Tue Sep 10 03:02:40 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lprint.c,v 1.16 2002/08/20 00:27:59 itojun Exp $       */
+/*     $NetBSD: lprint.c,v 1.17 2002/09/10 03:02:40 kim Exp $  */
 
 /*
  * Copyright (c) 1989, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)lprint.c   8.3 (Berkeley) 4/28/95";
 #else
-__RCSID( "$NetBSD: lprint.c,v 1.16 2002/08/20 00:27:59 itojun Exp $");
+__RCSID( "$NetBSD: lprint.c,v 1.17 2002/09/10 03:02:40 kim Exp $");
 #endif
 #endif /* not lint */
 
@@ -338,7 +338,7 @@
                if (cnt <= 1) {
                        (void)printf("%s: ", header);
                        for (p = tbuf, cnt = nr; cnt--; ++p)
-                               vputc(lastc = *p);
+                               vputc(lastc = (unsigned char)*p);
                        if (lastc != '\n')
                                (void)putchar('\n');
                        (void)close(fd);
@@ -364,6 +364,10 @@
 {
        char visout[5], *s2;
 
+       if ((isprint(ch)) || (isspace(ch))) {
+           (void)putchar(ch);
+           return;
+       }
        ch = toascii(ch);
        vis(visout, ch, VIS_SAFE|VIS_NOSLASH, 0);
        for (s2 = visout; *s2; s2++)
diff -r 5779244992e7 -r 7224eb719969 usr.bin/finger/net.c
--- a/usr.bin/finger/net.c      Tue Sep 10 02:52:40 2002 +0000
+++ b/usr.bin/finger/net.c      Tue Sep 10 03:02:40 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: net.c,v 1.17 2002/08/20 00:28:00 itojun Exp $  */
+/*     $NetBSD: net.c,v 1.18 2002/09/10 03:02:40 kim Exp $     */
 
 /*
  * Copyright (c) 1989, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)net.c      8.4 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: net.c,v 1.17 2002/08/20 00:28:00 itojun Exp $");
+__RCSID("$NetBSD: net.c,v 1.18 2002/09/10 03:02:40 kim Exp $");
 #endif
 #endif /* not lint */
 
@@ -131,25 +131,25 @@
         * Read from the remote system; once we're connected, we assume some
         * data.  If none arrives, we hang until the user interrupts.
         *
-        * If we see a <CR> or a <CR> with the high bit set, treat it as
-        * a newline; if followed by a newline character, only output one
-        * newline.
+        * If we see a <CR> followed by a newline character, only output
+        * one newline.
         *
-        * Otherwise, all high bits are stripped; if it isn't printable and
-        * it isn't a space, we can simply set the 7th bit.  Every ASCII
-        * character with bit 7 set is printable.
+        * If a character isn't printable and it isn't a space, we strip the
+        * 8th bit and set the 7th bit.  Every ASCII character with bit 7 set
+        * is printable.
         */
        if ((fp = fdopen(s, "r")) != NULL)
                while ((c = getc(fp)) != EOF) {
-                       c &= 0x7f;
                        if (c == '\r') {
                                if (lastc == '\r')      /* ^M^M - skip dupes */
                                        continue;
                                c = '\n';
                                lastc = '\r';
                        } else {
-                               if (!isprint(c) && !isspace(c))
+                               if (!isprint(c) && !isspace(c)) {
+                                       c &= 0x7f;
                                        c |= 0x40;
+                               }
                                if (lastc != '\r' || c != '\n')
                                        lastc = c;
                                else {



Home | Main Index | Thread Index | Old Index