Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/finger Obey the locale settings of the user when dec...



details:   https://anonhg.NetBSD.org/src/rev/b58b110d37a9
branches:  trunk
changeset: 535105:b58b110d37a9
user:      kim <kim%NetBSD.org@localhost>
date:      Sat Aug 10 16:10:46 2002 +0000

description:
Obey the locale settings of the user when deciding what characters are
valid for output.  If something bad gets printed, either the locale
settings for the user (or output terminal) are wrong, or the LC_CTYPE
definitions on the system are invalid.

diffstat:

 usr.bin/finger/finger.c |   9 +++++++--
 usr.bin/finger/net.c    |  20 ++++++++++----------
 2 files changed, 17 insertions(+), 12 deletions(-)

diffs (89 lines):

diff -r 010ef4b4acd5 -r b58b110d37a9 usr.bin/finger/finger.c
--- a/usr.bin/finger/finger.c   Sat Aug 10 09:42:23 2002 +0000
+++ b/usr.bin/finger/finger.c   Sat Aug 10 16:10:46 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: finger.c,v 1.17 2002/08/05 08:04:03 tron Exp $ */
+/*     $NetBSD: finger.c,v 1.18 2002/08/10 16:10:46 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.17 2002/08/05 08:04:03 tron Exp $");
+__RCSID("$NetBSD: finger.c,v 1.18 2002/08/10 16:10:46 kim Exp $");
 #endif
 #endif /* not lint */
 
@@ -87,6 +87,8 @@
 #include <time.h>
 #include <unistd.h>
 
+#include <locale.h>
+
 #include "utmpentry.h"
 
 #include "finger.h"
@@ -109,6 +111,9 @@
 {
        int ch;
 
+       /* Allow user's locale settings to affect character output. */
+       (void *) setlocale(LC_CTYPE, "");
+
        oflag = 1;              /* default to old "office" behavior */
 
        while ((ch = getopt(argc, argv, "lmpshog")) != -1)
diff -r 010ef4b4acd5 -r b58b110d37a9 usr.bin/finger/net.c
--- a/usr.bin/finger/net.c      Sat Aug 10 09:42:23 2002 +0000
+++ b/usr.bin/finger/net.c      Sat Aug 10 16:10:46 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: net.c,v 1.15 2002/08/02 00:10:40 christos Exp $        */
+/*     $NetBSD: net.c,v 1.16 2002/08/10 16:10:46 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.15 2002/08/02 00:10:40 christos Exp $");
+__RCSID("$NetBSD: net.c,v 1.16 2002/08/10 16:10:46 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