summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2007-08-03 09:08:49 +0000
committerpeter1138 <peter1138@openttd.org>2007-08-03 09:08:49 +0000
commit23a46a301e1d5c8d661bf0f823fbf5d29516a692 (patch)
treeb6337974657d183b3d4648de552643ab63470cc7
parentf95df6bb61f8e04bf146a8ebcd051b7e19820a82 (diff)
downloadopenttd-23a46a301e1d5c8d661bf0f823fbf5d29516a692.tar.xz
(svn r10762) -Codechange: Change enum StringIDEnum { to static const StringID = for
each STR_ entry. This avoids the need for a cast to StringID in some places and thus better type-safety.
-rw-r--r--src/command.h4
-rw-r--r--src/openttd.cpp2
-rw-r--r--src/openttd.h2
-rw-r--r--src/strgen/strgen.cpp11
-rw-r--r--src/strings.cpp4
5 files changed, 13 insertions, 10 deletions
diff --git a/src/command.h b/src/command.h
index 809fdab0f..65fc0c495 100644
--- a/src/command.h
+++ b/src/command.h
@@ -195,9 +195,9 @@ struct Command {
static inline bool CmdFailed(CommandCost cost) { return cost.Failed(); }
static inline bool CmdSucceeded(CommandCost cost) { return cost.Succeeded(); }
-static const CommandCost CMD_ERROR = CommandCost((StringID)INVALID_STRING_ID);
+static const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID);
-#define return_cmd_error(errcode) do { return CommandCost((StringID)(errcode)); } while (0)
+#define return_cmd_error(errcode) do { return CommandCost(errcode); } while (0)
/* command.cpp */
typedef void CommandCallback(bool success, TileIndex tile, uint32 p1, uint32 p2);
diff --git a/src/openttd.cpp b/src/openttd.cpp
index 757a79b45..2f5b4c8c9 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -5,7 +5,6 @@
#include "stdafx.h"
#define VARDEF
#include "string.h"
-#include "table/strings.h"
#include "debug.h"
#include "driver.h"
#include "saveload.h"
@@ -15,6 +14,7 @@
#include "helpers.hpp"
#include "openttd.h"
+#include "table/strings.h"
#include "strings.h"
#include "bridge_map.h"
#include "functions.h"
diff --git a/src/openttd.h b/src/openttd.h
index 7daf5b772..9fa72e915 100644
--- a/src/openttd.h
+++ b/src/openttd.h
@@ -51,7 +51,7 @@ struct PalSpriteID {
typedef uint16 EngineID;
typedef uint16 UnitID;
typedef uint16 StringID;
-#define INVALID_STRING_ID 0xFFFF
+static const StringID INVALID_STRING_ID = 0xFFFF;
typedef EngineID *EngineList; ///< engine list type placeholder acceptable for C code (see helpers.cpp)
diff --git a/src/strgen/strgen.cpp b/src/strgen/strgen.cpp
index c6eaa4466..cfae3814d 100644
--- a/src/strgen/strgen.cpp
+++ b/src/strgen/strgen.cpp
@@ -1019,19 +1019,20 @@ static void WriteStringsH(const char *filename)
out = fopen("tmp.xxx", "w");
if (out == NULL) fatal("can't open tmp.xxx");
- fprintf(out, "enum StringIdEnum {");
+ fprintf(out, "/* This file is automatically generated. Do not modify */\n\n");
+ fprintf(out, "#ifndef TABLE_STRINGS_H\n");
+ fprintf(out, "#define TABLE_STRINGS_H\n");
lastgrp = 0;
for (i = 0; i != lengthof(_strings); i++) {
if (_strings[i] != NULL) {
- fprintf(out, next == i ? "\t%s,\n" : "\n\t%s = 0x%X,\n", _strings[i]->name, i);
+ if (next != i) fprintf(out, "\n");
+ fprintf(out, "static const StringID %s = 0x%X;\n", _strings[i]->name, i);
next = i + 1;
}
}
- fprintf(out, "};\n");
-
fprintf(out,
"\nenum {\n"
"\tLANGUAGE_PACK_IDENT = 0x474E414C, // Big Endian value for 'LANG' (LE is 0x 4C 41 4E 47)\n"
@@ -1039,6 +1040,8 @@ static void WriteStringsH(const char *filename)
"};\n", (uint)_hash
);
+ fprintf(out, "\n#endif /* TABLE_STRINGS_H */\n");
+
fclose(out);
if (CompareFiles("tmp.xxx", filename)) {
diff --git a/src/strings.cpp b/src/strings.cpp
index c10855a0c..78df8facd 100644
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -696,7 +696,7 @@ static char* FormatString(char* buff, const char* str, const int64* argv, uint c
* 8bit - cargo type
* 16-bit - cargo count */
CargoID cargo = GetInt32(&argv);
- StringID cargo_str = (cargo == CT_INVALID) ? (StringID)STR_8838_N_A : GetCargo(cargo)->quantifier;
+ StringID cargo_str = (cargo == CT_INVALID) ? STR_8838_N_A : GetCargo(cargo)->quantifier;
buff = GetStringWithArgs(buff, cargo_str, argv++, last);
break;
}
@@ -852,7 +852,7 @@ static char* FormatString(char* buff, const char* str, const int64* argv, uint c
assert(g->IsValid());
args[0] = g->index;
- buff = GetStringWithArgs(buff, IsCustomName(g->string_id) ? g->string_id : (StringID)STR_GROUP_NAME_FORMAT, args, last);
+ buff = GetStringWithArgs(buff, IsCustomName(g->string_id) ? g->string_id : STR_GROUP_NAME_FORMAT, args, last);
break;
}