1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/core/CTranslator.h Sun Jan 07 08:47:38 2007 +0000
1.3 @@ -0,0 +1,101 @@
1.4 +#ifndef _INCLUDE_SOURCEMOD_TRANSLATOR_H_
1.5 +#define _INCLUDE_SOURCEMOD_TRANSLATOR_H_
1.6 +
1.7 +#include "sm_trie.h"
1.8 +#include <sh_string.h>
1.9 +#include <sh_vector.h>
1.10 +#include "sm_globals.h"
1.11 +#include "sm_memtable.h"
1.12 +#include "ITextParsers.h"
1.13 +
1.14 +#define MAX_TRANSLATE_PARAMS 32
1.15 +
1.16 +/* :TODO: write a templatized version of tries? */
1.17 +
1.18 +using namespace SourceHook;
1.19 +class CTranslator;
1.20 +
1.21 +enum PhraseParseState
1.22 +{
1.23 + PPS_None = 0,
1.24 + PPS_Phrases,
1.25 + PPS_InPhrase,
1.26 +};
1.27 +
1.28 +struct Language
1.29 +{
1.30 + char m_code2[3];
1.31 + int m_FullName;
1.32 +};
1.33 +
1.34 +struct Translation
1.35 +{
1.36 + const char *szPhrase;
1.37 + unsigned int lang_id;
1.38 + unsigned int file_id;
1.39 + void **params;
1.40 +};
1.41 +
1.42 +class CPhraseFile : public ITextListener_SMC
1.43 +{
1.44 +public:
1.45 + CPhraseFile(CTranslator *pTranslator, const char *file);
1.46 + ~CPhraseFile();
1.47 +public:
1.48 + void ReparseFile();
1.49 + const char *GetFilename();
1.50 + const char *GetTranslation(const Translation *pTrans, int **fmt_order, unsigned int *fmt_count);
1.51 +public: //ITextListener_SMC
1.52 + void ReadSMC_ParseStart();
1.53 + void ReadSMC_ParseEnd(bool halted, bool failed);
1.54 + SMCParseResult ReadSMC_NewSection(const char *name, bool opt_quotes);
1.55 + SMCParseResult ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes);
1.56 + SMCParseResult ReadSMC_LeavingSection();
1.57 + SMCParseResult ReadSMC_RawLine(const char *line, unsigned int curline);
1.58 +private:
1.59 + void ParseError(const char *message, ...);
1.60 + void ParseWarning(const char *message, ...);
1.61 +private:
1.62 + Trie *m_pPhraseLookup;
1.63 + String m_File;
1.64 + CTranslator *m_pTranslator;
1.65 + PhraseParseState m_ParseState;
1.66 + int m_CurPhrase;
1.67 + BaseMemTable *m_pMemory;
1.68 + BaseStringTable *m_pStringTab;
1.69 + unsigned int m_LangCount;
1.70 + String m_ParseError;
1.71 + String m_LastPhraseString;
1.72 + unsigned int m_CurLine;
1.73 + bool m_FileLogged;
1.74 +};
1.75 +
1.76 +class CTranslator : public ITextListener_SMC
1.77 +{
1.78 +public:
1.79 + CTranslator();
1.80 + ~CTranslator();
1.81 +public: //ITextListener_SMC
1.82 + void ReadSMC_ParseStart();
1.83 + SMCParseResult ReadSMC_NewSection(const char *name, bool opt_quotes);
1.84 + SMCParseResult ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes);
1.85 + SMCParseResult ReadSMC_LeavingSection();
1.86 +public:
1.87 + void RebuildLanguageDatabase(const char *lang_header_file);
1.88 + unsigned int FindOrAddPhraseFile(const char *phrase_file);
1.89 + BaseStringTable *GetStringTable();
1.90 + unsigned int GetLanguageCount();
1.91 + bool GetLanguageByCode(const char *code, unsigned int *index);
1.92 + size_t Translate(char *buffer, size_t maxlength, const Translation *pTrans);
1.93 +private:
1.94 + CVector<Language *> m_Languages;
1.95 + CVector<CPhraseFile *> m_Files;
1.96 + BaseStringTable *m_pStringTab;
1.97 + Trie *m_pLCodeLookup;
1.98 + bool m_InLanguageSection;
1.99 + String m_CustomError;
1.100 +};
1.101 +
1.102 +extern CTranslator g_Translator;
1.103 +
1.104 +#endif //_INCLUDE_SOURCEMOD_TRANSLATOR_H_