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/>.
10 /** @file strgen.h Structures related to strgen. */
15 #include "../language.h"
19 /** Information about the currently known strings. */
21 LangString
**strings
; ///< Array of all known strings.
22 uint16
*hash_heads
; ///< Hash table for the strings.
23 size_t tabs
; ///< The number of 'tabs' of strings.
24 size_t max_strings
; ///< The maximum number of strings.
25 int next_string_id
; ///< The next string ID to allocate.
27 StringData(size_t tabs
);
29 void FreeTranslation();
30 uint
HashStr(const char *s
) const;
31 void Add(const char *s
, LangString
*ls
);
32 LangString
*Find(const char *s
);
33 uint
VersionHashStr(uint hash
, const char *s
) const;
35 uint
CountInUse(uint tab
) const;
38 /** Helper for reading strings. */
40 StringData
&data
; ///< The data to fill during reading.
41 const char *file
; ///< The file we are reading.
42 bool master
; ///< Are we reading the master file?
43 bool translation
; ///< Are we reading a translation, implies !master. However, the base translation will have this false.
45 StringReader(StringData
&data
, const char *file
, bool master
, bool translation
);
46 virtual ~StringReader();
49 * Read a single line from the source of strings.
50 * @param buffer The buffer to read the data in to.
51 * @param size The size of the buffer.
52 * @return The buffer, or NULL if at the end of the file.
54 virtual char *ReadLine(char *buffer
, size_t size
) = 0;
57 * Handle the pragma of the file.
58 * @param str The pragma string to parse.
60 virtual void HandlePragma(char *str
);
63 * Start parsing the file.
68 /** Base class for writing the header, i.e. the STR_XXX to numeric value. */
71 * Write the string ID.
72 * @param name The name of the string.
73 * @param stringid The ID of the string.
75 virtual void WriteStringID(const char *name
, int stringid
) = 0;
77 /** Especially destroy the subclasses. */
78 virtual ~HeaderWriter() {};
80 void WriteHeader(const StringData
&data
);
83 /** Base class for all language writers. */
84 struct LanguageWriter
{
86 * Write the header metadata. The multi-byte integers are already converted to
87 * the little endian format.
88 * @param header The header to write.
90 virtual void WriteHeader(const LanguagePackHeader
*header
) = 0;
92 /** Write a null string. */
93 virtual void WriteNullString (void) = 0;
96 * Write a translated string.
97 * @param length The amount of byte to write.
98 * @param buffer The buffer to write.
100 virtual void WriteString (size_t length
, const byte
*buffer
) = 0;
102 /** Especially destroy the subclasses. */
103 virtual ~LanguageWriter() {}
105 virtual void WriteLang(const StringData
&data
);
108 void CDECL
strgen_warning(const char *s
, ...) WARN_FORMAT(1, 2);
109 void CDECL
strgen_error(const char *s
, ...) WARN_FORMAT(1, 2);
110 void NORETURN CDECL
strgen_fatal(const char *s
, ...) WARN_FORMAT(1, 2);
111 char *ParseWord(char **buf
);
113 extern const char *_file
;
114 extern int _cur_line
;
115 extern int _errors
, _warnings
, _show_todo
;
116 extern LanguagePackHeader _lang
;
118 #endif /* STRGEN_H */