1 ///////////////////////////////////////////////////////////////////////////
4 // Updated: 19-Jul-1998
6 // Copyright: Ferdinand Prantl (I'm sorry, author unknown ...)
7 // E-mail: prantl@ff.cuni.cz
9 // File-like string pattern matching routines
11 // You are free to use or modify this code to the following restrictions:
12 // - Acknowledge me somewhere in your about box, simple "Parts of code by.."
13 // will be enough. If you can't (or don't want to), contact me personally.
14 // - LEAVE THIS HEADER INTACT
15 ////////////////////////////////////////////////////////////////////////////
19 /******************************************************************************
21 * Functions for matching filename patterns to filenames.
24 * Filename patterns are composed of regular (printable) characters which
25 * may comprise a filename as well as special pattern matching characters:
27 * . Matches a period (.).
28 * Note that a period in a filename is not treated any
29 * differently than any other character.
32 * Matches any single character except '/' or '\'.
35 * Matches zero or more occurences of any characters other
37 * Leading '*' characters are allowed.
39 * SUB Substitute (^Z).
40 * Similar to '*', this matches zero or more occurences of
41 * any characters other than '/', '\', or '.'.
42 * Leading '^Z' characters are allowed.
45 * Matches the single character 'a' or 'b'.
46 * If the dash '-' character is to be included, it must
47 * immediately follow the opening bracket '['.
48 * If the closing bracket ']' character is to be included,
49 * it must be preceded by a quote '`'.
52 * Matches a single character in the range 'a' to 'z'.
53 * Ranges and sets may be combined within the same set of
56 * [!R] Exclusive range.
57 * Matches a single character not in the range 'R'.
58 * If range 'R' includes the dash '-' character, the dash
59 * must immediately follow the caret '!'.
62 * Makes the following pattern (up to the next '/') match
63 * any filename except those what it would normally match.
65 * / Path separator (UNIX and DOS).
66 * Matches a '/' or '\' pathname (directory) separator.
67 * Multiple separators are treated like a single
69 * A leading separator indicates an absolute pathname.
71 * \ Path separator (DOS).
72 * Same as the '/' character.
73 * Note that this character must be escaped if used within
74 * string constants ("\\").
77 * Makes the next character a regular (nonspecial)
79 * Note that to match the quote character itself, it must
81 * Note that this character must be escaped if used within
82 * string constants ("\\").
85 * Makes the next character a regular (nonspecial)
87 * Note that to match the quote character itself, it must
90 * Upper and lower case alphabetic characters are considered identical,
91 * i.e., 'a' and 'A' match each other.
92 * (What constitutes a lowercase letter depends on the current locale
95 * Spaces and control characters are treated as normal characters.
98 * The following patterns in the left column will match the filenames in
99 * the middle column and will not match filenames in the right column:
101 * Pattern Will Match Will Not Match
102 * ------- ---------- --------------
103 * a a (only) (anything else)
104 * a. a. (only) (anything else)
105 * a?c abc, acc, arc, a.c a, ac, abbc
106 * a*c ac, abc, abbc, acc, a.c a, ab, acb, bac
107 * a* a, ab, abb, a., a.b b, ba
108 * * a, ab, abb, a., .foo, a.foo (nothing)
109 * *. a., ab., abb., a.foo. a, ab, a.foo, .foo
110 * *.* a., a.b, ah.bc.foo a
111 * ^Z a, ab, abb a., .foo, a.foo
112 * ^Z. a., ab., abb. a, .foo, a.foo
113 * ^Z.* a, a., .foo, a.foo ab, abb
114 * *2.c 2.c, 12.c, foo2.c, foo.12.c 2x.c
115 * a[b-z]c abc, acc, azc (only) (anything else)
116 * [ab0-9]x ax, bx, 0x, 9x zx
117 * a[-.]b a-b, a.b (only) (anything else)
118 * a[!a-z]b a0b, a.b, a@b aab, azb, aa0b
119 * a[!-b]x a0x, a+x, acx a-x, abx, axxx
120 * a[-!b]x a-x, a!x, abx (only) (anything else)
121 * a[`]]x a]x (only) (anything else)
122 * a``x a`x (only) (anything else)
123 * oh`! oh! (only) (anything else)
124 * is`?it is?it (only) (anything else)
125 * !a?c a, ac, ab, abb, acb, a.foo abc, a.c, azc
129 #define FPAT_QUOTE _T('\\') /* Quotes a special char */
130 #define FPAT_QUOTE2 _T('`') /* Quotes a special char */
131 #define FPAT_DEL _T('/') /* Path delimiter */
132 #define FPAT_DEL2 _T('\\') /* Path delimiter */
133 #define FPAT_DOT _T('.') /* Dot char */
134 #define FPAT_NOT _T('!') /* Exclusion */
135 #define FPAT_ANY _T('?') /* Any one char */
136 #define FPAT_CLOS _T('*') /* Zero or more chars */
137 #define FPAT_CLOSP _T('\x1A') /* Zero or more nondelimiters */
138 #define FPAT_SET_L _T('[') /* Set/range open bracket */
139 #define FPAT_SET_R _T(']') /* Set/range close bracket */
140 #define FPAT_SET_NOT _T('!') /* Set exclusion */
141 #define FPAT_SET_THRU _T('-') /* Set range of chars */
143 int EDITPADC_CLASS fpattern_isvalid (LPCTSTR pat);
144 int EDITPADC_CLASS fpattern_match (LPCTSTR pat, LPCTSTR fname);
145 int EDITPADC_CLASS fpattern_matchn (LPCTSTR pat, LPCTSTR fname);