
                               					 7-Jan-1983 13:29:12	VAX-11 FORTRAN V3.1-23              Page   1
								14-Dec-1982 16:57:47	SYS$SYSROOT:[CAMAC.CTS]WCMATCH.FOR;7        

0001    	INTEGER*4 FUNCTION WCMATCH(MATCH_STRING, STRING)
0002    C
0003    C This function compares two strings for matching patterns.  The first string
0004    C (the "match_string") specifies the pattern and may contain the wildcard
0005    C characters "*" and/or "%".  The function returns the following values:
0006    C	1	if "string" is of the pattern specified by "match_string"
0007    C	0	otherwise
0008    C
0009    C
0010    C This routine is implemented essentially as a code-driven finite state machine,
0011    C except that a little bit of additional "memory" is kept in the temporary
0012    C variables M_TEMP and S_TEMP.  These variables retain the starting points for
0013    C pattern checking after a "*" in the match string.  If a pattern match fails,
0014    C the index variables can be quickly reset using the temporary variables.
0015    C
0016    C
0017    C   Date	By		Comments
0018    C 12/14/82	D.E.Greenwood	Original
0019    C
0020    C
0021    	CHARACTER M_CHAR*1, MATCH_STRING*(*), STRING*(*)
0022    	INTEGER*2 M_INDEX, MATCH_LEN, M_TEMP, S_INDEX, STR_LEN, S_TEMP
0023    C
0024    C
0025    	M_INDEX = 0
0026    	MATCH_LEN = LEN(MATCH_STRING)
0027    	S_INDEX = 0
0028    	STR_LEN = LEN(STRING)
0029    C
0030    C "State 1" - String is of form specified by match string, so far.  We check
0031    C the strings on a character by character basis, until the end of a string
0032    C or a "*" is reached.
0033    C
0034    10100	M_INDEX = M_INDEX + 1
0035    	S_INDEX = S_INDEX + 1
0036    	M_CHAR = MATCH_STRING(M_INDEX:M_INDEX)
0037    	IF (M_INDEX .GT. MATCH_LEN .AND. S_INDEX .GT. STR_LEN) GOTO 80000
0038    	IF (M_INDEX .GT. MATCH_LEN) GOTO 82000
0039    	IF (M_CHAR .EQ. '*') GOTO 10200
0040    	IF (S_INDEX .GT. STR_LEN) GOTO 82000
0041    	IF (M_CHAR .EQ. '%' .OR. M_CHAR .EQ. STRING(S_INDEX:S_INDEX))
0042         &		GOTO 10100
0043    	GOTO 82000
0044    C
0045    C "State 2" - Last match char was a "*"
0046    C
0047    10200	M_INDEX = M_INDEX + 1
0048    	IF (M_INDEX .GT. MATCH_LEN) GOTO 80000
0049    	M_CHAR = MATCH_STRING(M_INDEX:M_INDEX)
0050    	IF (M_CHAR .EQ. '*') GOTO 10200
0051    	IF (M_CHAR .NE. '%') GOTO 10400
0052    C
0053    C "State 3" - Last two match chars were "*%".  We treat that as if only the
0054    C "%" had been specified, i.e., we match only the current string char.
0055    C
0056    	IF (S_INDEX .GT. STR_LEN) GOTO 82000
0057    	GOTO 10100

WCMATCH                        					 7-Jan-1983 13:29:12	VAX-11 FORTRAN V3.1-23              Page   2
								14-Dec-1982 16:57:47	SYS$SYSROOT:[CAMAC.CTS]WCMATCH.FOR;7        

0058    C
0059    C "State 4" - Last match char was a "*", this match char is not - we want to
0060    C find a char in the string which equals this match char.
0061    C
0062    10400	IF (S_INDEX .GT. STR_LEN) GOTO 82000
0063    	IF (M_CHAR .EQ. STRING(S_INDEX:S_INDEX)) THEN
0064    	    M_TEMP = M_INDEX				! found - save starting
0065    	    S_TEMP = S_INDEX				!  index of string which
0066    	    GOTO 10500					!  may terminate "*" matching
0067    	ENDIF
0068    	S_INDEX = S_INDEX + 1
0069    	GOTO 10400
0070    C
0071    C "State 5" - First match char after "*" is same as current string char.  We
0072    C want to know if we have found a string which will terminate the wildcard match.
0073    C The things which identify such a string are end of both strings or another
0074    C wildcard char.
0075    C
0076    10500	M_INDEX = M_INDEX + 1
0077    	S_INDEX = S_INDEX + 1
0078    	IF (M_INDEX .GT. MATCH_LEN .AND. S_INDEX .GT. STR_LEN) GOTO 80000
0079    	IF (M_INDEX .GT. MATCH_LEN) GOTO 10600
0080    	M_CHAR = MATCH_STRING(M_INDEX:M_INDEX)
0081    	IF (M_CHAR .EQ. '*') GOTO 10200
0082    	IF (S_INDEX .GT. STR_LEN) GOTO 82000
0083    	IF (M_CHAR .EQ. '%') GOTO 10100
0084    	IF (M_CHAR .EQ. STRING(S_INDEX:S_INDEX)) GOTO 10500
0085    C
0086    C "State 6" - Failed to match string after "*" - restart test one char further
0087    C in the string
0088    C
0089    10600	M_INDEX = M_TEMP
0090    	S_INDEX = S_TEMP + 1
0091    	M_CHAR = MATCH_STRING(M_INDEX:M_INDEX)
0092    	GOTO 10400
0093    C
0094    C SUCCESS
0095    C
0096    80000	WCMATCH = 1
0097    	GOTO 89900
0098    C
0099    C FAIL
0100    C
0101    82000	WCMATCH = 0
0102    C
0103    89900	RETURN
0104    	END

WCMATCH                        					 7-Jan-1983 13:29:12	VAX-11 FORTRAN V3.1-23              Page   3
								14-Dec-1982 16:57:47	SYS$SYSROOT:[CAMAC.CTS]WCMATCH.FOR;7        

PROGRAM SECTIONS

    Name				 Bytes   Attributes

  0 $CODE                                  432   PIC CON REL LCL   SHR   EXE   RD NOWRT LONG
  2 $LOCAL                                  36   PIC CON REL LCL NOSHR NOEXE   RD   WRT LONG

    Total Space Allocated                  468


ENTRY POINTS

    Address  Type  Name          

  0-00000000  I*4  WCMATCH       


VARIABLES

    Address  Type  Name              Address  Type  Name              Address  Type  Name              Address  Type  Name          

  2-00000004  I*2  MATCH_LEN      AP-00000004@ CHAR MATCH_STRING    2-00000000  CHAR M_CHAR          2-00000002  I*2  M_INDEX       
  2-00000006  I*2  M_TEMP         AP-00000008@ CHAR STRING          2-0000000A  I*2  STR_LEN         2-00000008  I*2  S_INDEX       
  2-0000000C  I*2  S_TEMP        


LABELS

    Address   Label       Address   Label       Address   Label       Address   Label       Address   Label       Address   Label   

  0-00000035  10100     0-000000A9  10200     0-000000E3  10400     0-0000011B  10500     0-00000180  10600     0-000001A2  80000   
  0-000001A8  82000     0-000001AB  89900   


COMMAND QUALIFIERS

  FORTRAN /LIS CTS,CTSASSIGN,CTSDEASGN,CTSMODIFY,CTSSET,CTSSHOW,WCCOPY,WCMATCH

  /CHECK=(NOBOUNDS,OVERFLOW,NOUNDERFLOW)
  /DEBUG=(NOSYMBOLS,TRACEBACK)
  /STANDARD=(NOSYNTAX,NOSOURCE_FORM)
  /SHOW=(NOPREPROCESSOR,NOINCLUDE,MAP)
  /F77  /NOG_FLOATING  /I4  /OPTIMIZE  /WARNINGS  /NOD_LINES  /NOCROSS_REFERENCE  /NOMACHINE_CODE  /CONTINUATIONS=19


COMPILATION STATISTICS

  Run Time:           1.45 seconds
  Elapsed Time:       1.68 seconds
  Page Faults:        1
  Dynamic Memory:     382 pages
