.TITLE AUXOPE - Open Files for Read/Write .IDENT /1.0/ .ENABL LC ;+ ; ; Free software BY ; Project Software & Development, Inc. ; ; This software is furnished for free and may be used and copied as ; desired. This software or any other copies thereof may be provided ; or otherwise made available to any other person. No title to and ; ownership of the software is hereby transferred or allowed. ; ; The information in this software is subject to change without notice ; and should not be construed as a commitment by PROJECT SOFTWARE ; AND DEVELOPMENT, INC. ; ; PROJECT SOFTWARE assumes no responsibility for the use or reliability ; of this software on any equipment whatsoever. ; ; Project Software & Development, Inc. ; 14 Story St. ; Cambridge, Ma. 02138 ; 617-661-1444 ; ; ; Title: AUXLOPE ; Author: Robin Miller ; Date: July 23, 1985 ; ; Description: ; ; This module is called to open a file for read or write. It ; does all the neccessary syntax checking using the CSI routines, parsing ; of the file specification, and opening of the file. It presumes the FDB ; is setup with all the required information such as the LUN, the EFN, the ; record attributes, and the access mode. ; ; Modification History: ; ;- .ENABL AMA ; DEBUG = 0 ; Define for DDT debugging. .MCALL CSI$, CLOSE$, FCSBT$, FDOFF$, NBOFF$ .psect code,ro,i,lcl,rel,con ; Bit and offset definitions: CSI$ ; Define the CSI offsets. .IF NDF DEBUG FCSBT$ ; Define the FCS bits locally. FDOFF$ DEF$L ; Define the FDB offsets locally. NBOFF$ DEF$L ; Define the FNB offsets locally. .IFF FCSBT$ DEF$G ; Define the FCS bits globally. FDOFF$ DEF$G ; Define the FDB offsets globally. NBOFF$ DEF$G ; Define the FNB offsets globally. .ENDC ; .IF NDF DEBUG ; Define offsets for the dataset descriptor block: N.DEVD == 0 ; The device name descriptor. N.DIRD == 4 ; The directory descriptor. N.FILD == 10 ; The file name descriptor. .SBTTL Command String Interpreter (CSI) block. ; ; Scratch storage for wild UIC logic consists of a file name block ; followed by the following extra words. Also defined in PARSE.MAC. ; ; N.WNM1 = S.FNB ; 2 words for RAD50 non wild card ; ; project or programmer name. ; N.WNM2 = N.WNM1+4 ; 6 words of string storage for ; ; ASCII form of current directory name. S.WUIC = S.FNB+16. ; NO. OF BYTES IN SCRATCH AREA NB.SFL = NB.SD1!NB.SD2!NB.SNM!NB.STP!NB.SVR ; All wildcard bits. .psect rwdata,rw,d,lcl,rel,con INCSI1::.BLKB C.SIZE ; CSI buffer for one input file. .psect code,ro,i,lcl,rel,con .SBTTL OPEN - Open a file for read or write access. ;+ ; ; OPEN - Open a file for read or write access. ; ; This routine is used to open a single file for either read or write. If ; the file is already open on entry, it will be closed automatically. If ; the file access offset (F.FACC) in the FDB is not setup, it will be filled ; with either shared read (FO.RD!FA.SHA) or write without supercede ; (FO.WRT!FA.NSP). The Command String Interpreter (CSI) routines are used ; to check for syntax errors. If no error is returned from the CSI routines, ; then the file is openned for either read or write. ; ; The error code IE.BNM (bad file name) is returned if errors are encountered ; by the CSI routines. ; ; Inputs: ; R0 = The FDB address. ; R1 = The file specification address. ; R5 = The file entry address. ; ; Outputs: ; C bit clear/set = success/failure. ; All registers are preserved. ; ;- OPENR:: TSTB F.FACC(R0) ; Is the file access setup ? BNE OPEN ; If NE, yes. MOVB #FO.RD!FA.SHR,F.FACC(R0) ; No, setup for shared read. BR OPEN ; Continue ... OPENW:: TSTB F.FACC(R0) ; Is the file access setup ? BNE OPEN ; If NE, yes. MOVB #FO.WRT!FA.NSP,F.FACC(R0) ; No, setup for write/no supercede. .ENABL LSB OPEN: CALL $SAVAL ; Save all registers. CALL CKOPEN ; If the file is open, close it. CALL CLNAME ; Clear the file name from the FNB. CALL CHKCSI ; Check the command syntax. BCS 20$ ; If CS, illegal syntax. ; Parse the file name and open the file for read or write. MOV O.FNB(R5),R1 ; Copy the FNB address. MOV O.CSI(R5),R3 ; Copy the CSI block address. ; When opening files for a read operation, if no wildcards were ; specified we use the normal parsing, otherwise we use the ; wildcard parsing routine. BITB #CS.WLD,C.STAT(R3) ; Any wildcards in file specification ? BEQ 10$ ; If EQ, no (use normal parse). BITB #FO.RD,F.FACC(R0) ; Opening a file for read access ? BNE 10$ ; If NE, yes (do the open). SEC ; Presume wildcards or mulitple files. BITB #CS.MOR!CS.WLD,C.STAT(R3) ; Wildcards or multiple files ? BNE 20$ ; If NE, yes (illegal for write). 10$: MOV F.DSPT(R0),R2 ; Address of dataset descriptor. MOV F.DFNB(R0),R3 ; Address of the default FNB. CALL .PARSE ; Parse the file specification. BCS 20$ ; If CS, we had an error. CALL .OPFNB ; Else, open the file for write. 20$: RETURN .DSABL LSB .SBTTL CKOPEN - Check for open file. ;+ ; ; CKOPEN - Check for open file and close it if open. ; ; Inputs: ; R0 = The FDB address. ; ; Outputs: ; All registers are preserved. ; ;- CKOPEN: TST F.BDB(R0) ; Is the file already open ? BEQ 10$ ; If EQ, no. CLOSE$ R0 ; Yes, close it. 10$: RETURN .SBTTL CLNAME - Clear the file name in the FNB. ;+ ; ; CLNAME - Clear the file name in the FNB. ; ; This routine clears the file name (if any) in the FNB so that old file ; name information is not used when constructing an ASCII file name for ; error messages if a syntax error occurs in the CSI routines. ; ; Inputs: ; R0 = The FDB address. ; ; Outputs: ; All registers are preserved. ; ;- CLNAME: JSR R2,$SAVVR ; Save R0 - R2. ADD #F.FNB+N.FNAM,R0 ; Set address of the file name. MOV #5.,R1 ; Set size in words of file name. 10$: CLR (R0)+ ; Clear the file name. SOB R1,10$ ; And loop until done. RETURN .SBTTL CHKCSI - Check file name using CSI routines ;+ ; ; CHKCSI - Use CSI routines to check the filspc syntax. ; ; Inputs: ; R0 = The FDB address. ; R1 = File specification address. (terminated by NULL or ). ; R5 = The file entry address. ; ; Outputs: ; C bit clear/set = success/failure. ; All registers are preserved. ; ;- CHKCSI::CALL $SAVAL ; Save all registers. ;*** CLR F.DSPT(R0) ; Clear the dataset pointer. CLR F.ERR(R0) ; Initialize the FCS error code. BISB #IE.BNM,F.ERR(R0) ; Preset to "Bad file name" error. MOV O.CSI(R5),R3 ; Copy the CSI block address. MOV R3,F.DSPT(R0) ; Setup the dataset ADD #C.DSDS,F.DSPT(R0) ; descriptor address. ; Clear the CSI block so old information isn't used. MOV #C.SIZE/2,R2 ; SET THE CSI SIZE IN WORDS 10$: CLR (R3)+ ; CLEAR THE CSI BLOCK SOB R2,10$ ; BR UNTIL DONE MOV O.CSI(R5),R0 ; Set the CSI block address. MOV R1,C.CMLD+2(R0) ; Save the filspc address. ; Find the end of the file specification (either CR or NULL). 20$: CMPB (R1),#CR ; End of the file name ? BEQ 30$ ; If EQ, yes. TSTB (R1)+ ; End of the file name ? BNE 20$ ; If NE, nope (loop). DEC R1 ; Adjust for the null byte. ; Calculate the length of the file specification. 30$: SUB C.CMLD+2(R0),R1 ; Calculate the byte count. BEQ 50$ ; If EQ, don't do CSI parsing. MOV R1,C.CMLD(R0) ; Now save it. ; Check the syntax of the file specification. CALL .CSI1 ; Check the string syntax. BCS 60$ ; If CS, bad syntax. MOVB #CS.OUT,(R0) ; Set for output file parsing. CALL .CSI2 ; Parse the file specification. BCS 60$ ; If CS, syntax error. 50$: CLC ; Show success. RETURN 60$: SEC ; Show syntax error. RETURN .END