home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / TCPIP / NETKIT-B.05 / NETKIT-B / NetKit-B-0.05 / finger / sprint.c,v < prev    next >
Encoding:
Text File  |  1994-05-23  |  5.0 KB  |  186 lines

  1. head    1.1;
  2. access;
  3. symbols;
  4. locks
  5.     rzsfl:1.1; strict;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.1
  10. date    94.05.23.09.03.29;    author rzsfl;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @Original
  17. @
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/*
  26.  * Copyright (c) 1989 The Regents of the University of California.
  27.  * All rights reserved.
  28.  *
  29.  * This code is derived from software contributed to Berkeley by
  30.  * Tony Nardo of the Johns Hopkins University/Applied Physics Lab.
  31.  *
  32.  * Redistribution and use in source and binary forms, with or without
  33.  * modification, are permitted provided that the following conditions
  34.  * are met:
  35.  * 1. Redistributions of source code must retain the above copyright
  36.  *    notice, this list of conditions and the following disclaimer.
  37.  * 2. Redistributions in binary form must reproduce the above copyright
  38.  *    notice, this list of conditions and the following disclaimer in the
  39.  *    documentation and/or other materials provided with the distribution.
  40.  * 3. All advertising materials mentioning features or use of this software
  41.  *    must display the following acknowledgement:
  42.  *    This product includes software developed by the University of
  43.  *    California, Berkeley and its contributors.
  44.  * 4. Neither the name of the University nor the names of its contributors
  45.  *    may be used to endorse or promote products derived from this software
  46.  *    without specific prior written permission.
  47.  *
  48.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  49.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  51.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  52.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  53.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  54.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  55.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  56.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  57.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  58.  * SUCH DAMAGE.
  59.  */
  60.  
  61. #ifndef lint
  62. /*static char sccsid[] = "from: @@(#)sprint.c    5.8 (Berkeley) 12/4/90";*/
  63. static char rcsid[] = "$Id: sprint.c,v 1.3 1993/10/26 20:54:41 mycroft Exp $";
  64. #endif /* not lint */
  65.  
  66. #include <sys/types.h>
  67. #include <sys/time.h>
  68. #include <tzfile.h>
  69. #include <stdio.h>
  70. #include "finger.h"
  71.  
  72. extern int entries;
  73.  
  74. sflag_print()
  75. {
  76.     extern time_t now;
  77.     register PERSON *pn;
  78.     register WHERE *w;
  79.     register int cnt;
  80.     register char *p;
  81.     PERSON **list, **sort();
  82.     time_t time();
  83.     char *ctime(), *prphone();
  84.  
  85.     list = sort();
  86.     /*
  87.      * short format --
  88.      *    login name
  89.      *    real name
  90.      *    terminal name (the XX of ttyXX)
  91.      *    if terminal writeable (add an '*' to the terminal name
  92.      *        if not)
  93.      *    if logged in show idle time and day logged in, else
  94.      *        show last login date and time.  If > 6 moths,
  95.      *        show year instead of time.
  96.      *    office location
  97.      *    office phone
  98.      */
  99. #define    MAXREALNAME    20
  100.     (void)printf("%-*s %-*s %s\n", UT_NAMESIZE, "Login", MAXREALNAME,
  101.         "Name", "Tty  Idle  Login Time   Office     Office Phone");
  102.     for (cnt = 0; cnt < entries; ++cnt) {
  103.         pn = list[cnt];
  104.         for (w = pn->whead; w != NULL; w = w->next) {
  105.             (void)printf("%-*.*s %-*.*s ", UT_NAMESIZE, UT_NAMESIZE,
  106.                 pn->name, MAXREALNAME, MAXREALNAME,
  107.                 pn->realname ? pn->realname : "");
  108.             if (!w->loginat) {
  109.                 (void)printf("  *     *  No logins   ");
  110.                 goto office;
  111.             }
  112.             (void)putchar(w->info == LOGGEDIN && !w->writable ?
  113.                 '*' : ' ');
  114.             if (*w->tty)
  115.                 (void)printf("%-2.2s ",
  116.                     w->tty[0] != 't' || w->tty[1] != 't' ||
  117.                     w->tty[2] != 'y' ? w->tty : w->tty + 3);
  118.             else
  119.                 (void)printf("   ");
  120.             if (w->info == LOGGEDIN) {
  121.                 stimeprint(w);
  122.                 (void)printf("  ");
  123.             } else
  124.                 (void)printf("    *  ");
  125.             p = ctime(&w->loginat);
  126.             (void)printf("%.6s", p + 4);
  127.             if (now - w->loginat >= SECSPERDAY * DAYSPERNYEAR / 2)
  128.                 (void)printf("  %.4s", p + 20);
  129.             else
  130.                 (void)printf(" %.5s", p + 11);
  131. office:            if (pn->office)
  132.                 (void)printf(" %-10.10s", pn->office);
  133.             else if (pn->officephone)
  134.                 (void)printf(" %-10.10s", " ");
  135.             if (pn->officephone)
  136.                 (void)printf(" %-.15s",
  137.                     prphone(pn->officephone));
  138.             putchar('\n');
  139.         }
  140.     }
  141. }
  142.  
  143. PERSON **
  144. sort()
  145. {
  146.     register PERSON *pn, **lp;
  147.     PERSON **list;
  148.     int psort();
  149.     char *malloc();
  150.  
  151.     if (!(list = (PERSON **)malloc((u_int)(entries * sizeof(PERSON *))))) {
  152.         (void)fprintf(stderr, "finger: out of space.\n");
  153.         exit(1);
  154.     }
  155.     for (lp = list, pn = phead; pn != NULL; pn = pn->next)
  156.         *lp++ = pn;
  157.     (void)qsort(list, entries, sizeof(PERSON *), psort);
  158.     return(list);
  159. }
  160.  
  161. psort(p, t)
  162.     PERSON **p, **t;
  163. {
  164.     return(strcmp((*p)->name, (*t)->name));
  165. }
  166.  
  167. stimeprint(w)
  168.     WHERE *w;
  169. {
  170.     register struct tm *delta;
  171.  
  172.     delta = gmtime(&w->idletime);
  173.     if (!delta->tm_yday)
  174.         if (!delta->tm_hour)
  175.             if (!delta->tm_min)
  176.                 (void)printf("    -");
  177.             else
  178.                 (void)printf("%5d", delta->tm_min);
  179.         else
  180.             (void)printf("%2d:%02d",
  181.                 delta->tm_hour, delta->tm_min);
  182.     else
  183.         (void)printf("%4dd", delta->tm_yday);
  184. }
  185. @
  186.