PNMATCH - perform simple pattern match.

Usage:

B:
   val = pnmatch( name, pattern );
C:
   int pnmatch(const char *name, const char *pattern);

Where:

val
receives the value of one if the string "name" matches the "pattern" string, and zero otherwise.

Description:

PNMATCH determines whether or not the pattern in the ASCII string "pattern" matches the ASCII string in "name". The pattern is constructed as follows.

*
"*" matches any sequence of characters (including the empty string). The SHORTEST possible sequence is matched.
?
The character "?" matches any single character. Thus "a?c" matches "aac", "abc", "acc", etc.
[]
A class of characters may be matched by enclosing the members of that class in brackets. For example, "[axq]" will match any one of the characters 'a', 'x', or 'q'. A range of characters may be matched by specifying the lower and upper bounds separated by a dash. "[a-d]" will match the characters 'a', 'b', 'c', or 'd'.

Any character not mentioned above matches only itself. PNMATCH distinguishes between letters in upper and lower case, so if an application does not distinguish between cases, the user must change both "name" and "pattern" to the same case.

The application for which PNMATCH was written was the matching of file (path) names with a pattern. For example, the pattern "pas*.b" would match all strings beginning with "pas" and ending with ".b". It might very well be useful for a wider range of applications.

Warning:

To implement "*", the routine recurses. You should be sure to have either short strings (12 characters) or enough stack space to allow for a large number of function calls.

Copyright © 1996, Thinkage Ltd.