	         PROGRAM SPLREP
 
C  THIS IS A SIMPLE MINDED REPORT PROGRAM WHICH READS LB:[1,4]SYSLOG.DAT AND
C  DISPLAYS INFORMATION ON PRINT SPOOLER USAGE.
C	TO BUILD THIS TASK
C		A) BUILD PIN AND TYPE  PIN SPLREP.PRC
C			OR
C		B)	F4P SPLREP=SPLREP/NOTR
C			TKB>SPLREP.TSK/CP/FP=SPLREP,LB:[1,1]F4POTS/LB
C			TKB>/
C			TKB>ACTFIL=2
C			TKB>UNITS=2
C			TKB>LIBR=F4PRES:RO
C			TKB>//
 

C --	CPU STATISTICS REPORT
 
	INTEGER*2 IBUF(13)
	INTEGER*2 JACNT(100,2)				! ACNT TOT,#PAGE,#JOB
	LOGICAL*1 LFILE(24)				! FOR FILE NAME
	LOGICAL*1 LDATE(8),LANS,LPRTNM(6)
	LOGICAL*1 LTIME(8)
	EQUIVALENCE (IREC,IBUF(1))
C -- START RECORD
	EQUIVALENCE (IHR,IBUF(2))
	EQUIVALENCE (IMIN,IBUF(3))
	EQUIVALENCE (ISEC,IBUF(4))
	EQUIVALENCE (IYEAR,IBUF(5))
	EQUIVALENCE (IMONTH,IBUF(6))
	EQUIVALENCE (IDAY,IBUF(7))
	EQUIVALENCE (ITICS,IBUF(8))
	EQUIVALENCE (ITKPS,IBUF(9))
	EQUIVALENCE (IDELTA,IBUF(10))
	EQUIVALENCE (IACMSK,IBUF(13))
C -- SPOOL PACKET
	EQUIVALENCE (IACNT ,IBUF(5))		! USER'S ACCOUNT NUMBER
	EQUIVALENCE (ITOTPG,IBUF(6))		! TOT NUMBER OF PAGES PRNTED
	EQUIVALENCE (ICOPYS,IBUF(7))		! TOT NUMBER OF COPIES IN JOB
	EQUIVALENCE (ITKNM1,IBUF(11))		! DESPOOLER TASK NAME IN
	EQUIVALENCE (ITKNM2,IBUF(12))		! RAD50 FORMAT
 
	LUN2=1					! TERMINAL LUN
	LUN1=2					! FILE LUN(LB:[1,4]SYSLOG.DAT)
	OPEN(UNIT=LUN1,NAME='TI:')		! SET UP TERMINAL FOR I/O
 
 
C  -- OPEN LB:[1,4]SYSLOG.DAT
	CALL ERRSET(43,.TRUE.,.FALSE.,,.FALSE.,)! DON'T WARN USER IF UIC ON
						! LB: IS MISSING
	CALL ERRSET(29,.TRUE.,.FALSE.,,.FALSE.,)! DON'T WARN IF OPEN ERROR
1	WRITE(LUN1,2)
2	FORMAT(' LOGFILE: ',$)			! PROMPT FOR LOGFILE NAME
	READ(LUN1,4,ERR=1,END=9999)N,LFILE	! GET FILE NAME
4	FORMAT(Q,24A1)				! IN CHARACTER FORMAT
	IF(N.EQ.0)                       GOTO 25! <CR>,=> LB:[1,4]SYSLOG.DAT
 
	OPEN(UNIT=LUN2,NAME='LB:TMP.TMP;1',	! CREATE TEMP FILE TO SET LB:
     -		       TYPE='SCRATCH')		!
	CLOSE(UNIT=LUN2)			! AND CLOSE IT IMMEDIATELY
	OPEN(UNIT=LUN2,				! OPEN FILE SPECIFIED BY LFILE
     -	     NAME	=LFILE,			!
     -	     READONLY,				!
     -	     FORM	='UNFORMATTED',		!
     -	     TYPE	='OLD',			!
     -	     ACCESS	='SEQUENTIAL',		!
     -	     SHARED,				! SO LOG... CAN ALWAYS USE
     -	     ERR	=9000)			!
 						!
	GOTO 30					! SKIP SECOND OPEN
 
25	OPEN(UNIT=LUN2,				! OPEN DEFAULT FILE
     -       NAME	= 'LB:[1,4]SYSLOG.DAT',	!
     -	     READONLY,				!
     -	     FORM	= 'UNFORMATTED',	!
     -	     TYPE	= 'OLD',		!
     -	     ACCESS	= 'SEQUENTIAL',		!
     -	     SHARED,				! SO LOG... CAN ALWAYS USE
     -	     ERR	= 9050)			!

30	CONTINUE				! 
	LUN3=LUN1				! ASSUME OUTPUT TO TI:
	ITOTAL=0				! INIT TOTAL PAGES PRINTED
	IJOBS=0					! INIT TOTAL PRINT JOBS
	WRITE(LUN1,32)   			! SHALL WE SPOOL
32	FORMAT(' SPOOL OUTPUT FILE TO PRINTER[Y/N]: ',$) !
	READ(LUN1,34)LANS			! GET ANSWER
34	FORMAT(1A1)				!
	IF(LANS.NE.'Y')                  GOTO 38! NO DON'T SPOOL
	LUN3=3					! OUTPUT TO LUN3
	OPEN(UNIT=LUN3,NAME='LP.LST',		! SPOOL OUTPUT FILE
     -  CARRIAGECONTROL='LIST',DISPOSE='PRINT') !
38	WRITE(LUN3,40)
40	FORMAT(' 'T20,'SYSTEM PRINT SPOOLER USAGE REPORT',/)
C	WRITE(LUN3,50)
50	FORMAT(' 'T4,'DATE',T14,'TIME',T26,'ACNT',
     -		T37,'PAGES',T47,'COPIES',T60,'PRINTER')

100	READ(LUN2,ERR=9100,END=6000) IBUF	! READ THE ACCOUNT FILE
 						!
	IF(IREC.NE.1  .AND.			! SKIP IF NOT START, OR
     -     IREC.NE.4)                   GOTO 190! CHANGE DELTA RECORD
	WRITE(LUN3,105)				! SKIP A LINE
105	FORMAT(' ')				!
	WRITE(LUN3,50)				! OUTPUT HEADER
	IWARN=0					! WARNING NOT GIVEN
	DO 110 ,I=1,8				!
110	LTIME(I)=' '				!
	ENCODE(8,150,LDATE)IMONTH,IDAY,IYEAR	! GET ASCII DATE
150	FORMAT(I2,'/',I2,'/',I2)		!
	DO 160,I=1,8				!
160	IF(LDATE(I).EQ.' ')LDATE(I)='0'		! CONVERT SPACES TO '0'
	JACMSK=IACMSK				! SAVE FOR LATER
	ISPMSK=JACMSK.AND."10000		! GET SPOOL MASK("10000)
	IF(ISPMSK.NE."10000)			! IF SPOOL ACCOUNTING NOT ON
     -	 WRITE(LUN3,170)LDATE			! TELL USER IT WAS OFF
170	 FORMAT(' '8A1,5X,'SPOOLER ACCOUNTING NOT STARTED')!
C	IF(ISPMSK.EQ."10000)	   		! IF SPOOL ACNTNG TURNED ON
C    -   WRITE(LUN3,175)LDATE			! TELL USER IT IS ACTIVE
C175      FORMAT(' '8A1,5X,'SPOOLER ACCOUNTING RUNNING')

190	IF(IREC.NE.10)		        GOTO 100! READ AGAIN IF NOT SPL PACKET
	IF(ISPMSK.NE."10000   .AND.		! BAD FORM TO START AFTER
     -	    IWARN.EQ.0)				! BUT ONLY WARN ONCE
     -   WRITE(LUN3,195)LDATE			! ACCOUNTING ALREADY STARTED
195	 FORMAT(' ' 8A1,5X,'SPOOLER ACCOUNTING RESTARTED,',!
     -	' SUBSEQUENT START/STOPS NOT FLAGED')!
	IWARN=1					! ONLY WARN FIRST TIME
	ENCODE(8,450,LTIME)IHR,IMIN,ISEC	! CONVERT TIME TO ASCII
450	FORMAT(I2,':',I2,':',I2)		!
	DO 460,I=1,8				! CONVERT SPACES TO 0'S
460	IF(LTIME(I).EQ.' ')LTIME(I)='0'		! TO MAKE PRETTY
	CALL R50ASC(3,ITKNM1,LPRTNM(1))		! CONVERT DESPOOLER NAME TO
	CALL R50ASC(3,ITKNM2,LPRTNM(4))		! ASCII
	WRITE(LUN3,900)LDATE,LTIME,		!
     -			IACNT,ITOTPG,ICOPYS,	!
     -                  (LPRTNM(I), I=1,6)	!
900	FORMAT(' '8A1,2X,8A1,3X,I6,5X,I6,5X,I6,11X,6A1)	!
	IJOBS=IJOBS+1				! BUMP UP JOB COUNT
	ITOTAL=ITOTAL+ITOTPG			! AND TOTAL PAGE COUNT
	IF(IACNT.LT.1 .OR. IACNT.GT.100) GOTO 100! NOT VALID ACNT NUMBER,SKIP
	JACNT(IACNT,1)=JACNT(IACNT,1)+ITOTPG	! ADD IN PAGES PRINTED
	JACNT(IACNT,2)=JACNT(IACNT,2)+1		! ADD IN ONE MORE JOB
	GOTO 100				! AND READ LOG FILE AGAIN

6000	WRITE(LUN3,6020)			! PUT OUT AN ACCOUNT SUMMARY
6020	FORMAT(' ',/,/,' PAGES OUTPUT BY ACCOUNT NUMBER')
	WRITE(LUN3,6040)			!
6040	FORMAT(' ACCOUNT #  # PAGES   #JOBS')	!
	DO 6100, I=1,100			!
	IF(JACNT(I,1).NE.0)			! ONLY PRINT IF VALID ACNT
     -  WRITE(LUN3,6060)I,JACNT(I,1),JACNT(I,2) ! OUTPUT ACNT #,PAGES,JOBS
6060	FORMAT(' ',1X,I4,6X,I4,6X,I4)		!
6100	CONTINUE				! END LOOP
	GOTO 9990				! CLOSE FILES AND EXIT
9000	WRITE(LUN1,9010) N,LFILE		! WE GOT AN ERROR, WARN USER
9010	FORMAT(' SPLREP -- OPEN ERROR, FILE NOT FOUND:',<N>A1)	!
	GOTO 9990				!
9050  	WRITE(LUN1,9060)			! IF DEFAULT FILE
9060	FORMAT(' SPLREP -- OPEN ERROR, FILE NOT FOUND: SYSLOG.DAT')!
	GOTO 9990
9100	WRITE(LUN1,9010)			! IF WE GET A READ ERROR
9110	FORMAT(' CPUREP -- READ ERROR IN LOGFILE') ! WARN USER OF READ ERROR
	GOTO 9990				!
9990	CLOSE(UNIT=LUN2)			! CLOSE UP AND EXIT
	WRITE(LUN3,9991)ITOTAL,IJOBS		!
9991	FORMAT(' ',/,/,				! SKIP TWO LINES
     -         ' TOTAL NUMBER OF PAGES OUTPUT = ',I5,/,!
     -         ' TOTAL NUMBER OF PRINT JOBS   = ',I5) ! 
	CLOSE(UNIT=LUN3)
9999	CONTINUE				!
	END					!
