-- Match.mesa -- modified by McCreight, September 8, 1980 4:30 PM -- written by McCreight, May 30, 1980 6:08 PM -- edited by Brotz, November 19, 1981 9:59 AM DIRECTORY MatchDefs USING []; Match: PROGRAM EXPORTS MatchDefs = BEGIN IsMatch: PUBLIC PROCEDURE [name, pattern: STRING] RETURNS [BOOLEAN] = BEGIN -- does the name match the pattern? patternPos, namePos, patternAnchor, nameAnchor: CARDINAL; patternAnchor _ nameAnchor _ 0; -- where name began matching non-* seg of pattern patternPos _ patternAnchor; namePos _ nameAnchor; -- next compare position DO -- loop for last '* in pattern. WHILE patternPos BEGIN IF patternPos # 0 AND patternPos = patternAnchor THEN -- first char(s) of * segment {patternAnchor _ patternAnchor + 1; nameAnchor _ namePos + 1}; patternPos _ patternPos + 1; namePos _ namePos + 1; END; (pattern[patternPos] = '' AND patternPos < pattern.length - 1 AND pattern[patternPos + 1] = name[namePos]) => -- quoted character matches {patternPos _ patternPos + 2; namePos _ namePos + 1}; pattern[patternPos] = name[namePos] => -- chars match {patternPos _ patternPos + 1; namePos_ namePos + 1}; ENDCASE => BEGIN IF patternAnchor = 0 THEN RETURN[FALSE]; -- char mismatch, no pattern * yet. patternPos _ patternAnchor; namePos _ nameAnchor _ nameAnchor + 1; END; ENDLOOP; IF namePos >= name.length OR patternAnchor >= pattern.length THEN RETURN[TRUE]; -- name finished or pattern ends with * -- WHILE namePos < name.length DO -- skip trailing .'s or !ddd in name SELECT name[namePos] FROM '. => NULL; '! => BEGIN namePos _ namePos + 1; WHILE namePos < name.length DO SELECT name[namePos] FROM IN ['0 .. '9] => NULL; ENDCASE => EXIT; namePos _ namePos + 1; ENDLOOP; END; ENDCASE => EXIT; namePos _ namePos + 1; REPEAT FINISHED => RETURN[TRUE]; -- Trailing stuff was harmless. ENDLOOP; IF patternAnchor = 0 THEN RETURN[FALSE] ELSE {patternPos _ patternAnchor; namePos _ nameAnchor _ nameAnchor + 1}; ENDLOOP; END; -- of IsMatch -- Capitalize: PUBLIC PROCEDURE [s, capS: STRING] = BEGIN capS.length _ s.length; FOR i: CARDINAL IN [0 .. s.length) DO c: CHARACTER _ s[i]; capS[i] _ IF c IN ['a .. 'z] THEN c - 40B ELSE c; ENDLOOP; END; -- of Capitalize -- UnCapitalize: PUBLIC PROCEDURE [s, unCapS: STRING] = BEGIN unCapS.length _ s.length; FOR i: CARDINAL IN [0 .. s.length) DO c: CHARACTER _ s[i]; unCapS[i] _ IF c IN ['A .. 'Z] THEN c + 40B ELSE c; ENDLOOP; END; -- of UnCapitalize -- END. -- of Match --z19932(1270)\f1