/////////////////////////////////////////////////////////////////////////////
-// Name: utils.cpp
+// Name: src/msdos/utilsdos.cpp
// Purpose: DOS implementations of utility functions
// Author: Vaclav Slavik, M.J.Wetherell
// Id: $Id$
#endif
#include "wx/utils.h"
-#include "wx/string.h"
-#include "wx/intl.h"
+#ifndef WX_PRECOMP
+ #include "wx/string.h"
+ #include "wx/intl.h"
+ #include "wx/log.h"
+ #include "wx/app.h"
+#endif
+
#include "wx/apptrait.h"
-#include "wx/log.h"
#include "wx/process.h"
#include "wx/confbase.h" // for wxExpandEnvVars()
-#include "wx/app.h"
#include "wx/cmdline.h"
#include "wx/filename.h"
#include "wx/wfstream.h"
// wxGetenv is defined as getenv()
wxChar *p = wxGetenv(var);
if ( !p )
- return FALSE;
+ return false;
if ( value )
*value = p;
- return TRUE;
+ return true;
}
-bool wxSetEnv(const wxString& variable, const wxChar *value)
+static bool wxDoSetEnv(const wxString& variable, const char *value)
{
wxString s = variable;
if ( value )
- s << _T('=') << value;
+ s << wxT('=') << value;
// transform to ANSI
const char *p = s.mb_str();
return putenv(buf) == 0;
}
+bool wxSetEnv(const wxString& variable, const wxString& value)
+{
+ return wxDoSetEnv(variable, value.mb_str());
+}
+
+bool wxUnsetEnv(const wxString& variable)
+{
+ return wxDoSetEnv(variable, NULL);
+}
+
+
//----------------------------------------------------------------------------
// Hostname, username, home directory
//----------------------------------------------------------------------------
{
strDir = szHome;
// when msys sets %HOME% it uses '/' (cygwin uses '\\')
- strDir.Replace(_T("/"), _T("\\"));
+ strDir.Replace(wxT("/"), wxT("\\"));
}
}
wxString prog(wxTheApp->argv[0]);
#ifdef __DJGPP__
// djgpp startup code switches the slashes around, so restore them
- prog.Replace(_T("/"), _T("\\"));
+ prog.Replace(wxT("/"), wxT("\\"));
#endif
// it needs to be a full path to be usable
- if ( prog.compare(1, 2, _T(":\\")) == 0 )
- wxSplitPath(prog, &strDir, NULL, NULL);
+ if ( prog.compare(1, 2, wxT(":\\")) == 0 )
+ wxFileName::SplitPath(prog, &strDir, NULL, NULL);
}
if ( strDir.empty() )
{
- strDir = _T(".");
+ strDir = wxT(".");
}
}
return strDir.c_str();
}
-wxChar *wxGetUserHome(const wxString& user)
+wxString wxGetUserHome(const wxString& user)
{
- static wxString home;
+ wxString home;
if (user.empty() || user == wxGetUserId())
- return wx_const_cast(wxChar*, wxGetHomeDir(&home));
- else
- return _T("");
-}
+ wxGetHomeDir(&home);
-#if WXWIN_COMPATIBILITY_2_2
-void wxFatalError(const wxString &msg, const wxString &title)
-{
- wxFprintf( stderr, _("Error ") );
- if (!title.IsNull()) wxFprintf( stderr, wxT("%s "), WXSTRINGCAST(title) );
- if (!msg.IsNull()) wxFprintf( stderr, wxT(": %s"), WXSTRINGCAST(msg) );
- wxFprintf( stderr, wxT(".\n") );
- exit(3); // the same exit code as for abort()
+ return home;
}
-#endif // WXWIN_COMPATIBILITY_2_2
// returns %UserName%, $USER or just "user"
//
bool wxGetUserId(wxChar *buf, int n)
{
- const wxChar *user = wxGetenv(_T("UserName"));
+ const wxChar *user = wxGetenv(wxT("UserName"));
if (!user)
- user = wxGetenv(_T("USER"));
+ user = wxGetenv(wxT("USER"));
if (!user)
- user = _T("user");
+ user = wxT("user");
- wxStrncpy(buf, user, n);
+ wxStrlcpy(buf, user, n);
return true;
}
//
bool wxGetHostName(wxChar *buf, int n)
{
- const wxChar *host = wxGetenv(_T("ComputerName"));
-
+ const wxChar *host = wxGetenv(wxT("ComputerName"));
+
if (!host)
- host = wxGetenv(_T("HOSTNAME"));
+ host = wxGetenv(wxT("HOSTNAME"));
if (!host)
- host = _T("host");
+ host = wxT("host");
- wxStrncpy(buf, host, n);
+ wxStrlcpy(buf, host, n);
return true;
}
{
wxGetHostName(buf, n);
- const wxChar *domain = wxGetenv(_T("UserDnsDomain"));
+ const wxChar *domain = wxGetenv(wxT("UserDnsDomain"));
if (domain)
- wxStrncat(wxStrncat(buf, _T("."), n), domain, n);
+ wxStrncat(wxStrncat(buf, wxT("."), n), domain, n);
return true;
}
}
else
{
- wxLogDebug(_T("wxKill can only send signals to the current process under MSDOS"));
+ wxLogDebug(wxT("wxKill can only send signals to the current process under MSDOS"));
if (rc)
*rc = wxKILL_NO_PROCESS;
}
int result = system(command);
if (result == -1)
+ {
wxLogSysError(_("can't execute '%s'"), command.c_str());
+ }
return result == 0;
}
-long wxExecute(const wxString& command, int flags, wxProcess *process)
+long wxExecute(const wxString& command, int flags, wxProcess *process,
+ const wxExecuteEnv *env)
{
// FIXME: shouldn't depend on wxCmdLineParser
wxArrayString args(wxCmdLineParser::ConvertStringToArgs(command));
argv[n] = NULL;
while (n-- > 0)
- argv[n] = wx_const_cast(wxChar*, args[n].c_str());
+ argv[n] = const_cast<wxChar*>((const char *)args[n].c_str());
long result = wxExecute(argv, flags, process);
#if wxUSE_STREAMS
// A wxFFileInputStream that deletes the file in it's destructor
-//
+//
class wxTempFileInStream : public wxFFileInputStream
{
public:
wxTempFileInStream(const wxString& name)
- : wxFFileInputStream(name, _T("rt"))
+ : wxFFileInputStream(name, wxT("rt"))
{ }
- ~wxTempFileInStream()
+ virtual ~wxTempFileInStream()
{
m_file->Close();
wxRemoveFile(m_file->GetName());
}
if (!result)
+ {
wxLogSysError(_("error opening '%s'"), name.c_str());
+ }
return result;
}
// wxExecute implementation
//
-long wxExecute(wxChar **argv, int flags, wxProcess *process)
+long wxExecute(wxChar **argv, int flags, wxProcess *process,
+ const wxString* cwd, const wxEnvVariableHashMap* env)
{
#if wxUSE_STREAMS
const int STDIN = 0;
if (redirect)
{
// close stdin/out/err and reopen them as files
- if (!in.Reopen(_T("NUL"), O_RDONLY | O_TEXT))
+ if (!in.Reopen(wxT("NUL"), O_RDONLY | O_TEXT))
return -1;
- if (!out.Reopen(wxFileName::CreateTempFileName(_T("out")),
+ if (!out.Reopen(wxFileName::CreateTempFileName(wxT("out")),
O_CREAT | O_WRONLY | O_TRUNC | O_TEXT))
return -1;
- if (!err.Reopen(wxFileName::CreateTempFileName(_T("err")),
+ if (!err.Reopen(wxFileName::CreateTempFileName(wxT("err")),
O_CREAT | O_WRONLY | O_TRUNC | O_TEXT))
return -1;
}
int result = spawnvp(mode, argv[0], argv);
if (result == -1)
+ {
wxLogSysError(_("can't execute '%s'"), argv[0]);
+ }
#if wxUSE_STREAMS
if (redirect)
process->SetPipeStreams(new wxTempFileInStream(out.Release()),
- new wxFFileOutputStream(_T("NUL"), _T("wt")),
+ new wxFFileOutputStream(wxT("NUL"), wxT("wt")),
new wxTempFileInStream(err.Release()));
#endif // wxUSE_STREAMS
return result;
}
+
//----------------------------------------------------------------------------
-// Traits for console apps
+// OS-related
//----------------------------------------------------------------------------
-wxToolkitInfo& wxConsoleAppTraits::GetToolkitInfo()
+wxString wxGetOsDescription()
{
- static wxToolkitInfo info;
- info.versionMajor = _osmajor;
- info.versionMinor = _osminor;
- info.name = _T("wxBase");
- info.os = wxDOS;
- return info;
+ wxString osname(wxT("DOS"));
+ return osname;
}
+
+wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin)
+{
+ if ( verMaj )
+ *verMaj = _osmajor;
+ if ( verMin )
+ *verMin = _osminor;
+
+ return wxOS_DOS;
+}
+
+bool wxIsPlatform64Bit()
+{
+ return false;
+}
+