diff options
Diffstat (limited to 'backends/platform/sdl/posix/posix.cpp')
-rw-r--r-- | backends/platform/sdl/posix/posix.cpp | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/backends/platform/sdl/posix/posix.cpp b/backends/platform/sdl/posix/posix.cpp index 21ad7b9e35..d757186134 100644 --- a/backends/platform/sdl/posix/posix.cpp +++ b/backends/platform/sdl/posix/posix.cpp @@ -22,6 +22,8 @@ #define FORBIDDEN_SYMBOL_EXCEPTION_getenv #define FORBIDDEN_SYMBOL_EXCEPTION_mkdir +#define FORBIDDEN_SYMBOL_EXCEPTION_exit +#define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h #define FORBIDDEN_SYMBOL_EXCEPTION_time_h //On IRIX, sys/stat.h includes sys/time.h #include "common/scummsys.h" @@ -34,6 +36,8 @@ #include <errno.h> #include <sys/stat.h> +#include <sys/wait.h> +#include <unistd.h> OSystem_POSIX::OSystem_POSIX(Common::String baseConfigName) @@ -58,6 +62,12 @@ void OSystem_POSIX::initBackend() { OSystem_SDL::initBackend(); } +bool OSystem_POSIX::hasFeature(Feature f) { + if (f == kFeatureDisplayLogFile) + return true; + return OSystem_SDL::hasFeature(f); +} + Common::String OSystem_POSIX::getDefaultConfigFileName() { char configFile[MAXPATHLEN]; @@ -73,6 +83,10 @@ Common::String OSystem_POSIX::getDefaultConfigFileName() { } Common::WriteStream *OSystem_POSIX::createLogFile() { + // Start out by resetting _logFilePath, so that in case + // of a failure, we know that no log file is open. + _logFilePath.clear(); + const char *home = getenv("HOME"); if (home == NULL) return 0; @@ -128,7 +142,62 @@ Common::WriteStream *OSystem_POSIX::createLogFile() { logFile += "/scummvm.log"; Common::FSNode file(logFile); - return file.createWriteStream(); + Common::WriteStream *stream = file.createWriteStream(); + if (stream) + _logFilePath = logFile; + return stream; } +bool OSystem_POSIX::displayLogFile() { + if (_logFilePath.empty()) + return false; + + // FIXME: This may not work perfectly when in fullscreen mode. + // On my system it drops from fullscreen without ScummVM noticing, + // so the next Alt-Enter does nothing, going from windowed to windowed. + // (wjp, 20110604) + + pid_t pid = fork(); + if (pid < 0) { + // failed to fork + return false; + } else if (pid == 0) { + + // Try xdg-open first + execlp("xdg-open", "xdg-open", _logFilePath.c_str(), (char*)0); + + // If we're here, that clearly failed. + + // TODO: We may also want to try detecting the case where + // xdg-open is successfully executed but returns an error code. + + // Try xterm+less next + + execlp("xterm", "xterm", "-e", "less", _logFilePath.c_str(), (char*)0); + + // TODO: If less does not exist we could fall back to 'more'. + // However, we'll have to use 'xterm -hold' for that to prevent the + // terminal from closing immediately (for short log files) or + // unexpectedly. + + exit(127); + } + + int status; + // Wait for viewer to close. + // (But note that xdg-open may have spawned a viewer in the background.) + + // FIXME: We probably want the viewer to always open in the background. + // This may require installing a SIGCHLD handler. + pid = waitpid(pid, &status, 0); + + if (pid < 0) { + // Probably nothing sensible to do in this error situation + return false; + } + + return WIFEXITED(status) && WEXITSTATUS(status) == 0; +} + + #endif |