Next: , Previous: , Up: Extension Samples   [Contents][Index]


16.7.2 Interface To fnmatch()

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

@load "fnmatch"

This is how you load the extension.

result = fnmatch(pattern, string, flags)

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.

Besides the fnmatch() function, the fnmatch extension adds one constant (FNM_NOMATCH), and an array of flag values named FNM.

The arguments to fnmatch() are:

pattern

The filename wildcard to match.

string

The filename string.

flag

Either zero, or the bitwise OR of one or more of the flags in the FNM array.

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"