C
C  BULLETIN6.FOR, Version 11/27/92
C  Purpose: Contains subroutines for the BULLETIN utility program.
C  Environment: VAX/VMS
C  Programmer: Mark R. London
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 folderr
	      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)e
	      CALL CONVERT_BULLFOLDER(BULLFOLDER_FILE)R
	      NTRIES = 0B
	    END IFI
	    NTRIES = NTRIES + 1
	    IF (NTRIES.GT.30) CALL TIMER_ERR(LUN)
	   END DO
	   IF (IER.EQ.0) NEWS_OPEN = .FALSE.L
	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',S
     &	        RECORDSIZE=NEWS_FOLDER_RECORD,E
     &	        FORM='FORMATTED',ORGANIZATION='INDEXED',IOSTAT=IER2,T
     &	        KEY=(1:44:CHARACTER,45:48:INTEGER,49:56:CHARACTER,O
     &          57:64:CHARACTER:DESCENDING))
	      CLOSE (UNIT=7)
	      IDUMMY = FILE_LOCK(IER,IER1)	! Avoid breaking out of DO loopL
	    ELSE IF (IER.EQ.FOR$IOS_INCRECLEN) THEN
	      IDUMMY = FILE_LOCK(IER,IER1)F
	      CALL CONVERT_BULLNEWS(BULLNEWS_FILE)C
	      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 IFC

	IF (LUN.EQ.9) THENM
	   DO WHILE (FILE_LOCK(IER,IER1))
	    OPEN (UNIT=9,FILE=BULLINF_FILE,STATUS='UNKNOWN',M
     &	     ACCESS='KEYED',RECORDTYPE='FIXED',RECORDSIZE=FOLDER_MAX*2+3,
     &	     IOSTAT=IER,ORGANIZATION='INDEXED',
     &	     KEY=(1:12:CHARACTER))L
	     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,'(E
     &	    '' Cannot open file in OPEN_FILE, unit = '',I)') LUN 
	   IF (IER1.EQ.0) CALL ERRSNS(IDUMMY,IER1)T
	   IF (IER1.EQ.0) THENe
	      WRITE (6,'('' IOSTAT error = '',I)') IERE
	   ELSE
	      CALL SYS_GETMSG(IER1)
	   END IF
	   CALL ENABLE_CTRL_EXIT	! Enable CTRL-Y & -C & EXITD
	END IFN

	LUN = 0

	CALL RESET_PROTECTION

	RETURNO
	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/T

	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 IF3

	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'/E
	CHARACTER*80 BULLETIN_FILE /'BULL_DIR:BULLETIN.DAT'/ 

	CHARACTER*44 SAVE_FOLDERL
	DATA SAVE_BLOCK/-1/

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

	DATA LUN /0/K

	ENTRY OPEN_BULLNEWS_SHARED,
	LUN = LUN + 5			! Unit = 14

	ENTRY OPEN_BULLINF_SHARED
	LUN = LUN + 1			! Unit = 9E

	ENTRY OPEN_SYSUAF_SHAREDI
	LUN = LUN + 1			! Unit = 8 

	ENTRY OPEN_BULLFOLDER_SHARED 
	LUN = LUN + 3			! Unit = 7	

	ENTRY OPEN_BULLUSER_SHARED
	LUN = LUN + 2			! Unit = 4L

	ENTRY OPEN_BULLDIR_SHARED
	LUN = LUN + 1			! Unit = 2Q

	ENTRY OPEN_BULLFIL_SHARED
	LUN = LUN + 1			! Unit = 1R

	IER = 0

	NTRIES = 0D

	CALL DISABLE_CTRL

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

	    OPEN (UNIT=2,FILE=BULLNEWSDIR_FILE,
     &	      STATUS='OLD',FORM='UNFORMATTED',N
     &	      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.0E
     &		.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)O
	       IF (ASK_SIZE.NE.DIR_RECORD_LENGTH/4) THEN 
	          CLOSE (UNIT=2)S
	          IDUMMY = FILE_LOCK(IER,IER1)	! Avoid breaking out of DO loopI
	          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 IFE
	    NTRIES = NTRIES + 1
	    IF (NTRIES.GT.30) CALL ENABLE_CTRL_EXIT
	   END DO
	   DIR_NUM = -1
	END IFO

	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 = BLOCKO
	      SAVE_FOLDER = FOLDERF
	      CALL GET_REMOTE_MESSAGE(IER)D
	      IER = 0
	   END IF
	ELSE IF (LUN.EQ.1.AND..NOT.REMOTE_SET) THEN
	   SAVE_BLOCK = -1E
	   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',R
     &	      ACCESS='DIRECT',RECORDTYPE='FIXED',RECORDSIZE=32,
     &	      FORM='UNFORMATTED',IOSTAT=IER,SHARED,READONLY)I
	    IF (REMOTE_SET.EQ.4) THEN
	      IF (IER.EQ.0) THENR
	         DO WHILE (REC_LOCK(IER2))N
                    READ (1'1,IOSTAT=IER2) NBLOCKE
	         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_BULLFILEE
	       NTRIES = 0
	    END IFY
	    NTRIES = NTRIES + 1
	    IF (NTRIES.GT.30) CALL ENABLE_CTRL_EXIT
	   END DO
	END IF 

	IF (LUN.EQ.4) THENB
	   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) THENA
	       IDUMMY = FILE_LOCK(IER,IER1)
	       CALL CONVERT_USERFILE5
	       NTRIES = 0
	    END IF	
	    NTRIES = NTRIES + 1
	    IF (NTRIES.GT.30) CALL ENABLE_CTRL_EXIT
	   END DO
	END IF)

	IF (LUN.EQ.7) THENO
	   DO WHILE (FILE_LOCK(IER,IER1))
	    OPEN (UNIT=7,FILE=BULLFOLDER_FILE,STATUS='OLD',
     &	    RECORDSIZE=FOLDER_RECORD/4,
     &	    ACCESS='KEYED',RECORDTYPE='FIXED',W
     &	    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 IFI
	    NTRIES = NTRIES + 1
	    IF (NTRIES.GT.30) CALL ENABLE_CTRL_EXIT
	   END DO
	   IF (IER.EQ.0) NEWS_OPEN = .FALSE.E
	END IFS

	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,I
     &	    IOSTAT=IER,ORGANIZATION='INDEXED',SHARED)

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

	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)E
	   END DO
	END IFS

	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 + 1D
	     IF (NTRIES.GT.30) CALL ENABLE_CTRL_EXITF
	   END DO
	END IFE

	IF (IER.EQ.FOR$IOS_FILNOTFOU.AND.LUN.NE.8) THEN
	   CALL OPEN_FILE(LUN)o
	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)') IERE
	   ELSE
	      CALL SYS_GETMSG(IER1)
	   END IF
	   CALL ENABLE_CTRL_EXIT_
	END IFR

	LUN = 0

	RETURNL
	END


	SUBROUTINE RESET_PROTECTION

	IMPLICIT INTEGER (A-Z)0

	DATA PROT_LEVEL /0/

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

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

	RETURNs

	ENTRY SET_PROTECTIONL

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

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

	RETURNe
	END




	SUBROUTINE FOLDER_TO_NEWS

	IMPLICIT INTEGER (A-Z)'

	INCLUDE 'BULLFOLDER.INC' 

	NEWS_FOLDER = FOLDER:
	NEWS_FOLDER_NUMBER = FOLDER_NUMBER6
	NEWS_FOLDER_DESCRIP = FOLDER_DESCRIP(
     &			       MIN(45,INDEX(FOLDER_DESCRIP,' ')):)e
	NEWS_F_NBULL = F_NBULLB
	NEWS_F_COUNT = F_COUNT
	NEWS_F_START = F_START
	NEWS_F_LAST = F_LASTE
	NEWS_F_NEWEST_BTIM(1) = F_NEWEST_BTIM(1)E
	NEWS_F_NEWEST_BTIM(2) = F_NEWEST_BTIM(2)C
	NEWS_F_FLAG = FOLDER_FLAG
	NEWS_F_EXPIRE = FOLDER_BBEXPIRE
 	NEWS_F_EXPIRE_LIMIT = F_EXPIRE_LIMIT

	RETURNC

	ENTRY FOLDER1_TO_NEWS

	NEWS_FOLDER1 = FOLDER1O
	NEWS_FOLDER1_NUMBER = FOLDER1_NUMBERI
	NEWS_FOLDER1_DESCRIP = FOLDER1_DESCRIP(
     &			       MIN(45,INDEX(FOLDER1_DESCRIP,' ')):)
	NEWS_F1_NBULL = F1_NBULLT
	NEWS_F1_COUNT = F1_COUNTI
	NEWS_F1_START = F1_STARTR
	NEWS_F1_LAST = F1_LASTD
	NEWS_F1_NEWEST_BTIM(1) = F1_NEWEST_BTIM(1)E
	NEWS_F1_NEWEST_BTIM(2) = F1_NEWEST_BTIM(2)E
	NEWS_F1_FLAG = FOLDER1_FLAG
	NEWS_F1_EXPIRE = FOLDER1_BBEXPIRE
	NEWS_F1_EXPIRE_LIMIT = F1_EXPIRE_LIMITD

	RETURNG

	ENTRY NEWS_TO_FOLDER1

	FOLDER = NEWS_FOLDER6
	FOLDER_NUMBER = NEWS_FOLDER_NUMBERU
	FOLDER_DESCRIP = NEWS_FOLDER(:TRIM(NEWS_FOLDER))T
     &			 //NEWS_FOLDER_DESCRIPN
	FOLDER_BBOARD = '::'E
	F_NBULL = NEWS_F_NBULL
	F_COUNT = NEWS_F_COUNT 
	F_START = NEWS_F_STARTD
	F_LAST = NEWS_F_LAST+
	F_NEWEST_BTIM(1) = NEWS_F_NEWEST_BTIM(1)A
	F_NEWEST_BTIM(2) = NEWS_F_NEWEST_BTIM(2)Y
	FOLDER_FLAG = NEWS_F_FLAG
	IF (BTEST(FOLDER_FLAG,8)) FOLDER_BBOARD = 'NONE'D
	FOLDER_BBEXPIRE = NEWS_F_EXPIRE
	F_EXPIRE_LIMIT = NEWS_F_EXPIRE_LIMITL

	RETURNI

	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_COUNT4
	F1_NBULL = NEWS_F1_NBULLO
	F1_START = NEWS_F1_STARTE
	F1_LAST = NEWS_F1_LAST2
	F1_NEWEST_BTIM(1) = NEWS_F1_NEWEST_BTIM(1):
	F1_NEWEST_BTIM(2) = NEWS_F1_NEWEST_BTIM(2)6
	FOLDER1_FLAG = NEWS_F1_FLAG
	IF (BTEST(FOLDER1_FLAG,8)) FOLDER1_BBOARD = 'NONE' 
	FOLDER1_BBEXPIRE = NEWS_F1_EXPIRE
	F1_EXPIRE_LIMIT = NEWS_F1_EXPIRE_LIMITO

	RETURNN

	END




	SUBROUTINE CONVERT_BULLDIRS

	IMPLICIT INTEGER (A-Z)E

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC''

	INCLUDE 'BULLFILES.INC'

	CHARACTER BUFFER*125X

	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

	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,1
     &	      ORGANIZATION='INDEXED',IOSTAT=IER,DISPOSE='DELETE',
     &	      KEY=(9:12:INTEGER,1:8:CHARACTER),ACCESS='KEYED',I
     &	      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,I
     &	      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)S
	BULLDIR_HEADER(49:52) = BUFFER(70:)
	IF (IER.EQ.0) WRITE (9,IOSTAT=IER) BULLDIR_HEADER

	ICOUNT = 2O
	DO WHILE (IER.EQ.0)
	   READ (2'ICOUNT,IOSTAT=IER) BUFFERT
	   IF (IER.EQ.0) THEN
	      MSG_NUM = ICOUNT - 1F
	      DESCRIP = BUFFER(:)
	      FROM = BUFFER(54:)O
	      BULLDIR_ENTRY(81:84) = BUFFER(85:)_
	      BULLDIR_ENTRY(93:100) = BUFFER(108:) 
	      CALL SYS_BINTIM(BUFFER(89:99)//' '//BUFFER(100:107),EX_BTIM)T
	      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 DOD

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

900	CALL RESET_PROTECTIONF

	RETURN 

	END



	SUBROUTINE CONVERT_BULLFILESI
C+
C  SUBROUTINE CONVERT_BULLFILESN
CE
C  FUNCTION: Converts bulletin files to new format file.
C	Add expiration time to directory file, add extra byte to bulletinI
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.'')')0

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

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

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

	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')N

	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)'
	NEMPTY = 0L
	IF (IER.EQ.0) CALL WRITEDIR(0,IER1)

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

	CLOSE (UNIT=9))
	CLOSE (UNIT=2)Q
	CLOSE (UNIT=10)
	CLOSE (UNIT=1)D

	CALL RESET_PROTECTION
	RETURNb

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

	END

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

	IMPLICIT INTEGER (A-Z) 

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC'X

	INCLUDE 'BULLFILES.INC'

	CHARACTER*80 BUFFER,NEW_FILES

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

	CALL CLOSE_BULLDIR 

	CALL SET_PROTECTION

	CALL OPEN_BULLFOLDERA

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

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

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

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

	CALL OPEN_BULLDIR

	CALL READDIR(0,IER)

	IF (IER.EQ.1) THENG
	 NBLOCK = 0
	 DO I=1,NBULL
	   CALL READDIR(I,IER)S
	   NBLOCK = NBLOCK + 1E
	   SBLOCK = NBLOCK
	   DO J=BLOCK,LENGTH+BLOCK-1_
	      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)B
	   LENGTH = NBLOCK - SBLOCK + 1
	   BLOCK = SBLOCK
	   CALL WRITEDIR(I,IER)
	 END DO

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

	CLOSE (UNIT=10)
	CLOSE (UNIT=1)E

	CALL CLOSE_BULLDIRR
	GOTO 100W

200	CALL OPEN_BULLDIR_SHARED

	CALL RESET_PROTECTION

	RETURNI

	END



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

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC'F

	INCLUDE 'BULLFILES.INC'

	INCLUDE '($SSDEF)'F

	INCLUDE '($FORIOSDEF)'W

	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,']'))Y
	SUFFIX = INDEX(FILENAME(EODIR:),'.') + EODIR - 1E
	NEW_FILE = FILENAME(:SUFFIX)//'OLD'

	DO WHILE (FILE_LOCK(IER,IER1))E
	   OPEN (UNIT=7,FILE=FILENAME,STATUS='OLD',
     &	        ACCESS='KEYED',RECORDTYPE='FIXED',4
     &	        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',1
     &	        RECORDSIZE=FOLDER_RECORD,
     &	        FORM='FORMATTED',ORGANIZATION='INDEXED',IOSTAT=IER,
     &	        KEY=(1:44:CHARACTER,45:48:INTEGER,49:56:CHARACTER),
     &		DISPOSE='DELETE')*

	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)F
	   IF (ASK_SIZE.EQ.184) THENB
	      READ (7,FMT='(A25,A4,A12,A80,A12,3A4,A8,5A4)',R
     &			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)', 
     &			KEYGE=F_NUMBER,KEYID=1,IOSTAT=IER)E
     &		OLD_FOLDER,F_NUMBER,FOLDER_OWNER,FOLDER_DESCRIPD
     &		,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)D
              CALL GET_MSGKEY(NEWS_F_NEWEST_BTIM,FOLDER_CREATED_DATE) 
	      IF (NEWS_FEED()) THEN D
		 CALL LIB$MOVC3(4,%REF(FOLDER_BBOARD(7:)),F_LAST)2
	      ELSEC
	         F_LAST = 0
	      END IF
	      WRITE (19,FMT=FOLDER_FMT,IOSTAT=IER)T
     &	        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_LAST
	      F_NUMBER = F_NUMBER + 1
	   END IF
	 END DO
	ELSE 
	 F_NUMBER = 0
	 DO WHILE (IER.EQ.0)'
	   READ (7,FMT='(A25,A4,A12,A80,A12,3A4,A8)',
     &			KEYGE=F_NUMBER,KEYID=1,IOSTAT=IER)R
     &		OLD_FOLDER,F_NUMBER,FOLDER_OWNER,FOLDER_DESCRIPR
     &		,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))T
	      CALL CHKACL
     &		(FOLDER_FILE(:TRIM(FOLDER_FILE))//'.BULLFIL',IER)L
	      IF (IER.NE.(SS$_ACLEMPTY.OR.SS$_NORMAL).AND.IER) THEN
		 FOLDER_FLAG = IBSET(FOLDER_FLAG,0)
	      END IFO
	      DO WHILE (FILE_LOCK(IER,IER1))V
	       OPEN (UNIT=2,FILE=FOLDER_FILE(:TRIM(FOLDER_FILE)) 
     &	         //'.BULLDIR',STATUS='OLD',FORM='UNFORMATTED',e
     &	         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)n
	          CALL CONVERT_BULLDIRS
		END IF
	      END DOE
	      IF (IER.EQ.FOR$IOS_FILNOTFOU) THENE
		 F_NEWEST_BTIM(1) = 0D
		 F_NEWEST_BTIM(2) = 0&
	      ELSET
	         CALL READDIR(0,IER)S
	         IF (NEWEST_DATE.EQ.'5-NOV-1956 ') THEN
		    IF (NBULL.GT.0) THEN
		       CALL READDIR(NBULL,IER)
		       NEWEST_DATE = DATE.
		       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 IFR
	      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,0=
	      F_NUMBER = F_NUMBER + 1
	   END IF
	 END DO
	END IFT

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

	IER = LIB$RENAME_FILE(NEW_FILE,FILENAME)E
	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

	RETURND
	END



	SUBROUTINE CONVERT_BULLNEWS(FILENAME)
CD
C  SUBROUTINE CONVERT_BULLNEWS
CN
C  FUNCTION: Converts bulletin NEWS file to new format.N
C,
	IMPLICIT INTEGER (A-Z) 

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC' 

	INCLUDE 'BULLFILES.INC'

	INCLUDE '($SSDEF)',

	INCLUDE '($FORIOSDEF)'(

	CHARACTER*(*) FILENAMET

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

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

	CALL SET_PROTECTION

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

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

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

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

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

	NEWS_FOLDER_NUMBER = 0(
        CALL SYS_BINTIM('5-NOV-1982',NEWS_F_NEWEST_BTIM)
        CALL GET_MSGKEY(NEWS_F_NEWEST_BTIM,NEWS_F_CREATED_DATE)E
        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)8
	NEWS_F_LAST = 0
	NEWS_F_FLAG = 0
	NEWS_F_EXPIRE = 7
	NEWS_F_FIRST = 0Y
	NEWS_F_END = 0.
	NEWS_F_EXPIRE_LIMIT = 0
	READ (7,KEY=1000,KEYID=1,IOSTAT=IER) INPUT(:108)M
	DO WHILE (IER.EQ.0)
	      OLD_FOLDER = INPUT(:25)
	      CALL LIB$MOVC3(4,%REF(INPUT(26:)),NEWS_FOLDER_NUMBER)
	      OLD_DESCRIP = INPUT(30:)M
	      CALL LIB$MOVC3(4,%REF(INPUT(87:)),NEWS_F_START)
              CALL LIB$MOVC3(4,%REF(INPUT(91:)),NEWS_F_COUNT)D
              CALL LIB$MOVC3(4,%REF(INPUT(97:)),NEWS_F_NBULL)0
              CALL LIB$MOVC3(8,%REF(INPUT(101:)),NEWS_F_NEWEST_BTIM)
	      LMOVE = INDEX(OLD_DESCRIP,' ')-1T
	      IF (LMOVE.LE.0) THEN'
	         NEWS_FOLDER = OLD_FOLDER
	         NEWS_FOLDER_DESCRIP = OLD_DESCRIPC
	      ELSEL
	         NEWS_FOLDER = OLD_FOLDER//OLD_DESCRIP(:MIN(19,LMOVE)) 
	         NEWS_FOLDER_DESCRIP = OLD_DESCRIP(MIN(20,LMOVE+1):)I
	      END IF 
  	      WRITE (19,IOSTAT=IER) NEWS_FOLDER_COM  
	      READ (7,IOSTAT=IER) INPUT(:108)
	 END DO

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

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

	CALL RESET_PROTECTION

	RETURND
	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)I

	INCLUDE 'BULLFILES.INC'

	INCLUDE 'BULLUSER.INC'A

	CHARACTER BUFFER*74,NEW_FILE*80

	CHARACTER*12 LOGIN_DATE,READ_DATE
	CHARACTER*8 LOGIN_TIME,READ_TIME.

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

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

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

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

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

	IF (IER.NE.0) THENL
	   WRITE (6,'('' Cannot convert user file.'')')
	   IF (IER1.EQ.0) CALL ERRSNS(IDUMMY,IER1)F
	   CALL SYS_GETMSG(IER1) 
	   CALL RESET_PROTECTION_
	   CALL ENABLE_CTRL_EXITA
	END IFQ

	DO I=1,FLONG 
	   NEW_FLAG(I) = 'FFFFFFFF'X1
	   NOTIFY_FLAG(I) = 0
	   BRIEF_FLAG(I) = 0=
	   SET_FLAG(I) = 0&
	END DOD

	IF (RECL.EQ.42.OR.RECL.EQ.50.OR.RECL.EQ.58.OR.RECL.EQ.66.OR.F
     &		RECL.EQ.74) THEN		! Old format
	   IF (RECL.LE.58) RECL = 50B
	   IER = 0A
	   DO WHILE (IER.EQ.0) 
	      READ (9,'(A<RECL>)',IOSTAT=IER) BUFFERE
	      IF (IER.EQ.0) THEN 
		TEMP_USER = BUFFER(:12)Y
	        LOGIN_DATE = BUFFER(13:23)T
	        LOGIN_TIME = BUFFER(24:31)E
	        READ_DATE = BUFFER(32:42)
	        READ_TIME = BUFFER(43:50)
	        IF (RECL.EQ.58)
     &		  CALL LIB$MOVC3(8,%REF(BUFFER(51:)),SET_FLAG(1))=
	        IF (RECL.EQ.66)
     &		  CALL LIB$MOVC3(8,%REF(BUFFER(59:)),NEW_FLAG(1))E
	        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)S
	        WRITE (4,FMT=USER_FMT) TEMP_USER,LOGIN_BTIM,1
     &		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,,
     &		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/flagE
	   DO WHILE (IER.EQ.0))
	    READ (9,FMT='(A12,<4+OFLONG*4>A4)',IOSTAT=IER) 
     &	     TEMP_USER,LOGIN_BTIM,READ_BTIM,I
     &	     (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 IF 
	   END DO
	END IFE

	IER = 0

	CLOSE (UNIT=9) 
	CLOSE (UNIT=4),

	CALL RESET_PROTECTION

	RETURN 
	END


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

	IMPLICIT INTEGER (A - Z)R

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC'L

	COMMON /PROMPT/ COMMAND_PROMPTT
	CHARACTER*40 COMMAND_PROMPT

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	COMMON /DIR_POSITION/ DIR_NUM

	COMMON /NEXT/ NEXTW

	COMMON /KEEPLOCK/ KEEPLOCK 
	DATA KEEPLOCK/.FALSE./W

	COMMON /COMMAND_LINE/ INCMD
	CHARACTER*132 INCMD

	COMMON /BULLFIL/ BULLFIL

	CHARACTER*3 CFOLDER_NUMBER,

	CHARACTER*8 NEWS_KEY 

	ICOUNT = BULLETIN_NUM

	IF (ICOUNT.EQ.0) THEN
	   IF (.NOT.REMOTE_SET) THENR
	      DO WHILE (REC_LOCK(IER)) 
		IF (REMOTE_SET.EQ.4) THENO
		   IER = 0
		ELSE
	           READ (2,KEYID=0,KEY=0,IOSTAT=IER) BULLDIR_HEADER
		END IF
	      END DON
	      IF (IER.EQ.0) THENT
		 CALL CONVERT_HEADER_FROMBIN
		 IF (REMOTE_SET.EQ.4) THEN
		    DIR_NUM = -1
		 ELSE_
	            DIR_NUM = 0
		 END IF_
	      END IFI
	   ELSE
	      CALL REMOTE_GET_HEADER(BULLETIN_NUM,ICOUNT,IER)
	      RETURNC
	   END IF
	   IF (IER.EQ.0.AND..NOT.REMOTE_SET.EQ.4) THEND
	      IF (NBULL.LT.0) THEN	! This indicates bulletin deletion
					! was incomplete.
		 CALL CLOSE_BULLDIRu
		 CALL OPEN_BULLDIR
		 CALL CLEANUP_DIRFILE(1)
		 CALL UPDATE_FOLDERE
	      END IF
	      IF (NEMPTY.EQ.'    '.AND.
     &		  FOLDER_BBOARD(:2).NE.'::') NEMPTY = 0
CC
C  Check to see if cleanup of empty file space is necessary, which is*
C  defined here as being 50 blocks (200 128byte records).  Also check 
C  to see if cleanup was in progress but didn't properly finish.
CI
	      IF (NEMPTY.GT.200.AND.TEST_BULLCP().EQ.0) THEND
		 WRITE (CFOLDER_NUMBER,'(I3)') FOLDER_NUMBER
	         IER1 = LIB$SPAWN('$'//COMMAND_PROMPT(:INDEX(
     &		  COMMAND_PROMPT,'>')-1)//'/CLEANUP='//CFOLDER_NUMBER,
     &		  'NL:','NL:',1,'BULL_CLEANUP')S
	      ELSE IF (NEMPTY.EQ.-1) THEN
		 CALL CLEANUP_BULLFILE
	      END IF 
	   END IF
	ELSED
	   IF (.NOT.REMOTE_SET) THEN 
	      DO WHILE (REC_LOCK(IER))G
		 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_ENTRYR
	               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_ENTRYS
                       ELSE_
	                  READ(2,KEY=NEWS_KEY(ICOUNT,FOLDER_NUMBER)
     &			    ,KEYID=1,IOSTAT=IER) NEWSDIR_ENTRY2
		       END IFN
		       IF (INCMD(:4).EQ.'BACK') THEN
		          DO WHILE (IER.NE.0.AND.ICOUNT.GT.F_START)A
	                     ICOUNT = ICOUNT - 17
			     READ(2,KEY=NEWS_KEY(ICOUNT,FOLDER_NUMBER)I
     &		                     ,KEYID=1,IOSTAT=IER) NEWSDIR_ENTRY 
                          END DO
		       END IF)
		    END IF
		    IF (IER.EQ.0) THEN
		       NUM = GET_INTEGER(%REF(NEWS_MSG_KEY))
		       IF (NUM.NE.FOLDER_NUMBER) THEN 
			  IER = 36_
			  UNLOCK 2 
		       ELSEM
			  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.E
     &				 MSG_NUM.GT.F_START) THENI
			     INQUIRE (UNIT=7,OPENED=IER1)
			     IF (.NOT.IER1) CALL OPEN_BULLNEWS_SHARED
			     IDUMMY = REC_LOCK(IER)
			     CALL READ_FOLDER_FILE_KEYNAMEE
     &							(FOLDER,IER2)
			     F_START = MSG_NUM 
		             CALL REWRITE_FOLDER_FILE(IER2)
			     IF (.NOT.IER1) CALL CLOSE_BULLNEWS
			     IDUMMY = REC_LOCK(IER)
	                  END IFC
		       END IFC
		       IF (IER.EQ.0.AND.MSG_NUM.NE.BULLETIN_NUM) THENW
			  ICOUNT = MSG_NUM=
			  BULLETIN_NUM = ICOUNT
		       END IFE
		    END IF
		 ELSEC
                    IF (DIR_NUM.EQ.ICOUNT-1) THENS
	               READ(2,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=ICOUNT,IOSTAT=IER) W
     &					BULLDIR_ENTRY
		       END IFA
		       IF (MSG_NUM.NE.ICOUNT) THEN
		          IER = 36
		          UNLOCK 2 e
		       END IFw
		    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)N
	                  READ(2,KEYID=0,KEY=ICOUNT,IOSTAT=IER)  
     &					BULLDIR_ENTRY
		       END IF
		    END IF
		 END IFE
	      END DO=
	      IF (IER.EQ.0) THEN 
	      	 CALL GET_MSGKEY(MSG_BTIM,MSG_KEY)
		 CALL CONVERT_ENTRY_FROMBIN(
		 DIR_NUM = MSG_NUM
	         IF (REMOTE_SET.EQ.4.AND.BULLFIL.GT.0) CALL SET_BULLFIL
	      ELSE 
		 DIR_NUM = -1c
	      END IFU
	   ELSE
	      CALL REMOTE_GET_HEADER(BULLETIN_NUM,ICOUNT,IER)
	      RETURNE
	   END IF
	END IFE

	IF (IER.EQ.0) THEN 
	   ICOUNT = ICOUNT + 1E
	   IF (.NOT.KEEPLOCK) UNLOCK 2,
	END IFL

	RETURNC

	END



	CHARACTER*8 FUNCTION NEWS_KEY(ICOUNT,FOLDER_NUMBER)

	IMPLICIT INTEGER (A-Z)P

	CHARACTER*4 INTEGER_KEY

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

	RETURNI
	END



	INTEGER FUNCTION GET_INTEGER(NUM)

        IMPLICIT INTEGER (A-Z)

	CHARACTER*4 CTEMP,INTEGER_KEY

	CTEMP = INTEGER_KEY(NUM)I

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

	RETURNe
	END



	CHARACTER*4 FUNCTION INTEGER_KEY(NUM)

	IMPLICIT INTEGER (A-Z) 

	INTEGER TEMPP
	CHARACTER*4 CTEMP
	EQUIVALENCE (CTEMP,TEMP)Q

	TEMP = NUMN

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

	RETURN 
	END


	SUBROUTINE READDIR_KEYGE(IER)
CR
C  SUBROUTINE READDIR_KEYGEC
CQ
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:U
C	IER  -  If 0, no entry found.  Else contains message number.
CM

	IMPLICIT INTEGER (A - Z)R

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC'3

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	COMMON /DIR_POSITION/ DIR_NUM

	COMMON /KEYID/ NEWS_KEYID
	DATA NEWS_KEYID/2/B

	COMMON /KEEPLOCK/ KEEPLOCKF

	COMMON /BULLFIL/ BULLFILQ

	CHARACTER*4 INTEGER_KEY

	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) THENR
		    READ(2,KEYGT=INTEGER_KEY(FOLDER_NUMBER)//MSG_KEY
     &		      ,KEYID=NEWS_KEYID,IOSTAT=IER) NEWSDIR_ENTRYR
                 ELSE 
		    READ(2,IOSTAT=IER) NEWSDIR_ENTRY
	         END IF
 	         IF (IER.EQ.0) THENS
		    NUM = GET_INTEGER(%REF(NEWS_MSG_KEY)) 
	            IF (NUM.NE.FOLDER_NUMBER) THEN 
		       IER = 36_
		       UNLOCK 2R
		    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 E
			     IF (MSG_NUM.GT.NEWS_F_END) THENF
				IDUMMY = REC_LOCK(IER)
			     END IF
	                   ELSE
		             IER = 36A
			     UNLOCK 2
			   END IF
	               END IF
		    END IF
	         END IF
	      ELSE(
	         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)E
	            READ(2,KEYID=0,KEY=MSG_NUM,IOSTAT=IER) 
     &					BULLDIR_ENTRY
		 END IFR
	      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_BULLFILr
	   ELSE
	      IER = 0
	      DIR_NUM = -1 
	   END IF
	ELSES
	   CALL REMOTE_GET_HEADER(DUMMY,-1,IER)
 	END IF


	RETURN,

	END



	SUBROUTINE CONVERT_HEADER_FROMBIN

	IMPLICIT INTEGER (A-Z)e

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC'E

	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 IF 

	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)I

	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)c
           DESCRIP = NEWS_DESCRIPi
           FROM = NEWS_FROM  I
           BLOCK = NEWS_BLOCKL
	   LENGTH = NEWS_LENGTH
	   SYSTEM = 0
	END IF 

	ENTRY CONVERT_ENTRY_FROMBIN_FOLDER 

	CALL SYS$ASCTIM(,DATETIME,EX_BTIM,)

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

	CALL SYS$ASCTIM(,DATETIME,MSG_BTIM,)n

	DATE = DATETIME(:11)s
	TIME = DATETIME(13:23)A

	RETURN
	END





	SUBROUTINE WRITEDIR(BULLETIN_NUM,IER)
Cn
C  SUBROUTINE WRITEDIR
C.
C  FUNCTION: Writes the entry for the specified bulletin in theI
C	directory file.
C 
C  INPUTS:
C	BULLETIN_NUM  -  Bulletin number.  Starts with 1.M
C			 If 0, write the header of the directory file.
C  OUTPUTS:,
C	IER - Error status from WRITE.
C 

	IMPLICIT INTEGER (A - Z)L

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC'

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	COMMON /DIR_POSITION/ DIR_NUM

	CHARACTER*8 NEWS_KEYT

	CONV = .TRUE.

	GO TO 10.

	ENTRY WRITEDIR_NOCONV(BULLETIN_NUM,IER)

	CONV = .FALSE.N
	,
10	IF (BULLETIN_NUM.EQ.0) THEN
	   IF (CONV) CALL CONVERT_HEADER_TOBINO
	   IF (REMOTE_SET) THEN
	      WRITE(REMOTE_UNIT,'(3A)',IOSTAT=IER)9,0,BULLDIR_HEADER	
	   ELSE
	      IER = -1N
	      IF (DIR_NUM.EQ.0) THEN
		 IF (REMOTE_SET.EQ.4) THEN
                    IER = 0 
		 ELSE(
	            REWRITE (2,IOSTAT=IER) BULLDIR_HEADER
		 END IFR
	      END IF 
	      IF (IER.NE.0) THEN 
		 IF (REMOTE_SET.EQ.4) THEN
		    IER = 0M
		 ELSE 
		    READ (2,KEYID=0,KEY=0,IOSTAT=IER)R
		    IF (IER.EQ.0) THEN  
	               REWRITE (2,IOSTAT=IER) BULLDIR_HEADER(
		    END IF
		 END IFS
	      END IF 
	      IF (IER.NE.0) THENN
		 IF (REMOTE_SET.NE.4) THEN
	            WRITE (2,IOSTAT=IER) BULLDIR_HEADER
		 END IFE
	      END IFR
	   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) THENI
		 IF (REMOTE_SET.EQ.4) THEN
	            REWRITE (2,IOSTAT=IER) NEWSDIR_ENTRY 
		 ELSE 
	            REWRITE (2,IOSTAT=IER) BULLDIR_ENTRYO
		 END IFA
	      END IF&
	      IF (IER.NE.0) THENE
		 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(_
     &			     BULLETIN_NUM,FOLDER_NUMBER),IOSTAT=IER) 
		    END DO		
		 ELSEC
	            READ (2,KEYID=0,KEY=BULLETIN_NUM,IOSTAT=IER) 
		 END IFE
		 IF (REMOTE_SET.EQ.4.AND.(
     &			BULLETIN_NUM.EQ.NEWS_F_END+1) THEND
                    CALL SPECIAL_NEWSDIR_ENTRY(IER)U
	         ELSE IF (IER.EQ.0) THEN	
		    IF (REMOTE_SET.EQ.4) THEN 
	               REWRITE (2,IOSTAT=IER) NEWSDIR_ENTRY
		    ELSE
	               REWRITE (2,IOSTAT=IER) BULLDIR_ENTRY
		    END IF
	         ELSE
		    IF (REMOTE_SET.EQ.4) THEN 
	               WRITE (2,IOSTAT=IER) NEWSDIR_ENTRY
		    ELSE
	               WRITE (2,IOSTAT=IER) BULLDIR_ENTRY
		    END IF
		 END IF&
	      END IFT
	   END IF
	END IF

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

	DIR_NUM = -1 

	RETURN

	END



        SUBROUTINE SPECIAL_NEWSDIR_ENTRY(IER)K

        IMPLICIT INTEGER (A-Z)

        INCLUDE 'BULLDIR.INC'E

        INCLUDE 'BULLFOLDER.INC'

	INCLUDE '($RMSDEF)'

	DIMENSION BTIM(2)

	CHARACTER*8 NEWS_KEY 

        READ (2,KEYID=3,KEY=NEWS_MSGID,IOSTAT=IER) INPUT(:84)	
	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  U
	   IER = 2A
	   RETURN
	END IF 

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		 
	DO WHILE (IER1.EQ.0) 
	   FNUM = GET_INTEGER(%REF(INPUT))I
	   IF (FNUM.NE.FOLDER_NUMBER) THENT
	      IER1 = 2S
	   ELSE
	      CALL GET_MSGKEY(%REF(INPUT(85:)),%DESCR(BTIM))T
	      IF (COMPARE_BTIM(BTIM,NEWEST_EXBTIM).LT.0.AND.E
     &		  .NOT.BTEST(FOLDER_FLAG,13)) THEN
	         CALL COPY2(NEWEST_EXBTIM,BTIM)
	      END IFC
	      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		
	   END IF
	END DOZ

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

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

	RETURNt
	END



	SUBROUTINE CONVERT_HEADER_TOBIN

	IMPLICIT INTEGER (A-Z)

        INCLUDE 'BULLFOLDER.INC' e

	INCLUDE 'BULLDIR.INC'

        COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNITu

	CHARACTER*8 NEWS_KEYe

	CHARACTER*4 INTEGER_KEY

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

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

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

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

	RETURNT
	END



	SUBROUTINE CONVERT_ENTRY_TOBIN.

	IMPLICIT INTEGER (A-Z)	

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC' 

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

        COMMON /LOCALPOST/ LOCAL_POSTD

	CHARACTER*4 INTEGER_KEY

	CHARACTER*8 NEWS_KEY	

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

        IF (REMOTE_SET.EQ.4) THEN 
	   CALL COPY2(NEWS_POST_BTIM,MSG_BTIM)R
        END IF
 L
	CALL SYS_BINTIM(DATE//' '//TIME,MSG_BTIM)

	IF (LOCAL_POST) THEN5
	   CALL COPY2(NEWS_POST_BTIM,MSG_BTIM)E
	END IF 

	IF (REMOTE_SET.EQ.4) THEN
           NEWS_DESCRIP = DESCRIP.
           NEWS_FROM = FROMM
           NEWS_BLOCK = BLOCK 
           NEWS_LENGTH = LENGTH 
	   CALL GET_MSGKEY(MSG_BTIM,MSG_KEY)
	   NEWS_MSG_KEY = NEWS_KEY(MSG_NUM,FOLDER_NUMBER)
	   NEWS_MSG_BTIM_KEY = INTEGER_KEY(FOLDER_NUMBER)//MSG_KEYT
	   CALL GET_MSGKEY(EX_BTIM,MSG_KEY)
	   NEWS_EX_BTIM_KEY = INTEGER_KEY(FOLDER_NUMBER)//MSG_KEY
	ELSEU
	   CALL GET_MSGKEY(MSG_BTIM,MSG_KEY)B
	END IFT

	RETURN
	END



	SUBROUTINE READ_FIRST_EXPIRED(NDEL)

	IMPLICIT INTEGER (A-Z)Y

        INCLUDE 'BULLDIR.INC' 

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

	COMMON /KEEPLOCK/ KEEPLOCK 
 V
        CHARACTER*4 INTEGER_KEY 

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

	ENTRY READ_NEXT_EXPIRED(NDEL) 	

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

	RETURNE
	END



	SUBROUTINE READACL(FILENAME,ACLENT,ACLLENGTH)
CE
C  SUBROUTINE READACLU
CI
C  FUNCTION: Reads the ACL of a file.
CM
C  PARAMETERS:
C	FILENAME - Name of file to check.T
C	ACLENT - String which will be large enough to hold ACL information.G
CM
	IMPLICIT INTEGER (A-Z) 

	INCLUDE 'BULLFILES.INC'

	INCLUDE '($ACLDEF)'

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

	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_ADDACLENTR
	   CTXT = 0
	END IFB

	DO ACC_TYPE=1,2
	 POINT = 1
	 OUTLEN = 0
	 DO WHILE ((POINT.LT.ACLLENGTH).AND.IER)M
	   IF (.NOT.BIG) THEN
	      IER = SYS$FORMAT_ACL(ACLENT(POINT:POINT-1+C
     &		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))),I
     &				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.A
     &	       (ACC_TYPE.EQ.2.AND.INDEX(ACLSTR(AC:),'READ').GT.0.AND.
     &	        INDEX(ACLSTR(AC:),'WRITE').EQ.0)) THEN 
	      START_ID = INDEX(ACLSTR,'=') + 1
	      END_ID = INDEX(ACLSTR,',ACCESS') - 1N
	      IF (ACLSTR(END_ID:END_ID).EQ.']') THEN	
		 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))E
		    IF (ACLSTR(START_ID:START_ID).NE.','.AND.R
     &			(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 IFT
		 END DO 
		 IF (ASCII) THEN
		    START_ID = START_ID + 1H
		    END_ID = END_ID - 1R
		    IF (ACLSTR(START_ID:START_ID).EQ.'*') THEN
		       START_ID = INDEX(ACLSTR,'=') + 1 
	               END_ID = INDEX(ACLSTR,'ACCESS') - 2U
		    END IF
		 END IF
	      END IF
	      IF (OUTLEN.EQ.0) THEN
		IF (FILENAME.NE.BULLUSER_FILE) THEN 
	         IF (ACC_TYPE.EQ.1) THEN,
		    WRITE (6,'(
     &		    '' These users can read and write to this folder:'')')
	         ELSE
		    WRITE (6,'(D
     &		    '' 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 IFE
	      IDLEN = END_ID - START_ID + 1
	      IF (OUTLEN+IDLEN-1.GT.80) THENT
		 WRITE (6,'(1X,A)') OUTPUT(:OUTLEN-1)D
		 OUTPUT = ACLSTR(START_ID:END_ID)//','
		 OUTLEN = IDLEN + 2U
	      ELSE IF (OUTLEN+IDLEN-1.EQ.80) THEN
		 WRITE (6,'(1X,A)') 
     &			OUTPUT(:OUTLEN-1)//ACLSTR(START_ID:END_ID)E
	         OUTLEN = 1
	      ELSEE
	         OUTPUT(OUTLEN:) = ACLSTR(START_ID:END_ID)//','
		 OUTLEN = OUTLEN + IDLEN + 1
	      END IFK
	   END IF
	   POINT = POINT + ICHAR(ACLENT(POINT:POINT))
	 END DO
	 IF (OUTLEN.GT.1) WRITE (6,'(1X,A)') OUTPUT(:OUTLEN-2)F
	END DOB

	RETURNI
	END




	SUBROUTINE CONVERT_INFFILE 

	IMPLICIT INTEGER (A-Z)I

	INCLUDE 'BULLUSER.INC'I

	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-28)/16.GT.FLONG) THEN
	   WRITE (6,'('' ERROR: Old data files have more folders'',
     &		      '' than was specified with BULLUSER.INC.'')') 
	   WRITE (6,'('' Recompile with correct FOLDER_MAX.'')') 
	   IF (USERNAME.EQ.'DECNET') THEN
	      CALL SYS$DELPRC(,)I
	   ELSE
	      CALL SYS$CANEXH()
	      CALL EXIT
	   END IF
	END IFA

	RECL = RECL/8

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

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

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

	CLOSE (UNIT=9)S

	RETURNN
	END


	SUBROUTINE ERROR_AND_EXIT

	IMPLICIT INTEGER (A-Z)R
	I
	CALL ERRSNS(IDUMMY,IER)
	CALL SYS_GETMSG(IER) 
	CALL ENABLE_CTRL_EXIT

	RETURN
	END




	SUBROUTINE COPY_ACL(INFILE,OUTFILE)
CE
C  SUBROUTINE COPY_ACL
CM
C  FUNCTION:
C	Copy ACLs from one file to another fileH
C
	IMPLICIT INTEGER (A-Z)R

	INCLUDE '($ACLDEF)'

	CHARACTER*(*) INFILE,OUTFILEN

	CALL INIT_ITMLST	! Initialize item list
	CALL ADD_2_ITMLST(4,ACL$C_ACLLENGTH,%LOC(ACLLENGTH))S
				! Get length needed to store acl outputS
	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 aclO

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

	RETURND
	END


	SUBROUTINE COPY_ACL1(INFILE,OUTFILE,ACLENT,ACLLENGTH)
CE
C  SUBROUTINE COPY_ACL1R
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.
CD
	IMPLICIT INTEGER (A-Z)R

	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),,,,,)L
				! Read input file acl 

	IF (.NOT.IER) THENS
	   IER = SYS$PARSE_ACL('(ID=*,ACCESS=NONE)',ACLENT,,)
	   IF (.NOT.IER) RETURN
	   ACLLENGTH = ACL$S_ADDACLENTL
	   CTXT = 0
	   DO WHILE (IER)
	      CALL INIT_ITMLST	! Initialize item list
	      CALL ADD_2_ITMLST(ICHAR(ACLENT(:1)),ACL$C_ADDACLENT,S
     &				%LOC(ACLENT))O
	      CALL END_ITMLST(ACL1_ITMLST)	! Get address of itemlistI
	      IER = SYS$CHANGE_ACLC
     &			(,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 IFO

	CALL INIT_ITMLST	! Initialize item list

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

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

	RETURNE
	END




	SUBROUTINE CHECK_DIR_ACCESS()

	IMPLICIT INTEGER (A-Z)L

        INCLUDE 'BULLFILES.INC'F

	CHARACTER*80 TEST,TEST1

	DATA CHECKED /.FALSE./C

  	IF (CHECKED) RETURN

	CHECKED = .TRUE.E

	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)I
	      BULLNEWS_FILE = TEST1
	   END IF
	   IF (.NOT.IER) THEN  
	      TEST1 = FOLDER_DIRECTORY
	      FOLDER_DIRECTORY = TEST
	   END IF
	   CALL ADD_DIRECTORY(BULLNEWS_FILE)b
	   CALL ADD_DIRECTORY(BULLNEWSDIR_FILE)
	   IF (.NOT.IER) FOLDER_DIRECTORY = TEST1
	ELSE.
	   CALL ADD_DIRECTORY(BULLNEWS_FILE)T
	   CALL ADD_DIRECTORY(BULLNEWSDIR_FILE)
	END IF

	CALL CHECK_DIR(FOLDER_DIRECTORY)i
	CALL CHECK_DIR(NEWS_DIRECTORY)A

	CALL ADD_DIRECTORIES)

        RETURN
        END!
 t


	SUBROUTINE ADD_DIRECTORIESS

        INCLUDE 'BULLFILES.INC'A

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

	RETURNT
	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)
	   IER = SYS_TRNLNM_SYSTEM_INDEX('BULL_DIR_LIST',TEST)
	END DOL

	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)')C
     &		TEST1(:TRIM(TEST1)) 
	      CALL EXIT
	   END IF
	   DIRECTORY = TEST1C
	ELSEQ
           IF (INDEX(TEST,':').EQ.0) TEST = TEST(:TRIM(TEST))//':'
	   DIRECTORY = TEST
	END IFE

	RETURNN
	END




	SUBROUTINE ADD_DIRECTORY(DIRECTORY)

	IMPLICIT INTEGER (A-Z)N

	INCLUDE 'BULLFILES.INC'

	CHARACTER*(*) DIRECTORY

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

	RETURNA
        END	
