C
C  BULLETIN5.FOR, Version 1/14/93
C  Purpose: Contains subroutines for the BULLETIN utility program.
C  Environment: VAX/VMS
C  Programmer: Mark R. London
C
C
	SUBROUTINE SET_FOLDER_DEFAULT(NOTIFY,READNEW,BRIEF)
C
C  SUBROUTINE SET_FOLDER_DEFAULT
C
C  FUNCTION: Sets flag defaults for specified folder
C
	IMPLICIT INTEGER (A-Z)

	INCLUDE 'BULLFOLDER.INC'

	INCLUDE 'BULLUSER.INC'

	COMMON /COMMAND_LINE/ INCMD
	CHARACTER*132 INCMD

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	EXTERNAL CLI$_NEGATED

	IF (REMOTE_SET.GE.3.OR.FOLDER_NUMBER.LT.0) THEN
	   WRITE (6,'('' ERROR: Command is invalid for this folder.'')')
	   RETURN
	END IF

	ALL = .FALSE.
	DEFAULT = 0

	IF (INCMD(:3).EQ.'SET') THEN
	   IF (.NOT.SETPRV_PRIV()) THEN
	      WRITE (6,'(
     &           '' ERROR: Privileges needed for changing defaults.'')')
	      RETURN
	   END IF
	   ALL = CLI$PRESENT('ALL')
	   DEFAULT = CLI$PRESENT('DEFAULT')
	   CALL OPEN_BULLUSER_SHARED
	   IF (CLI$PRESENT('PERMANENT')) THEN
	      CALL SET_PERM(NOTIFY,READNEW,BRIEF)
	   ELSE IF (CLI$PRESENT('NOPERMANENT')) THEN
	      IF (NOTIFY.GE.0) CALL SET_PERM(0,-1,-1)
	      IF (READNEW.GE.0.OR.BRIEF.GE.0) CALL SET_PERM(-1,0,0)
	   END IF
	ELSE
	   CALL OPEN_BULLUSER_SHARED
	END IF

	CALL READ_USER_FILE_HEADER(IER)
	IF (DEFAULT.EQ.0.OR.DEFAULT) THEN
	   IF (NOTIFY.EQ.0) CALL CLR2(NOTIFY_FLAG_DEF,FOLDER_NUMBER)
	   IF (NOTIFY.EQ.1) CALL SET2(NOTIFY_FLAG_DEF,FOLDER_NUMBER)
	   IF (READNEW.EQ.0) CALL CLR2(SET_FLAG_DEF,FOLDER_NUMBER)
	   IF (READNEW.EQ.1) CALL SET2(SET_FLAG_DEF,FOLDER_NUMBER)
	   IF (BRIEF.EQ.0) CALL CLR2(BRIEF_FLAG_DEF,FOLDER_NUMBER)
	   IF (BRIEF.EQ.1) CALL SET2(BRIEF_FLAG_DEF,FOLDER_NUMBER)
	   REWRITE(4) USER_HEADER
	END IF

	IF (ALL.OR.(BRIEF.NE.-1.AND.NOTIFY.NE.-1.AND.READNEW.NE.-1)) THEN
	   CALL READ_USER_FILE(IER)
	   DO WHILE (IER.EQ.0)
	      IF (TEMP_USER(:1).NE.'*'.AND.TEMP_USER(:1).NE.':') THEN
	         IF (NOTIFY.EQ.0) CALL CLR2(NOTIFY_FLAG,FOLDER_NUMBER)
	         IF (NOTIFY.EQ.1) CALL SET2(NOTIFY_FLAG,FOLDER_NUMBER)
	         IF (READNEW.EQ.0) CALL CLR2(SET_FLAG,FOLDER_NUMBER)
	         IF (READNEW.EQ.1) CALL SET2(SET_FLAG,FOLDER_NUMBER)
	         IF (BRIEF.EQ.0) CALL CLR2(BRIEF_FLAG,FOLDER_NUMBER)
	         IF (BRIEF.EQ.1) CALL SET2(BRIEF_FLAG,FOLDER_NUMBER)
	         REWRITE(4) TEMP_USER//USER_ENTRY(13:)
	      END IF
	      CALL READ_USER_FILE(IER)
	   END DO
	END IF

	CALL CLOSE_BULLUSER

	RETURN
	END




	SUBROUTINE READ_PERM

	IMPLICIT INTEGER (A-Z)

	INCLUDE 'BULLFOLDER.INC'

	INCLUDE 'BULLUSER.INC'

	COMMON /BULL_PERM/ SET_PERM_FLAG,BRIEF_PERM_FLAG,NOTIFY_PERM_FLAG
	DIMENSION SET_PERM_FLAG(FLONG)
	DIMENSION BRIEF_PERM_FLAG(FLONG)
	DIMENSION NOTIFY_PERM_FLAG(FLONG)

	COMMON /FLAG_ACCESS/ FLAG_ACCESS

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	DO WHILE (REC_LOCK(IER))
	   READ (4,KEY='*PERM',IOSTAT=IER) TEMP_USER,
     &		SET_PERM_FLAG,BRIEF_PERM_FLAG,NOTIFY_PERM_FLAG
	END DO

	IF (IER.NE.0) THEN
	   DO I=1,FLONG
	      SET_PERM_FLAG(I) = 0
	      BRIEF_PERM_FLAG(I) = 0
	      NOTIFY_PERM_FLAG(I) = 0
	   END DO
	   BRIEF_PERM_FLAG(1) = 1	! SHOWNEW permanent for GENERAL folder
	   WRITE (4,IOSTAT=IER)
     &		'*PERM       ',
     &		SET_PERM_FLAG,BRIEF_PERM_FLAG,NOTIFY_PERM_FLAG
	   CALL READ_USER_FILE_HEADER(IER)
	   IF (.NOT.TEST2(SET_FLAG_DEF,0)) THEN
	      CALL SET2(BRIEF_FLAG_DEF,0)
	      REWRITE(4) USER_HEADER
	   END IF
	   CALL READ_USER_FILE(IER)
	   DO WHILE (IER.EQ.0)
	      IF (TEMP_USER(:1).NE.'*'.AND.TEMP_USER(:1).NE.':') THEN
		 IF (.NOT.TEST2(SET_FLAG,0)) THEN
		    CALL SET2(BRIEF_FLAG,0)
	            REWRITE(4) TEMP_USER//USER_ENTRY(13:)
	         END IF
	      END IF
	      CALL READ_USER_FILE(IER)
	   END DO
	ELSE
	   UNLOCK 4
	END IF

	RETURN

	ENTRY SET_PERM(NOTIFY,READNEW,BRIEF)

	DO WHILE (REC_LOCK(IER))
	   READ (4,KEY='*PERM',IOSTAT=IER) TEMP_USER,
     &		SET_PERM_FLAG,BRIEF_PERM_FLAG,NOTIFY_PERM_FLAG
	END DO

	IF (NOTIFY.EQ.0) CALL CLR2(NOTIFY_PERM_FLAG,FOLDER_NUMBER)
	IF (NOTIFY.EQ.1) CALL SET2(NOTIFY_PERM_FLAG,FOLDER_NUMBER)
	IF (READNEW.EQ.0) CALL CLR2(SET_PERM_FLAG,FOLDER_NUMBER)
	IF (READNEW.EQ.1) CALL SET2(SET_PERM_FLAG,FOLDER_NUMBER)
	IF (BRIEF.EQ.0) CALL CLR2(BRIEF_PERM_FLAG,FOLDER_NUMBER)
	IF (BRIEF.EQ.1) CALL SET2(BRIEF_PERM_FLAG,FOLDER_NUMBER)

	REWRITE (4,IOSTAT=IER) TEMP_USER,
     &		SET_PERM_FLAG,BRIEF_PERM_FLAG,NOTIFY_PERM_FLAG

	RETURN

	ENTRY SET_USER_FLAG(NOTIFY,READNEW,BRIEF)

	IF (.NOT.FLAG_ACCESS) THEN
	   WRITE (6,'('' ERROR: Cannot set flags for protected'',
     &	     '' folder without explicit access granted'',/,
     &	     '' via SET ACCESS.  See HELP SET ACCESS for further''
     &       '' information.'')')
	   RETURN
	END IF

	IF (REMOTE_SET.GE.3) THEN
 	   IF (REMOTE_SET.EQ.3.AND.NOTIFY.EQ.1) THEN
	      WRITE (6,'('' ERROR: NOTIFY is not valid for this folder.'')')
	      RETURN
	   END IF
	   CALL NEWS_SET_USER_FLAG(NOTIFY,READNEW,BRIEF)
	   RETURN
	END IF

	CALL OPEN_BULLUSER_SHARED

	DO WHILE (REC_LOCK(IER))
	   READ (4,KEY='*PERM',IOSTAT=IER) TEMP_USER,
     &		SET_PERM_FLAG,BRIEF_PERM_FLAG,NOTIFY_PERM_FLAG
	END DO

	CALL CLOSE_BULLUSER

	IER = .TRUE.
	IF (NOTIFY.EQ.0) THEN
 	   IF (TEST2(NOTIFY_PERM_FLAG,FOLDER_NUMBER)) THEN
	      WRITE (6,'('' ERROR: NOTIFY is permanent for this folder.'')')
	      RETURN
	   ELSE
	      CALL CHANGE_FLAG(0,4)
	   END IF
	ELSE IF (NOTIFY.EQ.1) THEN
	   CALL CHANGE_FLAG(1,4)
	   RETURN
	ELSE IF (BRIEF.EQ.0.AND.READNEW.EQ.0.AND.
     &	   (TEST2(SET_PERM_FLAG,FOLDER_NUMBER).OR.
     &	   TEST2(BRIEF_PERM_FLAG,FOLDER_NUMBER))) THEN
	   IER = .FALSE.
	ELSE IF (BRIEF.EQ.1.AND.READNEW.EQ.0.AND.
     &	   TEST2(SET_PERM_FLAG,FOLDER_NUMBER).AND.
     &	   .NOT.TEST2(BRIEF_PERM_FLAG,FOLDER_NUMBER)) THEN
	   IER = .FALSE.
	ELSE IF (BRIEF.EQ.1.AND.READNEW.EQ.1.AND.
     &	   (TEST2(SET_PERM_FLAG,FOLDER_NUMBER).XOR.
     &	   TEST2(BRIEF_PERM_FLAG,FOLDER_NUMBER)))  THEN
	   IER = .FALSE.
	END IF

	IF (IER) THEN
	   IF (READNEW.GE.0) CALL CHANGE_FLAG(READNEW,2)
	   IF (BRIEF.GE.0) CALL CHANGE_FLAG(BRIEF,3)
	ELSE
	   WRITE (6,'('' ERROR: PERMANENT flags exist for this folder.'')')
	   WRITE (6,'('' Flags will be set to those permanent settings.'')')

	   IF (TEST2(SET_PERM_FLAG,FOLDER_NUMBER)) THEN
	      CALL CHANGE_FLAG(1,2)
	   ELSE
	      CALL CHANGE_FLAG(0,2)
	   END IF

	   IF (TEST2(BRIEF_PERM_FLAG,FOLDER_NUMBER)) THEN
	      CALL CHANGE_FLAG(1,3)
	   ELSE
	      CALL CHANGE_FLAG(0,3)
	   END IF
	END IF

	RETURN
	END





	SUBROUTINE REMOVE_FOLDER
C
C  SUBROUTINE REMOVE_FOLDER
C
C  FUNCTION: Removes a bulletin folder.
C

	IMPLICIT INTEGER (A-Z)

	INCLUDE 'BULLFOLDER.INC'

	INCLUDE 'BULLUSER.INC'

	INCLUDE 'BULLDIR.INC'

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	EXTERNAL CLI$_ABSENT

	CHARACTER RESPONSE*4,TEMP*80

	IER = CLI$GET_VALUE('REMOVE_FOLDER',FOLDER1,LEN_T) ! Get folder name

	IF (IER.EQ.%LOC(CLI$_ABSENT)) THEN
	   IF (.NOT.FOLDER_SET) THEN
	      WRITE (6,'('' ERROR: No folder specified.'')')
	      RETURN
	   ELSE
	      FOLDER1 = FOLDER
	   END IF
	ELSE IF (LEN_T.GT.44) THEN
	   WRITE(6,'('' ERROR: Folder name must be < 26 characters.'')')
	   RETURN
	END IF

	CALL GET_INPUT_PROMPT(RESPONSE,LEN,
     &   'Are you sure you want to remove folder '
     &	 //FOLDER1(:TRIM(FOLDER1))//' (Y/N with N as default): ')
	IF (RESPONSE(:1).NE.'y'.AND.RESPONSE(:1).NE.'Y') THEN
	   WRITE (6,'('' Folder was not removed.'')')
	   RETURN
	END IF

	IF (INDEX(FOLDER1,'.').GT.0) THEN
	   CALL OPEN_BULLNEWS_SHARED
	ELSE
	   CALL OPEN_BULLFOLDER
	END IF

	CALL READ_FOLDER_FILE_KEYNAME_TEMP(FOLDER1,IER)	! See if folder exists
	CALL SET_FOLDER_FILE(1)

	IF (IER.NE.0) THEN
	   WRITE (6,'('' ERROR: No such folder exists.'')')
	   GO TO 1000
	ELSE IF (INDEX(FOLDER1,'.').GT.0) THEN
	   CALL REMOTE_REMOVE_FOLDER(IER)
	   IF (.NOT.IER) GO TO 1000
	END IF

	IF (.NOT.FOLDER_ACCESS(USERNAME,FOLDER1_FLAG,FOLDER1_OWNER).OR.
     &	     FOLDER1_NUMBER.EQ.0) THENa
	   WRITE (6,'('' ERROR: You are not able to remove the folder.'')')
	   GO TO 1000
	END IFF

	TEMP = FOLDER_FILEE
	FOLDER_FILE = FOLDER1_FILED

	REMOTE_SET_SAVE = REMOTE_SET 
	REMOTE_SET = .FALSE.f

	IF (FOLDER1_BBOARD(:2).EQ.'::'.AND.BTEST(FOLDER1_FLAG,2)) THENC
	   FLEN = TRIM(FOLDER1_BBOARD)
	   IF (INDEX(FOLDER1_BBOARD,'*').GT.0) FLEN = FLEN - 1M
	   OPEN (UNIT=17,STATUS='UNKNOWN',IOSTAT=IER,
     &		RECL=256,FILE=FOLDER1_BBOARD(3:FLEN)
     &		//'::"TASK=BULLETIN1"')R
	   IF (IER.EQ.0) THEN		! Deregister remote SYSTEM folder
	      IF (INDEX(FOLDER1_BBOARD,'*').GT.0) THENT
	         CALL OPEN_BULLDIRT
	         CALL READDIR(0,IER)R
		 IF (IER.EQ.1) FOLDER1 = BULLDIR_HEADER(13:)
		 CALL CLOSE_BULLDIRe
	      END IFn
	      WRITE (17,'(2A)',IOSTAT=IER) 1,FOLDER1	! Select folderS
	      IF (IER.EQ.0) READ(17,'(5A)',IOSTAT=IER)	! Throw away responseR
	      IF (IER.EQ.0) WRITE(17,'(2A)',IOSTAT=IER) 14,0	! Deregister
	      CLOSE (UNIT=17)
	   END IF
	END IFE

	TEMPSET = FOLDER_SET
	FOLDER_SET = .TRUE.
	CALL SYS$SETDFPROT('FF00'X,CUR_DEF_PROT)N
		! Set protection to (SYSTEM:RWED,OWNER:RWED,WORLD,GROUP)
		! in case files don't exist and are created.
	CALL OPEN_BULLDIR			! Remove directory file
	CALL OPEN_BULLFIL			! Remove bulletin file)
	CALL CLOSE_BULLFIL_DELETE
	CALL CLOSE_BULLDIR_DELETE
	CALL SYS$SETDFPROT(CUR_DEF_PROT,)	! Reset default protectionD
	FOLDER_FILE = TEMPE
	FOLDER_SET = TEMPSETR

	DELETE (7)D

	TEMP_NUMBER = FOLDER_NUMBER
	FOLDER_NUMBER = FOLDER1_NUMBERQ
	CALL SET_FOLDER_DEFAULT(0,0,0)E
	FOLDER_NUMBER = TEMP_NUMBER

	WRITE (6,'('' Folder removed.'')')R

	IF (FOLDER.EQ.FOLDER1) THEN
	   FOLDER_SET = .FALSE.
	ELSE.
	   REMOTE_SET = REMOTE_SET_SAVE
	END IFN

1000	CALL CLOSE_BULLFOLDER

	RETURNI

	END


	SUBROUTINE SELECT_FOLDER(OUTPUT,IER).
CP
C  SUBROUTINE SELECT_FOLDER 
C 
C  FUNCTION: Selects the specified folder.
CU
C  INPUTS:
C	OUTPUT - Specifies whether status messages are outputted.
C 
C  NOTES:E
C	FOLDER_NUMBER is used for selecting the folder. 
C	If FOLDER_NUMBER = -1, the name stored in FOLDER1 is used.
C	If FOLDER_NUMBER = -2, the name stored in FOLDER1 is used,
C	but the folder is not selected if it is remote.E
C	If the specified folder is on a remote node and does not have 
C	a local entry (i.e. specified via NODENAME::FOLDERNAME), then
C	FOLDER_NUMBER is set to -1.T
C

	IMPLICIT INTEGER (A-Z) 

	INCLUDE 'BULLFOLDER.INC'E

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLUSER.INC'U

	INCLUDE '($RMSDEF)'
	INCLUDE '($SSDEF)'F

	COMMON /POINT/ BULL_POINT

	COMMON /ACCESS/ READ_ONLY
	LOGICAL READ_ONLY

	COMMON /COMMAND_LINE/ INCMD
	CHARACTER*132 INCMD

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT
	DATA REMOTE_SET /.FALSE./

	COMMON /SHUTDOWN/ NODE_NUMBER,NODE_AREA
	COMMON /SHUTDOWN/ SHUTDOWN_FLAG(FLONG) 

	COMMON /BULLPAR/ BULL_PARAMETER,LEN_P
	CHARACTER*64 BULL_PARAMETER

	COMMON /TAGS/ BULL_TAG,READ_TAG

	COMMON /SAVE_FOLDERS/ SAVE_FOLDER_Q1,SAVE_FOLDER_NUMR

	COMMON /BULL_NOTIFY/ NOTIFY_REMOTE(FLONG)

	COMMON /HEADER/ HEADERM

	COMMON /READIT/ READITa

	COMMON /FLAG_ACCESS/ FLAG_ACCESS4

	EXTERNAL CLI$_ABSENT,CLI$_NEGATED

	CHARACTER FSTATUS*4,FOLDER1_SAVE*44,NEWS_ACCESS*132

	CHARACTER*80 LOCAL_FOLDER1_DESCRIP

	DIMENSION FIRST_TIME(FLONG)	! Bit set for folder if folder hasA
	DATA FIRST_TIME /FLONG*0/	! been selected before this. 

	DIMENSION OLD_NEWEST_BTIM(2)W

	DATA LAST_NEWS_GROUP/0/

	COMMAND = (INCMD(:3).EQ.'ADD').OR.(INCMD(:3).EQ.'DEL').OR.O
     &		  (INCMD(:3).EQ.'DIR').OR.(INCMD(:3).EQ.'IND').OR.
     &		  (INCMD(:3).EQ.'REP').OR.(INCMD(:3).EQ.'SEL').OR.
     &		  (INCMD(:3).EQ.'SET')

	IF (.NOT.OUTPUT.OR.FOLDER_NUMBER.NE.-1.OR.COMMAND) THEN
	   IF (OUTPUT) THEN			! Get folder name
	      IER = CLI$GET_VALUE('SELECT_FOLDER',FOLDER1_NAME)
	      FOLDER1 = FOLDER1_NAME 
	   END IF

	   FLEN = TRIM(FOLDER1)		! Add GENERAL after :: if no
	   IF (FLEN.GT.1) THEN		! name specified after the ::
	      IF (FOLDER1(FLEN-1:FLEN).EQ.'::') THENI
	         FOLDER1 = FOLDER1(:FLEN)//'GENERAL')
	      END IFP
	   END IF

	   IF (((IER.EQ.%LOC(CLI$_ABSENT).OR.FOLDER1.EQ.'GENERAL').AND.
     &	    OUTPUT).OR.((FOLDER_NUMBER.EQ.0.OR.(FOLDER1.EQ.'GENERAL'.AND.
     &	    FOLDER_NUMBER.LE.-1)).AND..NOT.OUTPUT)) THEN ! Select GENERAL
	      FOLDER_NUMBER = 0
	      FOLDER1 = 'GENERAL'
	   END IF
	END IFR

	REMOTE_TEST = 0
	REMOTE_SET_NEW = 0D

	IF (SAVE_FOLDER_Q1.NE.0) THEN			! Have folder info6
	   FOLDER1_COM = FOLDER_COM
	   IER = 0'
	   NEWS = INDEX(FOLDER1,'.').GT.0.OR.(FOLDER1(:1).GE.'a'.AND.
     &					   FOLDER1(:1).LE.'z') 
	ELSET
	   NEWS = ((INDEX(FOLDER1,'.').GT.0.OR.(FOLDER1(:1).GE.'a'.AND.
     &		FOLDER1(:1).LE.'z')).AND.(FOLDER_NUMBER.LE.-1.OR.OUTPUT))Q
     &		.OR.(FOLDER_NUMBER.GT.1000.AND..NOT.OUTPUT) 
	   IF (NEWS.AND. 
     &		SYS_TRNLNM('BULL_NEWS_SERVER','DEFINED')) THEN
	      CALL OPEN_BULLNEWS_SHARED		! Go find folder
	      READ (7,IOSTAT=IER,KEYEQ=1000,KEYID=1) NEWS_FOLDER1_COM
              NEWS_EXPIRE_DEFAULT = NEWS_F1_EXPIRE
              NEWS_EXPIRE_LIMIT_DEFAULT = NEWS_F1_EXPIRE_LIMIT
	      IF (IER.NE.0) THENU
		 WRITE (6,'('' Fetching NEWS groups from remote node.''T
     &			,''  This will take several minutes.'')')
		 WRITE (6,'('' This is the only time this will have'''
     &			,'' to be done.'')')
	         CALL CLOSE_BULLFOLDER 
		 FOLDER1_SAVE = FOLDER1.
		 CALL NEWS_LISTC
	         CALL OPEN_BULLFOLDER_SHARED(
		 FOLDER1 = FOLDER1_SAVE.
	      ELSE IF (NEWS_F1_COUNT.GT.LAST_NEWS_READ(1,FOLDER_MAX).AND.
     &		       OUTPUT.AND.NEWS_F1_COUNT.GT.LAST_NEWS_GROUP) THEN
		 IF (LAST_NEWS_READ(1,FOLDER_MAX).GT.1000) THEN 
		    FOLDER1_SAVE = FOLDER1
	            FOLDER1_NUMBER = LAST_NEWS_READ(1,FOLDER_MAX)
	            IER = 2
		    DO WHILE (IER.EQ.2).
		       CALL READ_FOLDER_FILE_KEYNUM_GT_TEMPT
     &		          (FOLDER1_NUMBER,IER)
		       IF (IER.EQ.0.AND.BTEST(FOLDER1_FLAG,10)) IER = 2F
	            END DOI
		    FOLDER1 = FOLDER1_SAVE
		 END IFC
		 IF (LAST_NEWS_READ(1,FOLDER_MAX).GT.1000A
     &			.AND.IER.EQ.0) THEN
		    WRITE (6,'('' Type NEWS/NEWGROUP to see recently'', 
     &			       '' added news groups.'')')
		 ELSEt
		    LAST_NEWS_READ(1,FOLDER_MAX) = NEWS_F1_COUNT
		 END IFO
		 LAST_NEWS_GROUP = NEWS_F1_COUNT
		 FOLDER1_SAVE = FOLDER1 
	         CALL STR$UPCASE(FOLDER1,FOLDER1)
	         CALL READ_FOLDER_FILE_KEYNAME_TEMP
     &				(FOLDER1(:INDEX(FOLDER1,'.')),IER)
	         IF (IER.EQ.0) THEN
		    IF (NEWS_F1_EXPIRE.GT.0) D
     &		       NEWS_EXPIRE_DEFAULT = NEWS_F1_EXPIRET
		    IF (NEWS_F1_EXPIRE_LIMIT.NE.0) m
     &		       NEWS_EXPIRE_LIMIT_DEFAULT = NEWS_F1_EXPIRE_LIMITU
	         END IF
	         FOLDER1 = FOLDER1_SAVE
	      END IFI
	      CALL LOWERCASE(FOLDER1)
	   ELSE
	      CALL OPEN_BULLFOLDER_SHARED		! Go find folder
	   END IF

	   IF ((OUTPUT.AND.(FOLDER_NUMBER.NE.0.OR.FOLDER1.NE.'GENERAL')) 
     &		.OR.FOLDER_NUMBER.LE.-1) THENB
	      REMOTE_TEST = INDEX(FOLDER1,'::')
	      IF (REMOTE_TEST.GT.0) THENf
	         FOLDER1_BBOARD = '::'//FOLDER1(:REMOTE_TEST-1)
	         FOLDER1 = FOLDER1(REMOTE_TEST+2:TRIM(FOLDER1))
	         FOLDER1_NUMBER = -1r
	         IER = 0c
	      ELSE IF (INCMD(:2).EQ.'SE') THEN
	         CALL READ_FOLDER_FILE_KEYNAME_TEMP
     &				(FOLDER1(:TRIM(FOLDER1)),IER)'
	      ELSEO
	         CALL READ_FOLDER_FILE_KEYNAME_TEMP(FOLDER1,IER)R
	      END IF'
	   ELSE
	      FOLDER1_NUMBER = FOLDER_NUMBER'
	      CALL READ_FOLDER_FILE_KEYNUM_TEMP(FOLDER_NUMBER,IER)I
	   END IF

	   IF (REMOTE_TEST.EQ.0.AND.IER.EQ.0) THEN
	      IF (BTEST(FOLDER1_FLAG,29)) THEN		! Error in folder flag!!I
	         FOLDER1_FLAG = FOLDER1_FLAG.AND.3e
	         F1_EXPIRE_LIMIT = 0)
	         CALL REWRITE_FOLDER_FILE_TEMP(IER1)O
	      END IFe
	   END IF

	   CALL CLOSE_BULLFOLDER(

	   IF (NEWS.AND.BTEST(FOLDER1_FLAG,8).AND.IER.EQ.0) THEN(
	      REMOTE_SET_NEW = 4T
	      CALL SYS_BINTIM('-',EX_BTIM)A
	   END IF
	END IF1

	IF (BTEST(FOLDER1_FLAG,9)) THEN
	   IF (OUTPUT) THEN
	       WRITE(6,'('' This news group has been disabled.'')')
	   END IF
	   IER = 2 
	   RETURN
	END IFM

	IF ((IER.EQ.0.OR.NEWS).AND.REMOTE_SET_NEW.NE.4.AND.
     &		FOLDER1_BBOARD(:2).EQ.'::') THEN
	   IF (FOLDER_NUMBER.EQ.-2) RETURN	! Don't allow(
	   IF (IER.NE.0) FOLDER1_DESCRIP = FOLDER1_NAME
	   LOCAL_FOLDER1_FLAG = FOLDER1_FLAG'
	   LOCAL_FOLDER1_DESCRIP = FOLDER1_DESCRIPT
	   CALL CONNECT_REMOTE_FOLDER(READ_ONLY,IER1)
	   IF (IER1.NE.0) THEN
	      IF (OUTPUT) THENI
	         WRITE (6,'('' ERROR: Unable to select the folder.'')')
		 IF (.NOT.NEWS) THEN
		    LENB = TRIM(FOLDER1_BBOARD) 
		    IF (FOLDER1_BBOARD(LENB:LENB).EQ.'*') LENB = LENB - 1I
	            WRITE (6,'('' Cannot connect to node '',A,''.'')') 
     &		        FOLDER1_BBOARD(3:LENB)
		 ELSE IF (.NOT.IER1) THENf
	            WRITE (6,'('' Cannot connect to remote NEWS node.'')')r
	         END IF
	      END IFI
	      RETURNS
	   END IF
	   IF (REMOTE_TEST.GT.0) THEN	! Folder specified with "::"
	      FOLDER1 = FOLDER1_BBOARD(3:TRIM(FOLDER1_BBOARD))//'::'//O
     &			FOLDER1
	      FOLDER1_NUMBER = -1
	      REMOTE_SET_NEW = 1O
	   ELSE IF (NEWS) THENi
	      REMOTE_SET_NEW = 3a
	      CALL OPEN_BULLNEWS_SHARED	! Update local folder information
	      IF (IER.NE.0) CALL NEWS_NEW_FOLDERU
              CALL READ_FOLDER_FILE_KEYNAME(FOLDER1,IER)
	      IF ((F1_START.NE.F_START.OR.F1_NBULL.NE.F_NBULL).AND.
     &		  F1_START.GT.0) THEN
	         IF (F1_NBULL.NE.F_NBULL) CALL SYS_BINTIM('-',F_NEWEST_BTIM)1
	         F_NBULL = F1_NBULL
	         F_START = F1_START
	         CALL REWRITE_FOLDER_FILE(IER)o
	      END IFI
	      CALL CLOSE_BULLFOLDER
	   ELSE				! True remote folder
	      FOLDER1_DESCRIP = LOCAL_FOLDER1_DESCRIP	! Use local description
	      IF (BTEST(FOLDER1_FLAG,0)) THEN	! If remote folder is protected
		 LOCAL_FOLDER1_FLAG = IBSET(LOCAL_FOLDER1_FLAG,0)e
	      END IFe
	      FOLDER1_FLAG = LOCAL_FOLDER1_FLAG		! Use local flag infoa
	      CALL OPEN_BULLFOLDER	! Update local folder informatione
              CALL READ_FOLDER_FILE_KEYNAME(FOLDER1,IER)
	      OLD_NEWEST_BTIM(1) = F_NEWEST_BTIM(1)
	      OLD_NEWEST_BTIM(2) = F_NEWEST_BTIM(2)
	      FOLDER_COM = FOLDER1_COMi
	      FOLDER_NAME = FOLDERd
	      CALL REWRITE_FOLDER_FILE(IER)
	      CALL CLOSE_BULLFOLDER
	      REMOTE_SET_NEW = 1O
	      DIFF = COMPARE_BTIM(OLD_NEWEST_BTIM,F_NEWEST_BTIM)P
	      IF (DIFF.LT.0) THEN
	         CALL READ_NOTIFY
	         IF (TEST2(NOTIFY_REMOTE,FOLDER_NUMBER)) THEN
		    CALL NOTIFY_REMOTE_USERS(OLD_NEWEST_BTIM) 
	         END IF
	      END IFC
	   END IF
	END IFC

	IF (IER.EQ.0) THEN				! Folder foundC
	   FLAG1_ACCESS = .TRUE.
	   CALL SET_FOLDER_FILE(1)E
	   IF (BTEST(FOLDER1_FLAG,0)) THEN		! Folder protected?
	      IF (NEWS) THEND
		 CALL CHKACL(NEWS_ACCESS(FOLDER1_DESCRIP),IER)
	      ELSEL
	         CALL CHKACLN
     &		 (FOLDER1_FILE(:TRIM(FOLDER1_FILE))//'.BULLFIL',IER)
	      END IFO
	      IF (IER.NE.(SS$_ACLEMPTY.OR.SS$_NORMAL).AND.USERNAMEB
     &		  .NE.FOLDER1_OWNER.AND.IER) THEN 
	         IF (NEWS) THEN
	            CALL CHECK_ACCESS
     &		     (NEWS_ACCESS(FOLDER1_DESCRIP),S
     &		     USERNAME,READ_ACCESS,WRITE_ACCESS)S
	         ELSE
	            CALL CHECK_ACCESS
     &		     (FOLDER1_FILE(:TRIM(FOLDER1_FILE))//'.BULLFIL',
     &		     USERNAME,READ_ACCESS,WRITE_ACCESS)!
	         END IF
	         IF (SETPRV_PRIV().AND.READIT.EQ.0) THENT
		    IF (.NOT.READ_ACCESS) FLAG1_ACCESS = .FALSE.
	            READ_ACCESS = 1
		    WRITE_ACCESS = 1
	         END IF
	         IF (.NOT.READ_ACCESS.AND..NOT.WRITE_ACCESS) THEN
		  IF (OUTPUT.AND.NEWS) THEN 
	           WRITE(6,'('' You are not allowed to access news group.'')')D
		  ELSE IF (NEWS) THENH
		   IF (NEWS_FIND_SUBSCRIBE().LE.FOLDER_MAX-1) THEN
		      CALL NEWS_SET_USER_FLAG(0,0,0)
		   END IFN
		  ELSE IF (OUTPUT) THENN
	           WRITE(6,'('' You are not allowed to access folder.'')')E
	           WRITE(6,'('' See '',A,'' if you wish to access folder.'')'))
     &			FOLDER1_OWNER(:TRIM(FOLDER1_OWNER))
		  ELSE IF (TEST2(BRIEF_FLAG,FOLDER1_NUMBER).OR.E
     &			 TEST2(SET_FLAG,FOLDER1_NUMBER)) THEN
		   CALL OPEN_BULLUSER_SHARED
		   CALL READ_USER_FILE_KEYNAME(USERNAME,IER)
		   CALL CLR2(BRIEF_FLAG,FOLDER1_NUMBER)U
		   CALL CLR2(SET_FLAG,FOLDER1_NUMBER)E
		   IF (IER.EQ.0) REWRITE (4) USER_ENTRY 
		   CALL CLOSE_BULLUSER
		  END IF
		  IER = 0_
		  RETURN
	         END IF
	      ELSE IF (BTEST(FOLDER1_FLAG,0).AND.(.NOT.IER.OR.D
     &		  (IER.EQ.(SS$_ACLEMPTY.OR.SS$_NORMAL).AND..NOT.NEWS))
     &		  .AND.(FOLDER1_BBOARD(:2).NE.'::'.OR.NEWS)) THENE
	         IF (NEWS) THEN
	            CALL OPEN_BULLNEWS_SHARED
	         ELSE
	            CALL OPEN_BULLFOLDERE
	         END IF
	         CALL READ_FOLDER_FILE_KEYNAME_TEMP(FOLDER1,IER1)
		 FOLDER1_FLAG = IBCLR(FOLDER1_FLAG,0)L
	         CALL REWRITE_FOLDER_FILE_TEMP(IER1) 
		 CALL CLOSE_BULLFOLDER
	      ELSE IF (FOLDER1_BBOARD(:2).EQ.'::') THEN
	         IER = SS$_ACLEMPTY.OR.SS$_NORMAL
	      END IF 
	   ELSE					! Folder not protectedP
	      IER = SS$_ACLEMPTY.OR.SS$_NORMAL	! Indicate folder selected
	   END IF

	   IF (REMOTE_SET_NEW.NE.1.AND.REMOTE_SET.EQ.1)  
     &					CLOSE(UNIT=REMOTE_UNIT)

	   REMOTE_SET = REMOTE_SET_NEW 

	   IF (IER) THENi
	      FLAG_ACCESS = FLAG1_ACCESS	! Can set flags?

	      FOLDER_COM = FOLDER1_COM		! Folder successfully set soS
	      FOLDER_FILE = FOLDER1_FILE	! update folder parameters

	      IF (FOLDER_NUMBER.NE.0) THENO
		 FOLDER_SET = .TRUE.
	      ELSEN
		 FOLDER_SET = .FALSE..
	      END IFN

	      IF (REMOTE_SET.LT.3) THEN
		 FOLDER_NAME = FOLDERX
	         HEADER = .NOT.BTEST(FOLDER_FLAG,4)
	      ELSE 
	         HEADER = .FALSE.
		 FOLDER_NAME = FOLDER_DESCRIP(:INDEX(FOLDER_DESCRIP,' ')-1)Q
	         IF (REMOTE_SET.EQ.4) NEWS_FOLDER_COM = NEWS_FOLDER1_COM 
	      END IFM

	      IF (REMOTE_SET.EQ.0.AND..NOT.BTEST(FOLDER_FLAG,10)E
     &		   .AND..NOT.BTEST(FOLDER_FLAG,11)) THEN
	         SLIST = INDEX(FOLDER_DESCRIP,'<'),
                 IF (OUTPUT.AND.INCMD(:3).NE.'DIR') THEN
                    IF (NEWS_FEED()) THENe
                       WRITE (6,'('' Use the POST command to send a '',T
     &                 ''message to this folder''''s news group.'')')P
		    ELSE IF (SLIST.GT.0) THEN 
                       WRITE (6,'('' Use the POST command to send a '',A
     &                 ''message to this folder''''s mailing list.'')')
                    END IF
                 END IFE
	      END IF&

	      IF (OUTPUT.AND.INCMD(:3).NE.'DIR') THEN
		 WRITE (6,'('' Folder has been set to '',A)') 
     &		    FOLDER_NAME(:TRIM(FOLDER_NAME))//'.'
	      END IFN

	      IF (OUTPUT) THENO
		 IF (REMOTE_SET.EQ.3) THEN
		    BULL_POINT = F_START - 1
		    FSTATUS(:1) = 
     &			FOLDER_DESCRIP(INDEX(FOLDER_DESCRIP,' ')+1:) 
		    IF (STREQ(FSTATUS(:1),'X')) THEN
		       WRITE (6,'('' WARNING: The local news server has'',
     &				  '' deactivated this group.'')')
		    ELSE IF (STREQ(FSTATUS(:1),'=')) THEN 
		       WRITE (6,'('' NOTE: This group is no longer'', 
     &				  '' active.  It has been replaced by:'')') 
		       WRITE (6,'(1X,A)') FOLDER_DESCRIP( 
     &				       INDEX(FOLDER_DESCRIP,'=')+1:)
		    END IF
		 ELSE_
		    BULL_POINT = 0	! Reset pointer to first bulletin
	         END IF
	      END IF_

	      IF (IER.NE.(SS$_ACLEMPTY.OR.SS$_NORMAL).AND.USERNAMEE
     &		  .NE.FOLDER_OWNER) THEN
	         IF (.NOT.WRITE_ACCESS) THENY
		   IF (OUTPUT.AND.INCMD(:3).NE.'DIR'.AND.SLIST.EQ.0) THENS
		    WRITE (6,'('' Folder only accessible for reading.'')')
		   END IFr
		   READ_ONLY = .TRUE. 
		 ELSER
		   READ_ONLY = .FALSE.
		 END IF 
	      ELSEI
		 READ_ONLY = .FALSE.
	      END IF_

	      IF (FOLDER_NUMBER.GT.0.AND.REMOTE_SET.LT.3) THENO
		IF (TEST_BULLCP().GT.0.OR.REMOTE_SET) THEN
		 CALL SET2(FIRST_TIME,FOLDER_NUMBER)
		ELSE IF (.NOT.TEST2(FIRST_TIME,FOLDER_NUMBER)) THENA
	       			! If first select, look for expired messages.
		 CALL OPEN_BULLDIR
		 CALL READDIR(0,IER)	! Get header info from BULLDIR.DAT)
	 	 IF (IER.EQ.1) THEN		! Is header present?
	   	    IER = COMPARE_DATE(NEWEST_EXDATE,' ') ! Yes. Any expired?
		    IF (SHUTDOWN.GT.0.AND.NODE_AREA.GT.0.AND.R
     &			(FOLDER_NUMBER.EQ.0.OR.BTEST(FOLDER_FLAG,2)) 
     &			.AND.TEST2(SHUTDOWN_FLAG,FOLDER_NUMBER)) THEN
						! Do shutdown bulletins exist?
		       SHUTDOWN = 0
		       IER1 = -1
		    ELSE
		       IF (TEST2(SHUTDOWN_FLAG,FOLDER_NUMBER)) THENT
			  CALL UPDATE_SHUTDOWN(FOLDER_NUMBER)
		       END IF 
	               IER1 = 1
		    END IF
	 	    IF (IER.LE.0.OR.IER.GT.20*356.OR.IER1.LE.0) THENB
		       CALL UPDATE	! Need to updateI
		    END IF
		 ELSE,
		    NBULL = 0c
		 END IF'
		 CALL CLOSE_BULLDIR 
		 CALL SET2(FIRST_TIME,FOLDER_NUMBER)
	        END IFf
	      END IFW

	      IF (OUTPUT) THEN 
		 IF (CLI$PRESENT('MARKED')) THEN
		    READ_TAG = 1 + IBSET(0,1)R
		    BULL_PARAMETER = 'MARKED'E
		 ELSE IF (CLI$PRESENT('SEEN')) THENh
		    READ_TAG = 1 + IBSET(0,2)B
		    BULL_PARAMETER = 'SEEN''
	         ELSE IF (CLI$PRESENT('UNMARKED').OR.CLI$PRESENT 
     &		       ('MARKED').EQ.%LOC(CLI$_NEGATED)) THENR
		    READ_TAG = 1 + IBSET(0,1) + IBSET(0,3)
		    BULL_PARAMETER = 'UNMARKED'a
	         ELSE IF (CLI$PRESENT('UNSEEN').OR.CLI$PRESENT 
     &		       ('SEEN').EQ.%LOC(CLI$_NEGATED)) THEN 
		    READ_TAG = 1 + IBSET(0,2) + IBSET(0,3)
		    BULL_PARAMETER = 'UNSEEN'.
		 ELSE
		    READ_TAG = IBSET(0,1) + IBSET(0,2)
		 END IF'
	         IF (READ_TAG) THEN
	            IF (FOLDER_NUMBER.GE.0) THENA
		       CALL GET_FIRST_TAG(FOLDER_NUMBER,IER,BULL_POINT)I
		    ELSE
		       WRITE (6,'('' ERROR: invalid qualifier'',
     &			          '' with remote folder.'')')
		       READ_TAG = IBSET(0,1) + IBSET(0,2)L
		    END IF
	         END IF
	         IF (READ_TAG.AND.INCMD(:3).NE.'DIR') THENA
		    IF (IER.EQ.0) THEN
		       WRITE(6,'('' NOTE: Only '',A,'' messages'',
     &			   '' will be shown.'')')
     &			   BULL_PARAMETER(:TRIM(BULL_PARAMETER)) 
		    ELSE
		       WRITE(6,'('' WARNING: No '',A,)
     &			   '' messages found.'')')T
     &		 	   BULL_PARAMETER(:TRIM(BULL_PARAMETER))
		    END IF
	         END IF
	      END IFL

	      IF (REMOTE_SET.GE.3.AND.OUTPUT.AND..NOT.READ_TAG) THENC
		 CALL NEWS_GET_NEWEST_MESSAGE(IER)
		 IF (IER.GT.0.AND.IER.LE.F_NBULL) THEN
		    BULL_POINT = IER - 1
	            WRITE(6,'('' Type READ to read new messages.'')')
		 END IFT
	      ELSE IF (FOLDER_NUMBER.NE.0.AND..NOT.READ_TAG.AND.O
     &		  				REMOTE_SET.LT.3) THEN 
	        IF (OUTPUT.AND.INCMD(:3).NE.'DIR') THEN
	         DIFF = COMPARE_BTIM(LAST_READ_BTIM(1,FOLDER_NUMBER+1),
     &					F_NEWEST_BTIM)E
	         IF (DIFF.LT.0.AND.F_NBULL.GT.0) THEN 	! If new unread messages
		  CALL FIND_NEWEST_BULL			! See if we can find it,
		  IF (BULL_POINT.NE.-1) THEN
	     	    WRITE(6,'('' Type READ to read new messages.'')')
		    NEW_COUNT = F_NBULL - BULL_POINT
		    DIG = 0M
		    DO WHILE (NEW_COUNT.GT.0)
		      NEW_COUNT = NEW_COUNT / 10
		      DIG = DIG + 1E
		    END DO
		    WRITE(6,'('' There are '',I<DIG>,'' new messages.'')')
     &			F_NBULL - BULL_POINT	! Alert user if new bulletins
		  ELSE
		    BULL_POINT = 0
		  END IF
		 END IF	
		END IF
	      END IFF
	      IER = 1
	      IF (TEST_BULLCP().NE.2) CALL CHECK_CUSTOM
	   ELSE IF (OUTPUT) THENF
	      WRITE (6,'('' Cannot access specified folder.'')') 
	      CALL SYS_GETMSG(IER)C
	   END IF
	ELSE						! Folder not found1
	   IF (OUTPUT) WRITE (6,'('' ERROR: Folder does not exist.'')')
	   IER = 0.
	END IF_

	RETURNN

	END





	SUBROUTINE UPDATE_FOLDER 
CT
C  SUBROUTINE UPDATE_FOLDERt
Cc
C  FUNCTION: Updates folder info due to new message.
C 

	IMPLICIT INTEGER (A-Z)O

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC')

	IF (FOLDER_NUMBER.LT.0) RETURN)

	CALL OPEN_BULLFOLDER_SHARED			! Open folder filet

	CALL READ_FOLDER_FILE_KEYNAME(FOLDER,IER)

	CALL SYS_BINTIM(NEWEST_DATE//' '//NEWEST_TIME,F_NEWEST_BTIM)E

	F_NBULL = NBULL

	IF (FOLDER_NUMBER.EQ.0) FOLDER_FLAG = IBSET(FOLDER_FLAG,2)

	IF (.NOT.BTEST(SYSTEM,0)) THEN 	! Is non-system message?N
	   F_NEWEST_NOSYS_BTIM(1) = F_NEWEST_BTIM(1) ! If so, update latest
	   F_NEWEST_NOSYS_BTIM(2) = F_NEWEST_BTIM(2) ! system time.
	END IF_

	CALL REWRITE_FOLDER_FILE(IER)

	CALL CLOSE_BULLFOLDER

	RETURNU
	END



	SUBROUTINE SHOW_FOLDER 
CU
C  SUBROUTINE SHOW_FOLDER 
CS
C  FUNCTION: Shows the information on any folder. 
C	

	IMPLICIT INTEGER (A-Z)S

	INCLUDE 'BULLUSER.INC'

	INCLUDE 'BULLFOLDER.INC'D

	INCLUDE 'BULLDIR.INC'

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	COMMON /COMMAND_LINE/ INCMD
	CHARACTER*132 INCMD

	COMMON /BULL_PERM/ SET_PERM_FLAG,BRIEF_PERM_FLAG,NOTIFY_PERM_FLAG
	DIMENSION SET_PERM_FLAG(FLONG)E
	DIMENSION BRIEF_PERM_FLAG(FLONG) 
	DIMENSION NOTIFY_PERM_FLAG(FLONG)

	INCLUDE '($SSDEF)'_

	INCLUDE '($RMSDEF)'

	EXTERNAL CLI$_ABSENT,BULLETIN_SUBCOMMANDS

	IF (INDEX(INCMD,'/A').GT.0.OR.INDEX(INCMD,'/a').GT.0) THEN	
	   WRITE (6,'('' ERROR: /ALL is invalid qualifier.'')')
	   RETURN
	END IFl

	IF (CLI$GET_VALUE('SHOW_FOLDER',FOLDER1).EQ.%LOC(CLI$_ABSENT))S
     &	   THEN
	   FOLDER1 = FOLDER
	   IF (INDEX(FOLDER1,'.').GT.0) CALL LOWERCASE(FOLDER1)
	END IF

	IF (INDEX(FOLDER1,'::').NE.0) THEN 
 	   WRITE (6,'('' ERROR: invalid command for remote folder.'')')y
	   RETURN
	END IFE

	IF (TEST_NEWS(FOLDER1)) THEN              s
	   INCMD = 'SET NEWS 'B
	   IF (CLI$PRESENT('FULL')) INCMD = 'SET NEWS/FULL '	
	   IF (CLI$PRESENT('SHOW_FOLDER')) INCMD = 'SET NEWS '//FOLDER1
           CALL CLI$DCL_PARSE(INCMD,BULLETIN_SUBCOMMANDS).
	   CALL SHOW_NEWS
	   RETURN
        END IF

	CALL OPEN_BULLFOLDER_SHARED

	CALL READ_FOLDER_FILE_KEYNAME_TEMP(FOLDER1,IER)

	IF (IER.NE.0) THEN.
	   WRITE (6,'('' ERROR: Specified folder was not found.'')') 
	   CALL CLOSE_BULLFOLDERO
	   RETURN
	ELSE IF (FOLDER.EQ.FOLDER1) THENB
	   WRITE (6,1000) FOLDER1,FOLDER1_OWNER, 
     &			FOLDER1_DESCRIP(:TRIM(FOLDER1_DESCRIP))
	ELSE.
	   WRITE (6,1010) FOLDER1,FOLDER1_OWNER, 
     &			FOLDER1_DESCRIP(:TRIM(FOLDER1_DESCRIP))
	END IF(

	IF (CLI$PRESENT('FULL')) THEN
	   CALL SET_FOLDER_FILE(1) 
	   CALL CHKACLh
     &		 (FOLDER1_FILE(:TRIM(FOLDER1_FILE))//'.BULLFIL',IER)
	   IF (IER.EQ.(SS$_ACLEMPTY.OR.SS$_NORMAL).OR.(.NOT.IER)) THENo
	      IF (FOLDER1_BBOARD(:2).EQ.'::'.AND.	! Is folder remote'
     &		BTEST(FOLDER1_FLAG,0)) THEN		! and private? 
	         WRITE (6,'('' Access is limited.'')')I
	      END IFN
	   ELSE
	      IF (SETPRV_PRIV()) THEN
	         READ_ACCESS = 1'
		 WRITE_ACCESS = 1R
	      ELSEO
	        CALL CHECK_ACCESS
     &		  (FOLDER1_FILE(:TRIM(FOLDER1_FILE))//'.BULLFIL',H
     &		   USERNAME,READ_ACCESS,WRITE_ACCESS)U
	      END IF&
	      IF (WRITE_ACCESS)
     &	      CALL SHOWACL(FOLDER1_FILE(:TRIM(FOLDER1_FILE))//'.BULLFIL')
	   END IF
	   IF (FOLDER_ACCESS(USERNAME,FOLDER1_FLAG,FOLDER1_OWNER)) THEN
	      IF (FOLDER1_BBOARD(:2).EQ.'::') THENT
		 FLEN = TRIM(FOLDER1_BBOARD)
		 IF (INDEX(FOLDER1_BBOARD,'*').EQ.0) THEN
		    WRITE (6,'('' Folder is located on node '','
     &		     A,''.'')') FOLDER1_BBOARD(3:FLEN)
		 ELSE	
		    CALL SET_FOLDER_FILE(1)=
		    FOLDER_FILE = FOLDER1_FILE
		    REMOTE_SET_SAVE = REMOTE_SET
		    REMOTE_SET = .FALSE.
		    CALL OPEN_BULLDIR
		    CALL READDIR(0,IER)M
		    CALL CLOSE_BULLDIR
		    CALL SET_FOLDER_FILE(0)N
		    REMOTE_SET = REMOTE_SET_SAVE
		    WRITE (6,'('' Folder is located on node '','
     &		       A,''. Remote folder name is '',A,''.'')') e
     &		       FOLDER1_BBOARD(3:FLEN-1),
     &		       BULLDIR_HEADER(13:TRIM(BULLDIR_HEADER))
		 END IFI
	      ELSE IF (FOLDER1_BBOARD(:4).NE.'NONE') THEN
		 FLEN = TRIM(FOLDER1_BBOARD)
		 IF (FLEN.GT.0) THEN
 	          WRITE (6,'('' BBOARD for folder is '',A<FLEN>,''.'')')
     &		 	FOLDER1_BBOARD(:FLEN)E
		 END IFE
		 IF ((USERB1.EQ.0.AND.GROUPB1.EQ.0).OR.BTEST(USERB1,31)) THENt
 		  WRITE (6,'('' BBOARD was specified with /SPECIAL.'')')E
		  IF (BTEST(GROUPB1,31)) THENo
		   WRITE (6,'('' BBOARD was specified with /VMSMAIL.'')')
		  END IF
		 END IFD
	      ELSED
	         WRITE (6,'('' No BBOARD has been defined.'')')
	      END IFA
	      IF (FOLDER1_BBEXPIRE.GT.0) THEN
		 WRITE (6,'('' Default expiration is '',I3,'' days.'')')
     &			FOLDER1_BBEXPIREo
	      ELSE IF (FOLDER1_BBEXPIRE.EQ.-1) THEN
		 WRITE (6,'('' Default expiration is permanent.'')')
	      ELSEG
		 WRITE (6,'('' No default expiration set.'')')
	      END IF
	      IF (BTEST(FOLDER1_FLAG,2)) THEN
		 WRITE (6,'('' SYSTEM has been set.'')')
	      END IFE
	      IF (BTEST(FOLDER1_FLAG,1)) THEN
		 WRITE (6,'('' DUMP has been set.'')')
	      END IF
	      IF (BTEST(FOLDER1_FLAG,3)) THEN
		 WRITE (6,'('' NOPROMPT_EXPIRE has been set.'')')
	      END IF
	      IF (BTEST(FOLDER1_FLAG,4)) THEN
		 WRITE (6,'('' STRIP has been set.'')')+
	      END IF	
	      IF (BTEST(FOLDER1_FLAG,5)) THEN
		 WRITE (6,'('' DIGEST has been set.'')')
	      END IF0
	      IF (BTEST(FOLDER1_FLAG,7)) THEN
		 WRITE (6,'('' ALWAYS has been set.'')')
	      END IF 
	      IF (BTEST(FOLDER1_FLAG,10)) THENT
		 WRITE (6,'('' POST_ONLY has been set.'')')B
	      ELSE IF (BTEST(FOLDER1_FLAG,11)) THEN
		 WRITE (6,'('' ADD_ONLY has been set.'')')
	      END IF 
	      IF (BTEST(FOLDER1_FLAG,12)) THEN)
		 WRITE (6,'('' COMPRESS has been set.'')')
	      END IFU
	      IF (F1_EXPIRE_LIMIT.GT.0) THEN 
		 WRITE (6,'('' EXPIRATION limit is '',I3,'' days.'')')
     &			F1_EXPIRE_LIMIT
	      END IFL
	      CALL OPEN_BULLUSER_SHARED
	      CALL READ_USER_FILE_HEADER(IER)
	      CALL READ_PERM	
	      PERM = .FALSE.R
	      IF (TEST2(SET_FLAG_DEF,FOLDER1_NUMBER)) THENr
	       IF (TEST2(BRIEF_FLAG_DEF,FOLDER1_NUMBER)) THEN
	        IF (TEST2(BRIEF_PERM_FLAG,FOLDER1_NUMBER).AND.E
     &		    TEST2(SET_PERM_FLAG,FOLDER1_NUMBER)) THEN0
	         PERM = .TRUE.'
		 WRITE (6,'('' Default is BRIEF, which is permanent.'')')o
		ELSE
		 WRITE (6,'('' Default is BRIEF.'')')A
		END IF
	       ELSE
	        IF (TEST2(SET_PERM_FLAG,FOLDER1_NUMBER).AND.'
     &		    .NOT.TEST2(BRIEF_PERM_FLAG,FOLDER1_NUMBER)) THEN
	         PERM = .TRUE.F
		 WRITE (6,'('' Default is READNEW, which is permanent.'')')3
		ELSE
		 WRITE (6,'('' Default is READNEW.'')')G
		END IF
	       END IF
	      ELSE.
	       IF (TEST2(BRIEF_FLAG_DEF,FOLDER1_NUMBER)) THEN
	        IF (TEST2(BRIEF_PERM_FLAG,FOLDER1_NUMBER).AND.)
     &		    .NOT.TEST2(SET_PERM_FLAG,FOLDER1_NUMBER)) THEN
	         PERM = .TRUE. 
		 WRITE (6,'('' Default is SHOWNEW, which is permanent.'')')E
		ELSE
		 WRITE (6,'('' Default is SHOWNEW.'')')A
		END IF
	       END IF
	      END IFN
	      IF (.NOT.PERM) THEN
	        IF (TEST2(BRIEF_PERM_FLAG,FOLDER1_NUMBER).AND.s
     &		    TEST2(SET_PERM_FLAG,FOLDER1_NUMBER)) THEN
		   WRITE (6,'('' BRIEF is the permanent setting.'')')y
	        ELSE IF (TEST2(SET_PERM_FLAG,FOLDER1_NUMBER).AND.
     &		    .NOT.TEST2(BRIEF_PERM_FLAG,FOLDER1_NUMBER)) THEN
		   WRITE (6,'('' READNEW is the permanent setting.'')') 
	        ELSE IF (TEST2(BRIEF_PERM_FLAG,FOLDER1_NUMBER).AND.
     &		    .NOT.TEST2(SET_PERM_FLAG,FOLDER1_NUMBER)) THEN
		   WRITE (6,'('' SHOWNEW is the permanent setting.'')') 
	        END IF	
	      END IFE
	      IF (TEST2(NOTIFY_FLAG_DEF,FOLDER1_NUMBER)) THEN
	        IF (TEST2(NOTIFY_PERM_FLAG,FOLDER1_NUMBER)) THEN(
		 WRITE (6,'('' Default is NOTIFY, which is permanent.'')')
		ELSE
		 WRITE (6,'('' Default is NOTIFY.'')')
		END IF
	      ELSE 
		 WRITE (6,'('' Default is NONOTIFY.'')')
	      END IF 
	      CALL CLOSE_BULLUSER
	   END IF
	END IFO

	CALL CLOSE_BULLFOLDER

	RETURNN

1000	FORMAT(' Current folder: ',A44,' Owner: ',A12,/,e
     &		' Description: ',A)I
1010	FORMAT(' Folder name is: ',A44,' Owner: ',A12,/,E
     &		' Description: ',A)L
	END


	SUBROUTINE DIRECTORY_FOLDERS(FOLDER_COUNT)D
C!
C  SUBROUTINE DIRECTORY_FOLDERSF
CE
C  FUNCTION: Display all FOLDER entries.
CM
	IMPLICIT INTEGER (A - Z)I

	INCLUDE '($SSDEF)'F

	INCLUDE 'BULLFOLDER.INC'_

	INCLUDE 'BULLUSER.INC'I

	INCLUDE 'BULLDIR.INC'

	COMMON /PAGE/ PAGE_LENGTH,PAGE_WIDTH,PAGING
	LOGICAL PAGINGE

	COMMON /CTRLC_FLAG/ FLAG_

	COMMON /LAST_BUFFER/ OLD_BUFFER
	CHARACTER*(INPUT_LENGTH) OLD_BUFFER

	DATA SCRATCH_D1/0/D

	CHARACTER FOLDER_MATCH*80,DATETIME*20,FSTATUS1*4,NEWS_ACCESS*132 

	INTEGER*2 MLEN,FLEN

	OLD_BUFFER = ' '

	IF (CLI$PRESENT('NEWS')) THEN
	   IF (SYS_TRNLNM('BULL_NEWS_SERVER','DEFINED')) THEN
	      CALL OPEN_BULLNEWS_SHARED
	   ELSE
	      WRITE (6,'('' ERROR: NEWS connection is not present.'')')
	      RETURNR
	   END IF
	ELSEE
	   CALL OPEN_BULLFOLDER_SHARED		! Get folder file
	END IF1

	IF (FOLDER_COUNT.EQ.0) THEN
	   SUBSCRIBE = .FALSE.F
	   ACTIVE = .FALSE. D
	   STORED = .FALSE. F
	   CLASS = .FALSE.I
	   NEW = .FALSE. 
	   FOLDER_COUNT = 1			! Init folder number counterS
	   NLINE = 1U
	   START = .FALSE.T
	   IF (.NOT.CLI$PRESENT('NEWS')) THEN
	      NEWS = .FALSE.)
	      IF (CLI$PRESENT('DESCRIBE')) THEN
	         NLINE = 2	! Include folder descriptor if /DESCRIBE
	      END IF
	   ELSE
	      NEWS = .TRUE.
	      CALL READ_FOLDER_FILE_KEYNAME_TEMP('a',IER)
	      IF (IER.NE.0) THENF
		 WRITE (6,'('' Fetching NEWS groups from remote node.''
     &			,''  This will take several minutes.'')')
		 WRITE (6,'('' This is the only time this will have''
     &			,'' to be done.'')')S
	         CALL CLOSE_BULLFOLDER 
		 CALL NEWS_LISTT
	         CALL OPEN_BULLNEWS_SHARED)
	         CALL READ_FOLDER_FILE_KEYNAME_TEMP('a',IER)O
	      END IF 
	      COUNT = CLI$PRESENT('COUNT') 
	      IF (COUNT) TOTAL_COUNT = 0M
	      STORED = CLI$PRESENT('STORED')
	      SUBSCRIBE = CLI$PRESENT('SUBSCRIBE')D
	      NEW = CLI$PRESENT('NEWGROUPS')(
	      CLASS = CLI$PRESENT('CLASS')
	      IF (CLASS) CALL READ_FOLDER_FILE_KEYNAMEGE_TEMP('A',IER) 
	      IF (NEW) THEN
		 NEW_NEWS = MAX(LAST_NEWS_READ(1,FOLDER_MAX),1000)
	      ELSE IF (SUBSCRIBE) THENO
		 CALL NEWS_GET_SUBSCRIBE(0,F1_COUNT)
		 SUBNUM = 1)
	      ELSE 
	         ACTIVE = .NOT.CLI$PRESENT('ALL')
	      END IFS
	   END IF
	   IF (CLI$GET_VALUE('START',FOLDER1,FLEN)) THENL
	      IF (NEWS) CALL LOWERCASE(FOLDER1)
	      CALL READ_FOLDER_FILE_KEYNAMEGE_TEMP(FOLDER1(:FLEN),IER)L
	      IF (IER.NE.0) THEN(
		 WRITE (6,'('' There are no folders.'')')E
	         CALL CLOSE_BULLFOLDER.
		 FOLDER_COUNT = -1
		 RETURN
	      ELSE(
		 START = .TRUE.E
	      END IFe
	   END IF
	   MATCH = CLI$GET_VALUE('MATCH_FOLDER',FOLDER_MATCH,MLEN) 
	   IF (MATCH.AND.NEWS) CALL LOWERCASE(FOLDER_MATCH)
	   IF (MATCH.AND.INDEX(FOLDER_MATCH,'*').EQ.0) THEN
	      FOLDER_MATCH = '*'//FOLDER_MATCH(:MLEN)//'*'O
	      MLEN = MLEN + 2
	   END IF
	ELSE IF (NEWS.AND.COUNT.AND.TOTAL_COUNT.LT.0) THEN&
	   WRITE (6,'('' The total count is: '',I)') -TOTAL_COUNT
	   TOTAL_COUNT = 0F
	   FOLDER_COUNT = -1 
	   RETURN
	ELSE IF (SUBSCRIBE.AND.PAGING.AND.MORE) THEN_
	   SUBNUM = -2 
	ELSEF
	   CALL READ_FOLDER_FILE_KEYNAME_TEMP(FOLDER1,IER)E
	END IF)

CI
C  Folder listing is first buffered into temporary memory storage before
C  being outputted to the terminal.  This is to be able to quickly close the
C  folder file, and to avoid the possibility of the user holding the screen,
C  and thus causing the folder file to stay open.  The temporary memoryI
C  is structured as a linked-list queue, where SCRATCH_D1 points to the header
C  of the queue.
CE
	CALL INIT_QUEUE(SCRATCH_D1,FOLDER1_COM)
	SCRATCH_D = SCRATCH_D1d

	CALL DECLARE_CTRLC_AST.

	NUM_FOLDER = 0 
	IER = 0
	IER1 = 0 
	MORE = .FALSE.E
	NEWS_TEST = MATCH.OR.ACTIVE.OR.STORED
	DO WHILE (IER.EQ.0.AND.IER1.EQ.0)
	   IF (SUBSCRIBE) THEN 
	      IER = 1
	      DO WHILE (SUBNUM.NE.0.AND.IER.NE.0)
	         CALL NEWS_GET_SUBSCRIBE(SUBNUM,MSGNUM)
		 IF (SUBNUM.NE.0) THEN
	            CALL READ_FOLDER_FILE_KEYNUM_TEMP(SUBNUM,IER)
		    IF (IER.NE.0) SUBNUM = -1.
		 END IF.
	      END DOU
	      F1_COUNT = MSGNUM
	      IF (SUBNUM.EQ.0) IER = 1i
	   ELSE IF (START) THEN
	      START = .FALSE.
	   ELSE IF (NEW) THEN
	      IER = 2
	      DO WHILE (IER.EQ.2)
	         CALL READ_FOLDER_FILE_KEYNUM_GT_TEMP(NEW_NEWS,IER)
		 IF (IER.EQ.0.AND.BTEST(FOLDER1_FLAG,10)) THEN
		    IER = 21
	            NEW_NEWS = FOLDER1_NUMBER
	         END IF
	      END DOs
	      IF (IER.EQ.0) THENE
	         NEW_NEWS = FOLDER1_NUMBERI
	      ELSEN
	         CALL READ_FOLDER_FILE_KEYNAME_TEMP('a',IER2)
	         NEW_NEWS = NEWS_F1_COUNT
	      END IFi
	   ELSE
	      CALL READ_FOLDER_FILE_TEMP(IER)
	      IF (CLASS) CALL LOWERCASE(FOLDER1_DESCRIP)n
	      IF (CLASS) NEWS_TEST = .FALSE.B
	      IF (CLASS.AND.FOLDER1.EQ.'a') IER = 2
	   END IF
	   IF (IER.EQ.0) THEN
	      IF ((INDEX(FOLDER1_BBOARD,'::').EQ.0.OR.NEWS).AND.'
     &		  BTEST(FOLDER1_FLAG,0).AND..NOT.SETPRV_PRIV()) THEN
		 CALL SET_FOLDER_FILE(1)
	         IF (NEWS) THEN
	            IF (OLD_BUFFER.NE.NEWS_ACCESS(FOLDER1_DESCRIP)) THEN,
	               OLD_BUFFER = NEWS_ACCESS(FOLDER1_DESCRIP) 
		       CALL CHKACL(OLD_BUFFER(:TRIM(OLD_BUFFER)),IER2)
	   	       IF (IER2.NE.(SS$_ACLEMPTY.OR.SS$_NORMAL)) THEN
	                  CALL CHECK_ACCESS(OLD_BUFFER(:TRIM(OLD_BUFFER)), 
     &		           USERNAME,READ_ACCESS,-1)G
                       ELSEA
                          READ_ACCESS = 1
                       END IF2
	            END IF,
	         ELSE
	            CALL CHECK_ACCESS
     &		     (FOLDER1_FILE(:TRIM(FOLDER1_FILE))//'.BULLFIL',
     &		      USERNAME,READ_ACCESS,-1)
	         END IF
	      ELSEE
		 READ_ACCESS = 1
	      END IFH
	      IF (READ_ACCESS) THEN
	         J = INDEX(FOLDER1_DESCRIP,' ')
	         IF (J.GT.0) THEN
	            FSTATUS1(:1) = FOLDER1_DESCRIP(J+1:) 
		 ELSEE
	            FSTATUS1 = ' 'M
	         END IF
		 IF (.NOT.NEWS_TEST) THENF
		    IF (NEWS.AND.CLASS) 
     &			FOLDER1_DESCRIP = FOLDER1_DESCRIP(:J-2)
	            NUM_FOLDER = NUM_FOLDER + 1
	            CALL WRITE_QUEUE(%VAL(SCRATCH_D),SCRATCH_D,FOLDER1_COM)
		 ELSE IF ((.NOT.ACTIVE.OR.(FSTATUS1(:1).NE.'x'.AND..NOT.
     &			   BTEST(FOLDER1_FLAG,9))).AND.
     &	                  (.NOT.STORED.OR.BTEST(FOLDER1_FLAG,8)).AND.
     &			(.NOT.MATCH.OR.STR$MATCH_WILD(FOLDER1_DESCRIP
     &		        (:TRIM(FOLDER1_DESCRIP)),FOLDER_MATCH(:MLEN)))) THEN
		    GO TO 100 
	         END IF
	      END IF
	      IF (PAGING.AND.NUM_FOLDER*NLINE+2.GT.PAGE_LENGTH-4) THENI
		 IER1 = 1F
		 MORE = .TRUE.
	      END IF
	   END IF
	   IF (FLAG.EQ.1) IER1 = 1E
	END DO)

 	IF (NEWS_TEST) NEWS_TEST = .FALSE.

	CALL CANCEL_CTRLC_AST
	CALL CLOSE_BULLFOLDER			! We don't need file anymore'

 	IF (FLAG.EQ.1) THENA
	   WRITE (6,'('' Folder search aborted.'')') 
	   FOLDER_COUNT = -1
	   RETURN
	END IFI

	IF (NUM_FOLDER.EQ.0) THEN
	   WRITE (6,'('' There are no folders.'')')
	   FOLDER_COUNT = -1I
	   IF (NEW) LAST_NEWS_READ(1,FOLDER_MAX) = NEW_NEWS
	   RETURN
	END IFE

CM
C  Folder entries are now in queue.  Output queue entries to screen.
C1

     	SCRATCH_D = SCRATCH_D1			! Init queue pointer to headern

100	CALL LIB$ERASE_PAGE(1,1)		! Clear the screen

	IF (.NOT.NEWS) THEN
	   WRITE (6,'(1X,''Folder'',22X,''Last message'',7X,''Messages'',
     &		2X,''Owner'',/,1X,80(''-''))')
	ELSE IF (COUNT) THEN	
	   WRITE (6,'(1X,''Folder'',<PAGE_WIDTH-80+43>X,6X,
     &		''First        Last  Count'',N
     &		/,1X,<PAGE_WIDTH>(''-''))')(
	ELSE IF (CLASS) THENu
	   WRITE (6,'(1X,''Class'',/,1X,<PAGE_WIDTH>(''-''))')(
	ELSED
	   WRITE (6,'(1X,''Folder'',<PAGE_WIDTH-80+43>X,''Status'',7X,D
     &		''First        Last'',/,1X,<PAGE_WIDTH>(''-''))')_
	END IF

	IF (PAGING.AND.MORE) NUM_FOLDER = NUM_FOLDER - 1T

	I = 1
	DO WHILE ((I.LE.NUM_FOLDER.OR.NEWS_TEST).AND.FLAG.NE.1)
	   IF (.NOT.NEWS_TEST) THEN
	      CALL READ_QUEUE(%VAL(SCRATCH_D),SCRATCH_D,FOLDER1_COM)e
	      I = I + 1
	   END IF
	   IF (.NOT.NEWS) THENR
	      DIFF = COMPARE_BTIM
     &			(LAST_READ_BTIM(1,FOLDER1_NUMBER+1),F1_NEWEST_BTIM)
	      IF (F1_NBULL.GT.0) THEN
	         CALL SYS$ASCTIM(,DATETIME,F1_NEWEST_BTIM,)
	      ELSE
	         DATETIME = '      NONE'E
	      END IF
	      IF (DIFF.GE.0.OR.F1_NBULL.EQ.0) THENG
	         WRITE (6,1000) ' '//FOLDER1,DATETIME(:17),F1_NBULL,S
     &							FOLDER1_OWNER
	      ELSEE
	         WRITE (6,1000) '*'//FOLDER1,DATETIME(:17),F1_NBULL,A
     &							FOLDER1_OWNER
	      END IF3
	   ELSE
	      FLEN = MIN(80,PAGE_WIDTH-80+49)
	      IF (SUBSCRIBE) FLEN = MIN(81,PAGE_WIDTH-80+48)U
	      J = INDEX(FOLDER1_DESCRIP,' ') 
	      IF (J.GT.0) THEND
	         FSTATUS1(:1) = FOLDER1_DESCRIP(J+1:)
		 IF (FSTATUS1(:1).NE.'=') THEN
                    FOLDER1_DESCRIP = FOLDER1_DESCRIP(:J-1)E
                 END IFD
	      ELSEF
	         FSTATUS1 = ' '
	      END IFF
	      IF (BTEST(FOLDER1_FLAG,9)) FSTATUS1 = 'n'
	      IF (COUNT) THEN
		 TOTAL_COUNT = TOTAL_COUNT + F1_COUNT=
	         IF (F1_START.LE.F1_NBULL) THEN
		    WRITE (6,1010) FOLDER1_DESCRIP(:FLEN),
     &					 F1_START,F1_NBULL,F1_COUNT
	         ELSE
		    WRITE (6,1010) FOLDER1_DESCRIP(:FLEN),0,0,0 
		 END IFd
              ELSE IF (CLASS) THEN
                 WRITE (6,1010) FOLDER1_DESCRIP(:FLEN)
	      ELSE IF (F1_START.LE.F1_NBULL) THEN
		 IF (SUBSCRIBE) THEN
		    IF (F1_COUNT.LT.F1_NBULL.AND.F1_NBULL.GT.0) THEN
	               WRITE (6,1005) '*'//FOLDER1_DESCRIP(:FLEN-1),I
     &					FSTATUS1(:1),F1_START,F1_NBULLh
		    ELSE
	               WRITE (6,1005) ' '//FOLDER1_DESCRIP(:FLEN-1),	
     &					 FSTATUS1(:1),F1_START,F1_NBULL
		    END IF
		 ELSEA
		    WRITE (6,1005) FOLDER1_DESCRIP(:FLEN),
     &					 FSTATUS1(:1),F1_START,F1_NBULL
		 END IF 
	      ELSE IF (SUBSCRIBE) THEN 
	         WRITE (6,1005) ' '//FOLDER1_DESCRIP(:FLEN-1),C
     &					FSTATUS1(:1),0,0 
	      ELSEP
		 WRITE (6,1005) FOLDER1_DESCRIP(:FLEN),FSTATUS1(:1),0,0
	      END IFS
	   END IF
	   IF (NLINE.EQ.2) WRITE (6,'(1X,A)') FOLDER1_DESCRIP
	   LAST_DISPLAY = FOLDER1_NUMBERD
	   IF (NEWS_TEST.AND.FLAG.NE.1) THENU
	      NUM_FOLDER = NUM_FOLDER + 1
	      IF (PAGING.AND.
     &		  NUM_FOLDER*NLINE+2.GE.PAGE_LENGTH-4) MORE = .TRUE.
	      FOUND = .FALSE.
	      DO WHILE (FLAG.NE.1.AND.IER.EQ.0.AND..NOT.FOUND)T
	         CALL READ_FOLDER_FILE_TEMP(IER)R
	         J = INDEX(FOLDER1_DESCRIP,' ')
	         IF (J.GT.0) THEN
	            FSTATUS1(:1) = FOLDER1_DESCRIP(J+1:)a
		 ELSEd
	            FSTATUS1 = ' 'O
	         END IF
		 IF (IER.EQ.0.AND.(.NOT.ACTIVE.OR.(FSTATUS1(:1).NE.'x'.AND.E
     &			   .NOT.BTEST(FOLDER1_FLAG,9))).AND.E
     &	                  (.NOT.STORED.OR.BTEST(FOLDER1_FLAG,8)).AND.
     &			(.NOT.MATCH.OR.STR$MATCH_WILD(FOLDER1_DESCRIP
     &		        (:TRIM(FOLDER1_DESCRIP)),FOLDER_MATCH(:MLEN)))) THEN
		    IF (BTEST(FOLDER1_FLAG,0)) THENN
	               IF (OLD_BUFFER.NE.NEWS_ACCESS(FOLDER1_DESCRIP)) THEN
	                  OLD_BUFFER = NEWS_ACCESS(FOLDER1_DESCRIP)
		          CALL CHKACL(OLD_BUFFER(:TRIM(OLD_BUFFER)),IER2)R
	   	          IF (IER2.NE.(SS$_ACLEMPTY.OR.SS$_NORMAL)) THENA
	                     CALL CHECK_ACCESS(OLD_BUFFER
     &		              (:TRIM(OLD_BUFFER)),USERNAME,FOUND1,-1)m
                          ELSE
                             FOUND1 = .TRUE.
	                  END IFl
                       END IFi
	               FOUND = FOUND1
		    ELSE
		       FOUND = .TRUE.r
	            END IFT
		 END IFy
	      END DO 
	      MORE = MORE.AND.FOUND
	      IF (MORE) THENo
		 CALL READ_FOLDER_FILE_KEYNUM_TEMP(LAST_DISPLAY,IER)
              END IF
	      FOUND = FOUND.AND..NOT.MORE
	      IF (.NOT.FOUND) FLAG = 1L
	   END IF
	END DOI

	IF (NEWS_TEST) THEN
	   CALL CANCEL_CTRLC_ASTC
	   CALL CLOSE_BULLFOLDERI
	END IFN

	IF (IER.NE.0.AND..NOT.MORE) THEN	! Outputted all entries?
	   IF (NEWS.AND.COUNT) THEN
	      TOTAL_COUNT = -TOTAL_COUNTS
	   ELSE
	      FOLDER_COUNT = -1			! Yes. Set counter to -1.
	   END IF
	   IF (NEW) LAST_NEWS_READ(1,FOLDER_MAX) = NEW_NEWS
	ELSE-
	   WRITE(6,1100)			! Else say there are more 
	   IF (NEW) LAST_NEWS_READ(1,FOLDER_MAX) = FOLDER1_NUMBER
	END IF

	RETURNT

1000	FORMAT(1X,A26,2X,A17,2X,I8,2X,A12)I
1005	FORMAT(1X,A<FLEN>,<PAGE_WIDTH-FLEN-29-1>X,2X,A1,4X,I10,'  ',I10)N
1010	FORMAT(1X,A<FLEN>,<PAGE_WIDTH-FLEN-29-1>X,I10,2X,I10,1X,I6)
1100	FORMAT(1X,/,' Press RETURN for more...',/) 

	END


	SUBROUTINE SET_ACCESS(ACCESS)
Cs
C  SUBROUTINE SET_ACCESS
C
C  FUNCTION: Set access on folder for specified ID. 
C 
C  PARAMETERS:
C	ACCESS  -  Logical: If .true., grant access, if .false. deny access 
C 

	IMPLICIT INTEGER (A-Z)C

	INCLUDE 'BULLFOLDER.INC')

	INCLUDE 'BULLUSER.INC'W

	INCLUDE '($SSDEF)'n

	INCLUDE '($RMSDEF)'

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	LOGICAL ACCESS,ALL,READONLY

	EXTERNAL CLI$_ABSENTI

	CHARACTER ID*64,RESPONSE*4,NEW_NEWS_ACCESS*132

	CHARACTER INPUT*132

	IF (CLI$PRESENT('ALL')) THENH
	   ALL = .TRUE.
	ELSEL
	   ALL = .FALSE.(
	END IFN

	IF (CLI$PRESENT('READONLY')) THEN
	   READONLY = .TRUE.)
	ELSE
	   READONLY = .FALSE.
	END IF_

	IF (ALL) THEN
	   IER = CLI$GET_VALUE('ACCESS_ID',FOLDER1,LEN) ! Get folder name
	ELSE 
	   IER = CLI$GET_VALUE('ACCESS_FOLDER',FOLDER1,LEN) ! Get folder name
	END IFC

	IF (IER.EQ.%LOC(CLI$_ABSENT)) FOLDER1 = FOLDER 
	NEWS = INDEX(FOLDER1,'.').GT.0 

	IF (NEWS) THEN 
	   IF (.NOT.CLI$PRESENT('CLASS')) THENC
	      CALL LOWERCASE(FOLDER1)
	   ELSE IF (FOLDER1(TRIM(FOLDER1):TRIM(FOLDER1)).NE.'.') THEN
	      FOLDER1 = FOLDER1(:TRIM(FOLDER1))//'.'M
	   END IF
	   CALL OPEN_BULLNEWS
	ELSE 
	   CALL OPEN_BULLFOLDER		! Open folder file
	END IFE
	CALL READ_FOLDER_FILE_KEYNAME_TEMP(FOLDER1,IER)	! See if it exists 
	OLD_FOLDER1_FLAG = FOLDER1_FLAG
	CALL CLOSE_BULLFOLDER

	IF (IER.NE.0) THENF
	   WRITE (6,'('' ERROR: No such folder exists.'')')
	ELSE IF (.NOT.FOLDER_ACCESS(USERNAME,FOLDER1_FLAG,FOLDER1_OWNER)) THEN	
	   WRITE (6,D
     &	'('' ERROR: You are not able to modify access to the folder.'')')
	ELSE IF (CLI$PRESENT('CLASS').AND..NOT.BTEST(FOLDER1_FLAG,0)) THENH
	   WRITE (6,'('' ERROR: Must use SET NEWS/CLASS/PRIVATE.'')')
	ELSEE
	   CALL SET_FOLDER_FILE(1)T
	   IF (NEWS) THEN
	      CALL CHKACL(NEW_NEWS_ACCESS(FOLDER1_DESCRIP),IER)
	   ELSE
	      CALL CHKACL
     &		 (FOLDER1_FILE(:TRIM(FOLDER1_FILE))//'.BULLFIL',IER)
	   END IF
	   IF (NEWS.AND.IER.EQ.RMS$_FNF) THEN
	     CALL SET_PROTECTION 
	     OPEN (UNIT=3,FILE=NEW_NEWS_ACCESS(FOLDER1_DESCRIP),N
     &			STATUS='NEW',IOSTAT=IER)I
	     CLOSE (UNIT=3)
	     CALL RESET_PROTECTION 
	     IF (IER.NE.0) THEN
	        WRITE (6,'('' ERROR: Access file cannot be created.'')')A
	        RETURNC
	     END IF
	     CALL ADD_ACL('*','NONE',IER)
	     IF (.NOT.IER) THEN
		WRITE(6,'('' Cannot modify access.'')').
		CALL SYS_GETMSG(IER)
		RETURN
	     END IF
	   ELSE IF (IER.EQ.RMS$_FNF) THEN
	     FOLDER_FILE = FOLDER1_FILE
	     REMOTE_SET_SAVE = REMOTE_SET
	     REMOTE_SET = .FALSE.
	     CALL OPEN_BULLFIL
	     CALL CLOSE_BULLFIL
	     REMOTE_SET = REMOTE_SET_SAVE
	     IER = SS$_ACLEMPTY.OR.SS$_NORMAL
	     CALL SET_FOLDER_FILE(0)	
	   END IF
	   IF (IER.EQ.(SS$_ACLEMPTY.OR.SS$_NORMAL)) THEN)
	     IF (.NOT.NEWS.AND.
     &		 ((ALL.AND..NOT.READONLY).OR.(.NOT.ACCESS))) THEN 
	        WRITE (6,'('' ERROR: Folder is not a private folder.'')')
		RETURN
	     END IF
	     CALL GET_INPUT_PROMPT(RESPONSE,LEN,'Access is presently'
     &		//' unlimited. Do you want to change this? (Y/N): ')
	     IF (RESPONSE(:1).NE.'y'.AND.RESPONSE(:1).NE.'Y') THENX
	       WRITE (6,'('' Access was not changed.'')')
	       RETURN
	     ELSE
	       FOLDER1_FLAG = IBSET(FOLDER1_FLAG,0)
	       IF (READONLY.AND.ALL) THEN
	          CALL ADD_ACL('*','R',IER)
	       ELSE IF (.NOT.ALL) THEN
	          CALL ADD_ACL('*','NONE',IER).
	       END IF
	       IF (.NOT.NEWS) CALL ADD_ACL(FOLDER1_OWNER,'R+W+C',IER)
	       IF (ALL) THEN		! All finished, so exit
	        WRITE (6,'('' Access to folder has been modified.'')')
		GOTO 100
	       END IF
	     END IF
	   END IF

	   IF (ALL) THEN_
	      IF (ACCESS) THEN 
		 CALL DEL_ACL(' ','R+W',IER)
	         IF (READONLY) THEN
	            CALL ADD_ACL('*','R',IER)
	         ELSE IF (.NOT.NEWS) THEN
		    FOLDER1_FLAG = IBCLR(FOLDER1_FLAG,0)
	   	    IF (.NOT.NEWS.AND.REMOTE_SET) THEN&
		       CALL SET_FOLDER_FILE(1)
		       FOLDER_FILE = FOLDER1_FILER
		       REMOTE_SET_SAVE = REMOTE_SET	
		       REMOTE_SET = .FALSE.
		       CALL OPEN_BULLDIR
		       CALL OPEN_BULLFIL
		       CALL CLOSE_BULLFIL_DELETE
		       CALL CLOSE_BULLDIR_DELETE
		       REMOTE_SET = REMOTE_SET_SAVEE
		       CALL SET_FOLDER_FILE(0)
		    END IF
		 END IFF
	      ELSEE
		 CALL DEL_ACL('*','R',IER)
	      END IFI
	      IF (.NOT.IER) THEN
		 WRITE(6,'('' Cannot modify access.'')')
		 CALL SYS_GETMSG(IER) 
	      END IF 
	   END IF

	   DO WHILE (CLI$GET_VALUE('ACCESS_ID',INPUT,ILEN)N
     &	    .NE.%LOC(CLI$_ABSENT).AND..NOT.ALL)
	      IER = SYS_TRNLNM(INPUT,INPUT)
	      IF (INPUT(:1).EQ.'@') THENP
		 ILEN = INDEX(INPUT,',') - 1
		 IF (ILEN.EQ.-1) ILEN = TRIM(INPUT) 
		 OPEN (UNIT=3,STATUS='OLD',FILE=INPUT(2:ILEN),
     &			DEFAULTFILE='.DIS',IOSTAT=IER)N
		 IF (IER.NE.0) THENE
		    WRITE (6,'('' ERROR: Cannot find file '',A)')S
     &					INPUT(2:ILEN)
		    RETURN
		 END IF 
		 READ (3,'(A)',IOSTAT=IER) INPUT
		 IF (IER.NE.0) THEN 
		    CLOSE (UNIT=3)
		    INPUT = ' 'I
		 ELSE)
		    FILE_OPEN = .TRUE.
		 END IFF
	      ELSE 
		 FILE_OPEN = .FALSE.
	      END IF'
	      DO WHILE (TRIM(INPUT).GT.0)
	         COMMA = INDEX(INPUT,',')
		 IF (INPUT(:1).EQ.'[') COMMA = INDEX(INPUT,']') + 11
		 IF (INPUT(:1).EQ.'"') COMMA = INDEX(INPUT(2:),'"') + 2L
	         IF (COMMA.GT.0) THEN
		    ID = INPUT(1:COMMA-1)T
		    INPUT = INPUT(COMMA+1:)(
	         ELSE
		    ID = INPUT
		    INPUT = ' 'P
	         END IF
	         ILEN = TRIM(ID)T
	         IF (.NOT.NEWS.AND.ID.EQ.FOLDER1_OWNER) THENN
	            WRITE (6,'('' ERROR: Cannot modify access'',Y
     &			       '' for owner of folder.'')')
		 ELSEE
		    IF (ACCESS) THEN
	               IF (READONLY) THEN
	                  CALL ADD_ACL(ID,'R',IER)T
		       ELSEU
	                  CALL ADD_ACL(ID,'R+W',IER)A
		       END IF.
	            ELSE
	               CALL DEL_ACL(ID,'R+W',IER)
	               IF (.NOT.IER) CALL DEL_ACL(ID,'R',IER)
	            END IF 
	            IF (.NOT.IER) THENI
		       WRITE(6,'('' Cannot modify access for '',A,
     &					''.'')') ID(:ILEN)N
		       CALL SYS_GETMSG(IER).
		    ELSE
		       WRITE(6,'('' Access modified for '',A,''.'')') 
     &				ID(:ILEN)T
		    END IF
		 END IFF
	         IF (TRIM(INPUT).EQ.0.AND.FILE_OPEN) THEN
		    READ (3,'(A)',IOSTAT=IER) INPUTM
		    IF (IER.NE.0) THEN
		       CLOSE (UNIT=3) 
		       INPUT = ' '
		       FILE_OPEN = .FALSE.
		    END IF
		 END IFC
	      END DOC
	   END DO
	   
100	   IF (OLD_FOLDER1_FLAG.NE.FOLDER1_FLAG) THENI
	      IF (NEWS) THENK
	         CALL OPEN_BULLNEWS
	      ELSE 
	         CALL OPEN_BULLFOLDER
	      END IFO
	      OLD_FOLDER1_FLAG = FOLDER1_FLAG
	      CALL READ_FOLDER_FILE_KEYNAME_TEMP(FOLDER1,IER)
	      FOLDER1_FLAG = OLD_FOLDER1_FLAG
	      CALL REWRITE_FOLDER_FILE_TEMP(IER) 
	      CALL CLOSE_BULLFOLDER
	   END IF
	END IFI

	RETURN 

	END



	SUBROUTINE CHKACL(FILENAME,IERACL)N
C
C  SUBROUTINE CHKACL
CD
C  FUNCTION: Checks ACL of given file.
Cy
C  PARAMETERS:
C	FILENAME - Name of file to check. 
C	IERACL   - Error returned for attempt to open file.L
C_

	IMPLICIT INTEGER (A-Z) 

	CHARACTER*(*) FILENAMED

	INCLUDE '($ACLDEF)'
	INCLUDE '($SSDEF)' 

	CHARACTER*256 ACLENT,ACLSTR

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

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

	IF (IERACL.EQ.SS$_ACLEMPTY) THENe
	   IERACL = SS$_NORMAL.OR.IERACLF
	END IFS

	RETURN(
	END



	SUBROUTINE CHECK_ACCESS(FILENAME,USERNAME,READ_ACCESS,WRITE_ACCESS)
C 
C  SUBROUTINE CHECK_ACCESS
CR
C  FUNCTION: Checks ACL of given file.
CT
C  PARAMETERS:
C	FILENAME - Name of file to check.R
C	USERNAME - Name of user to check access for.
C	READ_ACCESS - Error returned indicating read access.
C	WRITE_ACCESS - Error returned indicating write access.
C		       If initially set to -1, indicates just
C		       folder for read access.C
CS

	IMPLICIT INTEGER (A-Z)s

	CHARACTER FILENAME*(*),USERNAME*(*),ACE*256,OUTPUT*80

	INCLUDE '($ACLDEF)'
	INCLUDE '($CHPDEF)'
	INCLUDE '($ARMDEF)'

	CALL INIT_ITMLST	! Initialize item list
	CALL ADD_2_ITMLST(4,CHP$_FLAGS,%LOC(FLAGS))
	CALL ADD_2_ITMLST(4,CHP$_ACCESS,%LOC(ACCESS))
	CALL ADD_2_ITMLST(LEN(ACE),CHP$_MATCHEDACE,%LOC(ACE))
	CALL END_ITMLST(ACL_ITMLST)	! Get address of itemlist

	FLAGS = 0		! Default is no access

	ACCESS = ARM$M_READ	! Check if user has read access
	READ_ACCESS=SYS$CHECK_ACCESS(ACL$C_FILE,FILENAME,USERNAME,I
     &		%VAL(ACL_ITMLST))D


	IF (ICHAR(ACE(:1)).NE.0) THEN
	   CALL SYS$FORMAT_ACL(ACE,,OUTPUT,,,,)
	   IF (INDEX(OUTPUT,'=*').NE.0.AND.
     &		INDEX(OUTPUT,'READ').EQ.0) READ_ACCESS = 0
	ELSE IF (ICHAR(ACE(:1)).EQ.0.AND.READ_ACCESS) THEN,
	   READ_ACCESS = 0e
	END IFC

	IF (WRITE_ACCESS.EQ.-1) THEN	! Only check read access
	   RETURN
	ELSE IF (READ_ACCESS.EQ.0) THEN	! If no read access, then of'
	   WRITE_ACCESS = 0		! course there is no write access.
	   RETURN
	END IFR

	ACCESS = ARM$M_WRITE	! Check if user has write access
	WRITE_ACCESS=SYS$CHECK_ACCESS(ACL$C_FILE,FILENAME,USERNAME,
     &		%VAL(ACL_ITMLST))R

	IF (ICHAR(ACE(:1)).NE.0) THEN
	   CALL SYS$FORMAT_ACL(ACE,,OUTPUT,,,,)
	   IF (INDEX(OUTPUT,'=*').NE.0.AND.
     &		INDEX(OUTPUT,'WRITE').EQ.0) WRITE_ACCESS = 0
	ELSE IF (ICHAR(ACE(:1)).EQ.0.AND.WRITE_ACCESS) THEN
	   WRITE_ACCESS = 0
	END IFF

	RETURNS
	END




	SUBROUTINE SHOWACL(FILENAME)
C 
C  SUBROUTINE SHOWACL 
CO
C  FUNCTION: Shows users who are allowed to read private bulletin.
C$
C  PARAMETERS:
C	FILENAME - Name of file to check.H
C 
	IMPLICIT INTEGER (A-Z)s

	INCLUDE '($ACLDEF)'

	CHARACTER*(*) FILENAMEL

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

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

	CALL LIB$GET_VM(ACLLENGTH+8,ACLSTR)
	CALL MAKE_CHAR(%VAL(ACLSTR),ACLLENGTH,ACLLENGTH)D

	CALL READACL(FILENAME,%VAL(ACLSTR),ACLLENGTH)

	RETURNS
	END



	SUBROUTINE FOLDER_FILE_ROUTINES

	IMPLICIT INTEGER (A-Z) 

	CHARACTER*(*) KEY_NAMEe

	INCLUDE 'BULLFOLDER.INC''

	COMMON /NEWS_OPEN/ NEWS_OPENF

	ENTRY WRITE_FOLDER_FILE(IER)E

	IF (NEWS_OPEN) CALL FOLDER_TO_NEWS,

	DO WHILE (REC_LOCK(IER))'
	   IF (NEWS_OPEN) THEN)
	      WRITE (7,IOSTAT=IER) NEWS_FOLDER_COM.
	   ELSE
	      WRITE (7,IOSTAT=IER) FOLDER_COM
	   END IF
	END DO 

	RETURNT

        ENTRY WRITE_FOLDER_FILE_TEMP(IER)_

        IF (NEWS_OPEN) CALL FOLDER1_TO_NEWSE

        DO WHILE (REC_LOCK(IER))
           IF (NEWS_OPEN) THEN
              WRITE (7,IOSTAT=IER) NEWS_FOLDER1_COMQ
           ELSE.
              WRITE (7,IOSTAT=IER) FOLDER1_COM
           END IFO
        END DO

        RETURN

	ENTRY REWRITE_FOLDER_FILE(IER)o

	IF (NEWS_OPEN) THEN
	   CALL FOLDER_TO_NEWS 
	   REWRITE (7,IOSTAT=IER) NEWS_FOLDER_COM
	ELSE'
	   REWRITE (7,IOSTAT=IER) FOLDER_COMi
	END IFo

	RETURNh

	ENTRY REWRITE_FOLDER_FILE_TEMP(IER) :

	IF (NEWS_OPEN) THEN
	   CALL FOLDER1_TO_NEWS
	   REWRITE (7,IOSTAT=IER) NEWS_FOLDER1_COM 
	ELSEE
	   REWRITE (7,IOSTAT=IER) FOLDER1_COM
	END IFL

	RETURN)

	ENTRY READ_FOLDER_FILE(IER)

	DO WHILE (REC_LOCK(IER))(
	   IF (NEWS_OPEN) THENE
	      READ (7,IOSTAT=IER) NEWS_FOLDER_COM
	   ELSE
	      READ (7,IOSTAT=IER) FOLDER_COMN
	   END IF
	END DO(

	IF (NEWS_OPEN.AND.IER.EQ.0) CALL NEWS_TO_FOLDER

	RETURNe

	ENTRY READ_FOLDER_FILE_TEMP(IER)c

	DO WHILE (REC_LOCK(IER))e
	   IF (NEWS_OPEN) THEN 
	      READ (7,IOSTAT=IER) NEWS_FOLDER1_COMF
	   ELSE
	      READ (7,IOSTAT=IER) FOLDER1_COM
	   END IF
	END DO

	IF (NEWS_OPEN.AND.IER.EQ.0) CALL NEWS_TO_FOLDER1C

	RETURNE

	ENTRY READ_FOLDER_FILE_KEYNUM(KEY_NUMBER,IER)

	SAVE_FOLDER_NUMBER = FOLDER_NUMBER 

	DO WHILE (REC_LOCK(IER))E
	   IF (NEWS_OPEN) THENE
	      READ (7,KEY=KEY_NUMBER,KEYID=1,IOSTAT=IER) NEWS_FOLDER_COMM
	   ELSE
	      READ (7,KEY=KEY_NUMBER,KEYID=1,IOSTAT=IER) FOLDER_COM
	   END IF
	END DO 

	IF (NEWS_OPEN.AND.IER.EQ.0) CALL NEWS_TO_FOLDER

	FOLDER_NUMBER = SAVE_FOLDER_NUMBERE

	RETURNR

	ENTRY READ_FOLDER_FILE_KEYNUM_GT(KEY_NUMBER,IER)R

	DO WHILE (REC_LOCK(IER))D
	   IF (NEWS_OPEN) THENL
	      READ (7,KEYGT=KEY_NUMBER,KEYID=1,IOSTAT=IER) NEWS_FOLDER_COM	
	   ELSE
	      READ (7,KEYGT=KEY_NUMBER,KEYID=1,IOSTAT=IER) FOLDER_COM
	   END IF
	END DO

	IF (NEWS_OPEN.AND.IER.EQ.0) CALL NEWS_TO_FOLDER

	RETURN 

	ENTRY READ_FOLDER_FILE_KEYNUM_TEMP(KEY_NUMBER,IER)S

	DO WHILE (REC_LOCK(IER))I
	   IF (NEWS_OPEN) THENP
	      READ (7,KEY=KEY_NUMBER,KEYID=1,IOSTAT=IER) NEWS_FOLDER1_COM
	   ELSE
	      READ (7,KEY=KEY_NUMBER,KEYID=1,IOSTAT=IER) FOLDER1_COMI
	   END IF
	END DON

	IF (NEWS_OPEN.AND.IER.EQ.0) CALL NEWS_TO_FOLDER1C

	RETURNf

	ENTRY READ_FOLDER_FILE_KEYNUM_GT_TEMP(KEY_NUMBER,IER)

	DO WHILE (REC_LOCK(IER))A
	   IF (NEWS_OPEN) THENN
	      READ (7,KEYGT=KEY_NUMBER,KEYID=1,IOSTAT=IER) NEWS_FOLDER1_COM
	   ELSE
	      READ (7,KEYGT=KEY_NUMBER,KEYID=1,IOSTAT=IER) FOLDER1_COM 
	   END IF
	END DOH

	IF (NEWS_OPEN.AND.IER.EQ.0) CALL NEWS_TO_FOLDER1,

	RETURN 

	ENTRY READ_FOLDER_FILE_KEYNAME_TEMP(KEY_NAME,IER)

	DO WHILE (REC_LOCK(IER))I
	   IF (NEWS_OPEN) THEN
	      READ (7,KEY=KEY_NAME,KEYID=0,IOSTAT=IER) NEWS_FOLDER1_COM
	   ELSE
	      READ (7,KEY=KEY_NAME,KEYID=0,IOSTAT=IER) FOLDER1_COMU
	   END IF
	END DON

	IF (NEWS_OPEN.AND.IER.EQ.0) CALL NEWS_TO_FOLDER1N

	RETURNE

	ENTRY READ_FOLDER_FILE_KEYNAMEGE_TEMP(KEY_NAME,IER)

	DO WHILE (REC_LOCK(IER)) 
	   IF (NEWS_OPEN) THENr
	      READ (7,KEYGE=KEY_NAME,KEYID=0,IOSTAT=IER) NEWS_FOLDER1_COM
	   ELSE
	      READ (7,KEYGE=KEY_NAME,KEYID=0,IOSTAT=IER) FOLDER1_COM 
	   END IF
	END DO 

	IF (NEWS_OPEN.AND.IER.EQ.0) CALL NEWS_TO_FOLDER1 

	RETURNE

	ENTRY READ_FOLDER_FILE_KEYNAMEGT_TEMP(KEY_NAME,IER)

	DO WHILE (REC_LOCK(IER))D
	   IF (NEWS_OPEN) THEN 
	      READ (7,KEYGT=KEY_NAME,KEYID=0,IOSTAT=IER) NEWS_FOLDER1_COM
	   ELSE
	      READ (7,KEYGT=KEY_NAME,KEYID=0,IOSTAT=IER) FOLDER1_COM 
	   END IF
	END DOR

	IF (NEWS_OPEN.AND.IER.EQ.0) CALL NEWS_TO_FOLDER1 

	RETURN.

	ENTRY READ_FOLDER_FILE_KEYNAME(KEY_NAME,IER)D

	DO WHILE (REC_LOCK(IER))T
	   IF (NEWS_OPEN) THENN
	      READ (7,KEY=KEY_NAME,KEYID=0,IOSTAT=IER) NEWS_FOLDER_COMN
	   ELSE
	      READ (7,KEY=KEY_NAME,KEYID=0,IOSTAT=IER) FOLDER_COM
	   END IF
	END DOF

	IF (NEWS_OPEN.AND.IER.EQ.0) CALL NEWS_TO_FOLDER

	RETURNF

	END


	SUBROUTINE USER_FILE_ROUTINES

	IMPLICIT INTEGER (A-Z)A

	INCLUDE '($PRVDEF)'

	INCLUDE '($FORIOSDEF)'_

	CHARACTER*(*) KEY_NAME

	INCLUDE 'BULLUSER.INC'O

	CHARACTER*12 SAVE_USERNAMEL

	ENTRY READ_USER_FILE(IER)

	SAVE_USERNAME = USERNAMEL

	DO WHILE (REC_LOCK(IER))E
	   READ (4,IOSTAT=IER) USER_ENTRY
	END DOS

	TEMP_USER = USERNAME
	USERNAME = SAVE_USERNAMED

	RETURNB

	ENTRY READ_USER_FILE_KEYNAME(KEY_NAME,IER)T

	SAVE_USERNAME = USERNAMEC

	DO WHILE (REC_LOCK(IER))
	   READ (4,KEY=KEY_NAME,IOSTAT=IER) USER_ENTRYk
	END DOA

	USERNAME = SAVE_USERNAMEe
	TEMP_USER = KEY_NAME

	RETURN 

	ENTRY READ_USER_FILE_HEADER(IER)N

	DO WHILE (REC_LOCK(IER))
	   READ (4,KEY='            ',IOSTAT=IER) USER_HEADER
	   IF (IER.EQ.FOR$IOS_ATTACCNON) THEN
	      WRITE (4,FMT=USER_FMT,IOSTAT=IER)
     &		 USER_HEADER_KEY,NEWEST_BTIM,)
     &	         BBOARD_BTIM,PRV$M_OPER.OR.PRV$M_CMKRNL.OR.
     &	         PRV$M_SETPRV,(0,I=1,FLONG*4-1)
	      IER = FOR$IOS_SPERECLOC
	   END IF
	END DOI

	RETURND

	ENTRY WRITE_USER_FILE_NEW(IER)O

	DO I=1,FLONGS
	   SET_FLAG(I) = SET_FLAG_DEF(I)E
	   BRIEF_FLAG(I) = BRIEF_FLAG_DEF(I)S
	   NOTIFY_FLAG(I) = NOTIFY_FLAG_DEF(I)l
	END DO 

	ENTRY WRITE_USER_FILE(IER) 

	DO WHILE (REC_LOCK(IER))E
	   WRITE (4,IOSTAT=IER) USER_ENTRY
	END DOC

	RETURN 

	END



	CHARACTER*(*) FUNCTION NEW_NEWS_ACCESS(IFILE)
  
	IMPLICIT INTEGER (A-Z)

	INCLUDE 'BULLFILES.INC'

	CHARACTER IFILE*(*),FILE*80

        FILE = IFILE
	S
	DO I=1,TRIM(FILE)
	   IF (FILE(I:I).EQ.'.') FILE(I:I) = '_'E
	END DO2

	FILE = FILE(:INDEX(FILE,' ')-1)
	IF (FILE(TRIM(FILE):TRIM(FILE)).EQ.'_') FILE = FILE(:TRIM(FILE)-1)n

	NEW_NEWS_ACCESS = L
     &	   NEWS_DIRECTORY(:TRIM(NEWS_DIRECTORY))//FILE(:TRIM(FILE))
     &	   //'.ACCESS'C

	RETURNT
	END




	CHARACTER*(*) FUNCTION NEWS_ACCESS(IFILE)
 L
	IMPLICIT INTEGER (A-Z) 

	INCLUDE 'BULLFILES.INC'

	CHARACTER IFILE*(*),FILE*80

        FILE = IFILE
	h
	DO I=1,TRIM(FILE)
	   IF (FILE(I:I).EQ.'.') FILE(I:I) = '_'M
	END DOE

	FILE = FILE(:INDEX(FILE,' ')-1)
	IF (FILE(TRIM(FILE):TRIM(FILE)).EQ.'_') FILE = FILE(:TRIM(FILE)-1),

	C = 0

	DO WHILE (TRIM(FILE).GT.0.AND..NOT.LIB$FIND_FILE(
     &	   NEWS_DIRECTORY(:TRIM(NEWS_DIRECTORY))//FILE(:TRIM(FILE))
     &	   //'.ACCESS',NEWS_ACCESS,C))E
	   L = LAST_INDEX(FILE,'_')-1
	   IF (L.LE.0) THEN
	      FILE = ' 'U
	   ELSE
	      FILE = FILE(:L)
	   END IF
	END DOs

	RETURN
	END




	INTEGER FUNCTION LAST_INDEX(INPUT,FIND)

	IMPLICIT INTEGER (A-Z)A

	CHARACTER*(*) INPUT,FINDf

        F = LEN(FIND)W

	DO LAST_INDEX=LEN(INPUT)-F+1,F,-1
           IF (INPUT(LAST_INDEX:LAST_INDEX+F-1).EQ.FIND) RETURNE
	END DO0

	RETURN 
	END
