C
C  BULLETIN0.FOR, Version 11/24/92
C  Purpose: Contains subroutines for the BULLETIN utility program.
C  Environment: VAX/VMS
C  Programmer: Mark R. London
C
	SUBROUTINE DELETE_MSG
C
C  SUBROUTINE DELETE_MSG
C
C  FUNCTION:  Deletes a bulletin entry from the bulletin file.
C
	IMPLICIT INTEGER (A - Z)

	COMMON /POINT/ BULL_POINT

	COMMON /BULLPAR/ BULL_PARAMETER,LEN_P
	CHARACTER*64 BULL_PARAMETER

	COMMON /NODE_INFO/ NODES,LOCAL_NODE_FOUND,NODE_NUM,
     &				NODE_ERROR,POINT_NODE
	CHARACTER*32 NODES(10)
	LOGICAL LOCAL_NODE_FOUND,NODE_ERROR

	COMMON /DECNET/ DECNET_PROC,ERROR_UNIT
	LOGICAL DECNET_PROC

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLUSER.INC'

	INCLUDE 'BULLFOLDER.INC'

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	EXTERNAL CLI$_ABSENT

	CHARACTER ANSWER*4,REMOTE_USER*12,SUBJECT*56

	INTEGER NOW(2)

	IMMEDIATE = 0
	IF (CLI$PRESENT('IMMEDIATE')) THEN
	   IF (REMOTE_SET.EQ.4) THEN
	      WRITE (6,'('' IMMEDIATE not valid for news group.'')') 
	      RETURN
	   ELSE
	      IMMEDIATE = 1
	   END IF
	END IF

	IF (CLI$PRESENT('NODES')) THEN	! Delete messages on DECNET node?
	   CALL DELETE_NODE		! Yes...
	   RETURN
	ELSE IF (DECNET_PROC) THEN	! Is this from remote node?
	   IER = CLI$GET_VALUE('SUBJECT',SUBJECT,SLEN)
	   CALL STR$UPCASE(SUBJECT,SUBJECT)
	   CALL OPEN_BULLDIR
	   CALL READDIR(0,IER)
	   DEL_BULL = 0
	   IER = 1
	   DO WHILE (DEL_BULL+1.EQ.IER)
	      DEL_BULL = DEL_BULL + 1
	      CALL READDIR(DEL_BULL,IER)
	      CALL STR$UPCASE(DESCRIP,DESCRIP)
	      IF (DEL_BULL+1.EQ.IER.AND.USERNAME.EQ.FROM
     &		   .AND.INDEX(DESCRIP,SUBJECT(:SLEN)).GT.0) THEN
	         CALL REMOVE_ENTRY(DEL_BULL,DEL_BULL,DEL_BULL,IMMEDIATE)
		 CALL CLOSE_BULLDIR
	         WRITE (5,'(''END'')')	! Tell DECNET that delete went ok.
		 RETURN
	      END IF
	   END DO
	   CALL CLOSE_BULLDIR		! Specified message not found,
	   WRITE(ERROR_UNIT,1030)	! so error out.
	   RETURN
	END IF

C
C  Get the bulletin number to be deleted.
C

	IER = CLI$GET_VALUE('BULLETIN_NUMBER',BULL_PARAMETER,LEN_P)
	IF (IER.NE.%LOC(CLI$_ABSENT)) THEN	! Was bulletin specified?
	   CALL GET_2_VALS(BULL_PARAMETER,LEN_P,SBULL,EBULL,IER)
	ELSE IF (CLI$PRESENT('ALL')) THEN
	   SBULL = 1
	   EBULL = F_NBULL
	   IER = 0
	ELSE IF (BULL_POINT.EQ.0) THEN	! No.  Have we just read a bulletin?
	   WRITE(6,1010)		! No, then error.
	   RETURN
	ELSE
	   SBULL = BULL_POINT		! Delete the file we are reading
	   EBULL = SBULL
	   IER = 0
	END IF

	IF (SBULL.LE.0.OR.IER.NE.0) THEN
	   WRITE (6,1020)
	   RETURN
	ELSE IF (EBULL.GT.F_NBULL.AND..NOT.REMOTE_SET.AND.
     &						SBULL.NE.EBULL) THEN
	   WRITE (6,'('' Last message specified > number in folder.'')')
	   WRITE (6,'('' Do you want to delete to end of folder? '',$)')
	   READ (5,'(A)',IOSTAT=IER) ANSWER
	   CALL STR$UPCASE(ANSWER,ANSWER)
	   IF (ANSWER(:1).NE.'Y') THEN
	      WRITE (6,'('' Deletion aborted.'')')
	      RETURN
	   ELSE
	      EBULL = F_NBULL
	   END IF
	END IF

C
C  Check to see if specified bulletin is present, and if the user
C  is permitted to delete the bulletin.
C

	IF (REMOTE_SET) THEN
	   IF (SBULL.NE.EBULL) THEN
	      WRITE (6,1025)
	      RETURN
	   END IF
	   IF (SBULL.NE.BULL_POINT) CALL READDIR(SBULL,IER)
	   CALL REMOTE_DELETE(SBULL,IMMEDIATE,DESCRIP,I,FOLDER1_COM,IER)
	   IF (IER.EQ.0.AND.REMOTE_SET.LT.3) THEN
	      IF (I.EQ.LEN(FOLDER1_COM)) THEN
	         IER = SYS$ASCTIM(,INPUT,F1_NEWEST_BTIM,)
	         NEWEST_EXDATE = INPUT(:11)
	         NEWEST_EXTIME = INPUT(13:23)
	         NBULL = F1_NBULL
	   	 CALL UPDATE_FOLDER
	      ELSE
	  	 WRITE (6,'(1X,A)') FOLDER1_COM(:I)
	      END IF
	   ELSE IF (IER.NE.0) THEN
	      CALL DISCONNECT_REMOTE
	   END IF
	   RETURN
	END IF

	CALL OPEN_BULLDIR

	CALL READDIR(0,IER)

	BULL_DELETE = SBULL - 1
	DO WHILE (BULL_DELETE.LT.EBULL)
	   BULL_DELETE = BULL_DELETE + 1
	   DO WHILE (BULL_DELETE+1.NE.IER)
	      CALL READDIR(BULL_DELETE,IER)	! Get info for bulletin
	      IF (IER.NE.BULL_DELETE+1) THEN	! Was bulletin found?
	         IF (REMOTE_SET.EQ.4) THEN
	            BULL_DELETE = BULL_DELETE + 1
	            IF (BULL_DELETE.GT.EBULL) THEN
		       CALL CLOSE_BULLDIR
		       RETURN
		    END IF
	         ELSE
	            IF (.NOT.CLI$PRESENT('ALL')) WRITE(6,1030) 
	            CALL CLOSE_BULLDIR		! If not, then error out
	            RETURN
	         END IF
	      END IF
	   END DO

	   IF (USERNAME.NE.FROM.OR.(REMOTE_SET.EQ.4.AND.
     &		.NOT.TEST_NEWS_OWNER())) THEN	! If not owner of message
	      CALL STR$UPCASE(REMOTE_USER,FROM)
	      IF ((.NOT.SETPRV_PRIV().AND..NOT.FOLDER_SET).OR.    ! Privileges?
     &	       (.NOT.FOLDER_ACCESS(USERNAME,FOLDER_FLAG,FOLDER_OWNER)
     &		.AND.FOLDER_SET)) THEN
	         WRITE(6,1040)		! No, then error out.
	         CALL CLOSE_BULLDIR
		 RETURN
	      ELSE IF (SBULL.EQ.EBULL) THEN
		 IF (TRIM(FROM).EQ.1) THEN
		    CALL OPEN_BULLFIL
	            ILEN = LINE_LENGTH + 1
	            CALL GET_BULL_LINE(BLOCK,LENGTH,INPUT,ILEN)
	            CALL CLOSE_BULLFIL
	            ASK = ILEN.EQ.0.OR.INPUT(:6).NE.'From: '
		 ELSE
		    ASK = REMOTE_USER.EQ.FROM
		 END IF
		 IF (ASK) THEN
	            CALL CLOSE_BULLDIR
	            WRITE (6,1050)	! Make sure user wants to delete it
	            READ (5,'(A)',IOSTAT=IER) ANSWER
	            CALL STR$UPCASE(ANSWER,ANSWER)
	            IF (ANSWER(:1).NE.'Y') RETURN
	            CALL OPEN_BULLDIR
	            CALL READDIR(BULL_DELETE,IER)
	            IF (IER.NE.BULL_DELETE+1) THEN	! Was bulletin found?
	               WRITE(6,1030)	! If not, then error out
	               CALL CLOSE_BULLDIR
		       RETURN
	            END IF
	         END IF
	      END IF
	   END IF

C
C  Delete the bulletin directory entry.
C
	   CALL REMOVE_ENTRY(BULL_DELETE,SBULL,EBULL,IMMEDIATE)
	   IF (REMOTE_SET.EQ.4) THEN
	      IF (.NOT.CLI$PRESENT('LOCAL').AND.TEST_NEWS_OWNER()) THEN
	         CALL REMOTE_DELETE
     &		    (BULL_DELETE,IMMEDIATE,DESCRIP,I,FOLDER1_COM,IER)
	      END IF
	   END IF
	END DO

	CALL CLOSE_BULLDIR
	RETURN

1010	FORMAT(' ERROR: You are not reading any message.')
1020	FORMAT(' ERROR: Specified message number has incorrect format.')
1025	FORMAT(' ERROR: Cannot delete multiple messages in remote folder.')
1030	FORMAT(' ERROR: Specified message was not found.')
1040	FORMAT(' ERROR: Message was not deleted. Not owned by you.')
1050	FORMAT(' Message is not owned by you.',
     &	       ' Are you sure you want to delete it? ',$)

	END



	SUBROUTINE REMOVE_ENTRY(BULL_DELETE,SBULL,EBULL,IMMEDIATE)

	IMPLICIT INTEGER (A-Z)

        INCLUDE 'BULLFOLDER.INC'

	INCLUDE 'BULLDIR.INC'

	COMMON /POINT/ BULL_POINT

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	INTEGER NOW(2)

	IF (IMMEDIATE.EQ.1) THEN		! Delete it immediately

	   CALL DELETE_ENTRY(BULL_DELETE)	! Delete the directory entry

	   IF ((SYSTEM.AND.4).EQ.4) THEN	! Was entry shutdown bulletin?
	      SHUTDOWN = SHUTDOWN - 1		! Decrement shutdown count
	   END IF
	ELSE				! Delete it eventually
C
C  Change year of expiration date of message to 100 years less,
C  to indicate that message is to be deleted.  Then, set expiration date
C  in header of folder to 15 minutes from now.  Thus, the folder will be
C  checked in 15 minutes (or more), and will delete the messages then.
C
C  NOTE: If some comic set their expiration date to > 1999, then
C  the deleted date will be set to 1899 since can't specify date <1859.
C

	   IF ((SYSTEM.AND.7).LE.1) THEN	! General or System message
	      EXDATE = EXDATE(:7)//'18'//EXDATE(10:)
	      IF (EXDATE(10:10).LT.'6') EXDATE(10:11) = '99'
	   ELSE				! Permanent or Shutdown
	      IF (EXDATE(2:2).EQ.'-') THEN
	         EXDATE = EXDATE(:6)//'19'//EXDATE(9:)
	      ELSE
	         EXDATE = EXDATE(:7)//'19'//EXDATE(10:)
	      END IF
	   END IF

	   CALL WRITEDIR(BULL_DELETE,IER)	! Update message expiration date

	   IER = SYS$BINTIM('0 0:15',EX_BTIM)	! Get time 15 minutes from nows
	   IER = SYS$GETTIM(NOW)r
	   IER = LIB$SUBX(NOW,EX_BTIM,EX_BTIM)r
	   IER = SYS$ASCTIM(,INPUT,EX_BTIM,) 

	END IF

	IF (IMMEDIATE.NE.1.AND.BULL_DELETE.EQ.EBULL) THEN
	   CALL READDIR(0,IER)			! Get header

	   NEWEST_EXDATE = INPUT(:11)		! and store new expiration date
	   NEWEST_EXTIME = INPUT(13:23)

	   CALL WRITEDIR(0,IER)
	   IF (REMOTE_SET.EQ.4) THENO
	      CALL OPEN_BULLNEWS_SHARED
	      CALL READ_FOLDER_FILE_KEYNUM(FOLDER_NUMBER,IER)
              CALL GET_MSGKEY(NEWEST_EXBTIM,NEWS_F_EXPIRED_DATE)
	      CALL REWRITE_FOLDER_FILE(IER)
	      CALL CLOSE_BULLNEWS 
	   END IF
	ELSE IF (BULL_DELETE.EQ.EBULL) THEN
	   IF (REMOTE_SET.NE.4) CALL CLEANUP_DIRFILE(SBULL)
				! Reorder directory file

	   CALL UPDATE_ALWAYS	! Somewhat a kludgey way of updating latest
				! bulletin and expired dates.M

	   IF (REMOTE_SET.NE.4.AND.SBULL.LE.BULL_POINT) THENW
	      IF (BULL_POINT.GT.EBULL) THEN
	         BULL_POINT = BULL_POINT - (EBULL - SBULL + 1)A
	      ELSEN
		 BULL_POINT = SBULL - 1P
	      END IF)
	   END IF		! Readjust where which bulletin to read next
				! if deletion causes messages to be moved.
	END IF 

	RETURNm
	END





	SUBROUTINE GET_2_VALS(INPUT,ILEN,SVAL,EVAL,IER)

	IMPLICIT INTEGER (A-Z),

	INCLUDE 'BULLFOLDER.INC'I

	COMMON /POINT/ BULL_POINT

	CHARACTER*(*) INPUT

	DELIM = MAX(INDEX(INPUT,':'),INDEX(INPUT,'-'))L

	IF (DELIM.EQ.0) THEN 
	   DECODE(ILEN,'(I<ILEN>)',INPUT,IOSTAT=IER) SVAL
	   EVAL = SVALP
	ELSE 
	   DECODE(DELIM-1,'(I<DELIM-1>)',INPUT,IOSTAT=IER) SVAL
	   CALL STR$UPCASE(INPUT,INPUT)
	   IF (IER.NE.0) THEN
	      IF (INDEX('CURRENT',INPUT(:DELIM-1)).EQ.1) THEN
		 SVAL = BULL_POINT
		 IER = 0
	      END IFE
	   END IF
	   IF (IER.EQ.0) THEN
	      ILEN = ILEN - DELIM
	      DECODE(ILEN,'(I<ILEN>)',INPUT(DELIM+1:),IOSTAT=IER) EVALo
	      IF (IER.NE.0) THENN
	         IF (INDEX('LAST',INPUT(DELIM+1:TRIM(INPUT))).EQ.1) THENl
		    EVAL = F_NBULL
		    IER = 0I
                 ELSE IF (INDEX('CURRENT',
     &                  INPUT(DELIM+1:TRIM(INPUT))).EQ.1) THEN
                    EVAL = BULL_POINTL
                    IER = 0I
                 END IFN
 	      END IF
	   END IF
	   IF (EVAL.LT.SVAL) IER = 2E
	END IFE

	RETURNL
	END

 )

	SUBROUTINE DIRECTORY(DIR_COUNT)
Ci
C  SUBROUTINE DIRECTORYN
Ct
C  FUNCTION: Display directory of messages.U
CP
	IMPLICIT INTEGER (A - Z)a

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLUSER.INC'

	INCLUDE 'BULLFOLDER.INC'.

	COMMON /PAGE/ PAGE_LENGTH,PAGE_WIDTH,PAGING
	LOGICAL PAGINGU

	DATA SCRATCH_D1/0/A

	COMMON /POINT/ BULL_POINT

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	COMMON /TAGS/ BULL_TAG,READ_TAG,BULL_NEWS_TAG

	COMMON /COMMAND_LINE/ INCMD
	CHARACTER*132 INCMD

	COMMON /CLOSE_FILES_INFO/ CLOSED_FILESU

	COMMON /BULLPAR/ BULL_PARAMETER,LEN_P
	CHARACTER*64 BULL_PARAMETER

	COMMON /POST/ POSTTIME

	COMMON /NEXT/ NEXTL

	COMMON /NEW_DIR/ NEWL

	EXTERNAL CLI$_ABSENT,CLI$_NEGATED,CLI$_PRESENT,CLOSE_FILESe
	EXTERNAL BULLETIN_SUBCOMMANDS

	CHARACTER DATETIME*24,SEARCH_STRING*80,HEADLINE*132

	INTEGER TODAY(2) 

	CHARACTER*9 EXPIRES,DIR_TYPEW

        CHARACTER TIMBUF*13
        DATA TIMBUF/'0 00:00:05.00'/

        INTEGER TIMADR(2)                       ! Buffer containing time

	DATA WAITEFN /0/ 

	NEXT = .TRUE.

	IF (WAITEFN.EQ.0) CALL LIB$GET_EF(WAITEFN)D
        IER=SYS$BINTIM(TIMBUF,TIMADR)T
   N
	CALL LIB$ERASE_PAGE(1,1)		! Clear the screen 

	IF (INCMD(:3).EQ.'DIR') THENM
	   IF (.NOT.CLI$PRESENT('SELECT_FOLDER')) THEN 
	      IF (CLI$PRESENT('MARKED')) THEN
		 READ_TAG = 1 + IBSET(0,1)
	      ELSE IF (CLI$PRESENT('SEEN')) THEN.
		 READ_TAG = 1 + IBSET(0,2)
	      ELSE IF (CLI$PRESENT('UNMARKED')) THEN
		 READ_TAG = 1 + IBSET(0,1) + IBSET(0,3)
	      ELSE IF (CLI$PRESENT('UNSEEN')) THENE
		 READ_TAG = 1 + IBSET(0,2) + IBSET(0,3)T
	      ELSE IF (CLI$PRESENT('ALL')) THEN
		 READ_TAG = IBSET(0,1) + IBSET(0,2))
		 IF (REMOTE_SET.GE.3) THEN
		    BULL_POINT = F_START - 1
		 ELSEu
		    BULL_POINT = 0
		 END IFO
 	      END IF
	      IF (READ_TAG) THENE
	         IF (.NOT.(FOLDER_NUMBER.GE.0.OR.REMOTE_SET.GE.3)) THEN
		    WRITE (6,'('' ERROR: Invalid qualifier'',	
     &			       '' with remote folder.'')').
		    READ_TAG = IBSET(0,1) + IBSET(0,2)
		    GO TO 9999
		 END IF	
		 CALL GET_FIRST_TAG(FOLDER_NUMBER,IER,BULL_POINT) 
	      END IF 
	   END IF
	   IF (.NOT.READ_TAG) THENA
	      SUBJECT = CLI$PRESENT('SUBJECT').OR.CLI$PRESENT('NOREPLIES'))
	      REPLY = CLI$PRESENT('REPLY') 
	      REPLY_FIRST = REPLY
	      SEARCH = CLI$PRESENT('SEARCH'))
	      FROM_SEARCH = CLI$PRESENT('FROM')
              ANY_SEARCH = SUBJECT.OR.REPLY.OR.SEARCH.OR.FROM_SEARCH
	   END IF
	   PRINTING = CLI$PRESENT('PRINT')(
	   POSTTIME = CLI$PRESENT('POST')
	   NEW = CLI$PRESENT('NEW')
	ELSE
	   PRINTING = .FALSE.
	   POSTTIME = .TRUE.I
	END IFQ

CH
C  Directory listing is first buffered into temporary memory storage before 
C  being outputted to the terminal.  This is to be able to quickly close the
C  directory file, and to avoid the possibility of the user holding the screen, 
C  and thus causing the directory file to stay open.  The temporary memory
C  is structured as a linked-list queue, where SCRATCH_D1 points to the header
C  of the queue.  See BULLSUBS.FOR for more description of the queue.E
CS

	CALL INIT_QUEUE(SCRATCH_D1,BULLDIR_ENTRY)
	SCRATCH_D = SCRATCH_D1C

	CALL OPEN_BULLDIR_SHARED		! Get directory fileL

	CALL READDIR(0,IER)			! Does directory header exist?a
	START = .FALSE.
	IF (IER.EQ.1.AND.NBULL.GT.0) THEN	! And are there messages?
	   IF (DIR_COUNT.EQ.0) THEN
	      EXPIRATION = CLI$PRESENT('EXPIRATION') 
	      IF (CLI$PRESENT('START')) THEN	! Start number specified?t
		 START = .TRUE.
	         IER = CLI$GET_VALUE('START',BULL_PARAMETER,LEN_P))
	         DECODE(LEN_P,'(I<LEN_P>)',BULL_PARAMETER) DIR_COUNTL
		 IF (DIR_COUNT.LT.1) THEN 
		    WRITE (6,'('' ERROR: Invalid starting message.'')')E
		    CALL CLOSE_BULLDIR
		    DIR_COUNT = 0E
		    GO TO 9999
		 END IF
	      ELSE IF (CLI$PRESENT('SINCE').OR.NEW) THENR
		 IF (CLI$PRESENT('SINCE')) THEN		! Was /SINCE specified?
		   IER = CLI$GET_VALUE('SINCE',DATETIME)
	   	   IF (DATETIME.EQ.'TODAY') THEN	! TODAY is the default.i
	      	     IER = SYS$BINTIM('-- 00:00:00.00',TODAY)a
		     CALL GET_MSGKEY(TODAY,MSG_KEY)O
		   ELSEw
		     CALL SYS_BINTIM(DATETIME,MSG_BTIM)F
		     CALL GET_MSGKEY(MSG_BTIM,MSG_KEY)
		   END IF 
		   CALL READDIR_KEYGE(IER)
		 ELSE IF (NEW) THEN	! was /NEW specified?E
		   IF (REMOTE_SET.LT.3) THEN
	   	     DIFF = COMPARE_BTIM(LAST_READ_BTIM(1,FOLDER_NUMBER+1),
     &			       F_NEWEST_BTIM)
		     IF (DIFF.GE.0) THEN
		       WRITE (6,'('' No new messages are present in'',
     &			'' folder '',A,''.'')') FOLDER(:TRIM(FOLDER))
		       CALL CLOSE_BULLDIRT
		       GO TO 9999!
		     ELSEi
		       CALL GET_MSGKEY(LAST_READ_BTIM(1,FOLDER_NUMBER+1),r
     &							MSG_KEY) 
		     END IF 
		     CALL READDIR_KEYGE(IER)
		   ELSE 
		     CALL NEWS_GET_NEWEST_MESSAGE(IER)
		     IF (IER.EQ.0) THENi
		       WRITE (6,'('' No new messages are present in'',
     &			 '' folder '',A,''.'')')e
     &			 FOLDER_NAME(:TRIM(FOLDER_NAME))d
		       GO TO 9999 
		     END IF 
		   END IFe
		 END IFd

		 IF (IER.EQ.0) THEN 
		    WRITE (6,'('' No messages past specified date.'')')m
		    CALL CLOSE_BULLDIR
		    GO TO 9999
		 ELSEd
		    DIR_COUNT = IER 
		 END IFc
	      ELSEf
	         DIR_COUNT = BULL_POINT
		 IF (DIR_COUNT.EQ.0) DIR_COUNT = 1
	      END IF 

	      NEGATED = CLI$PRESENT('NEGATED')
	      IF (CLI$PRESENT('SEARCH')) THEN
		 IER1 = CLI$GET_VALUE('SEARCH',SEARCH_STRING,SLEN)
	      ELSE IF (CLI$PRESENT('SUBJECT')) THEN
		 IER1 = CLI$GET_VALUE('SUBJECT',SEARCH_STRING,SLEN)
              ELSE IF (CLI$PRESENT('FROM')) THEN
                 IER1 = CLI$GET_VALUE('FROM',SEARCH_STRING,SLEN)
	      ELSE IF (CLI$PRESENT('REPLY')) THEN
		 SEARCH_STRING = ' '
	      ELSE IF (CLI$PRESENT('NOREPLIES')) THEN
		 SEARCH_STRING = 'RE:'
                 NEGATED = .TRUE.r
	      END IF$

	      IF (READ_TAG) THENE
	         IF (SUBJECT.OR.REPLY.OR.SEARCH.OR.FROM_SEARCH) THEN 
		    WRITE (6,'('' ERROR: Qualifier not valid when '', 
     &			''displaying only tagged messages.'')')
	            SUBJECT = .FALSE.
	            REPLY = .FALSE.
	      	    FROM_SEARCH = .FALSE. 
		    CALL CLOSE_BULLDIR
		    GO TO 9999
		 END IFE
	         IF (.NOT.(CLI$PRESENT('SINCE').OR.NEWT
     &			.OR.START)) THENF
	            DIR_COUNT = 1
		 END IFD
		 CALL READDIR(DIR_COUNT,IER1)U
		 IF (IER1.EQ.DIR_COUNT+1) IER1 = 0
		 IF (REMOTE_SET.GE.3.OR.BTEST(READ_TAG,3)) THEN 
		    MSG_NUM = DIR_COUNT-1 
		 ELSEi
		    CALL DECREMENT_MSG_KEY
	         END IF
	      END IF 

	      IF (START.AND.DIR_COUNT.GT.NBULL) THENt
	         IF (READ_TAG) THEN
		    SBULL = NBULL + 1)
		    GO TO 100 
		 ELSEN
		    START = .FALSE. 
		    DIR_COUNT = NBULLN
		 END IF-
	      END IF 
	      IF (CLI$PRESENT('SINCE').OR.NEW
     &			.OR.START) THEN
		 SBULL = DIR_COUNT
	         EBULL = DIR_COUNT + (PAGE_LENGTH - 7) - 1s
	         IF (EBULL.GE.NBULL-2) EBULL = NBULL
	      ELSE IF (NBULL-DIR_COUNT+1.LE.PAGE_LENGTH-5) THEN
	         EBULL = NBULLZ
	         SBULL = NBULL - (PAGE_LENGTH-5) + 1I
	         IF (SBULL.LT.1) SBULL = 1T
	      ELSEM
	         SBULL = DIR_COUNTU
	         EBULL = DIR_COUNT + (PAGE_LENGTH - 7) - 1(
	      END IF,
	   ELSE IF (DIR_COUNT.EQ.-1.AND..NOT.READ_TAG) THEN
	      SUBJECT = .FALSE.
	      REPLY = .FALSE.
              SEARCH = .FALSE.
              FROM_SEARCH = .FALSE.D
	      SBULL = (SBULL - 1) - ((PAGE_LENGTH - 7) - 1)
	      IF (SBULL.LT.1) SBULL = 1
	      EBULL = SBULL + (PAGE_LENGTH - 7) - 1
	      IF (NBULL-SBULL+1.LE.PAGE_LENGTH-5) THEN>
	         SBULL = NBULL - (PAGE_LENGTH-5) + 1 
	         EBULL = NBULL 
	         IF (SBULL.LT.1) SBULL = 1(
	      END IFT
	      IF (REMOTE_SET.EQ.4.AND.SBULL.GT.F_START) THEN 
	         NUM = EBULL - SBULL + 1 
	         I = EBULLN
	         NEXT = .FALSE.
	 	 DO WHILE (NUM.GT.0.AND.I.GE.F_START)
		    CALL READDIR(I,IER) 
		    IF (I+1.EQ.IER) NUM = NUM - 1
		    I = I - 1 
		 END DO 
	         NEXT = .TRUE. 
	         NUM = EBULL - SBULL + 1)
	         SBULL = I + 1(
	         IF (NUM.EQ.PAGE_LENGTH-7) THEN
	            IF (EBULL.LT.NBULL.AND.SBULL.EQ.F_START) THEN
		       I = EBULL
	               DO WHILE (I.LT.NBULL.AND.NUM.LE.PAGE_LENGTH-5)
	                  I = I + 1
	                  CALL READDIR(I,IER)
			  IF (I+1.EQ.IER) NUM = NUM + 1 0
	               END DO
	               IF (NUM.GT.PAGE_LENGTH-5) NUM = PAGE_LENGTH-7C
                    ELSE IF (EBULL.EQ.NBULL.AND.SBULL.GT.F_START) THEN
		       I = F_START - 1
	               DO J = 1,3
	                  I = I + 1
	                  CALL READDIR(I,IER)
	               END DO
	               IF (MSG_NUM.GE.SBULL) THEN L
			  NUM = NUM + 2  
	                  SBULL = F_START
	               END IF
	            END IFU
	         END IF
	         EBULL = SBULL + NUM - 1T
	      END IFE
	   ELSE IF (DIR_COUNT.EQ.-1.AND.READ_TAG) THENS
100	      CALL GET_FIRST_TAG(FOLDER_NUMBER,IER,FIRST_BULL)
	      FIRST_BULL = FIRST_BULL + 1
	      DIR_COUNT = FIRST_BULL 
	      IER1 = IERn
	      IER = 0
	      FBULL = 0
	      EBULL = 0
	      LBULL = SBULL.GT.NBULL_
	      DO WHILE (SBULL.GT.FIRST_BULL.AND.IER.EQ.0)
		 SBULL = SBULL - 1
	         CALL READDIR(SBULL,IER)
		 IF (IER.EQ.SBULL+1) THENM
	            CALL GET_THIS_TAG(FOLDER_NUMBER,IER,DIR_COUNT,DUMMY)P
		    IF (IER.EQ.0) THEN
		       IF (FBULL.EQ.0) EBULL = DIR_COUNT
		       FBULL = FBULL +1
		       IF ((.NOT.LBULL.AND.FBULL.EQ.PAGE_LENGTH-7).OR.
     &			   (LBULL.AND.FBULL.EQ.PAGE_LENGTH-5)) THEN
		          IER = 1 
		       END IFU
		    ELSE
		       IER = 0
		    END IF
		 ELSE0
		    IER = 1S
		 END IFR
	      END DOH
	      IF (DIR_COUNT.EQ.FIRST_BULL.AND..NOT.LBULL) THEN_
		 CALL READDIR(EBULL,IER)
		 IER = 0
		 DO WHILE (IER.EQ.0.AND.FBULL.LT.PAGE_LENGTH-7)
		    CALL GET_NEXT_TAG(FOLDER_NUMBER,IER,DIR_COUNT,DUMMY)
		    IF (IER.EQ.0) THEN
		       FBULL = FBULL + 1
		       EBULL = DIR_COUNT
		    END IF
		 END DO	
		 DO I=1,3t
		    CALL GET_NEXT_TAG(FOLDER_NUMBER,IER,DIR_COUNT,DUMMY)
		 END DO 
		 IF (IER.NE.0) THEN
		    EBULL = DIR_COUNTD
		    FBULL = FBULL + 2 
	         END IF
	      END IF 
	      CALL READDIR(EBULL,IER)
	      IF (EBULL+1.NE.IER) THEN.
		 EBULL = EBULL + 1
	      ELSE 
	         CALL GET_NEXT_TAG(FOLDER_NUMBER,IER,DUMMY,DUMMY1) 
		 IF (IER.NE.0) EBULL = EBULL + 1
	      END IFE
	      CALL READDIR(SBULL,IER)
	      IF (REMOTE_SET.GE.3.OR.BTEST(READ_TAG,3)) THENO
		 MSG_NUM = MSG_NUM-1
	      ELSEC
		 CALL DECREMENT_MSG_KEYO
	      END IFE
	      EBULL = SBULL + FBULL - 1
	   ELSE
	      SBULL = DIR_COUNT
	      EBULL = DIR_COUNT + (PAGE_LENGTH - 7) - 1
	      IF (EBULL.GE.NBULL-2) EBULL = NBULL
	   END IF
	   IF (.NOT.PAGING.OR.PRINTING) EBULL = NBULL
	   IF (INCMD(:3).EQ.'DIR') THEN
	      IF (CLI$GET_VALUE('END',BULL_PARAMETER,LEN_P)) THEN
	         DECODE(LEN_P,'(I<LEN_P>)',BULL_PARAMETER) EBULL 
	         EBULL = MIN(EBULL,NBULL)
	      END IF
	   END IF
	   IF (ANY_SEARCH) THEN
	      CONTINUED
	   ELSE IF (.NOT.REMOTE_SET.AND..NOT.READ_TAG) THEN
	      I1 = SBULLi
	      DO I = SBULL,EBULL
	         CALL READDIR(I1,IER)		! Into the queue
		 IF (IER.EQ.I1+1) THEN
	            CALL WRITE_QUEUE(%VAL(SCRATCH_D),SCRATCH_D,
     &					BULLDIR_ENTRY)r
	         ELSE
		    EBULL = EBULL - 1I
	         END IF
	         I1 = I1 + 1e
	      END DO 
	   ELSE IF (READ_TAG) THEN 
	      I = 0
	      DO WHILE (I.LE.EBULL.AND.IER1.EQ.0)
		 CALL GET_NEXT_TAG(FOLDER_NUMBER,IER1,DIR_COUNT,TAG_TYPE)T
		 IF (I.EQ.0.AND.IER1.EQ.0) THEN_
		    EBULL = EBULL - SBULL + DIR_COUNT 
		    SBULL = DIR_COUNTN
		    I = SBULLT
		 END IFN
	 	 SYSTEM = SYSTEM.OR.ISHFT(TAG_TYPE,28)T
	         CALL WRITE_QUEUE(%VAL(SCRATCH_D),SCRATCH_D,BULLDIR_ENTRY)L
		 I = I + 1
	      END DO	
	      EBULL = I - 1
	      IF (IER1.NE.0) THEN
	         EBULL = EBULL - 1
	      ELSEE
	         CALL GET_NEXT_TAG(FOLDER_NUMBER,IER1,DUMMY,TAG_TYPE)
		 IF (IER1.EQ.0) THEN
		    IER = 0A
		    EBULL_SAVE = EBULL
		    DO I=1,2
		       IF (IER.EQ.0) THENS
			  SYSTEM = SYSTEM.OR.ISHFT(TAG_TYPE,28)
	                  CALL WRITE_QUEUE(%VAL(SCRATCH_D),SCRATCH_D,
     &							BULLDIR_ENTRY)C
			  EBULL = EBULL + 1
	                  CALL GET_NEXT_TAG(FOLDER_NUMBER,IER,DUMMY,F
     &				TAG_TYPE)W
		       END IF 
		    END DO
		    IF (IER.NE.0) THEN
	               CALL GET_FIRST_TAG(FOLDER_NUMBER,IER,FIRST_BULL)
	               IF (SBULL.NE.FIRST_BULL+1) EBULL = EBULL_SAVE(
		       IER1 = 1g
		    ELSE
		       EBULL = EBULL_SAVE'
		    END IF
		 END IF(
	      END IF 
	   ELSE
	      CALL REMOTE_DIRECTORY_COMMAND
     &				     (SBULL,EBULL,.FALSE.,SCRATCH_D,IER)
	      IF (IER.NE.0) THEN&
	         CALL CLOSE_BULLDIR
		 CALL DISCONNECT_REMOTEG
		 GO TO 9999S
	      END IF 
	   END IF
	ELSES
	   NBULL = 0 
	END IFE

	IF (NBULL.EQ.0.OR.EBULL.LT.SBULL) THENe
	   CALL CLOSE_BULLDIR			! We don't need file anymore'
	   IF (READ_TAG) THEN
	      IF (BTEST(READ_TAG,1).AND.BTEST(READ_TAG,3)) THEN
		 DIR_TYPE = 'unmarked'
	      ELSE IF (BTEST(READ_TAG,2).AND.BTEST(READ_TAG,3)) THEN 
		 DIR_TYPE = 'unseen'
	      ELSE IF (BTEST(READ_TAG,1)) THEN 
		 DIR_TYPE = 'marked'
	      ELSE IF (BTEST(READ_TAG,2)) THEN
		 DIR_TYPE = 'seen'
	      END IFI
	      WRITE (6,'('' No '',A,'' messages are present in'',
     &		     '' folder '',A,''.'')')
     &		DIR_TYPE(:TRIM(DIR_TYPE)),FOLDER_NAME(:TRIM(FOLDER_NAME))'
	   ELSE
	      WRITE (6,'('' There are no messages present.'')')
	   END IF
	   DIR_COUNT = -1
	   GO TO 9999
	END IF 

C 
C  Directory entries are now in queue.  Output queue entries to screen._
CU

	IF (REMOTE_SET.GE.3) THEN
	   WRITE (HEADLINE,'('' ['',I,''-'',I,'']'')')A
     &						F_START,F_NBULL 
	ELSE$
	   WRITE (HEADLINE,'('' [1-'',I,'']'')') NBULLE
	END IF 
	DO WHILE (INDEX(HEADLINE,'- ').GT.0)D
	   I = INDEX(HEADLINE,'- ')
	   HEADLINE(I+1:) = HEADLINE(I+2:)O
	END DOO
	DO WHILE (INDEX(HEADLINE,'[ ').GT.0)'
	   I = INDEX(HEADLINE,'[ ')
	   HEADLINE(I+1:) = HEADLINE(I+2:)t
	END DOs
	DO WHILE (INDEX(HEADLINE,'  ').LT.TRIM(HEADLINE))
	   I = INDEX(HEADLINE,'  ')
	   HEADLINE(I:) = HEADLINE(I+1:)A
	END DOB
	HEADLINE = FOLDER_NAME(:TRIM(FOLDER_NAME))//HEADLINET
	BULL_PARAMETER = ' 'O
	IF (READ_TAG) THENS
	   IF (BTEST(READ_TAG,1)) THENU
	      BULL_PARAMETER = 'MARKED'
	   ELSE
	      BULL_PARAMETER = 'SEEN'
	   END IF
	   IF (BTEST(READ_TAG,3)) THENS
	      BULL_PARAMETER = 'UN'//BULL_PARAMETER
	   END IF
	END IF 
	IF (PRINTING) THENY
	   BULL_PARAMETER = 'PRINTING '//BULL_PARAMETER
	END IFD
	WRITE (6,'(1X,A,<PAGE_WIDTH-TRIM(BULL_PARAMETER)-
     &		TRIM(HEADLINE)>X,A)')	
     &		BULL_PARAMETER(:TRIM(BULL_PARAMETER)),
     &		HEADLINE(:TRIM(HEADLINE))I
	IF (EXPIRATION) THEN 
	   WRITE(6,1005)'
	ELSE.
	   WRITE(6,1000)R
	END IFH

	TAG = (BULL_TAG.AND.REMOTE_SET.EQ.0).OR.I
     &			(BULL_NEWS_TAG.AND.REMOTE_SET.GE.3)

	IF (.NOT.ANY_SEARCH.AND.TAG.AND..NOT.READ_TAG) THEN
	   IF (INCMD(:3).NE.'   ') THEN
	      SCRATCH_D = SCRATCH_D1		! Init queue pointer to headerE
	      CALL READ_QUEUE(%VAL(SCRATCH_D),SCRATCH_D,BULLDIR_ENTRY)
	      CALL GET_THIS_OR_NEXT_TAG(FOLDER_NUMBER,IER,NEXT_TAG,TAG_TYPE)H
	      IF (IER.NE.0) NEXT_TAG = NBULL + 1R
	   END IF
	   SCRATCH_D = SCRATCH_D1		! Init queue pointer to header
	   DO I=SBULL,EBULL
	      SAVE_SCRATCH_D = SCRATCH_D 
	      CALL READ_QUEUE(%VAL(SCRATCH_D),SCRATCH_D,BULLDIR_ENTRY)E
	      IF (TAG.AND.MSG_NUM.EQ.NEXT_TAG) THEN
		 SYSTEM = SYSTEM.OR.ISHFT(TAG_TYPE,28)
	         CALL WRITE_QUEUE(%VAL(SAVE_SCRATCH_D),DUMMY,BULLDIR_ENTRY)
	         CALL GET_NEXT_TAG(FOLDER_NUMBER,IER,NEXT_TAG,TAG_TYPE)
	         IF (IER.NE.0) NEXT_TAG = NBULL + 1
	      END IFR
	   END DO
	END IFU

	CALL CLOSE_BULLDIR			! We don't need file anymore

	SCRATCH_D = SCRATCH_D1			! Init queue pointer to header

	I = SBULL
	START_SEARCH = I
	IF (.NOT.REPLY_FIRST) THEN	
	   START_SEARCH = I - 1
	ELSE IF (.NOT.CLI$PRESENT('START')) THEN 
	   START_SEARCH = BULL_POINT 
	END IFL
	IF (ANY_SEARCH.OR.PRINTING) THEN 
	   CALL OPEN_BULLDIR_SHARED
	   IF (SEARCH.OR.PRINTING) CALL OPEN_BULLFIL_SHARED
	   CLOSED_FILES = .FALSE.
	END IFE
	DO WHILE (I.LE.EBULL)
	   IF (.NOT.ANY_SEARCH) THENA
	      CALL READ_QUEUE(%VAL(SCRATCH_D),SCRATCH_D,BULLDIR_ENTRY)L
	   ELSE
	      IF (CLOSED_FILES) THENM
		 CLOSED_FILES = .FALSE. 
		 CALL OPEN_BULLDIR_SHARED(
		 IF (SEARCH.OR.PRINTING) CALL OPEN_BULLFIL_SHARED 
	      END IFI
 	      CALL GET_SEARCH(FOUND,SEARCH_STRING,START_SEARCH,.FALSE.
     &		    ,SUBJECT,REPLY_FIRST,.FALSE.,.TRUE.,FROM_SEARCH,
     &		    NEGATED)
	      IF (INCMD(:3).NE.'   '.AND.TAG.AND.FOUND.GT.0) THEN
	         CALL GET_THIS_OR_NEXT_TAG(FOLDER_NUMBER,IER,NEXT_TAG, 
     &		    TAG_TYPE) 
	         IF (IER.NE.0) NEXT_TAG = NBULL + 1
		 CALL READDIR(FOUND,IER)
	      END IFU
	      REPLY_FIRST = .FALSE.
	      IF (FOUND.GT.0) THENA
		 SEARCH_STRING = ' '
		 START_SEARCH = FOUND_
	         IF (TAG.AND.MSG_NUM.EQ.NEXT_TAG) THEN_
	            CALL GET_NEXT_TAG(FOLDER_NUMBER,IER,NEXT_TAG,DUMMY)
	            IF (IER.NE.0) NEXT_TAG = NBULL + 1 
		    CALL READDIR(FOUND,IER) 
		    SYSTEM = SYSTEM.OR.ISHFT(TAG_TYPE,28).
		    TAG_TYPE = DUMMY
	         END IF
	      ELSEI
		 I = EBULL + 1
	      END IFM
	      IER = SYS$SETIMR(%VAL(WAITEFN),TIMADR,CLOSE_FILES,)
	   END IF
	   IF (I.LE.EBULL) THEN
	      CALL CONVERT_ENTRY_FROMBIN_FOLDER
	      IF (BTEST(SYSTEM,30)) THEN 
		 WRITE (6,'('' >'',$)')E
	      ELSE-
		 WRITE (6,'(''  '',$)')A
	      END IFE
	      IF (BTEST(SYSTEM,29)) THEN 
		 WRITE (6,'(''+*'',$)') 
	      ELSE 
		 WRITE (6,'(''+ '',$)')E
	      END IF 
	      N = MAX(INT(LOG10(REAL(MSG_NUM)))+1,3)R
	      IF ((EXDATE(8:9).EQ.'18'.OR.INDEX(EXDATE,'1900').GT.0)L
     &		  .AND.REMOTE_SET.NE.3) THEN
	         WRITE(6,2010) MSG_NUM,DESCRIP(:54-N),FROM,'(DELETED)'N
	      ELSE IF (EXPIRATION) THEN
	         IF (BTEST(SYSTEM,2)) THEN		! Shutdown bulletin?U
		    EXPIRES = 'Shutdown'
	         ELSE IF (BTEST(SYSTEM,1)) THEN		! Permanent bulletin?,
		    EXPIRES = 'Permanent'D
	         ELSE IF (EXDATE(8:9).EQ.'18'.AND.REMOTE_SET.EQ.3) THEN
		    EXPIRES = 'Unknown' 
	         ELSE
		    EXPIRES = EXDATE(:7)//EXDATE(10:11)I
	         END IF
	         WRITE(6,2010) MSG_NUM,DESCRIP(:54-N),FROM,EXPIREST
	      ELSED
	         WRITE(6,2010) MSG_NUM,DESCRIP(:54-N),FROM,
     &						DATE(:7)//DATE(10:11)C
	      END IFL
	      IF (PRINTING) THENE
		 FOUND_MSG = .TRUE.G
		 CALL SYS$SETAST(%VAL(0))N
	         CALL PRINT(MSG_NUM,CLOSED_FILES)
		 CALL SYS$SETAST(%VAL(1))U
	      END IFU
	   END IF
	   I = I + 1U
	   IF (ANY_SEARCH) IER = SYS$CANTIM(,)+
	END DON

	DIR_COUNT = MSG_NUM + 1			! Update directory counter

	IF (ANY_SEARCH.OR.PRINTING) THENI
	   IF (SEARCH.OR.PRINTING) CALL CLOSE_BULLFIL
	   CALL CLOSE_BULLDIR
	   IF (ANY_SEARCH) THEN
	      IF (FOUND.GT.0) THENE
	         DIR_COUNT = FOUND + 1M
	      ELSE
	         DIR_COUNT = NBULL + 1)
	      END IF
	   END IF
	END IF(

	IF (DIR_COUNT.GT.NBULL.OR.(READ_TAG.AND.IER1.NE.0)) THENS
						! Outputted all entries?
	   DIR_COUNT = -1			! Yes. Set counter to -1.
	   IF (PRINTING.AND.CLI$PRESENT('NOW').AND.FOUND_MSG) THEN1
	      INCMD = 'PRINT/NOW'
	      IER = CLI$DCL_PARSE(INCMD,BULLETIN_SUBCOMMANDS)
	      CALL PRINT(MSG_NUM,CLOSED_FILES) 
	   END IF
	ELSE 
	   WRITE(6,1010)			! Else say there are more 
	END IFE

9999	POSTTIME = .FALSE. 
	NEXT = .FALSE. 
	RETURNL

1000	FORMAT('    #',1X,'Description',43X,'From',9X,'Date',/)
1005	FORMAT('    #',1X,'Description',43X,'From',8X,'Expires',/)B
1010	FORMAT(1X,/,' Press RETURN for more...',/)I

2010	FORMAT('+',I<N>,1X,A<54-N>,1X,A12,1X,A9)M

	END


	SUBROUTINE CLOSE_FILES 

	IMPLICIT INTEGER (A-Z)(

	COMMON /CLOSE_FILES_INFO/ CLOSED_FILES=

	INQUIRE(UNIT=1,OPENED=IER)E
	IF (IER) CALL CLOSE_BULLFIL

	INQUIRE(UNIT=2,OPENED=IER)B
	IF (IER) CALL CLOSE_BULLDIR

	CLOSED_FILES = .TRUE.

	RETURNE
	END



	SUBROUTINE GET_MSGKEY(BTIM,MSG_KEY)

	IMPLICIT INTEGER (A-Z)=

	INTEGER BTIM(2)

	CHARACTER*8 MSG_KEY,INPUT

	CALL LIB$MOVC3(8,BTIM(1),%REF(INPUT))

	DO I=1,8 
	   MSG_KEY(I:I) = INPUT(9-I:9-I)R
	END DOC

	RETURN 
	END



	SUBROUTINE FILE
CE
C  SUBROUTINE FILE
C 
C  FUNCTION:  Copies a bulletin to a file.
CR
	IMPLICIT INTEGER (A - Z)E

	COMMON /POINT/ BULL_POINT

	COMMON /BULLPAR/ BULL_PARAMETER,LEN_P
	CHARACTER*64 BULL_PARAMETER

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	COMMON /READ_DISPLAY/ LINE_OFFSET

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC'L

	EXTERNAL CLI$_ABSENTE

	CHARACTER*128 FILENAME 

	IF (CAPTIVE(1)) THEND
	   WRITE (6,'('' ERROR: Command invalid from CAPTIVE account.'')')
	   RETURN
	END IFT

	OPENED = .FALSE.C

10	IER = CLI$GET_VALUE('BULLETIN_NUMBER',BULL_PARAMETER,LEN_P)
	IF (IER.NE.%LOC(CLI$_ABSENT)) THEN	! Was bulletin specified?U
	   CALL GET_2_VALS(BULL_PARAMETER,LEN_P,SBULL,EBULL,IER)!
	   IF (EBULL.GT.F_NBULL) EBULL = F_NBULLT
	ELSE IF (OPENED) THEN
	   CALL CLOSE_BULLFIL
	   CALL CLOSE_BULLDIR
	   CLOSE (UNIT=3)			! Bulletin copy completed
	   RETURN
	ELSE IF (CLI$PRESENT('ALL')) THEN
	   SBULL = 1 
	   EBULL = F_NBULLE
	   IER = 0E
	ELSE IF (BULL_POINT.EQ.0) THEN	! No.  Have we just read a bulletin?
	   WRITE(6,1010)		! No, then error.
	   RETURN
	ELSE'
	   SBULL = BULL_POINT
	   EBULL = SBULL 
	   IER = 0o
	END IF,

	IF (SBULL.LE.0.OR.IER.NE.0.OR.EBULL.LT.SBULL) THEN(
	   WRITE (6,1015)
	   IF (OPENED) THEN
	      CALL CLOSE_BULLFILs
	      CALL CLOSE_BULLDIR 
	      CLOSE (UNIT=3)			! Bulletin copy completed
	   END IF
	   WRITE (6,'(1X,A)') BULL_PARAMETER(:LEN_P)t
	   RETURN
	END IF

	IF (.NOT.OPENED) THEN
	   IER = CLI$GET_VALUE('FILESPEC',FILENAME,LEN_F)

	   IF (IER.EQ.%LOC(CLI$_ABSENT)) THEN	! If no file name was specified
	      WRITE(6,1020)		! Write errorI
	      RETURN			! And return
	   END IF

	   CALL DISABLE_PRIVS

	   IF (CLI$PRESENT('NEW')) THEN
	      OPEN(UNIT=3,FILE=FILENAME(:LEN_F),ERR=900,N
     &	        RECL=LINE_LENGTH,STATUS='NEW',CARRIAGECONTROL='LIST')
	   ELSE
	      OPEN(UNIT=3,FILE=FILENAME(:LEN_F),IOSTAT=IER,
     &		RECL=LINE_LENGTH,E
     &		STATUS='OLD',CARRIAGECONTROL='LIST',ACCESS='APPEND')
	      IF (IER.NE.0) THEN
	         OPEN(UNIT=3,FILE=FILENAME(:LEN_F),ERR=900,
     &	           RECL=LINE_LENGTH,STATUS='NEW',CARRIAGECONTROL='LIST') 
	      ELSE IF (CLI$PRESENT('FF')) THEN 
	         WRITE (3,'(A)') CHAR(12)
	      END IFE
	   END IF

	   CALL ENABLE_PRIVS			! Reset SYSPRV privilegesE

	   HEAD = CLI$PRESENT('HEADER')

	   CALL OPEN_BULLDIR_SHARED
	   CALL OPEN_BULLFIL_SHARED	! Open BULLETIN file 
	END IFH

	OPENED = .TRUE.

	FIRST = .TRUE.R

	DO FBULL = SBULL,EBULL 
	   FBULL1 = FBULL
	   CALL READDIR(FBULL,IER)	! Get info for specified bulletin.

	   IF (IER.NE.FBULL+1.OR.FBULL.GT.EBULL.OR.(.NOT.CLI$PRESENT.
     &		('ALL').AND.FBULL1.EQ.SBULL.AND.FBULL.NE.SBULL)) THEN 
	      IF (REMOTE_SET.LT.3.OR.FBULL1.EQ.SBULL) WRITE(6,1030) FBULL1E
	      IF (FBULL1.GT.SBULL) GO TO 100H
	      CLOSE (UNIT=3,STATUS='DELETE') 
	      CALL CLOSE_BULLFILC
	      CALL CLOSE_BULLDIRE
	      RETURNC
	   ELSE IF (REMOTE_SET) THEN_
	      CALL REMOTE_READ_MESSAGE(FBULL,IER1)R
	      IF (IER1.GT.0) THEN
	         CALL DISCONNECT_REMOTE
	      ELSEt
	         CALL GET_REMOTE_MESSAGE(IER1)E
	      END IFV
	      IF (IER1.NE.0) GO TO 100C
	   END IF

	   IF (.NOT.FIRST.AND.CLI$PRESENT('FF')) THEN
	      WRITE (3,'(A)') CHAR(12)G
	   ELSE IF (FIRST) THEN
	      FIRST = .FALSE.
	   END IF

	   ILEN = LINE_LENGTH + 1

	   CALL GET_BULL_LINE(BLOCK,LENGTH,INPUT,ILEN)_
	   IF (ILEN.GT.0.AND.INPUT(:6).EQ.'From: ') THEN 
	      IF (HEAD) WRITE(3,1060) INPUT(7:ILEN),DATE//' '//TIME(:8)
	      CALL GET_BULL_LINE(BLOCK,LENGTH,INPUT,ILEN)
	   ELSE IF (HEAD) THENS
	      WRITE(3,1060) FROM,DATE//' '//TIME(:8)I
	   END IF
	   IF (ILEN.GT.0.AND.INPUT(:6).EQ.'Subj: ') THEN 
	      IF (HEAD) WRITE(3,1050) INPUT(7:ILEN)
	   ELSE
	      IF (HEAD) WRITE(3,1050) DESCRIP
	      IF (ILEN.GT.0) WRITE (3,'(A)') INPUT(:ILEN)
	   END IF

	   DO WHILE (ILEN.GT.0)		! Copy bulletin into fileL
	      CALL GET_BULL_LINE(BLOCK,LENGTH,INPUT,ILEN)
	      IF (ILEN.GT.0) WRITE (3,'(A)') INPUT(:ILEN)
	   END DO
	END DOE

100     IER = OTS$CVT_L_TI(SBULL,BULL_PARAMETER,,,)
 	IF (SBULL.EQ.EBULL) THEN
	   WRITE(6,1040) 
     &	      BULL_PARAMETER(FIRST_ALPHA(BULL_PARAMETER):),
     &	      FILENAME(:LEN_F)E
	ELSE 
	   WRITE(6,1045) 
     &	      BULL_PARAMETER(FIRST_ALPHA(BULL_PARAMETER):) 
	   IER = OTS$CVT_L_TI(EBULL,BULL_PARAMETER,,,)M
           WRITE(6,1046)
     &	      BULL_PARAMETER(FIRST_ALPHA(BULL_PARAMETER):),
     &	      FILENAME(:LEN_F)R
	END IF(
					! Show name of file created.&

	GO TO 10E

900	WRITE(6,1000).
	CALL ENABLE_PRIVS		! Reset BYPASS privilegesN
	RETURN 

1000	FORMAT(' ERROR: Error in opening file.') 
1010	FORMAT(' ERROR: You have not read any bulletin.')
1015	FORMAT(' ERROR: Specified message number has incorrect format:') 
1020	FORMAT(' ERROR: No file name was specified.')
1030	FORMAT(' ERROR: Following bulletin was not found: ',I)	
1040	FORMAT(' Message ',A,' written to ',A)S
1045	FORMAT(' Messages ',A,'-',$) 
1046	FORMAT('+',A,' written to ',A) 
1050	FORMAT('Description: ',A,/)
1060	FORMAT(/,'From: ',A,/,'Date: ',A)

	END



	SUBROUTINE COPY2(OUT,IN)F

	CALL LIB$MOVC3(8,IN,OUT) 

	RETURNO
	END



	SUBROUTINE LOGIN 
CI
C  SUBROUTINE LOGINT
C 
C  FUNCTION: Alerts user of new messages upon logging in.'
C'
	IMPLICIT INTEGER (A - Z) 

        INCLUDE 'BULLFILES.INC'W
 E
	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLUSER.INC' 

	INCLUDE 'BULLFOLDER.INC' 

	COMMON /READIT/ READITS

	COMMON /BULLPAR/ BULL_PARAMETER,LEN_P
	CHARACTER*64 BULL_PARAMETER

	COMMON /PAGE/ PAGE_LENGTH,PAGE_WIDTH,PAGING
	LOGICAL PAGING0

	COMMON /POINT/ BULL_POINT

	COMMON /PROMPT/ COMMAND_PROMPTI
	CHARACTER*40 COMMAND_PROMPT

	COMMON /SYSTEM_FOLDERS/ SYSTEM_FLAG(FLONG),DUMMY(2)

	COMMON /COMMAND_SWITCHES/ LOGIN_SWITCH,SYSTEM_SWITCH	
	COMMON /COMMAND_SWITCHES/ SYSTEM_LOGIN_BTIM(2)t
	COMMON /COMMAND_SWITCHES/ REVERSE_SWITCH,SEPARATE
	CHARACTER*4 SEPARATE 

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	CHARACTER TODAY*24,INREAD*1

	LOGICAL*1 CTRL_G/7/

	DATA GEN_DIR1/0/	! General directory link list header
	DATA SYS_DIR1/0/	! System directory link list header-
	DATA SYS_NUM1/0/	! System message number link list header
	DATA SYS_BUL1/0/	! System bulletin link list header
	DATA ALL_DIR1/0/	! Full directory link list header (for remote)

	DATA PAGE/0/Y

	DATA FIRST_WRITE/.TRUE./D
	LOGICAL FIRST_WRITE

	COMMON /LOGIN_BTIM/ LOGIN_BTIM_SAVE(2)A

	DIMENSION NOLOGIN_BTIM(2),TODAY_BTIM(2)
	DIMENSION NEW_BTIM(2),PASSCHANGE(2),BULLCP_BTIM(2)R
	DIMENSION LOGIN_BTIM_OLD(2),LOGIN_BTIM_NEW(2)

	FOLDER_NAME = FOLDERL

	CALL SYS$ASCTIM(,TODAY,,)		! Get the present time
	CALL SYS_BINTIM(TODAY,TODAY_BTIM)

	CALL SYS_BINTIM('5-NOV-2956 00:00:00.00',NOLOGIN_BTIM) 
	CALL SYS_BINTIM('5-NOV-1956 11:05:56',NEW_BTIM)

CU
C  Find user entry in BULLUSER.DAT to update information and
C  to get the last date that messages were read.
Cn

	CALL OPEN_BULLUSER_SHARED

	CALL READ_USER_FILE_HEADER(IER)		! Get the header

	IF (IER.EQ.0) THEN			! Header is present.
	   UNLOCK 4
	   CALL READ_USER_FILE_KEYNAME(USERNAME,IER1)
						! Find if there is an entryT
	   IF (NEW_FLAG(1).LT.143.OR.NEW_FLAG(1).GT.143) THEN
	      NEW_FLAG(2)=0		! If old version clear GENERIC value
	      NEW_FLAG(1)=143		! Set new version number
	   END IF
	   IF (IER1.EQ.0) THEN			! There is a user entry'
	      IF (COMPARE_BTIM(LOGIN_BTIM,NOLOGIN_BTIM).GE.0) THEN0
						! DISMAIL or SET LOGIN set
		 IF (CLI$PRESENT('ALL')) THEN 
		    CALL COPY2(LOGIN_BTIM,TODAY_BTIM(1))
		 ELSEC
		    RETURN			! Don't notify
	         END IF
	      END IFI
	      CALL COPY2(LOGIN_BTIM_SAVE,LOGIN_BTIM)P
	      CALL COPY2(LOGIN_BTIM,TODAY_BTIM)
	      REWRITE (4) USER_ENTRYT
	      IF (SYSTEM_FLAG(1).NE.0.AND.SYSTEM_FLAG(1).NE.1) READIT = 1
	      DO I = 1,FLONGG
		 IF (SET_FLAG(I).NE.0.OR.BRIEF_FLAG(I).NE.0.OR.I
     &		    (I.GT.1.AND.SYSTEM_FLAG(I).NE.0)) READIT = 1
	      END DOI
	   ELSE
	      CALL CLEANUP_LOGIN		! Good time to delete dead usersO
	      CALL COPY2(READ_BTIM,NEW_BTIM)	! Make new entry
	      DO I = 1,FLONGE
	         SET_FLAG(I) = SET_FLAG_DEF(I)
	         BRIEF_FLAG(I) = BRIEF_FLAG_DEF(I)A
		 NOTIFY_FLAG(I) = NOTIFY_FLAG_DEF(I)
	      END DOO
	      NEW_FLAG(1) = 143
	      NEW_FLAG(2) = 0
	      CALL CHECK_NEWUSER(USERNAME,DISMAIL,PASSCHANGE)
	      IF (DISMAIL.EQ.1) THENE
		 CALL COPY2(LOGIN_BTIM,NOLOGIN_BTIM)
	         CALL COPY2(LOGIN_BTIM_SAVE,LOGIN_BTIM)
	      ELSEA
	         CALL COPY2(LOGIN_BTIM_SAVE,NEW_BTIM)
		 CALL COPY2(LOGIN_BTIM,TODAY_BTIM)
	         DO I = 1,FLONG
		    IF (SET_FLAG(I).NE.0) READIT = 1
	         END DO
		 IF (COMPARE_BTIM(PASSCHANGE,NEWEST_BTIM).LT.0) IER1 = 0
			! Old password change indicates user is new to BULLETIN
			! but not to system, so don't limit message viewing.
	      END IFB
	      CALL WRITE_USER_FILE(IER)
	      IF (IER.NE.0) THEN		! Error in writing to user file
		 WRITE (6,1070)			! Tell user of the error
		 CALL CLOSE_BULLUSER		! Close the user file	
		 CALL EXIT			! Go away...l
	      END IFT
	      IF (DISMAIL.EQ.1) RETURN		! Go away if DISMAIL set 
	      DIFF = -1				! Force us to look at messages
	      CALL OPEN_BULLINF_SHARED.
	      DO I=1,FOLDER_MAX
	         CALL COPY2(LAST_READ_BTIM(1,I),READ_BTIM)L
	      END DOs
	      WRITE (9,IOSTAT=IER) USERNAME,O
     &		((LAST_READ_BTIM(I,J),I=1,2),J=1,FOLDER_MAX)
	      CALL CLOSE_BULLINF_
	   END IF
	   CALL COPY2(LOGIN_BTIM,LOGIN_BTIM_SAVE)
	   CALL READ_USER_FILE_HEADER(IER2)	! Reset read back to header
	END IFE

	IF (IER.EQ.0.AND.MINUTE_DIFF(TODAY_BTIM,BBOARD_BTIM)i
     &			.GT.BBOARD_UPDATE) THEN	! Update BBOARD mail?
	   CALL COPY2(BBOARD_BTIM,TODAY_BTIM)
	   REWRITE (4) USER_HEADER		! Rewrite headerN
	   IF (.NOT.TEST_BULLCP()) CALL CREATE_PROCESS('BBOARD')&
	ELSE IF (IER.NE.0) THEN
	   CALL CLOSE_BULLUSERR
	   CALL EXIT			! If no header, no messages=
	END IF:

	IF (IER1.EQ.0) THEN		! Skip date comparison if new entryS
CL
C  Compare and see if messages have been added since the last time
C  that the user has logged in or used the BULLETIN facility.&
C 
	   DIFF1 = COMPARE_BTIM(LOGIN_BTIM,READ_BTIM)
	   IF (DIFF1.LT.0) THEN		! If read messages since last login,
	      CALL COPY2(LOGIN_BTIM,READ_BTIM)I
		! then use read date to compare with latest bulletin datei
	   END IF			! to see if should alert user.

	   IF (SYSTEM_SWITCH) THEN 
	      DIFF1 = COMPARE_BTIM(SYSTEM_LOGIN_BTIM,NEWEST_BTIM)
	   ELSE
	      DIFF1 = COMPARE_BTIM(LOGIN_BTIM,NEWEST_BTIM)L
	   END IF
	END IFL

	CALL COPY2(LOGIN_BTIM_SAVE,LOGIN_BTIM)  ! Destroyed in UPDATE_READ 
	(
	IF (NEW_FLAG(2).NE.0.AND.NEW_FLAG(2).NE.-1) THENN
	   CALL LIB$MOVC3(4,NEW_FLAG(2),%REF(BULL_PARAMETER))
	   CALL SUBTIME(LOGIN_BTIM,BULL_PARAMETER(:4),IER)B
	ELSE IF (DIFF1.GT.0) THEN
	   BULL_POINT = -1S
	   IF (READIT.EQ.1) THENO
	      CALL UPDATE_READ(1)
	      CALL COPY2(LOGIN_BTIM_NEW,LOGIN_BTIM)
	      CALL READ_IN_FOLDERS 
	      CALL MODIFY_SYSTEM_LIST(1) 
	   END IF
	   CALL CLOSE_BULLUSERR
	   RETURN
	END IF0

	CALL READ_IN_FOLDERSS
	CALL MODIFY_SYSTEM_LIST(1)
        FOLDER_FILE = FOLDER_DIRECTORY(:TRIM(FOLDER_DIRECTORY))//FOLDER.

	ENTRY LOGIN_FOLDERN

	IF (NEW_FLAG(2).EQ.0.OR.NEW_FLAG(2).EQ.-1.OR.FOLDER_SET) THEN
	   CALL COPY2(LOGIN_BTIM,LOGIN_BTIM_SAVE)
	END IF 

	IF (REMOTE_SET.EQ.1) THEN	! If system remote folder, use remote
					! info, not local login timeU
	   IF (LAST_SYS_BTIM(1,FOLDER_NUMBER+1).NE.0) THEN)
	    CALL COPY2(LOGIN_BTIM,LAST_SYS_BTIM(1,FOLDER_NUMBER+1))
	    LAST_SYS_BTIM(1,FOLDER_NUMBER+1) = 0,
	    LAST_SYS_BTIM(2,FOLDER_NUMBER+1) = 0S
	   ELSE
	    DIFF1 = COMPARE_BTIM(LOGIN_BTIM,
     &			LAST_READ_BTIM(1,FOLDER_NUMBER+1))Q
	    IF (DIFF1.LT.0) THEN 
	      CALL COPY2(LOGIN_BTIM,LAST_READ_BTIM(1,FOLDER_NUMBER+1))I
	    ELSED
	      DIFF = MINUTE_DIFF(LOGIN_BTIM,F_NEWEST_BTIM)I
	      IF (DIFF.GE.0.AND.DIFF.LE.15) THEN  ! BULLCP updates every 15 min
	         IER = SYS$BINTIM('0 00:15',BULLCP_BTIM)
	         BULLCP_BTIM(1) = -BULLCP_BTIM(1) ! Convert to -delta timeD
	         BULLCP_BTIM(2) = -BULLCP_BTIM(2)-1
	         CALL LIB$SUBX(LOGIN_BTIM,BULLCP_BTIM,LOGIN_BTIM)
	      END IFB
	    END IF(
	   END IF
	END IFM

	ENTRY SHOW_SYSTEM

	JUST_SYSTEM = (.NOT.LOGIN_SWITCH.AND.SYSTEM_SWITCH).OR.
     &	        (BTEST(FOLDER_FLAG,2)
     &		.AND..NOT.TEST_SET_FLAG(FOLDER_NUMBER)
     &		.AND..NOT.TEST_BRIEF_FLAG(FOLDER_NUMBER))B

	NGEN = 0			! Number of general messages
	NSYS = 0			! Number of system messages(
	BULL_POINT = -1

	IF (IER1.NE.0.AND.FOLDER_NUMBER.GT.0) THEN,
	   IF (LOGIN_SWITCH) THEN
	      IF (READIT.EQ.1) THEN
	         CALL COPY2(LOGIN_BTIM_SAVE,LOGIN_BTIM)
	         CALL UPDATE_READ(1)u
	         CALL COPY2(LOGIN_BTIM_NEW,LOGIN_BTIM)O
	      END IFs
	      CALL CLOSE_BULLUSER
	   END IF
	   RETURN	! Don't overwhelm new user with lots of non-general msgs:
	END IFg

	IF (BTEST(FOLDER_FLAG,2).AND.SYSTEM_SWITCH) THEN 
			! Can folder have SYSTEM messages and /SYSTEM specified?0
	   CALL COPY2(LOGIN_BTIM,SYSTEM_LOGIN_BTIM) ! Use specified login time0
						    ! for system messages.
	END IF

	IF (LOGIN_SWITCH) THEN,
	   IF (READIT.EQ.1) THENN
	      CALL COPY2(LOGIN_BTIM_OLD,LOGIN_BTIM)
	      CALL UPDATE_READ(1)
	      CALL COPY2(LOGIN_BTIM_NEW,LOGIN_BTIM)
	      CALL COPY2(LOGIN_BTIM,LOGIN_BTIM_OLD)
	   END IF
	   CALL CLOSE_BULLUSERI
	END IF

	IF (READIT.EQ.1.AND.FOLDER_NUMBER.GE.0.AND.REMOTE_SET.LT.3) THENO
	   IF (LAST_SYS_BTIM(1,FOLDER_NUMBER+1).NE.0) THENL
	      DIFF1 = COMPARE_BTIM(LOGIN_BTIM, 
     &				LAST_SYS_BTIM(1,FOLDER_NUMBER+1))P
	      IF (DIFF1.LT.0) THENG
	         CALL COPY2(LOGIN_BTIM,LAST_SYS_BTIM(1,FOLDER_NUMBER+1))P
	      END IF4
	      CALL COPY2(LAST_SYS_BTIM(1,FOLDER_NUMBER+1),L
     &			 LOGIN_BTIM_NEW)O
	   END IF

	   IF (TEST2(BRIEF_FLAG,FOLDER_NUMBER)O
     &		       .AND.TEST2(SET_FLAG,FOLDER_NUMBER)) THENA
	      IF (.NOT.TEST2(SYSTEM_FLAG,FOLDER_NUMBER)) GO TO 9999
	   END IF
	END IFD

	CALL OPEN_BULLDIR_SHARED	! Get bulletin directory
	IF (.NOT.REMOTE_SET) THEN
	   CALL READDIR(0,IER)		! Get header info
	ELSE 
	   NBULL = F_NBULL1
	END IFt
	   
	CALL INIT_QUEUE(GEN_DIR1,BULLDIR_ENTRY)
	CALL INIT_QUEUE(SYS_DIR1,BULLDIR_ENTRY)
	CALL INIT_QUEUE(SYS_NUM1,%DESCR(ICOUNT))l
	GEN_DIR = GEN_DIR1_
	SYS_DIR = SYS_DIR1o
	SYS_NUM = SYS_NUM1f
	START = 1
	REVERSE = 0
	IF ((.NOT.TEST_SET_FLAG(FOLDER_NUMBER).OR.R
     &		.NOT.TEST_BRIEF_FLAG(FOLDER_NUMBER))
     &		.AND..NOT.BTEST(FOLDER_FLAG,7)) THEN
	   IF (REVERSE_SWITCH) REVERSE = 1G
	   IF (IER1.EQ.0) THENM
	      CALL GET_NEWEST_MSG(LOGIN_BTIM,START)
	      IF (START.EQ.-1) START = NBULL + 1,
	   END IF
	END IFr

	IF (REMOTE_SET) THENT
	   CALL INIT_QUEUE(ALL_DIR1,BULLDIR_ENTRY)O
	   ALL_DIR = ALL_DIR1
	   CALL REMOTE_DIRECTORY_COMMAND(START,NBULL,
     &					 .NOT.REVERSE,ALL_DIR,IER)i
	   IF (IER.NE.0) THEN
	      CALL CLOSE_BULLDIR 
	      CALL DISCONNECT_REMOTEe
	      GO TO 9999 
	   END IF
	   LAST_DIR = ALL_DIR
	   ALL_DIR = ALL_DIR1
	END IFe

	DO ICOUNT1 = NBULL,START,-1
	   IF (REVERSE) THEN 
	      ICOUNT = NBULL + START - ICOUNT1(
	   ELSE
	      ICOUNT = ICOUNT1r
	   END IF
	   IF (REMOTE_SET) THEN
	      IF (ALL_DIR.EQ.LAST_DIR) GO TO 100W
	      CALL READ_QUEUE(%VAL(ALL_DIR),ALL_DIR,BULLDIR_ENTRY)F
	      IER = ICOUNT + 1s
	   ELSE
	      CALL READDIR(ICOUNT,IER)T
	   END IF
	   IF (IER1.EQ.0.AND.IER.EQ.ICOUNT+1) THEN ! Is this a totally new user?T
	      IF (.NOT.REVERSE.AND..NOT.BTEST(FOLDER_FLAG,7)) THEN 
	         DIFF = COMPARE_BTIM(LOGIN_BTIM,MSG_BTIM) ! No, so compare date
	         IF (DIFF.GT.0) GO TO 100
	      END IFD
	      IF (.NOT.BTEST(FOLDER_FLAG,2)) SYSTEM = SYSTEM.AND.(.NOT.1)
			! Show system msg in non-system folder as general msg
	      IF (USERNAME.NE.FROM.OR.SYSTEM) THENL
				  	! Is bulletin system or from same user?
		 IF (SYSTEM) THEN	! Is it system bulletin? R
		    NSYS = NSYS + 1.
		    CALL WRITE_QUEUE(%VAL(SYS_DIR),SYS_DIR,BULLDIR_ENTRY)E
		    CALL WRITE_QUEUE(%VAL(SYS_NUM),SYS_NUM,%DESCR(ICOUNT))
	         ELSE IF (.NOT.JUST_SYSTEM) THENa
		    IF (BTEST(FOLDER_FLAG,7)) THEN
		       DIFF = COMPARE_BTIM
     &			      (LAST_READ_BTIM(1,FOLDER_NUMBER+1),MSG_BTIM)N
		    ELSE IF (.NOT.SYSTEM_SWITCH) THEN 
		       DIFF = -1
		    ELSE
	               DIFF = COMPARE_BTIM(LOGIN_BTIM_SAVE,MSG_BTIM)D
		    END IF
		    IF (DIFF.LT.0) THEN.
		       IF (.NOT.REVERSE.OR.BULL_POINT.EQ.-1) THEN 
		          BULL_POINT = ICOUNT - 1N
		          IF (.NOT.BTEST(FOLDER_FLAG,2).AND.
     &			   TEST_BRIEF_FLAG(FOLDER_NUMBER).AND.D
     &			   TEST_SET_FLAG(FOLDER_NUMBER)) GO TO 100G
		       END IF=
		       NGEN = NGEN + 1
		       SYSTEM = ICOUNT
		       CALL WRITE_QUEUE(%VAL(GEN_DIR),GEN_DIR,BULLDIR_ENTRY)
		    END IF
	         END IF
	      END IFm
	   ELSE IF (IER.EQ.ICOUNT+1) THEN
			! Totally new user, save only permanent system msgs
	      IF ((SYSTEM.AND.7).EQ.3.OR.
     &		  (SYSTEM.AND.BTEST(FOLDER_FLAG,7))) THENf
	         NSYS = NSYS + 1U
		 CALL WRITE_QUEUE(%VAL(SYS_DIR),SYS_DIR,BULLDIR_ENTRY)
		 CALL WRITE_QUEUE(%VAL(SYS_NUM),SYS_NUM,%DESCR(ICOUNT))w
	      ELSE IF (NGEN.EQ.0.OR.	! And save only the first non-system msg
     &		     BTEST(FOLDER_FLAG,7)) THEN ! and SET ALWAYS folder messages
		 SYSTEM = ICOUNT	! Save bulletin number for display
		 IF (.NOT.REVERSE.OR.BULL_POINT.EQ.-1) THEN	
		    BULL_POINT = ICOUNT - 11
		    IF (.NOT.BTEST(FOLDER_FLAG,2).AND.
     &			TEST_BRIEF_FLAG(FOLDER_NUMBER).AND.
     &		 	TEST_SET_FLAG(FOLDER_NUMBER)) GO TO 100s
		 END IFk
		 NGEN = NGEN + 1
		 CALL WRITE_QUEUE(%VAL(GEN_DIR),GEN_DIR,BULLDIR_ENTRY)
	      END IFB
	   END IF
	END DOU
100	CALL CLOSE_BULLDIR
CL
C  Review new directory entries.  If there are system messages,w
C  copy the system bulletin into GEN_DIR file BULLSYS.SCR for outputting
C  to the terminal.  If there are simple messages, just output the
C  header information.
C=
	IF (TEST_BRIEF_FLAG(FOLDER_NUMBER).AND.
     &			   TEST_SET_FLAG(FOLDER_NUMBER)) NGEN = 0

	IF (NGEN.EQ.0.AND.NSYS.EQ.0) GO TO 9999

	IF (NSYS.GT.0) THEN		! Are there any system messages?
	   IF (FIRST_WRITE) THEN 
	      PAGE = 4		! Don't erase MAIL/PASSWORD notifies0
	      FIRST_WRITE = .FALSE.	! if this is first write to screen.
	   END IF
	   LENF = TRIM(FOLDER_NAME)
	   S1 = (PAGE_WIDTH-(LENF+16))/2d
	   S2 = PAGE_WIDTH - S1 - (LENF + 16)
	   WRITE (6,'(''+'',A,$)') CTRL_G
	   WRITE (6,1026) FOLDER_NAME(:LENF)		! Yep...B
	   PAGE = PAGE + 1 
	   CTRL_G = 0		! Don't ring bell for non-system bulls
	   CALL OPEN_BULLFIL_SHARED
	   CALL INIT_QUEUE(SYS_BUL1,INPUT) 
	   SYS_BUL = SYS_BUL1
	   SYS_DIR = SYS_DIR1
	   SYS_NUM = SYS_NUM1
	   NSYS_LINE = 0A
	   DO J=1,NSYSW
	      CALL READ_QUEUE(%VAL(SYS_DIR),SYS_DIR,BULLDIR_ENTRY)U
	      IF (REMOTE_SET) THEN 
	         CALL READ_QUEUE(%VAL(SYS_NUM),SYS_NUM,%DESCR(ICOUNT))T
	         WRITE (REMOTE_UNIT,'(2A)',IOSTAT=IER) 5,ICOUNT
	         IF (IER.GT.0) THEN
	            CALL DISCONNECT_REMOTEI
	         ELSE
	            CALL GET_REMOTE_MESSAGE(IER) 
	         END IF
		 IF (IER.GT.0) THENR
		    CALL CLOSE_BULLFIL
		    GO TO 9999
		 END IF 
	      END IFY
 	      INPUT = ' 'R
	      CALL WRITE_QUEUE(%VAL(SYS_BUL),SYS_BUL,INPUT)
	      NSYS_LINE = NSYS_LINE + 1
	      ILEN = LINE_LENGTH + 1L
	      CALL GET_BULL_LINE(BLOCK,LENGTH,INPUT,ILEN)
	      IF (ILEN.GT.0.AND.INPUT(:6).EQ.'From: ') THEN
	         CALL GET_BULL_LINE(BLOCK,LENGTH,INPUT,ILEN)I
	      END IFE
	      IF (ILEN.GT.0.AND.INPUT(:6).EQ.'Subj: ') THEN
	         CALL GET_BULL_LINE(BLOCK,LENGTH,INPUT,ILEN)U
	      END IF 
	      DO WHILE (ILEN.GT.0)	! Copy bulletin to SYS_BUL link list
		 CALL WRITE_QUEUE(%VAL(SYS_BUL),SYS_BUL,INPUT)
		 NSYS_LINE = NSYS_LINE + 1
		 CALL GET_BULL_LINE(BLOCK,LENGTH,INPUT,ILEN)
	      END DO(
	      IF (ILEN.LT.0) THEN
		 CALL CLOSE_BULLFILU
		 GO TO 9999T
	      END IFM
	      IF (J.LT.NSYS.AND.SEPARATE.NE.' ') THEN
 	         INPUT = ' '
	         CALL WRITE_QUEUE(%VAL(SYS_BUL),SYS_BUL,INPUT)
		 DO I=1,PAGE_WIDTH
		    INPUT(I:I) = SEPARATEt
		 END DOt
		 CALL WRITE_QUEUE(%VAL(SYS_BUL),SYS_BUL,INPUT)
	         NSYS_LINE = NSYS_LINE + 2B
	      END IFN
	   END DO
	   CALL CLOSE_BULLFIL
	   SYS_BUL = SYS_BUL1
	   ILEN = 0
	   I = 1J
	   DO WHILE (I.LE.NSYS_LINE.OR.ILEN.GT.0)  ! Write out system messagesT
	      IF (ILEN.EQ.0) THEN
	         CALL READ_QUEUE(%VAL(SYS_BUL),SYS_BUL,INPUT)
		 ILEN = TRIM(INPUT)R
		 I = I + 1
	      END IFu
	      IF (SYS_BUL.NE.0) THEN 
		 IF (PAGE.EQ.PAGE_LENGTH-2.AND.PAGING) THEN 
							! If at end of screen
		    WRITE(6,1080)	! Ask for input to proceed to next page 
		    CALL GET_INPUT_NOECHO_PROMPT(INREAD,! Get terminal input
     &			'HIT any key for next page....') 
	            WRITE (6,'(1X)')O
	            CALL LIB$ERASE_PAGE(1,1)		! Clear the screen 
		    PAGE = 1
		    IF (ILEN.LE.PAGE_WIDTH) THEN
		       WRITE(6,1060) '+'//INPUT(:ILEN)
		       ILEN = 02
		    ELSE
		       WRITE(6,1060) '+'//INPUT(:PAGE_WIDTH)
		       INPUT = INPUT(PAGE_WIDTH+1:)C
		       ILEN = ILEN - PAGE_WIDTH!
		    END IF
		 ELSEm
		    PAGE = PAGE + 1t
		    IF (ILEN.LE.PAGE_WIDTH) THEN
		       WRITE(6,1060) ' '//INPUT(:ILEN)
		       ILEN = 0(
		    ELSE
		       WRITE(6,1060) ' '//INPUT(:PAGE_WIDTH)
		       INPUT = INPUT(PAGE_WIDTH+1:))
		       ILEN = ILEN - PAGE_WIDTHN
		    END IF
		 END IF 
	      END IFL
	   END DO
	   IF (NGEN.EQ.0) THENA
	      WRITE(6,'(A)')		! Write delimiting blank line
	   END IF
	   PAGE = PAGE + 1+
	END IFT

	ENTRY REDISPLAY_DIRECTORY

	GEN_DIR = GEN_DIR1&
	IF (NGEN.GT.0) THEN		! Are there new non-system messages?
	   LENF = TRIM(FOLDER_NAME)
	   S1 = (PAGE_WIDTH-13-LENF)/2R
	   S2 = PAGE_WIDTH-S1-13-LENF
	   IF (PAGE+5+NGEN.GT.PAGE_LENGTH.AND.PAGE.GT.0) THEN
	      WRITE(6,1080)		! Ask for input to proceed to next pageF
	      CALL GET_INPUT_NOECHO_PROMPT(INREAD,	! Get terminal input
     &			'HIT any key for next page....')O
	      WRITE (6,'(1X)')
	      CALL LIB$ERASE_PAGE(1,1)	! Clear the screen
	      WRITE (6,'(''+'',A,$)') CTRL_GE
	      WRITE(6,1028) 'New '//FOLDER_NAME(:LENF)//' messages'
	      PAGE = 1B
	   ELSE
	      IF (FIRST_WRITE) THEN
		 PAGE = 4		  ! Don't erase MAIL/PASSWORD notifiesL
	         FIRST_WRITE = .FALSE. ! if this is first write to screen.N
	      END IFR
	      WRITE (6,'(''+'',A,$)') CTRL_GA
	      WRITE(6,1027) 'New '//FOLDER_NAME(:LENF)//' messages'
	      PAGE = PAGE + 1
	   END IF
	   WRITE(6,1020) 
	   WRITE(6,1025)(
	   PAGE = PAGE + 2
	   I = 0E
	   DO WHILE (I.LT.NGEN)
	      I = I + 1
	      CALL READ_QUEUE(%VAL(GEN_DIR),GEN_DIR,BULLDIR_ENTRY)I
	      CALL CONVERT_ENTRY_FROMBIN_FOLDER
	      N = MAX(INT(LOG10(REAL(SYSTEM)))+1,3)
	      N1 = MAX(1,6-N)
	      IF (PAGE.EQ.PAGE_LENGTH-2.AND.PAGING) THEN ! If at end of screenN
		 WRITE(6,1080)	! Ask for input to proceed to next page
		 CALL GET_INPUT_NOECHO_PROMPT(INREAD,U
     &		'HIT Q(Quit listing) or any other key for next page....') 
	         CALL STR$UPCASE(INREAD,INREAD)
	         WRITE (6,'(1X)')
	         CALL LIB$ERASE_PAGE(1,1)		! Clear the screen
		 PAGE = 1 
		 IF (INREAD.EQ.'Q') THEN
		    I = NGEN		! Quit directory listing
		    WRITE(6,'(''+Quitting directory listing.'')')R
		 ELSE0
		    WRITE(6,1040) '+'//DESCRIP(:53),FROM,DATE(:6),SYSTEM
		 END IF 
					! Bulletin number is stored in SYSTEM
	      ELSEI
		 PAGE = PAGE + 1
		 WRITE(6,1040) ' '//DESCRIP(:53),FROM,DATE(:6),SYSTEMa
	      END IF
	   END DO
	   IF ((.NOT.FOLDER_SET.AND.BTEST(SET_FLAG(1),0).AND.DIFF1.LE.0)C
     &		.OR.(FOLDER_SET.AND.TEST_SET_FLAG(FOLDER_NUMBER))) THEN 
	      PAGE = 0	! Don't reset page counter if READNEW not set,
	   END IF	! as no prompt to read is generated.!
	END IFt
Cm
C  Instruct users how to read displayed messages if READNEW not selected.E
CT
	IF (.NOT.TEST_BRIEF_FLAG(FOLDER_NUMBER).AND.u
     &		TEST_SET_FLAG(FOLDER_NUMBER)) THEN
	   WRITE(6,1030)S
	ELSE IF (NGEN.EQ.0) THENI
	   ILEN = 57 + INDEX(COMMAND_PROMPT,'>') - 1
	   S1 = (PAGE_WIDTH-ILEN)/2
	   S2 = PAGE_WIDTH - S1 - ILEN 
	   WRITE(6,1035) 'The '//COMMAND_PROMPT(:ILEN-57)//
     &		'/SYSTEM command can be used to reread these messages.' 
	ELSEA
	   FLEN = TRIM(FOLDER_NAME)
	   IF (FOLDER_NUMBER.EQ.0) FLEN = -1M
	   ILEN = 30 + INDEX(COMMAND_PROMPT,'>') - 1 + FLEN
	   S1 = (PAGE_WIDTH-ILEN)/2
	   S2 = PAGE_WIDTH - S1 - ILEN 
	   IF (FOLDER_NUMBER.EQ.0) THEN
	      WRITE(6,1035) 'Type ' //COMMAND_PROMPT(:ILEN-29)// 
     &		' to read these messages.'
	   ELSE
	      WRITE(6,1035) 'Type '//COMMAND_PROMPT(:ILEN-30-FLEN)A
     &		//' '//FOLDER_NAME(:FLEN)//E
     &		' to read these messages.'
	   END IF
	END IF

9999	IF (LOGIN_SWITCH) THEN 
	   CALL COPY2(LOGIN_BTIM,LOGIN_BTIM_NEW)U
	   CALL COPY2(LOGIN_BTIM_SAVE,LOGIN_BTIM_OLD)
	END IF 
	RETURN 

1020	FORMAT(' Description',43X,'From',9X,'Date',3X,'Number')
1025	FORMAT(' -----------',43X,'----',9X,'----',3X,'------')
1026	FORMAT(' ',<S1>('*'),A,' System Messages',<S2>('*'))A
1027	FORMAT(/,' ',<S1>('*'),A,<S2>('*'))
1028	FORMAT('+',<S1>('*'),A,<S2>('*'))
1030	FORMAT(' ',<PAGE_WIDTH>('*'))
1035	FORMAT(' ',<S1>('*'),A,<S2>('*'))
1040	FORMAT(A<53>,2X,A12,1X,A6,<N1>X,I<N>)
1060	FORMAT(A)
1070	FORMAT(' ERROR: Cannot add new entry to user file.') 
1080	FORMAT(' ',/)

	END


	E
	SUBROUTINE GET_NODE_NUMBER_OTHER(NODE_NUMBER,NODE_AREA,NODE_NAME)

	IMPLICIT INTEGER (A-Z)

	INCLUDE '($SYIDEF)'

	CHARACTER*(*) NODE_NAME

	CALL INIT_ITMLST	! Initialize item list
				! Now add items to list&
	CALL ADD_2_ITMLST(4,SYI$_NODE_AREA,%LOC(NODE_AREA))
	CALL ADD_2_ITMLST(4,SYI$_NODE_NUMBER,%LOC(NODE_NUMBER))
	CALL END_ITMLST(GETSYI_ITMLST)	! Get address of itemlistU

	IER = SYS$GETSYIW(,,NODE_NAME(:TRIM(NODE_NAME)), 
     &			%VAL(GETSYI_ITMLST),,,)	! Get Info command.

	IF (.NOT.IER) THENN
	   WRITE (6,'('' ERROR: Specified node name not found.'')')
	   NODE_AREA = 0s
	END IFs

	RETURNe
	END

