d3dx9: Do not weld self.
[wine/multimedia.git] / programs / winefile / splitpath.c
blob20d7ded2d23691277fe546ba06f84c54e2752c74
1 /*
2 * Copyright 2000, 2004 Martin Fuchs
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "winefile.h"
22 void _wsplitpath(const WCHAR* path, WCHAR* drv, WCHAR* dir, WCHAR* name, WCHAR* ext)
24 const WCHAR* end; /* end of processed string */
25 const WCHAR* p; /* search pointer */
26 const WCHAR* s; /* copy pointer */
28 /* extract drive name */
29 if (path[0] && path[1]==':') {
30 if (drv) {
31 *drv++ = *path++;
32 *drv++ = *path++;
33 *drv = '\0';
35 } else if (drv)
36 *drv = '\0';
38 end = path + lstrlenW(path);
40 /* search for begin of file extension */
41 for(p=end; p>path && *--p!='\\' && *p!='/'; )
42 if (*p == '.') {
43 end = p;
44 break;
47 if (ext)
48 for(s=end; (*ext=*s++); )
49 ext++;
51 /* search for end of directory name */
52 for(p=end; p>path; )
53 if (*--p=='\\' || *p=='/') {
54 p++;
55 break;
58 if (name) {
59 for(s=p; s<end; )
60 *name++ = *s++;
62 *name = '\0';
65 if (dir) {
66 for(s=path; s<p; )
67 *dir++ = *s++;
69 *dir = '\0';
75 void main() // test splipath()
77 WCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
79 _wsplitpath(L"x\\y", drv, dir, name, ext);
80 _wsplitpath(L"x\\", drv, dir, name, ext);
81 _wsplitpath(L"\\x", drv, dir, name, ext);
82 _wsplitpath(L"x", drv, dir, name, ext);
83 _wsplitpath(L"", drv, dir, name, ext);
84 _wsplitpath(L".x", drv, dir, name, ext);
85 _wsplitpath(L":x", drv, dir, name, ext);
86 _wsplitpath(L"a:x", drv, dir, name, ext);
87 _wsplitpath(L"a.b:x", drv, dir, name, ext);
88 _wsplitpath(L"W:\\/\\abc/Z:~", drv, dir, name, ext);
89 _wsplitpath(L"abc.EFGH:12345", drv, dir, name, ext);
90 _wsplitpath(L"C:/dos/command.com", drv, dir, name, ext);