mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-05 00:36:57 +00:00
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.
This commit is contained in:
parent
eb89240370
commit
656c252636
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#define FORBIDDEN_SYMBOL_EXCEPTION_getenv
|
#define FORBIDDEN_SYMBOL_EXCEPTION_getenv
|
||||||
#define FORBIDDEN_SYMBOL_EXCEPTION_mkdir
|
#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
|
#define FORBIDDEN_SYMBOL_EXCEPTION_time_h //On IRIX, sys/stat.h includes sys/time.h
|
||||||
|
|
||||||
#include "common/scummsys.h"
|
#include "common/scummsys.h"
|
||||||
@ -34,6 +36,8 @@
|
|||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
OSystem_POSIX::OSystem_POSIX(Common::String baseConfigName)
|
OSystem_POSIX::OSystem_POSIX(Common::String baseConfigName)
|
||||||
@ -58,6 +62,12 @@ void OSystem_POSIX::initBackend() {
|
|||||||
OSystem_SDL::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() {
|
Common::String OSystem_POSIX::getDefaultConfigFileName() {
|
||||||
char configFile[MAXPATHLEN];
|
char configFile[MAXPATHLEN];
|
||||||
|
|
||||||
@ -138,4 +148,49 @@ Common::WriteStream *OSystem_POSIX::createLogFile() {
|
|||||||
return stream;
|
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
|
#endif
|
||||||
|
@ -31,6 +31,10 @@ public:
|
|||||||
OSystem_POSIX(Common::String baseConfigName = ".scummvmrc");
|
OSystem_POSIX(Common::String baseConfigName = ".scummvmrc");
|
||||||
virtual ~OSystem_POSIX() {}
|
virtual ~OSystem_POSIX() {}
|
||||||
|
|
||||||
|
virtual bool hasFeature(Feature f);
|
||||||
|
|
||||||
|
virtual bool displayLogFile();
|
||||||
|
|
||||||
virtual void init();
|
virtual void init();
|
||||||
virtual void initBackend();
|
virtual void initBackend();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user