many miscellaneous fixes

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1998 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-03-29 16:46:18 +00:00
parent 8826f46f0d
commit 0fb67cd196
7 changed files with 1826 additions and 1732 deletions

View File

@@ -9,37 +9,45 @@
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__
#pragma implementation "docview.h"
#pragma implementation "docview.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/defs.h"
#include "wx/defs.h"
#endif
#if wxUSE_DOC_VIEW_ARCHITECTURE
#ifndef WX_PRECOMP
#include "wx/string.h"
#include "wx/utils.h"
#include "wx/app.h"
#include "wx/dc.h"
#include "wx/dialog.h"
#include "wx/menu.h"
#include "wx/list.h"
#include "wx/filedlg.h"
#include <wx/intl.h>
#include "wx/string.h"
#include "wx/utils.h"
#include "wx/app.h"
#include "wx/dc.h"
#include "wx/dialog.h"
#include "wx/menu.h"
#include "wx/list.h"
#include "wx/filedlg.h"
#include <wx/intl.h>
#endif
#ifdef __WXGTK__
#include "wx/mdi.h"
#include "wx/mdi.h"
#endif
#include "wx/msgdlg.h"
@@ -59,43 +67,69 @@
#include <fstream>
#endif
// ----------------------------------------------------------------------------
// wxWindows macros
// ----------------------------------------------------------------------------
#if !USE_SHARED_LIBRARY
IMPLEMENT_ABSTRACT_CLASS(wxDocument, wxEvtHandler)
IMPLEMENT_ABSTRACT_CLASS(wxView, wxEvtHandler)
IMPLEMENT_ABSTRACT_CLASS(wxDocTemplate, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxDocManager, wxEvtHandler)
IMPLEMENT_CLASS(wxDocChildFrame, wxFrame)
IMPLEMENT_CLASS(wxDocParentFrame, wxFrame)
#if wxUSE_PRINTING_ARCHITECTURE
IMPLEMENT_DYNAMIC_CLASS(wxDocPrintout, wxPrintout)
#endif
IMPLEMENT_CLASS(wxCommand, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxCommandProcessor, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxFileHistory, wxObject)
// IMPLEMENT_DYNAMIC_CLASS(wxPrintInfo, wxObject)
IMPLEMENT_ABSTRACT_CLASS(wxDocument, wxEvtHandler)
IMPLEMENT_ABSTRACT_CLASS(wxView, wxEvtHandler)
IMPLEMENT_ABSTRACT_CLASS(wxDocTemplate, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxDocManager, wxEvtHandler)
IMPLEMENT_CLASS(wxDocChildFrame, wxFrame)
IMPLEMENT_CLASS(wxDocParentFrame, wxFrame)
#if wxUSE_PRINTING_ARCHITECTURE
IMPLEMENT_DYNAMIC_CLASS(wxDocPrintout, wxPrintout)
#endif
IMPLEMENT_CLASS(wxCommand, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxCommandProcessor, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxFileHistory, wxObject)
#endif
/*
* Definition of wxDocument
*/
// ----------------------------------------------------------------------------
// function prototypes
// ----------------------------------------------------------------------------
static inline wxString FindExtension(const char *path);
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// local functions
// ----------------------------------------------------------------------------
static wxString FindExtension(const char *path)
{
wxString ext;
wxSplitPath(path, NULL, NULL, &ext);
// VZ: extensions are considered not case sensitive - is this really a good
// idea?
return ext.MakeLower();
}
// ----------------------------------------------------------------------------
// Definition of wxDocument
// ----------------------------------------------------------------------------
wxDocument::wxDocument(wxDocument *parent)
{
m_documentModified=FALSE;
m_documentFile="";
m_documentTitle="";
m_documentParent=parent;
m_documentModified = FALSE;
m_documentParent = parent;
m_documentTemplate = (wxDocTemplate *) NULL;
m_documentTypeName = "";
m_savedYet = FALSE;
}
bool wxDocument::DeleteContents(void)
bool wxDocument::DeleteContents()
{
return TRUE;
}
wxDocument::~wxDocument(void)
wxDocument::~wxDocument()
{
DeleteContents();
@@ -104,14 +138,13 @@ wxDocument::~wxDocument(void)
GetDocumentManager()->RemoveDocument(this);
// Not safe to do here, since it'll
// invoke virtual view functions expecting to see
// valid derived objects: and by the time we get
// here, we've called destructors higher up.
// DeleteAllViews();
// Not safe to do here, since it'll invoke virtual view functions
// expecting to see valid derived objects: and by the time we get here,
// we've called destructors higher up.
//DeleteAllViews();
}
bool wxDocument::Close(void)
bool wxDocument::Close()
{
if (OnSaveModified())
return OnCloseDocument();
@@ -119,16 +152,16 @@ bool wxDocument::Close(void)
return FALSE;
}
bool wxDocument::OnCloseDocument(void)
bool wxDocument::OnCloseDocument()
{
DeleteContents();
Modify(FALSE);
return TRUE;
}
// Note that this implicitly deletes the document when
// the last view is deleted.
bool wxDocument::DeleteAllViews(void)
// Note that this implicitly deletes the document when the last view is
// deleted.
bool wxDocument::DeleteAllViews()
{
wxNode *node = m_documentViews.First();
while (node)
@@ -157,7 +190,7 @@ wxDocManager *wxDocument::GetDocumentManager(void) const
return m_documentTemplate->GetDocumentManager();
}
bool wxDocument::OnNewDocument(void)
bool wxDocument::OnNewDocument()
{
if (!OnSaveModified())
return FALSE;
@@ -175,7 +208,7 @@ bool wxDocument::OnNewDocument(void)
return TRUE;
}
bool wxDocument::Save(void)
bool wxDocument::Save()
{
bool ret = FALSE;
@@ -189,7 +222,7 @@ bool wxDocument::Save(void)
return ret;
}
bool wxDocument::SaveAs(void)
bool wxDocument::SaveAs()
{
wxDocTemplate *docTemplate = GetDocumentTemplate();
if (!docTemplate)
@@ -237,7 +270,7 @@ bool wxDocument::SaveAs(void)
bool wxDocument::OnSaveDocument(const wxString& file)
{
if (file == "")
if ( !file )
return FALSE;
wxString msgTitle;
@@ -301,19 +334,19 @@ bool wxDocument::OnOpenDocument(const wxString& file)
istream& wxDocument::LoadObject(istream& stream)
{
// wxObject::LoadObject(stream);
// wxObject::LoadObject(stream);
return stream;
}
ostream& wxDocument::SaveObject(ostream& stream)
{
// wxObject::SaveObject(stream);
// wxObject::SaveObject(stream);
return stream;
}
bool wxDocument::Revert(void)
bool wxDocument::Revert()
{
return FALSE;
}
@@ -348,13 +381,13 @@ wxWindow *wxDocument::GetDocumentWindow(void) const
return wxTheApp->GetTopWindow();
}
wxCommandProcessor *wxDocument::OnCreateCommandProcessor(void)
wxCommandProcessor *wxDocument::OnCreateCommandProcessor()
{
return new wxCommandProcessor;
}
// TRUE if safe to close
bool wxDocument::OnSaveModified(void)
bool wxDocument::OnSaveModified()
{
if (IsModified())
{
@@ -419,7 +452,7 @@ bool wxDocument::OnCreate(const wxString& WXUNUSED(path), long flags)
// Called after a view is added or removed.
// The default implementation deletes the document if
// there are no more views.
void wxDocument::OnChangedViewList(void)
void wxDocument::OnChangedViewList()
{
if (m_documentViews.Number() == 0)
{
@@ -457,21 +490,20 @@ void wxDocument::SetFilename(const wxString& filename, bool notifyViews)
}
}
/*
* Document view
*/
// ----------------------------------------------------------------------------
// Document view
// ----------------------------------------------------------------------------
wxView::wxView()
{
// SetDocument(doc);
// SetDocument(doc);
m_viewDocument = (wxDocument*) NULL;
m_viewTypeName = "";
m_viewFrame = (wxFrame *) NULL;
}
wxView::~wxView(void)
wxView::~wxView()
{
GetDocumentManager()->ActivateView(this, FALSE, TRUE);
m_viewDocument->RemoveView(this);
@@ -499,7 +531,7 @@ void wxView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint))
{
}
void wxView::OnChangeFilename(void)
void wxView::OnChangeFilename()
{
if (GetFrame() && GetDocument())
{
@@ -540,21 +572,26 @@ bool wxView::OnClose(bool WXUNUSED(deleteWindow))
}
#if wxUSE_PRINTING_ARCHITECTURE
wxPrintout *wxView::OnCreatePrintout(void)
wxPrintout *wxView::OnCreatePrintout()
{
return new wxDocPrintout(this);
}
#endif
// ----------------------------------------------------------------------------
// wxDocTemplate
// ----------------------------------------------------------------------------
/*
* wxDocTemplate
*/
wxDocTemplate::wxDocTemplate(wxDocManager *manager, const wxString& descr,
const wxString& filter, const wxString& dir, const wxString& ext,
const wxString& docTypeName, const wxString& viewTypeName,
wxClassInfo *docClassInfo, wxClassInfo *viewClassInfo, long flags)
wxDocTemplate::wxDocTemplate(wxDocManager *manager,
const wxString& descr,
const wxString& filter,
const wxString& dir,
const wxString& ext,
const wxString& docTypeName,
const wxString& viewTypeName,
wxClassInfo *docClassInfo,
wxClassInfo *viewClassInfo,
long flags)
{
m_documentManager = manager;
m_flags = flags;
@@ -571,13 +608,12 @@ wxDocTemplate::wxDocTemplate(wxDocManager *manager, const wxString& descr,
m_viewClassInfo = viewClassInfo;
}
wxDocTemplate::~wxDocTemplate(void)
wxDocTemplate::~wxDocTemplate()
{
m_documentManager->DisassociateTemplate(this);
}
// Tries to dynamically construct an object of the right
// class.
// Tries to dynamically construct an object of the right class.
wxDocument *wxDocTemplate::CreateDocument(const wxString& path, long flags)
{
if (!m_docClassInfo)
@@ -614,6 +650,10 @@ wxView *wxDocTemplate::CreateView(wxDocument *doc, long flags)
}
}
// ----------------------------------------------------------------------------
// wxDocManager
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxDocManager, wxEvtHandler)
EVT_MENU(wxID_OPEN, wxDocManager::OnFileOpen)
EVT_MENU(wxID_CLOSE, wxDocManager::OnFileClose)
@@ -639,7 +679,7 @@ wxDocManager::wxDocManager(long flags, bool initialize)
Initialize();
}
wxDocManager::~wxDocManager(void)
wxDocManager::~wxDocManager()
{
Clear();
if (m_fileHistory)
@@ -681,13 +721,13 @@ bool wxDocManager::Clear(bool force)
return TRUE;
}
bool wxDocManager::Initialize(void)
bool wxDocManager::Initialize()
{
m_fileHistory = OnCreateFileHistory();
return TRUE;
}
wxFileHistory *wxDocManager::OnCreateFileHistory(void)
wxFileHistory *wxDocManager::OnCreateFileHistory()
{
return new wxFileHistory;
}
@@ -1027,10 +1067,12 @@ void wxDocManager::AddFileToHistory(const wxString& file)
wxString wxDocManager::GetHistoryFile(int i) const
{
wxString histFile;
if (m_fileHistory)
return wxString(m_fileHistory->GetHistoryFile(i));
else
return wxString("");
histFile = m_fileHistory->GetHistoryFile(i);
return histFile;
}
void wxDocManager::FileHistoryUseMenu(wxMenu *menu)
@@ -1079,36 +1121,12 @@ int wxDocManager::GetNoHistoryFiles(void) const
return 0;
}
static char *FindExtension(char *path)
{
static char ext[10];
int len = strlen(path);
if (path)
{
int i = 0;
for (i = (len-1); i > 0; i --)
if (path[i] == '.')
break;
if (path[i] == '.')
{
int j;
for (j = i+1; j < len; j++)
ext[(int)(j-(i+1))] = (char)wxToLower(path[j]); // NOTE Should not use tolower under UNIX
ext[j-(i+1)] = 0;
return ext;
}
else
return (char *) NULL;
}
else return (char *) NULL;
}
// Given a path, try to find a matching template. Won't
// always work, of course.
// Given a path, try to find a matching template. Won't always work, of
// course.
wxDocTemplate *wxDocManager::FindTemplateForPath(const wxString& path)
{
char *theExt = FindExtension((char *)(const char *)path);
wxString theExt = FindExtension(path);
if (!theExt)
return (wxDocTemplate *) NULL;
wxDocTemplate *theTemplate = (wxDocTemplate *) NULL;
@@ -1135,13 +1153,11 @@ wxDocTemplate *wxDocManager::FindTemplateForPath(const wxString& path)
// dialog or implement own; OR match the extension to the
// template extension.
#ifdef __WXMSW__
wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
int noTemplates, wxString& path, long WXUNUSED(flags), bool WXUNUSED(save))
#else
wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **WXUNUSED(templates),
int WXUNUSED(noTemplates), wxString& path, long WXUNUSED(flags), bool WXUNUSED(save))
#endif
int noTemplates,
wxString& path,
long WXUNUSED(flags),
bool WXUNUSED(save))
{
// We can only have multiple filters in Windows
#ifdef __WXMSW__
@@ -1171,7 +1187,7 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **WXUNUSED(templat
if (!pathTmp.IsEmpty())
{
path = pathTmp;
char *theExt = FindExtension((char *)(const char *)path);
wxString theExt = FindExtension(path);
if (!theExt)
return (wxDocTemplate *) NULL;
@@ -1207,7 +1223,7 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **WXUNUSED(templat
}
else
return (wxDocTemplate *) NULL;
#endif
#endif // 0
}
wxDocTemplate *wxDocManager::SelectDocumentType(wxDocTemplate **templates,
@@ -1301,14 +1317,14 @@ void wxDocManager::ActivateView(wxView *view, bool activate, bool WXUNUSED(delet
// don't reset the current view because we may be going to
// a window without a view.
// WHAT DID I MEAN BY THAT EXACTLY?
/*
/*
if (deleting)
{
if (m_currentView == view)
m_currentView = NULL;
}
else
*/
*/
{
if (activate)
m_currentView = view;
@@ -1317,18 +1333,25 @@ void wxDocManager::ActivateView(wxView *view, bool activate, bool WXUNUSED(delet
}
}
/*
* Default document child frame
*/
// ----------------------------------------------------------------------------
// Default document child frame
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxDocChildFrame, wxFrame)
EVT_ACTIVATE(wxDocChildFrame::OnActivate)
EVT_CLOSE(wxDocChildFrame::OnCloseWindow)
END_EVENT_TABLE()
wxDocChildFrame::wxDocChildFrame(wxDocument *doc, wxView *view, wxFrame *frame, wxWindowID id, const wxString& title,
const wxPoint& pos, const wxSize& size, long style, const wxString& name):
wxFrame(frame, id, title, pos, size, style, name)
wxDocChildFrame::wxDocChildFrame(wxDocument *doc,
wxView *view,
wxFrame *frame,
wxWindowID id,
const wxString& title,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
: wxFrame(frame, id, title, pos, size, style, name)
{
m_childDocument = doc;
m_childView = view;
@@ -1336,7 +1359,7 @@ wxDocChildFrame::wxDocChildFrame(wxDocument *doc, wxView *view, wxFrame *frame,
view->SetFrame(this);
}
wxDocChildFrame::~wxDocChildFrame(void)
wxDocChildFrame::~wxDocChildFrame()
{
}
@@ -1392,9 +1415,9 @@ void wxDocChildFrame::OnCloseWindow(wxCloseEvent& event)
event.Veto();
}
/*
* Default parent frame
*/
// ----------------------------------------------------------------------------
// Default parent frame
// ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(wxDocParentFrame, wxFrame)
EVT_MENU(wxID_EXIT, wxDocParentFrame::OnExit)
@@ -1402,9 +1425,15 @@ BEGIN_EVENT_TABLE(wxDocParentFrame, wxFrame)
EVT_CLOSE(wxDocParentFrame::OnCloseWindow)
END_EVENT_TABLE()
wxDocParentFrame::wxDocParentFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title,
const wxPoint& pos, const wxSize& size, long style, const wxString& name):
wxFrame(frame, id, title, pos, size, style, name)
wxDocParentFrame::wxDocParentFrame(wxDocManager *manager,
wxFrame *frame,
wxWindowID id,
const wxString& title,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
: wxFrame(frame, id, title, pos, size, style, name)
{
m_docManager = manager;
}
@@ -1445,8 +1474,8 @@ void wxDocParentFrame::OnCloseWindow(wxCloseEvent& event)
#if wxUSE_PRINTING_ARCHITECTURE
wxDocPrintout::wxDocPrintout(wxView *view, const wxString& title):
wxPrintout(WXSTRINGCAST title)
wxDocPrintout::wxDocPrintout(wxView *view, const wxString& title)
: wxPrintout(WXSTRINGCAST title)
{
m_printoutView = view;
}
@@ -1508,11 +1537,11 @@ void wxDocPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, in
*selPageTo = 1;
}
#endif
#endif // wxUSE_PRINTING_ARCHITECTURE
/*
* Command processing framework
*/
// ----------------------------------------------------------------------------
// Command processing framework
// ----------------------------------------------------------------------------
wxCommand::wxCommand(bool canUndoIt, const wxString& name)
{
@@ -1520,7 +1549,7 @@ wxCommand::wxCommand(bool canUndoIt, const wxString& name)
m_commandName = name;
}
wxCommand::~wxCommand(void)
wxCommand::~wxCommand()
{
}
@@ -1532,7 +1561,7 @@ wxCommandProcessor::wxCommandProcessor(int maxCommands)
m_commandEditMenu = (wxMenu *) NULL;
}
wxCommandProcessor::~wxCommandProcessor(void)
wxCommandProcessor::~wxCommandProcessor()
{
ClearCommands();
}
@@ -1576,7 +1605,7 @@ bool wxCommandProcessor::Submit(wxCommand *command, bool storeIt)
return success;
}
bool wxCommandProcessor::Undo(void)
bool wxCommandProcessor::Undo()
{
if (m_currentCommand)
{
@@ -1595,7 +1624,7 @@ bool wxCommandProcessor::Undo(void)
return FALSE;
}
bool wxCommandProcessor::Redo(void)
bool wxCommandProcessor::Redo()
{
wxCommand *redoCommand = (wxCommand *) NULL;
wxNode *redoNode = (wxNode *) NULL;
@@ -1647,13 +1676,13 @@ bool wxCommandProcessor::CanRedo(void) const
return FALSE;
}
void wxCommandProcessor::Initialize(void)
void wxCommandProcessor::Initialize()
{
m_currentCommand = m_commands.Last();
SetMenuStrings();
}
void wxCommandProcessor::SetMenuStrings(void)
void wxCommandProcessor::SetMenuStrings()
{
if (m_commandEditMenu)
{
@@ -1713,7 +1742,7 @@ void wxCommandProcessor::SetMenuStrings(void)
}
}
void wxCommandProcessor::ClearCommands(void)
void wxCommandProcessor::ClearCommands()
{
wxNode *node = m_commands.First();
while (node)
@@ -1726,10 +1755,9 @@ void wxCommandProcessor::ClearCommands(void)
m_currentCommand = (wxNode *) NULL;
}
/*
* File history processor
*/
// ----------------------------------------------------------------------------
// File history processor
// ----------------------------------------------------------------------------
wxFileHistory::wxFileHistory(int maxFiles)
{
@@ -1738,7 +1766,7 @@ wxFileHistory::wxFileHistory(int maxFiles)
m_fileHistory = new char *[m_fileMaxFiles];
}
wxFileHistory::~wxFileHistory(void)
wxFileHistory::~wxFileHistory()
{
int i;
for (i = 0; i < m_fileHistoryN; i++)
@@ -1847,7 +1875,7 @@ void wxFileHistory::Save(wxConfigBase& config)
config.Write(buf, wxString(m_fileHistory[i]));
}
}
#endif
#endif // wxUSE_CONFIG
void wxFileHistory::AddFilesToMenu()
{
@@ -1891,25 +1919,10 @@ void wxFileHistory::AddFilesToMenu(wxMenu* menu)
}
}
#if 0
/*
* wxPrintInfo
*/
wxPrintInfo::wxPrintInfo(void)
{
pageNumber = 1;
}
wxPrintInfo::~wxPrintInfo(void)
{
}
#endif
/*
* Permits compatibility with existing file formats and functions
* that manipulate files directly
*/
// ----------------------------------------------------------------------------
// Permits compatibility with existing file formats and functions that
// manipulate files directly
// ----------------------------------------------------------------------------
bool wxTransferFileToStream(const wxString& filename, ostream& stream)
{
@@ -1946,5 +1959,5 @@ bool wxTransferStreamToFile(istream& stream, const wxString& filename)
return TRUE;
}
#endif
// End wxUSE_DOC_VIEW_ARCHITECTURE
#endif // wxUSE_DOC_VIEW_ARCHITECTURE

View File

@@ -274,6 +274,12 @@ bool wxFileExists(const char *pszFileName)
}
*/
bool wxDirExists( const wxString& dir )
{
struct stat st;
return ((stat(dir, &st) != -1) && S_ISDIR(st.st_mode) ? TRUE : FALSE);
}
bool
wxIsAbsolutePath (const wxString& filename)
{
@@ -785,7 +791,7 @@ wxMac2UnixFilename (char *s)
if (*s == ':')
*s = '/';
else
*s = wxToLower (*s); // Case INDEPENDENT
*s = tolower(*s); // Case INDEPENDENT
s++;
}
}
@@ -830,7 +836,7 @@ wxDos2UnixFilename (char *s)
*s = '/';
#ifdef __WXMSW__
else
*s = wxToLower (*s); // Case INDEPENDENT
*s = tolower(*s); // Case INDEPENDENT
#endif
s++;
}

View File

@@ -30,6 +30,7 @@
// standard headers
#include <locale.h>
#include <ctype.h>
// wxWindows
#include "wx/defs.h"
@@ -435,7 +436,7 @@ bool wxLocale::Init(const char *szName,
if ( m_strShort.IsEmpty() ) {
// FIXME I don't know how these 2 letter abbreviations are formed,
// this wild guess is surely wrong
m_strShort = wxToLower(szLocale[0]) + wxToLower(szLocale[1]);
m_strShort = tolower(szLocale[0]) + tolower(szLocale[1]);
}
// save the old locale to be able to restore it later

View File

@@ -75,7 +75,7 @@
// we use a global variable to store the frame pointer for wxLogStatus - bad,
// but it's he easiest way
static wxFrame *gs_pFrame;
static wxFrame *gs_pFrame; // FIXME MT-unsafe
// ============================================================================
// implementation
@@ -92,7 +92,7 @@ static wxFrame *gs_pFrame;
// work!), so we use a static buffer for all log messages
#define LOG_BUFFER_SIZE (4096)
// static buffer for error messages (@@@ MT-unsafe)
// static buffer for error messages (FIXME MT-unsafe)
static char s_szBuf[LOG_BUFFER_SIZE];
// generic log function
@@ -104,7 +104,7 @@ void wxLogGeneric(wxLogLevel level, const char *szFormat, ...)
vsprintf(s_szBuf, szFormat, argptr);
va_end(argptr);
wxLog::OnLog(level, s_szBuf);
wxLog::OnLog(level, s_szBuf, time(NULL));
}
}
@@ -117,7 +117,7 @@ void wxLogGeneric(wxLogLevel level, const char *szFormat, ...)
vsprintf(s_szBuf, szFormat, argptr); \
va_end(argptr); \
\
wxLog::OnLog(wxLOG_##level, s_szBuf); \
wxLog::OnLog(wxLOG_##level, s_szBuf, time(NULL)); \
} \
}
@@ -141,7 +141,7 @@ void wxLogStatus(wxFrame *pFrame, const char *szFormat, ...)
wxASSERT( gs_pFrame == NULL ); // should be reset!
gs_pFrame = pFrame;
wxLog::OnLog(wxLOG_Status, s_szBuf);
wxLog::OnLog(wxLOG_Status, s_szBuf, time(NULL));
gs_pFrame = (wxFrame *) NULL;
}
}
@@ -156,7 +156,7 @@ void wxLogVerbose(const char *szFormat, ...)
vsprintf(s_szBuf, szFormat, argptr);
va_end(argptr);
wxLog::OnLog(wxLOG_Info, s_szBuf);
wxLog::OnLog(wxLOG_Info, s_szBuf, time(NULL));
}
}
@@ -171,10 +171,24 @@ void wxLogVerbose(const char *szFormat, ...)
vsprintf(s_szBuf, szFormat, argptr); \
va_end(argptr); \
\
wxLog::OnLog(wxLOG_##level, s_szBuf); \
wxLog::OnLog(wxLOG_##level, s_szBuf, time(NULL)); \
} \
}
void wxLogTrace(const char *mask, const char *szFormat, ...)
{
wxLog *pLog = wxLog::GetActiveTarget();
if ( pLog != NULL && wxLog::IsAllowedTraceMask(mask) ) {
va_list argptr;
va_start(argptr, szFormat);
vsprintf(s_szBuf, szFormat, argptr);
va_end(argptr);
wxLog::OnLog(wxLOG_Trace, s_szBuf, time(NULL));
}
}
void wxLogTrace(wxTraceMask mask, const char *szFormat, ...)
{
wxLog *pLog = wxLog::GetActiveTarget();
@@ -188,7 +202,7 @@ void wxLogVerbose(const char *szFormat, ...)
vsprintf(s_szBuf, szFormat, argptr);
va_end(argptr);
wxLog::OnLog(wxLOG_Trace, s_szBuf);
wxLog::OnLog(wxLOG_Trace, s_szBuf, time(NULL));
}
}
@@ -209,7 +223,7 @@ void wxLogSysErrorHelper(long lErrCode)
sprintf(szErrMsg, _(" (error %ld: %s)"), lErrCode, wxSysErrorMsg(lErrCode));
strncat(s_szBuf, szErrMsg, WXSIZEOF(s_szBuf) - strlen(s_szBuf));
wxLog::OnLog(wxLOG_Error, s_szBuf);
wxLog::OnLog(wxLOG_Error, s_szBuf, time(NULL));
}
void WXDLLEXPORT wxLogSysError(const char *szFormat, ...)
@@ -246,8 +260,6 @@ wxLog::wxLog()
#else // release
m_bVerbose = FALSE;
#endif // debug/release
m_szTimeFormat = "[%d/%b/%y %H:%M:%S] ";
}
wxLog *wxLog::GetActiveTarget()
@@ -259,15 +271,15 @@ wxLog *wxLog::GetActiveTarget()
if ( !s_bInGetActiveTarget ) {
s_bInGetActiveTarget = TRUE;
#ifdef wxUSE_NOGUI
#ifdef wxUSE_NOGUI
ms_pLogger = new wxLogStderr;
#else
#else
// ask the application to create a log target for us
if ( wxTheApp != NULL )
ms_pLogger = wxTheApp->CreateLogTarget();
else
ms_pLogger = new wxLogStderr;
#endif
#endif
s_bInGetActiveTarget = FALSE;
@@ -292,54 +304,37 @@ wxLog *wxLog::SetActiveTarget(wxLog *pLogger)
return pOldLogger;
}
wxString wxLog::TimeStamp() const
void wxLog::RemoveTraceMask(const wxString& str)
{
int index = ms_aTraceMasks.Index(str);
if ( index != wxNOT_FOUND )
ms_aTraceMasks.Remove((size_t)index);
}
void wxLog::DoLog(wxLogLevel level, const char *szString, time_t t)
{
wxString str;
/* Let's disable TimeStamp and see if anyone complains.
* If not, we'll remove it, since it's probably unlikely
* to ever be used. -- JACS 22/11/98
if ( !IsEmpty(m_szTimeFormat) ) {
char szBuf[128];
time_t timeNow;
struct tm *ptmNow;
time(&timeNow);
ptmNow = localtime(&timeNow);
strftime(szBuf, WXSIZEOF(szBuf), m_szTimeFormat, ptmNow);
str = szBuf;
}
*/
return str;
}
void wxLog::DoLog(wxLogLevel level, const char *szString)
{
// prepend a timestamp if not disabled
wxString str = TimeStamp();
switch ( level ) {
case wxLOG_FatalError:
DoLogString(str << _("Fatal error: ") << szString);
DoLogString(_("Program aborted."));
DoLogString(str << _("Fatal error: ") << szString, t);
DoLogString(_("Program aborted."), t);
Flush();
abort();
break;
case wxLOG_Error:
DoLogString(str << _("Error: ") << szString);
DoLogString(str << _("Error: ") << szString, t);
break;
case wxLOG_Warning:
DoLogString(str << _("Warning: ") << szString);
DoLogString(str << _("Warning: ") << szString, t);
break;
case wxLOG_Info:
case wxLOG_Message:
if ( GetVerbose() )
DoLogString(str + szString);
DoLogString(str + szString, t);
// fall through
case wxLOG_Status:
@@ -348,13 +343,9 @@ void wxLog::DoLog(wxLogLevel level, const char *szString)
case wxLOG_Trace:
case wxLOG_Debug:
#ifdef __WXDEBUG__
// DoLogString(str << (level == wxLOG_Trace ? _("Trace") : _("Debug"))
// << ": " << szString);
// JACS: we don't really want to prefix with 'Debug'. It's just extra
// verbiage.
DoLogString(szString);
#endif
#ifdef __WXDEBUG__
DoLogString(szString, t);
#endif
break;
@@ -363,7 +354,7 @@ void wxLog::DoLog(wxLogLevel level, const char *szString)
}
}
void wxLog::DoLogString(const char *WXUNUSED(szString))
void wxLog::DoLogString(const char *WXUNUSED(szString), time_t t)
{
wxFAIL_MSG("DoLogString must be overriden if it's called.");
}
@@ -385,7 +376,7 @@ wxLogStderr::wxLogStderr(FILE *fp)
m_fp = fp;
}
void wxLogStderr::DoLogString(const char *szString)
void wxLogStderr::DoLogString(const char *szString, time_t t)
{
wxString str(szString);
str << '\n';
@@ -413,11 +404,11 @@ wxLogStream::wxLogStream(ostream *ostr)
m_ostr = ostr;
}
void wxLogStream::DoLogString(const char *szString)
void wxLogStream::DoLogString(const char *szString, time_t t)
{
(*m_ostr) << szString << endl << flush;
}
#endif
#endif // wxUSE_STD_IOSTREAM
#ifndef wxUSE_NOGUI
@@ -427,10 +418,8 @@ void wxLogStream::DoLogString(const char *szString)
#if wxUSE_STD_IOSTREAM
wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl *pTextCtrl)
// DLL mode in wxMSW, can't use it.
#if defined(NO_TEXT_WINDOW_STREAM)
#else
: wxLogStream(new ostream(pTextCtrl))
#if !defined(NO_TEXT_WINDOW_STREAM)
: wxLogStream(new ostream(pTextCtrl))
#endif
{
}
@@ -439,15 +428,22 @@ wxLogTextCtrl::~wxLogTextCtrl()
{
delete m_ostr;
}
#endif
#endif // wxUSE_STD_IOSTREAM
// ----------------------------------------------------------------------------
// wxLogGui implementation
// wxLogGui implementation (FIXME MT-unsafe)
// ----------------------------------------------------------------------------
wxLogGui::wxLogGui()
{
m_bErrors = FALSE;
Clear();
}
void wxLogGui::Clear()
{
m_bErrors = m_bWarnings = FALSE;
m_aMessages.Empty();
m_aTimes.Empty();
}
void wxLogGui::Flush()
@@ -458,8 +454,6 @@ void wxLogGui::Flush()
// do it right now to block any new calls to Flush() while we're here
m_bHasMessages = FALSE;
// @@@ ugly...
// concatenate all strings (but not too many to not overfill the msg box)
wxString str;
size_t nLines = 0,
@@ -478,21 +472,31 @@ void wxLogGui::Flush()
str << m_aMessages[n - 1] << "\n";
}
const char *title;
long style;
if ( m_bErrors ) {
wxMessageBox(str, _("Error"), wxOK | wxICON_EXCLAMATION);
title = _("Error");
style = wxICON_STOP;
}
else if ( m_bWarnings ) {
title = _("Warning");
style = wxICON_EXCLAMATION;
}
else {
wxMessageBox(str, _("Information"), wxOK | wxICON_INFORMATION);
title = _("Information");
style = wxICON_INFORMATION;
}
wxMessageBox(str, title, wxOK | style);
// no undisplayed messages whatsoever
m_bErrors = FALSE;
m_aMessages.Empty();
Clear();
}
// the default behaviour is to discard all informational messages if there
// are any errors/warnings.
void wxLogGui::DoLog(wxLogLevel level, const char *szString)
void wxLogGui::DoLog(wxLogLevel level, const char *szString, time_t t)
{
switch ( level ) {
case wxLOG_Info:
@@ -500,6 +504,7 @@ void wxLogGui::DoLog(wxLogLevel level, const char *szString)
case wxLOG_Message:
if ( !m_bErrors ) {
m_aMessages.Add(szString);
m_aTimes.Add((long)t);
m_bHasMessages = TRUE;
}
break;
@@ -524,22 +529,20 @@ void wxLogGui::DoLog(wxLogLevel level, const char *szString)
case wxLOG_Debug:
#ifdef __WXDEBUG__
{
wxString strTime = TimeStamp();
#ifdef __WXMSW__
// don't prepend debug/trace here: it goes to the debug window
// anyhow, but do put a timestamp
OutputDebugString(strTime + szString + "\n\r");
// don't prepend debug/trace here: it goes to the
// debug window anyhow, but do put a timestamp
OutputDebugString(wxString(szString) + "\n\r");
#else
// send them to stderr
fprintf(stderr, "%s %s: %s\n",
strTime.c_str(),
fprintf(stderr, "%s: %s\n",
level == wxLOG_Trace ? "Trace" : "Debug",
szString);
fflush(stderr);
#endif
}
#endif // __WXDEBUG__
break;
case wxLOG_FatalError:
@@ -548,15 +551,24 @@ void wxLogGui::DoLog(wxLogLevel level, const char *szString)
break;
case wxLOG_Error:
case wxLOG_Warning:
// discard earlier informational messages if this is the 1st error
// discard earlier informational messages if this is the 1st
// error because they might not make sense any more
if ( !m_bErrors ) {
m_aMessages.Empty();
m_aTimes.Empty();
m_bHasMessages = TRUE;
m_bErrors = TRUE;
}
// fall through
case wxLOG_Warning:
if ( !m_bErrors ) {
// for the warning we don't discard the info messages
m_bWarnings = TRUE;
}
m_aMessages.Add(szString);
m_aTimes.Add((long)t);
break;
default:
@@ -619,11 +631,8 @@ wxLogFrame::wxLogFrame(wxFrame *pParent, wxLogWindow *log, const char *szTitle)
{
m_log = log;
// @@ kludge: wxSIMPLE_BORDER is simply to prevent wxWindows from creating
// a rich edit control instead of a normal one we want in wxMSW
m_pTextCtrl = new wxTextCtrl(this, -1, wxEmptyString, wxDefaultPosition,
wxDefaultSize,
//wxSIMPLE_BORDER |
wxTE_MULTILINE |
wxHSCROLL |
wxTE_READONLY);
@@ -705,7 +714,7 @@ void wxLogFrame::OnSave(wxCommandEvent& WXUNUSED(event))
int nLines = m_pTextCtrl->GetNumberOfLines();
for ( int nLine = 0; bOk && nLine < nLines; nLine++ ) {
bOk = file.Write(m_pTextCtrl->GetLineText(nLine) +
// we're not going to pull in the whole wxTextFile if all we need is this...
// we're not going to pull in the whole wxTextFile if all we need is this...
#if wxUSE_TEXTFILE
wxTextFile::GetEOL()
#else // !wxUSE_TEXTFILE
@@ -764,15 +773,15 @@ void wxLogWindow::Flush()
m_bHasMessages = FALSE;
}
void wxLogWindow::DoLog(wxLogLevel level, const char *szString)
void wxLogWindow::DoLog(wxLogLevel level, const char *szString, time_t t)
{
// first let the previous logger show it
if ( m_pOldLog != NULL && m_bPassMessages ) {
// @@@ why can't we access protected wxLog method from here (we derive
// FIXME why can't we access protected wxLog method from here (we derive
// from wxLog)? gcc gives "DoLog is protected in this context", what
// does this mean? Anyhow, the cast is harmless and let's us do what
// we want.
((wxLogWindow *)m_pOldLog)->DoLog(level, szString);
((wxLogWindow *)m_pOldLog)->DoLog(level, szString, t);
}
if ( m_pLogFrame ) {
@@ -781,9 +790,9 @@ void wxLogWindow::DoLog(wxLogLevel level, const char *szString)
// by default, these messages are ignored by wxLog, so process
// them ourselves
{
wxString str = TimeStamp();
wxString str;
str << _("Status: ") << szString;
DoLogString(str);
DoLogString(str, t);
}
break;
@@ -796,23 +805,23 @@ void wxLogWindow::DoLog(wxLogLevel level, const char *szString)
default:
// and this will format it nicely and call our DoLogString()
wxLog::DoLog(level, szString);
wxLog::DoLog(level, szString, t);
}
}
m_bHasMessages = TRUE;
}
void wxLogWindow::DoLogString(const char *szString)
void wxLogWindow::DoLogString(const char *szString, time_t t)
{
// put the text into our window
wxTextCtrl *pText = m_pLogFrame->TextCtrl();
// remove selection (WriteText is in fact ReplaceSelection)
#ifdef __WXMSW__
#ifdef __WXMSW__
long nLen = pText->GetLastPosition();
pText->SetSelection(nLen, nLen);
#endif // Windows
#endif // Windows
pText->WriteText(szString);
pText->WriteText("\n"); // "\n" ok here (_not_ "\r\n")
@@ -851,10 +860,12 @@ wxLogWindow::~wxLogWindow()
// ----------------------------------------------------------------------------
// static variables
// ----------------------------------------------------------------------------
wxLog *wxLog::ms_pLogger = (wxLog *) NULL;
wxLog *wxLog::ms_pLogger = (wxLog *)NULL;
bool wxLog::ms_doLog = TRUE;
bool wxLog::ms_bAutoCreate = TRUE;
wxTraceMask wxLog::ms_ulTraceMask = (wxTraceMask)0;
wxArrayString wxLog::ms_aTraceMasks;
// ----------------------------------------------------------------------------
// stdout error logging helper
@@ -863,12 +874,12 @@ wxTraceMask wxLog::ms_ulTraceMask = (wxTraceMask)0;
// helper function: wraps the message and justifies it under given position
// (looks more pretty on the terminal). Also adds newline at the end.
//
// @@ this is now disabled until I find a portable way of determining the
// TODO this is now disabled until I find a portable way of determining the
// terminal window size (ok, I found it but does anybody really cares?)
#ifdef LOG_PRETTY_WRAP
static void wxLogWrap(FILE *f, const char *pszPrefix, const char *psz)
{
size_t nMax = 80; // @@@@
size_t nMax = 80; // FIXME
size_t nStart = strlen(pszPrefix);
fputs(pszPrefix, f);
@@ -900,16 +911,16 @@ static void wxLogWrap(FILE *f, const char *pszPrefix, const char *psz)
// get error code from syste
unsigned long wxSysErrorCode()
{
#ifdef __WXMSW__
#ifdef __WIN32__
#ifdef __WXMSW__
#ifdef __WIN32__
return ::GetLastError();
#else //WIN16
// @@@@ what to do on Windows 3.1?
#else //WIN16
// TODO what to do on Windows 3.1?
return 0;
#endif //WIN16/32
#else //Unix
#endif //WIN16/32
#else //Unix
return errno;
#endif //Win/Unix
#endif //Win/Unix
}
// get error message from system
@@ -918,8 +929,8 @@ const char *wxSysErrorMsg(unsigned long nErrCode)
if ( nErrCode == 0 )
nErrCode = wxSysErrorCode();
#ifdef __WXMSW__
#ifdef __WIN32__
#ifdef __WXMSW__
#ifdef __WIN32__
static char s_szBuf[LOG_BUFFER_SIZE / 2];
// get error message from system
@@ -936,7 +947,7 @@ const char *wxSysErrorMsg(unsigned long nErrCode)
LocalFree(lpMsgBuf);
// returned string is capitalized and ended with '\r\n' - bad
s_szBuf[0] = (char)wxToLower(s_szBuf[0]);
s_szBuf[0] = (char)tolower(s_szBuf[0]);
size_t len = strlen(s_szBuf);
if ( len > 0 ) {
// truncate string
@@ -945,13 +956,13 @@ const char *wxSysErrorMsg(unsigned long nErrCode)
}
return s_szBuf;
#else //Win16
// TODO @@@@
#else //Win16
// TODO
return NULL;
#endif // Win16/32
#else // Unix
#endif // Win16/32
#else // Unix
return strerror(nErrCode);
#endif // Win/Unix
#endif // Win/Unix
}
// ----------------------------------------------------------------------------
@@ -960,21 +971,22 @@ const char *wxSysErrorMsg(unsigned long nErrCode)
#ifdef __WXDEBUG__
// break into the debugger
void Trap()
{
#ifdef __WXMSW__
#ifdef __WXMSW__
DebugBreak();
#elif defined(__WXSTUBS__)
// TODO
#elif defined(__WXMAC__)
#if __powerc
#elif defined(__WXMAC__)
#if __powerc
Debugger();
#else
#else
SysBreak();
#endif
#else // Unix
#endif
#elif defined(__UNIX__)
raise(SIGTRAP);
#endif // Win/Unix
#else
// TODO
#endif // Win/Unix
}
// this function is called when an assert fails
@@ -982,7 +994,7 @@ void wxOnAssert(const char *szFile, int nLine, const char *szMsg)
{
// this variable can be set to true to suppress "assert failure" messages
static bool s_bNoAsserts = FALSE;
static bool s_bInAssert = FALSE;
static bool s_bInAssert = FALSE; // FIXME MT-unsafe
if ( s_bInAssert ) {
// He-e-e-e-elp!! we're trapped in endless loop
@@ -997,8 +1009,8 @@ void wxOnAssert(const char *szFile, int nLine, const char *szMsg)
char szBuf[LOG_BUFFER_SIZE];
// make life easier for people using VC++ IDE: clicking on the message will
// take us immediately to the place of the failed assert
// make life easier for people using VC++ IDE: clicking on the message
// will take us immediately to the place of the failed assert
#ifdef __VISUALC__
sprintf(szBuf, "%s(%d): assert failed", szFile, nLine);
#else // !VC++
@@ -1018,9 +1030,11 @@ void wxOnAssert(const char *szFile, int nLine, const char *szMsg)
// send it to the normal log destination
wxLogDebug(szBuf);
#if wxUSE_NOGUI
#if wxUSE_NOGUI
Trap();
#else
#else
// this message is intentionally not translated - it is for
// developpers only
strcat(szBuf, "\nDo you want to stop the program?"
"\nYou can also choose [Cancel] to suppress "
"further warnings.");
@@ -1037,7 +1051,7 @@ void wxOnAssert(const char *szFile, int nLine, const char *szMsg)
//case wxNO: nothing to do
}
#endif // USE_NOGUI
#endif // USE_NOGUI
}
s_bInAssert = FALSE;

View File

@@ -359,28 +359,6 @@ wxString wxNow( void )
return wxString(date);
}
/* Get Full RFC822 style email address */
bool
wxGetEmailAddress (char *address, int maxSize)
{
char host[65];
char user[65];
if (wxGetHostName(host, 64) == FALSE)
return FALSE;
if (wxGetUserId(user, 64) == FALSE)
return FALSE;
char tmp[130];
strcpy(tmp, user);
strcat(tmp, "@");
strcat(tmp, host);
strncpy(address, tmp, maxSize - 1);
address[maxSize-1] = '\0';
return TRUE;
}
/*
* Strip out any menu codes
*/
@@ -822,37 +800,81 @@ int isascii( int c )
}
#endif
bool wxGetUserId(wxString& buf)
// ----------------------------------------------------------------------------
// network and user id functions
// ----------------------------------------------------------------------------
// Get Full RFC822 style email address
bool wxGetEmailAddress(char *address, int maxSize)
{
bool success = wxGetUserId(wxBuffer, 500);
if (success)
{
buf = wxBuffer;
return TRUE;
}
else
wxString email = wxGetEmailAddress();
if ( !email )
return FALSE;
strncpy(address, email, maxSize - 1);
address[maxSize - 1] = '\0';
return TRUE;
}
bool wxGetUserName(wxString& buf)
wxString wxGetEmailAddress()
{
bool success = wxGetUserName(wxBuffer, 500);
if (success)
wxString email;
wxString host = wxGetHostName();
if ( !!host )
{
buf = wxBuffer;
return TRUE;
wxString user = wxGetUserId();
if ( !!user )
{
wxString email(user);
email << '@' << host;
}
else
return FALSE;
}
return email;
}
bool wxGetHostName(wxString& buf)
wxString wxGetUserId()
{
static const int maxLoginLen = 256; // FIXME arbitrary number
wxString buf;
bool ok = wxGetUserId(buf.GetWriteBuf(maxLoginLen), maxLoginLen);
buf.UngetWriteBuf();
if ( !ok )
buf.Empty();
return buf;
}
wxString wxGetUserName()
{
static const int maxUserNameLen = 1024; // FIXME arbitrary number
wxString buf;
bool ok = wxGetUserName(buf.GetWriteBuf(maxUserNameLen), maxUserNameLen);
buf.UngetWriteBuf();
if ( !ok )
buf.Empty();
return buf;
}
wxString wxGetHostName()
{
static const size_t hostnameSize = 257;
wxString buf;
bool ok = wxGetHostName(buf.GetWriteBuf(hostnameSize), hostnameSize);
buf.UngetWriteBuf();
return ok;
if ( !ok )
buf.Empty();
return buf;
}

View File

@@ -109,7 +109,7 @@ bool wxAcceleratorEntry::MatchesEvent(const wxKeyEvent& event) const
int accKeyCode = GetKeyCode();
int accKeyCode2 = GetKeyCode();
if (isascii(accKeyCode2))
accKeyCode2 = wxToLower(accKeyCode2);
accKeyCode2 = tolower(accKeyCode2);
return ((eventAltDown == accAltDown) && (eventCtrlDown == accCtrlDown) &&
(eventShiftDown == accShiftDown) &&

View File

@@ -110,9 +110,9 @@ void wxUsleep(unsigned long milliseconds)
// process management
// ----------------------------------------------------------------------------
int wxKill(long pid, int sig)
int wxKill(long pid, wxSignal sig)
{
return kill(pid, sig);
return kill(pid, (int)sig);
}
#define WXEXECUTE_NARGS 127
@@ -350,7 +350,7 @@ char *wxGetUserHome( const wxString &user )
{
struct passwd *who = (struct passwd *) NULL;
if (user.IsNull() || (user== ""))
if ( !user )
{
register char *ptr;
@@ -378,12 +378,15 @@ char *wxGetUserHome( const wxString &user )
}
// ----------------------------------------------------------------------------
// id routines
// network and user id routines
// ----------------------------------------------------------------------------
bool wxGetHostName(char *buf, int sz)
// retrieve either the hostname or FQDN depending on platform (caller must
// check whether it's one or the other, this is why this function is for
// private use only)
static bool wxGetHostNameInternal(char *buf, int sz)
{
wxCHECK_MSG( buf, FALSE, "NULL pointer in wxGetHostName" );
wxCHECK_MSG( buf, FALSE, "NULL pointer in wxGetHostNameInternal" );
*buf = '\0';
@@ -398,11 +401,11 @@ bool wxGetHostName(char *buf, int sz)
}
#elif defined(HAVE_GETHOSTNAME)
bool ok = gethostname(buf, sz) != -1;
#else
#else // no uname, no gethostname
wxFAIL_MSG("don't know host name for this machibe");
bool ok = FALSE;
#endif
#endif // uname/gethostname
if ( !ok )
{
@@ -412,6 +415,52 @@ bool wxGetHostName(char *buf, int sz)
return ok;
}
bool wxGetHostName(char *buf, int sz)
{
bool ok = wxGetHostNameInternal(buf, sz);
if ( ok )
{
// BSD systems return the FQDN, we only want the hostname, so extract
// it (we consider that dots are domain separators)
char *dot = strchr(buf, '.');
if ( dot )
{
// nuke it
*dot = '\0';
}
}
return ok;
}
bool wxGetFullHostName(char *buf, int sz)
{
bool ok = wxGetHostNameInternal(buf, sz);
if ( ok )
{
if ( !strchr(buf, '.') )
{
struct hostent *host = gethostbyname(buf);
if ( !host )
{
wxLogSysError(_("Cannot get the official hostname"));
ok = FALSE;
}
else
{
// the canonical name
strncpy(buf, host->h_name, sz);
}
}
//else: it's already a FQDN (BSD behaves this way)
}
return ok;
}
bool wxGetUserId(char *buf, int sz)
{
struct passwd *who;
@@ -473,14 +522,3 @@ void wxFatalError( const wxString &msg, const wxString &title )
exit(3); // the same exit code as for abort()
}
//------------------------------------------------------------------------
// directory routines
//------------------------------------------------------------------------
bool wxDirExists( const wxString& dir )
{
char buf[500];
strcpy( buf, WXSTRINGCAST(dir) );
struct stat sbuf;
return ((stat(buf, &sbuf) != -1) && S_ISDIR(sbuf.st_mode) ? TRUE : FALSE);
}