cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c	Dispuser.for
c	This program is the actual WHO command source.  SCANUSER must be
c	running on all systems for it to work properly.
c	Dale Miller - UALR
c	18-Apr-1985
c
c	Rev. 1.0  18-Apr-1985
c	Rev. 1.1  01-Feb-1986 - Changed calulation of logon time.
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
	implicit integer(a-z)

c SITE-SPECIFIC all arrays dimensioned 200 must be changed if the TOTAL number
c of users will exceed that amount.  Just set them as high (or low) as you need.
	character terminal(200)*9,pterminal(200)*6
	character username(200)*12,prcnam(200)*15
	character image(200)*15,pflag(200)*1
	integer minutes(200),cputim(200),tag(200),node(200)
	integer*2  t(7)
	character whomi*12,ctime*8,cdate*9
	character currtim*8
	integer*2  t2(7)
	logical guru
	integer normp/1081344/
c	                 J  F  M  A  M  J  J  A  S  O  N  D
	integer dim(12)/31,28,31,30,31,30,31,31,30,31,30,31/


c SITE-SPECIFIC Put in your node names in the same order as SCANUSER.

	character*6 nodename(4)/'alpha','beta','gamma','delta'/
	real seconds
	include 'sys$library:jpidef.for'

c	find out who's using this program
	istat = lib$getjpi(jpi$_username,,,,whomi,)
	guru=.false.
	if(whomi.eq.'DOMILLER'.or.whomi.eq.'MLSMITH' .or.
	1   whomi.eq.'LMCOUNTS') guru=.true.

	open(unit=1,organization='relative',recordtype='fixed',
     &	access='direct',recl=128,status='old',form='formatted',
     &	shared,file='sys$manager:scanuser.dat',readonly)
c
c	when is it?
	istat = sys$gettim(currtim)
        istat = sys$numtim(t2,currtim)
	call date(cdate)
	call time(ctime)

c
c	put everyone in the table
c
	recnum=1
	k=1
	system=1
c	loop to scan all users
 0010	continue

	read(1'recnum,100)pid,terminal(k),pterminal(k),username(k),
     &	prcnam(k),image(k),pri,apriv,cputim(k),t
 0100	format(z8,a9,a6,a12,a15,a15,i2,z8,z8,i4,6i2)
	tag(k)=k

	if(pid.eq.0) then
	    system=system+1
c SITE-SPECIFIC Change this calculation for other than 100 users per system.
	    recnum=(recnum/100)*100+101
c SITE-SPECIFIC number should be nodes * number of users per node (4*100)
	    if(recnum.ge.400) go to 1000
	    go to 10
	    endif
	node(k)=system

c	Should we flag a suspicious user?
c	Anyone who has nonstandard privileges is suspicious, so let
c	Dale & Mike know about them.
	pflag(k)=' '
	if(guru) then
	    if(apriv.ne.normp.and.apriv.ne.-1) pflag(k)='*'
	    endif

c	calculate time logged in (to nearest minute).
c	NOTE - this calculation will not work if more than one month has passed
c	since he logged on. (I didn't think it worth the extra steps)

	if(t2(2).eq.t(2)) then
	    minutes(k) = ((t2(3)-t(3))*24+(t2(4)-t(4)))*60+(t2(5)-t(5))
	else
	    if(t2(2).eq.2.and.(t2(1)/4)*4.eq.t2(1)) dim(2)=29
	    minutes(k) = ((dim(t2(2))-t2(3)+t(3))*24+
	1	         (t2(4)-t(4)))*60+(t2(5)-t(5))
	endif

	recnum=recnum+1
	k=k+1
        go to 10

c	Enter here after reading all input
 1000	continue
	k=k-1			! reflect real number of records

	write(6,14)cdate,ctime,k
 0014	format('    UALR system users on ',a9,' at ',a8,2x,i3,' Users')

c	sort it by username
	ndelta=k
	do while(ndelta.gt.1)
	    ndelta=ndelta/2
	    nswitch=1
	    do while(nswitch.eq.1)
		nswitch=0
		max = k-ndelta
		do i=1,max
		    if (username(tag(i)).gt.username(tag(i+ndelta)) .or.
     &		       ((username(tag(i)).eq.username(tag(i+ndelta))).and.
     &		       (node(tag(i)).gt.node(tag(i+ndelta))))) then
			temp=tag(i)
			tag(i)=tag(i+ndelta)
			tag(i+ndelta)=temp
			nswitch=1
			endif
		    enddo
		enddo
	    enddo

c	It's sorted! Now print it.
	write(6,15)
 0015	format('  Node  Term      Username     Process name',
	1   '  Imagename  Cpu sec  Elapsed min',/)
	do i=1,k	
c SITE-SPECIFIC You can fudge image names here.
	    if(image(tag(i)).eq.'CSH')		image(tag(i))='<UNIX>'
	    if(image(tag(i)).eq.'RTPAD')	image(tag(i))='<DECNET>'
	    if((image(tag(i)).eq.'SA021'.or.
	1	image(tag(i)).eq.'SA022').and..not.guru)
	2	image(tag(i))='<DCL>'          
	    write(6,12)pflag(tag(i)),nodename(node(tag(i))),
	1   terminal(tag(i)),username(tag(i)),prcnam(tag(i))(1:13),
	2   image(tag(i))(1:11),cputim(tag(i))/100,minutes(tag(i))
	    enddo
 0012	format(1x,a1,a6,a9,1x,a12,1x,a,1x,a,1x,i6,1x,i5)

	call exit
	end
