.TITLE LetterWriter ; Demonstrates: RMS, macros ; Purpose - Write a letter to all customers who have a B rating. ; Before running, the user must assign input and optionally ; assign output which is assumed to go to SYS$PRINT. Example: ; $ ASSIGN Customers.Dat InputFile ; $ ASSIGN LPA0: SYS$PRINT ; $ RUN Letter ; Declare Files and Records ................. InFAB: $FAB FNM= ; FAB for input OutFAB: $FAB FNM=, - ; FAB for output RAT=CR ; use carriage return InRAB: $RAB FAB=InFAB, - ; Associate input file UBF=InBuf, - ; buffer USZ=InLength ; buffer size OutRAB: $RAB FAB=OutFAB ; Associate output file ; (Other parameters assigned ; during run.) ; Declare Buffers ........................... InLength = 26 InBuf: .BLKB InLength ; Input buffer DearBuf: .ASCII "Dear (name goes here) " ; An output buffer for DearLength = . - DearBuf ; Other data and constants .................. BRating = ^A/B/ Comma = ^A/,/ ; Macro for checing R0 for error codes .MACRO CheckError ?Continue BLBS R0, Continue ; If R0 is even BRW ErrorStop ; branch to ErrorStop Continue: .ENDM CheckError ; ............................................ ; Begin program ............................. ; ............................................ .ENTRY Letter, 0 ; Initialize files and records .............. $OPEN FAB=InFAB ; Open input file CheckError $CREATE FAB=OutFAB ; Create output file CheckError $CONNECT RAB=InRAB ; Connect input record CheckError $CONNECT RAB=OutRAB ; Connect output record ; Begin main loop ........................... ; Read input record ......................... Loop: $GET RAB=InRAB ; Read record CMPL R0, #RMS$_EOF ; If end of file BNEQ Cont ; then BRW Done ; terminate program Cont: CheckError ; Check for errors ; Check rating ..............................- CMPB InBuf, #BRating ; If rating is not a B BNEQ Loop ; Repeat at Loop ; Process customers who have a B rating ..... BSBW WriteDearCustomer; Output "Dear ...," ; BSBW WriteBodyOfLetter; Future routine to write ; letter BRW Loop ; Next customer ; Done - terminate run ...................... Done: $CLOSE FAB=InFAB ; Close input file CheckError $CLOSE FAB=OutFab ; Close output file CheckError $EXIT_S ; Normal exit ; Error exit ................................ ErrorStop: $EXIT_S R0 ; Terminate with message ; ........................................... ; Subroutines ............................... ; ........................................... ; Subroutine to write "Dear CustomerName," .. ; Assumes customer name begins in 3rd ....... ; character of Inbuf ........................ WriteDearCustomer: SUBW3 #2, InRAB+RAB$W_RSZ, R6 ; Calculate length of name MOVC3 R6, - ; Length of customer name InBuf+2, - ; Location of customer name DearBuf+5 ; Address of name in DearBuf MOVB #Comma, (R3) ; Put comma at end of name ADDW3 R6, #6, OutRAB+RAB$W_RSZ ; Store length of DearBuf MOVAB DearBuf, OutRAB+RAB$L_RBF ; Store address of DearBuf $PUT RAB=OutRAB ; Output "Dear name," CheckError RSB .END Letter ;