.MCALL .MODULE .MODULE DIRMAT,VERSION=02,COMMENT= IDENT=NO ; Copyright (c) 1998 by Mentec, Inc., Nashua, NH. ; All rights reserved ; ; This software is furnished under a license for use only on a ; single computer system and may be copied only with the ; inclusion of the above copyright notice. This software, or ; any other copies thereof, may not be provided or otherwise ; made available to any other person except for use on such ; system and to one who agrees to these license terms. Title ; to and ownership of the software shall at all times remain ; in Mentec, Inc. ; ; The information in this document is subject to change without ; notice and should not be construed as a commitment by Digital ; Equipment Corporation, or Mentec, Inc. ; ; Digital and Mentec assume no responsibility for the use or ; reliability of its software on equipment which is not supplied ; by Digital or Mentec, and listed in the Software Product ; Description. ; DIR (Directory Program) ; .NLIST .LIST .PSECT MATCH ;+ ; Module DIRMAT ; This module contains the filename matching routines for DIR. ;- DFLAG: .WORD 0 ;Flag word for /BEFORE and /SINCE FL.BEF = 000001 ;/BEFORE switch FLAG FL.SIN = 000002 ;/SINCE switch FLAG .SBTTL MATCH1- Filename match driver ;+ ; MATCH1 ; This is the driver for matching input filenames against the directory ; entries. ; INPUTS: ; R5 -> directory entry ; OUTPUTS: ; R0 <> 0 if any of the input files matched the current file ; R0-R4 modified ; CHARS contains the ASCII of the current filename ; SWG is turned off if R0 <>0 ;- .PAGE ;+ ; The flowchart below defines how the /D, /G, and /P options modify the ; return value (success or failure) of the basic search algorithm. ; ; _________ (A) ; / \ no ! ; / Permanent \_______V___ ; \ file? / ; \_________/ ; ! ; ! yes ; ! ; ____V____ _________ _________ ; / File \ no / \ no / \ no ___ ; / names \___________/ /G \___________/ /P \___________!A! ; \ match? / \ given? / \ given? / V ; \_________/ \_________/ \_________/ ; ! ! ! ; ! yes ! yes ! yes ; ! _V_ V ; ! !A! !<--------- ; ! V ! ; ! ! ; V _________ ! _________ ; +-------+ / \ no ! / \ no ; ! /G=0 !_____________/ /P \_______V___/ Dates \______ ; +-------+ \ given? / \ given? / ^ ; \_________/ \_________/ ! ; ! ! ! ; ! yes ! yes ! ; _V_ ! ! ; !A! ____V____ ! ; V / \ yes ! ; / Dates \____! ; \ match? / ; \_________/ ; ! ; ! no ; _V_ ; !A! ; V ;- XTERNL GBLDAT GBLDAT MATCH1:: MOV R5,R0 ;Point to the directory entry ADD #DE.FN1,R0 ;Point to the 1st word of the filename MOV #CHARS,R1 ;Point to storage area for ASCII of the name CALL RTOA ;Convert the filename to ASCII BIT #DS.PRM,@R5 ;Is it a permanent file? BNE 2$ ;Branch if so 1$: CLR R0 ;Signal no match BR 9$ ; and return 2$: MOV #PATS,R3 ;Point to input filenames TST SWG ;'start at' option turned on? BEQ 3$ ;Branch if not MOV #SPATS,R3 ;Else point at the name we have to find first 3$: MOV INSPCS,R4 ;Get the number of filespecs BEQ 1$ ;Branch if none 4$: MOV R3,R1 ;Point to the input string MOV #CHARS,R2 ;Point to the filename (from directory) CALL MATCH ;Go see if the filenames match TST R0 ;Did they match? BEQ 5$ ;Branch if not. We're done MOV R3,R1 ;Point to the test string again ADD #7,R1 ;Point to the extension ADD #7,R2 ;Point to the extension CALL MATCH ;Go see if the filetypes match TST R0 ;Did they match? BNE 7$ ;Branch if so 5$: DEC R4 ;Down the count of file specs BEQ 6$ ;Branch if done TST SWG ;Doing a 'start at'? BNE 9$ ;Branch if so ADD #13,R3 ;Point to the next input spec BR 4$ ; and go try it. 6$: TST SWP ;Doing an 'exclude' ? BEQ 9$ ;Branch if not... No match INC R0 ;Else fake a match BR 8$ ; and go check the date 7$: CLR SWG ;We've matched, so clear the 'start at' switch TST SWP ;Doing the 'exclude' option? BNE 1$ ;Yes. Fake a no match. 8$: TST SWD ;Are we doing /DATE? BEQ 83$ ;Branch if not CLR DFLAG ;Clear date option flag CALL CHKDAT ;See if file has valid date BR 9$ ;Return 83$: CLR DFLAG ;Clear date option flag TST SWK ;Doing /BEFORE? BEQ 85$ ;Branch if not BIS #FL.BEF,DFLAG ;Set flag for CHKDAT CALL CHKDAT ;Check for a valid date for /BEFORE TST R0 ;Did the dates match? BEQ 9$ ;Branch if not 85$: CLR DFLAG ;Clear date option flag TST SWJ ;Doing /SINCE? BEQ 9$ ;Branch if not BIS #FL.SIN,DFLAG ;Set flag for CHKDAT CALL CHKDAT ;Check for a valid date for /SINCE 9$: RETURN .SBTTL MATCH- Pattern match routine ;+ ; MATCH ; This routine does a wildcard pattern match against an ASCII pattern string ; pointed to by R1 and a test string pointed to by R2. The matchable ; wildcards are: ; "%" => match any non-null, non-blank character ; "*" => match any string ; Both strings must end in an ASCII blank. ; If there is a match, R0 returns as <> 0. ; R1 is modified. ;- GBLDAT MATCH:: .SAVRG CLR R0 ;Assume failure MOV #BLANK,R4 ;An ASCII blank is often used 1$: MOVB (R1)+,R3 ;Get the next pattern character CMPB #ASTERK,R3 ;Is it a "*"? BNE 2$ ;Branch if not CMPB @R1,R4 ;Are we at the end of the string? BEQ 3$ ;Branch if so. We have a match 2$: CMPB @R2,R4 ;Is this the end of the test string? BNE 4$ ;Branch if not CMPB R3,R4 ;At the end of the pattern string? BNE 6$ ;Branch if not. Return a level 3$: INC R0 ;Else it matched!!! BR 6$ ;Return a level 4$: CMPB R3,R4 ;Is this the end of the pattern string? BEQ 6$ ;Branch if so CMPB #ASTERK,R3 ;Is the pattern character a "*"? BEQ 5$ ;Branch if so CMPB (R2)+,R3 ;Does test char match pattern char? BEQ 1$ ;Branch if yes CMPB #PRCENT,R3 ;Is the pattern char a "%"? BEQ 1$ ;Branch if so. It matches. BR 6$ ;Else return to caller 5$: MOV R1,-(SP) ;Save R1 MOV R2,-(SP) ; and R2 JSR PC,1$ ;And call self!!!! MOV (SP)+,R2 ;Restore R2 MOV (SP)+,R1 ; and R1 TST R0 ;Did the strings match? BNE 6$ ;Branch if so CMPB (R2)+,R4 ;At the end of the test string yet? BNE 5$ ;Branch if not 6$: RETURN ;Return a level .SBTTL CHKDAT- Check two dates for a 'match' ;+ ; CHKDAT ; This routine is used to determine if the current file qualifies ; as a match in regards to its creation date. It is only called ; if /D, /J, or /K was specified on the command line. ; INPUTS: ; DFLAG - If FL.BEF or FL.SIN is is set in it, CHKDAT will ; check for a /BEFORE or /SINCE match. If neither is set ; CHKDAT will assume /DATE. ; R5 -> a directory entry ; OUTPUTS: ; R0 <> 0 if the dates match ; R1-R4 modified ;- XTERNL GBLDAT GBLDAT CHKDAT:: MOV #UDATE,R2 ;R2 -> /DATE storage area BIT #FL.BEF,DFLAG ;Doing /BEFORE this time? BEQ 7$ ;Branch if not MOV #KDATE,R2 ;R2 -> /BEFORE storage area 7$: BIT #FL.SIN,DFLAG ;Doing /SINCE this time? BEQ 8$ ;Branch if not MOV #JDATE,R2 ;R2 -> /SINCE storage area 8$: MOV DE.DAT(R5),R0 ;Get the file's creation date CALL CONDAT ;Make it useful CLR R0 ;Clear the match flag MOV #TYEAR+2,R1 ;Point to the converted year MOV #3,R3 ;Initialize a counter 1$: MOV -(R1),R4 ;Get the file's creation date SUB (R2)+,R4 ;Subtract the given date BEQ 4$ ;Branch if they are the same BLT 2$ ;Branch if created before given date BIT #FL.SIN,DFLAG ;'since' switch? BR 3$ ; 2$: BIT #FL.BEF,DFLAG ;'before' switch? 3$: BEQ 6$ ;Branch if not BR 5$ ; 4$: DEC R3 ;Down the counter BNE 1$ ;Try again BIT #FL.BEF,DFLAG ;'before' switch? BNE 6$ ;Branch if so 5$: INC R0 ;Good date. 6$: RETURN .END