.TITLE SWPFLS - SWAP PRIMARY AND SECONDARY FILES .IDENT "X0202" ; ; COPYRIGHT (C) 1976 BY DIGITAL EQUIPMENT CORPORATION, ; MAYNARD, MASSACHUSETTS ; ; THIS SOFTWARE IS FURNISHED UNDER A LICENSE FOR USE ONLY ON A ; SINGLE COMPUTER SYSTEM AND MAY BE COPIED ONLY WITH THE IN- ; CLUSION OF THE ABOVE COPYRIGHT NOTICE. THIS SOFTWARE, OR ; ANY OTHER COPIES THEREOF, MAY NOT BE PROVIDED OR OTHERWISE ; MADE AVAILABLE TO ANY OTHER PERSON EXCEPT FOR USE ON SUCH ; SYSTEM AND TO ONE WHO AGREES TO THESE LICENSE TERMS. TITLE ; TO AND OWNERSHIP OF THE SOFTWARE SHALL AT ALL TIMES REMAIN ; IN DIGITAL. ; ; THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITH- ; OUT NOTICE AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY ; DIGITAL EQUIPMENT CORPORATION. ; ; DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY FOR ; THE USE OR RELIABILITY OF ITS SOFTWARE ON EQUIPMENT WHICH IS ; NOT SUPPLIED BY DIGITAL. ; ; ANDREW C. GOLDSTEIN 16-JUN-77 23:50 ; MARK H. BRAMHALL 27-FEB-79 18:42 .MCALL OFNB$R,OFNB$A,CLOSE$ .SBTTL INPUT FILE SAVE ;+ ; ; *** - INPSAV SWITCH TO SECONDARY INPUT FILE ; ; THIS ROUTINE SWITCHES TO THE SECONDARY INPUT CHANNEL BY CLOSING THE ; PRESENT INPUT FILE IF ANY, SWAPPING THE INPUT FILE NAME BLOCK WITH THE ; INPUT SAVE AREA, AND OPENING THE SECONDARY INPUT FILE, IF ANY. IF WE ; ARE ALREADY ON THE SECONDARY INPUT FILE, THIS ROUTINE IS A NOP. ; ; INPUTS: NONE ; ; OUTPUTS: NONE ; ; ALL REGISTERS ARE PRESERVED. ; ;- .PSECT CODE,RO,I INPSAV:: SAVE TSTB INFLG ; SEE IF ALREADY ON SECONDARY INPUT BNE 10$ ; BRANCH IF YES CALL SWITIN ; SWAP INPUT AND SAVED INPUT 10$: CALL SETNMI ; SET THE INPUT FILE NAME RETURN .SBTTL OUTPUT FILE SAVE ;+ ; ; *** - OUTSAV SWITCH TO SECONDARY OUTPUT FILE ; ; THIS ROUTINE SWITCHES TO THE SECONDARY OUTPUT CHANNEL BY CLOSING THE ; PRESENT OUTPUT FILE IF ANY, SWAPPING THE OUTPUT FILE NAME BLOCK WITH THE ; OUTPUT SAVE AREA, AND OPENING THE SECONDARY OUTPUT FILE, IF ANY. IF WE ; ARE ALREADY ON THE SECONDARY OUTPUT FILE, THIS ROUTINE IS A NOP. ; ; INPUTS: NONE ; ; OUTPUTS: NONE ; ; ALL REGISTERS ARE PRESERVED. ; ;- OUTSAV:: SAVE TSTB OUTFLG ; SEE IF ALREADY ON SECONDARY OUTPUT BNE 10$ ; BRANCH IF YES CALL SWITOU ; SWAP OUTPUT AND SAVED OUTPUT 10$: CALL SETNMO ; SET THE OUTPUT FILE NAME RETURN .SBTTL INPUT AND OUTPUT FILE RESTORE ;+ ; ; *** - FILRST SWITCH TO PRIMARY INPUT OR OUTPUT FILE ; ; THIS ROUTINE SWITCHES TO THE PRIMARY INPUT OR OUTPUT CHANNEL (AS DETERMINED ; BY THE MODE FLAG) BY CLOSING THE PRESENT INPUT OR OUTPUT FILE IF ANY, ; SWAPPING THE INPUT OR OUTPUT FILE NAME BLOCK WITH THE INPUT OR OUTPUT ; SAVE AREA, AND OPENING THE PRIMARY INPUT FILE, IF ANY. IF WE ; ARE ALREADY ON THE PRIMARY INPUT OR OUTPUT FILE, THIS ROUTINE IS A NOP. ; ; INPUTS: R4 = MODE: ; 0 = RESTORE INPUT ; + = RESTORE OUTPUT ; ; OUTPUTS: NONE ; ; ALL REGISTERS ARE PRESERVED. ; ;- FILRST:: TST R4 ; CHECK MODE BGT 20$ ; BRANCH IF OUTPUT TSTB INFLG ; SEE IF ALREADY ON PRIMARY INPUT BEQ 10$ ; BRANCH IF YES CALL SWITIN ; SWAP INPUT AND SAVED INPUT 10$: CALL SETNMI ; SET THE INPUT FILE NAME RETURN 20$: TSTB OUTFLG ; SEE IF ALREADY ON PRIMARY OUTPUT BEQ 30$ ; BRANCH IF YES CALL SWITOU ; SWAP OUTPUT AND SAVED OUTPUT 30$: CALL SETNMO ; SET THE OUTPUT FILE NAME RETURN .SBTTL SWAP INPUT AND SAVED INPUT FILES ;+ ; ; *** - SWITIN SWAP INPUT AND SAVED INPUT ; ; THIS ROUTINE SWAPS THE CURRENTLY OPEN INPUT FILE WITH THE SAVED INPUT ; FILE. IT CLOSES THE FILE IF OPEN (MARKING ITS POSITION) AND SWAPS THE ; CONTENTS OF THE FILE NAME BLOCK AND FILE NAME STRING WITH THE INPUT FILE ; SAVE AREA. THEN IT OPENS THE SWAPPED INPUT FILE, IF THERE WAS ONE. ; ; INPUTS: NONE ; ; OUTPUTS: NONE ; ; R0 - R4 CLOBBERED ; ;- SWITIN: MOV #INFDB,R0 ; POINT TO INPUT FDB TST F.FNB(R0) ; SEE IF FILE IS OPEN BEQ 10$ ; BRANCH IF NO CALL .MARK ; GET CURRENT FILE POSITION MOV F.FNB(R0),-(SP) ; SAVE FILE NUMBER CLOSE$ R0 ; CLOSE THE FILE BCS CLERR ; BRANCH IF FAILED TO CLOSE MOV (SP)+,F.FNB(R0) ; RESTORE FILE NUMBER 10$: MOV #INSAVE,R4 ; POINT TO INPUT SAVE AREA CALL SWAP ; SWAP NAME BLOCK WITH SAVE AREA MOV (R4),-(SP) ; NOW SWAP THE CONTENTS OF R1, R2, AND R3 MOV R1,(R4)+ ; WITH THE NEXT 3 WORDS OF THE SAVE AREA MOV (SP)+,R1 MOV (R4),-(SP) MOV R2,(R4)+ MOV (SP)+,R2 MOV (R4),-(SP) MOV R3,(R4)+ MOV (SP)+,R3 MOVB (R4),-(SP) ; SWAP INPUT CHARACTER HANDLING FLAG MOVB CHRFLG,(R4)+ MOVB (SP)+,CHRFLG MOVB (R4),-(SP) ; SWAP INPUT BP2 MODE FLAG MOVB INBP2,(R4)+ MOVB (SP)+,INBP2 MOV #INFDB,R0 ; GET FDB ADDRESS AGAIN MOVB (R4),-(SP) ; ALSO SWAP THE SAVED RECORD ATTRIBUTES MOVB F.RATT(R0),(R4)+ MOVB (R4),-(SP) ; SWAP END-OF-FILE FLAG WITH SAVE AREA MOVB EOFLAG(R5),(R4)+ MOVB (SP)+,R4 ; SIGN EXTEND END-OF-FILE INTO REGISTER CLR -(SP) ; EOF STATUS OF SWAPPED FILE IS UNKNOWN COMB INFLG ; INDICATE FILE SWAPPED TST F.FNB(R0) ; SEE IF THE FILE WAS OPEN (NON-ZERO FID) BEQ 30$ ; BRANCH IF NOT MOV R4,(SP) ; SET TRUE EOF STATUS OFNB$R R0 ; ELSE OPEN IT BCS CLERR CALL .POINT ; AND RE-POSITION BCC 30$ ; O.K. CMPB F.ERR(R0),#IE.EOF ; ELSE WAS THE ERROR END-OF-FILE? BNE CLERR ; IF NOT, GET OUT MOV #-1,(SP) ; YES - SET END OF FILE FLAG 30$: MOV (SP)+,EOFLAG(R5) ; RESTORE END-OF-FILE FLAG MOVB (SP)+,F.RATT(R0) ; RESTORE RECORD ATTRIBUTES RETURN CLERR: JMP FDBERR ; GENERAL ERROR EXIT .SBTTL SWAP OUTPUT AND SAVED OUTPUT FILES ;+ ; ; *** - SWITOU SWAP OUTPUT AND SAVED OUTPUT ; ; THIS ROUTINE SWAPS THE CURRENTLY OPEN OUTPUT FILE WITH THE SAVED OUTPUT ; FILE. IT CLOSES THE FILE IF OPEN AND SWAPS THE ; CONTENTS OF THE FILE NAME BLOCK AND FILE NAME STRING WITH THE OUTPUT FILE ; SAVE AREA. THEN IT OPENS THE SWAPPED OUTPUT FILE, IF THERE WAS ONE. ; ; INPUTS: NONE ; ; OUTPUTS: NONE ; ; R0 - R4 CLOBBERED ; ;- SWITOU: MOV #OUTFDB,R0 ; POINT TO OUTPUT FDB TST F.FNB(R0) ; SEE IF FILE IS OPEN BEQ 10$ ; BRANCH IF NO MOV F.FNB(R0),-(SP) ; SAVE FILE NUMBER CLOSE$ R0 ; CLOSE THE FILE BCS CLERR ; BRANCH IF FAILED TO CLOSE MOV (SP)+,F.FNB(R0) ; RESTORE FILE NUMBER 10$: MOV #OUSAVE,R4 ; POINT TO OUTPUT SAVE AREA CALL SWAP ; SWAP NAME BLOCK WITH SAVE AREA MOVB (R4),-(SP) ; SWAP OUTPUT BP2 MODE FLAG MOVB OUBP2,(R4)+ MOVB (SP)+,OUBP2 MOV #OUTFDB,R0 ; GET FDB ADDRESS AGAIN COMB OUTFLG ; INDICATE FILE SWAPPED TST F.FNB(R0) ; SEE IF THE FILE WAS OPEN (NON-ZERO FID) BEQ 20$ ; BRANCH IF NOT OFNB$A R0 ; ELSE OPEN IT BCS CLERR 20$: RETURN .SBTTL SWAP SAVE AREA WITH OPEN FILE ;+ ; ; *** - SWAP SWAP SAVE AREA WITH OPEN FILE ; ; THIS ROUTINE SWAPS A FILE SAVE AREA WITH THE NAME BLOCK AND NAME STRING ; OF A FILE. ; ; INPUTS: ; R0 = FDB ADDRESS OF FILE ; R4 = ADDRESS OF SAVE AREA ; ; OUTPUTS: ; R4 = ADDRESS PAST BASIC SAVE AREA ; R0 CLOBBERED, OTHER REGISTERS PRESERVED ; ;- SWAP: MOV R1,-(SP) ; SAVE R1 ADD #F.FNB,R0 ; POINT TO NAME BLOCK MOV #/2,R1 ; GET WORD COUNT 10$: MOV (R0),-(SP) ; AND SWAP EACH WORD MOV (R4),(R0)+ MOV (SP)+,(R4)+ SOB R1,10$ MOV (SP)+,R1 ; RESTORE R1 RETURN .SBTTL SET FILE STRING INTO FILENAME BUFFER ;+ ; ; *** - SETNMI SET INPUT FILE STRING ; *** - SETNMO SET OUTPUT FILE STRING ; ; THIS ROUTINE SETS THE SPECIFIED FILE STRING INTO THE FILENAME BUFFER. ; ; INPUTS: NONE ; ; OUTPUTS: ; R0 CLOBBERED ; ;- .ENABL LSB SETNMI: MOV #INFDB+F.FNB+S.FNB,R0 ; POINT TO INPUT FILE STRING BR 10$ SETNMO: MOV #OUTFDB+F.FNB+S.FNB,R0 ; POINT TO OUTPUT FILE STRING 10$: MOV R1,-(SP) ; SAVE R1 MOV R4,-(SP) ; SAVE R4 MOV FILBUF(R5),R4 ; POINT TO BUFFER CLRB (R4) ; PRE-CLEAR FILENAME BUFFER TST -S.FNB(R0) ; IS THE FILE OPEN? BEQ 30$ ; NOPE MOV #FILSIZ,R1 ; GET BYTE COUNT 20$: MOVB (R0)+,(R4)+ ; COPY STRING SOB R1,20$ 30$: MOV (SP)+,R4 ; RESTORE R4 MOV (SP)+,R1 ; RESTORE R1 RETURN .DSABL LSB .END