[Scummvm-cvs-logs] scummvm master -> 656c252636e3254706e66ca2791fcc76f66b64d3

wjp wjp at usecode.org
Sat Jun 4 15:15:32 CEST 2011


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
656c252636 POSIX: Implement displayLogFile in the posix backend


Commit: 656c252636e3254706e66ca2791fcc76f66b64d3
    https://github.com/scummvm/scummvm/commit/656c252636e3254706e66ca2791fcc76f66b64d3
Author: Willem Jan Palenstijn (wjp at usecode.org)
Date: 2011-06-04T06:12:07-07:00

Commit Message:
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.

Changed paths:
    backends/platform/sdl/posix/posix.cpp
    backends/platform/sdl/posix/posix.h



diff --git a/backends/platform/sdl/posix/posix.cpp b/backends/platform/sdl/posix/posix.cpp
index f30b953..a45949d 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 6246e6f..59909a9 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();
 






More information about the Scummvm-git-logs mailing list