13 #include "../language.h"
14 #include "../3rdparty/fmt/format.h"
16 #include <unordered_map>
42 std::vector<std::unique_ptr<LangString>>
strings;
50 void Add(std::unique_ptr<LangString> ls);
66 void HandleString(
char *str);
72 virtual std::optional<std::string>
ReadLine() = 0;
121 virtual void Write(
const uint8_t *buffer,
size_t length) = 0;
143 std::vector<CmdPair> non_consuming_commands;
144 std::array<const CmdStruct*, 32> consuming_commands{
nullptr };
150 void StrgenWarningI(
const std::string &msg);
151 void StrgenErrorI(
const std::string &msg);
152 [[noreturn]]
void StrgenFatalI(
const std::string &msg);
153 #define StrgenWarning(format_string, ...) StrgenWarningI(fmt::format(FMT_STRING(format_string) __VA_OPT__(,) __VA_ARGS__))
154 #define StrgenError(format_string, ...) StrgenErrorI(fmt::format(FMT_STRING(format_string) __VA_OPT__(,) __VA_ARGS__))
155 #define StrgenFatal(format_string, ...) StrgenFatalI(fmt::format(FMT_STRING(format_string) __VA_OPT__(,) __VA_ARGS__))
156 char *ParseWord(
char **buf);
158 extern const char *
_file;
160 extern int _errors, _warnings, _show_todo;
LanguagePackHeader _lang
Header information about a language.
int _cur_line
The current line we're parsing in the input file.
const char * _file
The filename of the input, so we can refer to it in errors/warnings.
Container for the different cases of a string.
Case(int caseidx, const std::string &string)
Create a new case.
int caseidx
The index of the case.
std::string string
The translation of the case.
Information about a single string.
int line
Line of string in source-file.
LangString(const std::string &name, const std::string &english, size_t index, int line)
Create a new string.
std::string english
English text.
std::vector< Case > translated_cases
Cases of the translation.
std::string translated
Translated text.
void FreeTranslation()
Free all data related to the translation.
std::string name
Name of the string.
size_t index
The index in the language file.
Base class for all language writers.
virtual void WriteHeader(const LanguagePackHeader *header)=0
Write the header metadata.
virtual void Finalise()=0
Finalise writing the file.
virtual void WriteLength(uint length)
Write the length as a simple gamma.
virtual ~LanguageWriter()=default
Especially destroy the subclasses.
virtual void Write(const uint8_t *buffer, size_t length)=0
Write a number of bytes.
virtual void WriteLang(const StringData &data)
Actually write the language.
Information about the currently known strings.
size_t tabs
The number of 'tabs' of strings.
uint CountInUse(uint tab) const
Count the number of tab elements that are in use.
uint VersionHashStr(uint hash, const char *s) const
Create a compound hash.
std::vector< std::unique_ptr< LangString > > strings
List of all known strings.
size_t max_strings
The maximum number of strings.
void Add(std::unique_ptr< LangString > ls)
Add a newly created LangString.
size_t next_string_id
The next string ID to allocate.
uint Version() const
Make a hash of the file to get a unique "version number".
LangString * Find(const std::string_view s)
Find a LangString based on the string name.
void FreeTranslation()
Free all data related to the translation.
StringData(size_t tabs)
Create a new string data container.
std::unordered_map< std::string_view, LangString * > name_to_string
Lookup table for the strings.
Helper for reading strings.
const std::string file
The file we are reading.
StringReader(StringData &data, const std::string &file, bool master, bool translation)
Prepare reading.
StringData & data
The data to fill during reading.
virtual void ParseFile()
Start parsing the file.
bool translation
Are we reading a translation, implies !master. However, the base translation will have this false.
virtual std::optional< std::string > ReadLine()=0
Read a single line from the source of strings.
virtual void HandlePragma(char *str)
Handle the pragma of the file.
bool master
Are we reading the master file?