don't display meta/control chars; bug report 4.3BSD/usr.bin/213
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Fri, 1 Sep 1989 23:57:38 +0000 (15:57 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Fri, 1 Sep 1989 23:57:38 +0000 (15:57 -0800)
SCCS-vsn: usr.bin/finger/finger.c 5.18
SCCS-vsn: usr.bin/finger/lprint.c 5.6

usr/src/usr.bin/finger/finger.c
usr/src/usr.bin/finger/lprint.c

index 8a3be81..135446a 100644 (file)
@@ -22,7 +22,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)finger.c   5.17 (Berkeley) %G%";
+static char sccsid[] = "@(#)finger.c   5.18 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -114,17 +114,16 @@ main(argc, argv)
 loginlist()
 {
        register PERSON *pn;
 loginlist()
 {
        register PERSON *pn;
-       FILE *fp;
        struct passwd *pw;
        struct utmp user;
        char name[UT_NAMESIZE + 1];
 
        struct passwd *pw;
        struct utmp user;
        char name[UT_NAMESIZE + 1];
 
-       if ((fp = fopen(_PATH_UTMP, "r")) == NULL) {
+       if (!freopen(_PATH_UTMP, "r", stdin)) {
                (void)fprintf(stderr, "finger: can't read %s.\n", _PATH_UTMP);
                exit(2);
        }
        name[UT_NAMESIZE] = NULL;
                (void)fprintf(stderr, "finger: can't read %s.\n", _PATH_UTMP);
                exit(2);
        }
        name[UT_NAMESIZE] = NULL;
-       while (fread((char *)&user, sizeof(user), 1, fp) == 1) {
+       while (fread((char *)&user, sizeof(user), 1, stdin) == 1) {
                if (!user.ut_name[0])
                        continue;
                if ((pn = find_person(user.ut_name)) == NULL) {
                if (!user.ut_name[0])
                        continue;
                if ((pn = find_person(user.ut_name)) == NULL) {
@@ -135,7 +134,6 @@ loginlist()
                }
                enter_where(&user, pn);
        }
                }
                enter_where(&user, pn);
        }
-       (void)fclose(fp);
        for (pn = phead; lflag && pn != NULL; pn = pn->next)
                enter_lastlog(pn);
 }
        for (pn = phead; lflag && pn != NULL; pn = pn->next)
                enter_lastlog(pn);
 }
@@ -150,7 +148,6 @@ userlist(argc, argv)
        struct utmp user;
        struct passwd *pw;
        int dolocal, *used;
        struct utmp user;
        struct passwd *pw;
        int dolocal, *used;
-       FILE *fp;
        char *index();
 
        if (!(used = (int *)calloc((u_int)argc, (u_int)sizeof(int)))) {
        char *index();
 
        if (!(used = (int *)calloc((u_int)argc, (u_int)sizeof(int)))) {
@@ -213,18 +210,17 @@ net:      for (pn = nethead; pn; pn = pn->next) {
         * Scan thru the list of users currently logged in, saving
         * appropriate data whenever a match occurs.
         */
         * Scan thru the list of users currently logged in, saving
         * appropriate data whenever a match occurs.
         */
-       if ((fp = fopen(_PATH_UTMP, "r")) == NULL) {
+       if (!freopen(_PATH_UTMP, "r", stdin)) {
                (void)fprintf( stderr, "finger: can't read %s.\n", _PATH_UTMP);
                exit(1);
        }
                (void)fprintf( stderr, "finger: can't read %s.\n", _PATH_UTMP);
                exit(1);
        }
-       while (fread((char *)&user, sizeof(user), 1, fp) == 1) {
+       while (fread((char *)&user, sizeof(user), 1, stdin) == 1) {
                if (!user.ut_name[0])
                        continue;
                if ((pn = find_person(user.ut_name)) == NULL)
                        continue;
                enter_where(&user, pn);
        }
                if (!user.ut_name[0])
                        continue;
                if ((pn = find_person(user.ut_name)) == NULL)
                        continue;
                enter_where(&user, pn);
        }
-       (void)fclose(fp);
        for (pn = phead; pn != NULL; pn = pn->next)
                enter_lastlog(pn);
 }
        for (pn = phead; pn != NULL; pn = pn->next)
                enter_lastlog(pn);
 }
index 7ff1c8d..9c290b4 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)lprint.c   5.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)lprint.c   5.6 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -25,6 +25,7 @@ static char sccsid[] = "@(#)lprint.c  5.5 (Berkeley) %G%";
 #include <sys/time.h>
 #include <tzfile.h>
 #include <stdio.h>
 #include <sys/time.h>
 #include <tzfile.h>
 #include <stdio.h>
+#include <ctype.h>
 #include "finger.h"
 #include "pathnames.h"
 
 #include "finger.h"
 #include "pathnames.h"
 
@@ -214,16 +215,35 @@ demi_print(str, oddfield)
 show_text(directory, file_name, header)
        char *directory, *file_name, *header;
 {
 show_text(directory, file_name, header)
        char *directory, *file_name, *header;
 {
-       register int fd, n;
+       register int ch;
 
        (void)sprintf(tbuf, "%s/%s", directory, file_name);
 
        (void)sprintf(tbuf, "%s/%s", directory, file_name);
-       if ((fd = open(tbuf, O_RDONLY, 0)) < 0)
+       if (!freopen(tbuf, "r", stdin))
                return(0);
        (void)printf("%s\n", header);
                return(0);
        (void)printf("%s\n", header);
-       (void)fflush(stdout);
-       while ((n = read(fd, tbuf, sizeof(tbuf))) > 0)
-               if (write(1, tbuf, n) != n)
-                       break;
-       (void)close(fd);
+       while ((ch = getchar(fp)) != EOF)
+               vputc(ch);
+       if (ch != '\n')
+               (void)putchar('\n');
        return(1);
 }
        return(1);
 }
+
+vputc(ch)
+       register int ch;
+{
+       int meta;
+
+       if (!isascii(ch)) {
+               (void)putchar('M');
+               (void)putchar('-');
+               ch = toascii(ch);
+               meta = 1;
+       } else
+               meta = 0;
+       if (isprint(ch) || !meta && isspace(ch))
+               (void)putchar(ch);
+       else {
+               (void)putchar('^');
+               (void)putchar(ch == '\177' ? '?' : ch | 0100);
+       }
+}