From:	SMTP%"BULLETIN@PFC.MIT.EDU" 19-AUG-1994 17:54:40.64
To:	EVERHART
CC:	
Subj:	BULLETIN5.FOR

Date: Fri, 19 Aug 1994 17:25:49 -0400 (EDT)
From: BULLETIN@PFC.MIT.EDU
To:   EVERHART@arisia.gce.com
Message-Id: <940819172549.21438991@PFC.MIT.EDU>
Subject: BULLETIN5.FOR

C
C  BULLETIN5.FOR, Version 8/10/94
C  Purpose: Contains subroutines for the BULLETIN utility program.
C  Environment: VAX/VMS
C  Programmer: Mark R. London
C
C  Copyright (c) 1990
C  Property of Massachusetts Institute of Technology, Cambridge MA 02139.
C  This program cannot be copied or distributed in any form for non-MIT
C  use without specific written approval of MIT Plasma Fusion Center
C  Management.
C
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*256 INCMD

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	EXTERNAL CLI$_NEGATED

	IF (REMOTE_SET.GE.3) THEN
	   CALL SET_NEWS_FOLDER_DEFAULT(NOTIFY,READNEW,BRIEF)
	   RETURN
        ELSE IF (FOLDER_NUMBER.LT.0) THEN
	   WRITE (6,'('' ERROR: Command is invalid for this folder.'')')
	   RETURN
	END IF

	ALL = .FALSE.
	DEFAULT = 0
	NODEFAULT = 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')
	   NODEFAULT = CLI$PRESENT('NODEFAULT')
	   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 (NODEFAULT) THEN
	   IF (NOTIFY.NE.-1) CALL CLR2(NOTIFY_FLAG_DEF,FOLDER_NUMBER)
	   IF (READNEW.NE.-1.OR.BRIEF.NE.-1) THEN
	      CALL CLR2(SET_FLAG_DEF,FOLDER_NUMBER)
	      CALL CLR2(BRIEF_FLAG_DEF,FOLDER_NUMBER)
	   END IF
	   REWRITE(4) USER_HEADER
	ELSE 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.'')')R
	      RETURNj
	   ELSE
	      FOLDER1 = FOLDERu
	   END IF
	ELSE IF (LEN_T.GT.44) THENT
	   WRITE(6,'('' ERROR: Folder name must be < 26 characters.'')')1
	   RETURN
	END IFT

	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 IFa

	IF (INDEX(FOLDER1,'.').GT.0) THEN
	   CALL OPEN_BULLNEWS_SHAREDn
	ELSEr
	   CALL OPEN_BULLFOLDER
	END IFi

	CALL READ_FOLDER_FILE_KEYNAME_TEMP(FOLDER1,IER)	! See if folder existsS
	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.AND.FOLDER1_BBOARD(:2).NE.'::')) THEN
	   WRITE (6,'('' ERROR: You are not able to remove the folder.'')')
	   GO TO 1000
	END IFL

	TEMP = FOLDER_FILE.
	FOLDER_FILE = FOLDER1_FILER

	REMOTE_SET_SAVE = REMOTE_SETf
	REMOTE_SET = .FALSE.N

	IF (FOLDER1_BBOARD(:2).EQ.'::'.AND.BTEST(FOLDER1_FLAG,2)) THENI
	   FLEN = TRIM(FOLDER1_BBOARD)(
	   IF (INDEX(FOLDER1_BBOARD,'*').GT.0) FLEN = FLEN - 1 
	   OPEN (UNIT=17,STATUS='UNKNOWN',IOSTAT=IER,
     &		RECL=256,FILE=FOLDER1_BBOARD(3:FLEN)
     &		//'::"TASK=BULLETIN1"')A
	   IF (IER.EQ.0) THEN		! Deregister remote SYSTEM folderN
	      IF (INDEX(FOLDER1_BBOARD,'*').GT.0) THENF
	         CALL OPEN_BULLDIRH
	         CALL READDIR(0,IER),
		 IF (IER.EQ.1) FOLDER1 = BULLDIR_HEADER(13:)
		 CALL CLOSE_BULLDIRI
	      END IF 
	      WRITE (17,'(2A)',IOSTAT=IER) 1,FOLDER1	! Select folderC
	      IF (IER.EQ.0) READ(17,'(5A)',IOSTAT=IER)	! Throw away response
	      IF (IER.EQ.0) WRITE(17,'(2A)',IOSTAT=IER) 14,0	! Deregister
	      CLOSE (UNIT=17)
	   END IF
	END IF_

	TEMPSET = FOLDER_SETF
	FOLDER_SET = .TRUE.
	CALL SYS$SETDFPROT('FF00'X,CUR_DEF_PROT)E
		! 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 fileE
	CALL CLOSE_BULLFIL_DELETE
	CALL CLOSE_BULLDIR_DELETE
	CALL SYS$SETDFPROT(CUR_DEF_PROT,)	! Reset default protectionF
	FOLDER_FILE = TEMP 
	FOLDER_SET = TEMPSETS

	DELETE (7)F

	IF (FOLDER1_NUMBER.NE.0.OR.FOLDER1_BBOARD(:2).NE.'::') THEN
		! Test is due to bug which changes folder number to zero
	   TEMP_NUMBER = FOLDER_NUMBERU
	   FOLDER_NUMBER = FOLDER1_NUMBER
	   TEMP_FLAG = FOLDER_FLAG.
	   IF (BTEST(FOLDER1_FLAG,2)) THENA
	      FOLDER_FLAG = IBCLR(FOLDER1_FLAG,2)
	      CALL MODIFY_SYSTEM_LIST(0).
	   END IF
	   CALL SET_FOLDER_DEFAULT(0,0,0)
	   FOLDER_FLAG = TEMP_FLAGF
	   FOLDER_NUMBER = TEMP_NUMBERI
	END IFC

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

	IF (FOLDER.EQ.FOLDER1) THEN
	   CALL CLOSE_BULLFOLDER
	   FOLDER_SET = .FALSE.
           FOLDER_NUMBER = 0
           CALL SELECT_FOLDER(.FALSE.,IER)
           WRITE (6,'('' Resetting to '',A,'' folder.'')')
     &              FOLDER(:TRIM(FOLDER)) 
	   RETURN
	ELSER
	   REMOTE_SET = REMOTE_SET_SAVE
	END IFC

1000	CALL CLOSE_BULLFOLDER

	RETURND

	END


	SUBROUTINE SELECT_FOLDER(OUTPUT,IER)
C
C  SUBROUTINE SELECT_FOLDERP
CI
C  FUNCTION: Selects the specified folder.
C
C  INPUTS:
C	OUTPUT - Specifies whether status messages are outputted.M
CA
C  NOTES:R
C	FOLDER_NUMBER is used for selecting the folder.N
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.)
C	If the specified folder is on a remote node and does not haveE
C	a local entry (i.e. specified via NODENAME::FOLDERNAME), then.
C	FOLDER_NUMBER is set to -1. 
CS

	IMPLICIT INTEGER (A-Z) 

	INCLUDE 'BULLFOLDER.INC' 

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLUSER.INC'M

	INCLUDE '($RMSDEF)'
	INCLUDE '($SSDEF)'f

	COMMON /POINT/ BULL_POINT

	COMMON /ACCESS/ READ_ONLY
	LOGICAL READ_ONLY

	COMMON /COMMAND_LINE/ INCMD
	CHARACTER*256 INCMD

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

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

	COMMON /BULLPAR/ BULL_PARAMETER,LEN_P
	CHARACTER*64 BULL_PARAMETER

	COMMON /TAGS/ BULL_TAG,READ_TAG

	COMMON /SAVE_FOLDERS/ SAVE_FOLDER_Q1,SAVE_FOLDER_NUM

	COMMON /BULL_NOTIFY/ NOTIFY_REMOTE(FLONG)

	COMMON /HEADER/ HEADER 

	COMMON /READIT/ READITE

	COMMON /FLAG_ACCESS/ FLAG_ACCESS

	COMMON /BULL_USER_CUSTOM/ BULL_USER_CUSTOMS
	DATA BULL_USER_CUSTOM/.FALSE./

	EXTERNAL CLI$_ABSENT,CLI$_NEGATED

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

	CHARACTER*80 LOCAL_FOLDER1_DESCRIPE

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

	DIMENSION OLD_NEWEST_BTIM(2)L

	DATA LAST_NEWS_GROUP/0/

	COMMAND = (INCMD(:3).EQ.'ADD').OR.(INCMD(:3).EQ.'DEL').OR.
     &		  (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_NAMEl
	   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.'::') THENt
	         FOLDER1 = FOLDER1(:FLEN)//'GENERAL'_
	      END IF
	   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 IFM

	REMOTE_TEST = 0
	REMOTE_SET_NEW = 0M

	IF (SAVE_FOLDER_Q1.NE.0) THEN			! Have folder infoL
	   FOLDER1_COM = FOLDER_COM
	   IER = 0T
	   NEWS = INDEX(FOLDER1,'.').GT.0.OR.(FOLDER1(:1).GE.'a'.AND.
     &					   FOLDER1(:1).LE.'z')O
	   IF (NEWS.AND.BTEST(FOLDER1_FLAG,8)) REMOTE_SET_NEW = 4
	ELSE
	   NEWS = ((INDEX(FOLDER1,'.').GT.0.OR.(FOLDER1(:1).GE.'a'.AND.
     &		FOLDER1(:1).LE.'z')).AND.(FOLDER_NUMBER.LE.-1.OR.OUTPUT))A
     &		.OR.(FOLDER_NUMBER.GT.1000.AND..NOT.OUTPUT)F
	   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) THENT
		 WRITE (6,'('' Fetching NEWS groups from remote node.''F
     &			,''  This will take several minutes.'')')
		 WRITE (6,'('' This is the only time this will have''_
     &			,'' to be done.'')').
	         CALL CLOSE_BULLFOLDER
		 FOLDER1_SAVE = FOLDER1R
		 CALL NEWS_LISTs
	         CALL OPEN_BULLFOLDER_SHARED 
		 FOLDER1 = FOLDER1_SAVEo
	      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) THENR
		    FOLDER1_SAVE = FOLDER1
	            FOLDER1_NUMBER = LAST_NEWS_READ(1,FOLDER_MAX)
	            IER = 2
		    DO WHILE (IER.EQ.2)
		       CALL READ_FOLDER_FILE_KEYNUM_GT_TEMP
     &		          (FOLDER1_NUMBER,IER)
		       IF (IER.EQ.0.AND.BTEST(FOLDER1_FLAG,10)) IER = 2 
	            END DOU
		    FOLDER1 = FOLDER1_SAVE
		 END IF
		 IF (LAST_NEWS_READ(1,FOLDER_MAX).GT.1000_
     &			.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 IF 
		 LAST_NEWS_GROUP = NEWS_F1_COUNT
		 FOLDER1_SAVE = FOLDER1l
	         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_EXPIRE 
		    IF (NEWS_F1_EXPIRE_LIMIT.NE.0) r
     &		       NEWS_EXPIRE_LIMIT_DEFAULT = NEWS_F1_EXPIRE_LIMIT 
	         END IF
	         FOLDER1 = FOLDER1_SAVE
	      END IFT
	      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) THEND
	      REMOTE_TEST = INDEX(FOLDER1,'::')
	      IF (REMOTE_TEST.GT.0) THENT
	         FOLDER1_BBOARD = '::'//FOLDER1(:REMOTE_TEST-1)
	         FOLDER1 = FOLDER1(REMOTE_TEST+2:TRIM(FOLDER1))
	         FOLDER1_NUMBER = -1(
	         IER = 0I
	      ELSE IF (INCMD(:2).EQ.'SE') THEND
	         CALL READ_FOLDER_FILE_KEYNAME_TEMP
     &				(FOLDER1(:TRIM(FOLDER1)),IER)D
	      ELSER
	         CALL READ_FOLDER_FILE_KEYNAME_TEMP(FOLDER1,IER)a
	      END IFh
	   ELSE
	      FOLDER1_NUMBER = FOLDER_NUMBER 
	      CALL READ_FOLDER_FILE_KEYNUM_TEMP(FOLDER_NUMBER,IER)A
	   END IF

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

	   CALL CLOSE_BULLFOLDERA

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

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

	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_FLAGL
	   LOCAL_FOLDER1_DESCRIP = FOLDER1_DESCRIP,
	   CALL CONNECT_REMOTE_FOLDER(READ_ONLY,IER1)
	   IF (IER1.NE.0) THEN)
	      IF (OUTPUT) THEN 
	         WRITE (6,'('' ERROR: Unable to select the folder.'')')
		 IF (.NOT.NEWS) THEN
		    LENB = TRIM(FOLDER1_BBOARD)S
		    IF (FOLDER1_BBOARD(LENB:LENB).EQ.'*') LENB = LENB - 1P
	            WRITE (6,'('' Cannot connect to node '',A,''.'')')M
     &		        FOLDER1_BBOARD(3:LENB)
		 ELSE IF (.NOT.IER1) THEN0
	            WRITE (6,'('' Cannot connect to remote NEWS node.'')')a
	         END IF
	      END IFE
	      RETURND
	   END IF
	   IF (REMOTE_TEST.GT.0) THEN	! Folder specified with "::"A
	      FOLDER1 = FOLDER1_BBOARD(3:TRIM(FOLDER1_BBOARD))//'::'//C
     &			FOLDER1
	      FOLDER1_NUMBER = -1
	      REMOTE_SET_NEW = 1A
	   ELSE IF (NEWS) THEN,
	      REMOTE_SET_NEW = 3F
	      CALL OPEN_BULLNEWS_SHARED	! Update local folder information
	      IF (IER.NE.0) CALL NEWS_NEW_FOLDERE
              CALL READ_FOLDER_FILE_KEYNAME(FOLDER1,IER)
	      IF ((F1_START.NE.F_START.OR.F1_NBULL.NE.F_NBULL).AND.
     &		  F1_START.GT.0) THENI
	         IF (F1_NBULL.NE.F_NBULL) CALL SYS_BINTIM('-',F_NEWEST_BTIM)R
	         F_NBULL = F1_NBULL
	         F_START = F1_START
	         CALL REWRITE_FOLDER_FILE(IER)U
	      END IFT
	      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) 
	      END IFo
	      FOLDER1_FLAG = LOCAL_FOLDER1_FLAG		! Use local flag infoe
	      REMOTE_SET_NEW = 1,
	   END IF
	END IFO

	IF (IER.EQ.0) THEN				! Folder founde
	   FLAG1_ACCESS = .TRUE.	
	   CALL SET_FOLDER_FILE(1) 
	   IF (BTEST(FOLDER1_FLAG,0)) THEN		! Folder protected?
	      IF (NEWS) THENO
		 CALL CHKACL(NEWS_ACCESS(FOLDER1_DESCRIP),IER)
	      ELSEI
	         CALL CHKACLC
     &		 (FOLDER1_FILE(:TRIM(FOLDER1_FILE))//'.BULLFIL',IER)
	      END IF
	      IF (IER.NE.(SS$_ACLEMPTY.OR.SS$_NORMAL).AND.USERNAMET
     &		  .NE.FOLDER1_OWNER.AND.IER) THEN
	         IF (NEWS) THEN
	            CALL CHECK_ACCESS
     &		     (NEWS_ACCESS(FOLDER1_DESCRIP),O
     &		     USERNAME,READ_ACCESS,WRITE_ACCESS)
	         ELSE
	            CALL CHECK_ACCESS
     &		     (FOLDER1_FILE(:TRIM(FOLDER1_FILE))//'.BULLFIL',
     &		     USERNAME,READ_ACCESS,WRITE_ACCESS)C
	         END IF
	         IF (SETPRV_PRIV().AND.READIT.EQ.0) THENQ
		    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) THENU
	           WRITE(6,'('' You are not allowed to access news group.'')')T
		  ELSE IF (NEWS) THEN*
		   IF (NEWS_FIND_SUBSCRIBE().LE.FOLDER_MAX-1) THEN
		      CALL NEWS_SET_USER_FLAG(0,0,0)
		   END IFl
		  ELSE IF (OUTPUT) THENI
	           WRITE(6,'('' You are not allowed to access folder.'')')W
	           WRITE(6,'('' See '',A,'' if you wish to access folder.'')')'
     &			FOLDER1_OWNER(:TRIM(FOLDER1_OWNER))
		  ELSE IF (TEST2(BRIEF_FLAG,FOLDER1_NUMBER).OR.&
     &			 TEST2(SET_FLAG,FOLDER1_NUMBER)) THEN
		   CALL OPEN_BULLUSER_SHARED
		   CALL READ_USER_FILE_KEYNAME(USERNAME,IER)
		   CALL CLR2(BRIEF_FLAG,FOLDER1_NUMBER)G
		   CALL CLR2(SET_FLAG,FOLDER1_NUMBER)E
		   IF (IER.EQ.0) REWRITE (4) USER_ENTRYE
		   CALL CLOSE_BULLUSER
		  END IF
		  IER = 0O
		  RETURN
	         END IF
	      ELSE IF (BTEST(FOLDER1_FLAG,0).AND.(.NOT.IER.OR.h
     &		  (IER.EQ.(SS$_ACLEMPTY.OR.SS$_NORMAL).AND..NOT.NEWS))
     &		  .AND.(FOLDER1_BBOARD(:2).NE.'::'.OR.NEWS)) THENN
	         IF (NEWS) THEN
	            CALL OPEN_BULLNEWS_SHARED
	         ELSE
	            CALL OPEN_BULLFOLDERO
	         END IF
	         CALL READ_FOLDER_FILE_KEYNAME_TEMP(FOLDER1,IER1)
		 FOLDER1_FLAG = IBCLR(FOLDER1_FLAG,0)U
	         CALL REWRITE_FOLDER_FILE_TEMP(IER1) 
		 CALL CLOSE_BULLFOLDER
	      ELSE IF (FOLDER1_BBOARD(:2).EQ.'::') THEN
	         IER = SS$_ACLEMPTY.OR.SS$_NORMAL
	      END IFC
	   ELSE					! Folder not protectedL
	      IER = SS$_ACLEMPTY.OR.SS$_NORMAL	! Indicate folder selected
	   END IF

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

	   REMOTE_SET = REMOTE_SET_NEW 

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

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

	      IF (FOLDER_NUMBER.NE.0) THEN 
		 FOLDER_SET = .TRUE.
	      ELSE=
		 FOLDER_SET = .FALSE.E
	      END IF

	      IF (REMOTE_SET.LT.3) THEN
		 FOLDER_NAME = FOLDER 
	         HEADER = .NOT.BTEST(FOLDER_FLAG,4)
	      ELSE 
	         HEADER = .FALSE.
		 FOLDER_NAME = FOLDER_DESCRIP(:INDEX(FOLDER_DESCRIP,' ')-1),
	         IF (REMOTE_SET.EQ.4) NEWS_FOLDER_COM = NEWS_FOLDER1_COMt
	      END IFi

	      IF (REMOTE_SET.EQ.1.AND.FOLDER_NUMBER.GE.0) THENA
	         CALL OPEN_BULLFOLDER	! Update local folder information
                 CALL READ_FOLDER_FILE_KEYNAME(FOLDER1,IER1)
	         OLD_NEWEST_BTIM(1) = F_NEWEST_BTIM(1)E
      	         OLD_NEWEST_BTIM(2) = F_NEWEST_BTIM(2)E
	         FOLDER_COM = FOLDER1_COM
	         CALL REWRITE_FOLDER_FILE(IER1)
	         CALL CLOSE_BULLFOLDERF
	         DIFF = COMPARE_BTIM(OLD_NEWEST_BTIM,F_NEWEST_BTIM)
	         IF (DIFF.LT.0.AND.IER1.EQ.0) THENE
	            CALL READ_NOTIFYL
	            IF (TEST2(NOTIFY_REMOTE,FOLDER_NUMBER)) THEN,
		       CALL NOTIFY_REMOTE_USERS(OLD_NEWEST_BTIM)
	            END IF 
	         END IF
	      END IFD

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

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

	      IF (OUTPUT) THENf
		 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:'')')R
		       WRITE (6,'(1X,A)') FOLDER_DESCRIP(F
     &				       INDEX(FOLDER_DESCRIP,'=')+1:)
		    END IF
		 ELSEE
		    BULL_POINT = 0	! Reset pointer to first bulletin
	         END IF
	      END IF 

	      IF (IER.NE.(SS$_ACLEMPTY.OR.SS$_NORMAL).AND.USERNAME 
     &		  .NE.FOLDER_OWNER) THEN
	         IF (.NOT.WRITE_ACCESS) THENE
		   IF (OUTPUT.AND.INCMD(:3).NE.'DIR'.AND.SLIST.EQ.0) THENR
		    WRITE (6,'('' Folder only accessible for reading.'')')
		   END IFL
		   READ_ONLY = .TRUE.(
		 ELSE 
		   READ_ONLY = .FALSE.
		 END IFC
	      ELSEE
		 READ_ONLY = .FALSE.
	      END IFA

	      IF (FOLDER_NUMBER.GT.0.AND.REMOTE_SET.LT.3) THEN 
		IF (TEST_BULLCP().GT.0.OR.REMOTE_SET) THEN
		 CALL SET2(FIRST_TIME,FOLDER_NUMBER)
		ELSE IF (.NOT.TEST2(FIRST_TIME,FOLDER_NUMBER)) THENs
	       			! 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.=
     &			(FOLDER_NUMBER.EQ.0.OR.BTEST(FOLDER_FLAG,2))C
     &			.AND.TEST2(SHUTDOWN_FLAG,FOLDER_NUMBER)) THEN
						! Do shutdown bulletins exist?
		       SHUTDOWN = 0R
		       IER1 = -1
		    ELSE
		       IF (TEST2(SHUTDOWN_FLAG,FOLDER_NUMBER)) THENB
			  CALL UPDATE_SHUTDOWN(FOLDER_NUMBER)
		       END IFB
	               IER1 = 1
		    END IF
	 	    IF (IER.LE.0.OR.IER.GT.20*356.OR.IER1.LE.0) THEN 
		       CALL UPDATE	! Need to updateE
		    END IF
		 ELSE0
		    NBULL = 0I
		 END IFC
		 CALL CLOSE_BULLDIR 
		 CALL SET2(FIRST_TIME,FOLDER_NUMBER)
	        END IF 
	      END IFN

	      IF (OUTPUT) THENT
		 IF (CLI$PRESENT('MARKED')) THEN
		    READ_TAG = 1 + IBSET(0,1)R
		    BULL_PARAMETER = 'MARKED'C
		 ELSE IF (CLI$PRESENT('SEEN')) THENE
		    READ_TAG = 1 + IBSET(0,2)A
		    BULL_PARAMETER = 'SEEN' 
	         ELSE IF (CLI$PRESENT('UNMARKED').OR.CLI$PRESENTU
     &		       ('MARKED').EQ.%LOC(CLI$_NEGATED)) THENL
		    READ_TAG = 1 + IBSET(0,1) + IBSET(0,3)
		    BULL_PARAMETER = 'UNMARKED' 
	         ELSE IF (CLI$PRESENT('UNSEEN').OR.CLI$PRESENT
     &		       ('SEEN').EQ.%LOC(CLI$_NEGATED)) THENL
		    READ_TAG = 1 + IBSET(0,2) + IBSET(0,3)
		    BULL_PARAMETER = 'UNSEEN'
		 ELSE 
		    READ_TAG = IBSET(0,1) + IBSET(0,2)
		 END IFE
	         IF (READ_TAG) THEN
	            IF (FOLDER_NUMBER.GE.0) THENr
		       CALL GET_FIRST_TAG(FOLDER_NUMBER,IER,BULL_POINT)P
		    ELSE
		       WRITE (6,'('' ERROR: invalid qualifier'',
     &			          '' with remote folder.'')')
		       READ_TAG = IBSET(0,1) + IBSET(0,2) 
		    END IF
	         END IF
	         IF (READ_TAG.AND.INCMD(:3).NE.'DIR') THENM
		    IF (IER.EQ.0) THEN
		       WRITE(6,'('' NOTE: Only '',A,'' messages'',
     &			   '' will be shown.'')')
     &			   BULL_PARAMETER(:TRIM(BULL_PARAMETER))0
		    ELSE
		       WRITE(6,'('' WARNING: No '',A,
     &			   '' messages found.'')')S
     &		 	   BULL_PARAMETER(:TRIM(BULL_PARAMETER))
		    END IF
	         END IF
	      END IFL

	      IF (REMOTE_SET.GE.3.AND.OUTPUT.AND..NOT.READ_TAG) THEN$
		 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 IF 
	      ELSE IF (FOLDER_NUMBER.NE.0.AND..NOT.READ_TAG.AND. 
     &		  				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)(
	         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 = 0t
		    DO WHILE (NEW_COUNT.GT.0)'
		      NEW_COUNT = NEW_COUNT / 10
		      DIG = DIG + 1)
		    END DO
		    WRITE(6,'('' There are '',I<DIG>,'' new messages.'')')
     &			F_NBULL - BULL_POINT	! Alert user if new bulletinse
		  ELSE
		    BULL_POINT = 0
		  END IF
		 END IF(
		END IF
	      END IF 
	      IER = 1
	      IF (TEST_BULLCP().NE.2) CALL CHECK_CUSTOM
	      IF (BTEST(BULL_USER_CUSTOM,2)) HEADER = .TRUE..
	   ELSE IF (OUTPUT) THENL
	      WRITE (6,'('' Cannot access specified folder.'')')	
	      CALL SYS_GETMSG(IER)E
	   END IF
	ELSE						! Folder not foundO
	   IF (OUTPUT) WRITE (6,'('' ERROR: Folder does not exist.'')')
	   IER = 0W
	END IFU

	RETURN

	END





	SUBROUTINE UPDATE_FOLDER 
CO
C  SUBROUTINE UPDATE_FOLDERF
C 
C  FUNCTION: Updates folder info due to new message.
C 

	IMPLICIT INTEGER (A-Z)T

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC'R

	IF (FOLDER_NUMBER.LT.0) RETURNN

	CALL OPEN_BULLFOLDER_SHARED			! Open folder fileL

	CALL READ_FOLDER_FILE_KEYNAME(FOLDER,IER)

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

	F_NBULL = NBULL

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

	IF (.NOT.BTEST(SYSTEM,0)) THEN 	! Is non-system message?R
	   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 IFt

	CALL REWRITE_FOLDER_FILE(IER)

	CALL CLOSE_BULLFOLDER

	RETURNt
	END



	SUBROUTINE SHOW_FOLDERN
CN
C  SUBROUTINE SHOW_FOLDER
C 
C  FUNCTION: Shows the information on any folder.R
CT

	IMPLICIT INTEGER (A-Z)T

	INCLUDE 'BULLUSER.INC'F

	INCLUDE 'BULLFOLDER.INC'

	INCLUDE 'BULLDIR.INC'

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	COMMON /COMMAND_LINE/ INCMD
	CHARACTER*256 INCMD

	COMMON /BULL_PERM/ SET_PERM_FLAG,BRIEF_PERM_FLAG,NOTIFY_PERM_FLAG
	DIMENSION SET_PERM_FLAG(FLONG) 
	DIMENSION BRIEF_PERM_FLAG(FLONG)E
	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 IFi

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

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

	IF (TEST_NEWS(FOLDER1)) THEN              I
	   INCMD = 'SET NEWS ' 
	   IF (CLI$PRESENT('FULL')) INCMD = 'SET NEWS/FULL 'B
	   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_BULLFOLDERL
	   RETURN
	ELSE IF (FOLDER.EQ.FOLDER1) THEND
	   WRITE (6,1000) FOLDER1,FOLDER1_OWNER,U
     &			FOLDER1_DESCRIP(:TRIM(FOLDER1_DESCRIP))
	ELSEE
	   WRITE (6,1010) FOLDER1,FOLDER1_OWNER,I
     &			FOLDER1_DESCRIP(:TRIM(FOLDER1_DESCRIP))
	END IF 

	IF (CLI$PRESENT('FULL')) THEN
	   CALL SET_FOLDER_FILE(1) 
	   CALL CHKACLG
     &		 (FOLDER1_FILE(:TRIM(FOLDER1_FILE))//'.BULLFIL',IER)
	   IF (IER.EQ.(SS$_ACLEMPTY.OR.SS$_NORMAL).OR.(.NOT.IER)) THENf
	      IF (FOLDER1_BBOARD(:2).EQ.'::'.AND.	! Is folder remote 
     &		BTEST(FOLDER1_FLAG,0)) THEN		! and private?T
	         WRITE (6,'('' Access is limited.'')')'
	      END IFn
	   ELSE
	      IF (SETPRV_PRIV()) THEN
	         READ_ACCESS = 1 
		 WRITE_ACCESS = 1 
	      ELSET
	        CALL CHECK_ACCESS
     &		  (FOLDER1_FILE(:TRIM(FOLDER1_FILE))//'.BULLFIL', 
     &		   USERNAME,READ_ACCESS,WRITE_ACCESS)'
	      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.'::') THENr
		 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)R
		    FOLDER_FILE = FOLDER1_FILE
		    REMOTE_SET_SAVE = REMOTE_SET
		    REMOTE_SET = .FALSE.
		    CALL OPEN_BULLDIRN
		    CALL READDIR(0,IER)O
		    CALL CLOSE_BULLDIR
		    CALL SET_FOLDER_FILE(0)I
		    REMOTE_SET = REMOTE_SET_SAVE
		    WRITE (6,'('' Folder is located on node '', 
     &		       A,''. Remote folder name is '',A,''.'')') =
     &		       FOLDER1_BBOARD(3:FLEN-1),
     &		       BULLDIR_HEADER(13:TRIM(BULLDIR_HEADER))
		 END IFA
	      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) 
		 END IFi
		 IF ((USERB1.EQ.0.AND.GROUPB1.EQ.0).OR.BTEST(USERB1,31)) THENC
 		  WRITE (6,'('' BBOARD was specified with /SPECIAL.'')')F
		  IF (BTEST(GROUPB1,31)) THENs
		   WRITE (6,'('' BBOARD was specified with /VMSMAIL.'')')n
		  END IF
		 END IFH
	      ELSEN
	         WRITE (6,'('' No BBOARD has been defined.'')')
	      END IF,
	      IF (FOLDER1_BBEXPIRE.GT.0) THEN
		 WRITE (6,'('' Default expiration is '',I3,'' days.'')')
     &			FOLDER1_BBEXPIRE 
	      ELSE IF (FOLDER1_BBEXPIRE.EQ.-1) THEN
		 WRITE (6,'('' Default expiration is permanent.'')')
	      ELSER
		 WRITE (6,'('' No default expiration set.'')')
	      END IFF
	      IF (BTEST(FOLDER1_FLAG,2)) THEN
		 WRITE (6,'('' SYSTEM has been set.'')')
	      END IF
	      IF (BTEST(FOLDER1_FLAG,1)) THEN
		 WRITE (6,'('' DUMP has been set.'')')
	      END IFT
	      IF (BTEST(FOLDER1_FLAG,3)) THEN
		 WRITE (6,'('' NOPROMPT_EXPIRE has been set.'')')P
	      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 IF 
	      IF (BTEST(FOLDER1_FLAG,7)) THEN
		 WRITE (6,'('' ALWAYS has been set.'')')
	      END IF	
	      IF (BTEST(FOLDER1_FLAG,10)) THEN)
		 WRITE (6,'('' POST_ONLY has been set.'')') 
	      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 IFS
	      IF (BTEST(FOLDER1_FLAG,14)) THEN 
		 WRITE (6,'('' ANONYMOUS has been set.'')')U
	      END IFr
	      IF (F1_EXPIRE_LIMIT.GT.0) THENM
		 WRITE (6,'('' EXPIRATION limit is '',I3,'' days.'')')
     &			F1_EXPIRE_LIMIT
	      END IF 
	      CALL OPEN_BULLUSER_SHARED
	      CALL READ_USER_FILE_HEADER(IER)
	      CALL READ_PERM 
	      PERM = .FALSE. 
	      IF (TEST2(SET_FLAG_DEF,FOLDER1_NUMBER)) THEN(
	       IF (TEST2(BRIEF_FLAG_DEF,FOLDER1_NUMBER)) THEN
	        IF (TEST2(BRIEF_PERM_FLAG,FOLDER1_NUMBER).AND.	
     &		    TEST2(SET_PERM_FLAG,FOLDER1_NUMBER)) THEN
	         PERM = .TRUE.N
		 WRITE (6,'('' Default is BRIEF, which is permanent.'')')	
		ELSE
		 WRITE (6,'('' Default is BRIEF.'')') 
		END IF
	       ELSE
	        IF (TEST2(SET_PERM_FLAG,FOLDER1_NUMBER).AND.U
     &		    .NOT.TEST2(BRIEF_PERM_FLAG,FOLDER1_NUMBER)) THEN
	         PERM = .TRUE.E
		 WRITE (6,'('' Default is READNEW, which is permanent.'')')I
		ELSE
		 WRITE (6,'('' Default is READNEW.'')')E
		END IF
	       END IF
	      ELSEE
	       IF (TEST2(BRIEF_FLAG_DEF,FOLDER1_NUMBER)) THEN
	        IF (TEST2(BRIEF_PERM_FLAG,FOLDER1_NUMBER).AND.N
     &		    .NOT.TEST2(SET_PERM_FLAG,FOLDER1_NUMBER)) THEN
	         PERM = .TRUE.S
		 WRITE (6,'('' Default is SHOWNEW, which is permanent.'')')n
		ELSE
		 WRITE (6,'('' Default is SHOWNEW.'')')e
		END IF
	       END IF
	      END IFN
	      IF (.NOT.PERM) THEN
	        IF (TEST2(BRIEF_PERM_FLAG,FOLDER1_NUMBER).AND.O
     &		    TEST2(SET_PERM_FLAG,FOLDER1_NUMBER)) THENI
		   WRITE (6,'('' BRIEF is the permanent setting.'')')
	        ELSE IF (TEST2(SET_PERM_FLAG,FOLDER1_NUMBER).AND.
     &		    .NOT.TEST2(BRIEF_PERM_FLAG,FOLDER1_NUMBER)) THEN
		   WRITE (6,'('' READNEW is the permanent setting.'')')L
	        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 IFT
	      END IF 
	      IF (TEST2(NOTIFY_FLAG_DEF,FOLDER1_NUMBER)) THEN
	        IF (TEST2(NOTIFY_PERM_FLAG,FOLDER1_NUMBER)) THENe
		 WRITE (6,'('' Default is NOTIFY, which is permanent.'')')
		ELSE
		 WRITE (6,'('' Default is NOTIFY.'')')
		END IF
	      ELSES
		 WRITE (6,'('' Default is NONOTIFY.'')')
	      END IF
	      CALL CLOSE_BULLUSER
	   END IF
	   SLIST = INDEX(FOLDER1_DESCRIP,'<')
	   ELIST = INDEX(FOLDER1_DESCRIP,'>')
	   IF (SLIST.GT.0.AND.ELIST.GT.SLIST) THENR
	      IF ((FOLDER1_DESCRIP(SLIST+1:SLIST+1).EQ.'@'.OR.o
     &		     TEST_NEWS(FOLDER_DESCRIP(SLIST+1:ELIST-1))).AND.L
     &		     INDEX(FOLDER_DESCRIP(SLIST+2:),'@').EQ.0) THEN
		 WRITE (6,'('' Last message fed by news group was: '',I)')
     &			 F_LAST
	      END IFT
	   END IF
	END IF!

	CALL CLOSE_BULLFOLDER

	RETURNT

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


	SUBROUTINE DIRECTORY_FOLDERS(FOLDER_COUNT)W
CL
C  SUBROUTINE DIRECTORY_FOLDERSE
C
C  FUNCTION: Display all FOLDER entries.
C 
	IMPLICIT INTEGER (A - Z)N

	INCLUDE '($SSDEF)'E

	INCLUDE 'BULLFOLDER.INC''

	INCLUDE 'BULLUSER.INC'E

	INCLUDE 'BULLDIR.INC'

	COMMON /PAGE/ PAGE_LENGTH,PAGE_WIDTH,PAGING
	LOGICAL PAGINGI

	COMMON /CTRLC_FLAG/ FLAG

	COMMON /LAST_BUFFER/ OLD_BUFFER
	CHARACTER*(INPUT_LENGTH) OLD_BUFFER

	DATA SCRATCH_D1/0/G

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

	INTEGER*2 MLEN,FLEN

	OLD_BUFFER = ' 'M

	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.'')')
	      RETURNL
	   END IF
	ELSEL
	   CALL OPEN_BULLFOLDER_SHARED		! Get folder file
	END IFO

	IF (FOLDER_COUNT.EQ.0) THEN
	   SUBSCRIBE = .FALSE.D
	   ACTIVE = .FALSE. I
	   STORED = .FALSE. )
	   CLASS = .FALSE.,
	   NEW = .FALSE. 
	   PERM = .FALSE.
	   DEFA = .FALSE.
	   FOLDER_COUNT = 1			! Init folder number counter 
	   NLINE = 1N
	   START = .FALSE. 
	   IF (.NOT.CLI$PRESENT('NEWS')) THEN
	      NEWS = .FALSE.L
	      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) THENM
		 WRITE (6,'('' Fetching NEWS groups from remote node.''R
     &			,''  This will take several minutes.'')')
		 WRITE (6,'('' This is the only time this will have''R
     &			,'' to be done.'')')L
	         CALL CLOSE_BULLFOLDERL
		 CALL NEWS_LISTF
	         CALL OPEN_BULLNEWS_SHARED6
	         CALL READ_FOLDER_FILE_KEYNAME_TEMP('a',IER)P
	      END IFD
	      COUNT = CLI$PRESENT('COUNT')T
	      IF (COUNT) TOTAL_COUNT = 0_
	      STORED = CLI$PRESENT('STORED')O
	      SUBSCRIBE = CLI$PRESENT('SUBSCRIBE')E
	      NEW = CLI$PRESENT('NEWGROUPS')_
	      CLASS = CLI$PRESENT('CLASS')I
	      PERM = CLI$PRESENT('PERMANENT')
	      DEFA =  CLI$PRESENT('DEFAULT')L
	      IF (CLASS) THEN
	         CALL CLOSE_BULLFOLDERe
	         CALL OPEN_BULLNEWS_SHARED
	      END IF 
	      IF (NEW) THEN
		 NEW_NEWS = MAX(LAST_NEWS_READ(1,FOLDER_MAX),1000)
	      ELSE IF (SUBSCRIBE) THEN_
		 CALL NEWS_GET_SUBSCRIBE(0,F1_COUNT)
		 SUBNUM = 1.
	      ELSE IF (PERM) THEN
	      	 CALL OPEN_BULLINF_SHARED 
	         DO WHILE (REC_LOCK(IER))
	            READ (9,KEY='*PERM',IOSTAT=IER) TEMP_USER,INF_REC
		 END DO
		 IF (IER.NE.0) THEND
	            DO I=1,FOLDER_MAX
	               INF_REC(1,I) = 0
	               INF_REC(2,I) = 0
	            END DO1
	         END IF
		 CALL CLOSE_BULLINF)
		 INUM = 1
	      ELSE IF (DEFA) THEN
	      	 CALL OPEN_BULLINF_SHARED 
	         DO WHILE (REC_LOCK(IER))
	            READ (9,KEY='*DEFAULT',IOSTAT=IER) TEMP_USER,INF_RECR
		 END DO 
		 IF (IER.NE.0) THENO
	            DO I=1,FOLDER_MAX
	               INF_REC(1,I) = 0
	               INF_REC(2,I) = 0
	            END DO 
	         END IF
		 CALL CLOSE_BULLINFT
		 INUM = 1_
	      ELSER
	         ACTIVE = .NOT.CLI$PRESENT('ALL')
	      END IFA
	   END IF
	   IF (CLI$GET_VALUE('START',FOLDER1,FLEN)) THENE
	      IF (NEWS) CALL LOWERCASE(FOLDER1)
	      CALL READ_FOLDER_FILE_KEYNAMEGE_TEMP(FOLDER1(:FLEN),IER)O
	      IF (IER.NE.0) THEN 
		 WRITE (6,'('' There are no folders.'')')F
	         CALL CLOSE_BULLFOLDER 
		 FOLDER_COUNT = -1
		 RETURN<
	      ELSE)
		 START = .TRUE._
	      END IF
	   END IF
	   MATCH = CLI$GET_VALUE('MATCH_FOLDER',FOLDER_MATCH,MLEN)E
	   IF (MATCH.AND.NEWS) CALL LOWERCASE(FOLDER_MATCH)
	   IF (MATCH.AND.INDEX(FOLDER_MATCH,'*').EQ.0) THEN
	      FOLDER_MATCH = '*'//FOLDER_MATCH(:MLEN)//'*'
	      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 = -13
	   RETURN
	ELSE IF (SUBSCRIBE.AND.PAGING.AND.MORE) THEN(
	   SUBNUM = -2E
	ELSEH
	   CALL READ_FOLDER_FILE_KEYNAME_TEMP(FOLDER1,IER)'
	END IF 

CS
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 memoryH
C  is structured as a linked-list queue, where SCRATCH_D1 points to the header
C  of the queue.
CA
	CALL INIT_QUEUE(SCRATCH_D1,FOLDER1_COM)
	SCRATCH_D = SCRATCH_D1I

	CALL DECLARE_CTRLC_AST1

	NUM_FOLDER = 0W
	IER = 0
	IER1 = 0a
	MORE = .FALSE.
	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 = -1F
		 END IF,
	      END DOW
	      IF (SUBNUM.EQ.0) IER = 1t
	   ELSE IF (PERM.OR.DEFA) THEN 
	      IER = 1
	      DO WHILE (INUM.LE.FOLDER_MAX.AND.IER.NE.0) 
		 IF (INF_REC2(1,INUM).NE.0) THEN
	            CALL READ_FOLDER_FILE_KEYNUM_TEMP
     &				(ZEXT(INF_REC2(1,INUM)),IER)
		 END IFF
		 INUM = INUM + 1
	      END DO 
	   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 = 22
	            NEW_NEWS = FOLDER1_NUMBER
	         END IF
	      END DOO
	      IF (IER.EQ.0) THEN 
	         NEW_NEWS = FOLDER1_NUMBERD
	      ELSEE
	         CALL READ_FOLDER_FILE_KEYNAME_TEMP('a',IER2)
	         NEW_NEWS = NEWS_F1_COUNT
	      END IF 
	   ELSE
	      CALL READ_FOLDER_FILE_TEMP(IER)
	      IF (CLASS) CALL LOWERCASE(FOLDER1_DESCRIP)M
	      IF (CLASS) NEWS_TEST = .FALSE.	
	      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)) THENN
	               OLD_BUFFER = NEWS_ACCESS(FOLDER1_DESCRIP)W
		       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)),G
     &		           USERNAME,READ_ACCESS,-1)_
                       ELSEE
                          READ_ACCESS = 1n
                       END IF 
	            END IFA
	         ELSE
	            CALL CHECK_ACCESS
     &		     (FOLDER1_FILE(:TRIM(FOLDER1_FILE))//'.BULLFIL',
     &		      USERNAME,READ_ACCESS,-1)
	         END IF
	      ELSEF
		 READ_ACCESS = 1
	      END IF 
	      IF (READ_ACCESS) THEN
	         J = INDEX(FOLDER1_DESCRIP,' ')
	         IF (J.GT.0) THEN
	            FSTATUS1(:1) = FOLDER1_DESCRIP(J+1:)I
		 ELSEN
	            FSTATUS1 = ' ')
	         END IF
		 IF (.NOT.NEWS_TEST) THEND
		    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 IFL
	      IF (PAGING.AND.NUM_FOLDER*NLINE+2.GT.PAGE_LENGTH-4) THENw
		 IER1 = 1'
		 MORE = .TRUE.
	      END IFE
	   END IF
	   IF (FLAG.EQ.1) IER1 = 1S
	END DOD

 	IF (NEWS_TEST) NEWS_TEST = .FALSE.

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

 	IF (FLAG.EQ.1) THEN:
	   WRITE (6,'('' Folder search aborted.'')')
	   FOLDER_COUNT = -1R
	   RETURN
	END IFT

	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 IF

CU
C  Folder entries are now in queue.  Output queue entries to screen.
CH

     	SCRATCH_D = SCRATCH_D1			! Init queue pointer to header

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,''News group'',<PAGE_WIDTH-80+39>X,6X,
     &		''First        Last  Count'',
     &		/,1X,<PAGE_WIDTH>(''-''))') 
	ELSE IF (CLASS) THEN(
	   WRITE (6,'(1X,''Class'',/,1X,<PAGE_WIDTH>(''-''))')T
	ELSE IF (SUBSCRIBE) THEN 
	   WRITE (6,'(1X,''News group'',<PAGE_WIDTH-80+39>X,1X,
     &		''First        Last   Last Read'',/,1X,<PAGE_WIDTH>(''-''))')=
	ELSE.
	   WRITE (6,'(1X,''News group'',<PAGE_WIDTH-80+39>X,''Status'',7X,
     &		''First        Last'',/,1X,<PAGE_WIDTH>(''-''))')1
	END IF 

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

	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) 
	      I = I + 1
	   END IF
	   IF (.NOT.NEWS) THENT
	      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,)
	      ELSEs
	         DATETIME = '      NONE'e
	      END IF 
	      IF (DIFF.GE.0.OR.F1_NBULL.EQ.0) THEN
	         WRITE (6,1000) ' '//FOLDER1,DATETIME(:17),F1_NBULL, 
     &							FOLDER1_OWNER
	      ELSEL
	         WRITE (6,1000) '*'//FOLDER1,DATETIME(:17),F1_NBULL, 
     &							FOLDER1_OWNER
	      END IFC
	   ELSE
	      IF (NEWS_TEST) UNLOCK 7
	      FLEN = MIN(80,PAGE_WIDTH-80+49)
	      IF (SUBSCRIBE) FLEN = MIN(81,PAGE_WIDTH-80+42)E
	      J = INDEX(FOLDER1_DESCRIP,' ')'
	      IF (J.GT.0) THENL
	         FSTATUS1(:1) = FOLDER1_DESCRIP(J+1:)
		 IF (FSTATUS1(:1).NE.'=') THEN
                    FOLDER1_DESCRIP = FOLDER1_DESCRIP(:J-1)U
                 END IFD
	      ELSEI
	         FSTATUS1 = ' '
	      END IF_
	      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,0E
		 END IF 
              ELSE IF (CLASS) THEN
                 WRITE (6,1010) FOLDER1_DESCRIP(:FLEN)
	      ELSE IF (F1_START.LE.F1_NBULL) THEN
		 IF (SUBSCRIBE) THEN
                    NEWS_FOLDER1_NUMBER = FOLDER1_NUMBER
		    CALL NEWS_GET_NEWEST_MESSAGE1(NEWS_NEW)R
		    IF (NEWS_NEW-1.LT.F1_NBULL.AND.F1_NBULL.GT.0) THEN
	               WRITE (6,1015) '*'//FOLDER1_DESCRIP(:FLEN-1),D
     &					F1_START,F1_NBULL,NEWS_NEW-1(
		    ELSE
	               WRITE (6,1015) ' '//FOLDER1_DESCRIP(:FLEN-1), 
     &					F1_START,F1_NBULL,NEWS_NEW-1 
		    END IF
		 ELSE 
		    WRITE (6,1005) FOLDER1_DESCRIP(:FLEN),
     &					 FSTATUS1(:1),F1_START,F1_NBULL
		 END IFR
	      ELSE IF (SUBSCRIBE) THENC
	         WRITE (6,1015) ' '//FOLDER1_DESCRIP(:FLEN-1),0,0,0
	      ELSE(
		 WRITE (6,1005) FOLDER1_DESCRIP(:FLEN),FSTATUS1(:1),0,0T
	      END IFd
	   END IF
	   IF (NLINE.EQ.2) WRITE (6,'(1X,A)') FOLDER1_DESCRIP
	   LAST_DISPLAY = FOLDER1_NUMBER=
	   IF (NEWS_TEST.AND.FLAG.NE.1) THEN 
	      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)A
	         CALL READ_FOLDER_FILE_TEMP(IER) 
	         J = INDEX(FOLDER1_DESCRIP,' ')
	         IF (J.GT.0) THEN
	            FSTATUS1(:1) = FOLDER1_DESCRIP(J+1:)T
		 ELSEA
	            FSTATUS1 = ' 'T
	         END IF
		 IF (IER.EQ.0.AND.(.NOT.ACTIVE.OR.(FSTATUS1(:1).NE.'x'.AND.-
     &			   .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)) THENh
	               IF (OLD_BUFFER.NE.NEWS_ACCESS(FOLDER1_DESCRIP)) THEN
	                  OLD_BUFFER = NEWS_ACCESS(FOLDER1_DESCRIP)
		          CALL CHKACL(OLD_BUFFER(:TRIM(OLD_BUFFER)),IER2)u
	   	          IF (IER2.NE.(SS$_ACLEMPTY.OR.SS$_NORMAL)) THEN=
	                     CALL CHECK_ACCESS(OLD_BUFFER
     &		              (:TRIM(OLD_BUFFER)),USERNAME,FOUND1,-1)M
                          ELSE
                             FOUND1 = .TRUE.
	                  END IF 
                       END IFI
	               FOUND = FOUND1
		    ELSE
		       FOUND = .TRUE.B
	            END IF 
		 END IF 
	      END DOE
	      MORE = MORE.AND.FOUND
	      IF (MORE) THEN=
		 CALL READ_FOLDER_FILE_KEYNUM_TEMP(LAST_DISPLAY,IER)
              END IF
	      FOUND = FOUND.AND..NOT.MORE
	      IF (.NOT.FOUND) FLAG = 1E
	   END IF
	END DO

	IF (NEWS_TEST) THEN
	   CALL CANCEL_CTRLC_ASTL
	   CALL CLOSE_BULLFOLDERE
	END IF&

	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
	ELSEI
	   WRITE(6,1100)			! Else say there are more	
	   IF (NEW) LAST_NEWS_READ(1,FOLDER_MAX) = FOLDER1_NUMBER
	END IFF

	RETURND

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

	END


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

	IMPLICIT INTEGER (A-Z)L

	INCLUDE 'BULLFOLDER.INC'N

	INCLUDE 'BULLUSER.INC'E

	INCLUDE '($SSDEF)'1

	INCLUDE '($RMSDEF)'

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	LOGICAL ACCESS,ALL,READONLY

	EXTERNAL CLI$_ABSENTR

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

	CHARACTER INPUT*132

	IF (CLI$PRESENT('ALL')) THENE
	   ALL = .TRUE.
	ELSE 
	   ALL = .FALSE.E
	END IFD

	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 IF_

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

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

	IF (IER.NE.0) THENT
	   WRITE (6,'('' ERROR: No such folder exists.'')')
	ELSE IF (.NOT.FOLDER_ACCESS(USERNAME,FOLDER1_FLAG,FOLDER1_OWNER)) THEN,
	   WRITE (6,&
     &	'('' ERROR: You are not able to modify access to the folder.'')')
	ELSE IF (CLI$PRESENT('CLASS').AND..NOT.BTEST(FOLDER1_FLAG,0)) THEN 
	   WRITE (6,'('' ERROR: Must use SET NEWS/CLASS/PRIVATE.'')')
	ELSE.
	   CALL SET_FOLDER_FILE(1) 
	   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),R
     &			STATUS='NEW',IOSTAT=IER)F
	     CLOSE (UNIT=3)
	     CALL RESET_PROTECTIONl
	     IF (IER.NE.0) THEN
	        WRITE (6,'('' ERROR: Access file cannot be created.'')') 
	        RETURN
	     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)) THEN6
	     IF (.NOT.NEWS.AND.
     &		 ((ALL.AND..NOT.READONLY).OR.(.NOT.ACCESS))) THEN6
	        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') THEN.
	       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)P
	       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) THEN7
		       CALL SET_FOLDER_FILE(1)
		       FOLDER_FILE = FOLDER1_FILEM
		       REMOTE_SET_SAVE = REMOTE_SETD
		       REMOTE_SET = .FALSE. 
		       CALL OPEN_BULLDIR
		       CALL OPEN_BULLFIL
		       CALL CLOSE_BULLFIL_DELETE
		       CALL CLOSE_BULLDIR_DELETE
		       REMOTE_SET = REMOTE_SET_SAVE 
		       CALL SET_FOLDER_FILE(0)
		    END IF
		 END IF'
	      ELSEI
		 CALL DEL_ACL('*','R',IER)
	      END IF1
	      IF (.NOT.IER) THENH
		 WRITE(6,'('' Cannot modify access.'')')
		 CALL SYS_GETMSG(IER)L
	      END IFN
	   END IF

	   DO WHILE (CLI$GET_VALUE('ACCESS_ID',INPUT,ILEN)T
     &	    .NE.%LOC(CLI$_ABSENT).AND..NOT.ALL)
	      IER = SYS_TRNLNM(INPUT,INPUT)
	      IF (INPUT(:1).EQ.'@') THEN 
		 ILEN = INDEX(INPUT,',') - 1
		 IF (ILEN.EQ.-1) ILEN = TRIM(INPUT) 
		 OPEN (UNIT=3,STATUS='OLD',FILE=INPUT(2:ILEN),
     &			DEFAULTFILE='.DIS',IOSTAT=IER)F
		 IF (IER.NE.0) THEN_
		    WRITE (6,'('' ERROR: Cannot find file '',A)')R
     &					INPUT(2:ILEN)
		    RETURN
		 END IF0
		 READ (3,'(A)',IOSTAT=IER) INPUT
		 IF (IER.NE.0) THEN(
		    CLOSE (UNIT=3)
		    INPUT = ' 'N
		 ELSE(
		    FILE_OPEN = .TRUE.
		 END IF6
	      ELSEO
		 FILE_OPEN = .FALSE.
	      END IF_
	      DO WHILE (TRIM(INPUT).GT.0)
	         COMMA = INDEX(INPUT,',')
		 IF (INPUT(:1).EQ.'[') COMMA = INDEX(INPUT,']') + 1T
		 IF (INPUT(:1).EQ.'"') COMMA = INDEX(INPUT(2:),'"') + 2
	         IF (COMMA.GT.0) THEN
		    ID = INPUT(1:COMMA-1)
		    INPUT = INPUT(COMMA+1:) 
	         ELSE
		    ID = INPUT
		    INPUT = ' 'I
	         END IF
	         ILEN = TRIM(ID)'
	         IF (.NOT.NEWS.AND.ID.EQ.FOLDER1_OWNER) THENM
	            WRITE (6,'('' ERROR: Cannot modify access'',L
     &			       '' for owner of folder.'')')
		 ELSE 
		    IF (ACCESS) THEN
	               IF (READONLY) THEN
	                  CALL ADD_ACL(ID,'R',IER)D
		       ELSEN
	                  CALL ADD_ACL(ID,'R+W',IER)P
		       END IF 
	            ELSEE
	               CALL DEL_ACL(ID,'R+W',IER)
	               IF (.NOT.IER) CALL DEL_ACL(ID,'R',IER)
	            END IFS
	            IF (.NOT.IER) THEN 
		       WRITE(6,'('' Cannot modify access for '',A,
     &					''.'')') ID(:ILEN)E
		       CALL SYS_GETMSG(IER) 
		    ELSE
		       WRITE(6,'('' Access modified for '',A,''.'')')N
     &				ID(:ILEN)_
		    END IF
		 END IF 
	         IF (TRIM(INPUT).EQ.0.AND.FILE_OPEN) THEN
		    READ (3,'(A)',IOSTAT=IER) INPUTL
		    IF (IER.NE.0) THEN
		       CLOSE (UNIT=3)S
		       INPUT = ' '
		       FILE_OPEN = .FALSE.
		    END IF
		 END IFO
	      END DO
	   END DO
	   
100	   IF (OLD_FOLDER1_FLAG.NE.FOLDER1_FLAG) THEN 
	      IF (NEWS) THEN_
	         CALL OPEN_BULLNEWS
	      ELSE 
	         CALL OPEN_BULLFOLDER
	      END IF	
	      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 IF 

	RETURN 

	END



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

	IMPLICIT INTEGER (A-Z) 

	CHARACTER*(*) FILENAME

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

	CHARACTER*256 ACLENTL

	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) THENM
	   IERACL = SS$_NORMAL.OR.IERACL,
	END IF 

	RETURNe
	END



	SUBROUTINE CHECK_ACCESS(FILENAME,USERNAME,READ_ACCESS,WRITE_ACCESS)
C
C  SUBROUTINE CHECK_ACCESS
C2
C  FUNCTION: Checks ACL of given file.
C>
C  PARAMETERS:
C	FILENAME - Name of file to check.0
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_

	IMPLICIT INTEGER (A-Z)t

	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,
     &		%VAL(ACL_ITMLST))T


	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) THENO
	   READ_ACCESS = 0e
	END IFE

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

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

	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 IF(

	RETURN_
	END




	SUBROUTINE SHOWACL(FILENAME)T
C,
C  SUBROUTINE SHOWACL&
C'
C  FUNCTION: Shows users who are allowed to read private bulletin.
CF
C  PARAMETERS:
C	FILENAME - Name of file to check.)
CE
	IMPLICIT INTEGER (A-Z)O

	INCLUDE '($ACLDEF)'

	CHARACTER*(*) FILENAME 

	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),,,)A

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

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

	RETURN 
	END



	SUBROUTINE FOLDER_FILE_ROUTINES

	IMPLICIT INTEGER (A-Z)

	CHARACTER*(*) KEY_NAMER

	INCLUDE 'BULLFOLDER.INC'e

	COMMON /NEWS_OPEN/ NEWS_OPEN 

	ENTRY WRITE_FOLDER_FILE(IER)O

	IF (NEWS_OPEN) CALL FOLDER_TO_NEWSR

	DO WHILE (REC_LOCK(IER))s
	   IF (NEWS_OPEN) THENS
	      WRITE (7,IOSTAT=IER) NEWS_FOLDER_COMI
	   ELSE
	      WRITE (7,IOSTAT=IER) FOLDER_COM
	   END IF
	END DOT

	RETURNO

        ENTRY WRITE_FOLDER_FILE_TEMP(IER)L

        IF (NEWS_OPEN) CALL FOLDER1_TO_NEWS 

        DO WHILE (REC_LOCK(IER))
           IF (NEWS_OPEN) THEN
              WRITE (7,IOSTAT=IER) NEWS_FOLDER1_COM(
           ELSEP
              WRITE (7,IOSTAT=IER) FOLDER1_COM
           END IFA
        END DO

        RETURN

	ENTRY REWRITE_FOLDER_FILE(IER)R

	IF (NEWS_OPEN) THEN
	   CALL FOLDER_TO_NEWSN
	   REWRITE (7,IOSTAT=IER) NEWS_FOLDER_COM
	ELSEE
	   REWRITE (7,IOSTAT=IER) FOLDER_COM 
	END IF.

	RETURNt

	ENTRY REWRITE_FOLDER_FILE_TEMP(IER) P

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

	RETURNF

	ENTRY READ_FOLDER_FILE(IER)

	DO WHILE (REC_LOCK(IER))D
	   IF (NEWS_OPEN) THEN 
	      READ (7,IOSTAT=IER) NEWS_FOLDER_COM
	   ELSE
	      READ (7,IOSTAT=IER) FOLDER_COM 
	   END IF
	END DOD

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

	RETURNf

	ENTRY READ_FOLDER_FILE_TEMP(IER)(

	DO WHILE (REC_LOCK(IER))m
	   IF (NEWS_OPEN) THEN0
	      READ (7,IOSTAT=IER) NEWS_FOLDER1_COM
	   ELSE
	      READ (7,IOSTAT=IER) FOLDER1_COM
	   END IF
	END DO,

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

	RETURN,

	ENTRY READ_FOLDER_FILE_KEYNUM(KEY_NUMBER,IER)

	SAVE_FOLDER_NUMBER = FOLDER_NUMBER

	DO WHILE (REC_LOCK(IER))M
	   IF (NEWS_OPEN) THENC
	      READ (7,KEY=KEY_NUMBER,KEYID=1,IOSTAT=IER) NEWS_FOLDER_COM 
	   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_NUMBER_

	RETURN 

	ENTRY READ_FOLDER_FILE_KEYNUM_GT(KEY_NUMBER,IER)_

	DO WHILE (REC_LOCK(IER))
	   IF (NEWS_OPEN) THEN
	      READ (7,KEYGT=KEY_NUMBER,KEYID=1,IOSTAT=IER) NEWS_FOLDER_COME
	   ELSE
	      READ (7,KEYGT=KEY_NUMBER,KEYID=1,IOSTAT=IER) FOLDER_COM
	   END IF
	END DON

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

	RETURN 

	ENTRY READ_FOLDER_FILE_KEYNUM_TEMP(KEY_NUMBER,IER)R

	DO WHILE (REC_LOCK(IER)) 
	   IF (NEWS_OPEN) THEN)
	      READ (7,KEY=KEY_NUMBER,KEYID=1,IOSTAT=IER) NEWS_FOLDER1_COM
	   ELSE
	      READ (7,KEY=KEY_NUMBER,KEYID=1,IOSTAT=IER) FOLDER1_COMF
	   END IF
	END DOT

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

	RETURN 

	ENTRY READ_FOLDER_FILE_KEYNUM_GT_TEMP(KEY_NUMBER,IER)

	DO WHILE (REC_LOCK(IER))'
	   IF (NEWS_OPEN) THEN 
	      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 DO 

	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))M
	   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_COM 
	   END IF
	END DO 

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

	RETURNN

	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_FOLDER1I

	RETURN 

	ENTRY READ_FOLDER_FILE_KEYNAMEGT_TEMP(KEY_NAME,IER)

	DO WHILE (REC_LOCK(IER)) 
	   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 DOM

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

	RETURN'

	ENTRY READ_FOLDER_FILE_KEYNAME(KEY_NAME,IER)

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

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

	RETURN 

	END


	SUBROUTINE USER_FILE_ROUTINES

	IMPLICIT INTEGER (A-Z) 

	INCLUDE '($PRVDEF)'

	INCLUDE '($FORIOSDEF)'L

	CHARACTER*(*) KEY_NAMED

	INCLUDE 'BULLUSER.INC'A

	CHARACTER*12 SAVE_USERNAMEE

	ENTRY READ_USER_FILE(IER)

	SAVE_USERNAME = USERNAMEA

	DO WHILE (REC_LOCK(IER))C
	   READ (4,IOSTAT=IER) USER_ENTRY
	END DOL

	TEMP_USER = USERNAMEN
	USERNAME = SAVE_USERNAME

	RETURN

	ENTRY READ_USER_FILE_KEYNAME(KEY_NAME,IER)S

	SAVE_USERNAME = USERNAMET

	DO WHILE (REC_LOCK(IER)).
	   READ (4,KEY=KEY_NAME,IOSTAT=IER) USER_ENTRYo
	END DO

	USERNAME = SAVE_USERNAMEo
	TEMP_USER = KEY_NAMEE

	RETURNP

	ENTRY READ_USER_FILE_HEADER(IER))

	DO WHILE (REC_LOCK(IER))D
	   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
	_
	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
