summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-01-18 15:41:38 +0000
committerrubidium <rubidium@openttd.org>2010-01-18 15:41:38 +0000
commitb1bd1067032c51a8d88818488c924c82a8678454 (patch)
treebaffff9722b0568418812cc9eff052edae02f715
parenta39a446e8faf99568eb8924535fd0034db00bb8e (diff)
downloadopenttd-b1bd1067032c51a8d88818488c924c82a8678454.tar.xz
(svn r18862) -Fix [FS#3544]: don't pass AI strings through iconv
-rw-r--r--src/ai/ai_info.cpp12
-rw-r--r--src/ai/ai_info_dummy.cpp2
-rw-r--r--src/ai/ai_instance.cpp10
-rw-r--r--src/ai/ai_scanner.cpp14
-rw-r--r--src/script/squirrel.cpp24
-rw-r--r--src/script/squirrel.hpp4
-rw-r--r--src/script/squirrel_helper.hpp10
-rw-r--r--src/script/squirrel_std.cpp2
-rw-r--r--src/stdafx.h4
9 files changed, 43 insertions, 39 deletions
diff --git a/src/ai/ai_info.cpp b/src/ai/ai_info.cpp
index 06fdc88ef..1b5ad51f1 100644
--- a/src/ai/ai_info.cpp
+++ b/src/ai/ai_info.cpp
@@ -173,12 +173,12 @@ SQInteger AIInfo::AddSetting(HSQUIRRELVM vm)
while (SQ_SUCCEEDED(sq_next(vm, -2))) {
const SQChar *sqkey;
if (SQ_FAILED(sq_getstring(vm, -2, &sqkey))) return SQ_ERROR;
- const char *key = FS2OTTD(sqkey);
+ const char *key = SQ2OTTD(sqkey);
if (strcmp(key, "name") == 0) {
const SQChar *sqvalue;
if (SQ_FAILED(sq_getstring(vm, -1, &sqvalue))) return SQ_ERROR;
- char *name = strdup(FS2OTTD(sqvalue));
+ char *name = strdup(SQ2OTTD(sqvalue));
char *s;
/* Don't allow '=' and ',' in configure setting names, as we need those
* 2 chars to nicely store the settings as a string. */
@@ -189,7 +189,7 @@ SQInteger AIInfo::AddSetting(HSQUIRRELVM vm)
} else if (strcmp(key, "description") == 0) {
const SQChar *sqdescription;
if (SQ_FAILED(sq_getstring(vm, -1, &sqdescription))) return SQ_ERROR;
- config.description = strdup(FS2OTTD(sqdescription));
+ config.description = strdup(SQ2OTTD(sqdescription));
items |= 0x002;
} else if (strcmp(key, "min_value") == 0) {
SQInteger res;
@@ -274,7 +274,7 @@ SQInteger AIInfo::AddLabels(HSQUIRRELVM vm)
{
const SQChar *sq_setting_name;
if (SQ_FAILED(sq_getstring(vm, -2, &sq_setting_name))) return SQ_ERROR;
- const char *setting_name = FS2OTTD(sq_setting_name);
+ const char *setting_name = SQ2OTTD(sq_setting_name);
AIConfigItem *config = NULL;
for (AIConfigItemList::iterator it = this->config_list.begin(); it != this->config_list.end(); it++) {
@@ -300,9 +300,9 @@ SQInteger AIInfo::AddLabels(HSQUIRRELVM vm)
if (SQ_FAILED(sq_getstring(vm, -1, &sq_label))) return SQ_ERROR;
/* Because squirrel doesn't support identifiers starting with a digit,
* we skip the first character. */
- const char *key_string = FS2OTTD(sq_key);
+ const char *key_string = SQ2OTTD(sq_key);
int key = atoi(key_string + 1);
- const char *label = FS2OTTD(sq_label);
+ const char *label = SQ2OTTD(sq_label);
if (config->labels->Find(key) == config->labels->End()) config->labels->Insert(key, strdup(label));
diff --git a/src/ai/ai_info_dummy.cpp b/src/ai/ai_info_dummy.cpp
index 08307ca7c..f38832310 100644
--- a/src/ai/ai_info_dummy.cpp
+++ b/src/ai/ai_info_dummy.cpp
@@ -94,7 +94,7 @@ void AI_CreateAIDummy(HSQUIRRELVM vm)
/* 3) We translate the error message in the character format that Squirrel wants.
* We can use the fact that the wchar string printing also uses %s to print
* old style char strings, which is what was generated during the script generation. */
- const SQChar *sq_dummy_script = OTTD2FS(dummy_script);
+ const SQChar *sq_dummy_script = OTTD2SQ(dummy_script);
/* And finally we load and run the script */
sq_pushroottable(vm);
diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp
index d321214b0..95250fd6c 100644
--- a/src/ai/ai_instance.cpp
+++ b/src/ai/ai_instance.cpp
@@ -90,7 +90,7 @@ AIStorage::~AIStorage()
static void PrintFunc(bool error_msg, const SQChar *message)
{
/* Convert to OpenTTD internal capable string */
- AIController::Print(error_msg, FS2OTTD(message));
+ AIController::Print(error_msg, SQ2OTTD(message));
}
AIInstance::AIInstance(AIInfo *info) :
@@ -493,9 +493,9 @@ enum {
}
const SQChar *res;
sq_getstring(vm, index, &res);
- /* @bug if a string longer than 512 characters is given to FS2OTTD, the
+ /* @bug if a string longer than 512 characters is given to SQ2OTTD, the
* internal buffer overflows. */
- const char *buf = FS2OTTD(res);
+ const char *buf = SQ2OTTD(res);
size_t len = strlen(buf) + 1;
if (len >= 255) {
AILog::Error("Maximum string length is 254 chars. No data saved.");
@@ -673,7 +673,7 @@ void AIInstance::Save()
SlObject(NULL, _ai_byte);
static char buf[256];
SlArray(buf, _ai_sl_byte, SLE_CHAR);
- if (vm != NULL) sq_pushstring(vm, OTTD2FS(buf), -1);
+ if (vm != NULL) sq_pushstring(vm, OTTD2SQ(buf), -1);
return true;
}
@@ -760,7 +760,7 @@ bool AIInstance::CallLoad()
/* Go to the instance-root */
sq_pushobject(vm, *this->instance);
/* Find the function-name inside the script */
- sq_pushstring(vm, OTTD2FS("Load"), -1);
+ sq_pushstring(vm, OTTD2SQ("Load"), -1);
/* Change the "Load" string in a function pointer */
sq_get(vm, -2);
/* Push the main instance as "this" object */
diff --git a/src/ai/ai_scanner.cpp b/src/ai/ai_scanner.cpp
index dc3dd0d1b..6ae8c2e77 100644
--- a/src/ai/ai_scanner.cpp
+++ b/src/ai/ai_scanner.cpp
@@ -99,7 +99,7 @@ bool AIScanner::ImportLibrary(const char *library, const char *class_name, int v
} else {
snprintf(error, sizeof(error), "couldn't find library '%s' version %d. The latest version available is %d", library, version, (*iter).second->GetVersion());
}
- sq_throwerror(vm, OTTD2FS(error));
+ sq_throwerror(vm, OTTD2SQ(error));
return false;
}
@@ -116,13 +116,13 @@ bool AIScanner::ImportLibrary(const char *library, const char *class_name, int v
/* Load the library in a 'fake' namespace, so we can link it to the name the user requested */
sq_pushroottable(vm);
- sq_pushstring(vm, OTTD2FS(fake_class), -1);
+ sq_pushstring(vm, OTTD2SQ(fake_class), -1);
sq_newclass(vm, SQFalse);
/* Load the library */
if (!Squirrel::LoadScript(vm, (*iter).second->GetMainScript(), false)) {
char error[1024];
snprintf(error, sizeof(error), "there was a compile error when importing '%s' version %d", library, version);
- sq_throwerror(vm, OTTD2FS(error));
+ sq_throwerror(vm, OTTD2SQ(error));
return false;
}
/* Create the fake class */
@@ -134,16 +134,16 @@ bool AIScanner::ImportLibrary(const char *library, const char *class_name, int v
/* Find the real class inside the fake class (like 'sets.Vector') */
sq_pushroottable(vm);
- sq_pushstring(vm, OTTD2FS(fake_class), -1);
+ sq_pushstring(vm, OTTD2SQ(fake_class), -1);
if (SQ_FAILED(sq_get(vm, -2))) {
sq_throwerror(vm, _SC("internal error assigning library class"));
return false;
}
- sq_pushstring(vm, OTTD2FS((*iter).second->GetInstanceName()), -1);
+ sq_pushstring(vm, OTTD2SQ((*iter).second->GetInstanceName()), -1);
if (SQ_FAILED(sq_get(vm, -2))) {
char error[1024];
snprintf(error, sizeof(error), "unable to find class '%s' in the library '%s' version %d", (*iter).second->GetInstanceName(), library, version);
- sq_throwerror(vm, OTTD2FS(error));
+ sq_throwerror(vm, OTTD2SQ(error));
return false;
}
HSQOBJECT obj;
@@ -157,7 +157,7 @@ bool AIScanner::ImportLibrary(const char *library, const char *class_name, int v
/* Now link the name the user wanted to our 'fake' class */
sq_pushobject(vm, parent);
- sq_pushstring(vm, OTTD2FS(class_name), -1);
+ sq_pushstring(vm, OTTD2SQ(class_name), -1);
sq_pushobject(vm, obj);
sq_newclass(vm, SQTrue);
sq_newslot(vm, -3, SQFalse);
diff --git a/src/script/squirrel.cpp b/src/script/squirrel.cpp
index 090df3304..dea7c6232 100644
--- a/src/script/squirrel.cpp
+++ b/src/script/squirrel.cpp
@@ -118,7 +118,7 @@ void Squirrel::PrintFunc(HSQUIRRELVM vm, const SQChar *s, ...)
void Squirrel::AddMethod(const char *method_name, SQFUNCTION proc, uint nparam, const char *params, void *userdata, int size)
{
- sq_pushstring(this->vm, OTTD2FS(method_name), -1);
+ sq_pushstring(this->vm, OTTD2SQ(method_name), -1);
if (size != 0) {
void *ptr = sq_newuserdata(vm, size);
@@ -126,21 +126,21 @@ void Squirrel::AddMethod(const char *method_name, SQFUNCTION proc, uint nparam,
}
sq_newclosure(this->vm, proc, size != 0 ? 1 : 0);
- if (nparam != 0) sq_setparamscheck(this->vm, nparam, OTTD2FS(params));
- sq_setnativeclosurename(this->vm, -1, OTTD2FS(method_name));
+ if (nparam != 0) sq_setparamscheck(this->vm, nparam, OTTD2SQ(params));
+ sq_setnativeclosurename(this->vm, -1, OTTD2SQ(method_name));
sq_newslot(this->vm, -3, SQFalse);
}
void Squirrel::AddConst(const char *var_name, int value)
{
- sq_pushstring(this->vm, OTTD2FS(var_name), -1);
+ sq_pushstring(this->vm, OTTD2SQ(var_name), -1);
sq_pushinteger(this->vm, value);
sq_newslot(this->vm, -3, SQTrue);
}
void Squirrel::AddConst(const char *var_name, bool value)
{
- sq_pushstring(this->vm, OTTD2FS(var_name), -1);
+ sq_pushstring(this->vm, OTTD2SQ(var_name), -1);
sq_pushbool(this->vm, value);
sq_newslot(this->vm, -3, SQTrue);
}
@@ -148,15 +148,15 @@ void Squirrel::AddConst(const char *var_name, bool value)
void Squirrel::AddClassBegin(const char *class_name)
{
sq_pushroottable(this->vm);
- sq_pushstring(this->vm, OTTD2FS(class_name), -1);
+ sq_pushstring(this->vm, OTTD2SQ(class_name), -1);
sq_newclass(this->vm, SQFalse);
}
void Squirrel::AddClassBegin(const char *class_name, const char *parent_class)
{
sq_pushroottable(this->vm);
- sq_pushstring(this->vm, OTTD2FS(class_name), -1);
- sq_pushstring(this->vm, OTTD2FS(parent_class), -1);
+ sq_pushstring(this->vm, OTTD2SQ(class_name), -1);
+ sq_pushstring(this->vm, OTTD2SQ(parent_class), -1);
if (SQ_FAILED(sq_get(this->vm, -3))) {
DEBUG(misc, 0, "[squirrel] Failed to initialize class '%s' based on parent class '%s'", class_name, parent_class);
DEBUG(misc, 0, "[squirrel] Make sure that '%s' exists before trying to define '%s'", parent_class, class_name);
@@ -178,7 +178,7 @@ bool Squirrel::MethodExists(HSQOBJECT instance, const char *method_name)
/* Go to the instance-root */
sq_pushobject(this->vm, instance);
/* Find the function-name inside the script */
- sq_pushstring(this->vm, OTTD2FS(method_name), -1);
+ sq_pushstring(this->vm, OTTD2SQ(method_name), -1);
if (SQ_FAILED(sq_get(this->vm, -2))) {
sq_settop(this->vm, top);
return false;
@@ -217,7 +217,7 @@ bool Squirrel::CallMethod(HSQOBJECT instance, const char *method_name, HSQOBJECT
/* Go to the instance-root */
sq_pushobject(this->vm, instance);
/* Find the function-name inside the script */
- sq_pushstring(this->vm, OTTD2FS(method_name), -1);
+ sq_pushstring(this->vm, OTTD2SQ(method_name), -1);
if (SQ_FAILED(sq_get(this->vm, -2))) {
DEBUG(misc, 0, "[squirrel] Could not find '%s' in the class", method_name);
sq_settop(this->vm, top);
@@ -269,7 +269,7 @@ bool Squirrel::CallBoolMethod(HSQOBJECT instance, const char *method_name, bool
/* First, find the class */
sq_pushroottable(vm);
- sq_pushstring(vm, OTTD2FS(class_name), -1);
+ sq_pushstring(vm, OTTD2SQ(class_name), -1);
if (SQ_FAILED(sq_get(vm, -2))) {
DEBUG(misc, 0, "[squirrel] Failed to find class by the name '%s'", class_name);
sq_settop(vm, oldtop);
@@ -455,7 +455,7 @@ static SQInteger _io_file_read(SQUserPointer file, SQUserPointer buf, SQInteger
default: func = _io_file_lexfeed_ASCII; fseek(file, -2, SEEK_CUR); break; // ASCII
}
- if (SQ_SUCCEEDED(sq_compile(vm, func, &f, OTTD2FS(filename), printerror))) {
+ if (SQ_SUCCEEDED(sq_compile(vm, func, &f, OTTD2SQ(filename), printerror))) {
FioFCloseFile(file);
return SQ_OK;
}
diff --git a/src/script/squirrel.hpp b/src/script/squirrel.hpp
index 7d8e05dad..43aaa11fa 100644
--- a/src/script/squirrel.hpp
+++ b/src/script/squirrel.hpp
@@ -175,7 +175,7 @@ public:
/**
* Convert a Squirrel-object to a string.
*/
- static const char *ObjectToString(HSQOBJECT *ptr) { return FS2OTTD(sq_objtostring(ptr)); }
+ static const char *ObjectToString(HSQOBJECT *ptr) { return SQ2OTTD(sq_objtostring(ptr)); }
/**
* Convert a Squirrel-object to an integer.
@@ -206,7 +206,7 @@ public:
/**
* Throw a Squirrel error that will be nicely displayed to the user.
*/
- void ThrowError(const char *error) { sq_throwerror(this->vm, OTTD2FS(error)); }
+ void ThrowError(const char *error) { sq_throwerror(this->vm, OTTD2SQ(error)); }
/**
* Release a SQ object.
diff --git a/src/script/squirrel_helper.hpp b/src/script/squirrel_helper.hpp
index 61b8f1a18..67f8a21ce 100644
--- a/src/script/squirrel_helper.hpp
+++ b/src/script/squirrel_helper.hpp
@@ -87,8 +87,8 @@ namespace SQConvert {
template <> inline int Return<int64> (HSQUIRRELVM vm, int64 res) { sq_pushinteger(vm, ClampToI32(res)); return 1; }
template <> inline int Return<Money> (HSQUIRRELVM vm, Money res) { sq_pushinteger(vm, ClampToI32(res)); return 1; }
template <> inline int Return<bool> (HSQUIRRELVM vm, bool res) { sq_pushbool (vm, res); return 1; }
- template <> inline int Return<char *> (HSQUIRRELVM vm, char *res) { if (res == NULL) sq_pushnull(vm); else { sq_pushstring(vm, OTTD2FS(res), -1); free(res); } return 1; }
- template <> inline int Return<const char *>(HSQUIRRELVM vm, const char *res) { if (res == NULL) sq_pushnull(vm); else { sq_pushstring(vm, OTTD2FS(res), -1); } return 1; }
+ template <> inline int Return<char *> (HSQUIRRELVM vm, char *res) { if (res == NULL) sq_pushnull(vm); else { sq_pushstring(vm, OTTD2SQ(res), -1); free(res); } return 1; }
+ template <> inline int Return<const char *>(HSQUIRRELVM vm, const char *res) { if (res == NULL) sq_pushnull(vm); else { sq_pushstring(vm, OTTD2SQ(res), -1); } return 1; }
template <> inline int Return<void *> (HSQUIRRELVM vm, void *res) { sq_pushuserpointer(vm, res); return 1; }
/**
@@ -109,7 +109,7 @@ namespace SQConvert {
sq_tostring(vm, index);
const SQChar *tmp;
sq_getstring(vm, -1, &tmp);
- char *tmp_str = strdup(FS2OTTD(tmp));
+ char *tmp_str = strdup(SQ2OTTD(tmp));
sq_poptop(vm);
*ptr->Append() = (void *)tmp_str;
str_validate(tmp_str, tmp_str + strlen(tmp_str));
@@ -763,7 +763,7 @@ namespace SQConvert {
/* Protect against calls to a non-static method in a static way */
sq_pushroottable(vm);
- sq_pushstring(vm, OTTD2FS(Tcls::GetClassName()), -1);
+ sq_pushstring(vm, OTTD2SQ(Tcls::GetClassName()), -1);
sq_get(vm, -2);
sq_pushobject(vm, instance);
if (sq_instanceof(vm) != SQTrue) return sq_throwerror(vm, _SC("class method is non-static"));
@@ -805,7 +805,7 @@ namespace SQConvert {
/* Protect against calls to a non-static method in a static way */
sq_pushroottable(vm);
- sq_pushstring(vm, OTTD2FS(Tcls::GetClassName()), -1);
+ sq_pushstring(vm, OTTD2SQ(Tcls::GetClassName()), -1);
sq_get(vm, -2);
sq_pushobject(vm, instance);
if (sq_instanceof(vm) != SQTrue) return sq_throwerror(vm, _SC("class method is non-static"));
diff --git a/src/script/squirrel_std.cpp b/src/script/squirrel_std.cpp
index f831231d8..a95020fcc 100644
--- a/src/script/squirrel_std.cpp
+++ b/src/script/squirrel_std.cpp
@@ -67,7 +67,7 @@ SQInteger SquirrelStd::require(HSQUIRRELVM vm)
real_filename = ReallocT(real_filename, scstrlen(real_filename) + scstrlen(filename) + 1);
scstrcat(real_filename, filename);
/* Tars dislike opening files with '/' on Windows.. so convert it to '\\' ;) */
- char *filen = strdup(FS2OTTD(real_filename));
+ char *filen = strdup(SQ2OTTD(real_filename));
#if (PATHSEPCHAR != '/')
for (char *n = filen; *n != '\0'; n++) if (*n == '/') *n = PATHSEPCHAR;
#endif
diff --git a/src/stdafx.h b/src/stdafx.h
index 0b4a0ad8b..38d09b547 100644
--- a/src/stdafx.h
+++ b/src/stdafx.h
@@ -242,10 +242,14 @@
const char *FS2OTTD(const TCHAR *name);
const TCHAR *OTTD2FS(const char *name);
+ #define SQ2OTTD(name) FS2OTTD(name)
+ #define OTTD2SQ(name) OTTD2FS(name)
#else
#define fopen(file, mode) fopen(OTTD2FS(file), mode)
const char *FS2OTTD(const char *name);
const char *OTTD2FS(const char *name);
+ #define SQ2OTTD(name) (name)
+ #define OTTD2SQ(name) (name)
#endif /* WIN32 */
#endif /* STRGEN */