summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarkvater <Darkvater@openttd.org>2006-08-12 22:56:45 +0000
committerDarkvater <Darkvater@openttd.org>2006-08-12 22:56:45 +0000
commitbc5de7808a70246d110e3032d7f12c65383c7c7d (patch)
tree777f080b4836af7c585e67cfed624533e20c5e47
parentf0a476e7cae49de89c0fd081fa267dfac9b60471 (diff)
downloadopenttd-bc5de7808a70246d110e3032d7f12c65383c7c7d.tar.xz
(svn r5871) -Feature: Add a possibility to handle pointer strings without a buffer from the configuration file. Handy for variables that will never be changed during runtime
-rw-r--r--saveload.c4
-rw-r--r--saveload.h10
-rw-r--r--settings.c17
3 files changed, 24 insertions, 7 deletions
diff --git a/saveload.c b/saveload.c
index 59de6f24a..d1e0cc7db 100644
--- a/saveload.c
+++ b/saveload.c
@@ -510,11 +510,13 @@ static inline size_t SlCalcStringLen(const char *ptr, uint length)
* Save/Load a string.
* @param ptr the string being manipulated
* @param the length of the string (full length)
- * @param conv must be SLE_FILE_STRING */
+ * @param conv must be SLE_FILE_STRING
+ * XXX - only works with global strings of a pre-allocated buffer */
static void SlString(void *ptr, uint length, VarType conv)
{
uint len;
assert(GetVarFileType(conv) == SLE_FILE_STRING);
+ assert(GetVarMemType(conv) == SLE_VAR_STRB || GetVarMemType(conv) == SLE_VAR_STRQ);
if (_sl.save) {
len = SlCalcNetStringLen(ptr, length);
diff --git a/saveload.h b/saveload.h
index 1a7fc82e2..9b2ba8b4a 100644
--- a/saveload.h
+++ b/saveload.h
@@ -98,8 +98,10 @@ enum VarTypes {
SLE_VAR_U64 = 8 << 4,
SLE_VAR_NULL = 9 << 4, ///< useful to write zeros in savegame.
SLE_VAR_STRB = 10 << 4, ///< normal string (with pre-allocated buffer)
- SLE_VAR_STRQ = 11 << 4, ///< string enclosed in parentheses
- /* 4 more possible memory-primitives */
+ SLE_VAR_STRBQ= 11 << 4, ///< string enclosed in parentheses (with pre-allocated buffer)
+ SLE_VAR_STR = 12 << 4, ///< string pointer
+ SLE_VAR_STRQ = 13 << 4, ///< string enclosed in parentheses
+ /* 2 more possible memory-primitives */
/* Shortcut values */
SLE_VAR_CHAR = SLE_VAR_I8,
@@ -119,12 +121,16 @@ enum VarTypes {
SLE_CHAR = SLE_FILE_I8 | SLE_VAR_CHAR,
SLE_STRINGID = SLE_FILE_STRINGID | SLE_VAR_U16,
SLE_STRINGBUF = SLE_FILE_STRING | SLE_VAR_STRB,
+ SLE_STRINGBQUOTE= SLE_FILE_STRING | SLE_VAR_STRBQ,
+ SLE_STRING = SLE_FILE_STRING | SLE_VAR_STR,
SLE_STRINGQUOTE = SLE_FILE_STRING | SLE_VAR_STRQ,
/* Shortcut values */
SLE_UINT = SLE_UINT32,
SLE_INT = SLE_INT32,
SLE_STRB = SLE_STRINGBUF,
+ SLE_STRBQ= SLE_STRINGBQUOTE,
+ SLE_STR = SLE_STRING,
SLE_STRQ = SLE_STRINGQUOTE,
/* 8 bytes allocated for a maximum of 8 flags
diff --git a/settings.c b/settings.c
index 4e8cc5cf1..5e7faae11 100644
--- a/settings.c
+++ b/settings.c
@@ -695,9 +695,16 @@ static void ini_load_settings(IniFile *ini, const SettingDesc *sd, const char *g
case SDT_STRING:
switch (GetVarMemType(sld->conv)) {
case SLE_VAR_STRB:
- case SLE_VAR_STRQ:
+ case SLE_VAR_STRBQ:
if (p != NULL) ttd_strlcpy((char*)ptr, p, sld->length);
break;
+ case SLE_VAR_STR:
+ case SLE_VAR_STRQ:
+ if (p != NULL) {
+ free(*(char**)ptr);
+ *(char**)ptr = strdup((const char*)p);
+ }
+ break;
case SLE_VAR_CHAR: *(char*)ptr = *(char*)p; break;
default: NOT_REACHED(); break;
}
@@ -806,7 +813,9 @@ static void ini_save_settings(IniFile *ini, const SettingDesc *sd, const char *g
case SDT_STRING:
switch (GetVarMemType(sld->conv)) {
case SLE_VAR_STRB: strcpy(buf, (char*)ptr); break;
- case SLE_VAR_STRQ: sprintf(buf, "\"%s\"", (char*)ptr); break;
+ case SLE_VAR_STRBQ:sprintf(buf, "\"%s\"", (char*)ptr); break;
+ case SLE_VAR_STR: strcpy(buf, *(char**)ptr); break;
+ case SLE_VAR_STRQ: sprintf(buf, "\"%s\"", *(char**)ptr); break;
case SLE_VAR_CHAR: sprintf(buf, "\"%c\"", *(char*)ptr); break;
default: NOT_REACHED();
}
@@ -1431,8 +1440,8 @@ static const SettingDesc _currency_settings[] = {
SDT_VAR(CurrencySpec, rate, SLE_UINT16, S, 0, 1, 0, 100, STR_NULL, NULL),
SDT_CHR(CurrencySpec, separator, S, 0, ".", STR_NULL, NULL),
SDT_VAR(CurrencySpec, to_euro, SLE_UINT16, S, 0, 0, 0,1000, STR_NULL, NULL),
- SDT_STR(CurrencySpec, prefix, SLE_STRQ, S, 0, NULL, STR_NULL, NULL),
- SDT_STR(CurrencySpec, suffix, SLE_STRQ, S, 0, " credits", STR_NULL, NULL),
+ SDT_STR(CurrencySpec, prefix, SLE_STRBQ, S, 0, NULL, STR_NULL, NULL),
+ SDT_STR(CurrencySpec, suffix, SLE_STRBQ, S, 0, " credits", STR_NULL, NULL),
SDT_END()
};