# strgen.h

Go to the documentation of this file.

    00001 /* $Id: strgen.h 24900 2013-01-08 22:46:42Z planetmaker $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #ifndef STRGEN_H
    00013 #define STRGEN_H
    00014
    00015 #include "../language.h"
    00016
    00018 struct Case {
    00019   int caseidx;
    00020   char *string;
    00021   Case *next;
    00022
    00023   Case(int caseidx, const char *string, Case *next);
    00024   ~Case();
    00025 };
    00026
    00028 struct LangString {
    00029   char *name;
    00030   char *english;
    00031   char *translated;
    00032   uint16 hash_next;
    00033   uint16 index;
    00034   int line;
    00035   Case *translated_case;
    00036
    00037   LangString(const char *name, const char *english, int index, int line);
    00038   ~LangString();
    00039   void FreeTranslation();
    00040 };
    00041
    00043 struct StringData {
    00044   LangString **strings;
    00045   uint16 *hash_heads;
    00046   size_t tabs;
    00047   size_t max_strings;
    00048   int next_string_id;
    00049
    00050   StringData(size_t tabs);
    00051   ~StringData();
    00052   void FreeTranslation();
    00053   uint HashStr(const char *s) const;
    00054   void Add(const char *s, LangString *ls);
    00055   LangString *Find(const char *s);
    00056   uint VersionHashStr(uint hash, const char *s) const;
    00057   uint Version() const;
    00058   uint CountInUse(uint tab) const;
    00059 };
    00060
    00062 struct StringReader {
    00063   StringData &data;
    00064   const char *file;
    00065   bool master;
    00066   bool translation;
    00067
    00068   StringReader(StringData &data, const char *file, bool master, bool translation);
    00069   virtual ~StringReader();
    00070   void HandleString(char *str);
    00071
    00078   virtual char *ReadLine(char *buffer, size_t size) = 0;
    00079
    00084   virtual void HandlePragma(char *str);
    00085
    00089   virtual void ParseFile();
    00090 };
    00091
    00093 struct HeaderWriter {
    00099   virtual void WriteStringID(const char *name, int stringid) = 0;
    00100
    00105   virtual void Finalise(const StringData &data) = 0;
    00106
    00108   virtual ~HeaderWriter() {};
    00109
    00110   void WriteHeader(const StringData &data);
    00111 };
    00112
    00114 struct LanguageWriter {
    00120   virtual void WriteHeader(const LanguagePackHeader *header) = 0;
    00121
    00127   virtual void Write(const byte *buffer, size_t length) = 0;
    00128
    00132   virtual void Finalise() = 0;
    00133
    00135   virtual ~LanguageWriter() {}
    00136
    00137   virtual void WriteLength(uint length);
    00138   virtual void WriteLang(const StringData &data);
    00139 };
    00140
    00141 void CDECL strgen_warning(const char *s, ...) WARN_FORMAT(1, 2);
    00142 void CDECL strgen_error(const char *s, ...) WARN_FORMAT(1, 2);
    00143 void NORETURN CDECL strgen_fatal(const char *s, ...) WARN_FORMAT(1, 2);
    00144 char *ParseWord(char **buf);
    00145
    00146 extern const char *_file;
    00147 extern int _cur_line;
    00148 extern int _errors, _warnings, _show_todo;
    00149 extern LanguagePackHeader _lang;
    00150
    00151 #endif /* STRGEN_H */