C
C  BULLETIN6.FOR, Version 5/4/93
C  Purpose: Contains subroutines for the BULLETIN utility program.
C  Environment: VAX/VMS
C  Programmer: Mark R. London
C
C  Copyright (c) 1990
C  Property of Massachusetts Institute of Technology, Cambridge MA 02139.
C  This program cannot be copied or distributed in any form for non-MIT
C  use without specific written approval of MIT Plasma Fusion Center
C  Management.
C
	SUBROUTINE CLOSE_FILE
C
C  SUBROUTINE CLOSE_FILE
C
C  FUNCTION: To close out the bulletin files and enable CTRL-C & -Y
C

        IMPLICIT INTEGER (A-Z)

	COMMON /BULLFIL/ BULLFIL
	DATA BULLFIL /0/

	DATA LUN /0/

	ENTRY CLOSE_BULLINF
	LUN = LUN + 1			! Unit = 9

	ENTRY CLOSE_SYSUAF
	LUN = LUN + 1			! Unit = 8

	ENTRY CLOSE_BULLNEWS
	ENTRY CLOSE_BULLFOLDER
	LUN = LUN + 3			! Unit = 7

	ENTRY CLOSE_BULLUSER
	LUN = LUN + 2			! Unit = 4

	ENTRY CLOSE_BULLDIR
	LUN = LUN + 1			! Unit = 2

	ENTRY CLOSE_BULLFIL
	LUN = LUN + 1			! Unit = 1

	CALL ENABLE_CTRL

	CLOSE (UNIT=LUN)

        IF (LUN.EQ.1.AND.BULLFIL.GT.0) BULLFIL = -BULLFIL

	LUN = 0

	RETURN
	END


	SUBROUTINE CLOSE_FILE_DELETE

	IMPLICIT INTEGER (A-Z)

        COMMON /BULLFIL/ BULLFIL

	DATA LUN /0/

	ENTRY CLOSE_BULLDIR_DELETE
	LUN = LUN + 1			! Unit = 2

	ENTRY CLOSE_BULLFIL_DELETE
	LUN = LUN + 1			! Unit = 1

	CALL ENABLE_CTRL

	CLOSE (UNIT=LUN,STATUS='DELETE')

        IF (LUN.EQ.1.AND.BULLFIL.GT.0) BULLFIL = -BULLFIL

	LUN = 0

	RETURN
	END


	SUBROUTINE OPEN_FILE(UNIT)

	IMPLICIT INTEGER (A-Z)

	INCLUDE 'BULLFILES.INC'

	INCLUDE 'BULLFOLDER.INC'

	INCLUDE 'BULLUSER.INC'

	INCLUDE 'BULLDIR.INC'

	INCLUDE '($FORIOSDEF)'

	INCLUDE '($PRVDEF)'

	INCLUDE '($RMSDEF)'

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	COMMON /DIR_POSITION/ DIR_NUM

        COMMON /NEWS_OPEN/ NEWS_OPEN

        COMMON /BULLFIL/ BULLFIL

	DATA LUN /0/

	LUN = UNIT - 14			! 14 gets added to LUN

	ENTRY OPEN_BULLNEWS
	LUN = LUN + 5			! Unit = 14

	ENTRY OPEN_BULLINF
	LUN = LUN + 1			! Unit = 9

	ENTRY OPEN_SYSUAF
	LUN = LUN + 1			! Unit = 8

	ENTRY OPEN_BULLFOLDER
	LUN = LUN + 3			! Unit = 7

	ENTRY OPEN_BULLUSER
	LUN = LUN + 2			! Unit = 4

	ENTRY OPEN_BULLDIR
	LUN = LUN + 1			! Unit = 2

	ENTRY OPEN_BULLFIL
	LUN = LUN + 1			! Unit = 1

	IER = 0

	NTRIES = 0

	CALL SET_PROTECTION

	CALL DISABLE_CTRL		! No breaks while file is open

	IF (LUN.EQ.2.AND.REMOTE_SET.EQ.4) THEN
	   DO WHILE (FILE_LOCK(IER,IER1))

	    OPEN (UNIT=2,FILE=BULLNEWSDIR_FILE,
     &	      STATUS='OLD',FORM='UNFORMATTED',
     &	      RECORDTYPE='FIXED',RECORDSIZE=NEWSDIR_RECORD_LENGTH/4,
     &	      ORGANIZATION='INDEXED',IOSTAT=IER,SHARED,
     &	      KEY=(13:20:CHARACTER,
     &	      1:8:CHARACTER,9:20:CHARACTER,21:84:CHARACTER,
     &	      85:96:CHARACTER),ACCESS='KEYED')

	    IF (IER.EQ.FOR$IOS_FILNOTFOU) THEN
	       OPEN (UNIT=2,FILE=BULLNEWSDIR_FILE,
     &	        STATUS='NEW',FORM='UNFORMATTED',SHARED,
     &	        RECORDTYPE='FIXED',RECORDSIZE=NEWSDIR_RECORD_LENGTH/4,
     &	        ORGANIZATION='INDEXED',IOSTAT=IER,DISPOSE='KEEP',
     &	        KEY=(13:20:CHARACTER,
     &	        1:8:CHARACTER,9:20:CHARACTER,21:84:CHARACTER,
     &	        85:96:CHARACTER),ACCESS='KEYED')
	    END IF
	    NTRIES = NTRIES + 1
	    IF (NTRIES.GT.30) CALL TIMER_ERR(LUN)
	   END DO
	   DIR_NUM = -1
	ELSE IF (LUN.EQ.2.AND..NOT.REMOTE_SET) THEN
	   DO WHILE (FILE_LOCK(IER,IER1))

	    OPEN (UNIT=2,FILE=FOLDER_FILE(:TRIM(FOLDER_FILE))
     &	      //'.BULLDIR',STATUS='OLD',FORM='UNFORMATTED',
     &	      RECORDTYPE='FIXED',RECORDSIZE=DIR_RECORD_LENGTH/4,
     &	      ORGANIZATION='INDEXED',IOSTAT=IER,
     &	      KEY=(9:12:INTEGER,1:8:CHARACTER),ACCESS='KEYED')

	    IF (IER.EQ.FOR$IOS_FILNOTFOU) THEN
	       OPEN (UNIT=2,FILE=FOLDER_FILE(:TRIM(FOLDER_FILE))
     &	        //'.BULLDIR',STATUS='NEW',FORM='UNFORMATTED',
     &	        RECORDTYPE='FIXED',RECORDSIZE=DIR_RECORD_LENGTH/4,
     &	        ORGANIZATION='INDEXED',IOSTAT=IER,DISPOSE='KEEP',
     &	        KEY=(9:12:INTEGER,1:8:CHARACTER),ACCESS='KEYED')
	    ELSE IF (IER.EQ.0) THEN
	       INQUIRE(UNIT=2,RECORDSIZE=ASK_SIZE)
	       IF (ASK_SIZE.NE.DIR_RECORD_LENGTH/4) THEN
	          CLOSE (UNIT=2)
	          IDUMMY = FILE_LOCK(IER,IER1)	! Avoid breaking out of DO loop
	          CALL CONVERT_BULLFILES
		  NTRIES = 0
	       END IF
	    ELSE IF (IER.EQ.FOR$IOS_INCFILORG) THEN
	       IDUMMY = FILE_LOCK(IER,IER1)	! Avoid breaking out of DO loop
	       CALL CONVERT_BULLDIRS
	       NTRIES = 0
	    END IF
	    NTRIES = NTRIES + 1
	    IF (NTRIES.GT.30) CALL TIMER_ERR(LUN)
	   END DO
	   DIR_NUM = -1
	END IF

	IF (LUN.EQ.1.AND..NOT.REMOTE_SET) THEN
	   DO WHILE (FILE_LOCK(IER,IER1))
	    IF (REMOTE_SET.EQ.4) THEN
	      IF (BULLFIL.NE.1) CALL SET_BULLFIL
	      OPEN (UNIT=1,FILE=FOLDER_FILE(:TRIM(FOLDER_FILE))
     &	      //'.BULLFIL',STATUS='UNKNOWN',IOSTAT=IER,SHARED,
     &	      ACCESS='DIRECT',RECORDTYPE='FIXED',RECORDSIZE=32,
     &	      FORM='UNFORMATTED')
	      IF (IER.EQ.0) THEN
	         DO WHILE (REC_LOCK(IER2))
                    READ (1'1,IOSTAT=IER2) NBLOCK
	         END DO
                 IF (IER2.NE.0) THEN
                    NBLOCK = 1
                    WRITE (1'1,IOSTAT=IER2) NBLOCK
		 END IF
                 BULLFIL = 1
              END IF
            ELSE
	      OPEN (UNIT=1,FILE=FOLDER_FILE(:TRIM(FOLDER_FILE))
     &	      //'.BULLFIL',STATUS='UNKNOWN',IOSTAT=IER,
     &	      ACCESS='DIRECT',RECORDTYPE='FIXED',RECORDSIZE=32,
     &	      FORM='UNFORMATTED')
            END IF
	    IF (IER.EQ.FOR$IOS_INCRECLEN) THEN
	       IDUMMY = FILE_LOCK(IER,IER1)	! Avoid breaking out of DO loop
	       CALL CONVERT_BULLFILE
	       NTRIES = 0
            ELSE IF (IER.EQ.FOR$IOS_OPEFAI) THEN
	       CALL ERRSNS(IDUMMY,IER1)
               IF (IER1.EQ.RMS$_DNF) THEN
	          IER1 =  LIB$CREATE_DIR(
     &				FOLDER_FILE(:INDEX(FOLDER_FILE,']')))
	          IF (IER1) IDUMMY = FILE_LOCK(IER,IER1)
	       END IF
	    END IF
	    NTRIES = NTRIES + 1
	    IF (NTRIES.GT.30) CALL TIMER_ERR(LUN)
	   END DO
	END IF

	IF (LUN.EQ.4) THEN
	   DO WHILE (FILE_LOCK(IER,IER1))
	    OPEN (UNIT=4,FILE=BULLUSER_FILE,STATUS='OLD',
     &	     ACCESS='KEYED',RECORDTYPE='FIXED',RECORDSIZE=7+FLONG*4,
     &	     ORGANIZATION='INDEXED',IOSTAT=IER,
     &	     KEY=(1:12:CHARACTER))
	    IF (IER.EQ.FOR$IOS_FILNOTFOU) THEN
	     OPEN (UNIT=4,FILE=BULLUSER_FILE,STATUS='UNKNOWN',
     &	      ACCESS='KEYED',RECORDTYPE='FIXED',RECORDSIZE=28+FLONG*16,
     &	      FORM='FORMATTED',ORGANIZATION='INDEXED',IOSTAT=IER,
     &	      KEY=(1:12:CHARACTER))
	     WRITE (4,FMT=USER_FMT) USER_HEADER_KEY,NEWEST_BTIM,
     &	      BBOARD_BTIM,PRV$M_OPER.OR.PRV$M_CMKRNL.OR.
     &	      PRV$M_SETPRV,(0,I=1,FLONG*4-1)
	     CLOSE (UNIT=4)
	     IDUMMY = FILE_LOCK(IER,IER1)
	    ELSE IF (IER.EQ.FOR$IOS_INCRECLEN) THEN
	     IDUMMY = FILE_LOCK(IER,IER1)
	     CALL CONVERT_USERFILE
	     NTRIES = 0
	    END IF
	    NTRIES = NTRIES + 1
	    IF (NTRIES.GT.30) CALL TIMER_ERR(LUN)
	   END DO
	END IF

	IF (LUN.EQ.7) THEN
	   DO WHILE (FILE_LOCK(IER,IER1))
	    OPEN (UNIT=7,FILE=BULLFOLDER_FILE,STATUS='OLD',
     &	     ACCESS='KEYED',RECORDTYPE='FIXED',
     &	     RECORDSIZE=FOLDER_RECORD/4,
     &	     ORGANIZATION='INDEXED',IOSTAT=IER)
	    IF (IER.EQ.FOR$IOS_FILNOTFOU) THEN
	      FOLDER1 = 'GENERAL'
	      FOLDER1_OWNER = 'SYSTEM'
	      FOLDER1_DESCRIP = 'Default general bulletin folder.'
	      FOLDER1_BBOARD = 'NONE'
	      FOLDER1_BBEXPIRE = 14
	      NBULL = 0
	      OPEN (UNIT=7,FILE=BULLFOLDER_FILE,STATUS='UNKNOWN',
     &	        ACCESS='KEYED',RECORDTYPE='FIXED',
     &	        RECORDSIZE=FOLDER_RECORD,
     &	        FORM='FORMATTED',ORGANIZATION='INDEXED',IOSTAT=IER2,
     &	        KEY=(1:44:CHARACTER,45:48:INTEGER,49:56:CHARACTER))
              CALL SYS_BINTIM('5-NOV-1982 00:00:00.00',
     &				NEWS_F_NEWEST_BTIM)
              CALL GET_MSGKEY(NEWS_F_NEWEST_BTIM,FOLDER1_CREATED_DATE)
	      WRITE (7,FMT=FOLDER_FMT,IOSTAT=IER2)
     &		FOLDER1,0,FOLDER1_CREATED_DATE,FOLDER1_OWNER,FOLDER1_DESCRIP
     &		,FOLDER1_BBOARD,FOLDER1_BBEXPIRE,USERB,GROUPB,ACCOUNTB
     &		,NBULL,F_NEWEST_BTIM,4,0,F_NEWEST_NOSYS_BTIM,0,0,0
						! 4 means system folder
	      CLOSE (UNIT=7)
	      IDUMMY = FILE_LOCK(IER,IER1)	! Avoid breaking out of DO loop
	    ELSE IF (IER.EQ.FOR$IOS_INCRECLEN) THEN
	      IDUMMY = FILE_LOCK(IER,IER1)
	      CALL CONVERT_BULLFOLDER(BULLFOLDER_FILE)
	      NTRIES = 0
	    END IF
	    NTRIES = NTRIES + 1
	    IF (NTRIES.GT.30) CALL TIMER_ERR(LUN)
	   END DO
	   IF (IER.EQ.0) NEWS_OPEN = .FALSE.
	END IF

	IF (LUN.EQ.14) THEN
	   DO WHILE (FILE_LOCK(IER,IER1))
	    OPEN (UNIT=7,FILE=BULLNEWS_FILE,STATUS='OLD',
     &	     ACCESS='KEYED',RECORDTYPE='FIXED',
     &	     RECORDSIZE=NEWS_FOLDER_RECORD/4,
     &	     ORGANIZATION='INDEXED',IOSTAT=IER)
	    IF (IER.EQ.FOR$IOS_FILNOTFOU) THEN
	      OPEN (UNIT=7,FILE=BULLNEWS_FILE,STATUS='UNKNOWN',
     &	        ACCESS='KEYED',RECORDTYPE='FIXED',
     &	        RECORDSIZE=NEWS_FOLDER_RECORD,
     &	        FORM='FORMATTED',ORGANIZATION='INDEXED',IOSTAT=IER2,
     &	        KEY=(1:44:CHARACTER,45:48:INTEGER,49:56:CHARACTER,
     &          57:64:CHARACTER:DESCENDING))
	      CLOSE (UNIT=7)
	      IDUMMY = FILE_LOCK(IER,IER1)	! Avoid breaking out of DO loop
	    ELSE IF (IER.EQ.FOR$IOS_INCRECLEN) THEN
	      IDUMMY = FILE_LOCK(IER,IER1)
	      CALL CONVERT_BULLNEWS(BULLNEWS_FILE)
	      NTRIES = 0
	    END IF
	    NTRIES = NTRIES + 1
	    IF (NTRIES.GT.30) CALL TIMER_ERR(LUN)
	   END DO
	   IF (IER.EQ.0) NEWS_OPEN = .TRUE.
	END IF

	IF (LUN.EQ.9) THEN
	   DO WHILE (FILE_LOCK(IER,IER1))
	    OPEN (UNIT=9,FILE=BULLINF_FILE,STATUS='UNKNOWN',
     &	     ACCESS='KEYED',RECORDTYPE='FIXED',RECORDSIZE=FOLDER_MAX*2+3,
     &	     IOSTAT=IER,ORGANIZATION='INDEXED',
     &	     KEY=(1:12:CHARACTER))
	     IF (IER.EQ.FOR$IOS_INCRECLEN) THEN
	       IDUMMY = FILE_LOCK(IER,IER1)	! Avoid breaking out of DO loop
	       CALL CONVERT_INFFILE
	       NTRIES = 0
	     END IF
	     NTRIES = 0
	     IF (NTRIES.GT.30) CALL TIMER_ERR(LUN)
	   END DO
	END IF

	IF (IER.NE.0) THEN
	   WRITE (6,'(
     &	    '' Cannot open file in OPEN_FILE, unit = '',I)') LUN
	   IF (IER1.EQ.0) CALL ERRSNS(IDUMMY,IER1)
	   IF (IER1.EQ.0) THEN
	      WRITE (6,'('' IOSTAT error = '',I)') IER
	   ELSE
	      CALL SYS_GETMSG(IER1)
	   END IF
	   CALL ENABLE_CTRL_EXIT	! Enable CTRL-Y & -C & EXIT
	END IF

	LUN = 0

	CALL RESET_PROTECTION

	RETURN
	END



	SUBROUTINE TIMER_ERR(UNIT)

	IMPLICIT INTEGER (A-Z)

	CHARACTER*14 NAMES(6)
	DATA NAMES/'directory','message','BULLUSER.DAT','BULLFOLDER.DAT',
     &			'BULLINF.DAT','BULLNEWS.DAT'/
	INTEGER NAME(14)
	DATA NAME/1,2,0,3,0,0,4,0,5,0,0,0,0,6/

	IF (TEST_BULLCP().NE.2) THEN	! If BULLCP process, don't log error
	   WRITE(6,'('' ERROR: Unable to open '',A,
     &	    	     '' file after 30 secs.'')')
     &			NAMES(NAME(UNIT))(:TRIM(NAMES(NAME(UNIT))))
	   WRITE (6,'('' Please try again later.'')')
	END IF

	CALL ENABLE_CTRL_EXIT		! No breaks while file is open
	END



	SUBROUTINE OPEN_FILE_SHARED

	IMPLICIT INTEGER (A-Z)

	INCLUDE '($FORIOSDEF)'

	INCLUDE 'BULLFILES.INC'

	INCLUDE 'BULLFOLDER.INC'

	INCLUDE 'BULLUSER.INC'

	INCLUDE 'BULLDIR.INC'

	COMMON /POINT/ BULL_POINT

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	COMMON /DIR_POSITION/ DIR_NUM

        COMMON /NEWS_OPEN/ NEWS_OPEN

        COMMON /BULLFIL/ BULLFIL

	EXTERNAL LNM_MODE_EXEC,ENABLE_CTRL_EXIT
C
C  The following 2 files were used prior to V1.1.
C
	CHARACTER*80 BULLDIR_FILE /'BULL_DIR:BULLDIR.DAT'/
	CHARACTER*80 BULLETIN_FILE /'BULL_DIR:BULLETIN.DAT'/

	CHARACTER*44 SAVE_FOLDER
	DATA SAVE_BLOCK/-1/

	CHARACTER*14 NAMES(6)
	DATA NAMES/'directory','message','BULLUSER.DAT','BULLFOLDER.DAT',
     &			'BULLINF.DAT','BULLNEWS.DAT'/
	INTEGER NAME(14)
	DATA NAME/1,2,0,3,0,0,4,0,5,0,0,0,0,6/

	DATA LUN /0/

	ENTRY OPEN_BULLNEWS_SHARED
	LUN = LUN + 5			! Unit = 14

	ENTRY OPEN_BULLINF_SHARED
	LUN = LUN + 1			! Unit = 9

	ENTRY OPEN_SYSUAF_SHARED
	LUN = LUN + 1			! Unit = 8

	ENTRY OPEN_BULLFOLDER_SHARED
	LUN = LUN + 3			! Unit = 7

	ENTRY OPEN_BULLUSER_SHARED
	LUN = LUN + 2			! Unit = 4

	ENTRY OPEN_BULLDIR_SHARED
	LUN = LUN + 1			! Unit = 2

	ENTRY OPEN_BULLFIL_SHARED
	LUN = LUN + 1			! Unit = 1

	IER = 0

	NTRIES = 0

	CALL DISABLE_CTRL

	IF (LUN.EQ.2.AND.REMOTE_SET.EQ.4) THEN
	   DO WHILE (FILE_LOCK(IER,IER1))

	    OPEN (UNIT=2,FILE=BULLNEWSDIR_FILE,
     &	      STATUS='OLD',FORM='UNFORMATTED',
     &	      RECORDTYPE='FIXED',RECORDSIZE=NEWSDIR_RECORD_LENGTH/4,
     &	      ORGANIZATION='INDEXED',IOSTAT=IER,SHARED,
     &	      KEY=(13:20:CHARACTER,
     &	      1:8:CHARACTER,9:20:CHARACTER,21:84:CHARACTER,
     &	      85:96:CHARACTER),ACCESS='KEYED')
	    NTRIES = NTRIES + 1
	    IF (NTRIES.GT.30) CALL TIMER_ERR(LUN)
	   END DO
	   DIR_NUM = -1
	ELSE IF (LUN.EQ.2.AND..NOT.REMOTE_SET) THEN
	   DO WHILE (FILE_LOCK(IER,IER1))

	    OPEN (UNIT=2,FILE=FOLDER_FILE(:TRIM(FOLDER_FILE))
     &	      //'.BULLDIR',STATUS='OLD',FORM='UNFORMATTED',
     &	      RECORDTYPE='FIXED',RECORDSIZE=DIR_RECORD_LENGTH/4,
     &	      ORGANIZATION='INDEXED',IOSTAT=IER,SHARED,
     &	      KEY=(9:12:INTEGER,1:8:CHARACTER),ACCESS='KEYED')
	    IF (IER.EQ.FOR$IOS_FILNOTFOU.AND.(FOLDER_NUMBER.EQ.0
     &		.OR.FOLDER.EQ.'GENERAL')) THEN
	       IER2 = LIB$RENAME_FILE(BULLETIN_FILE,'GENERAL.BULLFIL')
	       IER2 = LIB$RENAME_FILE(BULLDIR_FILE,'GENERAL.BULLDIR')
	       IF (IER2) IDUMMY = FILE_LOCK(IER,IER1) ! Don't break out of loop
	    ELSE IF (IER.EQ.0) THEN
	       INQUIRE(UNIT=2,RECORDSIZE=ASK_SIZE)
	       IF (ASK_SIZE.NE.DIR_RECORD_LENGTH/4) THEN
	          CLOSE (UNIT=2)
	          IDUMMY = FILE_LOCK(IER,IER1)	! Avoid breaking out of DO loop
	          CALL CONVERT_BULLFILES
		  NTRIES = 0
	       END IF
	    ELSE IF (IER.EQ.FOR$IOS_INCFILORG) THEN
	       IDUMMY = FILE_LOCK(IER,IER1)	! Avoid breaking out of DO loop
	       CALL CONVERT_BULLDIRS
	       NTRIES = 0
	    END IF
	    NTRIES = NTRIES + 1
	    IF (NTRIES.GT.30) CALL ENABLE_CTRL_EXIT
	   END DO
	   DIR_NUM = -1
	END IF

	IF (LUN.EQ.1.AND.REMOTE_SET.AND.(SAVE_BLOCK.NE.BLOCK.OR.
     &		SAVE_FOLDER.NE.FOLDER)) THEN
	   CALL REMOTE_READ_MESSAGE(BULL_POINT,IER)
	   IF (IER.GT.0) THEN
	      CALL ERROR_AND_EXIT
	   ELSE
	      SAVE_BLOCK = BLOCK
	      SAVE_FOLDER = FOLDER
	      CALL GET_REMOTE_MESSAGE(IER)
	      IER = 0
	   END IF
	ELSE IF (LUN.EQ.1.AND..NOT.REMOTE_SET) THEN
	   SAVE_BLOCK = -1
	   IF (REMOTE_SET.EQ.4.AND.BULLFIL.NE.2) CALL SET_BULLFIL
	   DO WHILE (FILE_LOCK(IER,IER1))
	     OPEN (UNIT=1,FILE=FOLDER_FILE(:TRIM(FOLDER_FILE))
     &	      //'.BULLFIL',STATUS='OLD',
     &	      ACCESS='DIRECT',RECORDTYPE='FIXED',RECORDSIZE=32,
     &	      FORM='UNFORMATTED',IOSTAT=IER,SHARED,READONLY)
	    IF (REMOTE_SET.EQ.4) THEN
	      IF (IER.EQ.0) THEN
	         DO WHILE (REC_LOCK(IER2))
                    READ (1'1,IOSTAT=IER2) NBLOCK
	         END DO
                 IF (IER2.NE.0) NBLOCK = 1
                 BULLFIL = 2
              END IF
            END IF
	    IF (IER.EQ.FOR$IOS_INCRECLEN) THEN
	       IDUMMY = FILE_LOCK(IER,IER1)	! Avoid breaking out of DO loop
	       CALL CONVERT_BULLFILE
	       NTRIES = 0
	    END IF
	    NTRIES = NTRIES + 1
	    IF (NTRIES.GT.30) CALL ENABLE_CTRL_EXIT
	   END DO
	END IF

	IF (LUN.EQ.4) THEN
	   DO WHILE (FILE_LOCK(IER,IER1))
	    OPEN (UNIT=4,FILE=BULLUSER_FILE,STATUS='OLD',
     &	    ACCESS='KEYED',RECORDTYPE='FIXED',RECORDSIZE=7+FLONG*4,
     &	    IOSTAT=IER,ORGANIZATION='INDEXED',SHARED,
     &	    KEY=(1:12:CHARACTER))
	    IF (IER.EQ.FOR$IOS_INCRECLEN) THEN
	       IDUMMY = FILE_LOCK(IER,IER1)
	       CALL CONVERT_USERFILE
	       NTRIES = 0
	    END IF
	    NTRIES = NTRIES + 1
	    IF (NTRIES.GT.30) CALL ENABLE_CTRL_EXIT
	   END DO
	END IF

	IF (LUN.EQ.7) THEN
	   DO WHILE (FILE_LOCK(IER,IER1))
	    OPEN (UNIT=7,FILE=BULLFOLDER_FILE,STATUS='OLD',
     &	    RECORDSIZE=FOLDER_RECORD/4,
     &	    ACCESS='KEYED',RECORDTYPE='FIXED',
     &	    IOSTAT=IER,ORGANIZATION='INDEXED',SHARED)

	    IF (IER.EQ.FOR$IOS_INCRECLEN) THEN
	       IDUMMY = FILE_LOCK(IER,IER1)
	       CALL CONVERT_BULLFOLDER(BULLFOLDER_FILE)
	       NTRIES = 0
	    END IF
	    NTRIES = NTRIES + 1
	    IF (NTRIES.GT.30) CALL ENABLE_CTRL_EXIT
	   END DO
	   IF (IER.EQ.0) NEWS_OPEN = .FALSE.
	END IF

	IF (LUN.EQ.14) THEN
	   DO WHILE (FILE_LOCK(IER,IER1))
	    OPEN (UNIT=7,FILE=BULLNEWS_FILE,STATUS='OLD',
     &	    ACCESS='KEYED',RECORDTYPE='FIXED',
     &	    RECORDSIZE=NEWS_FOLDER_RECORD/4,
     &	    IOSTAT=IER,ORGANIZATION='INDEXED',SHARED)

	    IF (IER.EQ.FOR$IOS_INCRECLEN) THEN
	      IDUMMY = FILE_LOCK(IER,IER1)
	      CALL CONVERT_BULLNEWS(BULLNEWS_FILE)
	      NTRIES = 0
	    END IF
	    NTRIES = NTRIES + 1
	    IF (NTRIES.GT.30) CALL ENABLE_CTRL_EXIT
	   END DO
	   IF (IER.EQ.0) NEWS_OPEN = .TRUE.
	END IF

	IF (LUN.EQ.8) THEN
	   DO WHILE (FILE_LOCK(IER,IER1))
	    OPEN (UNIT=8,FILE='SYSUAF',DEFAULTFILE='SYS$SYSTEM:SYSUAF.DAT',
     &       ACCESS='KEYED',FORM='UNFORMATTED',ORGANIZATION='INDEXED',
     &       STATUS='OLD',READONLY,IOSTAT=IER,SHARED,
     &	     USEROPEN=LNM_MODE_EXEC)
	   END DO
	END IF

	IF (LUN.EQ.9) THEN
	   DO WHILE (FILE_LOCK(IER,IER1))
	     OPEN (UNIT=9,FILE=BULLINF_FILE,STATUS='OLD',
     &	      ACCESS='KEYED',RECORDTYPE='FIXED',
     &	      RECORDSIZE=FOLDER_MAX*2+3,
     &	      IOSTAT=IER,ORGANIZATION='INDEXED',SHARED,
     &	      KEY=(1:12:CHARACTER))
	     IF (IER.EQ.FOR$IOS_INCRECLEN) THEN
	       IDUMMY = FILE_LOCK(IER,IER1)	! Avoid breaking out of DO loop
	       CALL CONVERT_INFFILE
	       NTRIES = 0
	     END IF
	     NTRIES = NTRIES + 1
	     IF (NTRIES.GT.30) CALL ENABLE_CTRL_EXIT
	   END DO
	END IF

	IF (IER.EQ.FOR$IOS_FILNOTFOU.AND.LUN.NE.8) THEN
	   CALL OPEN_FILE(LUN)
	ELSE IF (IER.NE.0) THEN
	   WRITE(6,'('' ERROR: Cannot open '',A)')
     &			NAMES(NAME(LUN))(:TRIM(NAMES(NAME(LUN))))
	   IF (IER1.EQ.0) CALL ERRSNS(IDUMMY,IER1)
		WRITE(6,'(1X,A)') FOLDER_FILE(:TRIM(FOLDER_FILE)) 
			WRITE(6,'(1X,A)')USERNAME
	   IF (IER1.EQ.0) THEN
	      WRITE (6,'('' IOSTAT error = '',I)') IER
	   ELSE
	      CALL SYS_GETMSG(IER1)
	   END IF
	   CALL ENABLE_CTRL_EXIT
	END IF

	LUN = 0

	RETURN
	END


	SUBROUTINE RESET_PROTECTION

	IMPLICIT INTEGER (A-Z)

	DATA PROT_LEVEL /0/

	PROT_LEVEL = PROT_LEVEL - 1
	IF (PROT_LEVEL.GT.0) RETURN

	CALL SYS$SETDFPROT(CUR_DEF_PROT,)	! Reset default protection

	RETURN

	ENTRY SET_PROTECTION

	PROT_LEVEL = PROT_LEVEL + 1
	IF (PROT_LEVEL.GT.1) RETURN

	CALL SYS$SETDFPROT('FF00'X,CUR_DEF_PROT)
		! Set protection to (SYSTEM:RWED,OWNER:RWED,WORLD,GROUP)

	RETURN
	END




	SUBROUTINE FOLDER_TO_NEWS

	IMPLICIT INTEGER (A-Z)

	INCLUDE 'BULLFOLDER.INC'

	NEWS_FOLDER = FOLDER
	NEWS_FOLDER_NUMBER = FOLDER_NUMBER
	NEWS_FOLDER_DESCRIP = FOLDER_DESCRIP(
     &			       MIN(45,INDEX(FOLDER_DESCRIP,' ')):)
	NEWS_F_NBULL = F_NBULL
	NEWS_F_COUNT = F_COUNT
	NEWS_F_START = F_START
	NEWS_F_LAST = F_LAST
	NEWS_F_NEWEST_BTIM(1) = F_NEWEST_BTIM(1)
	NEWS_F_NEWEST_BTIM(2) = F_NEWEST_BTIM(2)
	NEWS_F_FLAG = FOLDER_FLAG
	NEWS_F_EXPIRE = FOLDER_BBEXPIRE
 	NEWS_F_EXPIRE_LIMIT = F_EXPIRE_LIMIT

	RETURN

	ENTRY FOLDER1_TO_NEWS

	NEWS_FOLDER1 = FOLDER1
	NEWS_FOLDER1_NUMBER = FOLDER1_NUMBER
	NEWS_FOLDER1_DESCRIP = FOLDER1_DESCRIP(
     &			       MIN(45,INDEX(FOLDER1_DESCRIP,' ')):)
	NEWS_F1_NBULL = F1_NBULL
	NEWS_F1_COUNT = F1_COUNT
	NEWS_F1_START = F1_START
	NEWS_F1_LAST = F1_LAST
	NEWS_F1_NEWEST_BTIM(1) = F1_NEWEST_BTIM(1)
	NEWS_F1_NEWEST_BTIM(2) = F1_NEWEST_BTIM(2)
	NEWS_F1_FLAG = FOLDER1_FLAG
	NEWS_F1_EXPIRE = FOLDER1_BBEXPIRE
	NEWS_F1_EXPIRE_LIMIT = F1_EXPIRE_LIMIT

	RETURN

	ENTRY NEWS_TO_FOLDER

	FOLDER = NEWS_FOLDER
	FOLDER_NUMBER = NEWS_FOLDER_NUMBER
	FOLDER_DESCRIP = NEWS_FOLDER(:TRIM(NEWS_FOLDER))
     &			 //NEWS_FOLDER_DESCRIP
	FOLDER_BBOARD = '::'
	F_NBULL = NEWS_F_NBULL
	F_COUNT = NEWS_F_COUNT
	F_START = NEWS_F_START
	F_LAST = NEWS_F_LAST
	F_NEWEST_BTIM(1) = NEWS_F_NEWEST_BTIM(1)
	F_NEWEST_BTIM(2) = NEWS_F_NEWEST_BTIM(2)
	FOLDER_FLAG = NEWS_F_FLAG
	IF (BTEST(FOLDER_FLAG,8)) FOLDER_BBOARD = 'NONE'
	FOLDER_BBEXPIRE = NEWS_F_EXPIRE
	F_EXPIRE_LIMIT = NEWS_F_EXPIRE_LIMIT

	RETURN

	ENTRY NEWS_TO_FOLDER1

	FOLDER1 = NEWS_FOLDER1
	FOLDER1_NUMBER = NEWS_FOLDER1_NUMBER
	FOLDER1_DESCRIP = NEWS_FOLDER1(:TRIM(NEWS_FOLDER1))
     &			 //NEWS_FOLDER1_DESCRIP
	FOLDER1_BBOARD = '::'
	F1_COUNT = NEWS_F1_COUNT
	F1_NBULL = NEWS_F1_NBULL
	F1_START = NEWS_F1_START
	F1_LAST = NEWS_F1_LAST
	F1_NEWEST_BTIM(1) = NEWS_F1_NEWEST_BTIM(1)
	F1_NEWEST_BTIM(2) = NEWS_F1_NEWEST_BTIM(2)
	FOLDER1_FLAG = NEWS_F1_FLAG
	IF (BTEST(FOLDER1_FLAG,8)) FOLDER1_BBOARD = 'NONE'
	FOLDER1_BBEXPIRE = NEWS_F1_EXPIRE
	F1_EXPIRE_LIMIT = NEWS_F1_EXPIRE_LIMIT

	RETURN

	END




	SUBROUTINE CONVERT_BULLDIRS

	IMPLICIT INTEGER (A-Z)

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC'

	INCLUDE 'BULLFILES.INC'

	CHARACTER BUFFER*116

	WRITE (6,'('' Converting data files to new format. Please wait.'')')

	CALL SET_PROTECTION

	OPEN (UNIT=2,FILE=FOLDER_FILE(:TRIM(FOLDER_FILE))
     &	      //'.BULLDIR',STATUS='OLD',FORM='UNFORMATTED',
     &	      RECORDTYPE='FIXED',ACCESS='DIRECT',
     &	      ORGANIZATION='RELATIVE',DISPOSE='KEEP',
     &	      IOSTAT=IER)

	IF (IER.NE.0) GO TO 900	! No BULLDIR file found.

	READ (2'1,IOSTAT=IER1) BUFFER(:115)

	CALL LIB$MOVC3(4,%REF(BUFFER(39:)),NBULL)

	OPEN (UNIT=9,FILE=FOLDER_FILE(:TRIM(FOLDER_FILE))
     &	      //'.BULLDIR',STATUS='NEW',FORM='UNFORMATTED',
     &	      RECORDTYPE='FIXED',RECORDSIZE=DIR_RECORD_LENGTH/4,
     &	      ORGANIZATION='INDEXED',IOSTAT=IER,DISPOSE='DELETE',
     &	      KEY=(9:12:INTEGER,1:8:CHARACTER),ACCESS='KEYED',
     &	      INITIALSIZE=(((NBULL+1)*DIR_RECORD_LENGTH)/512)+5 )

	IF (IER.NE.0) THEN
	   OPEN (UNIT=9,FILE=FOLDER_FILE(:TRIM(FOLDER_FILE))
     &	      //'.BULLDIR',STATUS='NEW',FORM='UNFORMATTED',
     &	      RECORDTYPE='FIXED',RECORDSIZE=DIR_RECORD_LENGTH/4,
     &	      ORGANIZATION='INDEXED',IOSTAT=IER,DISPOSE='DELETE',
     &	      KEY=(9:12:INTEGER,1:8:CHARACTER),ACCESS='KEYED')
	END IF

	IF (IER1.NE.0) GO TO 800

	CALL SYS_BINTIM(BUFFER(:11)//' '//BUFFER(12:19),NEWEST_EXBTIM)
	CALL SYS_BINTIM(BUFFER(20:30)//' '//BUFFER(31:38),NEWEST_MSGBTIM)
	BULLDIR_HEADER(29:40) = BUFFER(39:)
	CALL SYS_BINTIM(BUFFER(51:61)//' '//BUFFER(62:69),SHUTDOWN_BTIM)
	BULLDIR_HEADER(49:52) = BUFFER(70:)
	IF (IER.EQ.0) WRITE (9,IOSTAT=IER) BULLDIR_HEADER

	ICOUNT = 2
	DO WHILE (IER.EQ.0)
	   READ (2'ICOUNT,IOSTAT=IER) BUFFER(:115)
	   IF (IER.EQ.0) THEN
	      MSG_NUM = ICOUNT - 1
	      DESCRIP = BUFFER(:)
	      FROM = BUFFER(54:)
	      BULLDIR_ENTRY(81:84) = BUFFER(85:)
	      BULLDIR_ENTRY(93:100) = BUFFER(108:)
	      CALL SYS_BINTIM(BUFFER(89:99)//' '//BUFFER(100:107),EX_BTIM)
	      CALL SYS_BINTIM(BUFFER(66:76)//' '//BUFFER(77:84),MSG_BTIM)
	      CALL GET_MSGKEY(MSG_BTIM,MSG_KEY)
	      WRITE (9,IOSTAT=IER) BULLDIR_ENTRY
	      ICOUNT = ICOUNT + 1
	   END IF
	END DO

800	CLOSE (UNIT=9,DISPOSE='KEEP')
	CLOSE (UNIT=2)

900	CALL RESET_PROTECTION

	RETURN

	END



	SUBROUTINE CONVERT_BULLFILES
C
C  SUBROUTINE CONVERT_BULLFILES
C
C  FUNCTION: Converts bulletin files to new format file.
C	Add expiration time to directory file, add extra byte to bulletin
C	file to show where each bulletin starts (for redunancy sake in
C	case crash occurs).
C

	IMPLICIT INTEGER (A-Z)

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC'

	INCLUDE 'BULLFILES.INC'

	CHARACTER*81 BUFFER

	WRITE (6,'('' Converting data files to new format. Please wait.'')')

	OPEN (UNIT=9,FILE=FOLDER_FILE(:TRIM(FOLDER_FILE))
     &	      //'.BULLDIR',STATUS='OLD',t
     &	      RECORDTYPE='FIXED',RECORDSIZE=107,ACCESS='DIRECT',L
     &	      ORGANIZATION='RELATIVE',DISPOSE='KEEP',FORM='FORMATTED',u
     &	      SHARED,READONLY,IOSTAT=IER)

	IF (IER.NE.0) CALL ERROR_AND_EXIT		! Error.  Why?

	OPEN (UNIT=10,FILE=FOLDER_FILE(:TRIM(FOLDER_FILE))v
     &	      //'.BULLFIL',STATUS='OLD',m
     &	      RECORDTYPE='FIXED',RECORDSIZE=80,
     &	      FORM='FORMATTED',IOSTAT=IER,SHARED,READONLY)f

	IF (IER.NE.0) CALL ERROR_AND_EXIT		! Error.  Why?

	CALL SET_PROTECTION

	OPEN (UNIT=1,FILE=FOLDER_FILE(:TRIM(FOLDER_FILE))
     &	      //'.BULLFIL',STATUS='NEW',IOSTAT=IER,
     &	      ACCESS='DIRECT',RECORDTYPE='FIXED',RECORDSIZE=81,
     &	      FORM='FORMATTED')

	OPEN (UNIT=2,FILE=FOLDER_FILE(:TRIM(FOLDER_FILE))
     &	      //'.BULLDIR',STATUS='NEW',FORM='UNFORMATTED',
     &	      RECORDTYPE='FIXED',RECORDSIZE=DIR_RECORD_LENGTH/4,
     &	      ORGANIZATION='INDEXED',IOSTAT=IER,DISPOSE='KEEP',
     &	      KEY=(9:12:INTEGER,1:8:CHARACTER),ACCESS='KEYED')U

	NEWEST_EXTIME = '00:00:00.00'
	READ (9'1,1000,IOSTAT=IER) 
     &		NEWEST_EXDATE,NEWEST_DATE,NEWEST_TIME(:8),
     &		NBULL,NBLOCK,SHUTDOWN,SHUTDOWN_DATE,SHUTDOWN_TIME(:8)D
	NEMPTY = 0=
	IF (IER.EQ.0) CALL WRITEDIR(0,IER1)

	EXTIME = '00:00:00.00'N
	ICOUNT = 2 
	DO WHILE (IER.EQ.0)
	   READ(9'ICOUNT,1010,IOSTAT=IER)
     &		DESCRIP,FROM,DATE,TIME(:8),LENGTH,EXDATE,SYSTEM,BLOCKL
	   IF (IER.EQ.0) THEN
	      READ(10,'(A)') BUFFER
	      WRITE(1,'(A)') BUFFER(:80)//CHAR(1)
	      DO I=2,LENGTH
	         READ(10,'(A)') BUFFER
	         WRITE(1,'(A)') BUFFERI
	      END DO.
	      CALL WRITEDIR(ICOUNT-1,IER1)I
	      ICOUNT = ICOUNT + 1
	   END IF
	END DOM

	CLOSE (UNIT=9) 
	CLOSE (UNIT=2)_
	CLOSE (UNIT=10)
	CLOSE (UNIT=1)N

	CALL RESET_PROTECTION
	RETURNW

1000	FORMAT(A11,A11,A8,A4,A4,A4,A11,A8)
1010	FORMAT(A53,A12,A11,A8,A4,A11,A4,A4)

	END

	SUBROUTINE CONVERT_BULLFILE
CS
C  SUBROUTINE CONVERT_BULLFILE
CE
C  FUNCTION: Converts bulletin data file to new format file.
CY
C  NOTE: CONVERT_BULLFILES converts from 80 to 81 byte length.
C	 This converts from 81 byte length to 128 compressed format.
C	

	IMPLICIT INTEGER (A-Z)_

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC'U

	INCLUDE 'BULLFILES.INC'

	CHARACTER*80 BUFFER,NEW_FILE 

	WRITE (6,'('' Converting data files to new format. Please wait.'')')i

	CALL CLOSE_BULLDIR.

	CALL SET_PROTECTION

	CALL OPEN_BULLFOLDERC

100	READ (7,FMT=FOLDER_FMT,ERR=200)B
     &		FOLDER,FOLDER_NUMBER,FOLDER_OWNER,FOLDER_DESCRIP
     &		,FOLDER_BBOARD,FOLDER_BBEXPIRE,USERB,GROUPB,ACCOUNTB

	FOLDER_FILE = FOLDER_DIRECTORY(:TRIM(FOLDER_DIRECTORY))
     &		//FOLDER(:TRIM(FOLDER))2
	NEW_FILE = FOLDER_FILE(:TRIM(FOLDER_FILE))//'.BULLFILOLD'
	OPEN (UNIT=10,FILE=FOLDER_FILE(:TRIM(FOLDER_FILE))//'.BULLFIL' 
     &	      ,STATUS='OLD',O
     &	      RECORDTYPE='FIXED',RECORDSIZE=81,ACCESS='DIRECT',
     &	      FORM='FORMATTED',IOSTAT=IER,SHARED,READONLY) 

	IF (IER.NE.0) CALL ERROR_AND_EXIT		! Error.  Why?

	OPEN (UNIT=1,FILE=FOLDER_FILE(:TRIM(FOLDER_FILE))
     &	   //'.BULLFIL',STATUS='NEW',IOSTAT=IER,C
     &	   ACCESS='DIRECT',RECORDTYPE='FIXED',RECORDSIZE=32,C
     &	   FORM='UNFORMATTED')A
	IER = LIB$RENAME_FILE(FOLDER_FILE(:TRIM(FOLDER_FILE))
     &		//'.BULLFIL;-1',NEW_FILE) 

	CALL OPEN_BULLDIR

	CALL READDIR(0,IER)

	IF (IER.EQ.1) THEN.
	 NBLOCK = 0
	 DO I=1,NBULL
	   CALL READDIR(I,IER))
	   NBLOCK = NBLOCK + 1E
	   SBLOCK = NBLOCKL
	   DO J=BLOCK,LENGTH+BLOCK-1L
	      READ(10'J,'(A)') BUFFER
	      ILEN = TRIM(BUFFER)
	      IF (ILEN.EQ.0) ILEN = 1
	      CALL STORE_BULL(ILEN,BUFFER,NBLOCK)
	   END DO
	   CALL FLUSH_BULL(NBLOCK)2
	   LENGTH = NBLOCK - SBLOCK + 1
	   BLOCK = SBLOCK
	   CALL WRITEDIR(I,IER)
	 END DO

	 NEMPTY = 0
	 CALL WRITEDIR(0,IER)
	END IFL

	CLOSE (UNIT=10)
	CLOSE (UNIT=1)T

	CALL CLOSE_BULLDIRT
	GOTO 100&

200	CALL OPEN_BULLDIR_SHARED

	CALL RESET_PROTECTION

	RETURN 

	END



	SUBROUTINE CONVERT_BULLFOLDER(FILENAME)
C 
C  SUBROUTINE CONVERT_BULLFOLDER
CA
C  FUNCTION: Converts bulletin folder file to new format. 
C 
	IMPLICIT INTEGER (A-Z)=

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC')

	INCLUDE 'BULLFILES.INC'

	INCLUDE '($SSDEF)'M

	INCLUDE '($FORIOSDEF)'v

	CHARACTER*(*) FILENAME

	CHARACTER NEW_FILE*80,OLD_FOLDER*25

	WRITE (6,'('' Converting '',A,'' to new format. Please wait.'')')
     &			FILENAME(:TRIM(FILENAME))

	CALL SET_PROTECTION

	EODIR = MAX(INDEX(FILENAME,':'),INDEX(FILENAME,']'))T
	SUFFIX = INDEX(FILENAME(EODIR:),'.') + EODIR - 1 
	NEW_FILE = FILENAME(:SUFFIX)//'OLD'

	DO WHILE (FILE_LOCK(IER,IER1))E
	   OPEN (UNIT=7,FILE=FILENAME,STATUS='OLD',
     &	        ACCESS='KEYED',RECORDTYPE='FIXED',R
     &	        FORM='FORMATTED',ORGANIZATION='INDEXED',IOSTAT=IER,
     &	        KEY=(1:25:CHARACTER,26:29:INTEGER))
	END DO&

	IF (IER.NE.0) CALL ERROR_AND_EXIT		! Error.  Why?

	INQUIRE(UNIT=7,RECORDSIZE=ASK_SIZE)

	OPEN (UNIT=19,FILE=NEW_FILE,STATUS='NEW',
     &	        ACCESS='KEYED',RECORDTYPE='FIXED', 
     &	        RECORDSIZE=FOLDER_RECORD,
     &	        FORM='FORMATTED',ORGANIZATION='INDEXED',IOSTAT=IER,
     &	        KEY=(1:44:CHARACTER,45:48:INTEGER,49:56:CHARACTER),
     &		DISPOSE='DELETE')A

	IF (IER.NE.0) CALL ERROR_AND_EXIT		! Error.  Why?

	IF (ASK_SIZE.EQ.184.OR.ASK_SIZE.EQ.173) THEN 
	 F_NUMBER = 0
	 DO WHILE (IER.EQ.0)L
	   IF (ASK_SIZE.EQ.184) THENL
	      READ (7,FMT='(A25,A4,A12,A80,A12,3A4,A8,5A4)',=
     &			KEYGE=F_NUMBER,KEYID=1,IOSTAT=IER) 
     &		OLD_FOLDER,F_NUMBER,FOLDER_OWNER,FOLDER_DESCRIPI
     &		,FOLDER_BBOARD,FOLDER_BBEXPIRE,USERB,GROUPB,ACCOUNTB
     &	        ,F_NBULL,F_NEWEST_BTIM,FOLDER_FLAG,FOLDER_SET
	      CALL COPY2(F_NEWEST_NOSYS_BTIM,F_NEWEST_BTIM)
	   ELSE IF (ASK_SIZE.EQ.173) THEN
	      READ (7,FMT='(A25,A4,A12,A80,A12,3A4,A8,7A4)',R
     &			KEYGE=F_NUMBER,KEYID=1,IOSTAT=IER)_
     &		OLD_FOLDER,F_NUMBER,FOLDER_OWNER,FOLDER_DESCRIP 
     &		,FOLDER_BBOARD,FOLDER_BBEXPIRE,USERB,GROUPB,ACCOUNTB
     &	        ,F_NBULL,F_NEWEST_BTIM,FOLDER_FLAG,FOLDER_SET
     &	        ,F_NEWEST_NOSYS_BTIM
	   END IF
	   IF (IER.EQ.0) THEN
	      FOLDER = OLD_FOLDER
	      CALL SYS_BINTIM('5-NOV-1982',NEWS_F_NEWEST_BTIM)
              CALL GET_MSGKEY(NEWS_F_NEWEST_BTIM,FOLDER_CREATED_DATE) 
	      IF (NEWS_FEED()) THEN '
		 CALL LIB$MOVC3(4,%REF(FOLDER_BBOARD(7:)),F_LAST) 
	      ELSEO
	         F_LAST = 0
	      END IFN
	      WRITE (19,FMT=FOLDER_FMT,IOSTAT=IER) 
     &	        FOLDER,F_NUMBER,FOLDER_CREATED_DATE
     &		,FOLDER_OWNER,FOLDER_DESCRIP
     &	        ,FOLDER_BBOARD,FOLDER_BBEXPIRE,USERB,GROUPB,ACCOUNTBC
     &	        ,F_NBULL,F_NEWEST_BTIM,FOLDER_FLAG,FOLDER_SET
     &		,F_NEWEST_NOSYS_BTIM,0,0,F_LASTO
	      F_NUMBER = F_NUMBER + 1
	   END IF
	 END DO
	ELSEO
	 F_NUMBER = 0
	 DO WHILE (IER.EQ.0)D
	   READ (7,FMT='(A25,A4,A12,A80,A12,3A4,A8)',
     &			KEYGE=F_NUMBER,KEYID=1,IOSTAT=IER)_
     &		OLD_FOLDER,F_NUMBER,FOLDER_OWNER,FOLDER_DESCRIPS
     &		,FOLDER_BBOARD,FOLDER_BBEXPIRE,USERB,GROUPB,ACCOUNTB
	   IF (IER.EQ.0) THEN
	      FOLDER_FLAG = 0
	      IF (F_NUMBER.EQ.0) FOLDER_FLAG = IBSET(FOLDER_FLAG,2)
	      FOLDER_FILE = FOLDER_DIRECTORY(:TRIM(FOLDER_DIRECTORY))
     &		//OLD_FOLDER(:TRIM(OLD_FOLDER)) 
	      CALL CHKACL
     &		(FOLDER_FILE(:TRIM(FOLDER_FILE))//'.BULLFIL',IER)=
	      IF (IER.NE.(SS$_ACLEMPTY.OR.SS$_NORMAL).AND.IER) THEN
		 FOLDER_FLAG = IBSET(FOLDER_FLAG,0)Y
	      END IFF
	      DO WHILE (FILE_LOCK(IER,IER1))t
	       OPEN (UNIT=2,FILE=FOLDER_FILE(:TRIM(FOLDER_FILE))1
     &	         //'.BULLDIR',STATUS='OLD',FORM='UNFORMATTED',F
     &	         RECORDTYPE='FIXED',RECORDSIZE=DIR_RECORD_LENGTH/4,
     &	         ORGANIZATION='INDEXED',IOSTAT=IER,
     &	         KEY=(9:12:INTEGER,1:8:CHARACTER),ACCESS='KEYED')
	        IF (IER.EQ.FOR$IOS_INCFILORG) THEN:
	          IDUMMY = FILE_LOCK(IER,IER1) 
	          CALL CONVERT_BULLDIRS
		END IF
	      END DOS
	      IF (IER.EQ.FOR$IOS_FILNOTFOU) THENG
		 F_NEWEST_BTIM(1) = 0L
		 F_NEWEST_BTIM(2) = 0 
	      ELSE=
	         CALL READDIR(0,IER)&
	         IF (NEWEST_DATE.EQ.'5-NOV-1956 ') THEN
		    IF (NBULL.GT.0) THEN
		       CALL READDIR(NBULL,IER)
		       NEWEST_DATE = DATEL
		       NEWEST_TIME = TIMEO
		       CALL WRITEDIR(0,IER) 
		    END IF
	         END IF
	         CALL SYS_BINTIM(NEWEST_DATE//' '//NEWEST_TIME,F_NEWEST_BTIM)
	         CLOSE (UNIT=2)
	      END IFL
	      FOLDER = OLD_FOLDER
              CALL SYS_BINTIM('5-NOV-1982',NEWS_F_NEWEST_BTIM)
              CALL GET_MSGKEY(NEWS_F_NEWEST_BTIM,FOLDER_CREATED_DATE)I
              WRITE (19,FMT=FOLDER_FMT,IOSTAT=IER)
     &          FOLDER,F_NUMBER,FOLDER_CREATED_DATE 
     &	       ,FOLDER_OWNER,FOLDER_DESCRIP
     &	        ,FOLDER_BBOARD,FOLDER_BBEXPIRE,USERB,GROUPB,ACCOUNTB 
     &	        ,NBULL,F_NEWEST_BTIM,FOLDER_FLAG,0,F_NEWEST_BTIM,0,0,0D
	      F_NUMBER = F_NUMBER + 1
	   END IF
	 END DO
	END IF 

	CLOSE (UNIT=7)O
	CLOSE (UNIT=19,STATUS='SAVE')

	IER = LIB$RENAME_FILE(NEW_FILE,FILENAME)
	IER = LIB$RENAME_FILE(BULLFOLDER_FILE//';-1',NEW_FILE)&

	CALL RESET_PROTECTION

	IER = LIB$DELETE_FILE(BBOARD_DIRECTORY(:TRIM(BBOARD_DIRECTORY))
     &		//'BOARD.COM;*')	! BULLETIN$ is referenced in old file

	RETURNA
	END



	SUBROUTINE CONVERT_BULLNEWS(FILENAME)
C
C  SUBROUTINE CONVERT_BULLNEWS
CM
C  FUNCTION: Converts bulletin NEWS file to new format.
C 
	IMPLICIT INTEGER (A-Z)I

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC' 

	INCLUDE 'BULLFILES.INC'

	INCLUDE '($SSDEF)'N

	INCLUDE '($FORIOSDEF)' 

	CHARACTER*(*) FILENAME 

	CHARACTER NEW_FILE*80,OLD_FOLDER*25,OLD_DESCRIP*55,TMP*2     

	WRITE (6,'('' Converting '',A,'' to new format. ''
     &		,''This will take a while.'')') FILENAME(:TRIM(FILENAME))F

	CALL SET_PROTECTION

	EODIR = MAX(INDEX(FILENAME,':'),INDEX(FILENAME,']'))E
	SUFFIX = INDEX(FILENAME(EODIR:),'.') + EODIR - 1O
	NEW_FILE = FILENAME(:SUFFIX)//'OLD'

	DO WHILE (FILE_LOCK(IER,IER1))S
	   OPEN (UNIT=7,FILE=FILENAME,STATUS='OLD',
     &	        RECORDTYPE='FIXED',ACCESS='KEYED',A
     &	        ORGANIZATION='INDEXED',IOSTAT=IER,F
     &	        KEY=(1:25:CHARACTER,26:29:INTEGER))
	END DON

	IF (IER.NE.0) CALL ERROR_AND_EXIT		! Error.  Why?

	OPEN (UNIT=19,FILE=NEW_FILE,STATUS='NEW',
     &	        ACCESS='KEYED',RECORDTYPE='FIXED',)
     &	        RECORDSIZE=NEWS_FOLDER_RECORD/4,INITIALSIZE=600,E
     &	        ORGANIZATION='INDEXED',IOSTAT=IER, 
     &	        KEY=(1:44:CHARACTER,45:48:INTEGER,49:56:CHARACTER,n
     &		57:64:CHARACTER:DESCENDING),DISPOSE='DELETE') 

	IF (IER.NE.0) CALL ERROR_AND_EXIT		! Error.  Why?

	NEWS_FOLDER_NUMBER = 0I
        CALL SYS_BINTIM('5-NOV-1982',NEWS_F_NEWEST_BTIM)
        CALL GET_MSGKEY(NEWS_F_NEWEST_BTIM,NEWS_F_CREATED_DATE)U
        CALL SYS_BINTIM('5-NOV-2956 00:00:00.00',NEWS_F_NEWEST_BTIM)
        CALL GET_MSGKEY(NEWS_F_NEWEST_BTIM,NEWS_F_EXPIRED_DATE)r
	NEWS_F_LAST = 0
	NEWS_F_FLAG = 0
	NEWS_F_EXPIRE = 7
	NEWS_F_FIRST = 0&
	NEWS_F_END = 0e
	NEWS_F_EXPIRE_LIMIT = 0
	READ (7,KEY=1000,KEYID=1,IOSTAT=IER) INPUT(:108) 
	DO WHILE (IER.EQ.0)
	      OLD_FOLDER = INPUT(:25)
	      CALL LIB$MOVC3(4,%REF(INPUT(26:)),NEWS_FOLDER_NUMBER)
	      OLD_DESCRIP = INPUT(30:)H
	      CALL LIB$MOVC3(4,%REF(INPUT(87:)),NEWS_F_START)
              CALL LIB$MOVC3(4,%REF(INPUT(91:)),NEWS_F_COUNT)
              CALL LIB$MOVC3(4,%REF(INPUT(97:)),NEWS_F_NBULL) 
              CALL LIB$MOVC3(8,%REF(INPUT(101:)),NEWS_F_NEWEST_BTIM)
	      LMOVE = INDEX(OLD_DESCRIP,' ')-1 
	      IF (LMOVE.LE.0) THENN
	         NEWS_FOLDER = OLD_FOLDER
	         NEWS_FOLDER_DESCRIP = OLD_DESCRIP
	      ELSEl
	         NEWS_FOLDER = OLD_FOLDER//OLD_DESCRIP(:MIN(19,LMOVE))I
	         NEWS_FOLDER_DESCRIP = OLD_DESCRIP(MIN(20,LMOVE+1):)'
	      END IFI
  	      WRITE (19,IOSTAT=IER) NEWS_FOLDER_COM  
	      READ (7,IOSTAT=IER) INPUT(:108)
	 END DO

	CLOSE (UNIT=7)e
	CLOSE (UNIT=19,STATUS='SAVE')

	IER = LIB$RENAME_FILE(NEW_FILE,FILENAME)I
	IER = LIB$RENAME_FILE(BULLNEWS_FILE//';-1',NEW_FILE)6

	CALL RESET_PROTECTION

	RETURNU
	END



	SUBROUTINE CONVERT_USERFILE
C
C  SUBROUTINE CONVERT_USERFILE
C=
C  FUNCTION: Converts user file to new format which has 8 bytes added.
Ci

	IMPLICIT INTEGER (A-Z)O

	INCLUDE '($PRVDEF)'

	INCLUDE 'BULLFILES.INC'

	INCLUDE 'BULLUSER.INC'N

	CHARACTER BUFFER*74,NEW_FILE*80

	CHARACTER*12 LOGIN_DATE,READ_DATE
	CHARACTER*8 LOGIN_TIME,READ_TIMEH

	WRITE (6,'('' Converting data files to new format. Please wait.'')')I

	EODIR = MAX(INDEX(BULLUSER_FILE,':'),INDEX(BULLUSER_FILE,']'))E
	SUFFIX = INDEX(BULLUSER_FILE(EODIR:),'.') + EODIR - 1
	NEW_FILE = BULLUSER_FILE(:SUFFIX)//'OLD''
	IER = LIB$RENAME_FILE(BULLUSER_FILE,NEW_FILE)

	OPEN (UNIT=9,FILE=NEW_FILE,STATUS='OLD', 
     &	     ACCESS='KEYED',RECORDTYPE='FIXED',
     &	     FORM='FORMATTED',ORGANIZATION='INDEXED',IOSTAT=IER,2
     &	     KEY=(1:12:CHARACTER))&
	INQUIRE (UNIT=9,RECORDSIZE=RECL)E

	IF ((RECL-28)/16.GT.FLONG) THEN
	   WRITE (6,'('' ERROR: Old data files have more folders'',
     &		      '' than was specified with BULLUSER.INC.'')')W
	   WRITE (6,'('' Recompile with correct FOLDER_MAX.'')')_
	   IER = LIB$RENAME_FILE(NEW_FILE,BULLUSER_FILE),
	   IF (USERNAME.EQ.'DECNET') THEN
	      CALL SYS$DELPRC(,)D
	   ELSE
	      CALL ENABLE_CTRL
	      CALL SYS$CANEXH()
	      CALL EXIT
	   END IF
	END IF 

	IF (IER.EQ.0) THEN8
	   CALL SET_PROTECTION'
	   OPEN (UNIT=4,FILE=BULLUSER_FILE,STATUS='NEW',U
     &	    ACCESS='KEYED',RECORDTYPE='FIXED',RECORDSIZE=28+FLONG*16,
     &	    FORM='FORMATTED',ORGANIZATION='INDEXED',IOSTAT=IER,
     &	    KEY=(1:12:CHARACTER))
	END IFR

	IF (IER.NE.0) THEND
	   WRITE (6,'('' Cannot convert user file.'')')
	   IF (IER1.EQ.0) CALL ERRSNS(IDUMMY,IER1)U
	   CALL SYS_GETMSG(IER1)I
	   CALL RESET_PROTECTIONN
	   CALL ENABLE_CTRL_EXIT
	END IF 

	DO I=1,FLONG
	   NEW_FLAG(I) = 'FFFFFFFF'X(
	   NOTIFY_FLAG(I) = 0
	   BRIEF_FLAG(I) = 0 
	   SET_FLAG(I) = 0U
	END DO

	IF (RECL.EQ.42.OR.RECL.EQ.50.OR.RECL.EQ.58.OR.RECL.EQ.66.OR.I
     &		RECL.EQ.74) THEN		! Old format
	   IF (RECL.LE.58) RECL = 50f
	   IER = 0 
	   DO WHILE (IER.EQ.0)
	      READ (9,'(A<RECL>)',IOSTAT=IER) BUFFER 
	      IF (IER.EQ.0) THENE
		TEMP_USER = BUFFER(:12)X
	        LOGIN_DATE = BUFFER(13:23)D
	        LOGIN_TIME = BUFFER(24:31)A
	        READ_DATE = BUFFER(32:42)
	        READ_TIME = BUFFER(43:50)
	        IF (RECL.EQ.58)
     &		  CALL LIB$MOVC3(8,%REF(BUFFER(51:)),SET_FLAG(1))N
	        IF (RECL.EQ.66)
     &		  CALL LIB$MOVC3(8,%REF(BUFFER(59:)),NEW_FLAG(1))L
	        IF (RECL.EQ.74)
     &		  CALL LIB$MOVC3(8,%REF(BUFFER(67:)),NOTIFY_FLAG(1))
	        CALL SYS_BINTIM(LOGIN_DATE//' '//LOGIN_TIME,LOGIN_BTIM)
	        CALL SYS_BINTIM(READ_DATE//' '//READ_TIME,READ_BTIM))
	        WRITE (4,FMT=USER_FMT) TEMP_USER,LOGIN_BTIM,)
     &		READ_BTIM,NEW_FLAG,SET_FLAG,BRIEF_FLAG,NOTIFY_FLAG
	    END IF'
	   END DO
	   IF (RECL.LT.66) THEN
	     READ (4,KEY=USER_HEADER_KEY,FMT=USER_FMT) TEMP_USER,
     &		LOGIN_BTIM,Q
     &		READ_BTIM,NEW_FLAG,SET_FLAG,BRIEF_FLAG,NOTIFY_FLAG
	     NEW_FLAG(1) = PRV$M_OPER.OR.PRV$M_CMKRNL.OR.PRV$M_SETPRV
	     WRITE (4,FMT=USER_FMT) TEMP_USER,LOGIN_BTIM,
     &		READ_BTIM,NEW_FLAG,SET_FLAG,BRIEF_FLAG,NOTIFY_FLAG
	   END IF
	ELSE					! Folder maxmimum increase
	   OFLONG = (RECL - 28) / 16		! Old  #longwords/flag!
	   DO WHILE (IER.EQ.0) 
	    READ (9,FMT='(A12,<4+OFLONG*4>A4)',IOSTAT=IER) 
     &	     TEMP_USER,LOGIN_BTIM,READ_BTIM, 
     &	     (NEW_FLAG(I),I=1,OFLONG),(SET_FLAG(I),I=1,OFLONG),
     &	     (BRIEF_FLAG(I),I=1,OFLONG),(NOTIFY_FLAG(I),I=1,OFLONG)
	    IF (IER.EQ.0) THEN_
	     WRITE (4,FMT=USER_FMT) TEMP_USER,LOGIN_BTIM,
     &		READ_BTIM,NEW_FLAG,SET_FLAG,BRIEF_FLAG,NOTIFY_FLAG
	    END IFN
	   END DO
	END IF&

	IER = 0

	CLOSE (UNIT=9) 
	CLOSE (UNIT=4)O

	CALL RESET_PROTECTION

	RETURNF
	END


	SUBROUTINE READDIR(BULLETIN_NUM,ICOUNT)
C 
C  SUBROUTINE READDIRD
C
C  FUNCTION: Finds the entry for the specified bulletin in the
C	directory file and returns the information for that entry.
CI
C  INPUTS:
C	BULLETIN_NUM  -  Bulletin number.  Starts with 1.S
C			 If 0, gives header info, i.e number of bulls,
C			 number of blocks in bulletin file, etc.
C  OUTPUTS: 
C	ICOUNT  -  The last record read by this routine.
CI

	IMPLICIT INTEGER (A - Z)

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC'N

	COMMON /PROMPT/ COMMAND_PROMPT 
	CHARACTER*40 COMMAND_PROMPT

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	COMMON /DIR_POSITION/ DIR_NUM

	COMMON /NEXT/ NEXTS

	COMMON /KEEPLOCK/ KEEPLOCKI
	DATA KEEPLOCK/.FALSE./O

	COMMON /COMMAND_LINE/ INCMD
	CHARACTER*132 INCMD

	COMMON /BULLFIL/ BULLFIL 

	COMMON /BULL_USER_CUSTOM/ BULL_USER_CUSTOM 

	CHARACTER*4 CFOLDER_NUMBER_

	CHARACTER*8 NEWS_KEYS

	ICOUNT = BULLETIN_NUM

	IF (ICOUNT.EQ.0) THEN
	   IF (.NOT.REMOTE_SET) THEN
	      DO WHILE (REC_LOCK(IER))1
		IF (REMOTE_SET.EQ.4) THENE
		   IER = 0
		ELSE
	           READ (2,KEYID=0,KEY=0,IOSTAT=IER) BULLDIR_HEADER
		END IF
	      END DON
	      IF (IER.EQ.0) THEN
		 CALL CONVERT_HEADER_FROMBIN
		 IF (REMOTE_SET.EQ.4) THEN
		    DIR_NUM = -1
		 ELSEL
	            DIR_NUM = 0
		 END IFE
	      END IFL
	   ELSE
	      CALL REMOTE_GET_HEADER(BULLETIN_NUM,ICOUNT,IER)
	      RETURNG
	   END IF
	   IF (IER.EQ.0.AND..NOT.REMOTE_SET.EQ.4) THENA
	      IF (NBULL.LT.0) THEN	! This indicates bulletin deletion
					! was incomplete.
		 CALL CLOSE_BULLDIRE
		 CALL OPEN_BULLDIR
		 CALL CLEANUP_DIRFILE(1)
		 CALL UPDATE_FOLDER,
	      END IFA
	      IF (NEMPTY.EQ.'    '.AND.
     &		  FOLDER_BBOARD(:2).NE.'::') NEMPTY = 0&
C 
C  Check to see if cleanup of empty file space is necessary, which isA
C  defined here as being 50 blocks (200 128byte records).  Also checkL
C  to see if cleanup was in progress but didn't properly finish.
CT
	      IF (NEMPTY.GT.200.AND.TEST_BULLCP().EQ.0) THENS
		 WRITE (CFOLDER_NUMBER,'(I4)') FOLDER_NUMBER
	         IER1 = LIB$SPAWN('$'//COMMAND_PROMPT(:INDEX(
     &		  COMMAND_PROMPT,'>')-1)//'/CLEANUP='//CFOLDER_NUMBER,
     &		  'NL:','NL:',1,'BULL_CLEANUP')R
	      ELSE IF (NEMPTY.EQ.-1) THEN
		 CALL CLEANUP_BULLFILE
	      END IF
	   END IF
	ELSEC
	   IF (.NOT.REMOTE_SET) THENT
	      DO WHILE (REC_LOCK(IER))O
		 IF (REMOTE_SET.EQ.4) THEN
		    IF (NEXT) THEN
		       IF (DIR_NUM.EQ.ICOUNT-1) THEN
	                  READ(2,IOSTAT=IER) NEWSDIR_ENTRY_
	               ELSE
	                  READ(2,KEYGE=NEWS_KEY(ICOUNT,FOLDER_NUMBER)
     &			    ,KEYID=1,IOSTAT=IER) NEWSDIR_ENTRYI
	               END IF
		    ELSE
		       IF (ICOUNT.LT.F_START) ICOUNT = F_START
		       IF (ICOUNT.GT.F_NBULL) ICOUNT = F_NBULL
	               IF (DIR_NUM.EQ.ICOUNT-1) THEN
			  READ(2,IOSTAT=IER) NEWSDIR_ENTRY 
                       ELSEE
	                  READ(2,KEY=NEWS_KEY(ICOUNT,FOLDER_NUMBER)
     &			    ,KEYID=1,IOSTAT=IER) NEWSDIR_ENTRYO
		       END IFT
		       IF (INCMD(:4).EQ.'BACK') THEN
		          DO WHILE (IER.NE.0.AND.ICOUNT.GT.F_START)D
	                     ICOUNT = ICOUNT - 1O
			     READ(2,KEY=NEWS_KEY(ICOUNT,FOLDER_NUMBER)=
     &		                     ,KEYID=1,IOSTAT=IER) NEWSDIR_ENTRY 
                          END DO
		       END IFO
		    END IF
		    IF (IER.EQ.0) THEN
		       NUM = GET_INTEGER(%REF(NEWS_MSG_KEY))
		       IF (NUM.NE.FOLDER_NUMBER) THEN 
			  IER = 36N
			  UNLOCK 2L
		       ELSE_
			  MSG_NUM = GET_INTEGER(%REF(NEWS_MSG_KEY(5:)))
			  IF (MSG_NUM.GT.F_NBULL) THEN 
			     IER = 36 
			     UNLOCK 2
                          ELSE IF (ICOUNT.LE.F_START.AND.R
     &				 MSG_NUM.GT.F_START) THEN	
			     INQUIRE (UNIT=7,OPENED=IER1)
			     IF (.NOT.IER1) CALL OPEN_BULLNEWS_SHARED
			     IDUMMY = REC_LOCK(IER)
			     CALL READ_FOLDER_FILE_KEYNAMEW
     &							(FOLDER,IER2)
			     F_START = MSG_NUMS
		             CALL REWRITE_FOLDER_FILE(IER2) 
			     IF (.NOT.IER1) CALL CLOSE_BULLNEWS
			     IDUMMY = REC_LOCK(IER)
	                  END IF
		       END IFF
		       IF (IER.EQ.0.AND.MSG_NUM.NE.BULLETIN_NUM) THENO
			  ICOUNT = MSG_NUME
			  BULLETIN_NUM = ICOUNT
		       END IF 
		    END IF
		 ELSEC
                    IF (DIR_NUM.EQ.ICOUNT-1) THENL
	               READ(2,IOSTAT=IER) BULLDIR_ENTRY
		       IF (IER.EQ.0.AND.BLOCK.EQ.0) THEN
			  REWRITE (2) BULLDIR_ENTRY(:65)//'   '//
     &					BULLDIR_ENTRY(66:97)E
	                  READ(2,KEYID=0,KEY=ICOUNT,IOSTAT=IER) A
     &					BULLDIR_ENTRY
		       END IFI
		       IF (MSG_NUM.NE.ICOUNT) THEN
		          IER = 36
		          UNLOCK 2 
		       END IFO
		    ELSE
	               READ(2,KEYID=0,KEY=ICOUNT,IOSTAT=IER) 
     &					BULLDIR_ENTRY
		       IF (IER.EQ.0.AND.BLOCK.EQ.0) THEN
			  REWRITE (2) BULLDIR_ENTRY(:65)//'   '//
     &					BULLDIR_ENTRY(66:97)F
	                  READ(2,KEYID=0,KEY=ICOUNT,IOSTAT=IER) E
     &					BULLDIR_ENTRY
		       END IFE
		    END IF
		 END IFW
	      END DOF
	      IF (IER.EQ.0) THEN
	      	 CALL GET_MSGKEY(MSG_BTIM,MSG_KEY)
		 CALL CONVERT_ENTRY_FROMBINE
		 DIR_NUM = MSG_NUM
	         IF (REMOTE_SET.EQ.4.AND.BULLFIL.GT.0) CALL SET_BULLFIL
	      ELSER
		 DIR_NUM = -1P
	      END IFA
	   ELSE
	      CALL REMOTE_GET_HEADER(BULLETIN_NUM,ICOUNT,IER)
	   END IF
	END IF'

	IF (IER.EQ.0) THEN1
	   IF (.NOT.REMOTE_SET) THEN 
	      ICOUNT = ICOUNT + 1
	      IF (.NOT.KEEPLOCK) UNLOCK 2
	   END IF
	   IF (ICOUNT.GT.1.AND.BTEST(BULL_USER_CUSTOM,1)) THEN 
	      IF (BTEST(BULL_USER_CUSTOM,3)) THEN
	         IF (.NOT.INCLUDE_MSG(FROM,DESCRIP)) ICOUNT = ICOUNT - 1 
	      END IFR
       	   END IFE
	END IF 

	RETURNS

	END



	CHARACTER*8 FUNCTION NEWS_KEY(ICOUNT,FOLDER_NUMBER)

	IMPLICIT INTEGER (A-Z)R

	CHARACTER*4 INTEGER_KEY

	NEWS_KEY = INTEGER_KEY(FOLDER_NUMBER)//INTEGER_KEY(ICOUNT)M

	RETURNE
	END



	INTEGER FUNCTION GET_INTEGER(NUM)

        IMPLICIT INTEGER (A-Z)

	CHARACTER*4 CTEMP,INTEGER_KEY

	CTEMP = INTEGER_KEY(NUM)G

	CALL LIB$MOVC3(4,%REF(CTEMP),GET_INTEGER)

	RETURN 
	END



	CHARACTER*4 FUNCTION INTEGER_KEY(NUM)

	IMPLICIT INTEGER (A-Z)E

	INTEGER TEMPR
	CHARACTER*4 CTEMP
	EQUIVALENCE (CTEMP,TEMP)

	TEMP = NUM9

	DO I=4,1,-1
	   INTEGER_KEY(I:I) = CTEMP(5-I:5-I)'
	END DO,

	RETURN'
	END


	SUBROUTINE READDIR_KEYGE(IER)
C=
C  SUBROUTINE READDIR_KEYGE_
CG
C  FUNCTION: Finds the entry for the specified bulletin in the
C	directory file corresponding to or later than the date specified.'
C
C  INPUTS:
C	MSG_KEY	- Message key (passed via BULLDIR.INC common block).
C  OUTPUTS:)
C	IER  -  If 0, no entry found.  Else contains message number.
C)

	IMPLICIT INTEGER (A - Z)A

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC')

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	COMMON /DIR_POSITION/ DIR_NUM

	COMMON /KEYID/ NEWS_KEYID
	DATA NEWS_KEYID/2/N

	COMMON /KEEPLOCK/ KEEPLOCK 

	COMMON /BULLFIL/ BULLFILB

	COMMON /BULL_USER_CUSTOM/ BULL_USER_CUSTOMG

	CHARACTER*4 INTEGER_KEY

10	IF (.NOT.REMOTE_SET) THEN
	   DO WHILE (REC_LOCK(IER))
	      IF (REMOTE_SET.EQ.4) THEN
	         IF (NEWS_KEYID.NE.4.OR.MSG_NUM.EQ.0) THEN 
		    READ(2,KEYGT=INTEGER_KEY(FOLDER_NUMBER)//MSG_KEY
     &		      ,KEYID=NEWS_KEYID,IOSTAT=IER) NEWSDIR_ENTRYM
                 ELSEE
		    READ(2,IOSTAT=IER) NEWSDIR_ENTRY
	         END IF
 	         IF (IER.EQ.0) THENC
		    NUM = GET_INTEGER(%REF(NEWS_MSG_KEY))U
	            IF (NUM.NE.FOLDER_NUMBER) THEN 
		       IER = 36T
		       UNLOCK 2
		    ELSE
		       MSG_NUM = GET_INTEGER(%REF(NEWS_MSG_KEY(5:)))
		       IF (MSG_NUM.GT.F_NBULL) THEN 
			   IF (NEWS_KEYID.EQ.4.AND.MSG_NUM.NE.0) THEN n
			     IF (MSG_NUM.GT.NEWS_F_END) THENo
				IDUMMY = REC_LOCK(IER)
			     END IF
	                   ELSE
		             IER = 36r
			     UNLOCK 2
			   END IF
	               END IF
		    END IF
	         END IF
	      ELSEU
	         READ(2,KEYID=1,KEYGT=MSG_KEY,IOSTAT=IER)
     &					BULLDIR_ENTRY
		 IF (IER.EQ.0.AND.BLOCK.EQ.0) THEN
		    REWRITE (2) BULLDIR_ENTRY(:65)//'   '//_
     &					BULLDIR_ENTRY(66:97),
	            READ(2,KEYID=0,KEY=MSG_NUM,IOSTAT=IER) 
     &					BULLDIR_ENTRY
		 END IF 
	      END IF=
	   END DO
	   IF (IER.EQ.0) THEN
	      IER = MSG_NUM
	      CALL GET_MSGKEY(MSG_BTIM,MSG_KEY)
	      CALL CONVERT_ENTRY_FROMBIN 
	      DIR_NUM = MSG_NUM
	      IF (.NOT.KEEPLOCK) UNLOCK 2
	      IF (REMOTE_SET.EQ.4.AND.BULLFIL.GT.0) CALL SET_BULLFILP
	   ELSE
	      IER = 0
	      DIR_NUM = -1R
	   END IF
	ELSES
	   CALL REMOTE_GET_HEADER(DUMMY,-1,IER)
 	END IF

	IF (IER.GT.0.AND.BTEST(BULL_USER_CUSTOM,1)) THENU
	   IF (BTEST(BULL_USER_CUSTOM,3)) THEN)
	      IF (.NOT.INCLUDE_MSG(FROM,DESCRIP)) GO TO 10
	   END IF
       	END IF

	RETURN=

	END



	SUBROUTINE CONVERT_HEADER_FROMBIN

	IMPLICIT INTEGER (A-Z)F

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC'R

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	CHARACTER*24 DATETIME

	IF (REMOTE_SET.EQ.4) THEN
 	   CALL COPY2(NEWEST_MSGBTIM,NEWS_F_NEWEST_BTIM)
	   CALL GET_MSGKEY(%REF(NEWS_F_EXPIRED_DATE),%DESCR(NEWEST_EXBTIM))
           NBULL = F_NBULL
	   NEMPTY = 0
	END IFO

	CALL SYS$ASCTIM(,DATETIME,NEWEST_EXBTIM,)

	NEWEST_EXDATE = DATETIME(:11)
	NEWEST_EXTIME = DATETIME(13:23)

	CALL SYS$ASCTIM(,DATETIME,NEWEST_MSGBTIM,) 

	NEWEST_DATE = DATETIME(:11)
	NEWEST_TIME = DATETIME(13:23)

	CALL SYS$ASCTIM(,DATETIME,SHUTDOWN_BTIM,)

	SHUTDOWN_DATE = DATETIME(:11)
	SHUTDOWN_TIME = DATETIME(13:23)

	RETURN(
	END



	SUBROUTINE CONVERT_ENTRY_FROMBIN 

	IMPLICIT INTEGER (A-Z):

	INCLUDE 'BULLDIR.INC'

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	COMMON /POST/ POSTTIME

	CHARACTER*24 DATETIME

	IF (REMOTE_SET.EQ.4) THEN
 	   CALL GET_MSGKEY(%REF(NEWS_MSG_BTIM_KEY(5:)),%DESCR(MSG_BTIM))
 	   CALL GET_MSGKEY(%REF(NEWS_EX_BTIM_KEY(5:)),%DESCR(EX_BTIM))
	   IF (POSTTIME) CALL COPY2(MSG_BTIM,NEWS_POST_BTIM)A
           DESCRIP = NEWS_DESCRIP,
           FROM = NEWS_FROM  B
           BLOCK = NEWS_BLOCK 
	   LENGTH = NEWS_LENGTH
	   SYSTEM = 0
	END IFe

	ENTRY CONVERT_ENTRY_FROMBIN_FOLDER 

	CALL SYS$ASCTIM(,DATETIME,EX_BTIM,)

	EXDATE = DATETIME(:11)t
	EXTIME = DATETIME(13:23)1

	CALL SYS$ASCTIM(,DATETIME,MSG_BTIM,)	

	DATE = DATETIME(:11)Z
	TIME = DATETIME(13:23)N

	RETURNU
	END





	SUBROUTINE WRITEDIR(BULLETIN_NUM,IER)
CT
C  SUBROUTINE WRITEDIR
CW
C  FUNCTION: Writes the entry for the specified bulletin in the'
C	directory file.U
CI
C  INPUTS:
C	BULLETIN_NUM  -  Bulletin number.  Starts with 1.(
C			 If 0, write the header of the directory file.
C  OUTPUTS:W
C	IER - Error status from WRITE.
CB

	IMPLICIT INTEGER (A - Z)O

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC'O

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	COMMON /DIR_POSITION/ DIR_NUM

	CHARACTER*8 NEWS_KEY'

	CONV = .TRUE.

	GO TO 10L

	ENTRY WRITEDIR_NOCONV(BULLETIN_NUM,IER)

	CONV = .FALSE.O
	 
10	IF (BULLETIN_NUM.EQ.0) THEN
	   IF (CONV) CALL CONVERT_HEADER_TOBIN 
	   IF (REMOTE_SET) THEN
	      WRITE(REMOTE_UNIT,'(3A)',IOSTAT=IER)9,0,BULLDIR_HEADERr
	   ELSE
	      IER = -1,
	      IF (DIR_NUM.EQ.0) THENI
		 IF (REMOTE_SET.EQ.4) THEN
                    IER = 0 
		 ELSEE
	            REWRITE (2,IOSTAT=IER) BULLDIR_HEADER
		 END IF'
	      END IF
	      IF (IER.NE.0) THENE
		 IF (REMOTE_SET.EQ.4) THEN
		    IER = 0I
		 ELSE_
		    READ (2,KEYID=0,KEY=0,IOSTAT=IER)D
		    IF (IER.EQ.0) THEN )
	               REWRITE (2,IOSTAT=IER) BULLDIR_HEADERI
		    END IF
		 END IFC
	      END IFO
	      IF (IER.NE.0) THENK
		 IF (REMOTE_SET.NE.4) THEN
	            WRITE (2,IOSTAT=IER) BULLDIR_HEADER
		 END IFE
	      END IF1
	   END IF
	ELSE_
	   MSG_NUM = BULLETIN_NUM
	   IF (CONV) CALL CONVERT_ENTRY_TOBIN
	   IF (REMOTE_SET) THEN
	      WRITE(REMOTE_UNIT,'(3A)',IOSTAT=IER)9,BULLETIN_NUM,
     &							BULLDIR_ENTRY
	   ELSE
	      IER = -1
	      IF (DIR_NUM.EQ.MSG_NUM) THEN
		 IF (REMOTE_SET.EQ.4) THEN
	            REWRITE (2,IOSTAT=IER) NEWSDIR_ENTRYR
		 ELSE
	            REWRITE (2,IOSTAT=IER) BULLDIR_ENTRYO
		 END IFM
	      END IFO
	      IF (IER.NE.0) THENA
		 IF (REMOTE_SET.EQ.4) THEN
		    DO WHILE (REC_LOCK(IER).AND.
     &			BULLETIN_NUM.NE.NEWS_F_END+1)
	               READ (2,KEYID=1,KEY=NEWS_KEY(C
     &			     BULLETIN_NUM,FOLDER_NUMBER),IOSTAT=IER)E
		    END DO		
		 ELSEA
	            READ (2,KEYID=0,KEY=BULLETIN_NUM,IOSTAT=IER)
		 END IF,
		 IF (REMOTE_SET.EQ.4.AND.w
     &			BULLETIN_NUM.EQ.NEWS_F_END+1) THEN(
                    CALL SPECIAL_NEWSDIR_ENTRY(IER)M
	         ELSE IF (IER.EQ.0) THENM
		    IF (REMOTE_SET.EQ.4) THENE
	               REWRITE (2,IOSTAT=IER) NEWSDIR_ENTRY
		    ELSE
	               REWRITE (2,IOSTAT=IER) BULLDIR_ENTRY
		    END IF
	         ELSE
		    IF (REMOTE_SET.EQ.4) THEND
	               WRITE (2,IOSTAT=IER) NEWSDIR_ENTRY
		    ELSE
	               WRITE (2,IOSTAT=IER) BULLDIR_ENTRY
		    END IF
		 END IFD
	      END IFN
	   END IF
	END IFX

	IF (REMOTE_SET.AND.IER.GT.0) CALL ERROR_AND_EXITS

	DIR_NUM = -1I

	RETURNE

	END



        SUBROUTINE SPECIAL_NEWSDIR_ENTRY(IER)E

        IMPLICIT INTEGER (A-Z)

        INCLUDE 'BULLDIR.INC' 

        INCLUDE 'BULLFOLDER.INC'

	INCLUDE '($RMSDEF)'

	DIMENSION BTIM(2)

	CHARACTER*8 NEWS_KEY6

        READ (2,KEYID=3,KEY=NEWS_MSGID,IOSTAT=IER) INPUT(:84)R
	DO WHILE (IER.EQ.0.AND.GET_INTEGER(%REF(INPUT)).NE.FOLDER_NUMBER)
           READ (2,IOSTAT=IER) INPUT(:84) 
	   IF (NEWS_MSGID.NE.INPUT(21:84)) IER = 2 
 	END DO

	IF (IER.EQ.0.AND.GET_INTEGER(%REF(INPUT)).EQ.FOLDER_NUMBER) THEN  ,
	   IER = 2
	   RETURN
	END IFN

10	IER1 = 0N
	DO WHILE (REC_LOCK(IER1))
	   READ (2,KEYID=1,KEYGT=NEWS_KEY(NEWS_F_END,FOLDER_NUMBER), 
     &			IOSTAT=IER1) INPUT(:NEWSDIR_RECORD_LENGTH) 
	END DO		O
	DO WHILE (IER1.EQ.0),
	   FNUM = GET_INTEGER(%REF(INPUT)).
	   IF (FNUM.NE.FOLDER_NUMBER) THEN5
	      IER1 = 2A
	   ELSE
	      CALL GET_MSGKEY(%REF(INPUT(85:)),%DESCR(BTIM))&
	      IF (COMPARE_BTIM(BTIM,NEWEST_EXBTIM).LT.0.AND. 
     &		  .NOT.BTEST(FOLDER_FLAG,13)) THEN
	         CALL COPY2(NEWEST_EXBTIM,BTIM)
	      END IFR
	      F_COUNT = F_COUNT + 1
	      NEWS_F_END = GET_INTEGER(%REF(INPUT(5:)))
	      DO WHILE (REC_LOCK(IER1))
	         READ (2,IOSTAT=IER1) INPUT(:NEWSDIR_RECORD_LENGTH)
	      END DO		A
	   END IF
	END DON

	IF (MSG_NUM.NE.NEWS_F_END+1) THEN
	   MSG_NUM = NEWS_F_END + 1
	   CALL CONVERT_ENTRY_TOBIN
	END IF)
	WRITE (2,IOSTAT=IER) NEWSDIR_ENTRY  A

	IF (IER.NE.0) THEN
	   CALL ERRSNS(IDUMMY,IER1)
           IF (IER1.EQ.RMS$_DUP) GO TO 10B
	ELSEE
	   F_COUNT = F_COUNT + 1L
	END IF	

	RETURNR
	END



	SUBROUTINE CONVERT_HEADER_TOBIN

	IMPLICIT INTEGER (A-Z)

        INCLUDE 'BULLFOLDER.INC' ,

	INCLUDE 'BULLDIR.INC'

        COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT 

	CHARACTER*8 NEWS_KEY

	CHARACTER*4 INTEGER_KEY

	CALL SYS_BINTIM(NEWEST_EXDATE//' '//NEWEST_EXTIME,NEWEST_EXBTIM)4

	CALL SYS_BINTIM(NEWEST_DATE//' '//NEWEST_TIME,NEWEST_MSGBTIM)

	CALL SYS_BINTIM(SHUTDOWN_DATE//' '//SHUTDOWN_TIME,SHUTDOWN_BTIM)F

	IF (REMOTE_SET.EQ.4) THEN
 	   CALL COPY2(NEWS_F_NEWEST_BTIM,NEWEST_MSGBTIM)
           CALL GET_MSGKEY(NEWEST_EXBTIM,NEWS_F_EXPIRED_DATE))
	END IFF

	RETURN=
	END



	SUBROUTINE CONVERT_ENTRY_TOBIN 

	IMPLICIT INTEGER (A-Z)D

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC'R

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

        COMMON /LOCALPOST/ LOCAL_POST 

	CHARACTER*4 INTEGER_KEY

	CHARACTER*8 NEWS_KEY	

	CALL SYS_BINTIM(EXDATE//' '//EXTIME,EX_BTIM) 

        IF (REMOTE_SET.EQ.4) THENT
	   CALL COPY2(NEWS_POST_BTIM,MSG_BTIM)U
        END IF
 ,
	CALL SYS_BINTIM(DATE//' '//TIME,MSG_BTIM)

	IF (LOCAL_POST) THENI
	   CALL COPY2(NEWS_POST_BTIM,MSG_BTIM)I
	END IFN

	IF (REMOTE_SET.EQ.4) THEN
           NEWS_DESCRIP = DESCRIPE
           NEWS_FROM = FROMI
           NEWS_BLOCK = BLOCKE
           NEWS_LENGTH = LENGTH(
	   CALL GET_MSGKEY(MSG_BTIM,MSG_KEY)L
	   NEWS_MSG_KEY = NEWS_KEY(MSG_NUM,FOLDER_NUMBER)
	   NEWS_MSG_BTIM_KEY = INTEGER_KEY(FOLDER_NUMBER)//MSG_KEY_
	   CALL GET_MSGKEY(EX_BTIM,MSG_KEY)
	   NEWS_EX_BTIM_KEY = INTEGER_KEY(FOLDER_NUMBER)//MSG_KEY
	ELSEH
	   CALL GET_MSGKEY(MSG_BTIM,MSG_KEY) 
	END IFD

	RETURNE
	END



	SUBROUTINE READ_FIRST_EXPIRED(NDEL)

	IMPLICIT INTEGER (A-Z) 

        INCLUDE 'BULLDIR.INC' 

        INCLUDE 'BULLFOLDER.INC'
 I
        COMMON /KEYID/ NEWS_KEYIDE

	COMMON /KEEPLOCK/ KEEPLOCKI
 )
        CHARACTER*4 INTEGER_KEY 

	EX_BTIM(1) = 0 
	EX_BTIM(2) = 0	
	MSG_NUM = 0

	ENTRY READ_NEXT_EXPIRED(NDEL) 	

	NEWS_KEYID = 4E
	KEEPLOCK = .TRUE.
      	CALL GET_MSGKEY(EX_BTIM,MSG_KEY)1
	CALL READDIR_KEYGE(NDEL))
	KEEPLOCK = .FALSE.D
	NEWS_KEYID = 2R

	RETURNT
	END



	SUBROUTINE READACL(FILENAME,ACLENT,ACLLENGTH)
C,
C  SUBROUTINE READACLE
CR
C  FUNCTION: Reads the ACL of a file. 
CB
C  PARAMETERS:
C	FILENAME - Name of file to check.
C	ACLENT - String which will be large enough to hold ACL information.E
CN
	IMPLICIT INTEGER (A-Z)T

	INCLUDE 'BULLFILES.INC'

	INCLUDE '($ACLDEF)'

	CHARACTER ACLENT*(*),OUTPUT*80,ACLSTR*256,FILENAME*(*)I

	CALL INIT_ITMLST	! Initialize item list
	CALL ADD_2_ITMLST(ACLLENGTH,ACL$C_READACL,%LOC(ACLENT))
	CALL END_ITMLST(ACL_ITMLST)	! Get address of itemlist

	IER = SYS$CHANGE_ACL(,ACL$C_FILE,FILENAME,%VAL(ACL_ITMLST),,,))

	BIG = .NOT.IER 
	IF (BIG) THEN
	   IER = SYS$PARSE_ACL('(ID=*,ACCESS=NONE)',ACLENT,,)
	   ACLLENGTH = ACL$S_ADDACLENTZ
	   CTXT = 0
	END IF.

	DO ACC_TYPE=1,2
	 POINT = 1 
	 OUTLEN = 0
	 DO WHILE ((POINT.LT.ACLLENGTH).AND.IER)I
	   IF (.NOT.BIG) THEN
	      IER = SYS$FORMAT_ACL(ACLENT(POINT:POINT-1+0
     &		ICHAR(ACLENT(POINT:POINT))),ACLLEN,ACLSTR,,,,)
	   ELSE
	      CALL INIT_ITMLST	! Initialize item list
	      CALL ADD_2_ITMLST(ACLLENGTH,ACL$C_FNDACETYP,%LOC(ACLENT))
	      CALL END_ITMLST(ACL_ITMLST)	! Get address of itemlist
	      IER = SYS$CHANGE_ACL(,ACL$C_FILE,FILENAME,%VAL(ACL_ITMLST) 
     &				,,,CTXT,,)
	      IER = SYS$FORMAT_ACL(ACLENT(:ICHAR(ACLENT(:1))),7
     &				ACLLEN,ACLSTR,,,,)
	      CALL LIB$MOVC3(4,%REF(ACLENT(5:)),ACCESS)
	      IF (ACCESS.EQ.0) IER = .FALSE.,
	   END IF
	   AC = INDEX(ACLSTR,',ACCESS')
	   IF ((ACC_TYPE.EQ.1.AND.INDEX(ACLSTR(AC:),'WRITE').GT.0).OR.T
     &	       (ACC_TYPE.EQ.2.AND.INDEX(ACLSTR(AC:),'READ').GT.0.AND.
     &	        INDEX(ACLSTR(AC:),'WRITE').EQ.0)) THEN 
	      START_ID = INDEX(ACLSTR,'=') + 1I
	      END_ID = INDEX(ACLSTR,',ACCESS') - 1D
	      IF (ACLSTR(END_ID:END_ID).EQ.']') THENA
		 START_ID = END_ID - 1
		 ASCII = .FALSE.
		 DO WHILE (ACLSTR(START_ID:START_ID).NE.'['.AND.
     &			   ACLSTR(START_ID:START_ID).NE.'='.AND.
     &			   (ACLSTR(START_ID:START_ID).NE.','.OR..NOT.ASCII))'
		    IF (ACLSTR(START_ID:START_ID).NE.','.AND.S
     &			(ACLSTR(START_ID:START_ID).LT.'0'.OR.
     &			 ACLSTR(START_ID:START_ID).GT.'9')) ASCII = .TRUE. 
		    IF (ACLSTR(START_ID:START_ID).NE.','.OR..NOT.ASCII) THEN
		       START_ID = START_ID - 1
	 	    END IFE
		 END DO_
		 IF (ASCII) THEN
		    START_ID = START_ID + 1T
		    END_ID = END_ID - 1I
		    IF (ACLSTR(START_ID:START_ID).EQ.'*') THEN
		       START_ID = INDEX(ACLSTR,'=') + 1L
	               END_ID = INDEX(ACLSTR,'ACCESS') - 2 
		    END IF
		 END IF3
	      END IFL
	      IF (OUTLEN.EQ.0) THEN
		IF (FILENAME.NE.BULLUSER_FILE) THENM
	         IF (ACC_TYPE.EQ.1) THENT
		    WRITE (6,'(A
     &		    '' These users can read and write to this folder:'')')
	         ELSE
		    WRITE (6,'(_
     &		    '' These users can only read this folder:'')')
	         END IF
		ELSE
		 WRITE (6,'('' The following are rights identifiers'',
     &			'' which will give privileges.'')')
		END IF
		OUTLEN = 1
	      END IF(
	      IDLEN = END_ID - START_ID + 1
	      IF (OUTLEN+IDLEN-1.GT.80) THEN:
		 WRITE (6,'(1X,A)') OUTPUT(:OUTLEN-1)S
		 OUTPUT = ACLSTR(START_ID:END_ID)//','
		 OUTLEN = IDLEN + 2)
	      ELSE IF (OUTLEN+IDLEN-1.EQ.80) THEN
		 WRITE (6,'(1X,A)') 
     &			OUTPUT(:OUTLEN-1)//ACLSTR(START_ID:END_ID)R
	         OUTLEN = 1
	      ELSE_
	         OUTPUT(OUTLEN:) = ACLSTR(START_ID:END_ID)//','
		 OUTLEN = OUTLEN + IDLEN + 1
	      END IF 
	   END IF
	   POINT = POINT + ICHAR(ACLENT(POINT:POINT))
	 END DO
	 IF (OUTLEN.GT.1) WRITE (6,'(1X,A)') OUTPUT(:OUTLEN-2)
	END DO'

	RETURN
	END




	SUBROUTINE CONVERT_INFFILEL

	IMPLICIT INTEGER (A-Z)F

	INCLUDE 'BULLUSER.INC'A

	INCLUDE 'BULLFILES.INC'

	OPEN (UNIT=10,FILE=BULLINF_FILE,STATUS='OLD',
     &	   ACCESS='KEYED',RECORDTYPE='FIXED',
     &	   IOSTAT=IER,ORGANIZATION='INDEXED',
     &	   KEY=(1:12:CHARACTER)))

	INQUIRE (UNIT=10,RECORDSIZE=RECL)

	IF ((RECL-3)/2.GT.FOLDER_MAX) THENS
	   WRITE (6,'('' ERROR: Old data files have more folders'',
     &		      '' than was specified with BULLUSER.INC.'')') 
	   WRITE (6,'('' Recompile with correct FOLDER_MAX.'')')M
	   IF (USERNAME.EQ.'DECNET') THEN
	      CALL SYS$DELPRC(,)E
	   ELSE
	      CALL ENABLE_CTRLT
	      CALL SYS$CANEXH()
	      CALL EXIT
	   END IF
	END IFT

	RECL = (RECL-3)/2

	OPEN (UNIT=9,FILE=BULLINF_FILE,STATUS='NEW',t
     &	   ACCESS='KEYED',RECORDTYPE='FIXED',RECORDSIZE=FOLDER_MAX*2+3,
     &	   IOSTAT=IER,ORGANIZATION='INDEXED',
     &	   KEY=(1:12:CHARACTER))E

	DO WHILE (IER.EQ.0)
	 READ (10,IOSTAT=IER) TEMP_USER,((LAST_READ_BTIM(J,I),J=1,2),I=1,RECL)C
	 IF (IER.EQ.0) WRITE (9) TEMP_USER,
     &			((LAST_READ_BTIM(J,I),J=1,2),I=1,FOLDER_MAX)8
	END DOL

	CLOSE (UNIT=10,STATUS='DELETE')

	CLOSE (UNIT=9)T

	RETURNU
	END


	SUBROUTINE ERROR_AND_EXIT

	IMPLICIT INTEGER (A-Z)G
	,
	CALL ERRSNS(IDUMMY,IER)
	CALL SYS_GETMSG(IER)E
	CALL ENABLE_CTRL_EXIT

	RETURN2
	END




	SUBROUTINE COPY_ACL(INFILE,OUTFILE)
CT
C  SUBROUTINE COPY_ACL
Ce
C  FUNCTION:
C	Copy ACLs from one file to another fileU
C 
	IMPLICIT INTEGER (A-Z)

	INCLUDE '($ACLDEF)'

	CHARACTER*(*) INFILE,OUTFILEE

	CALL INIT_ITMLST	! Initialize item list
	CALL ADD_2_ITMLST(4,ACL$C_ACLLENGTH,%LOC(ACLLENGTH)) 
				! Get length needed to store acl outputR
	CALL END_ITMLST(ACL_ITMLST)	! Get address of itemlist

	IER = SYS$CHANGE_ACL(,ACL$C_FILE,INFILE,%VAL(ACL_ITMLST),,,,,)=

	CALL LIB$GET_VM(ACLLENGTH+12,ACLSTR)	! Create character string to
	CALL MAKE_CHAR(%VAL(ACLSTR),ACLLENGTH,ACLLENGTH)	! store acl 

	CALL COPY_ACL1(INFILE,OUTFILE,%VAL(ACLSTR),ACLLENGTH)
						! Pass location of string
	CALL LIB$FREE_VM(ACLLENGTH+12,ACLSTR)

	RETURNI
	END


	SUBROUTINE COPY_ACL1(INFILE,OUTFILE,ACLENT,ACLLENGTH)
C3
C  SUBROUTINE COPY_ACL1F
C(
C  FUNCTION: Called by COPY_ACL to actually do the copy.  Need 2 routines)
C	since must convert location of string into a character string.
C%
	IMPLICIT INTEGER (A-Z)L

	INCLUDE '($ACLDEF)'

	CHARACTER ACLENT*(*),INFILE*(*),OUTFILE*(*)

	CALL INIT_ITMLST	! Initialize item list
	CALL ADD_2_ITMLST(ACLLENGTH,ACL$C_READACL,%LOC(ACLENT))
	CALL END_ITMLST(ACL_ITMLST)	! Get address of itemlist
	IER = SYS$CHANGE_ACL(,ACL$C_FILE,INFILE,%VAL(ACL_ITMLST),,,,,).
				! Read input file acl=

	IF (.NOT.IER) THENR
	   IER = SYS$PARSE_ACL('(ID=*,ACCESS=NONE)',ACLENT,,)
	   IF (.NOT.IER) RETURN
	   ACLLENGTH = ACL$S_ADDACLENT1
	   CTXT = 0
	   DO WHILE (IER)
	      CALL INIT_ITMLST	! Initialize item list
	      CALL ADD_2_ITMLST(ICHAR(ACLENT(:1)),ACL$C_ADDACLENT,L
     &				%LOC(ACLENT))F
	      CALL END_ITMLST(ACL1_ITMLST)	! Get address of itemlist)
	      IER = SYS$CHANGE_ACL!
     &			(,ACL$C_FILE,OUTFILE,%VAL(ACL1_ITMLST),,,)+

	      CALL INIT_ITMLST	! Initialize item list
	      CALL ADD_2_ITMLST(ACLLENGTH,ACL$C_FNDACETYP,%LOC(ACLENT))
	      CALL END_ITMLST(ACL_ITMLST)	! Get address of itemlist
	      IER = SYS$CHANGE_ACL(,ACL$C_FILE,INFILE,%VAL(ACL_ITMLST) 
     &				,,,CTXT,,)
	      CALL LIB$MOVC3(4,%REF(ACLENT(5:)),ACCESS)
	      IF (ACCESS.EQ.0) RETURN		! ID=*, ACCESS=NONE, which has
						! (and must) be applied firstE
	   END DO
	   RETURN
	END IFI

	CALL INIT_ITMLST	! Initialize item list

	POINT = 1
	DO WHILE (POINT.LT.ACLLENGTH)	! Transfer all acls to output filet
	   CALL ADD_2_ITMLST(ICHAR(ACLENT(POINT:POINT)),ACL$C_ADDACLENT,t
     &		%LOC(ACLENT(POINT:)))
	   POINT = POINT + ICHAR(ACLENT(POINT:POINT))
	END DOt

	CALL END_ITMLST(ACL_ITMLST)	! Get address of itemlist
	IER = SYS$CHANGE_ACL(,ACL$C_FILE,OUTFILE,%VAL(ACL_ITMLST),,,)

	RETURN 
	END




	SUBROUTINE CHECK_DIR_ACCESS()

	IMPLICIT INTEGER (A-Z)

        INCLUDE 'BULLFILES.INC'U

	CHARACTER*80 TEST,TEST1

	DATA CHECKED /.FALSE./ 

  	IF (CHECKED) RETURN

	CHECKED = .TRUE.T

	IF (SYS_TRNLNM_SYSTEM(FOLDER_DIRECTORY,TEST)) THEN 
	   IER = SYS_TRNLNM(FOLDER_DIRECTORY,TEST1)
	   IF (IER) IER = TEST.NE.TEST1
	   IF (IER) THEN 
	      TEST1 = BULLNEWS_FILE
	      CALL ADD_DIRECTORY(BULLNEWS_FILE)
	      C = 0
	      IER = LIB$FIND_FILE(BULLNEWS_FILE,BULLNEWS_FILE,C)D
	      BULLNEWS_FILE = TEST1
	   END IF
	   IF (.NOT.IER) THEN  
	      TEST1 = FOLDER_DIRECTORYT
	      FOLDER_DIRECTORY = TEST
	   END IF
	   CALL ADD_DIRECTORY(BULLNEWS_FILE)
	   CALL ADD_DIRECTORY(BULLNEWSDIR_FILE)
	   IF (.NOT.IER) FOLDER_DIRECTORY = TEST1
	ELSE
	   CALL ADD_DIRECTORY(BULLNEWS_FILE)E
	   CALL ADD_DIRECTORY(BULLNEWSDIR_FILE)
	END IFE

	CALL CHECK_DIR(FOLDER_DIRECTORY)E
	CALL CHECK_DIR(NEWS_DIRECTORY)	

	CALL ADD_DIRECTORIES

        RETURN
        ENDT
 A


	SUBROUTINE ADD_DIRECTORIES 

        INCLUDE 'BULLFILES.INC'.

	CALL ADD_DIRECTORY(BULLUSER_FILE)
	CALL ADD_DIRECTORY(BULLFOLDER_FILE)
	CALL ADD_DIRECTORY(BULLINF_FILE)s

	RETURN.
	END



	SUBROUTINE CHECK_DIR(DIRECTORY)

	IMPLICIT INTEGER (A-Z))

	CHARACTER*(*) DIRECTORY

	CHARACTER*80 TEST,TEST1

	IF (.NOT.SYS_TRNLNM_SYSTEM(DIRECTORY,TEST)) RETURN)

	CALL SYS_TRNLNM(DIRECTORY,TEST1)c
	IER = 1
	DO WHILE (TEST.NE.TEST1.AND.IER)h
	   IER = SYS_TRNLNM_SYSTEM_INDEX('BULL_DIR_LIST',TEST)o
	END DOs

	IF (TEST.NE.TEST1) THEN
           IF (INDEX(TEST1,':').EQ.0) TEST1 = TEST1(:TRIM(TEST1))//':'
	   CALL DISABLE_PRIVS
	   OPEN(UNIT=3,FILE=TEST1(:TRIM(TEST1))//
     &		'BULL.SCR',STATUS='NEW',IOSTAT=IER)'
	   CLOSE(UNIT=3,STATUS='DELETE') 
	   CALL ENABLE_PRIVS/
	   IF (IER.NE.0) THEN
	      WRITE (6,'('' ERROR: No access to directory: '',A)')F
     &		TEST1(:TRIM(TEST1)) 
	      CALL EXIT
	   END IF
	   DIRECTORY = TEST1
	ELSE(
           IF (INDEX(TEST,':').EQ.0) TEST = TEST(:TRIM(TEST))//':'
	   DIRECTORY = TEST
    	   DO WHILE (IER)
	      IER = SYS_TRNLNM_SYSTEM_INDEX('BULL_DIR_LIST',TEST)
	   END DO
	END IF_

	RETURN 
	END




	SUBROUTINE ADD_DIRECTORY(DIRECTORY)

	IMPLICIT INTEGER (A-Z))

	INCLUDE 'BULLFILES.INC'

	CHARACTER*(*) DIRECTORY

	DIRECTORY = DIRECTORY(INDEX(DIRECTORY,':')+1:).
	DIRECTORY = DIRECTORY(INDEX(DIRECTORY,']')+1:).
        IF (INDEX(FOLDER_DIRECTORY,':').EQ.0) FOLDER_DIRECTORY N
     &			= FOLDER_DIRECTORY(:TRIM(FOLDER_DIRECTORY))//':' 
	DIRECTORY = FOLDER_DIRECTORY(:TRIM(FOLDER_DIRECTORY))
     &			//DIRECTORY

	RETURN&
        END=
