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.

1045 lines
29 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. Name.c
  5. NOTE: The code is copied here from FsRtl because it called the pool allocator.
  6. The function prefixes were changed to avoid confusion.
  7. Abstract:
  8. The unicode name support package is for manipulating unicode strings
  9. The routines allow the caller to dissect and compare strings.
  10. The following routines are provided by this package:
  11. o FrsDissectName - This routine takes a path name string and breaks
  12. into two parts. The first name in the string and the remainder.
  13. It also checks that the first name is valid for an NT file.
  14. o FrsColateNames - This routine is used to colate directories
  15. according to lexical ordering. Lexical ordering is strict unicode
  16. numerical oerdering.
  17. o FrsDoesNameContainsWildCards - This routine tells the caller if
  18. a string contains any wildcard characters.
  19. o FrsIsNameInExpression - This routine is used to compare a string
  20. against a template (possibly containing wildcards) to sees if the
  21. string is in the language denoted by the template.
  22. Author:
  23. Gary Kimura [GaryKi] 5-Feb-1990
  24. Revision History:
  25. --*/
  26. #include <ntreppch.h>
  27. #pragma hdrstop
  28. #define DEBSUB "NAME:"
  29. #include <frs.h>
  30. //
  31. // Local support routine prototypes
  32. //
  33. BOOLEAN
  34. FrsIsNameInExpressionPrivate (
  35. IN PUNICODE_STRING Expression,
  36. IN PUNICODE_STRING Name,
  37. IN BOOLEAN IgnoreCase,
  38. IN PWCH UpcaseTable
  39. );
  40. VOID
  41. FrsDissectName (
  42. IN UNICODE_STRING Path,
  43. OUT PUNICODE_STRING FirstName,
  44. OUT PUNICODE_STRING RemainingName
  45. )
  46. /*++
  47. Routine Description:
  48. This routine cracks a path. It picks off the first element in the
  49. given path name and provides both it and the remaining part. A path
  50. is a set of file names separated by backslashes. If a name begins
  51. with a backslash, the FirstName is the string immediately following
  52. the backslash. Here are some examples:
  53. Path FirstName RemainingName
  54. ---- --------- -------------
  55. empty empty empty
  56. \ empty empty
  57. A A empty
  58. \A A empty
  59. A\B\C\D\E A B\C\D\E
  60. *A? *A? empty
  61. Note that both output strings use the same string buffer memory of the
  62. input string, and are not necessarily null terminated.
  63. Also, this routine makes no judgement as to the legality of each
  64. file name componant. This must be done separatly when each file name
  65. is extracted.
  66. Arguments:
  67. Path - The full path name to crack.
  68. FirstName - The first name in the path. Don't allocate a buffer for
  69. this string.
  70. RemainingName - The rest of the path. Don't allocate a buffer for this
  71. string.
  72. Return Value:
  73. None.
  74. --*/
  75. {
  76. ULONG i = 0;
  77. ULONG PathLength;
  78. ULONG FirstNameStart;
  79. //
  80. // Make both output strings empty for now
  81. //
  82. FRS_ASSERT( ValueIsMultOf2(Path.Length) );
  83. FirstName->Length = 0;
  84. FirstName->MaximumLength = 0;
  85. FirstName->Buffer = NULL;
  86. RemainingName->Length = 0;
  87. RemainingName->MaximumLength = 0;
  88. RemainingName->Buffer = NULL;
  89. PathLength = Path.Length / sizeof(WCHAR);
  90. //
  91. // Check for an empty input string
  92. //
  93. if (PathLength == 0) {
  94. return;
  95. }
  96. //
  97. // Skip over a starting backslash, and make sure there is more.
  98. //
  99. if ( Path.Buffer[0] == L'\\' ) {
  100. i = 1;
  101. }
  102. //
  103. // Now run down the input string until we hit a backslash or the end
  104. // of the string, remembering where we started;
  105. //
  106. for ( FirstNameStart = i;
  107. (i < PathLength) && (Path.Buffer[i] != L'\\');
  108. i += 1 ) {
  109. NOTHING;
  110. }
  111. //
  112. // At this point all characters up to (but not including) i are
  113. // in the first part. So setup the first name
  114. //
  115. FirstName->Length = (USHORT)((i - FirstNameStart) * sizeof(WCHAR));
  116. FirstName->MaximumLength = FirstName->Length;
  117. FirstName->Buffer = &Path.Buffer[FirstNameStart];
  118. //
  119. // Now the remaining part needs a string only if the first part didn't
  120. // exhaust the entire input string. We know that if anything is left
  121. // that is must start with a backslash. Note that if there is only
  122. // a trailing backslash, the length will get correctly set to zero.
  123. //
  124. if (i < PathLength) {
  125. RemainingName->Length = (USHORT)((PathLength - (i + 1)) * sizeof(WCHAR));
  126. RemainingName->MaximumLength = RemainingName->Length;
  127. RemainingName->Buffer = &Path.Buffer[i + 1];
  128. }
  129. //
  130. // And return to our caller
  131. //
  132. return;
  133. }
  134. BOOLEAN
  135. FrsDoesNameContainWildCards (
  136. IN PUNICODE_STRING Name
  137. )
  138. /*++
  139. Routine Description:
  140. This routine simply scans the input Name string looking for any Nt
  141. wild card characters.
  142. Arguments:
  143. Name - The string to check.
  144. Return Value:
  145. BOOLEAN - TRUE if one or more wild card characters was found.
  146. --*/
  147. {
  148. PUSHORT p;
  149. FRS_ASSERT( ValueIsMultOf2(Name->Length) );
  150. //
  151. // Check each character in the name to see if it's a wildcard
  152. // character.
  153. //
  154. if( Name->Length ) {
  155. for( p = Name->Buffer + (Name->Length / sizeof(WCHAR)) - 1;
  156. p >= Name->Buffer && *p != L'\\' ;
  157. p-- ) {
  158. //
  159. // check for a wild card character
  160. //
  161. if (FrsIsUnicodeCharacterWild( *p )) {
  162. //
  163. // Tell caller that this name contains wild cards
  164. //
  165. return TRUE;
  166. }
  167. }
  168. }
  169. //
  170. // No wildcard characters were found, so return to our caller
  171. //
  172. return FALSE;
  173. }
  174. BOOLEAN
  175. FrsAreNamesEqual (
  176. IN PUNICODE_STRING ConstantNameA,
  177. IN PUNICODE_STRING ConstantNameB,
  178. IN BOOLEAN IgnoreCase,
  179. IN PCWCH UpcaseTable OPTIONAL
  180. )
  181. /*++
  182. Routine Description:
  183. This routine simple returns whether the two names are exactly equal.
  184. If the two names are known to be constant, this routine is much
  185. faster than FrsIsNameInExpression.
  186. Arguments:
  187. ConstantNameA - Constant name.
  188. ConstantNameB - Constant name.
  189. IgnoreCase - TRUE if the Names should be Upcased before comparing.
  190. UpcaseTable - If supplied, use this table for case insensitive compares,
  191. otherwise, use the default system upcase table.
  192. Return Value:
  193. BOOLEAN - TRUE if the two names are lexically equal.
  194. --*/
  195. {
  196. ULONG Index;
  197. ULONG NameLength;
  198. BOOLEAN FreeStrings = FALSE;
  199. UNICODE_STRING LocalNameA;
  200. UNICODE_STRING LocalNameB;
  201. FRS_ASSERT( ValueIsMultOf2(ConstantNameA->Length) );
  202. FRS_ASSERT( ValueIsMultOf2(ConstantNameB->Length) );
  203. //
  204. // If the names aren't even the same size, then return FALSE right away.
  205. //
  206. if ( ConstantNameA->Length != ConstantNameB->Length ) {
  207. return FALSE;
  208. }
  209. NameLength = ConstantNameA->Length / sizeof(WCHAR);
  210. //
  211. // If we weren't given an upcase table, we have to upcase the names
  212. // ourselves.
  213. //
  214. if ( IgnoreCase && !ARGUMENT_PRESENT(UpcaseTable) ) {
  215. NTSTATUS Status;
  216. Status = RtlUpcaseUnicodeString( &LocalNameA, ConstantNameA, TRUE );
  217. if ( !NT_SUCCESS(Status) ) {
  218. XRAISEGENEXCEPTION(FrsErrorInternalError);
  219. }
  220. Status = RtlUpcaseUnicodeString( &LocalNameB, ConstantNameB, TRUE );
  221. if ( !NT_SUCCESS(Status) ) {
  222. RtlFreeUnicodeString( &LocalNameA );
  223. XRAISEGENEXCEPTION(FrsErrorInternalError);
  224. }
  225. ConstantNameA = &LocalNameA;
  226. ConstantNameB = &LocalNameB;
  227. IgnoreCase = FALSE;
  228. FreeStrings = TRUE;
  229. }
  230. //
  231. // Do either case sensitive or insensitive compare.
  232. //
  233. if ( !IgnoreCase ) {
  234. BOOLEAN BytesEqual;
  235. BytesEqual = (BOOLEAN) RtlEqualMemory( ConstantNameA->Buffer,
  236. ConstantNameB->Buffer,
  237. ConstantNameA->Length );
  238. if ( FreeStrings ) {
  239. RtlFreeUnicodeString( &LocalNameA );
  240. RtlFreeUnicodeString( &LocalNameB );
  241. }
  242. return BytesEqual;
  243. } else {
  244. for (Index = 0; Index < NameLength; Index += 1) {
  245. if ( UpcaseTable[ConstantNameA->Buffer[Index]] !=
  246. UpcaseTable[ConstantNameB->Buffer[Index]] ) {
  247. return FALSE;
  248. }
  249. }
  250. return TRUE;
  251. }
  252. }
  253. //
  254. // The following routine is just a wrapper around
  255. // FrsIsNameInExpressionPrivate to make a last minute fix a bit safer.
  256. //
  257. BOOLEAN
  258. FrsIsNameInExpression (
  259. IN PUNICODE_STRING Expression,
  260. IN PUNICODE_STRING Name,
  261. IN BOOLEAN IgnoreCase,
  262. IN PWCH UpcaseTable OPTIONAL
  263. )
  264. {
  265. BOOLEAN Result;
  266. UNICODE_STRING LocalName;
  267. FRS_ASSERT( ValueIsMultOf2(Expression->Length) );
  268. FRS_ASSERT( ValueIsMultOf2(Name->Length) );
  269. //
  270. // If we weren't given an upcase table, we have to upcase the names
  271. // ourselves.
  272. //
  273. if ( IgnoreCase && !ARGUMENT_PRESENT(UpcaseTable) ) {
  274. NTSTATUS Status;
  275. Status = RtlUpcaseUnicodeString( &LocalName, Name, TRUE );
  276. if ( !NT_SUCCESS(Status) ) {
  277. XRAISEGENEXCEPTION(FrsErrorInternalError);
  278. }
  279. Name = &LocalName;
  280. IgnoreCase = FALSE;
  281. } else {
  282. LocalName.Buffer = NULL;
  283. }
  284. //
  285. // Now call the main routine, remembering to free the upcased string
  286. // if we allocated one.
  287. //
  288. try {
  289. Result = FrsIsNameInExpressionPrivate( Expression,
  290. Name,
  291. IgnoreCase,
  292. UpcaseTable );
  293. } finally {
  294. if (LocalName.Buffer != NULL) {
  295. RtlFreeUnicodeString( &LocalName );
  296. }
  297. }
  298. return Result;
  299. }
  300. #define MATCHES_ARRAY_SIZE 16
  301. //
  302. // Local support routine prototypes
  303. //
  304. BOOLEAN
  305. FrsIsNameInExpressionPrivate (
  306. IN PUNICODE_STRING Expression,
  307. IN PUNICODE_STRING Name,
  308. IN BOOLEAN IgnoreCase,
  309. IN PWCH UpcaseTable
  310. )
  311. /*++
  312. Routine Description:
  313. This routine compares a Dbcs name and an expression and tells the caller
  314. if the name is in the language defined by the expression. The input name
  315. cannot contain wildcards, while the expression may contain wildcards.
  316. Expression wild cards are evaluated as shown in the nondeterministic
  317. finite automatons below. Note that ~* and ~? are DOS_STAR and DOS_QM.
  318. ~* is DOS_STAR, ~? is DOS_QM, and ~. is DOS_DOT
  319. S
  320. <-----<
  321. X | | e Y
  322. X * Y == (0)----->-(1)->-----(2)-----(3)
  323. S-.
  324. <-----<
  325. X | | e Y
  326. X ~* Y == (0)----->-(1)->-----(2)-----(3)
  327. X S S Y
  328. X ?? Y == (0)---(1)---(2)---(3)---(4)
  329. X . . Y
  330. X ~.~. Y == (0)---(1)----(2)------(3)---(4)
  331. | |________|
  332. | ^ |
  333. |_______________|
  334. ^EOF or .^
  335. X S-. S-. Y
  336. X ~?~? Y == (0)---(1)-----(2)-----(3)---(4)
  337. | |________|
  338. | ^ |
  339. |_______________|
  340. ^EOF or .^
  341. where S is any single character
  342. S-. is any single character except the final .
  343. e is a null character transition
  344. EOF is the end of the name string
  345. In words:
  346. * matches 0 or more characters.
  347. ? matches exactly 1 character.
  348. DOS_STAR matches 0 or more characters until encountering and matching
  349. the final . in the name.
  350. DOS_QM matches any single character, or upon encountering a period or
  351. end of name string, advances the expression to the end of the
  352. set of contiguous DOS_QMs.
  353. DOS_DOT matches either a . or zero characters beyond name string.
  354. Arguments:
  355. Expression - Supplies the input expression to check against
  356. (Caller must already upcase if passing CaseInsensitive TRUE.)
  357. Name - Supplies the input name to check for.
  358. IgnoreCase - TRUE if Name should be Upcased before comparing.
  359. UpcaseTable - UpCase table to use if Ingoring Case.
  360. Return Value:
  361. BOOLEAN - TRUE if Name is an element in the set of strings denoted
  362. by the input Expression and FALSE otherwise.
  363. --*/
  364. {
  365. USHORT NameOffset;
  366. USHORT ExprOffset;
  367. ULONG SrcCount;
  368. ULONG DestCount;
  369. ULONG PreviousDestCount;
  370. ULONG MatchesCount;
  371. WCHAR NameChar, ExprChar;
  372. USHORT LocalBuffer[MATCHES_ARRAY_SIZE * 2];
  373. USHORT *AuxBuffer = NULL;
  374. USHORT *PreviousMatches;
  375. USHORT *CurrentMatches;
  376. USHORT MaxState;
  377. USHORT CurrentState;
  378. BOOLEAN NameFinished = FALSE;
  379. //
  380. // The idea behind the algorithm is pretty simple. We keep track of
  381. // all possible locations in the regular expression that are matching
  382. // the name. If when the name has been exhausted one of the locations
  383. // in the expression is also just exhausted, the name is in the language
  384. // defined by the regular expression.
  385. //
  386. FRS_ASSERT( Name->Length != 0 );
  387. FRS_ASSERT( ValueIsMultOf2(Name->Length) );
  388. FRS_ASSERT( Expression->Length != 0 );
  389. FRS_ASSERT( ValueIsMultOf2(Expression->Length) );
  390. //
  391. // If one string is empty return FALSE. If both are empty return TRUE.
  392. //
  393. if ( (Name->Length == 0) || (Expression->Length == 0) ) {
  394. return (BOOLEAN)(!(Name->Length + Expression->Length));
  395. }
  396. //
  397. // Special case by far the most common wild card search of *
  398. //
  399. if ((Expression->Length == 2) && (Expression->Buffer[0] == L'*')) {
  400. return TRUE;
  401. }
  402. FRS_ASSERT( FrsDoesNameContainWildCards( Expression ) );
  403. FRS_ASSERT( !IgnoreCase || ARGUMENT_PRESENT(UpcaseTable) );
  404. //
  405. // Also special case expressions of the form *X. With this and the prior
  406. // case we have covered virtually all normal queries.
  407. //
  408. if (Expression->Buffer[0] == L'*') {
  409. UNICODE_STRING LocalExpression;
  410. LocalExpression = *Expression;
  411. LocalExpression.Buffer += 1;
  412. LocalExpression.Length -= 2;
  413. //
  414. // Only special case an expression with a single *
  415. //
  416. if ( !FrsDoesNameContainWildCards( &LocalExpression ) ) {
  417. ULONG StartingNameOffset;
  418. if (Name->Length < (USHORT)(Expression->Length - sizeof(WCHAR))) {
  419. return FALSE;
  420. }
  421. StartingNameOffset = ( Name->Length -
  422. LocalExpression.Length ) / sizeof(WCHAR);
  423. //
  424. // Do a simple memory compare if case sensitive, otherwise
  425. // we have got to check this one character at a time.
  426. //
  427. if ( !IgnoreCase ) {
  428. return (BOOLEAN) RtlEqualMemory( LocalExpression.Buffer,
  429. Name->Buffer + StartingNameOffset,
  430. LocalExpression.Length );
  431. } else {
  432. for ( ExprOffset = 0;
  433. ExprOffset < (USHORT)(LocalExpression.Length / sizeof(WCHAR));
  434. ExprOffset += 1 ) {
  435. NameChar = Name->Buffer[StartingNameOffset + ExprOffset];
  436. NameChar = UpcaseTable[NameChar];
  437. ExprChar = LocalExpression.Buffer[ExprOffset];
  438. FRS_ASSERT( ExprChar == UpcaseTable[ExprChar] );
  439. if ( NameChar != ExprChar ) {
  440. return FALSE;
  441. }
  442. }
  443. return TRUE;
  444. }
  445. }
  446. }
  447. //
  448. // Walk through the name string, picking off characters. We go one
  449. // character beyond the end because some wild cards are able to match
  450. // zero characters beyond the end of the string.
  451. //
  452. // With each new name character we determine a new set of states that
  453. // match the name so far. We use two arrays that we swap back and forth
  454. // for this purpose. One array lists the possible expression states for
  455. // all name characters up to but not including the current one, and other
  456. // array is used to build up the list of states considering the current
  457. // name character as well. The arrays are then switched and the process
  458. // repeated.
  459. //
  460. // There is not a one-to-one correspondence between state number and
  461. // offset into the expression. This is evident from the NFAs in the
  462. // initial comment to this function. State numbering is not continuous.
  463. // This allows a simple conversion between state number and expression
  464. // offset. Each character in the expression can represent one or two
  465. // states. * and DOS_STAR generate two states: ExprOffset*2 and
  466. // ExprOffset*2 + 1. All other expreesion characters can produce only
  467. // a single state. Thus ExprOffset = State/2.
  468. //
  469. //
  470. // Here is a short description of the variables involved:
  471. //
  472. // NameOffset - The offset of the current name char being processed.
  473. //
  474. // ExprOffset - The offset of the current expression char being processed.
  475. //
  476. // SrcCount - Prior match being investigated with current name char
  477. //
  478. // DestCount - Next location to put a matching assuming current name char
  479. //
  480. // NameFinished - Allows one more itteration through the Matches array
  481. // after the name is exhusted (to come *s for example)
  482. //
  483. // PreviousDestCount - This is used to prevent entry duplication, see coment
  484. //
  485. // PreviousMatches - Holds the previous set of matches (the Src array)
  486. //
  487. // CurrentMatches - Holds the current set of matches (the Dest array)
  488. //
  489. // AuxBuffer, LocalBuffer - the storage for the Matches arrays
  490. //
  491. //
  492. // Set up the initial variables
  493. //
  494. PreviousMatches = &LocalBuffer[0];
  495. CurrentMatches = &LocalBuffer[MATCHES_ARRAY_SIZE];
  496. PreviousMatches[0] = 0;
  497. MatchesCount = 1;
  498. NameOffset = 0;
  499. MaxState = (USHORT)(Expression->Length * 2);
  500. while ( !NameFinished ) {
  501. if ( NameOffset < Name->Length ) {
  502. NameChar = Name->Buffer[NameOffset / sizeof(WCHAR)];
  503. NameOffset += sizeof(WCHAR);;
  504. } else {
  505. NameFinished = TRUE;
  506. //
  507. // if we have already exhasted the expression, cool. Don't
  508. // continue.
  509. //
  510. if ( PreviousMatches[MatchesCount-1] == MaxState ) {
  511. break;
  512. }
  513. }
  514. //
  515. // Now, for each of the previous stored expression matches, see what
  516. // we can do with this name character.
  517. //
  518. SrcCount = 0;
  519. DestCount = 0;
  520. PreviousDestCount = 0;
  521. while ( SrcCount < MatchesCount ) {
  522. USHORT Length;
  523. //
  524. // We have to carry on our expression analysis as far as possible
  525. // for each character of name, so we loop here until the
  526. // expression stops matching. A clue here is that expression
  527. // cases that can match zero or more characters end with a
  528. // continue, while those that can accept only a single character
  529. // end with a break.
  530. //
  531. ExprOffset = (USHORT)((PreviousMatches[SrcCount++] + 1) / 2);
  532. Length = 0;
  533. while ( TRUE ) {
  534. if ( ExprOffset == Expression->Length ) {
  535. break;
  536. }
  537. //
  538. // The first time through the loop we don't want
  539. // to increment ExprOffset.
  540. //
  541. ExprOffset += Length;
  542. Length = sizeof(WCHAR);
  543. CurrentState = (USHORT)(ExprOffset * 2);
  544. if ( ExprOffset == Expression->Length ) {
  545. CurrentMatches[DestCount++] = MaxState;
  546. break;
  547. }
  548. ExprChar = Expression->Buffer[ExprOffset / sizeof(WCHAR)];
  549. FRS_ASSERT( !IgnoreCase || !((ExprChar >= L'a') && (ExprChar <= L'z')) );
  550. //
  551. // Before we get started, we have to check for something
  552. // really gross. We may be about to exhaust the local
  553. // space for ExpressionMatches[][], so we have to allocate
  554. // some memory if this is the case. Yuk!
  555. //
  556. if ( (DestCount >= MATCHES_ARRAY_SIZE - 2) &&
  557. (AuxBuffer == NULL) ) {
  558. ULONG ExpressionChars;
  559. ExpressionChars = Expression->Length / sizeof(WCHAR);
  560. AuxBuffer = FrsAlloc((ExpressionChars+1)*sizeof(USHORT)*2*2);
  561. //
  562. // I don't believe we can have a buffer overrun here. Put an assert
  563. // to catch any such case.
  564. //
  565. FRS_ASSERT((ExpressionChars+1)*sizeof(USHORT)*2*2 >= (MATCHES_ARRAY_SIZE * sizeof(USHORT) + (ExpressionChars+1)*2*sizeof(USHORT)));
  566. CopyMemory(AuxBuffer, CurrentMatches, MATCHES_ARRAY_SIZE * sizeof(USHORT) );
  567. CurrentMatches = AuxBuffer;
  568. CopyMemory(AuxBuffer + (ExpressionChars+1)*2, PreviousMatches,
  569. MATCHES_ARRAY_SIZE * sizeof(USHORT) );
  570. PreviousMatches = AuxBuffer + (ExpressionChars+1)*2;
  571. }
  572. //
  573. // * matches any character zero or more times.
  574. //
  575. if (ExprChar == L'*') {
  576. CurrentMatches[DestCount++] = CurrentState;
  577. CurrentMatches[DestCount++] = CurrentState + 3;
  578. continue;
  579. }
  580. //
  581. // DOS_STAR matches any character except . zero or more times.
  582. //
  583. if (ExprChar == DOS_STAR) {
  584. BOOLEAN ICanEatADot = FALSE;
  585. //
  586. // If we are at a period, determine if we are allowed to
  587. // consume it, ie. make sure it is not the last one.
  588. //
  589. if ( !NameFinished && (NameChar == '.') ) {
  590. USHORT Offset;
  591. for ( Offset = NameOffset;
  592. Offset < Name->Length;
  593. Offset += Length ) {
  594. if (Name->Buffer[Offset / sizeof(WCHAR)] == L'.') {
  595. ICanEatADot = TRUE;
  596. break;
  597. }
  598. }
  599. }
  600. if (NameFinished || (NameChar != L'.') || ICanEatADot) {
  601. CurrentMatches[DestCount++] = CurrentState;
  602. CurrentMatches[DestCount++] = CurrentState + 3;
  603. continue;
  604. } else {
  605. //
  606. // We are at a period. We can only match zero
  607. // characters (ie. the epsilon transition).
  608. //
  609. CurrentMatches[DestCount++] = CurrentState + 3;
  610. continue;
  611. }
  612. }
  613. //
  614. // The following expreesion characters all match by consuming
  615. // a character, thus force the expression, and thus state
  616. // forward.
  617. //
  618. CurrentState += (USHORT)(sizeof(WCHAR) * 2);
  619. //
  620. // DOS_QM is the most complicated. If the name is finished,
  621. // we can match zero characters. If this name is a '.', we
  622. // don't match, but look at the next expression. Otherwise
  623. // we match a single character.
  624. //
  625. if ( ExprChar == DOS_QM ) {
  626. if ( NameFinished || (NameChar == L'.') ) {
  627. continue;
  628. }
  629. CurrentMatches[DestCount++] = CurrentState;
  630. break;
  631. }
  632. //
  633. // A DOS_DOT can match either a period, or zero characters
  634. // beyond the end of name.
  635. //
  636. if (ExprChar == DOS_DOT) {
  637. if ( NameFinished ) {
  638. continue;
  639. }
  640. if (NameChar == L'.') {
  641. CurrentMatches[DestCount++] = CurrentState;
  642. break;
  643. }
  644. }
  645. //
  646. // From this point on a name character is required to even
  647. // continue, let alone make a match.
  648. //
  649. if ( NameFinished ) {
  650. break;
  651. }
  652. //
  653. // If this expression was a '?' we can match it once.
  654. //
  655. if (ExprChar == L'?') {
  656. CurrentMatches[DestCount++] = CurrentState;
  657. break;
  658. }
  659. //
  660. // Finally, check if the expression char matches the name char
  661. //
  662. if (ExprChar == (WCHAR)(IgnoreCase ?
  663. UpcaseTable[NameChar] : NameChar)) {
  664. CurrentMatches[DestCount++] = CurrentState;
  665. break;
  666. }
  667. //
  668. // The expression didn't match so go look at the next
  669. // previous match.
  670. //
  671. break;
  672. }
  673. //
  674. // Prevent duplication in the destination array.
  675. //
  676. // Each of the arrays is montonically increasing and non-
  677. // duplicating, thus we skip over any source element in the src
  678. // array if we just added the same element to the destination
  679. // array. This guarentees non-duplication in the dest. array.
  680. //
  681. if ((SrcCount < MatchesCount) &&
  682. (PreviousDestCount < DestCount) ) {
  683. while (PreviousDestCount < DestCount) {
  684. while ( PreviousMatches[SrcCount] <
  685. CurrentMatches[PreviousDestCount] ) {
  686. SrcCount += 1;
  687. }
  688. PreviousDestCount += 1;
  689. }
  690. }
  691. }
  692. //
  693. // If we found no matches in the just finished itteration, it's time
  694. // to bail.
  695. //
  696. if ( DestCount == 0 ) {
  697. if (AuxBuffer != NULL) { FrsFree( AuxBuffer ); }
  698. return FALSE;
  699. }
  700. //
  701. // Swap the meaning the two arrays
  702. //
  703. {
  704. USHORT *Tmp;
  705. Tmp = PreviousMatches;
  706. PreviousMatches = CurrentMatches;
  707. CurrentMatches = Tmp;
  708. }
  709. MatchesCount = DestCount;
  710. }
  711. CurrentState = PreviousMatches[MatchesCount-1];
  712. if (AuxBuffer != NULL) { FrsFree( AuxBuffer ); }
  713. return (BOOLEAN)(CurrentState == MaxState);
  714. }
  715.