summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-12-10 16:03:12 +0000
committerrubidium <rubidium@openttd.org>2011-12-10 16:03:12 +0000
commitc06a3555fb7c8eb5bb6af81bc92fe7479fbce193 (patch)
tree84ff8fde61be26df0a314dd4ba9cd49963507ee9 /src
parent7bb4a0b825f141e56541dbb7bd25787676125629 (diff)
downloadopenttd-c06a3555fb7c8eb5bb6af81bc92fe7479fbce193.tar.xz
(svn r23478) -Codechange: add a method to copy string parameters *and* its raw strings
Diffstat (limited to 'src')
-rw-r--r--src/strings.cpp26
-rw-r--r--src/strings_func.h1
2 files changed, 26 insertions, 1 deletions
diff --git a/src/strings.cpp b/src/strings.cpp
index d34d053fa..3bcd21d1e 100644
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -96,6 +96,30 @@ void CopyOutDParam(uint64 *dst, int offs, int num)
MemCpyT(dst, _global_string_params.GetPointerToOffset(offs), num);
}
+/**
+ * Copy \a num string parameters from the global string parameter array to the \a dst array.
+ * Furthermore clone raw string parameters into \a strings and amend the data in \a dst.
+ * @param dst Destination array of string parameters.
+ * @param strings Destination array for clone of the raw strings. Must be of same length as dst. Deallocation left to the caller.
+ * @param string The string used to determine where raw strings are and where there are no raw strings.
+ * @param num Number of string parameters to copy.
+ */
+void CopyOutDParam(uint64 *dst, const char **strings, StringID string, int num)
+{
+ char buf[DRAW_STRING_BUFFER];
+ GetString(buf, string, lastof(buf));
+
+ MemCpyT(dst, _global_string_params.GetPointerToOffset(0), num);
+ for (int i = 0; i < num; i++) {
+ if (_global_string_params.HasTypeInformation() && _global_string_params.GetTypeAtOffset(i) == SCC_RAW_STRING_POINTER) {
+ strings[i] = strdup((const char *)(size_t)_global_string_params.GetParam(i));
+ dst[i] = (size_t)strings[i];
+ } else {
+ strings[i] = NULL;
+ }
+ }
+}
+
static char *StationGetSpecialString(char *buff, int x, const char *last);
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char *last);
static char *GetSpecialNameString(char *buff, int ind, StringParameters *args, const char *last);
@@ -822,7 +846,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
break;
case SCC_RAW_STRING_POINTER: { // {RAW_STRING}
- const char *str = (const char *)(size_t)args->GetInt64();
+ const char *str = (const char *)(size_t)args->GetInt64(SCC_RAW_STRING_POINTER);
buff = FormatString(buff, str, args, last);
break;
}
diff --git a/src/strings_func.h b/src/strings_func.h
index 3f98ad48d..6d4398dad 100644
--- a/src/strings_func.h
+++ b/src/strings_func.h
@@ -168,6 +168,7 @@ void SetDParamStr(uint n, const char *str);
void CopyInDParam(int offs, const uint64 *src, int num);
void CopyOutDParam(uint64 *dst, int offs, int num);
+void CopyOutDParam(uint64 *dst, const char **strings, StringID string, int num);
/**
* Get the current string parameter at index \a n from parameter array \a s.