[NTOSKRNL]
[reactos.git] / reactos / ntoskrnl / fsrtl / dbcsname.c
index 903da2e..202c2a3 100644 (file)
@@ -46,8 +46,8 @@ FsRtlDissectDbcs(IN ANSI_STRING Name,
                  OUT PANSI_STRING FirstPart,
                  OUT PANSI_STRING RemainingPart)
 {
-    ULONG FirstPosition, i;
-    ULONG SkipFirstSlash = 0;
+    USHORT FirstPosition, i;
+    USHORT SkipFirstSlash = 0;
     PAGED_CODE();
 
     /* Zero the strings before continuing */
@@ -116,7 +116,7 @@ BOOLEAN
 NTAPI
 FsRtlDoesDbcsContainWildCards(IN PANSI_STRING Name)
 {
-    ULONG i;
+    USHORT i;
     PAGED_CODE();
 
     /* Check every character */
@@ -160,55 +160,110 @@ NTAPI
 FsRtlIsDbcsInExpression(IN PANSI_STRING Expression,
                         IN PANSI_STRING Name)
 {
-    ULONG ExpressionPosition, NamePosition, MatchingChars = 0;
+    USHORT ExpressionPosition = 0, NamePosition = 0, MatchingChars, StarFound = MAXUSHORT;
     PAGED_CODE();
 
     ASSERT(Name->Length);
     ASSERT(Expression->Length);
     ASSERT(!FsRtlDoesDbcsContainWildCards(Name));
 
-    /* One can't be null, both can be */
-    if (!Expression->Length || !Name->Length)
+    while (NamePosition < Name->Length && ExpressionPosition < Expression->Length)
     {
-        return !(Expression->Length ^ Name->Length);
-    }
+        if ((Expression->Buffer[ExpressionPosition] == Name->Buffer[NamePosition]))
+        {
+            NamePosition++;
+            ExpressionPosition++;
+        }
+        else if (StarFound != MAXUSHORT && (Expression->Buffer[StarFound + 1] == '*' ||
+                 Expression->Buffer[StarFound + 1] == '?' || Expression->Buffer[StarFound + 1] == ANSI_DOS_DOT))
+        {
+            ExpressionPosition = StarFound + 1;
+            switch (Expression->Buffer[ExpressionPosition])
+            {
+                case '*':
+                    StarFound = MAXUSHORT;
+                    break;
 
-    for (ExpressionPosition = 0; ExpressionPosition < Expression->Length; ExpressionPosition++)
-    {
-        if ((Expression->Buffer[ExpressionPosition] == Name->Buffer[MatchingChars]) ||
-            (Expression->Buffer[ExpressionPosition] == '?') ||
-            (Expression->Buffer[ExpressionPosition] == ANSI_DOS_QM) ||
-            (Expression->Buffer[ExpressionPosition] == ANSI_DOS_DOT &&
-            (Name->Buffer[MatchingChars] == '.' || Name->Buffer[MatchingChars] == '0')))
+                case '?':
+                    ExpressionPosition++;
+                    MatchingChars = NamePosition;
+                    while (Name->Buffer[NamePosition] != Expression->Buffer[ExpressionPosition] &&
+                           NamePosition < Name->Length)
+                    {
+                        NamePosition++;
+                    }
+
+                    if (NamePosition - MatchingChars > 0)
+                    {
+                        StarFound = MAXUSHORT;
+                    }
+                    break;
+
+                case ANSI_DOS_DOT:
+                    while (Name->Buffer[NamePosition] != '.' && NamePosition < Name->Length)
+                    {
+                        NamePosition++;
+                    }
+                    ExpressionPosition++;
+                    StarFound = MAXUSHORT;
+                    break;
+
+                default:
+                    /* Should never happen */
+                    ASSERT(FALSE);                   
+            }
+        }
+        else if ((Expression->Buffer[ExpressionPosition] == '?') || (Expression->Buffer[ExpressionPosition] == ANSI_DOS_QM) ||
+                 (Expression->Buffer[ExpressionPosition] == ANSI_DOS_DOT && Name->Buffer[NamePosition] == '.'))
         {
-            MatchingChars++;
+            NamePosition++;
+            ExpressionPosition++;
+            StarFound = MAXUSHORT;
         }
         else if (Expression->Buffer[ExpressionPosition] == '*')
         {
-            MatchingChars = Name->Length;
+            StarFound = ExpressionPosition++;
+            if (ExpressionPosition == Expression->Length)
+            {
+                NamePosition = Name->Length;
+                break;
+            }
         }
         else if (Expression->Buffer[ExpressionPosition] == ANSI_DOS_STAR)
         {
-            for (NamePosition = MatchingChars; NamePosition < Name->Length; NamePosition++)
+            StarFound = MAXUSHORT;
+            MatchingChars = NamePosition;
+            while (MatchingChars < Name->Length)
             {
-                if (Name->Buffer[NamePosition] == '.')
+                if (Name->Buffer[MatchingChars] == '.')
                 {
-                    MatchingChars = NamePosition;
-                    break;
+                    NamePosition = MatchingChars;
                 }
+                MatchingChars++;
             }
+            ExpressionPosition++;
         }
-        else
+        else if (StarFound != MAXUSHORT)
         {
-            MatchingChars = 0;
+            ExpressionPosition = StarFound + 1;
+            while (Name->Buffer[NamePosition] != Expression->Buffer[ExpressionPosition] &&
+                   NamePosition < Name->Length)
+            {
+                NamePosition++;
+            }
         }
-        if (MatchingChars == Name->Length)
+        else
         {
-            return TRUE;
+            break;
         }
     }
+    if (ExpressionPosition + 1 == Expression->Length && NamePosition == Name->Length &&
+        Expression->Buffer[ExpressionPosition] == ANSI_DOS_DOT)
+    {
+        ExpressionPosition++;
+    }
 
-    return FALSE;
+    return (ExpressionPosition == Expression->Length && NamePosition == Name->Length);
 }
 
 /*++
@@ -246,7 +301,7 @@ FsRtlIsFatDbcsLegal(IN ANSI_STRING DbcsName,
 {
     ANSI_STRING FirstPart, RemainingPart, Name;
     BOOLEAN LastDot;
-    ULONG i;
+    USHORT i;
     PAGED_CODE();
 
     /* Just quit if the string is empty */
@@ -383,7 +438,7 @@ FsRtlIsHpfsDbcsLegal(IN ANSI_STRING DbcsName,
                      IN BOOLEAN LeadingBackslashPermissible)
 {
     ANSI_STRING FirstPart, RemainingPart, Name;
-    ULONG i;
+    USHORT i;
     PAGED_CODE();
 
     /* Just quit if the string is empty */
@@ -436,7 +491,7 @@ FsRtlIsHpfsDbcsLegal(IN ANSI_STRING DbcsName,
                 i++;
             }
             /* Then check for bad characters */
-            else if (!!FsRtlIsAnsiCharacterLegalHpfs(FirstPart.Buffer[i], WildCardsPermissible))
+            else if (!FsRtlIsAnsiCharacterLegalHpfs(FirstPart.Buffer[i], WildCardsPermissible))
             {
                 return FALSE;
             }