.TITLE Wild_Match Match wildcard pattern .IDENT /VER 1.0.0/ .LIBRARY /SYS$LIBRARY:LIB/ $SSDEF ;++ ; This routine was copied from the F11B module MATCHNAME of the VMS V3.0 ; microfiche. Thank you, DEC! ; ; Wild_Match (pattern.rd, candidate.rd) ; ; R0 LBS if candidate matches pattern ; ;-- .ENTRY Wild_Match, ^M MOVAB G^LIB$SIG_TO_RET, (FP) CMPB (AP), S^#2 BGEQ 10$ MOVZWL #SS$_INSFARG, R0 RET 10$: MOVQ @4(AP), R4 MOVQ @8(AP), R2 MOVZWL R2, R2 MOVZWL R4, R4 MOVZWL #SS$_NOLOGNAM, R0 CLRL R6 ; ; Main scanning loop. ; 20$: DECL R4 ; Pattern exhausted? BLSS 40$ ; Branch if yes. MOVZBL (R5)+, R1 ; Get next character in pattern CMPB R1, #^A/*/ ; Wild string? BEQL 70$ ; Branch if yes DECL R2 ; Candidate exhausted? BLSS 60$ ; Branch if yes CMPB R1, (R3)+ ; Compare pattern with candidate BEQL 20$ ; Loop if match CMPB R1, #^A/%/ ; Wild (joker) character? BEQL 20$ ; Branch if yes. ; ; We have detected a mismatch, or we are out of pattern while there is ; candidate left. Back up to the last '*', advance a candidate character, ; and try again. ; 30$: DECL R6 ; Count a saved candidate char BLSS 60$ ; Branch if none saved INCL R7 ; Set to try next character MOVQ R6, R2 ; Restore descriptors to backup MOVQ R8, R4 BRB 20$ ; Continue testing. ; ; Here when pattern is exhausted. ; 40$: TSTL R2 ; Candidate exhausted? BNEQ 30$ ; Branch if no ; ; Here to return. ; 50$: MOVL S^#1, R0 60$: RET ; ; We have detected a '*' in the pattern. Save the descriptors for later ; backtracking. ; 70$: TSTL R4 ; Pattern null after '*'? BEQL 50$ ; Branch if yes MOVQ R2, R6 ; Save both descriptors MOVQ R4, R8 BRB 20$ ; Continue testing. .END