BSD 4_3_Reno release
[unix-history] / usr / src / usr.bin / finger / lprint.c
index 8ab7043..3bb77d5 100644 (file)
@@ -2,21 +2,26 @@
  * Copyright (c) 1989 The Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1989 The Regents of the University of California.
  * All rights reserved.
  *
- * 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.
+ * 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: (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.7 (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>
@@ -26,8 +31,8 @@ static char sccsid[] = "@(#)lprint.c  5.7 (Berkeley) %G%";
 #include <tzfile.h>
 #include <stdio.h>
 #include <ctype.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 */
@@ -59,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(), *prphone();
+       char *t, *tzn, *prphone();
 
        /*
         * long format --
 
        /*
         * long format --
@@ -124,8 +130,11 @@ lprint(pn)
        for (w = pn->whead; w != NULL; w = w->next) {
                switch (w->info) {
                case LOGGEDIN:
        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
@@ -155,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) {
@@ -215,16 +226,18 @@ 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 ch;
+       register int ch, lastc;
+       register FILE *fp;
 
        (void)sprintf(tbuf, "%s/%s", directory, file_name);
 
        (void)sprintf(tbuf, "%s/%s", directory, file_name);
-       if (!freopen(tbuf, "r", stdin))
+       if ((fp = fopen(tbuf, "r")) == NULL)
                return(0);
        (void)printf("%s\n", header);
                return(0);
        (void)printf("%s\n", header);
-       while ((ch = getchar(fp)) != EOF)
-               vputc(ch);
-       if (ch != '\n')
+       while ((ch = getc(fp)) != EOF)
+               vputc(lastc = ch);
+       if (lastc != '\n')
                (void)putchar('\n');
                (void)putchar('\n');
+       (void)fclose(fp);
        return(1);
 }
 
        return(1);
 }