6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
38 void _wsplitpath(const WCHAR
* path
, WCHAR
* drv
, WCHAR
* dir
, WCHAR
* name
, WCHAR
* ext
)
40 const WCHAR
* end
; // end of processed string
41 const WCHAR
* p
; // search pointer
42 const WCHAR
* s
; // copy pointer
45 if (path
[0] && path
[1]==':') {
54 // search for end of string or stream separator
55 for(end
=path
; *end
&& *end
!=L
':'; )
58 // search for begin of file extension
59 for(p
=end
; p
>path
&& *--p
!=L
'\\' && *p
!=L
'/'; )
66 for(s
=end
; *ext
=*s
++; )
69 // search for end of directory name
71 if (*--p
=='\\' || *p
=='/') {
93 void _splitpath(const CHAR
* path
, CHAR
* drv
, CHAR
* dir
, CHAR
* name
, CHAR
* ext
)
95 const CHAR
* end
; // end of processed string
96 const CHAR
* p
; // search pointer
97 const CHAR
* s
; // copy pointer
100 if (path
[0] && path
[1]==':') {
109 // search for end of string or stream separator
110 for(end
=path
; *end
&& *end
!=':'; )
113 // search for begin of file extension
114 for(p
=end
; p
>path
&& *--p
!='\\' && *p
!='/'; )
121 for(s
=end
; (*ext
=*s
++); )
124 // search for end of directory name
126 if (*--p
=='\\' || *p
=='/') {
149 void main() // test splipath()
151 TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
153 _tsplitpath(L"x\\y", drv, dir, name, ext);
154 _tsplitpath(L"x\\", drv, dir, name, ext);
155 _tsplitpath(L"\\x", drv, dir, name, ext);
156 _tsplitpath(L"x", drv, dir, name, ext);
157 _tsplitpath(L"", drv, dir, name, ext);
158 _tsplitpath(L".x", drv, dir, name, ext);
159 _tsplitpath(L":x", drv, dir, name, ext);
160 _tsplitpath(L"a:x", drv, dir, name, ext);
161 _tsplitpath(L"a.b:x", drv, dir, name, ext);
162 _tsplitpath(L"W:\\/\\abc/Z:~", drv, dir, name, ext);
163 _tsplitpath(L"abc.EFGH:12345", drv, dir, name, ext);
164 _tsplitpath(L"C:/dos/command.com", drv, dir, name, ext);