Next: , Previous: Extension Sample File Functions, Up: Extension Samples

16.7.2 Interface To fnmatch()

This extension provides an interface to the C library fnmatch() function. The usage is:

     @load "fnmatch"
     result = fnmatch(pattern, string, flags)

The fnmatch extension adds a single function named fnmatch(), one constant (FNM_NOMATCH), and an array of flag values named FNM.

The arguments to fnmatch() are:

The filename wildcard to match.
The filename string.
Either zero, or the bitwise OR of one or more of the flags in the FNM array.

The return value is zero on success, FNM_NOMATCH if the string did not match the pattern, or a different non-zero value if an error occurred.

The flags are follows:

FNM["CASEFOLD"] Corresponds to the FNM_CASEFOLD flag as defined in fnmatch().

FNM["FILE_NAME"] Corresponds to the FNM_FILE_NAME flag as defined in fnmatch().

FNM["LEADING_DIR"] Corresponds to the FNM_LEADING_DIR flag as defined in fnmatch().

FNM["NOESCAPE"] Corresponds to the FNM_NOESCAPE flag as defined in fnmatch().

FNM["PATHNAME"] Corresponds to the FNM_PATHNAME flag as defined in fnmatch().

FNM["PERIOD"] Corresponds to the FNM_PERIOD flag as defined in fnmatch().

Here is an example:

     @load "fnmatch"
     flags = or(FNM["PERIOD"], FNM["NOESCAPE"])
     if (fnmatch("*.a", "foo.c", flags) == FNM_NOMATCH)
         print "no match"