// check the closing bracket
if ( bracket != Bracket_None ) {
if ( m == str.Len() || str[m] != (char)bracket ) {
- wxLogWarning("missing '%c' at position %d in '%s'.",
+ wxLogWarning(_("missing '%c' at position %d in '%s'."),
(char)bracket, m + 1, str.c_str());
}
else {
else if ( strCurrent == ".." ) {
// go up one level
if ( aParts.IsEmpty() )
- wxLogWarning("'%s' has extra '..', ignored.", sz);
+ wxLogWarning(_("'%s' has extra '..', ignored."), sz);
else
aParts.Remove(aParts.Count() - 1);
int fd = open(szFileName, O_CREAT | (bOverwrite ? O_TRUNC : O_EXCL));
if ( fd == -1 ) {
- wxLogSysError("can't create file '%s'", szFileName);
+ wxLogSysError(_("can't create file '%s'"), szFileName);
return FALSE;
}
else {
int fd = open(szFileName, flags, S_IREAD | S_IWRITE);
if ( fd == -1 ) {
- wxLogSysError("can't open file '%s'", szFileName);
+ wxLogSysError(_("can't open file '%s'"), szFileName);
return FALSE;
}
else {
{
if ( IsOpened() ) {
if ( close(m_fd) == -1 ) {
- wxLogSysError("can't close file descriptor %d", m_fd);
+ wxLogSysError(_("can't close file descriptor %d"), m_fd);
m_fd = fd_invalid;
return FALSE;
}
int iRc = ::read(m_fd, pBuf, nCount);
if ( iRc == -1 ) {
- wxLogSysError("can't read from file descriptor %d", m_fd);
+ wxLogSysError(_("can't read from file descriptor %d"), m_fd);
return ofsInvalid;
}
else
int iRc = ::write(m_fd, pBuf, nCount);
if ( iRc == -1 ) {
- wxLogSysError("can't write to file descriptor %d", m_fd);
+ wxLogSysError(_("can't write to file descriptor %d"), m_fd);
m_error = TRUE;
return 0;
}
else
- return iRc;
+ return (uint)iRc;
}
// flush
bool wxFile::Flush()
{
if ( IsOpened() ) {
- // @@@ fsync() is not ANSI (BSDish)
+// @@@ fsync() is not ANSI (BSDish)
// if ( fsync(m_fd) == -1 ) { // TODO
if (TRUE) {
- wxLogSysError("can't flush file descriptor %d", m_fd);
+ wxLogSysError(_("can't flush file descriptor %d"), m_fd);
return FALSE;
}
}
int iRc = lseek(m_fd, ofs, flag);
if ( iRc == -1 ) {
- wxLogSysError("can't seek on file descriptor %d", m_fd);
+ wxLogSysError(_("can't seek on file descriptor %d"), m_fd);
return ofsInvalid;
}
else
int iRc = tell(m_fd);
if ( iRc == -1 ) {
- wxLogSysError("can't get seek position on file descriptor %d", m_fd);
+ wxLogSysError(_("can't get seek position on file descriptor %d"), m_fd);
return ofsInvalid;
}
else
#endif //_MSC_VER
if ( iRc == -1 ) {
- wxLogSysError("can't find length of file on file descriptor %d", m_fd);
+ wxLogSysError(_("can't find length of file on file descriptor %d"), m_fd);
return ofsInvalid;
}
else
return FALSE;
case -1:
- wxLogSysError("can't determine if the end of file is reached on "
- "descriptor %d", m_fd);
+ wxLogSysError(_("can't determine if the end of file is reached on "
+ "descriptor %d"), m_fd);
break;
default:
m_file.Close();
if ( wxFile::Exists(m_strName) && remove(m_strName) != 0 ) {
- wxLogSysError("can't remove file '%s'", m_strName.c_str());
+ wxLogSysError(_("can't remove file '%s'"), m_strName.c_str());
return FALSE;
}
if ( rename(m_strTemp, m_strName) != 0 ) {
- wxLogSysError("can't commit changes to file '%s'", m_strName.c_str());
+ wxLogSysError(_("can't commit changes to file '%s'"), m_strName.c_str());
return FALSE;
}
{
m_file.Close();
if ( remove(m_strTemp) != 0 )
- wxLogSysError("can't remove temporary file '%s'", m_strTemp.c_str());
+ wxLogSysError(_("can't remove temporary file '%s'"), m_strTemp.c_str());
}
const char *szHome = getenv("HOME");
if ( szHome == NULL ) {
// we're homeless...
- wxLogWarning("can't find user's HOME, using current directory.");
+ wxLogWarning(_("can't find user's HOME, using current directory."));
szHome = ".";
}
str << szHome << "/." << szFile;
SetRootPath();
}
else
- wxLogWarning("Can't open global configuration file '%s'.",
+ wxLogWarning(_("can't open global configuration file '%s'."),
strGlobal.c_str());
}
}
SetRootPath();
}
else
- wxLogWarning("Can't open user configuration file '%s'.",
+ wxLogWarning(_("can't open user configuration file '%s'."),
strLocal.c_str());
}
}
}
if ( *pEnd != ']' ) {
- wxLogError("file '%s': unexpected character %c at line %d.",
+ wxLogError(_("file '%s': unexpected character %c at line %d."),
file.GetName(), *pEnd, n + 1);
continue; // skip this line
}
break;
default:
- wxLogWarning("file '%s', line %d: '%s' ignored after group header.",
+ wxLogWarning(_("file '%s', line %d: '%s' "
+ "ignored after group header."),
file.GetName(), n + 1, pEnd);
bCont = FALSE;
}
pEnd++;
if ( *pEnd++ != '=' ) {
- wxLogError("file '%s', line %d: '=' expected.", file.GetName(), n + 1);
+ wxLogError(_("file '%s', line %d: '=' expected."),
+ file.GetName(), n + 1);
}
else {
ConfigEntry *pEntry = m_pCurrentGroup->FindEntry(strKey);
else {
if ( bLocal && pEntry->IsImmutable() ) {
// immutable keys can't be changed by user
- wxLogWarning("file '%s', line %d: value for immutable key '%s' ignored.",
+ wxLogWarning(_("file '%s', line %d: value for "
+ "immutable key '%s' ignored."),
file.GetName(), n + 1, strKey.c_str());
continue;
}
// (c) key from global file now found in local one
// which is exactly what we want.
else if ( !bLocal || pEntry->IsLocal() ) {
- wxLogWarning("file '%s', line %d: key '%s' was first found at line %d.",
+ wxLogWarning(_("file '%s', line %d: key '%s' was first "
+ "found at line %d."),
file.GetName(), n + 1, strKey.c_str(), pEntry->Line());
if ( bLocal )
wxTempFile file(m_strLocalFile);
if ( !file.IsOpened() ) {
- wxLogError("Can't open user configuration file.");
+ wxLogError(_("can't open user configuration file."));
return FALSE;
}
// write all strings to file
for ( LineList *p = m_linesHead; p != NULL; p = p->Next() ) {
if ( !file.Write(p->Text() + wxTextFile::GetEOL()) ) {
- wxLogError("Can't write user configuration file.");
+ wxLogError(_("can't write user configuration file."));
return FALSE;
}
}
Init();
if ( remove(szFile) == -1 )
- wxLogSysError("Can't delete user configuration file '%s'", szFile);
+ wxLogSysError(_("can't delete user configuration file '%s'"), szFile);
szFile = m_strGlobalFile;
if ( remove(szFile) )
- wxLogSysError("Can't delete system configuration file '%s'", szFile);
+ wxLogSysError(_("can't delete system configuration file '%s'"), szFile);
return TRUE;
}
void wxFileConfig::ConfigEntry::SetLine(LineList *pLine)
{
if ( m_pLine != NULL ) {
- wxLogWarning("Entry '%s' appears more than once in group '%s'",
+ wxLogWarning(_("entry '%s' appears more than once in group '%s'"),
Name().c_str(), m_pParent->GetFullName().c_str());
}
void wxFileConfig::ConfigEntry::SetValue(const wxString& strValue, bool bUser)
{
if ( bUser && IsImmutable() ) {
- wxLogWarning("Attempt to change immutable key '%s' ignored.",
+ wxLogWarning(_("attempt to change immutable key '%s' ignored."),
Name().c_str());
return;
}
strResult += '\n';
break;
+ case 'r':
+ strResult += '\r';
+ break;
+
case 't':
strResult += '\t';
break;
else {
if ( str[n] != '"' || !bQuoted )
strResult += str[n];
- else if ( n != str.Len() - 1 )
- wxLogWarning("unexpected \" at position %d in '%s'.", n, str.c_str());
+ else if ( n != str.Len() - 1 ) {
+ wxLogWarning(_("unexpected \" at position %d in '%s'."),
+ n, str.c_str());
+ }
//else: it's the last quote of a quoted string, ok
}
}
c = 'n';
break;
+ case '\r':
+ c = 'r';
+ break;
+
case '\t':
c = 't';
break;
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
-// declaration
+// declarations
// ============================================================================
// ----------------------------------------------------------------------------
#pragma hdrstop
#endif
-// standard headers
-#include <locale.h>
-
// wxWindows
-#include "wx/defs.h"
-#include "wx/string.h"
+#ifndef WX_PRECOMP
+ #include "wx/defs.h"
+ #include "wx/string.h"
+#endif //WX_PRECOMP
+
#include "wx/intl.h"
#include "wx/file.h"
#include "wx/log.h"
#include "wx/utils.h"
+// standard headers
+#include <locale.h>
#include <stdlib.h>
// ----------------------------------------------------------------------------
#define MSGCATALOG_EXTENSION ".mo"
// ----------------------------------------------------------------------------
-// global functions
+// global functions (private to this module)
// ----------------------------------------------------------------------------
// suppress further error messages about missing translations
// (if you don't have one catalog file, you wouldn't like to see the
// error message for each string in it, so normally it's given only
// once)
-void wxSuppressTransErrors();
+static void wxSuppressTransErrors();
// restore the logging
-void wxRestoreTransErrors();
+static void wxRestoreTransErrors();
// get the current state
-bool wxIsLoggingTransErrors();
+static bool wxIsLoggingTransErrors();
-// get the current locale object (## may be NULL!)
-extern wxLocale *wxSetLocale(wxLocale *pLocale);
+// get the current locale object (@@ may be NULL!)
+static wxLocale *wxSetLocale(wxLocale *pLocale);
// ----------------------------------------------------------------------------
// wxMsgCatalog corresponds to one disk-file message catalog.
DELETEA(m_pszName);
}
+// a helper class which suppresses all translation error messages
+// from the moment of it's creation until it's destruction
class NoTransErr
{
public:
// open disk file and read in it's contents
bool wxMsgCatalog::Load(const char *szDirPrefix, const char *szName)
{
- // search order (assume language 'foo') is
- // 1) $LC_PATH/foo/LC_MESSAGES (if LC_PATH set)
- // 2) ./foo/LC_MESSAGES
- // 3) ./foo
+ // search order (assume language 'lang') is
+ // 1) $LC_PATH/lang/LC_MESSAGES (if LC_PATH set)
+ // 2) ./lang/LC_MESSAGES
+ // 3) ./lang
// 4) . (Added by JACS)
//
// under UNIX we search also in:
- // 5) /usr/share/locale/foo/LC_MESSAGES (Linux)
- // 6) /usr/lib/locale/foo/LC_MESSAGES (Solaris)
+ // 5) /usr/share/locale/lang/LC_MESSAGES (Linux)
+ // 6) /usr/lib/locale/lang/LC_MESSAGES (Solaris)
#define MSG_PATH FILE_SEP_PATH + "LC_MESSAGES" PATH_SEP
wxString strPath("");
// NB: '<<' is unneeded between too literal strings:
// they are concatenated at compile time
- strPath += "./" + wxString(szDirPrefix) + MSG_PATH // (2)
- + "./" + szDirPrefix + FILE_SEP_PATH + PATH_SEP // (3)
- + "." + PATH_SEP
+ strPath << "./" << wxString(szDirPrefix) + MSG_PATH // (2)
+ << "./" << szDirPrefix << FILE_SEP_PATH << PATH_SEP // (3)
+ << "." << PATH_SEP // (4)
#ifdef __UNIX__
- "/usr/share/locale/" + szDirPrefix + MSG_PATH // (5)
- "/usr/lib/locale/" + szDirPrefix + MSG_PATH // (6)
+ "/usr/share/locale/" << szDirPrefix << MSG_PATH // (5)
+ "/usr/lib/locale/" << szDirPrefix << MSG_PATH // (6)
#endif //UNIX
;
// (we're using an object because we have several return paths)
NoTransErr noTransErr;
- wxLogVerbose("looking for catalog '%s' in path '%s'.",
- szName, strPath.c_str());
+ wxLogVerbose(_("looking for catalog '%s' in path '%s'..."),
+ szName, strPath.c_str());
wxString strFullName;
if ( !wxFindFileInPath(&strFullName, strPath, strFile) ) {
- wxLogWarning("catalog file for domain '%s' not found.", szName);
+ wxLogWarning(_("catalog file for domain '%s' not found."), szName);
return FALSE;
}
// open file
- wxLogVerbose("using catalog '%s' from '%s'.",
- szName, strFullName.c_str());
+ wxLogVerbose(_("catalog '%s' found in '%s'."), szName, strFullName.c_str());
+ // declare these vars here because we're using goto further down
+ bool bValid;
+ off_t nSize;
+
wxFile fileMsg(strFullName);
if ( !fileMsg.IsOpened() )
- return FALSE;
+ goto error;
// get the file size
- off_t nSize = fileMsg.Length();
+ nSize = fileMsg.Length();
if ( nSize == ofsInvalid )
- return FALSE;
+ goto error;
// read the whole file in memory
m_pData = new uint8[nSize];
if ( fileMsg.Read(m_pData, nSize) != nSize ) {
DELETEA(m_pData);
m_pData = NULL;
- return FALSE;
+ goto error;
}
// examine header
- bool bValid = (size_t)nSize > sizeof(wxMsgCatalogHeader);
+ bValid = (size_t)nSize > sizeof(wxMsgCatalogHeader);
wxMsgCatalogHeader *pHeader;
if ( bValid ) {
if ( !bValid ) {
// 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());
DELETEA(m_pData);
m_pData = NULL;
// initialize
m_numStrings = Swap(pHeader->numStrings);
- m_pOrigTable = (wxMsgTableEntry *)(m_pData +
- Swap(pHeader->ofsOrigTable));
- m_pTransTable = (wxMsgTableEntry *)(m_pData +
- Swap(pHeader->ofsTransTable));
+ m_pOrigTable = (wxMsgTableEntry *)(m_pData + Swap(pHeader->ofsOrigTable));
+ m_pTransTable = (wxMsgTableEntry *)(m_pData + Swap(pHeader->ofsTransTable));
m_nHashSize = Swap(pHeader->nHashSize);
m_pHashTable = (uint32 *)(m_pData + Swap(pHeader->ofsHashTable));
// everything is fine
return TRUE;
+
+error:
+ wxLogError(_("error opening message catalog '%s', not loaded."),
+ strFullName.c_str());
+ return FALSE;
}
// search for a string
szLocale = szName;
m_pszOldLocale = setlocale(LC_ALL, szLocale);
if ( m_pszOldLocale == NULL )
- wxLogError("locale '%s' can not be set.", szLocale);
+ wxLogError(_("locale '%s' can not be set."), szLocale);
// the short name will be used to look for catalog files as well,
// so we need something here
if ( m_strShort.IsEmpty() ) {
- // #### I don't know how these 2 letter abbreviations are formed,
+ // @@@@ I don't know how these 2 letter abbreviations are formed,
// this wild guess is almost surely wrong
m_strShort = wxToLower(szLocale[0]) + wxToLower(szLocale[1]);
}
wxSuppressTransErrors();
if ( szDomain != NULL )
- wxLogWarning("string '%s' not found in domain '%s' for locale '%s'.",
- szOrigString, szDomain, m_strLocale.c_str());
+ wxLogWarning(_("string '%s' not found in domain '%s'"
+ " for locale '%s'."),
+ szOrigString, szDomain, m_strLocale.c_str());
else
- wxLogWarning("string '%s' not found in locale '%s'.",
- szOrigString, m_strLocale.c_str());
+ wxLogWarning(_("string '%s' not found in locale '%s'."),
+ szOrigString, m_strLocale.c_str());
}
return szOrigString;
// the current locale object
wxLocale *g_pLocale = NULL;
-wxLocale *wxGetLocale()
-{
- return g_pLocale;
-}
-
wxLocale *wxSetLocale(wxLocale *pLocale)
{
wxLocale *pOld = g_pLocale;
static char s_szBuf[LOG_BUFFER_SIZE];
// generic log function
-void wxLogGeneric(wxLogLevel level, wxTString strFormat, ...)
+void wxLogGeneric(wxLogLevel level, const char *szFormat, ...)
{
if ( wxLog::GetActiveTarget() != NULL ) {
va_list argptr;
- va_start(argptr, strFormat);
- vsprintf(s_szBuf, strFormat, argptr);
+ va_start(argptr, szFormat);
+ vsprintf(s_szBuf, szFormat, argptr);
va_end(argptr);
wxLog::OnLog(level, s_szBuf);
}
#define IMPLEMENT_LOG_FUNCTION(level) \
- void wxLog##level(wxTString strFormat, ...) \
+ void wxLog##level(const char *szFormat, ...) \
{ \
if ( wxLog::GetActiveTarget() != NULL ) { \
va_list argptr; \
- va_start(argptr, strFormat); \
- vsprintf(s_szBuf, strFormat, argptr); \
+ va_start(argptr, szFormat); \
+ vsprintf(s_szBuf, szFormat, argptr); \
va_end(argptr); \
\
wxLog::OnLog(wxLOG_##level, s_szBuf); \
IMPLEMENT_LOG_FUNCTION(Status)
// same as info, but only if 'verbose' mode is on
-void wxLogVerbose(wxTString strFormat, ...)
+void wxLogVerbose(const char *szFormat, ...)
{
wxLog *pLog = wxLog::GetActiveTarget();
if ( pLog != NULL && pLog->GetVerbose() ) {
va_list argptr;
- va_start(argptr, strFormat);
- vsprintf(s_szBuf, strFormat, argptr);
+ va_start(argptr, szFormat);
+ vsprintf(s_szBuf, szFormat, argptr);
va_end(argptr);
wxLog::OnLog(wxLOG_Info, s_szBuf);
wxLog::OnLog(wxLOG_Error, s_szBuf);
}
-void WXDLLEXPORT wxLogSysError(wxTString strFormat, ...)
+void WXDLLEXPORT wxLogSysError(const char *szFormat, ...)
{
va_list argptr;
- va_start(argptr, strFormat);
- vsprintf(s_szBuf, strFormat, argptr);
+ va_start(argptr, szFormat);
+ vsprintf(s_szBuf, szFormat, argptr);
va_end(argptr);
wxLogSysErrorHelper(wxSysErrorCode());
}
-void WXDLLEXPORT wxLogSysError(long lErrCode, wxTString strFormat, ...)
+void WXDLLEXPORT wxLogSysError(long lErrCode, const char *szFormat, ...)
{
va_list argptr;
- va_start(argptr, strFormat);
- vsprintf(s_szBuf, strFormat, argptr);
+ va_start(argptr, szFormat);
+ vsprintf(s_szBuf, szFormat, argptr);
va_end(argptr);
wxLogSysErrorHelper(lErrCode);
// (don't prepend "Debug" here: it will go to debug window anyhow)
::OutputDebugString(str + szString + "\n\r");
#endif //Win32
- DoLogString(str << (level == wxLOG_Trace ? "Trace" : "Debug")
+ DoLogString(str << (level == wxLOG_Trace ? _("Trace") : _("Debug"))
<< ": " << szString);
#endif
OutputDebugString("\n\r");
#else //!WIN32
// send them to stderr
- fprintf(stderr, level == wxLOG_Trace ? "Trace: %s\n"
- : "Debug: %s\n", szString);
+ fprintf(stderr, "%s: %s\n",
+ level == wxLOG_Trace ? _("Trace") : _("Debug"), szString);
fflush(stderr);
#endif // WIN32
#endif
case wxLOG_FatalError:
// show this one immediately
- wxMessageBox(szString, "Fatal error", wxICON_HAND);
+ wxMessageBox(szString, _("Fatal error"), wxICON_HAND);
break;
case wxLOG_Error:
bOk = file.Close();
if ( !bOk ) {
- wxLogError("Can't save log contents to file.");
+ wxLogError(_("Can't save log contents to file."));
return;
}
}
m_pTextCtrl->Clear();
}
-wxLogWindow::wxLogWindow(const wxTString& strTitle, bool bShow)
+wxLogWindow::wxLogWindow(const char *szTitle, bool bShow)
{
m_pOldLog = wxLog::GetActiveTarget();
- m_pLogFrame = new wxLogFrame(strTitle);
+ m_pLogFrame = new wxLogFrame(szTitle);
if ( bShow )
m_pLogFrame->Show(TRUE);
#ifdef __WXDEBUG__
+void Trap()
+{
+ #ifdef __WXMSW__
+ DebugBreak();
+ #else // Unix
+ raise(SIGTRAP);
+ #endif // Win/Unix
+}
+
// this function is called when an assert fails
void wxOnAssert(const char *szFile, int nLine, const char *szMsg)
{
// this variable can be set to true to suppress "assert failure" messages
- static s_bNoAsserts = FALSE;
+ static bool s_bNoAsserts = FALSE;
+ static bool s_bInAssert = FALSE;
+
+ if ( s_bInAssert ) {
+ // He-e-e-e-elp!! we're trapped in endless loop
+ Trap();
+ }
+
+ s_bInAssert = TRUE;
char szBuf[LOG_BUFFER_SIZE];
sprintf(szBuf, _("Assert failed in file %s at line %d"), szFile, nLine);
switch ( wxMessageBox(szBuf, _("Debug"),
wxYES_NO | wxCANCEL | wxICON_STOP ) ) {
case wxYES:
- #ifdef __WXMSW__
- DebugBreak();
- #else // Unix
- raise(SIGTRAP);
- #endif // Win/Unix
+ Trap();
break;
case wxCANCEL:
//case wxNO: nothing to do
}
}
+
+ s_bInAssert = FALSE;
}
#endif //WXDEBUG
// interpret the results (@@ far from being even 50% fool proof)
if ( nDos + nUnix + nMac == 0 ) {
// no newlines at all
- wxLogWarning("'%s' is probably a binary file.", m_strFile.c_str());
+ wxLogWarning(_("'%s' is probably a binary file."), m_strFile.c_str());
}
else {
#define GREATER_OF(t1, t2) n##t1 == n##t2 ? typeDefault \
wxTempFile fileTmp(m_strFile);
if ( !fileTmp.IsOpened() ) {
- wxLogError("can't write file '%s' to disk.", m_strFile.c_str());
+ wxLogError(_("can't write file '%s' to disk."), m_strFile.c_str());
return FALSE;
}