.TITLE NUMBER .IDENT /280582/ .ENABL LC ; ; ; Written by Ray Di Marco ; 28-May-82. ; ; ;---------------------------------------------------------------------------- ; ; ; This program is part of the DBSMNG demonstration application; its function ; is to output on the terminal all entries in the SRT file DK:PHONES.INX that ; match the target entered by the user. When the SRT file is properly setup, ; this program can be used to quickly extract telephone numbers; as a binary ; search of the INDEX file is used and the actual database is not accessed ; (the name and telephone numbers have actually been copied into each SRT file ; entry) the program is extremely quick and can be run on-line. ; ; .SBTTL Declarations ; ; .MCALL .PRINT,.EXIT ; used for error handling .MCALL .GTLIN ; Input ; ; .GLOBL SFLINT,SFLPSN,SFLINP,SFLINC,SFLPAR,SFLNME ; "SRTFIO" ; .PSECT CODE ; open code ; ====== ==== ; ; ; .MACRO FATAL STR,?A,?B .PRINT #'B .EXIT B': .ASCIZ |INSPECT-fatal-'STR'| .EVEN .ENDM FATAL ; .SBTTL Initialization code ; ; START: MOV #SFLNME,R0 ; R0 -> destination MOV #FILNME,R1 ; R1 -> source 100$: MOVB (R1)+,(R0)+ ; copy ... BNE 100$ ; ... time CALL SFLINT ; OPEN DATA FILE CMP SFLPAR,#3 ; minimum record size = 3 BLO 6000$ ; to small -> abort CMP SFLINT+2,#2 ; need at least 2 records BLOS 6100$ ; not enough -> abort JMP RESTRT ; enter loop ; ; 6000$: FATAL 6100$: FATAL .SBTTL Main Loop Code ; ; RESTRT: .GTLIN #..TARG,#PROMPT ; prompt MOV #..TARG,R0 ; R0 -> line buffer 100$: TSTB (R0)+ ; at EOS? BNE 100$ ; no -> loop SUB #..TARG+1,R0 ; R0 = target size BEQ RESTRT ; no -> reprompt MOV R0,TARSIZ ; save size ; MOV #..TARG,R1 ; R1 -> TARGET 200$: CMPB (R1)+,#140 ; LC character? BLO 240$ ; no -> skip BICB #40,-1(R1) ; convert UC 240$: SOB R0,200$ ; loop till all done ; ; 2000$: CALL FIND ; find best match BHIS 3000$ ; not found -> 3000$ .PRINT #NFOUND ; tell failed JMP RESTRT ; restart time ; 3000$: MOV SFLPAR,R1 ; R1 = rec size MOV #..RECN,R0 ; R0 -> buffer CALL SFLINP ; input record ADD SFLPAR,R0 ; R0 -> end of input CLRB (R0) ; terminate .PRINT #FOUND ; print header .PRINT #..INDX ; print entry DEC ..MTCH ; used 1 more BNE 3000$ ; loop if need JMP RESTRT ; restart time ; ; .SBTTL Primitive - "FIND" ... find for target ; ; FIND: MOV SFLPAR+2,R4 ; R4 = number of entries CALL 5000$ ; R4 = R4 / 2 MOV R4,R3 ; R3 = starting entry ; 2000$: CMP R3,SFLPAR+2 ; in range? BLOS 2010$ ; yes -> skip MOV SFLPAR+2,R3 ; force into range 2010$: MOV R3,R0 ; R0 = next entry to search CALL SFLPSN ; position on entry R0 CALL 5000$ ; R4 = step size BEQ 2400$ ; out of steps -> done ADD R4,R3 ; assume going to step up CALL 5400$ ; compare TAR to REC BHI 2000$ ; TAR > REC -> step up SUB R4,R3 ; we are not stepping up ... SUB R4,R3 ; ... we are stepping down BGT 2000$ ; loop not wrapped arround MOV #1,R3 ; don't allow wrap arround BR 2000$ ; loop ; ; 2400$: CMP R3,#1 ; at first entry? BHI 2440$ ; no -> skip MOV #2,R3 ; force to second 2440$: DEC R3 ; skip back 1 record CLR ..MTCH ; no matchs as yet DEC R3 ; preloop fudge 2500$: INC R3 ; try next record CMP R3,SFLPAR+2 ; all done? BHI 2600$ ; yes -> terminate MOV R3,R0 ; R0 = match area CALL SFLPSN ; position file CALL 5400$ ; compare TAR with REC BLO 2700$ ; TAR < REC -> terminate BHI 2500$ ; TAR > REC -> loop INC ..MTCH ; found another match CMP ..MTCH,#1 ; first match found BNE 2500$ ; no -> loop MOV R3,..INDN ; save address of first match BR 2500$ ; loop ; 2600$: MOV SFLPAR+2,R3 ; ensure have legal index 2700$: TST ..MTCH ; have any matchs? BNE 2710$ ; yes -> skip MOV R3,..INDN ; use best match 2710$: MOV ..INDN,R0 ; R0 = best match CALL SFLPSN ; position file MOV SFLPAR,R1 ; R1 = number bytes/record MOV #..RECN,R0 ; R0 -> buffer CALL SFLINP ; input record/index ADD SFLPAR,R0 ; R0 -> end of input CLRB (R0) ; terminate record MOV ..INDN,R0 ; R0 = best match CALL SFLPSN ; position file CMP ..MTCH,#1 ; should only have 1 match RETURN ; exit ; ; ; 5000$: CMP R4,#1 ; last step = 1? BEQ 5040$ ; yes -> skip INC R4 ; R4 = number+1 5040$: ASR R4 ; R4 = number/2 rounded up BIC #100000,R4 ; ensure sign bit clear RETURN ; bye ; ; 5400$: CALL SFLINC ; discard first byte CALL SFLINC ; discard second byte MOV TARSIZ,R2 ; R2 = record size MOV #..TARG,R1 ; R1 = TARGET 5600$: CALL SFLINC ; R0 = next input character CMPB (R1)+,R0 ; comp TAR to REC byte BNE 5700$ ; skip no match SOB R2,5600$ ; loop if matched 5700$: RETURN ; all done ; .SBTTL Data Structures ; ; TARSIZ: .WORD 0 ; target size ..TARG: .BLKB 100 ; Target to be found ..MTCH: .WORD 0 ; number of matchs ..INDN: .WORD 0 ; number of current index record ..RECN: .WORD 0 ; database record number for index ..INDX: .BLKB 100 ; index FILNME: .ASCIZ /PHONES.INX/ ; name of index file PROMPT: .ASCII /Phone Number for : /<200> FOUND: .ASCII / /<200> NFOUND: .ASCIZ / Sorry, no match!/ ; ; .END START