X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1311c7a9bbaefda6b68eee5c32c3309f163a8861..b6a158b04e7784dc30ad8fc043eb94ae71c19e4f:/src/common/filefn.cpp?ds=sidebyside diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index b47d856e66..66f56e999e 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -26,6 +26,7 @@ #endif #include "wx/utils.h" +#include #include #include @@ -267,10 +268,25 @@ void wxStripExtension(char *buffer) } } +void wxStripExtension(wxString& buffer) +{ + size_t len = buffer.Length(); + size_t i = len-1; + while (i > 0) + { + if (buffer.GetChar(i) == '.') + { + buffer = buffer.Left(i); + break; + } + i --; + } +} + // Destructive removal of /./ and /../ stuff char *wxRealPath (char *path) { -#ifdef __WINDOWS__ +#ifdef __WXMSW__ static const char SEP = '\\'; Unix2DosFilename(path); #else @@ -300,7 +316,7 @@ char *wxRealPath (char *path) path[0] = SEP; path[1] = '\0'; } -#ifdef __WINDOWS__ +#ifdef __WXMSW__ /* Check that path[2] is NULL! */ else if (path[1] == ':' && !path[2]) { @@ -330,7 +346,7 @@ char *wxCopyAbsolutePath(const wxString& filename) buf[0] = '\0'; wxGetWorkingDirectory(buf, sizeof(buf)/sizeof(char)); char ch = buf[strlen(buf) - 1]; -#ifdef __WINDOWS__ +#ifdef __WXMSW__ if (ch != '\\' && ch != '/') strcat(buf, "\\"); #else @@ -381,7 +397,7 @@ char *wxExpandPath(char *buf, const char *name) trimchars[2] = '\t'; trimchars[3] = 0; -#ifdef __WINDOWS__ +#ifdef __WXMSW__ const char SEP = '\\'; #else const char SEP = '/'; @@ -402,7 +418,7 @@ char *wxExpandPath(char *buf, const char *name) s = nm; d = lnm; -#ifdef __WINDOWS__ +#ifdef __WXMSW__ q = FALSE; #else q = nm[0] == '\\' && nm[1] == '~'; @@ -410,7 +426,7 @@ char *wxExpandPath(char *buf, const char *name) /* Expand inline environment variables */ while ((*d++ = *s)) { -#ifndef __WINDOWS__ +#ifndef __WXMSW__ if (*s == '\\') { if ((*(d - 1) = *++s)) { s++; @@ -419,7 +435,7 @@ char *wxExpandPath(char *buf, const char *name) break; } else #endif -#ifdef __WINDOWS__ +#ifdef __WXMSW__ if (*s++ == '$' && (*s == '{' || *s == ')')) #else if (*s++ == '$') @@ -510,7 +526,7 @@ wxContractPath (const wxString& filename, const wxString& envname, const wxStrin return NULL; strcpy (dest, WXSTRINGCAST filename); -#ifdef __WINDOWS__ +#ifdef __WXMSW__ Unix2DosFilename(dest); #endif @@ -537,7 +553,7 @@ wxContractPath (const wxString& filename, const wxString& envname, const wxStrin strcpy(wxBuffer, "~"); if (user && *user) strcat(wxBuffer, user); -#ifdef __WINDOWS__ +#ifdef __WXMSW__ // strcat(wxBuffer, "\\"); #else // strcat(wxBuffer, "/"); @@ -568,7 +584,7 @@ char *wxFileNameFromPath (char *path) #endif return tcp + 1; } /* while */ -#ifdef __WINDOWS__ +#ifdef __WXMSW__ if (isalpha (*path) && *(path + 1) == ':') return path + 2; #endif @@ -595,7 +611,7 @@ wxString wxFileNameFromPath (const wxString& path1) #endif return wxString(tcp + 1); } /* while */ -#ifdef __WINDOWS__ +#ifdef __WXMSW__ if (isalpha (*path) && *(path + 1) == ':') return wxString(path + 2); #endif @@ -637,7 +653,7 @@ wxPathOnly (char *path) else i --; } -#ifdef __WINDOWS__ +#ifdef __WXMSW__ // Try Drive specifier if (isalpha (buf[0]) && buf[1] == ':') { @@ -685,7 +701,7 @@ wxString wxPathOnly (const wxString& path) else i --; } -#ifdef __WINDOWS__ +#ifdef __WXMSW__ // Try Drive specifier if (isalpha (buf[0]) && buf[1] == ':') { @@ -712,7 +728,7 @@ wxDos2UnixFilename (char *s) { if (*s == '\\') *s = '/'; -#ifdef __WINDOWS__ +#ifdef __WXMSW__ else *s = wxToLower (*s); // Case INDEPENDENT #endif @@ -721,10 +737,14 @@ wxDos2UnixFilename (char *s) } void +#ifdef __WXMSW__ wxUnix2DosFilename (char *s) +#else +wxUnix2DosFilename (char *WXUNUSED(s)) +#endif { // Yes, I really mean this to happen under DOS only! JACS -#ifdef __WINDOWS__ +#ifdef __WXMSW__ if (s) while (*s) { @@ -824,9 +844,11 @@ bool wxRemoveFile(const wxString& file) bool wxMkdir(const wxString& dir) { -#ifdef __VMS__ +#if defined(__WXSTUBS__) + return FALSE; +#elif defined(__VMS__) return FALSE; -#elif (defined(__GNUWIN32__) && !defined(__MINGW32__)) || !defined(__WINDOWS__) +#elif (defined(__GNUWIN32__) && !defined(__MINGW32__)) || !defined(__WXMSW__) return (mkdir (WXSTRINGCAST dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0); #else return (mkdir(WXSTRINGCAST dir) == 0); @@ -847,7 +869,7 @@ bool wxDirExists(const wxString& dir) { #ifdef __VMS__ return FALSE; -#elif !defined(__WINDOWS__) +#elif !defined(__WXMSW__) struct stat sbuf; return (stat(dir, &sbuf) != -1) && S_ISDIR(sbuf.st_mode) ? TRUE : FALSE; #else @@ -941,7 +963,7 @@ char *wxGetTempFileName(const wxString& prefix, char *buf) return buf; } } - cerr << "wxWindows: error finding temporary file name.\n"; + cerr << _("wxWindows: error finding temporary file name.\n"); if (buf) buf[0] = 0; return NULL; #endif @@ -1051,7 +1073,7 @@ char *wxFindNextFile(void) return NULL; } -#elif defined(__WINDOWS__) +#elif defined(__WXMSW__) #ifdef __WIN32__ HANDLE wxFileStrucHandle = INVALID_HANDLE_VALUE; @@ -1216,7 +1238,7 @@ char *wxFindNextFile(void) } #endif - // __WINDOWS__ + // __WXMSW__ // Get current working directory. // If buf is NULL, allocates space using new, else @@ -1285,7 +1307,7 @@ bool wxFindFileInPath(wxString *pStr, const char *pszPath, const char *pszFile) { // we assume that it's not empty wxCHECK_MSG( !IsEmpty(pszFile), FALSE, - "empty file name in wxFindFileInPath"); + _("empty file name in wxFindFileInPath")); // skip path separator in the beginning of the file name if present if ( wxIsPathSeparator(*pszFile) ) @@ -1315,3 +1337,37 @@ bool wxFindFileInPath(wxString *pStr, const char *pszPath, const char *pszFile) return pc != NULL; // if true => we breaked from the loop } +void WXDLLEXPORT wxSplitPath(const char *pszFileName, + wxString *pstrPath, + wxString *pstrName, + wxString *pstrExt) +{ + wxCHECK_RET( pszFileName, _("NULL file name in wxSplitPath") ); + + const char *pDot = strrchr(pszFileName, FILE_SEP_EXT); + const char *pSepUnix = strrchr(pszFileName, FILE_SEP_PATH_UNIX); + const char *pSepDos = strrchr(pszFileName, FILE_SEP_PATH_DOS); + + // take the last of the two + size_t nPosUnix = pSepUnix ? pSepUnix - pszFileName : 0; + size_t nPosDos = pSepDos ? pSepDos - pszFileName : 0; + if ( nPosDos > nPosUnix ) + nPosUnix = nPosDos; +// size_t nLen = Strlen(pszFileName); + + if ( pstrPath ) + *pstrPath = wxString(pszFileName, nPosUnix); + if ( pDot ) { + size_t nPosDot = pDot - pszFileName; + if ( pstrName ) + *pstrName = wxString(pszFileName + nPosUnix + 1, nPosDot - nPosUnix); + if ( pstrExt ) + *pstrExt = wxString(pszFileName + nPosDot + 1); + } + else { + if ( pstrName ) + *pstrName = wxString(pszFileName + nPosUnix + 1); + if ( pstrExt ) + pstrExt->Empty(); + } +}