OBJNAM RDONLY.LIT ; Created 18-Mar-87, Irv Bromberg, edited 18-Mar-87
RADIX 10
VMAJOR=1
VMINOR=0
VEDIT=1

SEARCH SYS
SEARCH SYSSYM
SEARCH TRM

if eq,1

Fetches LIB:RDONLY.VUX into MEM: and renames it to TDVNAM.VUX where TDVNAM is
the name of the user's current terminal driver.  The next time AlphaVUE is
used the user will not be able to modify the file.  To return to normal
operation use the command DEL *.VUX.

It is possible for TDVNAM.VUX to already be memory if RDONLY was
previously executed.  This program checks for a RAD50 signature [RDONLY]
at the end of the module and when it is there it considers the module to
be a valid copy of RDONLY.VUX and so does not re-fetch it from the disk.
When the signature is not present the TDVNAM.VUX file is deleted and a
new copy of LIB:RDONLY.VUX is fetched and renamed to TDVNAM.VUX.

Application:  This command allows read-only AlphaVUE text editing to be
set up without special tricks to figure out the user's current terminal
driver name and how to force a command to be executed to load and rename
the file.

endc

JCB=A0
TDV=A2
DDB=A3
Module=A4
TCB=A5
Atemp=A6

TDVNAM=D0
Size=D1

       PHDR    -1,0,PH$REE!PH$REU

       MOV     JOBCUR,JCB
       MOV     JOBTRM(JCB),TCB         ; get user's TCB
       MOV     T.TDV(TCB),TDV          ; get user's TDV
       MOV     -4(TDV),TDVNAM          ; get user's TDVNAM
       LEA     DDB,JOBRBK(JCB)         ; use JOBRBK as temp DDB for sch/fetch
       MOV     TDVNAM,D.FIL(DDB)       ; look for MEM:TDVNAM.VUX first
       MOVW    #[VUX],D.EXT(DDB)       ; .VUX
       SRCH    D.FIL(DDB),Module,F.USR ; search MEM: only
       BNE     Disk                    ; not found, get from disk
       MOV     -12(Module),Size        ; get size of found module
       CMP     -12-4(Module)[Size],#[RDO]_16+[NLY] ; RDONLY signature there?
       BNE     Clobber                 ; no, clobber that module
       EXIT                            ; yes, all done

Clobber: ANDW   #^C<PRM>,-8(Module)     ; cause old module to be deleted
       CLRW    -2(Module)              ; and zap it's extension
       ; now force the required VUX file to be loaded from disk

Disk:   ; TDVNAM.VUX not found or does not have valid RDONLY signature
       ; so fetch LIB:RDONLY.VUX and rename it
       MOVW    #[DSK],D.DEV(DDB)       ; [DSK]
       CLRW    D.DRV(DDB)              ; drive #0
       CLR     D.DVR(DDB)              ; make monitor get the driver
       MOVW    #7_8!0,D.PPN(DDB)       ; [7,0]
       MOV     #[RDO]_16+[NLY],D.FIL(DDB) ; RDONLY
       FETCH   @DDB,Module,F.USR       ; fetch but search MEM: only
       BEQ     OK
       TYPE    <?>                     ; ?DSK0:RDONLY.VUX[7,0] not found
       PFILE   @DDB
       TYPECR  < not found>
       EXIT

OK:     ORW     #FIL,-8(Module)         ; prevent EXIT from deleting it
       MOV     TDVNAM,-6(Module)       ; rename module to TDVNAM
       EXIT

       END