.TITLE REFUTL - REFormat utility routines .IDENT /2.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: REFUTL.MAC ; Author: Gary N. Larsen ; Date: April 8, 1983 ; ; Description: ; ; Utility routines for the REFormat program. ; ; Modification History: ; ;- .ENABL AMA .NLIST BEX .MCALL CLOSE$, PUT$ ; Local Equates. BS = 8. ; ASCII for 'BACK SPACE' ESC = 27. ; ASCII for 'ESCAPE' SPACE = 32. ; ASCII for 'SPACE' .SBTTL BAKSPC - CHECK FOR BACKSPACE SEQUENCE ;+ ; ; BAKSPC - Check for a backspace delete sequence ; ; This subroutine checks for a ; sequence to delete the previous character. If it finds a backspace ; only, it presumes we are reformatting an IBM type logfile which ; uses the backspace as a delete character. ; ; Inputs: ; R3 = address of the output buffer. ; R4 = address of the input buffer. ; ; Outputs: ; None ; ;- BAKSPC:: CMPB (R4),#BS ; IS THE CHARACTER A BACKSPACE ? BNE 50$ ; IF NE, NO MOVB (R4)+,(R3)+ ; MOVE IN THE BACKSPACE FOR NOW INC OUTBYT ; ADJUST THE BYTE COUNT CMPB (R4),#SPACE ; IS THE NEXT CHARACTER A SPACE BNE 20$ ; IF NE, NO MOVB (R4)+,(R3)+ ; MOVE IN THE SPACE FOR NOW INC OUTBYT ; ADJUST THE BYTE COUNT CMPB (R4),#BS ; IS THE NEXT CHARACTER A BACKSPACE BNE 40$ ; IF NE, NO INC R4 ; POINT INPUT POINTER PAST THE SUB #3,OUTBYT ; DECREMENT THE BYTE COUNT TST OUTBYT ; WAS DELETE SEQUENCE FIRST IN BUFFER ? BGE 10$ ; IF GE, NO CLR OUTBYT ; SET BYTE COUNT TO ZERO SUB #2,R3 ; ADJUST THE BUFFER POINTER BR 40$ ; AND CHECK NEXT CHARACTER 10$: SUB #3,R3 ; AND ADJUST THE BUFFER POINTER ; SEQUENCEIN OUTPUT BUFFER BR 40$ ; AND CHECK THE NEXT CHARACTER ; Presume I B M backspace rubout sequence. 20$: SUB #2,OUTBYT ; DECREMENT THE BYTE COUNT TST OUTBYT ; BACKUP PAST BEGINNING OF BUFFER ? BGE 30$ ; IF GE, NO CLR OUTBYT ; SET BYTE COUNT TO ZERO DEC R3 ; ADJUST THE BUFFER POINTER BR 40$ ; AND CHECK NEXT CHARACTER 30$: SUB #2,R3 ; AND ADJUST THE BUFFER POINTER ; SEQUENCEIN OUTPUT BUFFER 40$: SEC ; SHOW BACKSPACE SEQUENCE FOUND RETURN ; AND EXIT 50$: CLC ; SHOW NO BACKSPACE FOUND RETURN ; AND RETURN .SBTTL ESCAPE - CHECK FOR VT100 SEQUENCES ;+ ; ; ESCAPE - Check for VT100 escape sequences ; ; This subroutine checks for a VT100 cursor addressing escape ; sequences and befor each cursor positioning it writes out the buffer. ; ; Inputs: ; R3 = address of the output buffer. ; R4 = address of the input buffer. ; ; Outputs: ; R0-R2 are preserved. ; ;- ESCAPE:: JSR R2,$SAVVR ; Save R0 - R2 MOV R4,R0 ; ADDRESS OF CHARACTER TO CHECK CMPB (R0)+,#ESC ; IS THE CHARACTER AN ESCAPE ? BNE 50$ ; IF NE, NO CMP R3,#OUTBUF ; Are we at the beginning of outbuffer? BEQ 30$ ; IF EQ, YES WRITE OUT CMP R0,INBYT ; REACHED END OF INPUT BUFFER ? BHIS 30$ ; IF HI, YES CMPB (R0)+,#'[ ; IS IT AN ESCAPE SEQUENCE ? BNE 50$ ; IF NE, NO CMP R0,INBYT ; REACHED END OF INPUT BUFFER ? BHIS 30$ ; IF HI, YES CMPB (R0)+,#'A ; IS IT A CURSOR POSITION SEQUENCE ? BGE 30$ ; IF GE, NO 10$: CMP R0,INBYT ; REACHED END OF INPUT BUFFER ? BHIS 30$ ; IF HI, YES CMPB (R0)+,#'A ; FOUND THE TERMINATOR FOR SEQUENCE ? BLT 10$ ; IF LT, NO CMPB -1(R0),#'z ; REALLY FOUND TERMINATOR ? BGT 10$ ; IF GT, NO CMPB -1(R0),#'f ; ELSE IS IT TERMINATED WITH "f" ? BEQ 20$ ; IF EQ, YES CMPB -1(R0),#'H ; ELSE IS IT TERMINATED WITH "H" ? BEQ 20$ ; IF EQ, YES BR 30$ ; AND PUT SEQUENCE IN BUFFER 20$: CALL WRTBUF ; WRITE OUT THE BUFFER 30$: SUB R4,R0 ; FIND NUMBER OF BYTES WE PASSED OVER 40$: MOVB (R4)+,(R3)+ ; NOW MOVE THEM INTO OUTPUT BUFFER INC OUTBYT ; ADJUST THE BYTE COUNT SOB R0,40$ ; GET THEM ALL SEC ; SHOW ESCAPE SEQUENCE FOUND RETURN 50$: CLC ; TELL MAINLINE NO ESCAPE RETURN .SBTTL CHKVFU - CHECK FOR A VFU BYTE ;+ ; ; CHKVFU - Check for a line printer VFU byte. ; ; This subroutine which checks for a VFU byte and converts them to ; the appropriate number of blank lines or a form feed. ; ; Inputs: ; R3 = address of the output buffer. ; R4 = address of the input buffer. ; ; Outputs: ; R4 updated if VFU byte encountered. ; V bit set/clear = found VFU / no VFU. ; ;- CHKVFU::BIT #B.VFU,STATUS ; Convert VFU bytes specified ? BEQ 40$ ; If EQ, no BITB #200,(R4) ; IS IT A VFU BYTE ? BEQ 40$ ; IF EQ, NO (V BIT CLEARED). BITB #100,(R4) ; SKIP FUNCTION (Data Printer) ? BEQ 20$ ; IF EQ, NO ; Change VFU skip function to a form feed. Put on next record. 10$: CALL WRTBUF ; WRITE THE RECORD MOVB #FF,(R3)+ ; CHANGE IT TO FORM FEED INC R4 ; AND POINT PAST IT INC OUTBYT ; ADJUST OUTPUT BYTE COUNT BR 30$ ; AND RETURN ; Data Printer skip to channel 1 = 301, space 1 = 201. ; Data Products skip to channel 1 = 200, space 1 = 221. 20$: BITB #37,(R4) ; SKIP CHANNEL 1 (Data Products) ? BEQ 10$ ; IF EQ, PRESUME YES ; Change VFU space function to 's. MOVB (R4)+,R5 ; GET THE SPACE BYTE BIC #^C17,R5 ; ISOLATE THE COUNT 25$: CALL WRTBUF ; SPACE APPROPRIATE # OF LINES BCS 30$ ; If CS, don't write anymore. DEC R5 ; Adjust the space count. BGT 25$ ; If GT, more to go. 30$: SEV ; SHOW VFU BYTE FOUND 40$: RETURN .SBTTL WRTBUF - Write The Output Buffer ;+ ; ; WRTBUF - Write the reformatted output buffer. ; ; Outputs: ; R3 = Starting address of the output buffer. ; Carry bit clear/set = success/failure. ; ; All other registers are preserved. ; ;- WRTBUF::JSR R2,$SAVVR ; Save R0 - R2 BIT #B.EBC,STATUS ; Convert from EBCDIC to ASCII BEQ 3$ ; If EQ, no CALL TRNEBC ; Else do the translation 3$: BIT #B.ASC,STATUS ; Convert from ASCII to EBCDIC BEQ 5$ ; If EQ, no CALL TRNASC ; Else do the translation 5$: INC OUTREC ; Count the number of records. ADD OUTBYT,OUTCNT+2 ; Accumulate output byte count. ADC OUTCNT ; And the high bits (if any). PUT$ #OUTFDB,#OUTBUF,OUTBYT ; Write the output buffer. BCC 10$ ; If CC, success. CALL FILERR ; Else, report the error. 10$: MOV #0,OUTBYT ; Initialize the output byte count. MOV #OUTBUF,R3 ; Reset the output buffer address. RETURN .SBTTL PRINTR - Convert Vax-11 Print file ;+ ; ; PRINTR - Convert Vax-11 Print file to implied carriage control. ; ; Inputs: ; R3 = address of the output buffer. ; R5 = Byte containing carriage control. ; ; Format of the Carriage control byte. ; ; Bit 7 Bits 6-0 Definition ; ; 0 0 No carriage control. ; 0 1-127 Number of CR/LF's to output. ; ; Bit 7 Bit 6 Bit 5 Bits 4-0 Definition ; ; 1 0 0 Ascii Char. 7-bit Ascii char. to output. ; 1 0 1 Ascii Char. 8-bit Ascii char. to output. ; 1 1 0 0-63 Device specific code. ; 1 1 1 - Reserved. ; ;- B.CTRL == 200 ; Special carriage control B.NASC == 40 ; Not an ASCII character to output B.8BIT == 20 ; Eight bit ASCII PRINTR:: BIT #B.CTRL,R5 ; Special carriage control ? BNE 20$ ; If NE, Yes BIC #177600,R5 ; Strip the High byte TST R5 ; Any CR/LF's to output ? BEQ 100$ ; IF EQ, NO 10$: CALL WRTBUF ; Write them to output file SOB R5,10$ ; Get them all BR 100$ ; and get out 20$: BIT #B.NASC,R5 ; Output ascii characters ? BNE 40$ ; If NE, NO ; BIT #B.8BIT,R5 ; 8-Bit ascii ? ; BNE 30$ ; If NE, YES BIC #177660,R5 ; Clear all but the character CMPB R5,#CR ; Was it a return ? BEQ 100$ ; IF NE, NO CMPB R5,#LF ; Was it a Linefeed ? BNE 25$ ; IF NE, NO CALL WRTBUF ; Else write out the buffer BR 100$ ; and exit 25$: MOVB R5,(R3)+ ; and move it INC OUTBYT ; increment the output byte count BR 100$ 30$: 40$: ; BIT #20,R5 ; Device specific code ? ; BNE 100$ ; If NE, No 100$: RETURN ; and exit .SBTTL FORMAN - Convert Fortran carriage control ;+ ; ; FORMAN - Convert Fortran carriage control to implied carriage control. ; ; Inputs: ; R3 = address of the output buffer. ; R4 = address of byte containing carriage control. ; ; Format of the Carriage control byte. ; ;- B.SNGL = 40 ; SINGLE SPACING B.DBLE = 60 ; DOUBLE SPACING B.FORM = 61 ; FORM FEED B.OVER = 53 ; OVERPRINT B.PRMP = 44 ; PROMPTING FORMAN:: CMPB #B.DBLE,(R4) ; Double spacing ? BNE 10$ ; If NE, no CALL WRTBUF ; Else write a blankline BR 50$ ; and exit 10$: CMPB #B.FORM,(R4) ; Insert a into buffer ? BNE 20$ ; If NE, no MOVB #FF,(R3)+ ; Else put in the form feed INC OUTBYT ; adjust the byte count BR 50$ ; and exit 20$: ;CMPB #B.SNGL,(R4) ; Single spacing ? ;BNE 30$ ; If NE, no ; IF single spacing just print the ; record. 30$: ;CMPB #B.OVER,(R4) ; Over printing ? ;BNE 40$ ; If NE, no ; IF overprint just print the ; record for now. 40$: ;CMPB #B.PRMP,(R4) ; Prompting ? ;BNE 50$ ; If NE, no ; IF prompting just print the ; record for now. 50$: INC R4 ; Point past the carriage control RETURN .SBTTL TRNEBC - Translate from EBCDIC to ASCII ;+ ; ; TRNEBC - Translate buffer from EBCDIC to ASCII. ; ;- TRNEBC::JSR R2,$SAVVR ; Save R0 - R2 MOV #OUTBUF,R0 ; Address of the output buffer MOV OUTBYT,R1 ; Byte count of the output buffer BEQ 20$ ; If zero nothing to translate 10$: MOVB (R0),R2 ; Address of byte to move. BIC #177400,R2 ; Clear the high byte. MOVB E2ATBL(R2),(R0)+ ; Do the translation SOB R1,10$ ; until we hit the end of the buffer 20$: RETURN .SBTTL TRNASC - Translate from ASCII to EBCDIC. ;+ ; ; TRNASC - Translate buffer from ASCII to EBCDIC. ; ;- TRNASC::JSR R2,$SAVVR ; Save R0 - R2 MOV #OUTBUF,R0 ; Address of the output buffer MOV OUTBYT,R1 ; Byte count of the output buffer BEQ 20$ ; If zero nothing to translate 10$: MOVB (R0),R2 ; Address of byte to move. BIC #177400,R2 ; Clear the high byte. MOVB A2ETBL(R2),(R0)+ ; Do the translation. SOB R1,10$ ; until we hit the end of the buffer. 20$: RETURN .SBTTL CLOFIL - Close Input And Output Files ;+ ; ; CLOFIL - Close the input and/or output files if open. ; ;- CLOFIL::JSR R2,$SAVVR ; Save R0 - R2 MOV #INFDB,R0 ; Address of the input FDB. TST F.BDB(R0) ; Is the input file open ? BEQ 10$ ; If EQ, no. CLOSE$ R0 ; Close the input file. 10$: MOV #OUTFDB,R0 ; Address of the output FDB. TST F.BDB(R0) ; Is the output file open ? BEQ 20$ ; If EQ, no CALL .TRNCL ; Else truncate the output file. 20$: RETURN .END