.TITLE OPENRW - OPEN A FILE FOR READ/WRITE .IDENT /1.1/ .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: OPENRW.MAC ; Author: Robin Miller ; Date: May 28, 1982 ; ; Description: ; ; This module is called to open a file for either read or write. ; It does all the neccessary syntax checking and parsing of the file ; specification into the File Descriptor Block (FDB). 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: ; ; August 10, 1982 by Robin Miller Version 1.1 ; Return bad file name error (IE.BNM) on syntax errors from CSI$. ; ;- .ENABL AMA ; DEBUG = 0 ; DEFINE FOR DDT DEBUGGING .MCALL CSI$, CLOSE$, FCSBT$, FDOFF$, NBOFF$ ; Bit and offset definitions. CSI$ ; DEFINE CSI OFFSETS .IF NDF DEBUG FCSBT$ ; DEFINE FCS BITS FDOFF$ DEF$L ; DEFINE FDB OFFSETS NBOFF$ DEF$L ; DEFINE FNB OFFSETS .IFF .GLOBL CSIBLK FCSBT$ DEF$G ; DEFINE FCS BITS GLOBALLY FDOFF$ DEF$G ; DEFINE FDB OFFSETS GLOBALLY NBOFF$ DEF$G ; DEFINE FNB OFFSETS GLOBALLY .ENDC ; Local Equates. CR = 15 ; ASCII FOR CARRIAGE RETURN ; Command String Interpreter (CSI) block. CSIBLK: .BLKB C.SIZE ; ALLOCATE A CSI BUFFER .EVEN ;+ ; ; OPENR - Opens a file for read. ; OPENW - Opens a file for write. ; ; 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 address of the FDB. ; R1 = address of the file specification. ; ; 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, PRSEUME YES MOVB #FO.RD!FA.SHR,F.FACC(R0) ; SETUP THE FDB FOR READ BR OPEN ; DO REST OF OPEN CODE OPENW:: TSTB F.FACC(R0) ; IS THE FILE ACCESS SETUP ? BNE OPEN ; IF NE, PRESUME YES MOVB #FO.WRT!FA.NSP,F.FACC(R0) ; SETUP THE FDB FOR WRITE OPEN: CALL $SAVAL ; SAVE ALL REGISTERS ; If an output file is already open, we'll close it. TST F.BDB(R0) ; IS THE FILE ALREADY OPEN ? BEQ 10$ ; IF EQ, NO CLOSE$ R0 ; YES, CLOSE IT 10$: CLR F.DSPT(R0) ; CLEAR THE DATASET POINTER CLR F.ERR(R0) ; INITIALIZE THE FCS ERROR BISB #IE.BNM,F.ERR(R0) ; NOW SET IT TO BAD FILE NAME 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 R0,R1 ; COPY THE FDB ADDRESS ADD #F.FNB,R1 ; POINT TO THE FNB ADDRESS 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, ERROR CALL .OPFNB ; OPEN THE FILE FOR WRITE 20$: RETURN ;+ ; ; CHKCSI - Use CSI routines to check the filspc syntax. ; ; Inputs: ; R0 = the FDB address. ; R1 = file specification address. ; (terminated by NULL or ). ; ; Outputs: ; C bit clear/set = success/failure. ; All registers are preserved. ; ;- CHKCSI: CALL $SAVAL ; SAVE ALL REGISTERS MOV R0,R4 ; COPY THE FDB ADDRESS ; Clear the CSI block so old information isn't used. MOV #C.SIZE/2,R2 ; SET THE CSI SIZE IN WORDS MOV #CSIBLK,R3 ; SET ADDRESS OF CSI BLOCK 10$: CLR (R3)+ ; CLEAR THE CSI BLOCK SOB R2,10$ ; BR UNTIL DONE MOV #CSIBLK,R0 ; ADDRESS OF CSI BLOCK MOV R1,C.CMLD+2(R0) ; SAVE THE FILSPC ADDRESS ; Find the end of the file specification. 20$: CMPB (R1),#CR ; AT END OF FILE NAME ? BEQ 30$ ; IF EQ, YES TSTB (R1)+ ; END OF FILE NAME ? BNE 20$ ; IF NE, NO (LOOP) DEC R1 ; ADJUST FOR THE NULL ; 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 MOV R1,C.CMLD(R0) ; AND SAVE IT ; Check the syntax of the file specification. CALL .CSI1 ; CHECK THE SYNTAX BCS 60$ ; IF CS, BAD SYNTAX MOVB #CS.OUT,(R0) ; SET FOR OUTPUT FILE CALL .CSI2 ; PARSE FILE SPECIFICATION BCS 60$ ; IF CS, ERROR 40$: MOV #CSIBLK+C.DSDS,F.DSPT(R4) ; POINT TO DATASET DESCRIPTOR BITB #CS.MOR!CS.WLD,CSIBLK+C.STAT ; WILDCARDS OR MULTIPLE FILES ? BNE 60$ ; IF NE, YES (ILLEGAL FOR WRITE) 50$: CLC ; SHOW SUCCESS RETURN 60$: SEC ; SHOW SYNTAX ERROR RETURN .END