summaryrefslogtreecommitdiff
path: root/src/strgen
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-12-17 23:16:16 +0000
committerrubidium <rubidium@openttd.org>2011-12-17 23:16:16 +0000
commit50b63c587087733b2d3b059e10a10eba748c0166 (patch)
tree1f004d4165d0434bf51e5f848d566e063a4b33af /src/strgen
parent89c263c2df3f7d457716ae5cc8c5cf0e8eb7d520 (diff)
downloadopenttd-50b63c587087733b2d3b059e10a10eba748c0166.tar.xz
(svn r23585) -Codechange: replace some magic numbers with less magic constants
Diffstat (limited to 'src/strgen')
-rw-r--r--src/strgen/strgen.cpp4
-rw-r--r--src/strgen/strgen.h8
-rw-r--r--src/strgen/strgen_base.cpp8
3 files changed, 9 insertions, 11 deletions
diff --git a/src/strgen/strgen.cpp b/src/strgen/strgen.cpp
index 4ca02a1a7..0b40e02c4 100644
--- a/src/strgen/strgen.cpp
+++ b/src/strgen/strgen.cpp
@@ -529,7 +529,7 @@ int CDECL main(int argc, char *argv[])
mkpath(pathbuf, lengthof(pathbuf), src_dir, "english.txt");
/* parse master file */
- StringData data;
+ StringData data(TAB_COUNT);
FileStringReader master_reader(data, pathbuf, true, false);
master_reader.ParseFile();
if (_errors != 0) return 1;
@@ -546,7 +546,7 @@ int CDECL main(int argc, char *argv[])
mkpath(pathbuf, lengthof(pathbuf), src_dir, "english.txt");
- StringData data;
+ StringData data(TAB_COUNT);
/* parse master file and check if target file is correct */
FileStringReader master_reader(data, pathbuf, true, false);
master_reader.ParseFile();
diff --git a/src/strgen/strgen.h b/src/strgen/strgen.h
index b3584ab5f..e44c5be42 100644
--- a/src/strgen/strgen.h
+++ b/src/strgen/strgen.h
@@ -39,15 +39,13 @@ struct LangString {
/** Information about the currently known strings. */
struct StringData {
- static const uint STRINGS_IN_TAB = 2048;
-
LangString **strings; ///< Array of all known strings.
uint16 *hash_heads; ///< Hash table for the strings.
size_t tabs; ///< The number of 'tabs' of strings.
size_t max_strings; ///< The maxmimum number of strings.
int next_string_id; ///< The next string ID to allocate.
- StringData(size_t tabs = 32);
+ StringData(size_t tabs);
~StringData();
void FreeTranslation();
uint HashStr(const char *s) const;
@@ -134,8 +132,8 @@ struct LanguageWriter {
/** Especially destroy the subclasses. */
virtual ~LanguageWriter() {}
- void WriteLength(uint length);
- void WriteLang(const StringData &data);
+ virtual void WriteLength(uint length);
+ virtual void WriteLang(const StringData &data);
};
void CDECL strgen_warning(const char *s, ...) WARN_FORMAT(1, 2);
diff --git a/src/strgen/strgen_base.cpp b/src/strgen/strgen_base.cpp
index 98e5aefb1..5563de31e 100644
--- a/src/strgen/strgen_base.cpp
+++ b/src/strgen/strgen_base.cpp
@@ -89,7 +89,7 @@ void LangString::FreeTranslation()
* Create a new string data container.
* @param max_strings The maximum number of strings.
*/
-StringData::StringData(size_t tabs) : tabs(tabs), max_strings(tabs * STRINGS_IN_TAB)
+StringData::StringData(size_t tabs) : tabs(tabs), max_strings(tabs * TAB_SIZE)
{
this->strings = CallocT<LangString *>(max_strings);
this->hash_heads = CallocT<uint16>(max_strings);
@@ -215,7 +215,7 @@ uint StringData::Version() const
uint StringData::CountInUse(uint tab) const
{
int i;
- for (i = STRINGS_IN_TAB; --i >= 0;) if (this->strings[(tab * STRINGS_IN_TAB) + i] != NULL) break;
+ for (i = TAB_SIZE; --i >= 0;) if (this->strings[(tab * TAB_SIZE) + i] != NULL) break;
return i + 1;
}
@@ -938,7 +938,7 @@ void LanguageWriter::WriteLang(const StringData &data)
_lang.offsets[tab] = TO_LE16(n);
for (uint j = 0; j != in_use[tab]; j++) {
- const LangString *ls = data.strings[(tab * StringData::STRINGS_IN_TAB) + j];
+ const LangString *ls = data.strings[(tab * TAB_SIZE) + j];
if (ls != NULL && ls->translated == NULL) _lang.missing++;
}
}
@@ -953,7 +953,7 @@ void LanguageWriter::WriteLang(const StringData &data)
for (size_t tab = 0; tab < data.tabs; tab++) {
for (uint j = 0; j != in_use[tab]; j++) {
- const LangString *ls = data.strings[(tab * StringData::STRINGS_IN_TAB) + j];
+ const LangString *ls = data.strings[(tab * TAB_SIZE) + j];
const Case *casep;
const char *cmdp;