.TITLE PRT2CR .IDENT /X01-00/ ;++ ; Copyright © 1991 James F. Duff. All rights reserved. ; ; This program is free software; you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation; either version 1, or (at your option) ; any later version. ; ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with this program; if not, write to the Free Software ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ; ; The author can be contacted on the Internet at DUFF@DECUS.COM.AU. ;-- ;++ ; ; FACILITY: ; ; FILE UTILITIES ; ; ABSTRACT: ; ; This program reads files with carriage control = print and outputs ; a file which will print looking exactly the same but with carriage ; control = carriage return. ; ; COBOL report files use print carriage control. ; ; The program is invoked by DCL. ; The input file must be sequential variable or an error will occur. ; ; MODULE INTERFACE: ; ; DCL ; ; Syntax: ; ; PRT2CR input_file output_file ; ; ENVIRONMENT: ; ; User mode ; ; AUTHOR: ; ; James F. Duff (duff@decus.com.au) ; ; MODIFIED BY: ; ; X01-00 Jim Duff 07-JUN-1991 ; Original version of module ; ;-- .LIBRARY "SYS$LIBRARY:LIB.MLB" $SSDEF $FABDEF $RABDEF $RMSDEF .MACRO JMPERR ARG=R0,ADR=ERROR,?A BLBS ARG,A .IIF DIF ARG,R0, MOVL ARG,R0 JMP ADR A: .ENDM JMPERR .PSECT PRT2CR_RODATA NOWRT,SHR,NOEXE,PAGE P1_D: .ASCID /INFILE/ P2_D: .ASCID /OUTFILE/ .PSECT PRT2CR_RWDATA WRT,NOSHR,NOEXE,PAGE .ALIGN LONG INFAB: $FAB ORG=SEQ, - FAC=GET, - RFM=VAR, - RAT=PRN INRAB: $RAB FAB=INFAB, - UBF=RECORD, - USZ=65535, - RHB=CONTROL OUTFAB: $FAB ORG=SEQ, - FAC=PUT, - RFM=VAR, - RAT=CR OUTRAB: $RAB FAB=OUTFAB, - UBF=RECORD, - USZ=65535, - RBF=RECORD INFILE_D: .LONG 255 .ADDRESS - INFILE OUTFILE_D: .LONG 255 .ADDRESS - OUTFILE RESULT_D: .LONG 255 .ADDRESS - INFILE CONTEXT:.BLKL 1 CONTROL: C1: .BLKB 1 C2: .BLKB 1 TEMP: .BLKB 1 C: .BLKB 255 INFILE: .BLKB 255 OUTFILE:.BLKB 255 RECORD: .BLKB 65535 .PSECT PRT2CR_CODE NOWRT,SHR,EXE,PAGE .ENTRY PRT2CR,^M<> PUSHAL INFILE_D ; Write input file len here PUSHAL INFILE_D ; Write input file name here PUSHAL P1_D ; 1st paramater: "INFILE" CALLS #3,G^CLI$GET_VALUE ; Get value of parameter JMPERR ; Error? PUSHAL OUTFILE_D ; Write output file len here PUSHAL OUTFILE_D ; Write output file name here PUSHAL P2_D ; 2nd parameter: "OUTFILE" CALLS #3,G^CLI$GET_VALUE ; Get parameter's value JMPERR ; Error? PUSHAL #1 ; No wildcards PUSHL #0 ; Omitted PUSHL #0 ; Ditto PUSHL #0 ; Ditto PUSHAL CONTEXT ; Context PUSHAQ RESULT_D ; Write resultant filename here PUSHAQ INFILE_D ; Lookup this filespec CALLS #7,G^LIB$FIND_FILE ; Find a filename JMPERR ; Errors? LOCC #^A/ /,#255,INFILE ; Locate a space in the filename SUBL3 R0,#255,INFILE_D ; And store len of filename MOVB INFILE_D,INFAB+FAB$B_FNS ; Store in File Access Block too MOVAB INFILE,INFAB+FAB$L_FNA ; Addr of filename to FAB $OPEN FAB=INFAB ; Open the file JMPERR ; Error? $CONNECT - ; Connect a record stream RAB=INRAB JMPERR ; Error? MOVW INFAB+FAB$W_MRS, - ; Indicate max record size for OUTFAB+FAB$W_MRS ; output file MOVB OUTFILE_D,OUTFAB+FAB$B_FNS ; Len of output filename MOVAB OUTFILE,OUTFAB+FAB$L_FNA ; Addr of output filename $CREATE FAB=OUTFAB ; Create the output file JMPERR ; Error? $CONNECT - ; Connect a record stream RAB=OUTRAB READ_LOOP: $GET RAB=INRAB ; Read record from file CMPL #RMS$_EOF,R0 ; End of file? BNEQ 10$ ; No, branch JMP CLOSE ; Yes, jmp to close file 10$: JMPERR ; Error? JSB PROCESS_C1 ; Process 1st control byte MOVW INRAB+RAB$W_RSZ, - ; Indicate length of record OUTRAB+RAB$W_RSZ ; to output file $PUT RAB=OUTRAB ; Write record JMPERR ; Error? JSB PROCESS_C2 ; Process 2nd control byte BRW READ_LOOP ; Branch for next record CLOSE: $CLOSE FAB=INFAB ; Close the input file JMPERR ; Error? $CLOSE FAB=OUTFAB ; Close the output file JMPERR ; Error? PUSHAL CONTEXT ; Context to clean up CALLS #1,G^LIB$FIND_FILE_END ; Clean it up JMPERR ; Error? EXIT: MOVZWL #SS$_NORMAL,R0 ; Indicate normal completion ERROR: $EXIT_S R0 ; Exit with status PROCESS_C1: ; Subroutine to process C1 MOVB C1,TEMP ; Move it to a temp variable BRB START ; Go process it PROCESS_C2: ; Subroutine to process C2 MOVB C2,TEMP ; Move C2 to a temp variable START: PUSHR #^M ; Save required registers BBC #7,TEMP,100$ ; Branch if bit 7 clear EXTZV #0,#4,TEMP,C ; Extract a nibble. This ; contains the control ; character to output CMPB C,#13 ; Is it carriage return? BNEQ 15$ ; No, branch BRW 200$ ; Yes, ignore 15$: BBC #6,TEMP,20$ ; Branch if bit 6 clear. ADDB2 #128,C ; 8 Bit code: add 128 20$: MOVW #1,OUTRAB+RAB$W_RSZ ; One byte to output MOVAB C,OUTRAB+RAB$L_RBF ; Addr of byte $PUT RAB=OUTRAB ; Write it to the file JMPERR ; Error? MOVAB RECORD,OUTRAB+RAB$L_RBF ; Restore record addr in RAB BRB 200$ ; Go to output it 100$: TSTB TEMP ; Do anything? BEQL 200$ ; No, branch EXTZV #0,#6,TEMP,R6 ; Extract number of linefeeds DECL R6 ; Less one as RMS fixes it TSTL R6 ; Zero? BEQL 200$ ; Yes, branch DECL R6 ; No, less one for the line we ; are going to write MOVC5 #0,#0,#10,R6,C ; Specified no of line feeds MOVW R6,OUTRAB+RAB$W_RSZ ; Indicate how many bytes output MOVAB C,OUTRAB+RAB$L_RBF ; Addr of bytes $PUT RAB=OUTRAB ; Write to the file JMPERR ; Error? MOVAB RECORD,OUTRAB+RAB$L_RBF ; Restore record addr in RAB 200$: POPR #^M ; Restore registers RSB ; Return .END PRT2CR