OpenTTD: src/strgen/strgen.h Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

strgen.h
Go to the documentation of this file.
1 /* $Id: strgen.h 26511 2014-04-25 17:43:09Z rubidium $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
9
12 #ifndef STRGEN_H
13 #define STRGEN_H
14
15 #include "../language.h"
16
18 struct Case {
19 int caseidx;
20 char *string;
21 Case *next;
22
23 Case(int caseidx, const char *string, Case *next);
24 ~Case();
25 };
26
28 struct LangString {
29 char *name;
30 char *english;
31 char *translated;
32 uint16 hash_next;
33 uint16 index;
34 int line;
35 Case *translated_case;
36
37 LangString(const char *name, const char *english, int index, int line);
38 ~LangString();
39 void FreeTranslation();
40 };
41
43 struct StringData {
44 LangString **strings;
45 uint16 *hash_heads;
46 size_t tabs;
47 size_t max_strings;
48 int next_string_id;
49
50 StringData(size_t tabs);
51 ~StringData();
52 void FreeTranslation();
53 uint HashStr(const char *s) const;
54 void Add(const char *s, LangString *ls);
55 LangString *Find(const char *s);
56 uint VersionHashStr(uint hash, const char *s) const;
57 uint Version() const;
58 uint CountInUse(uint tab) const;
59 };
60
62 struct StringReader {
63 StringData &data;
64 const char *file;
65 bool master;
66 bool translation;
67
68 StringReader(StringData &data, const char *file, bool master, bool translation);
69 virtual ~StringReader();
70 void HandleString(char *str);
71
78 virtual char *ReadLine(char *buffer, const char *last) = 0;
79
84 virtual void HandlePragma(char *str);
85
89 virtual void ParseFile();
90 };
91
93 struct HeaderWriter {
99 virtual void WriteStringID(const char *name, int stringid) = 0;
100
105 virtual void Finalise(const StringData &data) = 0;
106
108 virtual ~HeaderWriter() {};
109
110 void WriteHeader(const StringData &data);
111 };
112
114 struct LanguageWriter {
120 virtual void WriteHeader(const LanguagePackHeader *header) = 0;
121
127 virtual void Write(const byte *buffer, size_t length) = 0;
128
132 virtual void Finalise() = 0;
133
135 virtual ~LanguageWriter() {}
136
137 virtual void WriteLength(uint length);
138 virtual void WriteLang(const StringData &data);
139 };
140
141 void CDECL strgen_warning(const char *s, ...) WARN_FORMAT(1, 2);
142 void CDECL strgen_error(const char *s, ...) WARN_FORMAT(1, 2);
143 void NORETURN CDECL strgen_fatal(const char *s, ...) WARN_FORMAT(1, 2);
144 char *ParseWord(char **buf);
145
146 extern const char *_file;
147 extern int _cur_line;
148 extern int _errors, _warnings, _show_todo;
149 extern LanguagePackHeader _lang;
150
151 #endif /* STRGEN_H */