aboutsummaryrefslogtreecommitdiff
path: root/backends/platform
diff options
context:
space:
mode:
authorWillem Jan Palenstijn2011-06-04 15:07:12 +0200
committerWillem Jan Palenstijn2011-06-04 15:12:07 +0200
commit656c252636e3254706e66ca2791fcc76f66b64d3 (patch)
tree102802ca64e1882b03a1d70b9be0961ca3145f3f /backends/platform
parenteb89240370178d09fd6e9cba836dfa4b94d7998a (diff)
downloadscummvm-rg350-656c252636e3254706e66ca2791fcc76f66b64d3.tar.gz
scummvm-rg350-656c252636e3254706e66ca2791fcc76f66b64d3.tar.bz2
scummvm-rg350-656c252636e3254706e66ca2791fcc76f66b64d3.zip
POSIX: Implement displayLogFile in the posix backend
Tested only on Linux, but hopefully this is sufficiently portable to support the other POSIX platforms. Using fork/exec instead of the simpler 'system' to avoid quoting issues and depending on specific shell features to handle a missing xdg-open gracefully.
Diffstat (limited to 'backends/platform')
-rw-r--r--backends/platform/sdl/posix/posix.cpp55
-rw-r--r--backends/platform/sdl/posix/posix.h4
2 files changed, 59 insertions, 0 deletions
diff --git a/backends/platform/sdl/posix/posix.cpp b/backends/platform/sdl/posix/posix.cpp
index f30b953a8f..a45949deda 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];
@@ -138,4 +148,49 @@ Common::WriteStream *OSystem_POSIX::createLogFile() {
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.
+ // 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.)
+ 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
diff --git a/backends/platform/sdl/posix/posix.h b/backends/platform/sdl/posix/posix.h
index 6246e6f59d..59909a958f 100644
--- a/backends/platform/sdl/posix/posix.h
+++ b/backends/platform/sdl/posix/posix.h
@@ -31,6 +31,10 @@ public:
OSystem_POSIX(Common::String baseConfigName = ".scummvmrc");
virtual ~OSystem_POSIX() {}
+ virtual bool hasFeature(Feature f);
+
+ virtual bool displayLogFile();
+
virtual void init();
virtual void initBackend();