gawk: Extension Sample Fnmatch
1
1 16.7.2 Interface to 'fnmatch()'
1 -------------------------------
1
1 This extension provides an interface to the C library 'fnmatch()'
1 function. The usage is:
1
1 '@load "fnmatch"'
1 This is how you load the extension.
1
1 'result = fnmatch(pattern, string, flags)'
1 The return value is zero on success, 'FNM_NOMATCH' if the string
1 did not match the pattern, or a different nonzero value if an error
1 occurred.
1
1 In addition to the 'fnmatch()' function, the 'fnmatch' extension adds
1 one constant ('FNM_NOMATCH'), and an array of flag values named 'FNM'.
1
1 The arguments to 'fnmatch()' are:
1
1 'pattern'
1 The file name wildcard to match
1
1 'string'
1 The file name string
1
1 'flag'
1 Either zero, or the bitwise OR of one or more of the flags in the
1 'FNM' array
1
1 The flags are as follows:
1
1 Array element Corresponding flag defined by 'fnmatch()'
1 --------------------------------------------------------------------------
1 'FNM["CASEFOLD"]' 'FNM_CASEFOLD'
1 'FNM["FILE_NAME"]' 'FNM_FILE_NAME'
1 'FNM["LEADING_DIR"]''FNM_LEADING_DIR'
1 'FNM["NOESCAPE"]' 'FNM_NOESCAPE'
1 'FNM["PATHNAME"]' 'FNM_PATHNAME'
1 'FNM["PERIOD"]' 'FNM_PERIOD'
1
1 Here is an example:
1
1 @load "fnmatch"
1 ...
1 flags = or(FNM["PERIOD"], FNM["NOESCAPE"])
1 if (fnmatch("*.a", "foo.c", flags) == FNM_NOMATCH)
1 print "no match"
1