123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- #include "splitpath.h"
- #include <string.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #ifdef WANT_UNICODE
- void _wsplitpath(const WCHAR* path, WCHAR* drv, WCHAR* dir, WCHAR* name, WCHAR* ext)
- {
- const WCHAR* end;
- const WCHAR* p;
- const WCHAR* s;
-
- if (path[0] && path[1]==':') {
- if (drv) {
- *drv++ = *path++;
- *drv++ = *path++;
- *drv = L'\0';
- }
- } else if (drv)
- *drv = L'\0';
-
- for(end=path; *end && *end!=L':'; )
- end++;
-
- for(p=end; p>path && *--p!=L'\\' && *p!=L'/'; )
- if (*p == L'.') {
- end = p;
- break;
- }
- if (ext)
- for(s=end; *ext=*s++; )
- ext++;
-
- for(p=end; p>path; )
- if (*--p=='\\' || *p=='/') {
- p++;
- break;
- }
- if (name) {
- for(s=p; s<end; )
- *name++ = *s++;
- *name = L'\0';
- }
- if (dir) {
- for(s=path; s<p; )
- *dir++ = *s++;
- *dir = L'\0';
- }
- }
- #endif
- #ifdef WANT_ACP
- void _splitpath(const char* path, char* drv, char* dir, char* name, char* ext)
- {
- const char* end;
- const char* p;
- const char* s;
-
- if (path[0] && path[1]==':') {
- if (drv) {
- *drv++ = *path++;
- *drv++ = *path++;
- *drv = '\0';
- }
- } else if (drv)
- *drv = '\0';
-
- for(end=path; *end && *end!=':'; )
- end++;
-
- for(p=end; p>path && *--p!='\\' && *p!='/'; )
- if (*p == '.') {
- end = p;
- break;
- }
- if (ext)
- for(s=end; (*ext=*s++); )
- ext++;
-
- 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';
- }
- }
- #endif
- #ifdef WANT_UNICODE
- void _wmakepath( WCHAR *path, const WCHAR *drive, const WCHAR *dir, const WCHAR *fname, const WCHAR *ext ) {
- if (!path) return;
- *path = 0;
- if (drive) {
- *path++ = *drive;
- *path++ = ':';
- }
- if (dir) {
- strcat(path, dir);
- if (dir[strlen(dir)-1] != '\\' && dir[strlen(dir)-1] != '/')
- strcat(path, "/");
- path += strlen(path);
- }
- if (fname) strcat(path, fname);
- if (ext) {
- if (*ext != '.') strcat(path++, ".");
- strcat(path, ext);
- }
- }
- #endif
- #ifdef WANT_ACP
- void _makepath( char *path, const char *drive, const char *dir, const char *fname, const char *ext ) {
- if (!path) return;
- *path = 0;
- if (drive) {
- *path++ = *drive;
- *path++ = ':';
- }
- if (dir) {
- strcat(path, dir);
- if (dir[strlen(dir)-1] != '\\' && dir[strlen(dir)-1] != '/')
- strcat(path, "/");
- path += strlen(path);
- }
- if (fname) strcat(path, fname);
- if (ext) {
- if (*ext != '.') strcat(path++, ".");
- strcat(path, ext);
- }
- }
- #endif
- #ifdef __cplusplus
- }
- #endif
|