BSD 4_3_Reno release
[unix-history] / usr / src / usr.bin / finger / lprint.c
index 284aaed..3bb77d5 100644 (file)
@@ -5,21 +5,23 @@
  * This code is derived from software contributed to Berkeley by
  * Tony Nardo of the Johns Hopkins University/Applied Physics Lab.
  *
  * This code is derived from software contributed to Berkeley by
  * Tony Nardo of the Johns Hopkins University/Applied Physics Lab.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms are permitted provided
+ * that: (1) source distributions retain this entire copyright notice and
+ * comment, and (2) distributions including binaries display the following
+ * acknowledgement:  ``This product includes software developed by the
+ * University of California, Berkeley and its contributors'' in the
+ * documentation or other materials provided with the distribution and in
+ * all advertising materials mentioning features or use of this software.
+ * Neither the name of the University nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)lprint.c   5.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)lprint.c   5.12 (Berkeley) 6/24/90";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -28,8 +30,9 @@ static char sccsid[] = "@(#)lprint.c  5.2 (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 <paths.h>
 #include "finger.h"
 #include "finger.h"
-#include "pathnames.h"
 
 #define        LINE_LEN        80
 #define        TAB_LEN         8               /* 8 spaces between tabs */
 
 #define        LINE_LEN        80
 #define        TAB_LEN         8               /* 8 spaces between tabs */
@@ -61,9 +64,10 @@ lprint(pn)
        register struct tm *delta;
        register WHERE *w;
        register int cpr, len, maxlen;
        register struct tm *delta;
        register WHERE *w;
        register int cpr, len, maxlen;
+       struct tm *tp;
        int oddfield;
        time_t time();
        int oddfield;
        time_t time();
-       char *t, *ctime();
+       char *t, *tzn, *prphone();
 
        /*
         * long format --
 
        /*
         * long format --
@@ -88,7 +92,7 @@ lprint(pn)
            strlen(pn->office) + strlen(pn->officephone) +
            sizeof(OFFICE_TAG) + 2 <= 5 * TAB_LEN) {
                (void)sprintf(tbuf, "%s: %s, %s", OFFICE_TAG, pn->office,
            strlen(pn->office) + strlen(pn->officephone) +
            sizeof(OFFICE_TAG) + 2 <= 5 * TAB_LEN) {
                (void)sprintf(tbuf, "%s: %s, %s", OFFICE_TAG, pn->office,
-                   pn->officephone);
+                   prphone(pn->officephone));
                oddfield = demi_print(tbuf, oddfield);
        } else {
                if (pn->office) {
                oddfield = demi_print(tbuf, oddfield);
        } else {
                if (pn->office) {
@@ -97,12 +101,13 @@ lprint(pn)
                }
                if (pn->officephone) {
                        (void)sprintf(tbuf, "%s: %s", OFFICE_PHONE_TAG,
                }
                if (pn->officephone) {
                        (void)sprintf(tbuf, "%s: %s", OFFICE_PHONE_TAG,
-                           pn->officephone);
+                           prphone(pn->officephone));
                        oddfield = demi_print(tbuf, oddfield);
                }
        }
        if (pn->homephone) {
                        oddfield = demi_print(tbuf, oddfield);
                }
        }
        if (pn->homephone) {
-               (void)sprintf(tbuf, "%s: %s", "Home Phone", pn->homephone);
+               (void)sprintf(tbuf, "%s: %s", "Home Phone",
+                   prphone(pn->homephone));
                oddfield = demi_print(tbuf, oddfield);
        }
        if (oddfield)
                oddfield = demi_print(tbuf, oddfield);
        }
        if (oddfield)
@@ -118,15 +123,18 @@ lprint(pn)
         *      when last logged in
         */
        /* find out longest device name for this user for formatting */
         *      when last logged in
         */
        /* find out longest device name for this user for formatting */
-       for (w = pn->whead; w != NULL; w = w->next)
+       for (w = pn->whead, maxlen = -1; w != NULL; w = w->next)
                if ((len = strlen(w->tty)) > maxlen)
                        maxlen = len;
        /* find rest of entries for user */
        for (w = pn->whead; w != NULL; w = w->next) {
                switch (w->info) {
                case LOGGEDIN:
                if ((len = strlen(w->tty)) > maxlen)
                        maxlen = len;
        /* find rest of entries for user */
        for (w = pn->whead; w != NULL; w = w->next) {
                switch (w->info) {
                case LOGGEDIN:
-                       cpr = printf("On since %16.16s on %s",
-                           ctime(&w->loginat), w->tty);
+                       tp = localtime(&w->loginat);
+                       t = asctime(tp);
+                       tzn = tp->tm_zone;
+                       cpr = printf("On since %16.16s (%s) on %s",
+                           t, tzn, w->tty);
                        /*
                         * idle time is tough; if have one, print a comma,
                         * then spaces to pad out the device name, then the
                        /*
                         * idle time is tough; if have one, print a comma,
                         * then spaces to pad out the device name, then the
@@ -156,13 +164,15 @@ lprint(pn)
                                (void)printf("Never logged in.");
                                break;
                        }
                                (void)printf("Never logged in.");
                                break;
                        }
-                       t = ctime(&w->loginat);
+                       tp = localtime(&w->loginat);
+                       t = asctime(tp);
+                       tzn = tp->tm_zone;
                        if (now - w->loginat > SECSPERDAY * DAYSPERNYEAR / 2)
                        if (now - w->loginat > SECSPERDAY * DAYSPERNYEAR / 2)
-                               cpr = printf("Last login %10.10s, %4.4s on %s",
-                                   t, t + 20, w->tty);
+                               cpr = printf("Last login %10.10s (%s), %4.4s on %s",
+                                   t, t + 20, tzn, w->tty);
                        else
                        else
-                               cpr = printf("Last login %16.16s on %s",
-                                       t, w->tty);
+                               cpr = printf("Last login %16.16s (%s) on %s",
+                                   t, tzn, w->tty);
                        break;
                }
                if (*w->host) {
                        break;
                }
                if (*w->host) {
@@ -172,11 +182,6 @@ lprint(pn)
                }
                putchar('\n');
        }
                }
                putchar('\n');
        }
-       /*
-        * long format con't:
-        *      mail status
-        */
-       chkmail(pn);
 }
 
 demi_print(str, oddfield)
 }
 
 demi_print(str, oddfield)
@@ -221,50 +226,37 @@ 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, lastc;
+       register FILE *fp;
 
        (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 ((fp = fopen(tbuf, "r")) == NULL)
                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 = getc(fp)) != EOF)
+               vputc(lastc = ch);
+       if (lastc != '\n')
+               (void)putchar('\n');
+       (void)fclose(fp);
        return(1);
 }
 
        return(1);
 }
 
-chkmail(pn)
-       PERSON *pn;
+vputc(ch)
+       register int ch;
 {
 {
-       register char *date;
-       struct stat sb;
+       int meta;
 
 
-       /*
-        * build path of user's mail box and get stats; if missing
-        * or empty, no mail.
-        */
-       (void)sprintf(tbuf, "%s/%s", _PATH_MAILDIR, pn->name);
-       if (stat(tbuf, &sb) < 0 || !sb.st_size) {
-               (void)printf("No unread mail.\n");
-               return;
-       }
-
-       /*
-        * if access time matches the modification time then we know
-        * that new mail was received but we haven't a clue as to when
-        * it was last read.
-        */
-       date = ctime(&sb.st_ctime);
-       if (sb.st_atime == sb.st_ctime)
-               (void)printf("New mail received %16.16s.\n", date);
-       else if (sb.st_atime > sb.st_ctime) {
-               date = ctime(&sb.st_atime);
-               (void)printf("No new mail, last read %16.16s.\n", date);
-       } else {
-               (void)printf("Mail received %16.16s; ", date);
-               date = ctime(&sb.st_atime);
-               (void)printf("last read %16.16s.\n", date);
+       if (!isascii(ch)) {
+               (void)putchar('M');
+               (void)putchar('-');
+               ch = toascii(ch);
+               meta = 1;
+       } else
+               meta = 0;
+       if (isprint(ch) || !meta && (ch == ' ' || ch == '\t' || ch == '\n'))
+               (void)putchar(ch);
+       else {
+               (void)putchar('^');
+               (void)putchar(ch == '\177' ? '?' : ch | 0100);
        }
 }
        }
 }