X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d7ef641d4e6d0e2157beb920bdd7d72fc6aecfd7..74c80fe40be90a5a604b9de8731fcedf910e7d7d:/src/unix/utilsunx.cpp diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp index 5b9a1f627d..9a1243beb7 100644 --- a/src/unix/utilsunx.cpp +++ b/src/unix/utilsunx.cpp @@ -39,6 +39,8 @@ #include "wx/process.h" #include "wx/thread.h" +#include "wx/cmdline.h" + #include "wx/wfstream.h" #include "wx/private/selectdispatcher.h" @@ -264,10 +266,12 @@ int wxKill(long pid, wxSignal sig, wxKillError *rc, int flags) } // Shutdown or reboot the PC -bool wxShutdown(wxShutdownFlags wFlags) +bool wxShutdown(int flags) { + flags &= ~wxSHUTDOWN_FORCE; + wxChar level; - switch ( wFlags ) + switch ( flags ) { case wxSHUTDOWN_POWEROFF: level = _T('0'); @@ -277,12 +281,16 @@ bool wxShutdown(wxShutdownFlags wFlags) level = _T('6'); break; + case wxSHUTDOWN_LOGOFF: + // TODO: use dcop to log off? + return false; + default: wxFAIL_MSG( _T("unknown wxShutdown() flag") ); return false; } - return system(wxString::Format(_T("init %c"), level).mb_str()) == 0; + return system(wxString::Format("init %c", level).mb_str()) == 0; } // ---------------------------------------------------------------------------- @@ -421,7 +429,7 @@ private: int m_argc; char **m_argv; - DECLARE_NO_COPY_CLASS(ArgsArray); + DECLARE_NO_COPY_CLASS(ArgsArray) }; } // anonymous namespace @@ -436,60 +444,9 @@ bool wxMacLaunch(char **argv); long wxExecute(const wxString& command, int flags, wxProcess *process) { - wxArrayString args; - - const char *cptr = command.c_str(); - - // split the command line in arguments - // - // TODO: combine this with wxCmdLineParser::ConvertStringToArgs(), it - // doesn't do exactly the same thing right now but it's pretty close - // and we shouldn't maintain 2 copies of this code - do - { - wxString argument; - char quotechar = '\0'; // is arg quoted? - bool escaped = false; - - // eat leading whitespace: - while ( wxIsspace(*cptr) ) - cptr++; - - if ( *cptr == '\'' || *cptr == '"' ) - quotechar = *cptr++; - - do - { - if ( *cptr == '\\' && !escaped ) - { - escaped = true; - cptr++; - continue; - } - - // all other characters: - argument += *cptr++; - escaped = false; - - // have we reached the end of the argument? - if ( (*cptr == quotechar && !escaped) - || (quotechar == '\0' && wxIsspace(*cptr)) - || *cptr == '\0' ) - { - args.push_back(argument); - - // if not at end of buffer, swallow last character: - if ( *cptr ) - cptr++; - - break; // done with this one, start over - } - } while ( *cptr ); - } while ( *cptr ); + ArgsArray argv(wxCmdLineParser::ConvertStringToArgs(command, + wxCMD_LINE_SPLIT_UNIX)); - ArgsArray argv(args); - - // do execute the command return wxExecute(argv, flags, process); } @@ -526,7 +483,7 @@ long wxExecute(char **argv, int flags, wxProcess *process) _T("wxExecute() can be called only from the main thread") ); #endif // wxUSE_THREADS -#if defined(__DARWIN__) +#if defined(__WXCOCOA__) || ( defined(__WXOSX_MAC__) && wxOSX_USE_COCOA_OR_CARBON ) // wxMacLaunch() only executes app bundles and only does it asynchronously. // It returns false if the target is not an app bundle, thus falling // through to the regular code for non app bundles. @@ -1352,7 +1309,7 @@ private: DECLARE_NO_COPY_CLASS(wxEndHandler) }; -#if wxUSE_STREAMS +#if HAS_PIPE_INPUT_STREAM // class for monitoring our ends of child stdout/err, should be constructed // with the FD and stream from wxExecuteData and will do nothing if they're @@ -1381,7 +1338,7 @@ private: DECLARE_NO_COPY_CLASS(wxRedirectedIOHandler) }; -#endif // wxUSE_STREAMS +#endif // HAS_PIPE_INPUT_STREAM // helper function which calls waitpid() and analyzes the result int DoWaitForChild(int pid, int flags = 0) @@ -1456,7 +1413,7 @@ int wxAppTraits::WaitForChild(wxExecuteData& execData) } //else: synchronous execution case -#if wxUSE_STREAMS +#if HAS_PIPE_INPUT_STREAM wxProcess * const process = execData.process; if ( process && process->IsRedirected() ) { @@ -1480,7 +1437,7 @@ int wxAppTraits::WaitForChild(wxExecuteData& execData) } } //else: no IO redirection, just block waiting for the child to exit -#endif // wxUSE_STREAMS +#endif // HAS_PIPE_INPUT_STREAM return DoWaitForChild(execData.pid); }