# Include "stdio. H"
# Include "stdlib. H"
# Include "wchar. H"
Typedef wchar_t wchar;
Void _ wsplitpath (const wchar * path, wchar * DRV, wchar * Dir, wchar * Name, wchar * ext)
{
Const wchar * end;/* end of processed string */
Const wchar * P;/* search pointer */
Const wchar * s;/* Copy pointer */
/* Extract drive name */
If (path [0] & path [1] = ':'){
If (DRV ){
* DRV ++ = * path ++;
* DRV ++ = * path ++;
* DRV = '\ 0 ';
}
} Else if (DRV)
* DRV = '\ 0 ';
/* Search for end of string or stream separator */
For (END = path; * end & * end! = ':';)
End ++;
/* Search for begin of file extension */
For (P = end; P> Path & * -- p! = '\' & * P! = '/';)
If (* P = '.'){
End = P;
Break;
}
If (EXT)
For (S = end; (* ext = * s ++ );)
EXT ++;
/* Search for end of directory name */
For (P = end; P> path ;)
If (* -- p = '\' | * P = '/'){
P ++;
Break;
}
If (name ){
For (S = P; S <end ;)
* Name ++ = * s ++;
* Name = '\ 0 ';
}
If (DIR ){
For (S = path; S <p ;)
* Dir ++ = * s ++;
* Dir = '\ 0 ';
}
}
# DEFINE _ max_drive 255
# DEFINE _ max_dir 255
# DEFINE _ max_fname 255
# DEFINE _ max_ext255
Int main () // test splipath ()
{
Wchar_t DRV [_ max_drive + 1], dir [_ max_dir], name [_ max_fname], ext [_ max_ext];
_ Wsplitpath (L "/perforce/sandbox/flower.jpg", DRV, Dir, name, ext );
Wprintf (L "DRV = % s, Dir = % s, filename = % s, ext = % s \ n", DRV, Dir, name, ext );
_ Wsplitpath (L "C: \ Program Files \ sandbox \ flower.jpg", DRV, Dir, name, ext );
Wprintf (L "DRV = % s, Dir = % s, filename = % s, ext = % s \ n", DRV, Dir, name, ext );
_ Wsplitpath (L "\ x", DRV, Dir, name, ext );
_ Wsplitpath (L "X", DRV, Dir, name, ext );
_ Wsplitpath (L "", DRV, Dir, name, ext );
_ Wsplitpath (L ". X", DRV, Dir, name, ext );
_ Wsplitpath (L "", DRV, Dir, name, ext );
_ Wsplitpath (L "A: X", DRV, Dir, name, ext );
_ Wsplitpath (L "A. B: X", DRV, Dir, name, ext );
_ Wsplitpath (L "W: \\/ \\ ABC/Z :~ ", DRV, Dir, name, ext );
_ Wsplitpath (L "ABC. efgh: 12345", DRV, Dir, name, ext );
_ Wsplitpath (L "C:/DOS/command.com", DRV, Dir, name, ext );
Return 0;
}