.title COOKIE - Produce fortune COOKIE message ; ; Author: Dennis Merchant ; Dec, 1990 ; ; Function: Read a random record from a Fortune COOKIE file and ; writes the message to the terminal. ; ; Data : ; .PSECT DATA,WRT,NOEXE ; COOKIE_FAB: $FAB FNM = ,- ;Cookie file name SHR = ;Only reading it COOKIE_RAB: $RAB FAB = COOKIE_FAB,- ;Pointer to FAB KBF = KEY_STR,- ;Key buffer KRF = 0,- ;Primary key MBC = 3, - ;Multi-Block Count RAC = KEY,- ;Keyed Access ROP = WAT,- ;Wait for record UBF = REC_BUFF,- ;Record Buffer USZ = REC_SIZE ;Record Size ; REC_SIZE: .WORD 150 ;Maximum Record Size REC_BUFF: .BLKB 150 ;Record Buffer KEY_STR: .ASCII /0005/ ;Key String Buffer OUT_STR_D: .WORD 0 ;Output length .WORD 270 ;Set to x'010E' .ADDRESS REC_BUFF+5 ;Point to Record Buffer+5 ; ; The following value needs to be changed to reflect the actual number ; of entries in the cookie file. ; HIGH: .long 841 ;Maximum Random Number ; LOW: .long 1 ;Minimum Random Number RANDNUM: .long 0 OUTSTR: .ascid / / OUTLEN: .long 8 INLEN: .long 2 ; .PSECT CODE,NOWRT,EXE ; ; Code : ; .ENTRY COOKIE,^M<> $OPEN FAB=COOKIE_FAB ;Open the File BLBC R0,EXIT1 ;Quit On Error $CONNECT RAB=COOKIE_RAB ;Connect to File BLBC R0,EXIT2 ;Quit On Error BRB READ ;Skip Error Handling EXIT1: MOVAL COOKIE_FAB,R6 ;Keep Address BRW F_ERR ;Signal FAB Error EXIT2: MOVAL COOKIE_RAB,R6 ;Keep Address BRW R_ERR ;Signal RAB Error READ: PUSHL HIGH ;Maximum Value PUSHL LOW ;Minimum Value PUSHAL RANDNUM ;Random Value CALLS #3,G^RAND ;Get a random number PUSHL INLEN ;Input length PUSHL OUTLEN ;Output length PUSHAL OUTSTR ;Place the output here PUSHAL RANDNUM ;Number to convert CALLS #4,G^OTS$CVT_L_TI ;Convert to ASCII MOVC3 #4,OUTSTR+12,KEY_STR ;Move to Key MOVB #4,COOKIE_RAB+RAB$B_KSZ ;Set Key Size $GET RAB=COOKIE_RAB ;Read the record BLBS R0,OUT_MSG ;Write it out if successful CMPL R0,#RMS$_RNF ;Record not found? BEQL READ ;No, then try again BRW EXIT2 ;Otherwise error OUT_MSG: MOVW COOKIE_RAB+RAB$W_RSZ,- OUT_STR_D ;Length of Record SUBW2 #5,OUT_STR_D ;Remove Length of Key+1 PUSHAL OUT_STR_D ;Save on Stack CALLS #1,G^LIB$PUT_OUTPUT ;Write it out to SYS$OUTPUT MOVB #RAB$C_SEQ,- COOKIE_RAB+RAB$B_RAC ;Indicate Sequential Read READ_SEQ: $GET RAB=COOKIE_RAB ;Read the record BLBS R0,READ_OK ;Was the read successful? CMPL R0,#RMS$_EOF ;End of File? BEQL DONE ;Then were done BRW EXIT2 ;Otherwise error READ_OK: CMPC3 #4,KEY_STR,REC_BUFF ;Is the key the same? BNEQ DONE ;If not, then quit MOVW COOKIE_RAB+RAB$W_RSZ,- OUT_STR_D ;Length of Record SUBW2 #5,OUT_STR_D ;Remove Length of Key+1 PUSHAL OUT_STR_D ;Save on Stack CALLS #1,G^LIB$PUT_OUTPUT ;Write it out to SYS$OUTPUT BRW READ_SEQ ;Read the Next one ; F_ERR: PUSHL FAB$L_STV(R6) ;Push STV and STS on PUSHL FAB$L_STS(R6) ;stack in reverse order CALLS #2,G^LIB$SIGNAL ;Signal Message BRB EXIT ; and leave R_ERR: PUSHL RAB$L_STV(R6) ;Push STV and STS on PUSHL RAB$L_STS(R6) ;stack in reverse order CALLS #2,G^LIB$SIGNAL ;Signal Message DONE: $CLOSE FAB=COOKIE_FAB ;Close the file EXIT: RET ;Return with status in R0 .END COOKIE