wxFindFirst/NextFile() now return wxString and not "char *", wxGetCwd() added
(to be used instead of wxGetWorkingDirectory) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1656 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -107,6 +107,12 @@ TRUE if successful.
|
|||||||
|
|
||||||
Copies {\it file1} to {\it file2}, returning TRUE if successful.
|
Copies {\it file1} to {\it file2}, returning TRUE if successful.
|
||||||
|
|
||||||
|
\membersection{::wxGetCwd}\label{wxgetcwd}
|
||||||
|
|
||||||
|
\func{wxString}{wxGetCwd}{\void}
|
||||||
|
|
||||||
|
Returns a string containing the current (or working) directory.
|
||||||
|
|
||||||
\membersection{::wxGetHostName}\label{wxgethostname}
|
\membersection{::wxGetHostName}\label{wxgethostname}
|
||||||
|
|
||||||
\func{bool}{wxGetHostName}{\param{const wxString\& }{buf}, \param{int }{sz}}
|
\func{bool}{wxGetHostName}{\param{const wxString\& }{buf}, \param{int }{sz}}
|
||||||
@@ -158,6 +164,8 @@ Returns TRUE if successful, FALSE otherwise.
|
|||||||
|
|
||||||
\func{wxString}{wxGetWorkingDirectory}{\param{const wxString\& }{buf=NULL}, \param{int }{sz=1000}}
|
\func{wxString}{wxGetWorkingDirectory}{\param{const wxString\& }{buf=NULL}, \param{int }{sz=1000}}
|
||||||
|
|
||||||
|
This function is obsolete: use \helpref{wxGetCwd}{wxgetcwd} instead.
|
||||||
|
|
||||||
Copies the current working directory into the buffer if supplied, or
|
Copies the current working directory into the buffer if supplied, or
|
||||||
copies the working directory into new storage (which you must delete yourself)
|
copies the working directory into new storage (which you must delete yourself)
|
||||||
if the buffer is NULL.
|
if the buffer is NULL.
|
||||||
|
@@ -13,7 +13,7 @@
|
|||||||
#define _FILEFN_H_
|
#define _FILEFN_H_
|
||||||
|
|
||||||
#ifdef __GNUG__
|
#ifdef __GNUG__
|
||||||
#pragma interface "filefn.h"
|
#pragma interface "filefn.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <wx/list.h>
|
#include <wx/list.h>
|
||||||
@@ -24,9 +24,9 @@
|
|||||||
|
|
||||||
// define off_t
|
// define off_t
|
||||||
#ifndef __WXMAC__
|
#ifndef __WXMAC__
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#else
|
#else
|
||||||
typedef long off_t;
|
typedef long off_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__VISUALC__) || defined(__MWERKS__)
|
#if defined(__VISUALC__) || defined(__MWERKS__)
|
||||||
@@ -39,11 +39,12 @@ typedef long off_t;
|
|||||||
|
|
||||||
const off_t wxInvalidOffset = (off_t)-1;
|
const off_t wxInvalidOffset = (off_t)-1;
|
||||||
|
|
||||||
typedef enum {
|
enum wxSeekMode
|
||||||
|
{
|
||||||
wxFromStart,
|
wxFromStart,
|
||||||
wxFromCurrent,
|
wxFromCurrent,
|
||||||
wxFromEnd
|
wxFromEnd
|
||||||
} wxSeekMode;
|
};
|
||||||
|
|
||||||
WXDLLEXPORT_DATA(extern const char*) wxEmptyString;
|
WXDLLEXPORT_DATA(extern const char*) wxEmptyString;
|
||||||
|
|
||||||
@@ -68,7 +69,6 @@ WXDLLEXPORT wxString wxFileNameFromPath(const wxString& path);
|
|||||||
#define FileNameFromPath wxFileNameFromPath
|
#define FileNameFromPath wxFileNameFromPath
|
||||||
|
|
||||||
// Get directory
|
// Get directory
|
||||||
WXDLLEXPORT char* wxPathOnly(char *path);
|
|
||||||
WXDLLEXPORT wxString wxPathOnly(const wxString& path);
|
WXDLLEXPORT wxString wxPathOnly(const wxString& path);
|
||||||
#define PathOnly wxPathOnly
|
#define PathOnly wxPathOnly
|
||||||
|
|
||||||
@@ -86,6 +86,7 @@ WXDLLEXPORT void wxUnix2DosFilename(char *s);
|
|||||||
WXDLLEXPORT void wxMac2UnixFilename(char *s);
|
WXDLLEXPORT void wxMac2UnixFilename(char *s);
|
||||||
WXDLLEXPORT void wxUnix2MacFilename(char *s);
|
WXDLLEXPORT void wxUnix2MacFilename(char *s);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Strip the extension, in situ
|
// Strip the extension, in situ
|
||||||
WXDLLEXPORT void wxStripExtension(char *buffer);
|
WXDLLEXPORT void wxStripExtension(char *buffer);
|
||||||
WXDLLEXPORT void wxStripExtension(wxString& buffer);
|
WXDLLEXPORT void wxStripExtension(wxString& buffer);
|
||||||
@@ -113,8 +114,8 @@ WXDLLEXPORT char* wxCopyAbsolutePath(const wxString& path);
|
|||||||
// Flags are reserved for future use.
|
// Flags are reserved for future use.
|
||||||
#define wxFILE 1
|
#define wxFILE 1
|
||||||
#define wxDIR 2
|
#define wxDIR 2
|
||||||
WXDLLEXPORT char* wxFindFirstFile(const char *spec, int flags = wxFILE);
|
WXDLLEXPORT wxString wxFindFirstFile(const char *spec, int flags = wxFILE);
|
||||||
WXDLLEXPORT char* wxFindNextFile(void);
|
WXDLLEXPORT wxString wxFindNextFile();
|
||||||
|
|
||||||
// Does the pattern contain wildcards?
|
// Does the pattern contain wildcards?
|
||||||
WXDLLEXPORT bool wxIsWild(const wxString& pattern);
|
WXDLLEXPORT bool wxIsWild(const wxString& pattern);
|
||||||
@@ -142,6 +143,9 @@ WXDLLEXPORT bool wxRenameFile(const wxString& file1, const wxString& file2);
|
|||||||
// IMPORTANT NOTE getcwd is know not to work under some releases
|
// IMPORTANT NOTE getcwd is know not to work under some releases
|
||||||
// of Win32s 1.3, according to MS release notes!
|
// of Win32s 1.3, according to MS release notes!
|
||||||
WXDLLEXPORT char* wxGetWorkingDirectory(char *buf = (char *) NULL, int sz = 1000);
|
WXDLLEXPORT char* wxGetWorkingDirectory(char *buf = (char *) NULL, int sz = 1000);
|
||||||
|
// new and preferred version of wxGetWorkingDirectory
|
||||||
|
// NB: can't have the same name because of overloading ambiguity
|
||||||
|
WXDLLEXPORT wxString wxGetCwd();
|
||||||
|
|
||||||
// Set working directory
|
// Set working directory
|
||||||
WXDLLEXPORT bool wxSetWorkingDirectory(const wxString& d);
|
WXDLLEXPORT bool wxSetWorkingDirectory(const wxString& d);
|
||||||
@@ -153,23 +157,23 @@ WXDLLEXPORT bool wxMkdir(const wxString& dir);
|
|||||||
WXDLLEXPORT bool wxRmdir(const wxString& dir, int flags = 0);
|
WXDLLEXPORT bool wxRmdir(const wxString& dir, int flags = 0);
|
||||||
|
|
||||||
// separators in file names
|
// separators in file names
|
||||||
#define FILE_SEP_EXT '.'
|
#define wxFILE_SEP_EXT '.'
|
||||||
#define FILE_SEP_DSK ':'
|
#define wxFILE_SEP_DSK ':'
|
||||||
#define FILE_SEP_PATH_DOS '\\'
|
#define wxFILE_SEP_PATH_DOS '\\'
|
||||||
#define FILE_SEP_PATH_UNIX '/'
|
#define wxFILE_SEP_PATH_UNIX '/'
|
||||||
|
|
||||||
// separator in the path list (as in PATH environment variable)
|
// separator in the path list (as in PATH environment variable)
|
||||||
// NB: these are strings and not characters on purpose!
|
// NB: these are strings and not characters on purpose!
|
||||||
#define PATH_SEP_DOS ";"
|
#define wxPATH_SEP_DOS ";"
|
||||||
#define PATH_SEP_UNIX ":"
|
#define wxPATH_SEP_UNIX ":"
|
||||||
|
|
||||||
// platform independent versions
|
// platform independent versions
|
||||||
#ifdef __UNIX__
|
#ifdef __UNIX__
|
||||||
#define FILE_SEP_PATH FILE_SEP_PATH_UNIX
|
#define wxFILE_SEP_PATH wxFILE_SEP_PATH_UNIX
|
||||||
#define PATH_SEP PATH_SEP_UNIX
|
#define wxPATH_SEP wxPATH_SEP_UNIX
|
||||||
#else // Windows
|
#else // Windows
|
||||||
#define FILE_SEP_PATH FILE_SEP_PATH_DOS
|
#define wxFILE_SEP_PATH wxFILE_SEP_PATH_DOS
|
||||||
#define PATH_SEP PATH_SEP_DOS
|
#define wxPATH_SEP wxPATH_SEP_DOS
|
||||||
#endif // Unix/Windows
|
#endif // Unix/Windows
|
||||||
|
|
||||||
// this is useful for wxString::IsSameAs(): to compare two file names use
|
// this is useful for wxString::IsSameAs(): to compare two file names use
|
||||||
@@ -182,7 +186,7 @@ WXDLLEXPORT bool wxRmdir(const wxString& dir, int flags = 0);
|
|||||||
|
|
||||||
// is the char a path separator?
|
// is the char a path separator?
|
||||||
inline bool wxIsPathSeparator(char c)
|
inline bool wxIsPathSeparator(char c)
|
||||||
{ return c == FILE_SEP_PATH_DOS || c == FILE_SEP_PATH_UNIX; }
|
{ return c == wxFILE_SEP_PATH_DOS || c == wxFILE_SEP_PATH_UNIX; }
|
||||||
|
|
||||||
// does the string ends with path separator?
|
// does the string ends with path separator?
|
||||||
WXDLLEXPORT bool wxEndsWithPathSeparator(const char *pszFileName);
|
WXDLLEXPORT bool wxEndsWithPathSeparator(const char *pszFileName);
|
||||||
@@ -209,19 +213,20 @@ WXDLLEXPORT wxString wxGetOSDirectory();
|
|||||||
class WXDLLEXPORT wxPathList : public wxStringList
|
class WXDLLEXPORT wxPathList : public wxStringList
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void AddEnvList(const wxString& envVariable); // Adds all paths in environment variable
|
// Adds all paths in environment variable
|
||||||
|
void AddEnvList(const wxString& envVariable);
|
||||||
|
|
||||||
void Add(const wxString& path);
|
void Add(const wxString& path);
|
||||||
// Avoid compiler warning
|
// Avoid compiler warning
|
||||||
wxNode *Add(const char *s) { return wxStringList::Add(s); }
|
wxNode *Add(const char *s) { return wxStringList::Add(s); }
|
||||||
|
// Find the first full path for which the file exists
|
||||||
wxString FindValidPath(const wxString& filename); // Find the first full path
|
wxString FindValidPath(const wxString& filename);
|
||||||
// for which the file exists
|
// Find the first full path for which the file exists; ensure it's an
|
||||||
wxString FindAbsoluteValidPath(const wxString& filename); // Find the first full path
|
// absolute path that gets returned.
|
||||||
// for which the file exists; ensure it's an absolute
|
wxString FindAbsoluteValidPath(const wxString& filename);
|
||||||
// path that gets returned.
|
// Given full path and filename, add path to list
|
||||||
void EnsureFileAccessible(const wxString& path); // Given full path and filename,
|
void EnsureFileAccessible(const wxString& path);
|
||||||
// add path to list
|
// Returns TRUE if the path is in the list
|
||||||
bool Member(const wxString& path);
|
bool Member(const wxString& path);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifdef __GNUG__
|
#ifdef __GNUG__
|
||||||
#pragma implementation "filefn.h"
|
#pragma implementation "filefn.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// For compilers that support precompilation, includes "wx.h".
|
// For compilers that support precompilation, includes "wx.h".
|
||||||
@@ -18,11 +18,11 @@
|
|||||||
#include "wx/defs.h"
|
#include "wx/defs.h"
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
#pragma hdrstop
|
#pragma hdrstop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef WX_PRECOMP
|
#ifndef WX_PRECOMP
|
||||||
#include "wx/defs.h"
|
#include "wx/defs.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/utils.h"
|
#include "wx/utils.h"
|
||||||
@@ -46,42 +46,42 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#ifndef __MWERKS__
|
#ifndef __MWERKS__
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#else
|
#else
|
||||||
#include <stat.h>
|
#include <stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __UNIX__
|
#ifdef __UNIX__
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
#if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__SALFORDC__)
|
#if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__SALFORDC__)
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
#include <dos.h>
|
#include <dos.h>
|
||||||
#endif
|
#endif // __WINDOWS__
|
||||||
#endif
|
#endif // native Win compiler
|
||||||
|
|
||||||
#ifdef __GNUWIN32__
|
#ifdef __GNUWIN32__
|
||||||
#ifndef __TWIN32__
|
#ifndef __TWIN32__
|
||||||
#include <sys/unistd.h>
|
#include <sys/unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define stricmp strcasecmp
|
#define stricmp strcasecmp
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __BORLANDC__ // Please someone tell me which version of Borland needs
|
#ifdef __BORLANDC__ // Please someone tell me which version of Borland needs
|
||||||
// this (3.1 I believe) and how to test for it.
|
// this (3.1 I believe) and how to test for it.
|
||||||
// If this works for Borland 4.0 as well, then no worries.
|
// If this works for Borland 4.0 as well, then no worries.
|
||||||
#include <dir.h>
|
#include <dir.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __SALFORDC__
|
#ifdef __SALFORDC__
|
||||||
#include <dir.h>
|
#include <dir.h>
|
||||||
#include <unix.h>
|
#include <unix.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/setup.h"
|
#include "wx/setup.h"
|
||||||
@@ -89,29 +89,29 @@
|
|||||||
|
|
||||||
// No, Cygwin doesn't appear to have fnmatch.h after all.
|
// No, Cygwin doesn't appear to have fnmatch.h after all.
|
||||||
#if defined(HAVE_FNMATCH_H)
|
#if defined(HAVE_FNMATCH_H)
|
||||||
#include "fnmatch.h"
|
#include "fnmatch.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define _MAXPATHLEN 500
|
#define _MAXPATHLEN 500
|
||||||
|
|
||||||
extern char *wxBuffer;
|
extern char *wxBuffer;
|
||||||
#ifdef __WXMAC__
|
#ifdef __WXMAC__
|
||||||
extern char gwxMacFileName[] ;
|
extern char gwxMacFileName[] ;
|
||||||
extern char gwxMacFileName2[] ;
|
extern char gwxMacFileName2[] ;
|
||||||
extern char gwxMacFileName3[] ;
|
extern char gwxMacFileName3[] ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !USE_SHARED_LIBRARIES
|
#if !USE_SHARED_LIBRARIES
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxPathList, wxStringList)
|
IMPLEMENT_DYNAMIC_CLASS(wxPathList, wxStringList)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void wxPathList::Add (const wxString& path)
|
void wxPathList::Add (const wxString& path)
|
||||||
{
|
{
|
||||||
wxStringList::Add ((char *)(const char *)path);
|
wxStringList::Add ((char *)(const char *)path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add paths e.g. from the PATH environment variable
|
// Add paths e.g. from the PATH environment variable
|
||||||
@@ -148,13 +148,12 @@ void wxPathList::AddEnvList (const wxString& envVariable)
|
|||||||
// to the list if not already there.
|
// to the list if not already there.
|
||||||
void wxPathList::EnsureFileAccessible (const wxString& path)
|
void wxPathList::EnsureFileAccessible (const wxString& path)
|
||||||
{
|
{
|
||||||
wxString path1(path);
|
wxString path_only(wxPathOnly(path));
|
||||||
char *path_only = wxPathOnly (WXSTRINGCAST path1);
|
if ( !path_only.IsEmpty() )
|
||||||
if (path_only)
|
{
|
||||||
{
|
if ( !Member(path_only) )
|
||||||
if (!Member (wxString(path_only)))
|
Add(path_only);
|
||||||
Add (wxString(path_only));
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxPathList::Member (const wxString& path)
|
bool wxPathList::Member (const wxString& path)
|
||||||
@@ -391,7 +390,7 @@ char *wxCopyAbsolutePath(const wxString& filename)
|
|||||||
if (! IsAbsolutePath(wxExpandPath(wxBuffer, filename))) {
|
if (! IsAbsolutePath(wxExpandPath(wxBuffer, filename))) {
|
||||||
char buf[_MAXPATHLEN];
|
char buf[_MAXPATHLEN];
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
wxGetWorkingDirectory(buf, sizeof(buf)/sizeof(char));
|
wxGetWorkingDirectory(buf, WXSIZEOF(buf));
|
||||||
char ch = buf[strlen(buf) - 1];
|
char ch = buf[strlen(buf) - 1];
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
if (ch != '\\' && ch != '/')
|
if (ch != '\\' && ch != '/')
|
||||||
@@ -1135,268 +1134,280 @@ char *wxGetTempFileName(const wxString& prefix, char *buf)
|
|||||||
// Flags are reserved for future use.
|
// Flags are reserved for future use.
|
||||||
|
|
||||||
#ifndef __VMS__
|
#ifndef __VMS__
|
||||||
static DIR *wxDirStream = (DIR *) NULL;
|
static DIR *gs_dirStream = (DIR *) NULL;
|
||||||
static char *wxFileSpec = (char *) NULL;
|
static wxString gs_strFileSpec;
|
||||||
static int wxFindFileFlags = 0;
|
static int gs_findFlags = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char *wxFindFirstFile(const char *spec, int flags)
|
wxString wxFindFirstFile(const char *spec, int flags)
|
||||||
{
|
{
|
||||||
|
wxString result;
|
||||||
|
|
||||||
#ifndef __VMS__
|
#ifndef __VMS__
|
||||||
if (wxDirStream)
|
if (gs_dirStream)
|
||||||
closedir(wxDirStream); // edz 941103: better housekeping
|
closedir(gs_dirStream); // edz 941103: better housekeping
|
||||||
|
|
||||||
wxFindFileFlags = flags;
|
gs_findFlags = flags;
|
||||||
|
|
||||||
if (wxFileSpec)
|
gs_strFileSpec = spec;
|
||||||
delete[] wxFileSpec;
|
|
||||||
wxFileSpec = copystring(spec);
|
|
||||||
|
|
||||||
// Find path only so we can concatenate
|
// Find path only so we can concatenate
|
||||||
// found file onto path
|
// found file onto path
|
||||||
char *p = wxPathOnly(wxFileSpec);
|
wxString path(wxPathOnly(gs_strFileSpec));
|
||||||
|
|
||||||
/* MATTHEW: special case: path is really "/" */
|
// special case: path is really "/"
|
||||||
if (p && !*p && *wxFileSpec == '/')
|
if ( !path && gs_strFileSpec[0u] == '/' )
|
||||||
p = "/";
|
path = '/';
|
||||||
/* MATTHEW: p is NULL => Local directory */
|
// path is empty => Local directory
|
||||||
if (!p)
|
if ( !path )
|
||||||
p = ".";
|
path = '.';
|
||||||
|
|
||||||
if ((wxDirStream=opendir(p))==NULL)
|
gs_dirStream = opendir(path);
|
||||||
return (char *) NULL;
|
if ( !gs_dirStream )
|
||||||
|
{
|
||||||
|
wxLogSysError(_("Can not enumerate files in directory '%s'"),
|
||||||
|
path.c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = wxFindNextFile();
|
||||||
|
}
|
||||||
|
#endif // !VMS
|
||||||
|
|
||||||
/* MATTHEW: [5] wxFindNextFile can do the rest of the work */
|
return result;
|
||||||
return wxFindNextFile();
|
|
||||||
#endif
|
|
||||||
// ifndef __VMS__
|
|
||||||
return (char *) NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *wxFindNextFile(void)
|
wxString wxFindNextFile()
|
||||||
{
|
{
|
||||||
|
wxString result;
|
||||||
|
|
||||||
#ifndef __VMS__
|
#ifndef __VMS__
|
||||||
static char buf[400]; // FIXME static buffer
|
wxCHECK_MSG( gs_dirStream, result, "must call wxFindFirstFile first" );
|
||||||
|
|
||||||
/* MATTHEW: [2] Don't crash if we read too many times */
|
// Find path only so we can concatenate
|
||||||
if (!wxDirStream)
|
// found file onto path
|
||||||
return (char *) NULL;
|
wxString path(wxPathOnly(gs_strFileSpec));
|
||||||
|
wxString name(wxFileNameFromPath(gs_strFileSpec));
|
||||||
|
|
||||||
// Find path only so we can concatenate
|
/* MATTHEW: special case: path is really "/" */
|
||||||
// found file onto path
|
if ( !path && gs_strFileSpec[0u] == '/')
|
||||||
char *p = wxPathOnly(wxFileSpec);
|
path = '/';
|
||||||
char *n = wxFileNameFromPath(wxFileSpec);
|
|
||||||
|
|
||||||
/* MATTHEW: special case: path is really "/" */
|
// Do the reading
|
||||||
if (p && !*p && *wxFileSpec == '/')
|
struct dirent *nextDir;
|
||||||
p = "/";
|
for ( nextDir = readdir(gs_dirStream);
|
||||||
|
nextDir != NULL;
|
||||||
|
nextDir = readdir(gs_dirStream) )
|
||||||
|
{
|
||||||
|
if (wxMatchWild(name, nextDir->d_name))
|
||||||
|
{
|
||||||
|
result.Empty();
|
||||||
|
if ( !path.IsEmpty() )
|
||||||
|
{
|
||||||
|
result = path;
|
||||||
|
if ( path != '/' )
|
||||||
|
result += '/';
|
||||||
|
}
|
||||||
|
|
||||||
// Do the reading
|
result += nextDir->d_name;
|
||||||
struct dirent *nextDir;
|
|
||||||
for (nextDir = readdir(wxDirStream); nextDir != NULL; nextDir = readdir(wxDirStream))
|
|
||||||
{
|
|
||||||
|
|
||||||
/* MATTHEW: [5] Only return "." and ".." when they match, and only return
|
// Only return "." and ".." when they match
|
||||||
directories when flags & wxDIR */
|
bool isdir;
|
||||||
if (wxMatchWild(n, nextDir->d_name)) {
|
if ( (strcmp(nextDir->d_name, ".") == 0) ||
|
||||||
bool isdir;
|
(strcmp(nextDir->d_name, "..") == 0))
|
||||||
|
{
|
||||||
|
if ( (gs_findFlags & wxDIR) != 0 )
|
||||||
|
isdir = TRUE;
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
isdir = wxDirExists(result);
|
||||||
|
|
||||||
buf[0] = 0;
|
// and only return directories when flags & wxDIR
|
||||||
if (p && *p) {
|
if ( !gs_findFlags ||
|
||||||
strcpy(buf, p);
|
((gs_findFlags & wxDIR) && isdir) ||
|
||||||
if (strcmp(p, "/") != 0)
|
((gs_findFlags & wxFILE) && !isdir) )
|
||||||
strcat(buf, "/");
|
{
|
||||||
}
|
return result;
|
||||||
strcat(buf, nextDir->d_name);
|
}
|
||||||
|
}
|
||||||
if ((strcmp(nextDir->d_name, ".") == 0) ||
|
|
||||||
(strcmp(nextDir->d_name, "..") == 0)) {
|
|
||||||
if (wxFindFileFlags && !(wxFindFileFlags & wxDIR))
|
|
||||||
continue;
|
|
||||||
isdir = TRUE;
|
|
||||||
} else
|
|
||||||
isdir = wxDirExists(buf);
|
|
||||||
|
|
||||||
if (!wxFindFileFlags
|
|
||||||
|| ((wxFindFileFlags & wxDIR) && isdir)
|
|
||||||
|| ((wxFindFileFlags & wxFILE) && !isdir))
|
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
closedir(wxDirStream);
|
|
||||||
wxDirStream = (DIR *) NULL;
|
|
||||||
#endif
|
|
||||||
// ifndef __VMS__
|
|
||||||
|
|
||||||
return (char *) NULL;
|
result.Empty(); // not found
|
||||||
|
|
||||||
|
closedir(gs_dirStream);
|
||||||
|
gs_dirStream = (DIR *) NULL;
|
||||||
|
#endif // !VMS
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(__WXMSW__)
|
#elif defined(__WXMSW__)
|
||||||
|
|
||||||
#ifdef __WIN32__
|
#ifdef __WIN32__
|
||||||
HANDLE wxFileStrucHandle = INVALID_HANDLE_VALUE;
|
static HANDLE gs_hFileStruct = INVALID_HANDLE_VALUE;
|
||||||
WIN32_FIND_DATA wxFileStruc;
|
static WIN32_FIND_DATA gs_findDataStruct;
|
||||||
#else
|
#else // Win16
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
static struct ffblk wxFileStruc;
|
static struct ffblk gs_findDataStruct;
|
||||||
#else
|
#else
|
||||||
static struct _find_t wxFileStruc;
|
static struct _find_t gs_findDataStruct;
|
||||||
#endif
|
#endif // Borland
|
||||||
#endif
|
#endif // Win32/16
|
||||||
static wxString wxFileSpec = "";
|
|
||||||
static int wxFindFileFlags;
|
|
||||||
|
|
||||||
char *wxFindFirstFile(const char *spec, int flags)
|
static wxString gs_strFileSpec;
|
||||||
|
static int gs_findFlags = 0;
|
||||||
|
|
||||||
|
wxString wxFindFirstFile(const char *spec, int flags)
|
||||||
{
|
{
|
||||||
wxFileSpec = spec;
|
wxString result;
|
||||||
wxFindFileFlags = flags; /* MATTHEW: [5] Remember flags */
|
|
||||||
|
|
||||||
// Find path only so we can concatenate
|
gs_strFileSpec = spec;
|
||||||
// found file onto path
|
gs_findFlags = flags; /* MATTHEW: [5] Remember flags */
|
||||||
wxString path1(wxFileSpec);
|
|
||||||
char *p = wxPathOnly(WXSTRINGCAST path1);
|
// Find path only so we can concatenate found file onto path
|
||||||
if (p && (strlen(p) > 0))
|
wxString path(wxPathOnly(gs_strFileSpec));
|
||||||
strcpy(wxBuffer, p);
|
if ( !path.IsEmpty() )
|
||||||
else
|
result << path << '\\';
|
||||||
wxBuffer[0] = 0;
|
|
||||||
|
|
||||||
#ifdef __WIN32__
|
#ifdef __WIN32__
|
||||||
if (wxFileStrucHandle != INVALID_HANDLE_VALUE)
|
if ( gs_hFileStruct != INVALID_HANDLE_VALUE )
|
||||||
FindClose(wxFileStrucHandle);
|
FindClose(gs_hFileStruct);
|
||||||
|
|
||||||
wxFileStrucHandle = ::FindFirstFile(WXSTRINGCAST spec, &wxFileStruc);
|
gs_hFileStruct = ::FindFirstFile(WXSTRINGCAST spec, &gs_findDataStruct);
|
||||||
|
|
||||||
if (wxFileStrucHandle == INVALID_HANDLE_VALUE)
|
if ( gs_hFileStruct == INVALID_HANDLE_VALUE )
|
||||||
return NULL;
|
{
|
||||||
|
wxLogSysError(_("Can not enumerate files in directory '%s'"),
|
||||||
|
path.c_str());
|
||||||
|
|
||||||
bool isdir = !!(wxFileStruc.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
|
result.Empty();
|
||||||
|
|
||||||
if (isdir && !(flags & wxDIR))
|
return result;
|
||||||
return wxFindNextFile();
|
}
|
||||||
else if (!isdir && flags && !(flags & wxFILE))
|
|
||||||
return wxFindNextFile();
|
|
||||||
|
|
||||||
if (wxBuffer[0] != 0)
|
bool isdir = !!(gs_findDataStruct.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
|
||||||
strcat(wxBuffer, "\\");
|
|
||||||
strcat(wxBuffer, wxFileStruc.cFileName);
|
|
||||||
return wxBuffer;
|
|
||||||
#else
|
|
||||||
|
|
||||||
int flag = _A_NORMAL;
|
if (isdir && !(flags & wxDIR))
|
||||||
if (flags & wxDIR) /* MATTHEW: [5] Use & */
|
|
||||||
flag = _A_SUBDIR;
|
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
|
||||||
if (findfirst(WXSTRINGCAST spec, &wxFileStruc, flag) == 0)
|
|
||||||
#else
|
|
||||||
if (_dos_findfirst(WXSTRINGCAST spec, flag, &wxFileStruc) == 0)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
/* MATTHEW: [5] Check directory flag */
|
|
||||||
char attrib;
|
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
|
||||||
attrib = wxFileStruc.ff_attrib;
|
|
||||||
#else
|
|
||||||
attrib = wxFileStruc.attrib;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (attrib & _A_SUBDIR) {
|
|
||||||
if (!(wxFindFileFlags & wxDIR))
|
|
||||||
return wxFindNextFile();
|
return wxFindNextFile();
|
||||||
} else if (wxFindFileFlags && !(wxFindFileFlags & wxFILE))
|
else if (!isdir && flags && !(flags & wxFILE))
|
||||||
|
return wxFindNextFile();
|
||||||
|
|
||||||
|
result += gs_findDataStruct.cFileName;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
#else
|
||||||
|
int flag = _A_NORMAL;
|
||||||
|
if (flags & wxDIR) /* MATTHEW: [5] Use & */
|
||||||
|
flag = _A_SUBDIR;
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
if (findfirst(WXSTRINGCAST spec, &gs_findDataStruct, flag) == 0)
|
||||||
|
#else
|
||||||
|
if (_dos_findfirst(WXSTRINGCAST spec, flag, &gs_findDataStruct) == 0)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
/* MATTHEW: [5] Check directory flag */
|
||||||
|
char attrib;
|
||||||
|
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
attrib = gs_findDataStruct.ff_attrib;
|
||||||
|
#else
|
||||||
|
attrib = gs_findDataStruct.attrib;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (attrib & _A_SUBDIR) {
|
||||||
|
if (!(gs_findFlags & wxDIR))
|
||||||
|
return wxFindNextFile();
|
||||||
|
} else if (gs_findFlags && !(gs_findFlags & wxFILE))
|
||||||
return wxFindNextFile();
|
return wxFindNextFile();
|
||||||
|
|
||||||
if (wxBuffer[0] != 0)
|
result +=
|
||||||
strcat(wxBuffer, "\\");
|
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
strcat(wxBuffer, wxFileStruc.ff_name);
|
gs_findDataStruct.ff_name
|
||||||
#else
|
#else
|
||||||
strcat(wxBuffer, wxFileStruc.name);
|
gs_findDataStruct.name
|
||||||
#endif
|
#endif
|
||||||
return wxBuffer;
|
;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
#endif // __WIN32__
|
#endif // __WIN32__
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *wxFindNextFile(void)
|
wxString wxFindNextFile()
|
||||||
{
|
{
|
||||||
// Find path only so we can concatenate
|
wxString result;
|
||||||
// found file onto path
|
|
||||||
wxString p2(wxFileSpec);
|
|
||||||
char *p = wxPathOnly(WXSTRINGCAST p2);
|
|
||||||
if (p && (strlen(p) > 0))
|
|
||||||
strcpy(wxBuffer, p);
|
|
||||||
else
|
|
||||||
wxBuffer[0] = 0;
|
|
||||||
|
|
||||||
try_again:
|
// Find path only so we can concatenate found file onto path
|
||||||
|
wxString path(wxPathOnly(gs_strFileSpec));
|
||||||
|
|
||||||
|
try_again:
|
||||||
|
|
||||||
#ifdef __WIN32__
|
#ifdef __WIN32__
|
||||||
if (wxFileStrucHandle == INVALID_HANDLE_VALUE)
|
if (gs_hFileStruct == INVALID_HANDLE_VALUE)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
bool success = (FindNextFile(wxFileStrucHandle, &wxFileStruc) != 0);
|
bool success = (FindNextFile(gs_hFileStruct, &gs_findDataStruct) != 0);
|
||||||
if (!success) {
|
if (!success)
|
||||||
FindClose(wxFileStrucHandle);
|
{
|
||||||
wxFileStrucHandle = INVALID_HANDLE_VALUE;
|
FindClose(gs_hFileStruct);
|
||||||
return NULL;
|
gs_hFileStruct = INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool isdir = !!(gs_findDataStruct.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
|
||||||
|
|
||||||
bool isdir = !!(wxFileStruc.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
|
if (isdir && !(gs_findFlags & wxDIR))
|
||||||
|
goto try_again;
|
||||||
|
else if (!isdir && gs_findFlags && !(gs_findFlags & wxFILE))
|
||||||
|
goto try_again;
|
||||||
|
|
||||||
if (isdir && !(wxFindFileFlags & wxDIR))
|
if ( !path.IsEmpty() )
|
||||||
goto try_again;
|
result << path << '\\';
|
||||||
else if (!isdir && wxFindFileFlags && !(wxFindFileFlags & wxFILE))
|
result << gs_findDataStruct.cFileName;
|
||||||
goto try_again;
|
}
|
||||||
|
|
||||||
if (wxBuffer[0] != 0)
|
return result;
|
||||||
strcat(wxBuffer, "\\");
|
#else // Win16
|
||||||
strcat(wxBuffer, wxFileStruc.cFileName);
|
|
||||||
return wxBuffer;
|
|
||||||
#else
|
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
if (findnext(&wxFileStruc) == 0)
|
if (findnext(&gs_findDataStruct) == 0)
|
||||||
#else
|
#else
|
||||||
if (_dos_findnext(&wxFileStruc) == 0)
|
if (_dos_findnext(&gs_findDataStruct) == 0)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
/* MATTHEW: [5] Check directory flag */
|
/* MATTHEW: [5] Check directory flag */
|
||||||
char attrib;
|
char attrib;
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
attrib = wxFileStruc.ff_attrib;
|
attrib = gs_findDataStruct.ff_attrib;
|
||||||
#else
|
#else
|
||||||
attrib = wxFileStruc.attrib;
|
attrib = gs_findDataStruct.attrib;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (attrib & _A_SUBDIR) {
|
if (attrib & _A_SUBDIR) {
|
||||||
if (!(wxFindFileFlags & wxDIR))
|
if (!(gs_findFlags & wxDIR))
|
||||||
goto try_again;
|
goto try_again;
|
||||||
} else if (wxFindFileFlags && !(wxFindFileFlags & wxFILE))
|
} else if (gs_findFlags && !(gs_findFlags & wxFILE))
|
||||||
goto try_again;
|
goto try_again;
|
||||||
|
|
||||||
|
|
||||||
if (wxBuffer[0] != 0)
|
result +=
|
||||||
strcat(wxBuffer, "\\");
|
|
||||||
#ifdef __BORLANDC__
|
#ifdef __BORLANDC__
|
||||||
strcat(wxBuffer, wxFileStruc.ff_name);
|
gs_findDataStruct.ff_name
|
||||||
#else
|
#else
|
||||||
strcat(wxBuffer, wxFileStruc.name);
|
gs_findDataStruct.name
|
||||||
#endif
|
|
||||||
return wxBuffer;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
#endif
|
#endif
|
||||||
|
;
|
||||||
|
}
|
||||||
|
#endif // Win32/16
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif // Unix/Windows
|
||||||
// __WXMSW__
|
|
||||||
|
|
||||||
// Get current working directory.
|
// Get current working directory.
|
||||||
// If buf is NULL, allocates space using new, else
|
// If buf is NULL, allocates space using new, else
|
||||||
@@ -1416,6 +1427,11 @@ char *wxGetWorkingDirectory(char *buf, int sz)
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxString wxGetCwd()
|
||||||
|
{
|
||||||
|
return wxString(wxGetWorkingDirectory());
|
||||||
|
}
|
||||||
|
|
||||||
bool wxSetWorkingDirectory(const wxString& d)
|
bool wxSetWorkingDirectory(const wxString& d)
|
||||||
{
|
{
|
||||||
#if defined( __UNIX__ ) || defined( __WXMAC__ )
|
#if defined( __UNIX__ ) || defined( __WXMAC__ )
|
||||||
@@ -1490,11 +1506,14 @@ bool wxFindFileInPath(wxString *pStr, const char *pszPath, const char *pszFile)
|
|||||||
|
|
||||||
wxString strFile;
|
wxString strFile;
|
||||||
char *pc;
|
char *pc;
|
||||||
for ( pc = strtok(szPath, PATH_SEP); pc; pc = strtok((char *) NULL, PATH_SEP) ) {
|
for ( pc = strtok(szPath, wxPATH_SEP);
|
||||||
|
pc != NULL;
|
||||||
|
pc = strtok((char *) NULL, wxPATH_SEP) )
|
||||||
|
{
|
||||||
// search for the file in this directory
|
// search for the file in this directory
|
||||||
strFile = pc;
|
strFile = pc;
|
||||||
if ( !wxEndsWithPathSeparator(pc) )
|
if ( !wxEndsWithPathSeparator(pc) )
|
||||||
strFile += FILE_SEP_PATH;
|
strFile += wxFILE_SEP_PATH;
|
||||||
strFile += pszFile;
|
strFile += pszFile;
|
||||||
|
|
||||||
if ( FileExists(strFile) ) {
|
if ( FileExists(strFile) ) {
|
||||||
@@ -1515,9 +1534,9 @@ void WXDLLEXPORT wxSplitPath(const char *pszFileName,
|
|||||||
{
|
{
|
||||||
wxCHECK_RET( pszFileName, "NULL file name in wxSplitPath" );
|
wxCHECK_RET( pszFileName, "NULL file name in wxSplitPath" );
|
||||||
|
|
||||||
const char *pDot = strrchr(pszFileName, FILE_SEP_EXT);
|
const char *pDot = strrchr(pszFileName, wxFILE_SEP_EXT);
|
||||||
const char *pSepUnix = strrchr(pszFileName, FILE_SEP_PATH_UNIX);
|
const char *pSepUnix = strrchr(pszFileName, wxFILE_SEP_PATH_UNIX);
|
||||||
const char *pSepDos = strrchr(pszFileName, FILE_SEP_PATH_DOS);
|
const char *pSepDos = strrchr(pszFileName, wxFILE_SEP_PATH_DOS);
|
||||||
|
|
||||||
// take the last of the two: nPosUnix containts the last slash in the
|
// take the last of the two: nPosUnix containts the last slash in the
|
||||||
// filename
|
// filename
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
// Created: 29/01/98
|
// Created: 29/01/98
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
|
||||||
// Licence: wxWindows license
|
// Licence: wxWindows license
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -97,7 +97,7 @@ public:
|
|||||||
|
|
||||||
// public variable pointing to the next element in a linked list (or NULL)
|
// public variable pointing to the next element in a linked list (or NULL)
|
||||||
wxMsgCatalog *m_pNext;
|
wxMsgCatalog *m_pNext;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// this implementation is binary compatible with GNU gettext() version 0.10
|
// this implementation is binary compatible with GNU gettext() version 0.10
|
||||||
|
|
||||||
@@ -118,11 +118,11 @@ private:
|
|||||||
ofsTransTable; // +10: start of translated string table
|
ofsTransTable; // +10: start of translated string table
|
||||||
size_t32 nHashSize, // +14: hash table size
|
size_t32 nHashSize, // +14: hash table size
|
||||||
ofsHashTable; // +18: offset of hash table start
|
ofsHashTable; // +18: offset of hash table start
|
||||||
};
|
};
|
||||||
|
|
||||||
// all data is stored here, NULL if no data loaded
|
// all data is stored here, NULL if no data loaded
|
||||||
size_t8 *m_pData;
|
size_t8 *m_pData;
|
||||||
|
|
||||||
// data description
|
// data description
|
||||||
size_t32 m_numStrings, // number of strings in this domain
|
size_t32 m_numStrings, // number of strings in this domain
|
||||||
m_nHashSize; // number of entries in hash table
|
m_nHashSize; // number of entries in hash table
|
||||||
@@ -187,21 +187,21 @@ size_t32 wxMsgCatalog::GetHash(const char *sz)
|
|||||||
// swap the 2 halves of 32 bit integer if needed
|
// swap the 2 halves of 32 bit integer if needed
|
||||||
size_t32 wxMsgCatalog::Swap(size_t32 ui) const
|
size_t32 wxMsgCatalog::Swap(size_t32 ui) const
|
||||||
{
|
{
|
||||||
return m_bSwapped ? (ui << 24) | ((ui & 0xff00) << 8) |
|
return m_bSwapped ? (ui << 24) | ((ui & 0xff00) << 8) |
|
||||||
((ui >> 8) & 0xff00) | (ui >> 24)
|
((ui >> 8) & 0xff00) | (ui >> 24)
|
||||||
: ui;
|
: ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxMsgCatalog::wxMsgCatalog()
|
wxMsgCatalog::wxMsgCatalog()
|
||||||
{
|
{
|
||||||
m_pData = NULL;
|
m_pData = NULL;
|
||||||
m_pszName = NULL;
|
m_pszName = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxMsgCatalog::~wxMsgCatalog()
|
wxMsgCatalog::~wxMsgCatalog()
|
||||||
{
|
{
|
||||||
wxDELETEA(m_pData);
|
wxDELETEA(m_pData);
|
||||||
wxDELETEA(m_pszName);
|
wxDELETEA(m_pszName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// small class to suppress the translation erros until exit from current scope
|
// small class to suppress the translation erros until exit from current scope
|
||||||
@@ -211,7 +211,7 @@ public:
|
|||||||
NoTransErr() { wxSuppressTransErrors(); }
|
NoTransErr() { wxSuppressTransErrors(); }
|
||||||
~NoTransErr() { wxRestoreTransErrors(); }
|
~NoTransErr() { wxRestoreTransErrors(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
// return all directories to search for given prefix
|
// return all directories to search for given prefix
|
||||||
static wxString GetAllMsgCatalogSubdirs(const char *prefix,
|
static wxString GetAllMsgCatalogSubdirs(const char *prefix,
|
||||||
const char *lang)
|
const char *lang)
|
||||||
@@ -220,10 +220,10 @@ static wxString GetAllMsgCatalogSubdirs(const char *prefix,
|
|||||||
|
|
||||||
// search first in prefix/fr/LC_MESSAGES, then in prefix/fr and finally in
|
// search first in prefix/fr/LC_MESSAGES, then in prefix/fr and finally in
|
||||||
// prefix (assuming the language is 'fr')
|
// prefix (assuming the language is 'fr')
|
||||||
searchPath << prefix << FILE_SEP_PATH << lang << FILE_SEP_PATH
|
searchPath << prefix << wxFILE_SEP_PATH << lang << wxFILE_SEP_PATH
|
||||||
<< "LC_MESSAGES" << PATH_SEP
|
<< "LC_MESSAGES" << wxPATH_SEP
|
||||||
<< prefix << FILE_SEP_PATH << lang << PATH_SEP
|
<< prefix << wxFILE_SEP_PATH << lang << wxPATH_SEP
|
||||||
<< prefix << PATH_SEP;
|
<< prefix << wxPATH_SEP;
|
||||||
|
|
||||||
return searchPath;
|
return searchPath;
|
||||||
}
|
}
|
||||||
@@ -238,17 +238,17 @@ static wxString GetFullSearchPath(const char *lang)
|
|||||||
for ( size_t n = 0; n < count; n++ )
|
for ( size_t n = 0; n < count; n++ )
|
||||||
{
|
{
|
||||||
searchPath << GetAllMsgCatalogSubdirs(s_searchPrefixes[n], lang)
|
searchPath << GetAllMsgCatalogSubdirs(s_searchPrefixes[n], lang)
|
||||||
<< PATH_SEP;
|
<< wxPATH_SEP;
|
||||||
}
|
}
|
||||||
|
|
||||||
// then take the current directory
|
// then take the current directory
|
||||||
// FIXME it should be the directory of the executable
|
// FIXME it should be the directory of the executable
|
||||||
searchPath << GetAllMsgCatalogSubdirs(".", lang) << PATH_SEP;
|
searchPath << GetAllMsgCatalogSubdirs(".", lang) << wxPATH_SEP;
|
||||||
|
|
||||||
// and finally add some standard ones
|
// and finally add some standard ones
|
||||||
searchPath
|
searchPath
|
||||||
<< GetAllMsgCatalogSubdirs("/usr/share/locale", lang) << PATH_SEP
|
<< GetAllMsgCatalogSubdirs("/usr/share/locale", lang) << wxPATH_SEP
|
||||||
<< GetAllMsgCatalogSubdirs("/usr/lib/locale", lang) << PATH_SEP
|
<< GetAllMsgCatalogSubdirs("/usr/lib/locale", lang) << wxPATH_SEP
|
||||||
<< GetAllMsgCatalogSubdirs("/usr/local/share/locale", lang);
|
<< GetAllMsgCatalogSubdirs("/usr/local/share/locale", lang);
|
||||||
|
|
||||||
return searchPath;
|
return searchPath;
|
||||||
@@ -263,7 +263,7 @@ bool wxMsgCatalog::Load(const char *szDirPrefix, const char *szName)
|
|||||||
if ( pszLcPath != NULL )
|
if ( pszLcPath != NULL )
|
||||||
strPath += pszLcPath + wxString(szDirPrefix) + MSG_PATH;
|
strPath += pszLcPath + wxString(szDirPrefix) + MSG_PATH;
|
||||||
#endif // 0
|
#endif // 0
|
||||||
|
|
||||||
wxString searchPath = GetFullSearchPath(szDirPrefix);
|
wxString searchPath = GetFullSearchPath(szDirPrefix);
|
||||||
const char *sublocale = strchr(szDirPrefix, '_');
|
const char *sublocale = strchr(szDirPrefix, '_');
|
||||||
if ( sublocale )
|
if ( sublocale )
|
||||||
@@ -273,9 +273,9 @@ bool wxMsgCatalog::Load(const char *szDirPrefix, const char *szName)
|
|||||||
// exist
|
// exist
|
||||||
searchPath << GetFullSearchPath(wxString(szDirPrefix).
|
searchPath << GetFullSearchPath(wxString(szDirPrefix).
|
||||||
Left((size_t)(sublocale - szDirPrefix)))
|
Left((size_t)(sublocale - szDirPrefix)))
|
||||||
<< PATH_SEP;
|
<< wxPATH_SEP;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString strFile = szName;
|
wxString strFile = szName;
|
||||||
strFile += MSGCATALOG_EXTENSION;
|
strFile += MSGCATALOG_EXTENSION;
|
||||||
|
|
||||||
@@ -297,7 +297,7 @@ bool wxMsgCatalog::Load(const char *szDirPrefix, const char *szName)
|
|||||||
// open file
|
// open file
|
||||||
wxLogVerbose(_("using catalog '%s' from '%s'."),
|
wxLogVerbose(_("using catalog '%s' from '%s'."),
|
||||||
szName, strFullName.c_str());
|
szName, strFullName.c_str());
|
||||||
|
|
||||||
wxFile fileMsg(strFullName);
|
wxFile fileMsg(strFullName);
|
||||||
if ( !fileMsg.IsOpened() )
|
if ( !fileMsg.IsOpened() )
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -313,10 +313,10 @@ bool wxMsgCatalog::Load(const char *szDirPrefix, const char *szName)
|
|||||||
wxDELETEA(m_pData);
|
wxDELETEA(m_pData);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// examine header
|
// examine header
|
||||||
bool bValid = (size_t)nSize > sizeof(wxMsgCatalogHeader);
|
bool bValid = (size_t)nSize > sizeof(wxMsgCatalogHeader);
|
||||||
|
|
||||||
wxMsgCatalogHeader *pHeader = (wxMsgCatalogHeader *)m_pData;
|
wxMsgCatalogHeader *pHeader = (wxMsgCatalogHeader *)m_pData;
|
||||||
if ( bValid ) {
|
if ( bValid ) {
|
||||||
// we'll have to swap all the integers if it's true
|
// we'll have to swap all the integers if it's true
|
||||||
@@ -325,20 +325,20 @@ bool wxMsgCatalog::Load(const char *szDirPrefix, const char *szName)
|
|||||||
// check the magic number
|
// check the magic number
|
||||||
bValid = m_bSwapped || pHeader->magic == MSGCATALOG_MAGIC;
|
bValid = m_bSwapped || pHeader->magic == MSGCATALOG_MAGIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !bValid ) {
|
if ( !bValid ) {
|
||||||
// it's either too short or has incorrect magic number
|
// it's either too short or has incorrect magic number
|
||||||
wxLogWarning(_("'%s' is not a valid message catalog."), strFullName.c_str());
|
wxLogWarning(_("'%s' is not a valid message catalog."), strFullName.c_str());
|
||||||
|
|
||||||
wxDELETEA(m_pData);
|
wxDELETEA(m_pData);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize
|
// initialize
|
||||||
m_numStrings = Swap(pHeader->numStrings);
|
m_numStrings = Swap(pHeader->numStrings);
|
||||||
m_pOrigTable = (wxMsgTableEntry *)(m_pData +
|
m_pOrigTable = (wxMsgTableEntry *)(m_pData +
|
||||||
Swap(pHeader->ofsOrigTable));
|
Swap(pHeader->ofsOrigTable));
|
||||||
m_pTransTable = (wxMsgTableEntry *)(m_pData +
|
m_pTransTable = (wxMsgTableEntry *)(m_pData +
|
||||||
Swap(pHeader->ofsTransTable));
|
Swap(pHeader->ofsTransTable));
|
||||||
|
|
||||||
m_nHashSize = Swap(pHeader->nHashSize);
|
m_nHashSize = Swap(pHeader->nHashSize);
|
||||||
@@ -358,16 +358,16 @@ const char *wxMsgCatalog::GetString(const char *szOrig) const
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if ( HasHashTable() ) { // use hash table for lookup if possible
|
if ( HasHashTable() ) { // use hash table for lookup if possible
|
||||||
size_t32 nHashVal = GetHash(szOrig);
|
size_t32 nHashVal = GetHash(szOrig);
|
||||||
size_t32 nIndex = nHashVal % m_nHashSize;
|
size_t32 nIndex = nHashVal % m_nHashSize;
|
||||||
|
|
||||||
size_t32 nIncr = 1 + (nHashVal % (m_nHashSize - 2));
|
size_t32 nIncr = 1 + (nHashVal % (m_nHashSize - 2));
|
||||||
|
|
||||||
while ( TRUE ) {
|
while ( TRUE ) {
|
||||||
size_t32 nStr = Swap(m_pHashTable[nIndex]);
|
size_t32 nStr = Swap(m_pHashTable[nIndex]);
|
||||||
if ( nStr == 0 )
|
if ( nStr == 0 )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if ( strcmp(szOrig, StringAtOfs(m_pOrigTable, nStr - 1)) == 0 )
|
if ( strcmp(szOrig, StringAtOfs(m_pOrigTable, nStr - 1)) == 0 )
|
||||||
return StringAtOfs(m_pTransTable, nStr - 1);
|
return StringAtOfs(m_pTransTable, nStr - 1);
|
||||||
|
|
||||||
@@ -408,8 +408,8 @@ wxLocale::wxLocale()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NB: this function has (desired) side effect of changing current locale
|
// NB: this function has (desired) side effect of changing current locale
|
||||||
bool wxLocale::Init(const char *szName,
|
bool wxLocale::Init(const char *szName,
|
||||||
const char *szShort,
|
const char *szShort,
|
||||||
const char *szLocale,
|
const char *szLocale,
|
||||||
bool bLoadDefault)
|
bool bLoadDefault)
|
||||||
{
|
{
|
||||||
@@ -430,10 +430,10 @@ bool wxLocale::Init(const char *szName,
|
|||||||
// this wild guess is surely wrong
|
// this wild guess is surely wrong
|
||||||
m_strShort = wxToLower(szLocale[0]) + wxToLower(szLocale[1]);
|
m_strShort = wxToLower(szLocale[0]) + wxToLower(szLocale[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// save the old locale to be able to restore it later
|
// save the old locale to be able to restore it later
|
||||||
m_pOldLocale = wxSetLocale(this);
|
m_pOldLocale = wxSetLocale(this);
|
||||||
|
|
||||||
// load the default catalog with wxWindows standard messages
|
// load the default catalog with wxWindows standard messages
|
||||||
m_pMsgCat = NULL;
|
m_pMsgCat = NULL;
|
||||||
bool bOk = TRUE;
|
bool bOk = TRUE;
|
||||||
@@ -469,7 +469,7 @@ wxLocale::~wxLocale()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get the translation of given string in current locale
|
// get the translation of given string in current locale
|
||||||
const char *wxLocale::GetString(const char *szOrigString,
|
const char *wxLocale::GetString(const char *szOrigString,
|
||||||
const char *szDomain) const
|
const char *szDomain) const
|
||||||
{
|
{
|
||||||
wxASSERT( szOrigString != NULL ); // would be pretty silly
|
wxASSERT( szOrigString != NULL ); // would be pretty silly
|
||||||
@@ -479,7 +479,7 @@ const char *wxLocale::GetString(const char *szOrigString,
|
|||||||
wxMsgCatalog *pMsgCat;
|
wxMsgCatalog *pMsgCat;
|
||||||
if ( szDomain != NULL ) {
|
if ( szDomain != NULL ) {
|
||||||
pMsgCat = FindCatalog(szDomain);
|
pMsgCat = FindCatalog(szDomain);
|
||||||
|
|
||||||
// does the catalog exist?
|
// does the catalog exist?
|
||||||
if ( pMsgCat != NULL )
|
if ( pMsgCat != NULL )
|
||||||
pszTrans = pMsgCat->GetString(szOrigString);
|
pszTrans = pMsgCat->GetString(szOrigString);
|
||||||
@@ -505,7 +505,7 @@ const char *wxLocale::GetString(const char *szOrigString,
|
|||||||
#else // !debug
|
#else // !debug
|
||||||
wxSuppressTransErrors();
|
wxSuppressTransErrors();
|
||||||
#endif // debug/!debug
|
#endif // debug/!debug
|
||||||
|
|
||||||
if ( szDomain != NULL )
|
if ( szDomain != NULL )
|
||||||
{
|
{
|
||||||
wxLogWarning(_("string '%s' not found in domain '%s' for locale '%s'."),
|
wxLogWarning(_("string '%s' not found in domain '%s' for locale '%s'."),
|
||||||
@@ -533,7 +533,7 @@ wxMsgCatalog *wxLocale::FindCatalog(const char *szDomain) const
|
|||||||
if ( Stricmp(pMsgCat->GetName(), szDomain) == 0 )
|
if ( Stricmp(pMsgCat->GetName(), szDomain) == 0 )
|
||||||
return pMsgCat;
|
return pMsgCat;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -547,19 +547,19 @@ bool wxLocale::IsLoaded(const char *szDomain) const
|
|||||||
bool wxLocale::AddCatalog(const char *szDomain)
|
bool wxLocale::AddCatalog(const char *szDomain)
|
||||||
{
|
{
|
||||||
wxMsgCatalog *pMsgCat = new wxMsgCatalog;
|
wxMsgCatalog *pMsgCat = new wxMsgCatalog;
|
||||||
|
|
||||||
if ( pMsgCat->Load(m_strShort, szDomain) ) {
|
if ( pMsgCat->Load(m_strShort, szDomain) ) {
|
||||||
// add it to the head of the list so that in GetString it will
|
// add it to the head of the list so that in GetString it will
|
||||||
// be searched before the catalogs added earlier
|
// be searched before the catalogs added earlier
|
||||||
pMsgCat->m_pNext = m_pMsgCat;
|
pMsgCat->m_pNext = m_pMsgCat;
|
||||||
m_pMsgCat = pMsgCat;
|
m_pMsgCat = pMsgCat;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// don't add it because it couldn't be loaded anyway
|
// don't add it because it couldn't be loaded anyway
|
||||||
delete pMsgCat;
|
delete pMsgCat;
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -596,12 +596,12 @@ wxLocale *g_pLocale = NULL;
|
|||||||
|
|
||||||
wxLocale *wxGetLocale()
|
wxLocale *wxGetLocale()
|
||||||
{
|
{
|
||||||
return g_pLocale;
|
return g_pLocale;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxLocale *wxSetLocale(wxLocale *pLocale)
|
wxLocale *wxSetLocale(wxLocale *pLocale)
|
||||||
{
|
{
|
||||||
wxLocale *pOld = g_pLocale;
|
wxLocale *pOld = g_pLocale;
|
||||||
g_pLocale = pLocale;
|
g_pLocale = pLocale;
|
||||||
return pOld;
|
return pOld;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user