From:	CSBVAX::MRGATE!RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP 15-AUG-1988 07:29
To:	ARISIA::EVERHART
Subj:	SUM (Show Users More) Part 4 of 4


Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Fri, 12 AUG 88 22:53:57 PDT
Received: from hac2arpa.hac.com by KL.SRI.COM with TCP; Fri, 12 Aug 88 22:45:12 PDT
Received: from draco.HAC.COM by hac2arpa.hac.com (3.2/SMI-DDN)
	id AA13275; Fri, 12 Aug 88 21:59:03 PDT
Received: by draco id <24C20638025@draco.HAC.COM> ;
       Fri, 12 Aug 88 21:54:40 PDT
Date: Fri, 12 Aug 88 21:54:39 PDT
From: Michael N. Kimura <MNK@draco.hac.com>
Subject: SUM (Show Users More) Part 4 of 4
To: info-vax%kl.sri.com@hac2arpa.hac.com
X-Vms-Mail-To: EXOS%"<info-vax%kl.sri.com@hac2arpa.hac.com>",MNK
Message-Id: <880812215439.24C20638025@draco.HAC.COM>

+-+-+-+ Beginning of part 4 +-+-+-+
X`009    call Insert_Sort(Line(1:Line_Len))
X
X`009    !---------------------------------------------------------------
X`009    !* Add one to the user count
X
X`009    User_Cnt = User_Cnt + 1
X
X9999`009continue`009!* simulate a break
X`009enddo
X
X`009!-------------------------------------------------------------------
X`009!* Check status of last GETJPI
X
X`009if (.not. JPI_Succ .and. JPI_Succ .ne. SS$_NOMOREPROC) call exit(JPI_Succ)
X
X`009!-------------------------------------------------------------------
X`009!* Open output unit with "list" carriage control
X
X`009open(unit=10,file=Output_Filename(1:Output_Filename_len),
X`0091`009defaultfile='SUM.LIS',carriagecontrol='list',status='new')
X
X`009!-------------------------------------------------------------------
X`009!* Check if Username was specified on command line and if not found
X`009!* display SHOW$_NOSUCHUSER message
X
X`009if (P1_Username_Len .ne. 0 .and. User_Cnt .eq. 0) then
V`009`009call LIB$SIGNAL(SHOW$_NOSUCHUSER,%val(1),P1_Username(1:P1_Username_Len)
X)
X`009`009call exit(%loc(SHOW$_NOSUCHUSER) .or. '10000000'x)
X`009endif
X
X`009!-------------------------------------------------------------------
X`009!* Dump the header (taken from SHOW USERS)
X
V`009succ = SYS$FAO('!10* VAX/VMS Interactive Users!/!11* !%D!/!4* Total number 
Xof interactive users = !UW',
X`0091`009Line_Len, Line,
X`0091`009%val(0),%val(Get_IJobCnt(SYS$GW_IJOBCNT)))
X`009if (.not. succ) call exit(succ)
X
X`009write (10,1000) line(1:line_len)
X1000`009format(a)
X
X`009!-------------------------------------------------------------------
X`009!* If we found some users then dump the header and records
X
X`009if (User_Cnt .gt. 0) then
X
X`009    write (10,1010) ' Username     Process Name      PID     Terminal'
X1010`009    format(/a)
X
X`009    !---------------------------------------------------------------
X`009    !* Dump the records to the output file
X
X`009    do while (Succ)
X
X`009`009!-----------------------------------------------------------
X`009`009!* Get next record from the sorted list
X`009 
X`009`009Succ = Get_Record(Line,Line_Len)
X
X`009`009!-----------------------------------------------------------
X`009`009!* Output the record if successful
X
X`009`009if (Succ) write(10,1000) Line(1:Line_Len)
X
X`009    enddo
X
X`009endif`009!* User_Cnt .gt. 0
X
X`009!-------------------------------------------------------------------
X`009!* That's all folks....
X
X`009end
$ GOSUB UNPACK_FILE
$ FILE_IS = "SUM_V5.FOR"
$ CHECKSUM_IS = 474832593
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X!*===========================================================================
X!* Show Users More -- This program mimics VAX/VMS SHOW USERS command but adds
X!*`009`009      the remote node(port) information for LAT terminals
X!*
X!* Environment: User Mode, VAX/VMS Version V5.0 or greater
X!*
X!*`009`009Note: This has only been tested on a Field Test Version of
X!*`009`009      VAX/VMS Version V5.0
X!*
X!* Privilege:`009WORLD`009- To get Job/Process Information
X!*
X!* Date:`00913-May-1988
X!*
X!* Author:`009Michael Kimura
X!*
X!*`009`009Hughes Aircraft Company (RSG)
X!*`009`009MS: R2/A159
X!*`009`009P.O. Box 92426
X!*`009`009Los Angeles,  CA  90009
X!*
X!*`009`009(213) 615-9775
X!*
X!*===========================================================================
X
X`009options/extend_source`009`009!* Allow lines longer than 72 chars
X
X`009program sum`009`009`009!* Show Users More
X
X!---------------------------------------------------------------------------
X!* Declarations
X
X`009implicit none`009`009`009!* Declare everything!
X
X`009include '($syssrvnam)'`009`009!* Include System Service Names
X`009include '($ssdef)'`009`009!* Include SS$ codes
X`009include '($dscdef)'`009`009!* Include DSC$ codes
X
X`009include 'ItmLst'`009`009!* Include Item List Structure
X
X`009parameter
X`0091`009DEF_TT_PHYDEVNAM = 8,`009`009!* Default length of PHYDEVNAM
X`0091`009DEF_REMOTE_NODE = 6`009`009!* Default length of Rem. Node
X
X`009integer*4
X`0091`009JPI_Succ,`009`009!* GETJPI VMS Success Codes
X`0091`009Succ,`009`009`009!* VMS Success Code
X`0091`009Wild /-1/,`009`009!* Wildcard PID for GETJPI
X`0091`009PID`009`009`009!* PID
X
X`009integer*2
X`0091`009P1_Username_Len,`009!* Length of Username to search for
X`0091`009Output_Filename_len,`009!* Output Filename length
X`0091`009Username_Len,`009`009!* Username length
X`0091`009PrcNam_Len,`009`009!* Process Name length
X`0091`009Terminal_Len,`009`009!* Terminal Name length
X`0091`009TT_PhyDevNam_Len,`009!* Physical Device Name length
X`0091`009TT_AccPorNam_Len,`009!* Node/Port Name length
X`0091`009End_Node_Name,`009`009!* Last byte of Node Name
X`0091`009Beg_Port_Name,`009`009!* First byte of Port Name
X`0091`009End_Port_Name,`009`009!* Last byte of Port Name
X`0091`009Slash,`009`009`009!* Location of "/" in TT_AccPorNam
X`0091`009Fmt_TT_PhyDevNam,`009!* Format length of Physical Device
X`0091`009Fmt_Remote_Node,`009!* Format length of Remote Node
X`0091`009Get_IJobCnt,`009`009!* Subroutine to retrieve SYS$GW_IJOBCNT
X`0091`009Line_Len,`009`009!* Length of Line
X`0091`009User_Cnt /0/,`009`009!* Count of Users
X`0091`009IOSB(4),`009`009!* I/O Status Block
X`0091`009KeyBuf(5) /`009`009!* Key Buffer for SOR Routines
X`0091`009    1,`009`009`009    !* Number of Keys
X`0091`009    DSC$K_DTYPE_T,`009    !* Type (Text)
X`0091`009    0,`009`009`009    !* Order (Ascending)
X`0091`009    1,`009`009`009    !* Offset (Byte 2)
X`0091`009    12/`009`009`009    !* Length (12 Bytes)
X
X`009volatile`009!* Don't Optimize these into Registers!
X`0091`009Username_Len,`009`009!* Username length
X`0091`009PrcNam_Len,`009`009!* Process Name length
X`0091`009PID,`009`009`009!* PID
X`0091`009Terminal_Len,`009`009!* Terminal Name length
X`0091`009TT_PhyDevNam_Len,`009!* Physical Device Name length
X`0091`009TT_AccPorNam_Len`009!* Node/Port Name length
X
X`009character
X`0091`009P1_Username*255,`009!* Username to search for
X`0091`009Output_Filename*255,`009!* Output File Name
X`0091`009Username*12,`009`009!* Username buffer
X`0091`009PrcNam*15,`009`009!* Process Name buffer
X`0091`009Terminal*7,`009`009!* Terminal Name buffer
X`0091`009TT_PhyDevNam*64,`009!* Physical Device Name of Terminal
X`0091`009TT_AccPorNam*64,`009!* Name of local port on remote system
X`0091`009Line*255`009`009!* Output line
X
X`009logical*1
X`0091`009Get_Record,`009`009!* Get next record from sorted list
X`0091`009Full_Display`009`009!* Full Display?
X
X`009external
X`0091`009SYS$GW_IJOBCNT,`009`009!* In SYS$SYSTEM:SYS.STB
X`0091`009SHOW$_NOSUCHUSER`009!* In SYS$MESSAGE:CLIUTLMSG
X`009`009`009`009`009!* Pointer in SHWMSGPTR.OBJ
X
X!---------------------------------------------------------------------------
X!* Call CLI routines to parse the command line
X
X`009call Parse_Cmd_Line(
X`0091`009P1_Username,
X`0091`009P1_Username_Len,
X`0091`009Output_Filename,
X`0091`009Output_Filename_len,
X`0091`009Full_Display)
X
X!---------------------------------------------------------------------------
X!* Load the GETJPI and GETDVI Item Lists
X
X`009call Load_ItmLst(
X`0091`009GetJpi_ItmLst,
X`0091`009Username,
X`0091`009Username_Len,
X`0091`009PrcNam,
X`0091`009PrcNam_Len,
X`0091`009PID,
X`0091`009Terminal,
X`0091`009Terminal_Len,
X`0091`009GetDvi_ItmLst,
X`0091`009TT_PhyDevNam,
X`0091`009TT_PhyDevNam_Len,
X`0091`009TT_AccPorNam,
X`0091`009TT_AccPorNam_Len)
X
X!---------------------------------------------------------------------------
X!* Initialization(s)
X
X`009Fmt_Remote_Node = DEF_REMOTE_NODE
X`009JPI_Succ = SS$_NORMAL`009!* Initialize JPI_Succ to successful
X
X!---------------------------------------------------------------------------
X!* Show Us More...
X
X`009!-------------------------------------------------------------------
X`009!* Repeat loop until no more processes
X
X`009do while ( (JPI_Succ) .or.`009`009`009!* Last GetJPI was Successful
X`0091`009   (JPI_Succ .eq. SS$_NOPRIV) .or.`009!* No privilege is ok
X`0091`009   (JPI_Succ .eq. SS$_SUSPENDED) )`009!* Suspended processes are ok
X
X`009    !---------------------------------------------------------------
X`009    !* GetJPI on the next process
X
X`009    JPI_Succ = SYS$GETJPIW(,Wild,,GetJpi_ItmLst,IOSB,,)
X`009    if (.not. JPI_Succ) goto 9999`009!* break
X`009    if (.not. IOSB(1)) call exit(IOSB(1))
X
X`009    !---------------------------------------------------------------
X`009    !* If no terminal then not an interactive user (break)
X
X`009    if (Terminal_Len .eq. 0) goto 9999`009!* break
X
X`009    !---------------------------------------------------------------
X`009    !* If user specified a username and it doesn't match then break
X
X`009    if (P1_Username_Len .ne. 0) then
V`009`009if (index(Username(1:Username_Len),P1_Username(1:P1_Username_Len)) .ne.
X 1) goto 9999`009!* break
X`009    endif
X
X`009    !---------------------------------------------------------------
X`009    !* Get the Physical Device name of the terminal and
X`009    !* Get the Name of the Local Port on Remote system
X
X`009    TT_PhyDevNam_Len = 0`009!* Initialize to null
X`009    TT_AccPorNam_Len = 0`009!* Initialize to null
X
X`009    Succ = SYS$GETDVIW(,,Terminal(1:Terminal_Len),GetDvi_ItmLst,IOSB,,,)
X`009    if (.not. Succ .and. Succ .ne. SS$_NOSUCHDEV) call exit(Succ)
X`009    if (.not. IOSB(1) .and. IOSB(1) .ne. SS$_NOSUCHDEV) call exit(IOSB(1))
X
X`009    !---------------------------------------------------------------
X`009    !* Format the Physical Device Name
X
X`009    if (TT_PhyDevNam_Len .eq. 0) then
X
X`009`009!-----------------------------------------------------------
X`009`009!* Physical device name is null so process is Disconnected
X
X`009`009TT_PhyDevNam = ' Disconnected'
X`009`009TT_PhyDevNam_Len = len(' Disconnected')
X`009`009Fmt_TT_PhyDevNam = TT_PhyDevNam_Len - 1
X
X`009    else
X
X`009`009Fmt_TT_PhyDevNam = DEF_TT_PhyDevNam
X
X`009`009!-----------------------------------------------------------
X`009`009!* Physical Device name matches Terminal name so set to null
X
X`009`009if (index(TT_PhyDevNam(1:TT_PhyDevNam_Len),
X`0091`009    Terminal(1:Terminal_Len)) .ne. 0)
X`0091`009    TT_PhyDevNam_Len = 1
X
X`009    endif`009!* Pysical Device name checking
X
X`009    !---------------------------------------------------------------
X`009    !* Format the Name of Local Port on Remote system
X
X`009    End_Node_Name = 0`009!* Initialize to null
X`009    Beg_Port_Name = 1`009!* Initialize to null
X`009    End_Port_Name = 0`009!* Initialize to null
X
X`009    if (TT_AccPorNam_Len .ne. 0) then
X`009`009Slash = index(TT_AccPorNam(1:TT_AccPorNam_Len),'/')
X`009`009if (Slash .eq. 0) then
X`009`009    End_Node_Name = TT_AccPorNam_Len
X`009`009else
X`009`009    End_Node_Name = Slash - 1
X`009`009    Beg_Port_Name = Slash + 1
X`009`009    End_Port_Name = TT_AccPorNam_Len
X`009`009endif
X`009    endif
X
X`009    !---------------------------------------------------------------
X`009    !* User specified /FULL so set field lengths to full width
X
X`009    if (Full_Display) then
X`009`009Fmt_TT_PhyDevNam = max(DEF_TT_PhyDevNam,TT_PhyDevNam_Len-1)
X`009`009Fmt_Remote_Node = max(DEF_REMOTE_NODE,End_Node_Name)
X`009    endif
X
X`009    !---------------------------------------------------------------
X`009    !* Format the output record
X
X`009    Succ = SYS$FAO(' !12AS !15AS !XL  !7AS !#AS !#AS !AS',
X`0091`009Line_Len, Line,
X`0091`009Username(1:Username_Len),
X`0091`009PrcNam(1:PrcNam_Len),
X`0091`009%val(PID),
X`0091`009Terminal(1:Terminal_Len),
X`0091`009%val(Fmt_TT_PhyDevNam),
X`0091`009TT_PhyDevNam(2:TT_PhyDevNam_Len),
X`0091`009%val(Fmt_Remote_Node),
X`0091`009TT_AccPorNam(1:End_Node_Name),
X`0091`009TT_AccPorNam(Beg_Port_Name:End_Port_Name))
X`009    if (.not. Succ) call exit(Succ)
X
X`009    !---------------------------------------------------------------
X`009    !* Insert this record into the sorted list
X
X`009    call Insert_Sort(Line(1:Line_Len))
X
X`009    !---------------------------------------------------------------
X`009    !* Add one to the user count
X
X`009    User_Cnt = User_Cnt + 1
X
X9999`009continue`009!* simulate a break
X`009enddo
X
X`009!-------------------------------------------------------------------
X`009!* Check status of last GETJPI
X
X`009if (.not. JPI_Succ .and. JPI_Succ .ne. SS$_NOMOREPROC) call exit(JPI_Succ)
X
X`009!-------------------------------------------------------------------
X`009!* Open output unit with "list" carriage control
X
X`009open(unit=10,file=Output_Filename(1:Output_Filename_len),
X`0091`009defaultfile='SUM.LIS',carriagecontrol='list',status='new')
X
X`009!-------------------------------------------------------------------
X`009!* Check if Username was specified on command line and if not found
X`009!* display SHOW$_NOSUCHUSER message
X
X`009if (P1_Username_Len .ne. 0 .and. User_Cnt .eq. 0) then
V`009`009call LIB$SIGNAL(SHOW$_NOSUCHUSER,%val(1),P1_Username(1:P1_Username_Len)
X)
X`009`009call exit(%loc(SHOW$_NOSUCHUSER) .or. '10000000'x)
X`009endif
X
X`009!-------------------------------------------------------------------
X`009!* Dump the header (taken from SHOW USERS)
X
V`009succ = SYS$FAO('!10* VAX/VMS Interactive Users!/!11* !%D!/!4* Total number 
Xof interactive users = !UW',
X`0091`009Line_Len, Line,
X`0091`009%val(0),%val(Get_IJobCnt(SYS$GW_IJOBCNT)))
X`009if (.not. succ) call exit(succ)
X
X`009write (10,1000) line(1:line_len)
X1000`009format(a)
X
X`009!-------------------------------------------------------------------
X`009!* If we found some users then dump the header and records
X
X`009if (User_Cnt .gt. 0) then
X
X`009    write (10,1010) ' Username     Process Name      PID     Terminal'
X1010`009    format(/a)
X
X`009    !---------------------------------------------------------------
X`009    !* Dump the records to the output file
X
X`009    do while (Succ)
X
X`009`009!-----------------------------------------------------------
X`009`009!* Get next record from the sorted list
X`009 
X`009`009Succ = Get_Record(Line,Line_Len)
X
X`009`009!-----------------------------------------------------------
X`009`009!* Output the record if successful
X
X`009`009if (Succ) write(10,1000) Line(1:Line_Len)
X
X`009    enddo
X
X`009endif`009!* User_Cnt .gt. 0
X
X`009!-------------------------------------------------------------------
X`009!* That's all folks....
X
X`009end
$ GOSUB UNPACK_FILE
$ EXIT
-+-+-+-+-+ End of part 4 +-+-+-+-+-

