Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

829 lines
26 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. wild.c
  5. Abstract:
  6. This module implements functions to process wildcard specifiers.
  7. Author:
  8. Vijesh
  9. Revision History:
  10. --*/
  11. //
  12. // These following bit values are set in the FsRtlLegalDbcsCharacterArray
  13. //
  14. #define FSRTL_FAT_LEGAL 0x01
  15. #define FSRTL_HPFS_LEGAL 0x02
  16. #define FSRTL_NTFS_LEGAL 0x04
  17. #define FSRTL_WILD_CHARACTER 0x08
  18. #define FSRTL_OLE_LEGAL 0x10
  19. #define FSRTL_NTFS_STREAM_LEGAL (FSRTL_NTFS_LEGAL | FSRTL_OLE_LEGAL)
  20. //
  21. // The global static legal ANSI character array. Wild characters
  22. // are not considered legal, they should be checked seperately if
  23. // allowed.
  24. //
  25. #define _FAT_ FSRTL_FAT_LEGAL
  26. #define _HPFS_ FSRTL_HPFS_LEGAL
  27. #define _NTFS_ FSRTL_NTFS_LEGAL
  28. #define _OLE_ FSRTL_OLE_LEGAL
  29. #define _WILD_ FSRTL_WILD_CHARACTER
  30. static const UCHAR LocalLegalAnsiCharacterArray[128] = {
  31. 0 , // 0x00 ^@
  32. _OLE_, // 0x01 ^A
  33. _OLE_, // 0x02 ^B
  34. _OLE_, // 0x03 ^C
  35. _OLE_, // 0x04 ^D
  36. _OLE_, // 0x05 ^E
  37. _OLE_, // 0x06 ^F
  38. _OLE_, // 0x07 ^G
  39. _OLE_, // 0x08 ^H
  40. _OLE_, // 0x09 ^I
  41. _OLE_, // 0x0A ^J
  42. _OLE_, // 0x0B ^K
  43. _OLE_, // 0x0C ^L
  44. _OLE_, // 0x0D ^M
  45. _OLE_, // 0x0E ^N
  46. _OLE_, // 0x0F ^O
  47. _OLE_, // 0x10 ^P
  48. _OLE_, // 0x11 ^Q
  49. _OLE_, // 0x12 ^R
  50. _OLE_, // 0x13 ^S
  51. _OLE_, // 0x14 ^T
  52. _OLE_, // 0x15 ^U
  53. _OLE_, // 0x16 ^V
  54. _OLE_, // 0x17 ^W
  55. _OLE_, // 0x18 ^X
  56. _OLE_, // 0x19 ^Y
  57. _OLE_, // 0x1A ^Z
  58. _OLE_, // 0x1B ESC
  59. _OLE_, // 0x1C FS
  60. _OLE_, // 0x1D GS
  61. _OLE_, // 0x1E RS
  62. _OLE_, // 0x1F US
  63. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x20 space
  64. _FAT_ | _HPFS_ | _NTFS_ , // 0x21 !
  65. _WILD_| _OLE_, // 0x22 "
  66. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x23 #
  67. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x24 $
  68. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x25 %
  69. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x26 &
  70. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x27 '
  71. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x28 (
  72. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x29 )
  73. _WILD_| _OLE_, // 0x2A *
  74. _HPFS_ | _NTFS_ | _OLE_, // 0x2B +
  75. _HPFS_ | _NTFS_ | _OLE_, // 0x2C ,
  76. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x2D -
  77. _FAT_ | _HPFS_ | _NTFS_ , // 0x2E .
  78. 0 , // 0x2F /
  79. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x30 0
  80. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x31 1
  81. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x32 2
  82. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x33 3
  83. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x34 4
  84. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x35 5
  85. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x36 6
  86. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x37 7
  87. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x38 8
  88. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x39 9
  89. _NTFS_ , // 0x3A :
  90. _HPFS_ | _NTFS_ | _OLE_, // 0x3B ;
  91. _WILD_| _OLE_, // 0x3C <
  92. _HPFS_ | _NTFS_ | _OLE_, // 0x3D =
  93. _WILD_| _OLE_, // 0x3E >
  94. _WILD_| _OLE_, // 0x3F ?
  95. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x40 @
  96. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x41 A
  97. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x42 B
  98. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x43 C
  99. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x44 D
  100. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x45 E
  101. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x46 F
  102. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x47 G
  103. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x48 H
  104. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x49 I
  105. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x4A J
  106. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x4B K
  107. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x4C L
  108. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x4D M
  109. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x4E N
  110. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x4F O
  111. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x50 P
  112. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x51 Q
  113. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x52 R
  114. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x53 S
  115. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x54 T
  116. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x55 U
  117. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x56 V
  118. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x57 W
  119. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x58 X
  120. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x59 Y
  121. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x5A Z
  122. _HPFS_ | _NTFS_ | _OLE_, // 0x5B [
  123. 0 , // 0x5C backslash
  124. _HPFS_ | _NTFS_ | _OLE_, // 0x5D ]
  125. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x5E ^
  126. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x5F _
  127. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x60 `
  128. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x61 a
  129. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x62 b
  130. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x63 c
  131. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x64 d
  132. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x65 e
  133. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x66 f
  134. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x67 g
  135. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x68 h
  136. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x69 i
  137. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x6A j
  138. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x6B k
  139. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x6C l
  140. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x6D m
  141. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x6E n
  142. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x6F o
  143. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x70 p
  144. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x71 q
  145. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x72 r
  146. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x73 s
  147. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x74 t
  148. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x75 u
  149. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x76 v
  150. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x77 w
  151. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x78 x
  152. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x79 y
  153. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x7A z
  154. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x7B {
  155. 0 | _OLE_, // 0x7C |
  156. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x7D }
  157. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x7E ~
  158. _FAT_ | _HPFS_ | _NTFS_ | _OLE_, // 0x7F 
  159. };
  160. UCHAR const* const FsRtlLegalAnsiCharacterArray = &LocalLegalAnsiCharacterArray[0];
  161. #define LEGAL_ANSI_CHARACTER_ARRAY (FsRtlLegalAnsiCharacterArray)
  162. #define mQueryBits(uFlags, uBits) ((uFlags) & (uBits))
  163. #define FlagOn(uFlags, uBit) (mQueryBits(uFlags, uBit) != 0)
  164. #define IsUnicodeCharacterWild(C) ( \
  165. (((C) >= 0x40) ? FALSE : FlagOn( LEGAL_ANSI_CHARACTER_ARRAY[(C)], \
  166. FSRTL_WILD_CHARACTER ) ) \
  167. )
  168. typedef struct _UNICODE_STRING {
  169. USHORT Length;
  170. USHORT MaximumLength;
  171. PWSTR Buffer;
  172. } UNICODE_STRING, *PUNICODE_STRING;
  173. #define DOS_STAR TEXT('<')
  174. #define DOS_QM TEXT('>')
  175. #define DOS_DOT TEXT('"')
  176. BOOLEAN
  177. DoesNameContainWildCards (
  178. IN PTSTR Name
  179. )
  180. /*++
  181. Routine Description:
  182. This routine simply scans the input Name string looking for any Nt
  183. wild card characters.
  184. Arguments:
  185. Name - The string to check.
  186. Return Value:
  187. BOOLEAN - TRUE if one or more wild card characters was found.
  188. --*/
  189. {
  190. PTCHAR p;
  191. //
  192. // Check each character in the name to see if it's a wildcard
  193. // character.
  194. //
  195. if( lstrlen(Name) ) {
  196. for( p = Name + lstrlen(Name) - 1;
  197. p >= Name && *p != TEXT('\\') ;
  198. p-- ) {
  199. //
  200. // check for a wild card character
  201. //
  202. if (IsUnicodeCharacterWild( *p )) {
  203. //
  204. // Tell caller that this name contains wild cards
  205. //
  206. return TRUE;
  207. }
  208. }
  209. }
  210. //
  211. // No wildcard characters were found, so return to our caller
  212. //
  213. return FALSE;
  214. }
  215. BOOLEAN
  216. IsNameInExpressionPrivate (
  217. IN PCTSTR Expression,
  218. IN PCTSTR Name
  219. )
  220. /*++
  221. Routine Description:
  222. This routine compares a Dbcs name and an expression and tells the caller
  223. if the name is in the language defined by the expression. The input name
  224. cannot contain wildcards, while the expression may contain wildcards.
  225. Expression wild cards are evaluated as shown in the nondeterministic
  226. finite automatons below. Note that ~* and ~? are DOS_STAR and DOS_QM.
  227. ~* is DOS_STAR, ~? is DOS_QM, and ~. is DOS_DOT
  228. S
  229. <-----<
  230. X | | e Y
  231. X * Y == (0)----->-(1)->-----(2)-----(3)
  232. S-.
  233. <-----<
  234. X | | e Y
  235. X ~* Y == (0)----->-(1)->-----(2)-----(3)
  236. X S S Y
  237. X ?? Y == (0)---(1)---(2)---(3)---(4)
  238. X . . Y
  239. X ~.~. Y == (0)---(1)----(2)------(3)---(4)
  240. | |________|
  241. | ^ |
  242. |_______________|
  243. ^EOF or .^
  244. X S-. S-. Y
  245. X ~?~? Y == (0)---(1)-----(2)-----(3)---(4)
  246. | |________|
  247. | ^ |
  248. |_______________|
  249. ^EOF or .^
  250. where S is any single character
  251. S-. is any single character except the final .
  252. e is a null character transition
  253. EOF is the end of the name string
  254. In words:
  255. * matches 0 or more characters.
  256. ? matches exactly 1 character.
  257. DOS_STAR matches 0 or more characters until encountering and matching
  258. the final . in the name.
  259. DOS_QM matches any single character, or upon encountering a period or
  260. end of name string, advances the expression to the end of the
  261. set of contiguous DOS_QMs.
  262. DOS_DOT matches either a . or zero characters beyond name string.
  263. Arguments:
  264. Expression - Supplies the input expression to check against
  265. (Caller must already upcase if passing CaseInsensitive TRUE.)
  266. Name - Supplies the input name to check for.
  267. CaseInsensitive - TRUE if Name should be Upcased before comparing.
  268. Return Value:
  269. BOOLEAN - TRUE if Name is an element in the set of strings denoted
  270. by the input Expression and FALSE otherwise.
  271. --*/
  272. {
  273. USHORT NameOffset;
  274. USHORT ExprOffset;
  275. ULONG SrcCount;
  276. ULONG DestCount;
  277. ULONG PreviousDestCount;
  278. ULONG MatchesCount;
  279. TCHAR NameChar, ExprChar;
  280. USHORT LocalBuffer[16 * 2];
  281. USHORT *AuxBuffer = NULL;
  282. USHORT *PreviousMatches;
  283. USHORT *CurrentMatches;
  284. USHORT MaxState;
  285. USHORT CurrentState;
  286. BOOLEAN NameFinished = FALSE;
  287. ULONG NameLen, ExpressionLen;
  288. //
  289. // The idea behind the algorithm is pretty simple. We keep track of
  290. // all possible locations in the regular expression that are matching
  291. // the name. If when the name has been exhausted one of the locations
  292. // in the expression is also just exhausted, the name is in the language
  293. // defined by the regular expression.
  294. //
  295. NameLen = lstrlen(Name)*sizeof(TCHAR);
  296. ExpressionLen = lstrlen(Expression)*sizeof(TCHAR);
  297. //
  298. // If one string is empty return FALSE. If both are empty return TRUE.
  299. //
  300. if ( (NameLen == 0) || (ExpressionLen == 0) ) {
  301. return (BOOLEAN)(!(NameLen + ExpressionLen));
  302. }
  303. //
  304. // Special case by far the most common wild card search of *
  305. //
  306. if ((ExpressionLen == 2) && (Expression[0] == TEXT('*'))) {
  307. return TRUE;
  308. }
  309. //
  310. // Also special case expressions of the form *X. With this and the prior
  311. // case we have covered virtually all normal queries.
  312. //
  313. if (Expression[0] == TEXT('*')) {
  314. TCHAR LocalExpression[MAX_PATH];
  315. ULONG LocalExpressionLen;
  316. lstrcpy( LocalExpression, Expression+1);
  317. LocalExpressionLen = lstrlen( LocalExpression )*sizeof(TCHAR);
  318. //
  319. // Only special case an expression with a single *
  320. //
  321. if ( !DoesNameContainWildCards( LocalExpression ) ) {
  322. ULONG StartingNameOffset;
  323. if (NameLen < (USHORT)(ExpressionLen-sizeof(TCHAR))) {
  324. return FALSE;
  325. }
  326. StartingNameOffset = ( NameLen -
  327. LocalExpressionLen )/sizeof(TCHAR);
  328. //
  329. // Do a simple memory compare if case sensitive, otherwise
  330. // we have got to check this one character at a time.
  331. //
  332. return (BOOLEAN) RtlEqualMemory( LocalExpression,
  333. Name + StartingNameOffset,
  334. LocalExpressionLen );
  335. }
  336. }
  337. //
  338. // Walk through the name string, picking off characters. We go one
  339. // character beyond the end because some wild cards are able to match
  340. // zero characters beyond the end of the string.
  341. //
  342. // With each new name character we determine a new set of states that
  343. // match the name so far. We use two arrays that we swap back and forth
  344. // for this purpose. One array lists the possible expression states for
  345. // all name characters up to but not including the current one, and other
  346. // array is used to build up the list of states considering the current
  347. // name character as well. The arrays are then switched and the process
  348. // repeated.
  349. //
  350. // There is not a one-to-one correspondence between state number and
  351. // offset into the expression. This is evident from the NFAs in the
  352. // initial comment to this function. State numbering is not continuous.
  353. // This allows a simple conversion between state number and expression
  354. // offset. Each character in the expression can represent one or two
  355. // states. * and DOS_STAR generate two states: ExprOffset*2 and
  356. // ExprOffset*2 + 1. All other expreesion characters can produce only
  357. // a single state. Thus ExprOffset = State/2.
  358. //
  359. //
  360. // Here is a short description of the variables involved:
  361. //
  362. // NameOffset - The offset of the current name char being processed.
  363. //
  364. // ExprOffset - The offset of the current expression char being processed.
  365. //
  366. // SrcCount - Prior match being investigated with current name char
  367. //
  368. // DestCount - Next location to put a matching assuming current name char
  369. //
  370. // NameFinished - Allows one more itteration through the Matches array
  371. // after the name is exhusted (to come *s for example)
  372. //
  373. // PreviousDestCount - This is used to prevent entry duplication, see coment
  374. //
  375. // PreviousMatches - Holds the previous set of matches (the Src array)
  376. //
  377. // CurrentMatches - Holds the current set of matches (the Dest array)
  378. //
  379. // AuxBuffer, LocalBuffer - the storage for the Matches arrays
  380. //
  381. //
  382. // Set up the initial variables
  383. //
  384. PreviousMatches = &LocalBuffer[0];
  385. CurrentMatches = &LocalBuffer[16];
  386. PreviousMatches[0] = 0;
  387. MatchesCount = 1;
  388. NameOffset = 0;
  389. MaxState = (USHORT)(ExpressionLen * 2);
  390. while ( !NameFinished ) {
  391. if ( NameOffset < NameLen ) {
  392. NameChar = Name[NameOffset / sizeof(TCHAR)];
  393. NameOffset += sizeof(TCHAR);;
  394. } else {
  395. NameFinished = TRUE;
  396. //
  397. // if we have already exhasted the expression, cool. Don't
  398. // continue.
  399. //
  400. if ( PreviousMatches[MatchesCount-1] == MaxState ) {
  401. break;
  402. }
  403. }
  404. //
  405. // Now, for each of the previous stored expression matches, see what
  406. // we can do with this name character.
  407. //
  408. SrcCount = 0;
  409. DestCount = 0;
  410. PreviousDestCount = 0;
  411. while ( SrcCount < MatchesCount ) {
  412. USHORT Length;
  413. //
  414. // We have to carry on our expression analysis as far as possible
  415. // for each character of name, so we loop here until the
  416. // expression stops matching. A clue here is that expression
  417. // cases that can match zero or more characters end with a
  418. // continue, while those that can accept only a single character
  419. // end with a break.
  420. //
  421. ExprOffset = (USHORT)((PreviousMatches[SrcCount++] + 1) / 2);
  422. Length = 0;
  423. while ( TRUE ) {
  424. if ( ExprOffset == ExpressionLen ) {
  425. break;
  426. }
  427. //
  428. // The first time through the loop we don't want
  429. // to increment ExprOffset.
  430. //
  431. ExprOffset += Length;
  432. Length = sizeof(TCHAR);
  433. CurrentState = (USHORT)(ExprOffset * 2);
  434. if ( ExprOffset == ExpressionLen ) {
  435. CurrentMatches[DestCount++] = MaxState;
  436. break;
  437. }
  438. ExprChar = Expression[ExprOffset / sizeof(TCHAR)];
  439. //
  440. // Before we get started, we have to check for something
  441. // really gross. We may be about to exhaust the local
  442. // space for ExpressionMatches[][], so we have to allocate
  443. // some pool if this is the case. Yuk!
  444. //
  445. if ( (DestCount >= 16 - 2) &&
  446. (AuxBuffer == NULL) ) {
  447. ULONG ExpressionChars;
  448. ExpressionChars = ExpressionLen / sizeof(TCHAR);
  449. AuxBuffer = malloc( (ExpressionChars+1) * sizeof(USHORT)*2*2 );
  450. RtlCopyMemory( AuxBuffer,
  451. CurrentMatches,
  452. 16 * sizeof(USHORT) );
  453. CurrentMatches = AuxBuffer;
  454. RtlCopyMemory( AuxBuffer + (ExpressionChars+1)*2,
  455. PreviousMatches,
  456. 16 * sizeof(USHORT) );
  457. PreviousMatches = AuxBuffer + (ExpressionChars+1)*2;
  458. }
  459. //
  460. // * matches any character zero or more times.
  461. //
  462. if (ExprChar == TEXT('*')) {
  463. CurrentMatches[DestCount++] = CurrentState;
  464. CurrentMatches[DestCount++] = CurrentState + 3;
  465. continue;
  466. }
  467. //
  468. // DOS_STAR matches any character except . zero or more times.
  469. //
  470. if (ExprChar == DOS_STAR) {
  471. BOOLEAN ICanEatADot = FALSE;
  472. //
  473. // If we are at a period, determine if we are allowed to
  474. // consume it, ie. make sure it is not the last one.
  475. //
  476. if ( !NameFinished && (NameChar == TEXT('.')) ) {
  477. USHORT Offset;
  478. for ( Offset = NameOffset;
  479. Offset < NameLen;
  480. Offset += Length ) {
  481. if (Name[Offset / sizeof(TCHAR)] == TEXT('.')) {
  482. ICanEatADot = TRUE;
  483. break;
  484. }
  485. }
  486. }
  487. if (NameFinished || (NameChar != TEXT('.')) || ICanEatADot) {
  488. CurrentMatches[DestCount++] = CurrentState;
  489. CurrentMatches[DestCount++] = CurrentState + 3;
  490. continue;
  491. } else {
  492. //
  493. // We are at a period. We can only match zero
  494. // characters (ie. the epsilon transition).
  495. //
  496. CurrentMatches[DestCount++] = CurrentState + 3;
  497. continue;
  498. }
  499. }
  500. //
  501. // The following expreesion characters all match by consuming
  502. // a character, thus force the expression, and thus state
  503. // forward.
  504. //
  505. CurrentState += (USHORT)(sizeof(TCHAR) * 2);
  506. //
  507. // DOS_QM is the most complicated. If the name is finished,
  508. // we can match zero characters. If this name is a '.', we
  509. // don't match, but look at the next expression. Otherwise
  510. // we match a single character.
  511. //
  512. if ( ExprChar == DOS_QM ) {
  513. if ( NameFinished || (NameChar == TEXT('.')) ) {
  514. continue;
  515. }
  516. CurrentMatches[DestCount++] = CurrentState;
  517. break;
  518. }
  519. //
  520. // A DOS_DOT can match either a period, or zero characters
  521. // beyond the end of name.
  522. //
  523. if (ExprChar == DOS_DOT) {
  524. if ( NameFinished ) {
  525. continue;
  526. }
  527. if (NameChar == TEXT('.')) {
  528. CurrentMatches[DestCount++] = CurrentState;
  529. break;
  530. }
  531. }
  532. //
  533. // From this point on a name character is required to even
  534. // continue, let alone make a match.
  535. //
  536. if ( NameFinished ) {
  537. break;
  538. }
  539. //
  540. // If this expression was a '?' we can match it once.
  541. //
  542. if (ExprChar == TEXT('?')) {
  543. CurrentMatches[DestCount++] = CurrentState;
  544. break;
  545. }
  546. //
  547. // Finally, check if the expression char matches the name char
  548. //
  549. if (ExprChar == (TCHAR)(NameChar)) {
  550. CurrentMatches[DestCount++] = CurrentState;
  551. break;
  552. }
  553. //
  554. // The expression didn't match so go look at the next
  555. // previous match.
  556. //
  557. break;
  558. }
  559. //
  560. // Prevent duplication in the destination array.
  561. //
  562. // Each of the arrays is montonically increasing and non-
  563. // duplicating, thus we skip over any source element in the src
  564. // array if we just added the same element to the destination
  565. // array. This guarentees non-duplication in the dest. array.
  566. //
  567. if ((SrcCount < MatchesCount) &&
  568. (PreviousDestCount < DestCount) ) {
  569. while (PreviousDestCount < DestCount) {
  570. while ( PreviousMatches[SrcCount] <
  571. CurrentMatches[PreviousDestCount] ) {
  572. SrcCount += 1;
  573. }
  574. PreviousDestCount += 1;
  575. }
  576. }
  577. }
  578. //
  579. // If we found no matches in the just finished itteration, it's time
  580. // to bail.
  581. //
  582. if ( DestCount == 0 ) {
  583. if (AuxBuffer != NULL) { free( AuxBuffer ); }
  584. return FALSE;
  585. }
  586. //
  587. // Swap the meaning the two arrays
  588. //
  589. {
  590. USHORT *Tmp;
  591. Tmp = PreviousMatches;
  592. PreviousMatches = CurrentMatches;
  593. CurrentMatches = Tmp;
  594. }
  595. MatchesCount = DestCount;
  596. }
  597. CurrentState = PreviousMatches[MatchesCount-1];
  598. if (AuxBuffer != NULL) { free( AuxBuffer ); }
  599. return (BOOLEAN)(CurrentState == MaxState);
  600. }