OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
13 #include "../language.h"
51 uint
HashStr(
const char *s)
const;
68 void HandleString(
char *str);
76 virtual char *
ReadLine(
char *buffer,
const char *last) = 0;
97 virtual void WriteStringID(
const char *name,
int stringid) = 0;
125 virtual void Write(
const byte *buffer,
size_t length) = 0;
139 void CDECL strgen_warning(
const char *s, ...) WARN_FORMAT(1, 2);
140 void CDECL strgen_error(const
char *s, ...) WARN_FORMAT(1, 2);
141 void NORETURN CDECL strgen_fatal(const
char *s, ...) WARN_FORMAT(1, 2);
142 char *ParseWord(
char **buf);
144 extern const
char *
_file;
146 extern
int _errors, _warnings, _show_todo;
virtual void Finalise()=0
Finalise writing the file.
const char * _file
The filename of the input, so we can refer to it in errors/warnings.
uint HashStr(const char *s) const
Create a hash of the string for finding them back quickly.
virtual void HandlePragma(char *str)
Handle the pragma of the file.
size_t max_strings
The maximum number of strings.
Case(int caseidx, const char *string, Case *next)
Create a new case.
uint VersionHashStr(uint hash, const char *s) const
Create a compound hash.
void Add(const char *s, LangString *ls)
Add a newly created LangString.
char * translated
Translated text.
virtual void Write(const byte *buffer, size_t length)=0
Write a number of bytes.
StringData(size_t tabs)
Create a new string data container.
StringReader(StringData &data, const char *file, bool master, bool translation)
Prepare reading.
virtual ~StringReader()
Make sure the right reader gets freed.
~LangString()
Free everything we allocated.
LanguagePackHeader _lang
Header information about a language.
LangString(const char *name, const char *english, size_t index, int line)
Create a new string.
int caseidx
The index of the case.
int _cur_line
The current line we're parsing in the input file.
virtual void WriteLang(const StringData &data)
Actually write the language.
LangString * Find(const char *s)
Find a LangString based on the string name.
bool master
Are we reading the master file?
size_t next_string_id
The next string ID to allocate.
Information about a single string.
uint Version() const
Make a hash of the file to get a unique "version number".
char * english
English text.
char * name
Name of the string.
Information about the currently known strings.
~Case()
Free everything we allocated.
uint CountInUse(uint tab) const
Count the number of tab elements that are in use.
void FreeTranslation()
Free all data related to the translation.
~StringData()
Free everything we allocated.
LangString ** strings
Array of all known strings.
Case * next
The next, chained, case.
virtual void WriteHeader(const LanguagePackHeader *header)=0
Write the header metadata.
char * string
The translation of the case.
size_t index
The index in the language file.
size_t tabs
The number of 'tabs' of strings.
size_t hash_next
Next hash entry.
StringData & data
The data to fill during reading.
virtual char * ReadLine(char *buffer, const char *last)=0
Read a single line from the source of strings.
int line
Line of string in source-file.
bool translation
Are we reading a translation, implies !master. However, the base translation will have this false.
virtual void ParseFile()
Start parsing the file.
Base class for all language writers.
virtual ~LanguageWriter()
Especially destroy the subclasses.
Case * translated_case
Cases of the translation.
const char * file
The file we are reading.
size_t * hash_heads
Hash table for the strings.
Container for the different cases of a string.
void FreeTranslation()
Free all data related to the translation.
virtual void WriteLength(uint length)
Write the length as a simple gamma.
Helper for reading strings.