.TITLE OPEN - OPEN FILES FOR READ/WRITE .IDENT /02.2/ .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: OPEN ; Author: Robin Miller ; Date: February 11, 1982 ; ; Description: ; ; This module is called to open a file for read or write. It ; will do 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: ; ;- .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 WLDFNB, WLDDSD, WLDVER, WLDFLG, CSIBLK FCSBT$ DEF$G ; DEFINE FCS BITS GLOBALLY FDOFF$ DEF$G ; DEFINE FDB OFFSETS GLOBALLY NBOFF$ DEF$G ; DEFINE FNB OFFSETS GLOBALLY .ENDC ; Command String Interpreter (CSI) block. S.WUIC = 14. ; EXTRA BYTES FOR WILDCARD UIC N.WNM2 = 42. ; OFFSET TO DIRECTORY STRING STORAGE NB.SFL = NB.SD1!NB.SD2!NB.SNM!NB.STP!NB.SVR ; WILDCARD BITS CSIBLK: .BLKB C.SIZE ; ALLOCATE CSI BUFFER .EVEN WLDFNB: .BLKB S.FNB+S.WUIC ; FNB FOR WILDCARD UIC'S WLDDSD: .BLKW 6 ; WILDCARDS DATASET DESCRIPTOR WLDVER: .WORD 0 ; SPACE TO SAVE ORIGINAL VERISION WLDFLG::.WORD 0 ; WILDCARDS ACTIVE FLAG <> 0 = TRUE .SBTTL OPEN - OPEN A FILE FOR READ OR WRITE ;+ ; ; OPEN - Open a file for read or write. ; ; This routine calls the CSI routines to check for syntax errors, and if ; there are none, opens the file for append, read, or write. The carry ; bit is returned for both syntax errors from the CSI routines and FCS ; errors from open. The actual error code is in offset F.ERR of the FDB. ; ; The error code IE.BNM (bad file name) is returned in offset F.ERR of the ; file descriptor block if errors are encountered by the CSI routines. ; ; Inputs: ; R0 = the address of the FDB. ; R1 = the address of the FNB. ; R2 = Address of file specification (terminated by NULL). ; R3 = Type of open to perform: ; #'R = open for read. ; #'W = open for write. ; ; Outputs: ; C clear/set = success/failure. ; All registers are preserved. ; ;- OPEN:: CALL $SAVAL ; SAVE ALL REGISTERS TST F.BDB(R0) ; IS THE FILE ALREADY OPEN ? BEQ 10$ ; IF EQ, NO CLOSE$ R0 ; YES, CLOSE IT 10$: MOV #C.SIZE/2,R4 ; GET CSI SIZE IN WORDS MOV #CSIBLK,R5 ; SET ADDRESS OF CSI BLOCK 20$: CLR (R5)+ ; CLEAR THE CSI BLOCK SOB R4,20$ ; BR UNTIL DONE MOV R0,R4 ; COPY THE FDB ADDRESS MOV R1,R5 ; AND THE FNB ADDRESS MOV #CSIBLK,R0 ; ADDRESS OF CSI BLOCK MOV R2,C.CMLD+2(R0) ; SAVE THE STRING ADDRESS CLR F.DSPT(R4) ; CLEAR THE DATASET POINTER CLR F.ERR(R4) ; INITIALIZE FCS ERROR CODE BISB #IE.BNM,F.ERR(R4) ; NOW SET IT TO BAD FILE NAME 30$: TSTB (R2)+ ; AT END OF THE STRING ? BNE 30$ ; IF NE, NO (LOOP) DEC R2 ; ADJUST FOR THE NULL SUB C.CMLD+2(R0),R2 ; CALCULATE THE BYTE COUNT BEQ 40$ ; IF EQ, DON'T DO CSI MOV R2,C.CMLD(R0) ; AND SAVE IT CALL .CSI1 ; CHECK THE SYNTAX BCS 50$ ; IF CS, BAD SYNTAX MOVB #CS.OUT,(R0) ; SET FOR OUTPUT FILE CALL .CSI2 ; PARSE FILE SPECIFICATION BCS 50$ ; IF CS, ERROR 40$: MOV R4,R0 ; RESET THE FDB ADDRESS MOV R5,R1 ; AND THE FNB ADDRESS MOV #CSIBLK+C.DSDS,F.DSPT(R0) ; POINT TO DATASET DESCRIPTOR CMPB #'R,R3 ; OPEN FILE FOR READ ? BEQ OPENR ; IF EQ, YES BITB #CS.MOR!CS.WLD,CSIBLK+C.STAT ; WILDCARDS OR MULTIPLE FILES ? BNE 50$ ; IF NE, YES (ILLEGAL FOR WRITE) JMP OPENW ; NO, OPEN IT FOR WRITE 50$: SEC ; SHOW SYNTAX ERROR RETURN .SBTTL OPENR - OPEN THE FILE FOR READ ;+ ; ; OPENR - Open the file for read (handles wildcards). ; ONEXT - Alternate entry to open next file for wildcards. ; ; This routine is used to open a file or a series of files if wildcards ; are specified. The dataset descriptor pointed to by the FDB is first ; copied to the wildcard dataset descriptor. This is used when wildcards ; are specified in the project or programmer number (UIC). On subsequent ; calls to ONEXT, either the next file specification will be returned, or ; the carry bit will be set to indicate an FCS failure (should be IE.NSF). ; ; Inputs: ; R0 = the address of the FDB. ; R1 = the address of the FNB. ; ; Outputs: ; C bit clear/set = success/failure. ; Presumes registers saved by OPEN routine. ; ;- OPENR:: MOV #6,R2 ; SIZE OF DATASET DESCRIPTOR MOV F.DSPT(R0),R3 ; ADDESS OF DATASET DESCRIPTOR MOV #WLDDSD,R4 ; ADDRESS OF WILDCARD DATASET ; Copy the dataset descriptor to the wildcard descriptor. 10$: MOV (R3)+,(R4)+ ; COPY THE DATASET SOB R2,10$ ; LOOP TILL DONE MOV WLDDSD+N.DIRD,R2 ; GET LENGTH OF DESCRIPTOR BEQ 30$ ; IF EQ, NONE AVAILABLE MOV WLDDSD+N.DIRD+2,R3 ; GET ADDRESS OF DIRECTORY MOV #WLDFNB+N.WNM2,R4 ; ADDRESS OF STRING STORAGE MOV R4,WLDDSD+N.DIRD+2 ; SET NEW STRING ADDRESS ; Copy the directory descriptor. 20$: MOVB (R3)+,(R4)+ ; COPY TO SCRATCH STORAGE SOB R2,20$ ; LOOP TILL DONE 30$: MOV F.DSPT(R0),R2 ; ADDRESS OF DATASET DESCRIPTOR MOV F.DFNB(R0),R3 ; ADDRESS OF THE DEFAULT FNB MOV #WLDFNB,R4 ; ADDRESS OF THE WILDCARD FNB CALL .WPARS ; PARSE THE CONTROLLING STRING BCS 40$ ; IF CS, FAILURE MOV #-1,WLDFLG ; PRESUME WILDCARDS ACTIVE MOV N.FVER(R1),WLDVER ; SAVE ORIGINAL VERSION # BR ONEXT ; CONTINUE TO DO THE .FIND 40$: RETURN .SBTTL ONEXT - OPEN THE NEXT WILDCARD FILE ; Alternate entry to find next file when doing wildcards. ; Inputs: R0 = the FDB address, R1 = the FNB address. ONEXT:: TST F.BDB(R0) ; IS THE FILE ALREADY OPEN ? BEQ 5$ ; IF EQ, NO CLOSE$ R0 ; YES, CLOSE IT 5$: MOVB #IE.NSF,F.ERR(R0) ; PRESUME NO SUCH FILE TST WLDFLG ; ANY WILDCARDS ACTIVE ? BEQ 20$ ; IF EQ, NO BIT #NB.SFL,N.STAT(R1) ; ARE THERE ANY WILDCARDS ? BNE 10$ ; IF NE, YES CLR WLDFLG ; NO, CLEAR THE FLAG 10$: MOV #WLDFNB,R2 ; ADDRESS OF WILDCARD FNB MOV N.FVER(R1),N.FID+4(R1) ; COPY OLD VERSION NUMBER MOV WLDVER,N.FVER(R1) ; RESTORE ORIGINAL VERSION # CALL .FNDNX ; FIND THE NEXT FILE BCS 20$ ; IF CS, WE FAILED TSTB F.FACC(R0) ; IS THE FILE ACCESS SETUP ? BNE 15$ ; IF NE, PRSEUME YES MOVB #FO.RD,F.FACC(R0) ; SETUP THE FDB FOR READ 15$: CALL .OPFNB ; OPEN THE FILE FOR READ RETURN 20$: CLR WLDFLG ; NO MORE FILES SEC ; SHOW FAILURE RETURN .SBTTL OPENW - OPEN FILE FOR WRITE ;+ ; ; OPENW - Open a file for write. ; ; This routine is called after the command string interpreter to open ; a new file. ; ; Inputs: ; R0 = the address of the FDB. ; R1 = the address of the FNB. ; ; Outputs: ; C bit clear/set = success/failure. ; Presumes registers are saved by OPEN routine. ; ;- OPENW:: 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 TSTB F.FACC(R0) ; IS THE FILE ACCESS SETUP ? BNE 10$ ; IF NE, PRESUME YES MOVB #FO.WRT!FA.NSP,F.FACC(R0) ; SETUP THE FDB FOR WRITE 10$: CALL .OPFNB ; OPEN THE FILE FOR WRITE 20$: RETURN .END