splitpath.c

Go to the documentation of this file.
00001 /*
00002  * Copyright 2000, 2004 Martin Fuchs
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00017  */
00018 
00019 #include "winefile.h"
00020 
00021 
00022 #ifdef __WINE__
00023 #ifdef UNICODE
00024 
00025 /* implementation of the _splitpath runtime library function with wide character strings */
00026 void _wsplitpath(const WCHAR* path, WCHAR* drv, WCHAR* dir, WCHAR* name, WCHAR* ext)
00027 {
00028     const WCHAR* end; /* end of processed string */
00029     const WCHAR* p;   /* search pointer */
00030     const WCHAR* s;   /* copy pointer */
00031 
00032     /* extract drive name */
00033     if (path[0] && path[1]==':') {
00034         if (drv) {
00035             *drv++ = *path++;
00036             *drv++ = *path++;
00037             *drv = '\0';
00038         }
00039     } else if (drv)
00040         *drv = '\0';
00041 
00042     /* search for end of string or stream separator */
00043     for(end=path; *end && *end!=':'; )
00044         end++;
00045 
00046     /* search for begin of file extension */
00047     for(p=end; p>path && *--p!='\\' && *p!='/'; )
00048         if (*p == '.') {
00049             end = p;
00050             break;
00051         }
00052 
00053     if (ext)
00054         for(s=end; (*ext=*s++); )
00055             ext++;
00056 
00057     /* search for end of directory name */
00058     for(p=end; p>path; )
00059         if (*--p=='\\' || *p=='/') {
00060             p++;
00061             break;
00062         }
00063 
00064     if (name) {
00065         for(s=p; s<end; )
00066             *name++ = *s++;
00067 
00068         *name = '\0';
00069     }
00070 
00071     if (dir) {
00072         for(s=path; s<p; )
00073             *dir++ = *s++;
00074 
00075         *dir = '\0';
00076     }
00077 }
00078 
00079 #else /* UNICODE */
00080 
00081 /* implementation of the _splitpath runtime library function with ANSI character strings */
00082 void _splitpath(const CHAR* path, CHAR* drv, CHAR* dir, CHAR* name, CHAR* ext)
00083 {
00084     const CHAR* end; /* end of processed string */
00085     const CHAR* p;   /* search pointer */
00086     const CHAR* s;   /* copy pointer */
00087 
00088     /* extract drive name */
00089     if (path[0] && path[1]==':') {
00090         if (drv) {
00091             *drv++ = *path++;
00092             *drv++ = *path++;
00093             *drv = '\0';
00094         }
00095     } else if (drv)
00096         *drv = '\0';
00097 
00098     /* search for end of string or stream separator */
00099     for(end=path; *end && *end!=':'; )
00100         end++;
00101 
00102     /* search for begin of file extension */
00103     for(p=end; p>path && *--p!='\\' && *p!='/'; )
00104         if (*p == '.') {
00105             end = p;
00106             break;
00107         }
00108 
00109     if (ext)
00110         for(s=end; (*ext=*s++); )
00111             ext++;
00112 
00113     /* search for end of directory name */
00114     for(p=end; p>path; )
00115         if (*--p=='\\' || *p=='/') {
00116             p++;
00117             break;
00118         }
00119 
00120     if (name) {
00121         for(s=p; s<end; )
00122             *name++ = *s++;
00123 
00124         *name = '\0';
00125     }
00126 
00127     if (dir) {
00128         for(s=path; s<p; )
00129             *dir++ = *s++;
00130 
00131         *dir = '\0';
00132     }
00133 }
00134 
00135 #endif /* UNICODE */
00136 #endif /* __WINE__ */
00137 
00138 
00139 /*
00140 void main() // test splipath()
00141 {
00142     TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
00143 
00144     _tsplitpath(L"x\\y", drv, dir, name, ext);
00145     _tsplitpath(L"x\\", drv, dir, name, ext);
00146     _tsplitpath(L"\\x", drv, dir, name, ext);
00147     _tsplitpath(L"x", drv, dir, name, ext);
00148     _tsplitpath(L"", drv, dir, name, ext);
00149     _tsplitpath(L".x", drv, dir, name, ext);
00150     _tsplitpath(L":x", drv, dir, name, ext);
00151     _tsplitpath(L"a:x", drv, dir, name, ext);
00152     _tsplitpath(L"a.b:x", drv, dir, name, ext);
00153     _tsplitpath(L"W:\\/\\abc/Z:~", drv, dir, name, ext);
00154     _tsplitpath(L"abc.EFGH:12345", drv, dir, name, ext);
00155     _tsplitpath(L"C:/dos/command.com", drv, dir, name, ext);
00156 }
00157 */

Winefile Source Code Documentation
generated on 15.09.2008 by doxygen

Winefile Homepage