-// ----------------------------------------------------------------------------
-// misc functions
-// ----------------------------------------------------------------------------
-
-// Don't synthesize KeyUp events holding down a key and producing KeyDown
-// events with autorepeat. On by default and always on in wxMSW. wxGTK version
-// in utilsgtk.cpp.
-#ifndef __WXGTK__
-bool wxSetDetectableAutoRepeat( bool WXUNUSED(flag) )
-{
- return TRUE; // detectable auto-repeat is the only mode MSW supports
-}
-#endif // !wxGTK
-
-#endif // wxUSE_GUI
-
-const wxChar *wxGetInstallPrefix()
-{
- wxString prefix;
-
- if ( wxGetEnv(wxT("WXPREFIX"), &prefix) )
- return prefix.c_str();
-
-#ifdef wxINSTALL_PREFIX
- return wxT(wxINSTALL_PREFIX);
-#else
- return wxT("");
-#endif
-}
-
-wxString wxGetDataDir()
-{
- wxString format = wxGetInstallPrefix();
- format << wxFILE_SEP_PATH
- << wxT("share") << wxFILE_SEP_PATH
- << wxT("wx") << wxFILE_SEP_PATH
- << wxT("%i.%i");
- wxString dir;
- dir.Printf(format.c_str(), wxMAJOR_VERSION, wxMINOR_VERSION);
- return dir;
-}
-
-
-// ----------------------------------------------------------------------------
-// network and user id functions
-// ----------------------------------------------------------------------------
-
-// Get Full RFC822 style email address
-bool wxGetEmailAddress(wxChar *address, int maxSize)
-{
- wxString email = wxGetEmailAddress();
- if ( !email )
- return FALSE;
-
- wxStrncpy(address, email, maxSize - 1);
- address[maxSize - 1] = wxT('\0');
-
- return TRUE;
-}
-
-wxString wxGetEmailAddress()
-{
- wxString email;
-
- wxString host = wxGetFullHostName();
- if ( !!host )
- {
- wxString user = wxGetUserId();
- if ( !!user )
- {
- email << user << wxT('@') << host;
- }
- }
-
- return email;
-}
-
-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();
-
- if ( !ok )
- buf.Empty();
-
- return buf;
-}
-
-wxString wxGetFullHostName()
-{
- static const size_t hostnameSize = 257;
-
- wxString buf;
- bool ok = wxGetFullHostName(buf.GetWriteBuf(hostnameSize), hostnameSize);
-
- buf.UngetWriteBuf();
-
- if ( !ok )
- buf.Empty();
-
- return buf;
-}
-
-wxString wxGetHomeDir()
-{
- wxString home;
- wxGetHomeDir(&home);
-
- return home;
-}
-
-#if 0
-
-wxString wxGetCurrentDir()
-{
- wxString dir;
- size_t len = 1024;
- bool ok;
- do
- {
- ok = getcwd(dir.GetWriteBuf(len + 1), len) != NULL;
- dir.UngetWriteBuf();
-
- if ( !ok )
- {
- if ( errno != ERANGE )
- {
- wxLogSysError(_T("Failed to get current directory"));
-
- return wxEmptyString;
- }
- else
- {
- // buffer was too small, retry with a larger one
- len *= 2;
- }
- }
- //else: ok
- } while ( !ok );
-
- return dir;
-}
-
-#endif // 0
-
-// ----------------------------------------------------------------------------
-// wxExecute
-// ----------------------------------------------------------------------------
-
-// wxDoExecuteWithCapture() helper: reads an entire stream into one array
-//
-// returns TRUE if ok, FALSE if error
-#if wxUSE_STREAMS
-static bool ReadAll(wxInputStream *is, wxArrayString& output)
-{
- wxCHECK_MSG( is, FALSE, _T("NULL stream in wxExecute()?") );
-
- // the stream could be already at EOF or in wxSTREAM_BROKEN_PIPE state
- is->Reset();
-
- wxTextInputStream tis(*is);
-
- bool cont = TRUE;
- while ( cont )
- {
- wxString line = tis.ReadLine();
- if ( is->Eof() )
- break;
-
- if ( !*is )
- {
- cont = FALSE;
- }
- else
- {
- output.Add(line);
- }
- }
-
- return cont;
-}
-#endif // wxUSE_STREAMS
-
-// this is a private function because it hasn't a clean interface: the first
-// array is passed by reference, the second by pointer - instead we have 2
-// public versions of wxExecute() below
-static long wxDoExecuteWithCapture(const wxString& command,
- wxArrayString& output,
- wxArrayString* error)
-{
-#ifdef __WIN16__
- wxFAIL_MSG("Sorry, this version of wxExecute not implemented on WIN16.");
-
- return 0;
-#else // !Win16
- // create a wxProcess which will capture the output
- wxProcess *process = new wxProcess;
- process->Redirect();
-
- long rc = wxExecute(command, wxEXEC_SYNC, process);
-
-#if wxUSE_STREAMS
- if ( rc != -1 )
- {
- if ( !ReadAll(process->GetInputStream(), output) )
- rc = -1;
-
- if ( error )
- {
- if ( !ReadAll(process->GetErrorStream(), *error) )
- rc = -1;
- }
-
- }
-#endif // wxUSE_STREAMS
-
- delete process;
-
- return rc;
-#endif // IO redirection supoprted
-}
-
-long wxExecute(const wxString& command, wxArrayString& output)
-{
- return wxDoExecuteWithCapture(command, output, NULL);
-}
-
-long wxExecute(const wxString& command,
- wxArrayString& output,
- wxArrayString& error)
-{
- return wxDoExecuteWithCapture(command, output, &error);
-}
-