[Scummvm-cvs-logs] scummvm master -> 6c5f50c246062bcb50a20efe7951be7e23449ca0
fingolfin
max at quendi.de
Mon May 23 19:45:32 CEST 2011
This automated email contains information about 8 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
fa2c268d6a SWORD25: Replace some non-portable calls, add FIXMEs
3931e1dc50 SWORD25: Avoid including lua headers in other headers
8e3aafd30d COMMON: Provide our own implementations for scumm_str(n)icmp
e6c78b4f46 SWORD25: Include scummsys.h from lua.h, partially deal with the consequences
590c6ede63 BACKENDS: Move SCUMMVM_SAVEPATH env var handling to POSIX savefile manager
6f6051a9e1 COMMON: Mark more symbols as forbidden
20cad6e8b6 COMMON: Modify Base::processSettings, get rid of Common::kArgumentNotProcessed
6c5f50c246 COMMON: Add exit() to list of forbidden symbols
Commit: fa2c268d6a813a2fdfc4475607b1ebb5d878a624
https://github.com/scummvm/scummvm/commit/fa2c268d6a813a2fdfc4475607b1ebb5d878a624
Author: Max Horn (max at quendi.de)
Date: 2011-05-23T10:12:24-07:00
Commit Message:
SWORD25: Replace some non-portable calls, add FIXMEs
Changed paths:
engines/sword25/util/lua/loslib.cpp
diff --git a/engines/sword25/util/lua/loslib.cpp b/engines/sword25/util/lua/loslib.cpp
index 578a7cb..ac634db 100644
--- a/engines/sword25/util/lua/loslib.cpp
+++ b/engines/sword25/util/lua/loslib.cpp
@@ -4,9 +4,6 @@
** See Copyright Notice in lua.h
*/
-
-#include <stdlib.h>
-#include <string.h>
#include <time.h>
#define loslib_c
@@ -17,9 +14,16 @@
#include "lauxlib.h"
#include "lualib.h"
+// FIXME: Get rid of all time.h stuff
+#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
+
+#include "common/system.h"
+
static int os_execute (lua_State *L) {
- lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));
+ // Non-portable call, removed in ScummVM.
+ // FIXME: Is this ever invoked? If so, investigate that code further.
+ lua_pushinteger(L, -1); // signal that an error occurred
return 1;
}
@@ -35,24 +39,30 @@ static int os_remove (lua_State *L) {
static int os_rename (lua_State *L) {
- // Removed in ScummVM, does nothing.
+ // Non-portable call, removed in ScummVM.
return 1;
}
static int os_tmpname (lua_State *L) {
+ // Non-portable call, removed in ScummVM.
+ // FIXME: Why do we return an error in tmpname, but for other
+ // removed methods we just do nothing?
return luaL_error(L, "unable to generate a unique filename");
}
static int os_getenv (lua_State *L) {
- lua_pushstring(L, getenv(luaL_checkstring(L, 1))); /* if NULL push nil */
+ // Non-portable call, removed in ScummVM.
+ // FIXME: Is this ever invoked? If so, investigate that code further.
+ lua_pushstring(L, NULL);
return 1;
}
static int os_clock (lua_State *L) {
- lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC);
+ // Non-portable call to clock() replaced by invocation of OSystem::getMillis.
+ lua_pushnumber(L, ((lua_Number)g_system->getMillis())/(lua_Number)1000);
return 1;
}
@@ -103,6 +113,12 @@ static int getfield (lua_State *L, const char *key, int d) {
static int os_date (lua_State *L) {
const char *s = luaL_optstring(L, 1, "%c");
+ // FIXME: Rewrite the code below to use OSystem::getTimeAndDate
+ // Alternatively, remove it, if sword25 does not use it.
+ //
+ // The former would mean sacrificing the ability to choose the timezone, *or*
+ // we would have to drive an effort to add time zone support to OSystem (is it
+ // worth that, though???)
time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL));
struct tm *stm;
if (*s == '!') { /* UTC? */
@@ -148,6 +164,8 @@ static int os_date (lua_State *L) {
static int os_time (lua_State *L) {
+ // FIXME: Rewrite the code below to use OSystem::getTimeAndDate.
+ // Alternatively, remove it, if sword25 does not use it.
time_t t;
if (lua_isnoneornil(L, 1)) /* called without args? */
t = time(NULL); /* get current time */
@@ -173,6 +191,9 @@ static int os_time (lua_State *L) {
static int os_difftime (lua_State *L) {
+ // FIXME: difftime is not portable, unfortunately.
+ // So we either have to replace this code, or just remove it,
+ // depending on whether sword25 actually uses it.
lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)),
(time_t)(luaL_optnumber(L, 2, 0))));
return 1;
@@ -189,6 +210,13 @@ static int os_setlocale (lua_State *L) {
static int os_exit (lua_State *L) {
+ // FIXME: Using exit is not portable!
+ // Using OSystem::quit() isn't really a great idea, either.
+ // We really would prefer to let the main run loop exit, so that
+ // our main() can perform cleanup.
+ g_system->quit();
+ // leave the exit call in there for now, in case some of our
+ // OSystem::quit applications are incorrect... *sigh*
exit(luaL_optint(L, 1, EXIT_SUCCESS));
}
Commit: 3931e1dc50ad773aa3f9d95b2810857a3e7ce943
https://github.com/scummvm/scummvm/commit/3931e1dc50ad773aa3f9d95b2810857a3e7ce943
Author: Max Horn (max at quendi.de)
Date: 2011-05-23T10:12:25-07:00
Commit Message:
SWORD25: Avoid including lua headers in other headers
Changed paths:
engines/sword25/math/vertex.h
engines/sword25/script/luascript.h
diff --git a/engines/sword25/math/vertex.h b/engines/sword25/math/vertex.h
index 817f48e..4cb0eac 100644
--- a/engines/sword25/math/vertex.h
+++ b/engines/sword25/math/vertex.h
@@ -43,7 +43,8 @@
#include <math.h>
#include "common/rect.h"
#include "sword25/kernel/common.h"
-#include "sword25/util/lua/lua.h"
+
+struct lua_State;
#if defined(MACOSX) || defined(SOLARIS) || defined(__MINGW32__)
#define sqrtf(x) ((float)sqrt(x))
diff --git a/engines/sword25/script/luascript.h b/engines/sword25/script/luascript.h
index f3530d6..cd6d0e8 100644
--- a/engines/sword25/script/luascript.h
+++ b/engines/sword25/script/luascript.h
@@ -36,7 +36,8 @@
#include "common/str-array.h"
#include "sword25/kernel/common.h"
#include "sword25/script/script.h"
-#include "sword25/util/lua/lua.h"
+
+struct lua_State;
namespace Sword25 {
Commit: 8e3aafd30d14bcd586cc06a525e2dc2a8298c7b2
https://github.com/scummvm/scummvm/commit/8e3aafd30d14bcd586cc06a525e2dc2a8298c7b2
Author: Max Horn (max at quendi.de)
Date: 2011-05-23T10:12:25-07:00
Commit Message:
COMMON: Provide our own implementations for scumm_str(n)icmp
This takes up a tiny little bit of extra binary size, but gets
rid of some awful #ifdef hackery.
Changed paths:
backends/platform/wince/missing/io.h
backends/platform/wince/portdefs.h
common/scummsys.h
common/str.cpp
test/common/str.h
diff --git a/backends/platform/wince/missing/io.h b/backends/platform/wince/missing/io.h
index 96bc6a9..de492ca 100644
--- a/backends/platform/wince/missing/io.h
+++ b/backends/platform/wince/missing/io.h
@@ -1,7 +1,6 @@
/* Header is not present in Windows CE SDK */
/* This stuff will live here until port configuration file is in place */
-#define stricmp _stricmp
#define strdup _strdup
#ifndef _FILE_DEFINED
diff --git a/backends/platform/wince/portdefs.h b/backends/platform/wince/portdefs.h
index 1f8b9bb..64aa80a 100644
--- a/backends/platform/wince/portdefs.h
+++ b/backends/platform/wince/portdefs.h
@@ -31,8 +31,6 @@ int isprint(int c);
int isspace(int c);
char *strrchr(const char *s, int c);
char *strdup(const char *s);
-int _stricmp(const char *string1, const char *string2);
-int stricmp(const char *string1, const char *string2);
void assert(void *expression);
void assert(int expression);
long int strtol(const char *nptr, char **endptr, int base);
@@ -53,8 +51,6 @@ void GetCurrentDirectory(int len, char *buf);
#include <math.h>
#undef GetCurrentDirectory
extern "C" void GetCurrentDirectory(int len, char *buf);
-#define stricmp _stricmp
-#define strnicmp _strnicmp
#define snprintf _snprintf
#define strdup _strdup
#define fopen wce_fopen
diff --git a/common/scummsys.h b/common/scummsys.h
index 2420349..5cf3ba4 100644
--- a/common/scummsys.h
+++ b/common/scummsys.h
@@ -107,21 +107,6 @@
#include "config.h"
#endif
-//
-// Define scumm_stricmp and scumm_strnicmp
-//
-#if defined(_WIN32_WCE) || defined(_MSC_VER)
- #define scumm_stricmp stricmp
- #define scumm_strnicmp _strnicmp
- #define snprintf _snprintf
-#elif defined(__MINGW32__) || defined(__GP32__) || defined(__DS__)
- #define scumm_stricmp stricmp
- #define scumm_strnicmp strnicmp
-#else
- #define scumm_stricmp strcasecmp
- #define scumm_strnicmp strncasecmp
-#endif
-
// In the following we configure various targets, in particular those
// which can't use our "configure" tool and hence don't use config.h.
@@ -404,6 +389,15 @@
#endif
+//
+// Define scumm_stricmp and scumm_strnicmp
+//
+extern int scumm_stricmp(const char *s1, const char *s2);
+extern int scumm_strnicmp(const char *s1, const char *s2, uint n);
+#if defined(_WIN32_WCE) || defined(_MSC_VER)
+ // FIXME: Why is this necessary?
+ #define snprintf _snprintf
+#endif
//
diff --git a/common/str.cpp b/common/str.cpp
index 08a6cb6..740e7b6 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -833,3 +833,36 @@ size_t strlcat(char *dst, const char *src, size_t size) {
}
} // End of namespace Common
+
+// Portable implementation of stricmp / strcasecmp / strcmpi.
+// TODO: Rename this to Common::strcasecmp
+int scumm_stricmp(const char *s1, const char *s2) {
+ byte l1, l2;
+ do {
+ // Don't use ++ inside tolower, in case the macro uses its
+ // arguments more than once.
+ l1 = (byte)*s1++;
+ l1 = tolower(l1);
+ l2 = (byte)*s2++;
+ l2 = tolower(l2);
+ } while (l1 == l2 && l1 != 0);
+ return l1 - l2;
+}
+
+// Portable implementation of strnicmp / strncasecmp / strncmpi.
+// TODO: Rename this to Common::strncasecmp
+int scumm_strnicmp(const char *s1, const char *s2, uint n) {
+ byte l1, l2;
+ do {
+ if (n-- == 0)
+ return 0; // no difference found so far -> signal equality
+
+ // Don't use ++ inside tolower, in case the macro uses its
+ // arguments more than once.
+ l1 = (byte)*s1++;
+ l1 = tolower(l1);
+ l2 = (byte)*s2++;
+ l2 = tolower(l2);
+ } while (l1 == l2 && l1 != 0);
+ return l1 - l2;
+}
diff --git a/test/common/str.h b/test/common/str.h
index 5d9fe29..0dee16a 100644
--- a/test/common/str.h
+++ b/test/common/str.h
@@ -378,4 +378,21 @@ class StringTestSuite : public CxxTest::TestSuite
TS_ASSERT_EQUALS(Common::strlcat(test4, appendString, 11), strlen(resultString));
TS_ASSERT_EQUALS(strcmp(test4, resultString), 0);
}
+
+ void test_scumm_stricmp() {
+ TS_ASSERT_EQUALS(scumm_stricmp("abCd", "abCd"), 0);
+ TS_ASSERT_EQUALS(scumm_stricmp("abCd", "ABCd"), 0);
+ TS_ASSERT_LESS_THAN(scumm_stricmp("abCd", "ABCe"), 0);
+ TS_ASSERT_LESS_THAN(scumm_stricmp("abCd", "ABCde"), 0);
+ }
+
+ void test_scumm_strnicmp() {
+ TS_ASSERT_EQUALS(scumm_strnicmp("abCd", "abCd", 3), 0);
+ TS_ASSERT_EQUALS(scumm_strnicmp("abCd", "ABCd", 4), 0);
+ TS_ASSERT_EQUALS(scumm_strnicmp("abCd", "ABCd", 5), 0);
+ TS_ASSERT_EQUALS(scumm_strnicmp("abCd", "ABCe", 3), 0);
+ TS_ASSERT_LESS_THAN(scumm_strnicmp("abCd", "ABCe", 4), 0);
+ TS_ASSERT_EQUALS(scumm_strnicmp("abCd", "ABCde", 4), 0);
+ TS_ASSERT_LESS_THAN(scumm_strnicmp("abCd", "ABCde", 5), 0);
+ }
};
Commit: e6c78b4f469729726561af44aa1df8259f0fdf27
https://github.com/scummvm/scummvm/commit/e6c78b4f469729726561af44aa1df8259f0fdf27
Author: Max Horn (max at quendi.de)
Date: 2011-05-23T10:12:25-07:00
Commit Message:
SWORD25: Include scummsys.h from lua.h, partially deal with the consequences
This should help mark the spots that are still non-portable, just follow
the FIXMEs.
Changed paths:
engines/sword25/util/lua/ldo.cpp
engines/sword25/util/lua/lmathlib.cpp
engines/sword25/util/lua/loadlib.cpp
engines/sword25/util/lua/loslib.cpp
engines/sword25/util/lua/lua.h
engines/sword25/util/lua/print.cpp
diff --git a/engines/sword25/util/lua/ldo.cpp b/engines/sword25/util/lua/ldo.cpp
index 07508fb..b039923 100644
--- a/engines/sword25/util/lua/ldo.cpp
+++ b/engines/sword25/util/lua/ldo.cpp
@@ -5,6 +5,14 @@
*/
+// FIXME: LUAI_THROW and LUAI_TRY use either throw/catch or setjmp/longjmp.
+// Neither of these is supported in ScummVM. So we need to come up
+// with a replacement. The most simple, direct and crude approach:
+// Replace "throw" with an "error()" call. Of course we only
+// would want to do that if this actually never happens...
+#define FORBIDDEN_SYMBOL_EXCEPTION_setjmp
+#define FORBIDDEN_SYMBOL_EXCEPTION_longjmp
+
#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
@@ -94,6 +102,11 @@ static void resetstack (lua_State *L, int status) {
void luaD_throw (lua_State *L, int errcode) {
if (L->errorJmp) {
L->errorJmp->status = errcode;
+ // FIXME: LUAI_THROW and LUAI_TRY use either throw/catch or setjmp/longjmp.
+ // Neither of these is supported in ScummVM. So we need to come up
+ // with a replacement. The most simple, direct and crude approach:
+ // Replace "throw" with an "error()" call. Of course we only
+ // would want to do that if this actually never happens...
LUAI_THROW(L, L->errorJmp);
}
else {
@@ -113,6 +126,11 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {
lj.status = 0;
lj.previous = L->errorJmp; /* chain new error handler */
L->errorJmp = &lj;
+ // FIXME: LUAI_THROW and LUAI_TRY use either throw/catch or setjmp/longjmp.
+ // Neither of these is supported in ScummVM. So we need to come up
+ // with a replacement. The most simple, direct and crude approach:
+ // Replace "throw" with an "error()" call. Of course we only
+ // would want to do that if this actually never happens...
LUAI_TRY(L, &lj,
(*f)(L, ud);
);
diff --git a/engines/sword25/util/lua/lmathlib.cpp b/engines/sword25/util/lua/lmathlib.cpp
index 7e64d75..6c36bbc 100644
--- a/engines/sword25/util/lua/lmathlib.cpp
+++ b/engines/sword25/util/lua/lmathlib.cpp
@@ -5,6 +5,10 @@
*/
+// FIXME: rand and srand should be replaced by a RandomSource
+#define FORBIDDEN_SYMBOL_EXCEPTION_rand
+#define FORBIDDEN_SYMBOL_EXCEPTION_srand
+
#include <stdlib.h>
// MSVC does not define M_PI, M_SQRT2 and other math defines by default.
// _USE_MATH_DEFINES must be defined in order to have these defined, thus
diff --git a/engines/sword25/util/lua/loadlib.cpp b/engines/sword25/util/lua/loadlib.cpp
index 2549e2b..2fa831a 100644
--- a/engines/sword25/util/lua/loadlib.cpp
+++ b/engines/sword25/util/lua/loadlib.cpp
@@ -8,6 +8,15 @@
** implementation for Windows, and a stub for other systems.
*/
+// FIXME: Avoid using these APIs.
+// Actually, this could be achieved by removing 80% of the remaining
+// code in this file. Most of it is an elaborate way of expressing
+// something like "return ERROR;" anyway, as we don't support loading
+// dynamic libs
+#define FORBIDDEN_SYMBOL_EXCEPTION_FILE
+#define FORBIDDEN_SYMBOL_EXCEPTION_fopen
+#define FORBIDDEN_SYMBOL_EXCEPTION_fclose
+
#include <stdlib.h>
#include <string.h>
@@ -39,13 +48,6 @@
#define ERRLIB 1
#define ERRFUNC 2
-#define setprogdir(L) ((void)0)
-
-
-static void ll_unloadlib (void *lib);
-static void *ll_load (lua_State *L, const char *path);
-static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym);
-
/*
** {======================================================
@@ -60,24 +62,6 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym);
#define DLMSG "dynamic libraries not enabled; check your Lua installation"
-static void ll_unloadlib (void *lib) {
- (void)lib; /* to avoid warnings */
-}
-
-
-static void *ll_load (lua_State *L, const char *path) {
- (void)path; /* to avoid warnings */
- lua_pushliteral(L, DLMSG);
- return NULL;
-}
-
-
-static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
- (void)lib; (void)sym; /* to avoid warnings */
- lua_pushliteral(L, DLMSG);
- return NULL;
-}
-
/* }====================================================== */
@@ -108,7 +92,6 @@ static void **ll_register (lua_State *L, const char *path) {
*/
static int gctm (lua_State *L) {
void **lib = (void **)luaL_checkudata(L, 1, "_LOADLIB");
- if (*lib) ll_unloadlib(*lib);
*lib = NULL; /* mark library as closed */
return 0;
}
@@ -116,15 +99,11 @@ static int gctm (lua_State *L) {
static int ll_loadfunc (lua_State *L, const char *path, const char *sym) {
void **reg = ll_register(L, path);
- if (*reg == NULL) *reg = ll_load(L, path);
- if (*reg == NULL)
+ if (*reg == NULL) {
+ lua_pushliteral(L, DLMSG); // loading not supported, just push an error msg
return ERRLIB; /* unable to load library */
- else {
- lua_CFunction f = ll_sym(L, *reg, sym);
- if (f == NULL)
- return ERRFUNC; /* unable to find function */
- lua_pushcfunction(L, f);
- return 0; /* return function */
+ } else {
+ return ERRFUNC; /* unable to find function */
}
}
@@ -407,23 +386,11 @@ static int ll_seeall (lua_State *L) {
-/* auxiliary mark (for internal use) */
-#define AUXMARK "\1"
-
static void setpath (lua_State *L, const char *fieldname, const char *envname,
const char *def) {
- const char *path = getenv(envname);
- if (path == NULL) /* no environment variable? */
- lua_pushstring(L, def); /* use default */
- else {
- /* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */
- path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP,
- LUA_PATHSEP AUXMARK LUA_PATHSEP);
- luaL_gsub(L, path, AUXMARK, def);
- lua_remove(L, -2);
- }
- setprogdir(L);
- lua_setfield(L, -2, fieldname);
+ // no environment variable -> use default
+ lua_pushstring(L, def);
+ lua_setfield(L, -2, fieldname);
}
diff --git a/engines/sword25/util/lua/loslib.cpp b/engines/sword25/util/lua/loslib.cpp
index ac634db..c46aea5 100644
--- a/engines/sword25/util/lua/loslib.cpp
+++ b/engines/sword25/util/lua/loslib.cpp
@@ -4,6 +4,9 @@
** See Copyright Notice in lua.h
*/
+// FIXME: Get rid of all time.h stuff
+#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
+
#include <time.h>
#define loslib_c
@@ -14,9 +17,6 @@
#include "lauxlib.h"
#include "lualib.h"
-// FIXME: Get rid of all time.h stuff
-#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
-
#include "common/system.h"
diff --git a/engines/sword25/util/lua/lua.h b/engines/sword25/util/lua/lua.h
index 088a511..417cdad 100644
--- a/engines/sword25/util/lua/lua.h
+++ b/engines/sword25/util/lua/lua.h
@@ -9,6 +9,8 @@
#ifndef lua_h
#define lua_h
+#include "common/scummsys.h"
+
#include <stdarg.h>
#include <stddef.h>
diff --git a/engines/sword25/util/lua/print.cpp b/engines/sword25/util/lua/print.cpp
index 22039c9..70c6081 100644
--- a/engines/sword25/util/lua/print.cpp
+++ b/engines/sword25/util/lua/print.cpp
@@ -4,6 +4,9 @@
** See Copyright Notice in lua.h
*/
+// FIXME
+#define FORBIDDEN_SYMBOL_EXCEPTION_printf
+
#include <ctype.h>
#include <stdio.h>
Commit: 590c6ede63d9fa61d2b05ce74596b043f5c79bc8
https://github.com/scummvm/scummvm/commit/590c6ede63d9fa61d2b05ce74596b043f5c79bc8
Author: Max Horn (max at quendi.de)
Date: 2011-05-23T10:12:26-07:00
Commit Message:
BACKENDS: Move SCUMMVM_SAVEPATH env var handling to POSIX savefile manager
Changed paths:
backends/saves/posix/posix-saves.cpp
base/commandLine.cpp
diff --git a/backends/saves/posix/posix-saves.cpp b/backends/saves/posix/posix-saves.cpp
index d82f8a1..37545c7 100644
--- a/backends/saves/posix/posix-saves.cpp
+++ b/backends/saves/posix/posix-saves.cpp
@@ -21,7 +21,8 @@
*/
-// Enable mkdir
+// Enable getenv, mkdir and time.h stuff
+#define FORBIDDEN_SYMBOL_EXCEPTION_getenv
#define FORBIDDEN_SYMBOL_EXCEPTION_mkdir
#define FORBIDDEN_SYMBOL_EXCEPTION_time_h //On IRIX, sys/stat.h includes sys/time.h
@@ -59,6 +60,27 @@ POSIXSaveFileManager::POSIXSaveFileManager() {
savePath += "/" DEFAULT_SAVE_PATH;
ConfMan.registerDefault("savepath", savePath);
}
+
+ // The user can override the savepath with the SCUMMVM_SAVEPATH
+ // environment variable. This is weaker than a --savepath on the
+ // command line, but overrides the default savepath.
+ //
+ // To ensure that the command line option (if given) has precedence,
+ // we only set the value in the transient domain if it is not
+ // yet present there.
+ if (!ConfMan.hasKey("savepath", Common::ConfigManager::kTransientDomain)) {
+ const char *dir = getenv("SCUMMVM_SAVEPATH");
+ if (dir && *dir && strlen(dir) < MAXPATHLEN) {
+ Common::FSNode saveDir(dir);
+ if (!saveDir.exists()) {
+ warning("Ignoring non-existent SCUMMVM_SAVEPATH '%s'", dir);
+ } else if (!saveDir.isWritable()) {
+ warning("Ignoring non-writable SCUMMVM_SAVEPATH '%s'", dir);
+ } else {
+ ConfMan.set("savepath", dir, Common::ConfigManager::kTransientDomain);
+ }
+ }
+ }
#endif
}
/*
diff --git a/base/commandLine.cpp b/base/commandLine.cpp
index 1ca4a64..f819b03 100644
--- a/base/commandLine.cpp
+++ b/base/commandLine.cpp
@@ -958,26 +958,6 @@ Common::Error processSettings(Common::String &command, Common::StringMap &settin
}
- // The user can override the savepath with the SCUMMVM_SAVEPATH
- // environment variable. This is weaker than a --savepath on the
- // command line, but overrides the default savepath, hence it is
- // handled here, just before the command line gets parsed.
-#if !defined(_WIN32_WCE) && !defined(__GP32__) && !defined(ANDROID)
- if (!settings.contains("savepath")) {
- const char *dir = getenv("SCUMMVM_SAVEPATH");
- if (dir && *dir && strlen(dir) < MAXPATHLEN) {
- Common::FSNode saveDir(dir);
- if (!saveDir.exists()) {
- warning("Non-existent SCUMMVM_SAVEPATH save path. It will be ignored");
- } else if (!saveDir.isWritable()) {
- warning("Non-writable SCUMMVM_SAVEPATH save path. It will be ignored");
- } else {
- settings["savepath"] = dir;
- }
- }
- }
-#endif
-
// Finally, store the command line settings into the config manager.
for (Common::StringMap::const_iterator x = settings.begin(); x != settings.end(); ++x) {
Common::String key(x->_key);
Commit: 6f6051a9e1da4d4debc1bf851b101c7a40d8b531
https://github.com/scummvm/scummvm/commit/6f6051a9e1da4d4debc1bf851b101c7a40d8b531
Author: Max Horn (max at quendi.de)
Date: 2011-05-23T10:12:26-07:00
Commit Message:
COMMON: Mark more symbols as forbidden
Changed paths:
backends/fs/posix/posix-fs.cpp
backends/platform/sdl/posix/posix.cpp
common/forbidden.h
diff --git a/backends/fs/posix/posix-fs.cpp b/backends/fs/posix/posix-fs.cpp
index 4d69a51..7f2ca69 100644
--- a/backends/fs/posix/posix-fs.cpp
+++ b/backends/fs/posix/posix-fs.cpp
@@ -26,6 +26,7 @@
#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
#define FORBIDDEN_SYMBOL_EXCEPTION_unistd_h
#define FORBIDDEN_SYMBOL_EXCEPTION_mkdir
+#define FORBIDDEN_SYMBOL_EXCEPTION_getenv
#include "backends/fs/posix/posix-fs.h"
#include "backends/fs/stdiostream.h"
diff --git a/backends/platform/sdl/posix/posix.cpp b/backends/platform/sdl/posix/posix.cpp
index 84bbf55..4dd0039 100644
--- a/backends/platform/sdl/posix/posix.cpp
+++ b/backends/platform/sdl/posix/posix.cpp
@@ -20,6 +20,7 @@
*
*/
+#define FORBIDDEN_SYMBOL_EXCEPTION_getenv
#define FORBIDDEN_SYMBOL_EXCEPTION_mkdir
#define FORBIDDEN_SYMBOL_EXCEPTION_time_h //On IRIX, sys/stat.h includes sys/time.h
diff --git a/common/forbidden.h b/common/forbidden.h
index d769ff3..d9282b7 100644
--- a/common/forbidden.h
+++ b/common/forbidden.h
@@ -140,6 +140,26 @@
#define system(a) FORBIDDEN_SYMBOL_REPLACEMENT
#endif
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_getenv
+#undef getenv
+#define getenv(a) FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_putenv
+#undef putenv
+#define putenv(a) FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_setenv
+#undef setenv
+#define setenv(a,b,c) FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_unsetenv
+#undef unsetenv
+#define unsetenv(a) FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
//
// Disable various symbols from time.h
@@ -281,6 +301,27 @@
#endif
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_stricmp
+#undef stricmp
+#define stricmp(a,b) FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_strnicmp
+#undef strnicmp
+#define strnicmp(a,b,c) FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_strcasecmp
+#undef strcasecmp
+#define strcasecmp(a,b) FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_strncasecmp
+#undef strncasecmp
+#define strncasecmp(a,b,c) FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
+
/*
* We also would like to disable the following symbols;
* however, these are also frequently used in regular code,
Commit: 20cad6e8b6fe9ae843245697e872256c4ca1e545
https://github.com/scummvm/scummvm/commit/20cad6e8b6fe9ae843245697e872256c4ca1e545
Author: Max Horn (max at quendi.de)
Date: 2011-05-23T10:39:25-07:00
Commit Message:
COMMON: Modify Base::processSettings, get rid of Common::kArgumentNotProcessed
Instead of defining a hacked up Common::Error code, split the return
value of processSettings into two parts: An error code, and a value
which indicates whether the specified command was completely handled
by processSettings or not.
Changed paths:
base/commandLine.cpp
base/commandLine.h
base/main.cpp
common/error.cpp
common/error.h
common/forbidden.h
common/textconsole.cpp
diff --git a/base/commandLine.cpp b/base/commandLine.cpp
index f819b03..78eea50 100644
--- a/base/commandLine.cpp
+++ b/base/commandLine.cpp
@@ -23,6 +23,8 @@
// FIXME: Avoid using printf
#define FORBIDDEN_SYMBOL_EXCEPTION_printf
+#define FORBIDDEN_SYMBOL_EXCEPTION_exit
+
#include "engines/metaengine.h"
#include "base/commandLine.h"
#include "base/plugins.h"
@@ -885,7 +887,8 @@ Common::String parseCommandLine(Common::StringMap &settings, int argc, const cha
#endif // DISABLE_COMMAND_LINE
-Common::Error processSettings(Common::String &command, Common::StringMap &settings) {
+bool processSettings(Common::String &command, Common::StringMap &settings, Common::Error &err) {
+ err = Common::kNoError;
#ifndef DISABLE_COMMAND_LINE
@@ -894,33 +897,34 @@ Common::Error processSettings(Common::String &command, Common::StringMap &settin
// have been loaded.
if (command == "list-targets") {
listTargets();
- return Common::kNoError;
+ return true;
} else if (command == "list-games") {
listGames();
- return Common::kNoError;
+ return true;
} else if (command == "list-saves") {
- return listSaves(settings["list-saves"].c_str());
+ err = listSaves(settings["list-saves"].c_str());
+ return true;
} else if (command == "list-themes") {
listThemes();
- return Common::kNoError;
+ return true;
} else if (command == "version") {
printf("%s\n", gScummVMFullVersion);
printf("Features compiled in: %s\n", gScummVMFeatures);
- return Common::kNoError;
+ return true;
} else if (command == "help") {
printf(HELP_STRING, s_appName);
- return Common::kNoError;
+ return true;
}
#ifdef DETECTOR_TESTING_HACK
else if (command == "test-detector") {
runDetectorTest();
- return Common::kNoError;
+ return true;
}
#endif
#ifdef UPGRADE_ALL_TARGETS_HACK
else if (command == "upgrade-targets") {
upgradeTargets();
- return Common::kNoError;
+ return true;
}
#endif
@@ -972,7 +976,7 @@ Common::Error processSettings(Common::String &command, Common::StringMap &settin
ConfMan.set(key, value, Common::ConfigManager::kTransientDomain);
}
- return Common::kArgumentNotProcessed;
+ return false;
}
} // End of namespace Base
diff --git a/base/commandLine.h b/base/commandLine.h
index 4e611d9..2798ab0 100644
--- a/base/commandLine.h
+++ b/base/commandLine.h
@@ -32,9 +32,28 @@ class String;
namespace Base {
+/**
+ * Register various defaults with the ConfigManager.
+ */
void registerDefaults();
+
+/**
+ * Parse the command line for options and a command; the options
+ * are stored in the map 'settings, the command (if any) is returned.
+ */
Common::String parseCommandLine(Common::StringMap &settings, int argc, const char * const *argv);
-Common::Error processSettings(Common::String &command, Common::StringMap &settings);
+
+/**
+ * Process the command line options and arguments.
+ * Returns true if everything was handled and ScummVM should quit
+ * (e.g. because "--help" was specified, and handled).
+ *
+ * @param[in] command the command as returned by parseCommandLine
+ * @param[in] settings the settings as returned by parseCommandLine
+ * @param[out] err indicates whether any error occurred, and which
+ * @return true if the command was completely processed and ScummVM should quit, false otherwise
+ */
+bool processSettings(Common::String &command, Common::StringMap &settings, Common::Error &err);
} // End of namespace Base
diff --git a/base/main.cpp b/base/main.cpp
index 4ed70a5..906f4c9 100644
--- a/base/main.cpp
+++ b/base/main.cpp
@@ -349,8 +349,7 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
Common::Error res;
// TODO: deal with settings that require plugins to be loaded
- res = Base::processSettings(command, settings);
- if (res.getCode() != Common::kArgumentNotProcessed) {
+ if (Base::processSettings(command, settings, res)) {
if (res.getCode() != Common::kNoError)
warning("%s", res.getDesc().c_str());
return res.getCode();
diff --git a/common/error.cpp b/common/error.cpp
index f150f26..a6c52a0 100644
--- a/common/error.cpp
+++ b/common/error.cpp
@@ -67,9 +67,6 @@ static String errorToString(ErrorCode errorCode) {
case kEnginePluginNotSupportSaves:
return _s("Engine plugin does not support save states");
- case kArgumentNotProcessed:
- return _s("Command line argument not processed");
-
case kUnknownError:
default:
return _s("Unknown error");
diff --git a/common/error.h b/common/error.h
index c06cec4..23c12b6 100644
--- a/common/error.h
+++ b/common/error.h
@@ -47,7 +47,6 @@ enum ErrorCode {
kUnsupportedGameidError, ///< Engine initialization: Gameid not supported by this (Meta)Engine
kUnsupportedColorMode, ///< Engine initialization: Engine does not support backend's color mode
-
kReadPermissionDenied, ///< Unable to read data due to missing read permission
kWritePermissionDenied, ///< Unable to write data due to missing write permission
@@ -63,8 +62,6 @@ enum ErrorCode {
kEnginePluginNotFound, ///< Failed to find plugin to handle target
kEnginePluginNotSupportSaves, ///< Failed if plugin does not support listing save states
- kArgumentNotProcessed, ///< Used in command line parsing
-
kUnknownError ///< Catch-all error, used if no other error code matches
};
diff --git a/common/forbidden.h b/common/forbidden.h
index d9282b7..f127983 100644
--- a/common/forbidden.h
+++ b/common/forbidden.h
@@ -140,6 +140,11 @@
#define system(a) FORBIDDEN_SYMBOL_REPLACEMENT
#endif
+#ifndef FORBIDDEN_SYMBOL_EXCEPTION_exit
+#undef exit
+#define exit(a) FORBIDDEN_SYMBOL_REPLACEMENT
+#endif
+
#ifndef FORBIDDEN_SYMBOL_EXCEPTION_getenv
#undef getenv
#define getenv(a) FORBIDDEN_SYMBOL_REPLACEMENT
diff --git a/common/textconsole.cpp b/common/textconsole.cpp
index 0bd233d..f2325ac 100644
--- a/common/textconsole.cpp
+++ b/common/textconsole.cpp
@@ -19,6 +19,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#define FORBIDDEN_SYMBOL_EXCEPTION_exit
+
#include "common/textconsole.h"
#include "common/system.h"
#include "common/str.h"
Commit: 6c5f50c246062bcb50a20efe7951be7e23449ca0
https://github.com/scummvm/scummvm/commit/6c5f50c246062bcb50a20efe7951be7e23449ca0
Author: Max Horn (max at quendi.de)
Date: 2011-05-23T10:39:26-07:00
Commit Message:
COMMON: Add exit() to list of forbidden symbols
Changed paths:
backends/modular-backend.cpp
backends/modular-backend.h
backends/platform/sdl/sdl.cpp
engines/agi/loader_v2.cpp
engines/sci/console.cpp
engines/sword25/util/lua/ldo.cpp
engines/sword25/util/lua/loslib.cpp
diff --git a/backends/modular-backend.cpp b/backends/modular-backend.cpp
index fe3991a..c5f147f 100644
--- a/backends/modular-backend.cpp
+++ b/backends/modular-backend.cpp
@@ -20,6 +20,8 @@
*
*/
+#define FORBIDDEN_SYMBOL_EXCEPTION_exit
+
#include "backends/modular-backend.h"
#include "backends/fs/fs-factory.h"
@@ -277,3 +279,7 @@ FilesystemFactory *ModularBackend::getFilesystemFactory() {
assert(_fsFactory);
return _fsFactory;
}
+
+void ModularBackend::quit() {
+ exit(0);
+}
diff --git a/backends/modular-backend.h b/backends/modular-backend.h
index 43148b6..e46fbfd 100644
--- a/backends/modular-backend.h
+++ b/backends/modular-backend.h
@@ -148,8 +148,7 @@ public:
virtual Common::SaveFileManager *getSavefileManager();
virtual FilesystemFactory *getFilesystemFactory();
- virtual void quit() { exit(0); }
- virtual void setWindowCaption(const char *caption) {}
+ virtual void quit();
virtual void displayMessageOnOSD(const char *msg);
//@}
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 5cb4097..a3fb719 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -21,6 +21,7 @@
*/
#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
+#define FORBIDDEN_SYMBOL_EXCEPTION_exit
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
diff --git a/engines/agi/loader_v2.cpp b/engines/agi/loader_v2.cpp
index f5f8830..a2ac6f0 100644
--- a/engines/agi/loader_v2.cpp
+++ b/engines/agi/loader_v2.cpp
@@ -149,11 +149,11 @@ uint8 *AgiLoader_v2::loadVolRes(struct AgiDir *agid) {
fp.read(&x, 5);
if ((sig = READ_BE_UINT16((uint8 *) x)) == 0x1234) {
agid->len = READ_LE_UINT16((uint8 *) x + 3);
- data = (uint8 *) calloc(1, agid->len + 32);
+ data = (uint8 *)calloc(1, agid->len + 32);
if (data != NULL) {
fp.read(data, agid->len);
} else {
- exit(1);
+ error("AgiLoader_v2::loadVolRes out of memory");
}
} else {
warning("AgiLoader_v2::loadVolRes: bad signature %04x", sig);
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp
index 5f5af19..e6b5c3c 100644
--- a/engines/sci/console.cpp
+++ b/engines/sci/console.cpp
@@ -3372,7 +3372,7 @@ bool Console::cmdQuit(int argc, const char **argv) {
} else if (!scumm_stricmp(argv[1], "now")) {
// Quit ungracefully
- exit(0);
+ g_system->quit();
}
return Cmd_Exit(0, 0);
diff --git a/engines/sword25/util/lua/ldo.cpp b/engines/sword25/util/lua/ldo.cpp
index b039923..b699c5d 100644
--- a/engines/sword25/util/lua/ldo.cpp
+++ b/engines/sword25/util/lua/ldo.cpp
@@ -13,6 +13,8 @@
#define FORBIDDEN_SYMBOL_EXCEPTION_setjmp
#define FORBIDDEN_SYMBOL_EXCEPTION_longjmp
+#include "common/textconsole.h"
+
#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
@@ -116,7 +118,7 @@ void luaD_throw (lua_State *L, int errcode) {
lua_unlock(L);
G(L)->panic(L);
}
- exit(EXIT_FAILURE);
+ error("luaD_throw failure");
}
}
diff --git a/engines/sword25/util/lua/loslib.cpp b/engines/sword25/util/lua/loslib.cpp
index c46aea5..b61f8c6 100644
--- a/engines/sword25/util/lua/loslib.cpp
+++ b/engines/sword25/util/lua/loslib.cpp
@@ -18,6 +18,7 @@
#include "lualib.h"
#include "common/system.h"
+#include "common/textconsole.h"
static int os_execute (lua_State *L) {
@@ -214,10 +215,9 @@ static int os_exit (lua_State *L) {
// Using OSystem::quit() isn't really a great idea, either.
// We really would prefer to let the main run loop exit, so that
// our main() can perform cleanup.
- g_system->quit();
- // leave the exit call in there for now, in case some of our
- // OSystem::quit applications are incorrect... *sigh*
- exit(luaL_optint(L, 1, EXIT_SUCCESS));
+ if (0 == luaL_optint(L, 1, EXIT_SUCCESS))
+ g_system->quit();
+ error("LUA os_exit invokes with non-zero exit value");
}
static const luaL_Reg syslib[] = {
More information about the Scummvm-git-logs
mailing list