mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Reorder functions in strgen and reduce external symbols.
parent
b96b26ef15
commit
4fc0900865
|
@ -173,7 +173,7 @@ void FileStringReader::HandlePragma(char *str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CompareFiles(const std::filesystem::path &path1, const std::filesystem::path &path2)
|
static bool CompareFiles(const std::filesystem::path &path1, const std::filesystem::path &path2)
|
||||||
{
|
{
|
||||||
/* Check for equal size, but ignore the error code for cases when a file does not exist. */
|
/* Check for equal size, but ignore the error code for cases when a file does not exist. */
|
||||||
std::error_code error_code;
|
std::error_code error_code;
|
||||||
|
|
|
@ -49,7 +49,6 @@ struct StringData {
|
||||||
void FreeTranslation();
|
void FreeTranslation();
|
||||||
void Add(std::shared_ptr<LangString> ls);
|
void Add(std::shared_ptr<LangString> ls);
|
||||||
LangString *Find(const std::string &s);
|
LangString *Find(const std::string &s);
|
||||||
uint VersionHashStr(uint hash, const char *s) const;
|
|
||||||
uint Version() const;
|
uint Version() const;
|
||||||
uint CountInUse(uint tab) const;
|
uint CountInUse(uint tab) const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,21 +16,22 @@
|
||||||
|
|
||||||
#include "strgen.h"
|
#include "strgen.h"
|
||||||
|
|
||||||
|
|
||||||
#include "../table/strgen_tables.h"
|
#include "../table/strgen_tables.h"
|
||||||
|
|
||||||
#include "../safeguards.h"
|
#include "../safeguards.h"
|
||||||
|
|
||||||
/* Compiles a list of strings into a compiled string list */
|
|
||||||
|
|
||||||
static bool _translated; ///< Whether the current language is not the master language
|
static bool _translated; ///< Whether the current language is not the master language
|
||||||
static bool _translation; ///< Is the current file actually a translation or not
|
static bool _translation; ///< Is the current file actually a translation or not
|
||||||
const char *_file = "(unknown file)"; ///< The filename of the input, so we can refer to it in errors/warnings
|
const char *_file = "(unknown file)"; ///< The filename of the input, so we can refer to it in errors/warnings
|
||||||
int _cur_line; ///< The current line we're parsing in the input file
|
int _cur_line; ///< The current line we're parsing in the input file
|
||||||
int _errors, _warnings, _show_todo;
|
int _errors, _warnings, _show_todo;
|
||||||
LanguagePackHeader _lang; ///< Header information about a language.
|
LanguagePackHeader _lang; ///< Header information about a language.
|
||||||
|
static const char *_cur_ident;
|
||||||
|
static ParsedCommandStruct _cur_pcs;
|
||||||
|
static int _cur_argidx;
|
||||||
|
|
||||||
static const CmdStruct *ParseCommandString(const char **str, std::string ¶m, int *argno, int *casei);
|
static const CmdStruct *ParseCommandString(const char **str, std::string ¶m, int *argno, int *casei);
|
||||||
|
static int TranslateArgumentIdx(int arg, int offset = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new case.
|
* Create a new case.
|
||||||
|
@ -110,7 +111,7 @@ LangString *StringData::Find(const std::string &s)
|
||||||
* @param s The string hash.
|
* @param s The string hash.
|
||||||
* @return The new hash.
|
* @return The new hash.
|
||||||
*/
|
*/
|
||||||
uint StringData::VersionHashStr(uint hash, const char *s) const
|
static uint VersionHashStr(uint hash, const char *s)
|
||||||
{
|
{
|
||||||
for (; *s != '\0'; s++) {
|
for (; *s != '\0'; s++) {
|
||||||
hash = std::rotl(hash, 3) ^ *s;
|
hash = std::rotl(hash, 3) ^ *s;
|
||||||
|
@ -140,7 +141,7 @@ uint StringData::Version() const
|
||||||
s = ls->name.c_str();
|
s = ls->name.c_str();
|
||||||
hash ^= i * 0x717239;
|
hash ^= i * 0x717239;
|
||||||
hash = (hash & 1 ? hash >> 1 ^ 0xDEADBEEF : hash >> 1);
|
hash = (hash & 1 ? hash >> 1 ^ 0xDEADBEEF : hash >> 1);
|
||||||
hash = this->VersionHashStr(hash, s + 1);
|
hash = VersionHashStr(hash, s + 1);
|
||||||
|
|
||||||
s = ls->english.c_str();
|
s = ls->english.c_str();
|
||||||
while ((cs = ParseCommandString(&s, buf, &argno, &casei)) != nullptr) {
|
while ((cs = ParseCommandString(&s, buf, &argno, &casei)) != nullptr) {
|
||||||
|
@ -166,12 +167,6 @@ uint StringData::CountInUse(uint tab) const
|
||||||
return i + 1;
|
return i + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *_cur_ident;
|
|
||||||
|
|
||||||
/* Used when generating some advanced commands. */
|
|
||||||
static ParsedCommandStruct _cur_pcs;
|
|
||||||
static int _cur_argidx;
|
|
||||||
|
|
||||||
/** The buffer for writing a single string. */
|
/** The buffer for writing a single string. */
|
||||||
struct Buffer : std::vector<uint8_t> {
|
struct Buffer : std::vector<uint8_t> {
|
||||||
/**
|
/**
|
||||||
|
@ -209,7 +204,7 @@ struct Buffer : std::vector<uint8_t> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
size_t Utf8Validate(const char *s)
|
static size_t Utf8Validate(const char *s)
|
||||||
{
|
{
|
||||||
uint32_t c;
|
uint32_t c;
|
||||||
|
|
||||||
|
@ -233,21 +228,15 @@ size_t Utf8Validate(const char *s)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void EmitSingleChar(Buffer *buffer, char *buf, int value)
|
void EmitSingleChar(Buffer *buffer, char *buf, int value)
|
||||||
{
|
{
|
||||||
if (*buf != '\0') StrgenWarning("Ignoring trailing letters in command");
|
if (*buf != '\0') StrgenWarning("Ignoring trailing letters in command");
|
||||||
buffer->AppendUtf8(value);
|
buffer->AppendUtf8(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* The plural specifier looks like
|
/* The plural specifier looks like
|
||||||
* {NUM} {PLURAL -1 passenger passengers} then it picks either passenger/passengers depending on the count in NUM */
|
* {NUM} {PLURAL -1 passenger passengers} then it picks either passenger/passengers depending on the count in NUM */
|
||||||
|
static bool ParseRelNum(char **buf, int *value, int *offset)
|
||||||
/* This is encoded like
|
|
||||||
* CommandByte <ARG#> <NUM> {Length of each string} {each string} */
|
|
||||||
|
|
||||||
bool ParseRelNum(char **buf, int *value, int *offset)
|
|
||||||
{
|
{
|
||||||
const char *s = *buf;
|
const char *s = *buf;
|
||||||
char *end;
|
char *end;
|
||||||
|
@ -310,9 +299,8 @@ char *ParseWord(char **buf)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Forward declaration */
|
/* This is encoded like
|
||||||
static int TranslateArgumentIdx(int arg, int offset = 0);
|
* CommandByte <ARG#> <NUM> {Length of each string} {each string} */
|
||||||
|
|
||||||
static void EmitWordList(Buffer *buffer, const std::vector<const char *> &words, uint nw)
|
static void EmitWordList(Buffer *buffer, const std::vector<const char *> &words, uint nw)
|
||||||
{
|
{
|
||||||
/* Maximum word length in bytes, excluding trailing NULL. */
|
/* Maximum word length in bytes, excluding trailing NULL. */
|
||||||
|
@ -444,7 +432,6 @@ static uint ResolveCaseName(const char *str, size_t len)
|
||||||
return case_idx + 1;
|
return case_idx + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* returns nullptr on eof
|
/* returns nullptr on eof
|
||||||
* else returns command struct */
|
* else returns command struct */
|
||||||
static const CmdStruct *ParseCommandString(const char **str, std::string ¶m, int *argno, int *casei)
|
static const CmdStruct *ParseCommandString(const char **str, std::string ¶m, int *argno, int *casei)
|
||||||
|
@ -500,7 +487,6 @@ static const CmdStruct *ParseCommandString(const char **str, std::string ¶m,
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (c != '}') {
|
if (c != '}') {
|
||||||
if (c == '=') s--;
|
if (c == '=') s--;
|
||||||
/* copy params */
|
/* copy params */
|
||||||
|
@ -565,7 +551,6 @@ ParsedCommandStruct ExtractCommandString(const char *s, bool)
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const CmdStruct *TranslateCmdForCompare(const CmdStruct *a)
|
const CmdStruct *TranslateCmdForCompare(const CmdStruct *a)
|
||||||
{
|
{
|
||||||
if (a == nullptr) return nullptr;
|
if (a == nullptr) return nullptr;
|
||||||
|
@ -584,7 +569,6 @@ const CmdStruct *TranslateCmdForCompare(const CmdStruct *a)
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool CheckCommandsMatch(const char *a, const char *b, const char *name)
|
static bool CheckCommandsMatch(const char *a, const char *b, const char *name)
|
||||||
{
|
{
|
||||||
/* If we're not translating, i.e. we're compiling the base language,
|
/* If we're not translating, i.e. we're compiling the base language,
|
||||||
|
@ -826,7 +810,6 @@ static void PutArgidxCommand(Buffer *buffer)
|
||||||
buffer->AppendByte(TranslateArgumentIdx(_cur_argidx));
|
buffer->AppendByte(TranslateArgumentIdx(_cur_argidx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void PutCommandString(Buffer *buffer, const char *str)
|
static void PutCommandString(Buffer *buffer, const char *str)
|
||||||
{
|
{
|
||||||
_cur_argidx = 0;
|
_cur_argidx = 0;
|
||||||
|
|
Loading…
Reference in New Issue