home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V6 / usr / source / s2 / who.c < prev    next >
Encoding:
C/C++ Source or Header  |  1975-05-13  |  954 b   |  69 lines

  1. /*
  2.  * who
  3.  */
  4.  
  5. int    fout;
  6. int    buf[256];
  7.  
  8. main(argc, argv)
  9. char **argv;
  10. {
  11.     char *s, *cbuf;
  12.     int n, fi, i;
  13.     int tty;
  14.     struct {
  15.         char name[8];
  16.         char tty;
  17.         char pad1;
  18.         int time[2];
  19.         char pad2[2];
  20.     } *p;
  21.  
  22.     s = "/etc/utmp";
  23.     if(argc == 2)
  24.         s = argv[1];
  25.     fi = open(s, 0);
  26.     if(fi < 0) {
  27.         write("cannot open wtmp\n", 17);
  28.         exit();
  29.     }
  30.     fout = dup(1);
  31.     close(1);
  32.     if (argc==3)
  33.         tty = ttyn(0);
  34.  
  35. loop:
  36.     n = read(fi, buf, 512);
  37.     if(n == 0) {
  38.         flush();
  39.         if (argc==3)
  40.             write(fout, "Nobody.\n", 8);
  41.         exit();
  42.     }
  43.  
  44.     p = &buf;
  45.     for(p = &buf; (n =- 16)>=0; p++) {
  46.         if (argc==3 && tty!=p->tty)
  47.             continue;
  48.         if(p->name[0] == '\0' && argc==1)
  49.             continue;
  50.         for(i=0; i<8; i++) {
  51.             if(p->name[i] == '\0')
  52.                 p->name[i] = ' ';
  53.             putchar(p->name[i]);
  54.         }
  55.         for(i=0; i<3; i++)
  56.             putchar("tty"[i]);
  57.         putchar(p->tty);
  58.         cbuf = ctime(p->time);
  59.         for(i=3; i<16; i++)
  60.             putchar(cbuf[i]);
  61.         putchar('\n');
  62.         if (argc==3) {
  63.             flush();
  64.             exit();
  65.         }
  66.     }
  67.     goto loop;
  68. }
  69.