update for HEAD-2003021201
[reactos.git] / drivers / fs / vfat / string.c
1 /* $Id$
2  *
3  * COPYRIGHT:        See COPYING in the top level directory
4  * PROJECT:          ReactOS kernel
5  * FILE:             services/fs/vfat/string.c
6  * PURPOSE:          VFAT Filesystem
7  * PROGRAMMER:       Jason Filby (jasonfilby@yahoo.com)
8  *
9  */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <ddk/ntddk.h>
14 #include <wchar.h>
15
16 #define NDEBUG
17 #include <debug.h>
18
19 #include "vfat.h"
20
21 /* FUNCTIONS ****************************************************************/
22
23 BOOLEAN wstrcmpjoki(PWSTR s1, PWSTR s2)
24 /*
25  * FUNCTION: Compare two wide character strings, s2 with jokers (* or ?)
26  * return TRUE if s1 like s2
27  */
28 {
29    while ((*s2=='*')||(*s2=='?')||(towlower(*s1)==towlower(*s2)))
30    {
31       if ((*s1)==0 && (*s2)==0)
32         return(TRUE);
33       if(*s2=='*')
34       {
35         s2++;
36         while (*s1)
37         if (wstrcmpjoki(s1,s2)) return TRUE;
38          else s1++;
39       }
40       else
41       {
42         s1++;
43         s2++;
44       }
45    }
46    if ((*s2)=='.')
47    {
48         for (;((*s2)=='.')||((*s2)=='*')||((*s2)=='?');s2++) {}
49    }
50    if ((*s1)==0 && (*s2)==0)
51         return(TRUE);
52    return(FALSE);
53 }
54
55 PWCHAR  
56 vfatGetNextPathElement (PWCHAR  pFileName)
57 {
58   if (*pFileName == L'\0')
59   {
60     return  0;
61   }
62
63   while (*pFileName != L'\0' && *pFileName != L'\\')
64   {
65     pFileName++;
66   }
67
68   return  pFileName;
69 }
70
71 void
72 vfatWSubString (PWCHAR pTarget, const PWCHAR pSource, size_t pLength)
73 {
74   wcsncpy (pTarget, pSource, pLength);
75   pTarget [pLength] = L'\0';
76 }
77
78 BOOL  
79 vfatIsFileNameValid (PWCHAR pFileName)
80 {
81   PWCHAR  c;
82
83   c = pFileName;
84   while (*c != 0)
85   {
86     if (*c == L'*' || *c == L'?')
87     {
88       return FALSE;
89     }
90     c++;
91   }
92
93   return  TRUE;
94 }
95
96