      INTEGER A$BUF(200)
      INTEGER NFD,TFD
      INTEGER OPEN
      INTEGER * 4 TTABLE(128)
      INTEGER PID,FIRST0,UTYPE
      INTEGER GETUS0,GETLO0,LENGTH
      LOGICAL HEADER
      INTEGER REM,UID(33),NAME(30),LOCN(30),TIME(6)
      INTEGER PROJE0(33)
      INTEGER UTABLE
      INTEGER LOADU0
      INTEGER USAGE(31)
      INTEGER PARSCL
      INTEGER AAAAA0(5)
      INTEGER AAAAB0(11)
      INTEGER AAAAC0(11)
      INTEGER AAAAD0
      INTEGER AAAAE0
      INTEGER AAAAF0(5)
      DATA USAGE/213,243,225,231,229,186,160,247,232,239,160,251,173,225
     *,160,252,160,173,236,160,252,160,173,240,160,252,160,173,241,253,0
     */
      DATA AAAAA0/225,236,240,241,0/
      DATA AAAAB0/189,245,243,229,242,236,233,243,244,189,0/
      DATA AAAAC0/189,244,229,242,237,236,233,243,244,189,0/
      DATA AAAAF0/170,243,170,238,0/
      IF((PARSCL(AAAAA0,A$BUF).NE.-3))GOTO 10000
        CALL ERROR(USAGE)
10000 IF((A$BUF(236-225+1).EQ.0))GOTO 10001
      IF((A$BUF(240-225+1).EQ.0))GOTO 10001
        CALL ERROR('can''t display both location and project at the same
     * time.')
10001 NFD=OPEN(AAAAB0,1)
      IF((NFD.NE.-3))GOTO 10002
        CALL ERROR('can''t read user list.')
10002 TFD=OPEN(AAAAC0,1)
      IF((TFD.NE.-3))GOTO 10003
        CALL CLOSE(NFD)
        CALL ERROR('can''t read terminal list.')
10003 UTABLE=LOADU0(NFD)
      CALL LOADT0(TFD,TTABLE)
      HEADER=.NOT.(A$BUF(241-225+1).NE.0)
      IF((A$BUF(225-225+1).EQ.0))GOTO 10004
        FIRST0=1
        GOTO 10005
10004   FIRST0=2
10005 DO 10006 PID=FIRST0,128
        IF((GETUS0(PID,REM,UID,TIME,PROJE0,UTYPE).EQ.-1))GOTO 10008
          AAAAD0=GETLO0(PID,TTABLE,TFD,LOCN,UTYPE)
          GOTO 10009
10010       IF((A$BUF(225-225+1).NE.0))GOTO 10011
              GOTO 10007
10011     GOTO 10012
10013       GOTO 10007
10009     AAAAE0=AAAAD0+4
          GOTO(10010,10014,10013),AAAAE0
10014     CONTINUE
10012     IF((.NOT.HEADER))GOTO 10015
            IF((A$BUF(240-225+1).EQ.0))GOTO 10017
            IF((A$BUF(236-225+1).NE.0))GOTO 10017
            GOTO 10016
10017         CALL PRINT(-11,'*#p *3p  *5p  *29p  *27p*n.',(33-1)/4,'Use
     *r.','Pid.','In At.','Name.','Location.')
              GOTO 10018
10016         CALL PRINT(-11,'*#p *3p  *5p  *29p  *27p*n.',(33-1)/4,'Use
     *r.','Pid.','In At.','Name.','Project.')
10018       CALL PRINT(-11,'*,,-u*#s *3s  *5s  *29s  *27s*n.',(33-1)/4,0
     *,0,0,0,0)
            HEADER=.FALSE.
10015     CALL GETNA0(UTABLE,NFD,UID,NAME)
          IF((LENGTH(UID).LE.(33-1)/4))GOTO 10019
            CALL PRINT(-11,AAAAF0,UID)
            IF((A$BUF(240-225+1).EQ.0))GOTO 10021
            IF((A$BUF(236-225+1).NE.0))GOTO 10021
            GOTO 10020
10021         CALL PRINT(-11,'*#t *3i*c *5s  *29,29s  *,27s*n.',(33+3)/4
     *,PID,REM,TIME,NAME,LOCN)
              GOTO 10022
10020         CALL PRINT(-11,'*#t *3i*c *5s  *29,29s  *,27s*n.',(33+3)/4
     *,PID,REM,TIME,NAME,PROJE0)
10022       GOTO 10023
10019       IF((A$BUF(240-225+1).EQ.0))GOTO 10025
            IF((A$BUF(236-225+1).NE.0))GOTO 10025
            GOTO 10024
10025         CALL PRINT(-11,'*#s *3i*c *5s  *29,29s  *,27s*n.',(33-1)/4
     *,UID,PID,REM,TIME,NAME,LOCN)
              GOTO 10026
10024         CALL PRINT(-11,'*#s *3i*c *5s  *29,29s  *,27s*n.',(33-1)/4
     *,UID,PID,REM,TIME,NAME,PROJE0)
10026     CONTINUE
10023   CONTINUE
10008   CONTINUE
10006 CONTINUE
10007 CALL CLOSE(NFD)
      CALL CLOSE(TFD)
      CALL SWT
      END
      INTEGER FUNCTION GETLO0(PID,TABLE,FD,LOCN,UTYPE)
      INTEGER PID,UTYPE
      INTEGER * 4 TABLE(128)
      INTEGER FD
      INTEGER LOCN(30)
      INTEGER L
      INTEGER GETLIN
      INTEGER LINE(102)
      INTEGER AAAAG0(20)
      INTEGER AAAAH0(10)
      INTEGER AAAAI0(13)
      DATA AAAAG0/210,229,237,239,244,229,160,204,239,231,233,238,160,21
     *1,229,242,246,229,242,0/
      DATA AAAAH0/206,208,216,160,211,236,225,246,229,0/
      DATA AAAAI0/208,232,225,238,244,239,237,160,213,243,229,242,0/
      GOTO 10027
10028   CALL CTOC(AAAAG0,LOCN,30)
        GETLO0=-2
        RETURN
10029   IF((TABLE(PID).NE.-1))GOTO 10030
          GETLO0=-1
          RETURN
10030     CALL SEEKF(TABLE(PID),FD)
          L=GETLIN(LINE,FD)
          IF((L.EQ.-1))GOTO 10032
          IF((L.LT.19))GOTO 10032
          GOTO 10031
10032       LOCN(1)=0
            GOTO 10033
10031       IF((LINE(L).NE.138))GOTO 10034
              LINE(L)=0
10034       CALL CTOC(LINE(18),LOCN,30)
10033     GETLO0=-4
          RETURN
10035   CALL CTOC(AAAAH0,LOCN,30)
        GETLO0=-3
        RETURN
10036   CALL CTOC(AAAAI0,LOCN,30)
        GETLO0=-3
        RETURN
10027 IF((UTYPE.EQ.3))GOTO 10028
      IF((UTYPE.LE.6))GOTO 10029
      IF((UTYPE.EQ.67))GOTO 10035
      IF((UTYPE.GE.65))GOTO 10036
        CALL ERROR('in get_locn: can''t happen.')
      END
      INTEGER FUNCTION GETUS0(PID,REM,UID,TIME,PROJE0,UTYPE)
      INTEGER PID,UTYPE
      INTEGER REM,UID(33),TIME(6),PROJE0(33)
      INTEGER USERM(43),CODE,H,M
      INTEGER AAAAJ0(11)
      DATA AAAAJ0/170,178,233,186,170,178,172,172,176,233,0/
      CALL GMETR$(4,LOC(USERM),43,CODE,PID)
      IF((CODE.NE.0))GOTO 10038
      IF((USERM(2).LT.0))GOTO 10038
      GOTO 10037
10038   GETUS0=-1
        RETURN
10037 IF((USERM(1).LT.3))GOTO 10039
        CALL PTOC(USERM(5),160,UID,33)
        CALL PTOC(USERM(21),160,PROJE0,33)
        GOTO 10040
10039   GETUS0=-1
        RETURN
10040 CALL MAPSTR(UID,1)
      CALL MAPSTR(PROJE0,1)
      UTYPE=USERM(2)
      IF((USERM(2).EQ.2))GOTO 10042
      IF((USERM(2).EQ.4))GOTO 10042
      GOTO 10041
10042   REM=242
        GOTO 10043
10041   REM=160
10043 H=MOD((USERM(4)/15)/60,24)
      M=MOD(USERM(4)/15,60)
      CALL ENCODE(TIME,6,AAAAJ0,H,M)
      GETUS0=-2
      RETURN
      END
      SUBROUTINE GETNA0(TABLE,NFD,UID,NAME)
      INTEGER TABLE
      INTEGER NFD
      INTEGER UID(1),NAME(30)
      INTEGER L,I
      INTEGER CTOC,EQUAL,EXPAND,GETLIN,LOOKUP
      INTEGER * 4 MARK
      INTEGER LINE(102),JUNK(102)
      INTEGER AAAAK0(9)
      INTEGER AAAAL0(4)
      DATA AAAAK0/189,199,225,212,229,227,232,189,0/
      DATA AAAAL0/249,229,243,0/
      IF((LOOKUP(UID,MARK,TABLE).NE.1))GOTO 10044
        CALL SEEKF(MARK,NFD)
        L=GETLIN(LINE,NFD)
        IF((L.EQ.-1))GOTO 10046
        IF((L.LT.9))GOTO 10046
        GOTO 10045
10046     NAME(1)=0
          RETURN
10045   IF((LINE(L).NE.138))GOTO 10047
          LINE(L)=0
10047   IF((EXPAND(AAAAK0,JUNK,102).EQ.-3))GOTO 10048
        IF((EQUAL(JUNK,AAAAL0).NE.1))GOTO 10048
          I=1
          IF((L.LE.70))GOTO 10049
            I=I+(CTOC(LINE(70),NAME(I),MIN0(30-I+1,89-70+2)))
            I=I-(1)
            GOTO 10052
10050       I=I-(1)
10052       IF((I.LT.1))GOTO 10051
            IF((NAME(I).NE.160))GOTO 10051
            GOTO 10050
10051       IF((I.GT.1))GOTO 10053
              I=1
              GOTO 10054
10053         NAME(I+1)=160
              I=I+(2)
10054     CONTINUE
10049     IF((L.LE.34))GOTO 10055
            I=I+(CTOC(LINE(34),NAME(I),MIN0(30-I+1,68-34+2)))
            I=I-(1)
            GOTO 10058
10056       I=I-(1)
10058       IF((I.LT.1))GOTO 10057
            IF((NAME(I).NE.160))GOTO 10057
            GOTO 10056
10057       I=I+(1)
10055     NAME(I)=0
          GOTO 10059
10048     CALL CTOC(LINE(33+1),NAME,30)
10059   RETURN
10044 NAME(1)=0
      RETURN
      END
      INTEGER FUNCTION LOADU0(FD)
      INTEGER FD
      INTEGER MEM(16384)
      COMMON /DS$MEM/MEM
      INTEGER MKTABL
      INTEGER GETLIN
      INTEGER LINE(102)
      INTEGER * 4 MARK
      INTEGER * 4 MARKF
      CALL DSINIT(16384)
      LOADU0=MKTABL(2)
10060   MARK=MARKF(FD)
        IF((GETLIN(LINE,FD).NE.-1))GOTO 10061
          GOTO 10062
10061   LINE(33)=0
        CALL STRIM(LINE)
        CALL MAPSTR(LINE,1)
        CALL ENTER(LINE,MARK,LOADU0)
      GOTO 10060
10062 RETURN
      END
      SUBROUTINE LOADT0(FD,TABLE)
      INTEGER FD
      INTEGER * 4 TABLE(128)
      INTEGER PIDSTR(10),TTYSTR(10),LINE(102)
      INTEGER I,L,PID
      INTEGER GETLIN,GETWRD,CTOI
      INTEGER * 4 MARK
      INTEGER * 4 MARKF
      DO 10063 I=1,128
        TABLE(I)=-1
10063 CONTINUE
10064 CONTINUE
10065   MARK=MARKF(FD)
        L=GETLIN(LINE,FD)
        IF((L.NE.-1))GOTO 10066
          GOTO 10067
10066   I=1
        IF((GETWRD(LINE,I,TTYSTR,10).EQ.0))GOTO 10069
        IF((GETWRD(LINE,I,PIDSTR,10).EQ.0))GOTO 10069
        GOTO 10068
10069     GOTO 10070
10068   I=2
        PID=CTOI(PIDSTR,I)
        IF((PID.LT.1))GOTO 10072
        IF((PID.GT.128))GOTO 10072
        GOTO 10071
10072     GOTO 10070
10071   TABLE(PID)=MARK
10070 GOTO 10065
10067 RETURN
      END
      INTEGER FUNCTION GETWRD(IN,I,OUT,MAX)
      INTEGER IN(1),OUT(1)
      INTEGER I,MAX
      INTEGER J
10073 IF((IN(I).NE.160))GOTO 10074
        I=I+(1)
      GOTO 10073
10074 J=1
10075 IF((IN(I).EQ.0))GOTO 10076
      IF((IN(I).EQ.160))GOTO 10076
      IF((IN(I).EQ.138))GOTO 10076
        IF((J.LT.MAX))GOTO 10077
          GOTO 10076
10077   OUT(J)=IN(I)
        I=I+(1)
        J=J+(1)
      GOTO 10075
10076 OUT(J)=0
      GETWRD=J-1
      RETURN
      END
C ---- Long Name Map ----
C firstpid                       first0
C loaduserlist                   loadu0
C getlocn                        getlo0
C project                        proje0
C getuserinfo                    getus0
C loadtermlist                   loadt0
C getname                        getna0
