	.TITLE	NOTICE	Allow User To List System Notices
	.IDENT	/1.01/

;++
;  Title:
;	NOTICE	Allow User To List System Notices
;
;  Facility:
;	Utility for listing contents of system notices files.
;	Run via NOTICE command defined by SYSLOGIN
;
;  Abstract:
;  Program to allow the user to read the system notices.
;  Most recent notice is written to the SYS$OUTPUT, then user is prompted
;  to see if more messages should be displayed.
;
;  Environment:
;	Native mode. No special considerations.
;
;  Author: 
;	Gary L. Grebus, Creation Date: 08-Apr-1980
;	Computer Center
;	Battelle Columbus Labs
;	505 King Ave.
;	Columbus, Ohio  43201
;
;  Modified by:
;	Gary L. Grebus, 09-Apr-1980
;	1.01 - Added automatic printing of date and time of notice.
;
;--

	.PAGE

;++
;  Functional Description:
;  Program copies  contents of most recent (highest version) of system
;  notices file.  User if prompted "More?" and if reply looks like yes, the
;  next lower version is printed.  If there are no notice files, 
;  a message is given.
;
;--


;  Define symbols

MSG_C_MAXREC=160			;Max length (chars) of message record

;  Local macros
	.MACRO	MSG	ADDR,LEN
	$RAB_STORE -
		RAB=OUT_RAB,-
		RBF='ADDR,-
		RSZ=#'LEN		;;Point RAB at message
	$PUT	RAB=OUT_RAB		;;Issue the message
	.ENDM	MSG

	.PSECT	RWDATA	RD,WRT,NOEXE,NOSHR,LONG

;  Local data

;  RMS blocks for files
MSG_FAB:
	$FAB	FAC=GET,-
		FNM=<SYS$MAIL:SYSMSG.TXT>,-
		NAM=MSG_NAM,-
		ORG=SEQ,RFM=VAR,-
		SHR=GET,XAB=MSG_XAB	;Notice file FAB

MSG_RAB:
	$RAB	FAB=MSG_FAB,-
		UBF=MSG_LINE,-
		USZ=MSG_C_MAXREC	;Notice file RAB

MSG_XAB:
	$XABDAT				;XAB  for getting creation date

MSG_NAM:
	$NAM	RSA=MSG_FULLSPEC,-
		RSS=NAM$C_MAXRSS	;NAM to get version number

OUT_FAB:
	$FAB	FAC=PUT,-
		FNM=<SYS$OUTPUT>,-
		ORG=SEQ,RFM=VAR,RAT=CR	;FAB for writing to the user

OUT_RAB:
	$RAB	FAB=OUT_FAB		;SYS$OUTPUT RAB

MSG_LINE:
	.BLKB	MSG_C_MAXREC		;Buffer for notice file records

MSG_FULLSPEC:
	.BLKB	NAM$C_MAXRSS		;Buffer to hold full notice file spec

NXT_VERS:
	.LONG	-1			;Next file version to open
	
VERS_TEXT:
	.BLKB	6			;Buffer for text of version number

VERS_TEXT_D:
	.LONG	6
	.ADDRESS	VERS_TEXT	;Desc for above buffer

VERS_L_TEXT:
	.BLKL	1			;Length of version string in buffer

VERS_CTL:
	.ASCID	/;!UL/			;Control string for coding version nr.

PROMPT:
	.ASCID	/More? /		;Prompt for user response 

NO_MSGS:
	.ASCII	/There are currently no system notices./
NO_MSGS_LEN=.-NO_MSGS

END_MSGS:
	.ASCII	/End of system notices./
END_MSGS_LEN=.-END_MSGS

RPLY_BUF:
	.BLKB	3			;Buffer to hold user's reply
RPLY_BUF_DESC:
	.LONG	3
	.ADDRESS	RPLY_BUF	;Desc for buffer

BLANK_LINE:
	.ASCII	/ /			;A blank

TIME_BUF:
	.BLKB	20			;Buffer to hold ASCII for notice date
					;and time
TIME_BUF_LEN=.-TIME_BUF

TIME_BUF_D:
	.LONG	TIME_BUF_LEN
	.ADDRESS	TIME_BUF	;Desc for above buffer

	.PAGE
	.PSECT	CODE	NOWRT,EXE,SHR,LONG
	.ENTRY	NOTICE,0

;+
;  Main program for NOTICE
;  Register usage:
;	No registers are used except R0-R1 (scratch).
;-

;  Loop through all the versions of the notice file
	$OPEN	FAB=OUT_FAB		;Open SYS$OUTPUT
	$CONNECT	RAB=OUT_RAB	;And connect it

OPN_MSG:
	$OPEN	FAB=MSG_FAB		;Open the notice file
	BLBS	R0,10$			;Branch if success
	BRW	NO_MORE			;No notices to send

10$:	$CONNECT	RAB=MSG_RAB	;Connect the file
	BLBS	R0,30$			;Branch if success
	BRW	NO_MORE			;If error - assume no notices

;  Prefix message with the date and time of creation
30$:	MSG	BLANK_LINE,1		;Leave a blank line
	$ASCTIM_S -
		TIMBUF=TIME_BUF_D,-
		TIMADR=<MSG_XAB+XAB$Q_CDT> ;Convert creation date and time
					;of file
	BLBC	R0,35$			;Skip this part if failure
	MSG	TIME_BUF,TIME_BUF_LEN	;Print date and time
	MSG	BLANK_LINE,1		;Leave a blank line

;  Loop copying notice file to SYS$OUTPUT
35$:	$GET	RAB=MSG_RAB		;Get a line
	BLBC	R0,40$			;Stop on any error
	$RAB_STORE -
		RAB=OUT_RAB,-
		RBF=MSG_LINE,-
		RSZ=<MSG_RAB+RAB$W_RSZ>	;Point output RAB at record
	$PUT	RAB=OUT_RAB		;Put the line
	BRB	35$			;Loop

40$:	MSG	BLANK_LINE,1		;Leave a blank line
	$CLOSE	FAB=MSG_FAB		;Close this notice file

;  Ask user if he wants to see more
	PUSHAL	PROMPT			;Arg 2 is prompt desc
	PUSHAL	RPLY_BUF_DESC		;Arg 1 is reply buffer desc
	CALLS	#2,LIB$GET_INPUT	;Get user's answer
	CMPB	RPLY_BUF,#^A/Y/		;Check for affirmative reply
	BEQL	50$			;Branch if so
	CMPB	RPLY_BUF,#^A/y/		;Maybe lower case?
	BEQL	50$			;Branch if so
	BRW	FIN			;User is done

;  Compute version for next file and adjust FAB
50$:	MOVZBL	MSG_NAM+NAM$B_RSL,R0	;Get length of full file spec
	LOCC	#^A/;/,R0,MSG_FULLSPEC	;Find beginning of the version nr.

	PUSHAL	NXT_VERS		;Arg 3 is dest of value
	ADDL3	#1,R1,-(SP)		;Arg 2 is string address+1
	SUBL3	#1,R0,-(SP)		;Arg 1 is string length-1
	CALLS	#3,LIB$CVT_DTB		;Convert version nr to binary
	DECL	NXT_VERS		;Next version to use is current-1
	BNEQ	60$			;Branch if version non_zero
	BRW	NO_MORE			;All versions checked

;  Supply new version via default file spec field in FAB
60$:	$FAO_S	CTRSTR=VERS_CTL,-
		OUTLEN=VERS_L_TEXT,-
		OUTBUF=VERS_TEXT_D,-
		P1=NXT_VERS		;Convert version to text
	$FAB_STORE -
		FAB=MSG_FAB,-
		DNA=VERS_TEXT,-
		DNS=VERS_L_TEXT		;Supply this version via default
	BRW	OPN_MSG			;Loop for this version	

;  No more notice files to write
NO_MORE:
	TSTL	NXT_VERS		;Check next version num
	BGEQ	10$			;Branch if still initial value
	MSG	NO_MSGS,NO_MSGS_LEN	;Issue the "No notices" message
	BRB	FIN

10$:	MSG	END_MSGS,END_MSGS_LEN	;Isue "No More" message

FIN:	$CLOSE	FAB=OUT_FAB		;Done with SYS$OUTPUT
	MOVL	#SS$_NORMAL,R0		;Signal normal completion
	RET				;Go home

	.END	NOTICE
	
