2014-08-04 12:36:20 +04:00
|
|
|
// vim: set ts=4 sw=4 tw=99 noet:
|
|
|
|
//
|
|
|
|
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
|
|
|
|
// Copyright (C) The AMX Mod X Development Team.
|
|
|
|
//
|
|
|
|
// This software is licensed under the GNU General Public License, version 3 or higher.
|
|
|
|
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
|
|
|
// https://alliedmods.net/amxmodx-license
|
2004-07-27 23:54:21 +04:00
|
|
|
|
|
|
|
#ifndef _INCLUDE_CLANG_H
|
|
|
|
#define _INCLUDE_CLANG_H
|
|
|
|
|
2005-11-21 04:35:37 +03:00
|
|
|
#include "sh_tinyhash.h"
|
|
|
|
|
2004-08-13 20:21:15 +04:00
|
|
|
#define LANG_SERVER 0
|
|
|
|
#define LANG_PLAYER -1
|
2004-07-28 22:31:30 +04:00
|
|
|
|
2006-01-24 21:47:08 +03:00
|
|
|
#define ERR_BADKEY 1 // Lang key not found
|
|
|
|
#define ERR_BADLANG 2 // Invalid lang
|
2005-11-20 06:47:47 +03:00
|
|
|
|
2004-08-15 14:53:48 +04:00
|
|
|
struct md5Pair
|
2004-07-27 23:54:21 +04:00
|
|
|
{
|
2004-08-15 14:53:48 +04:00
|
|
|
String file;
|
|
|
|
String val;
|
|
|
|
};
|
2004-07-27 23:54:21 +04:00
|
|
|
|
2005-11-21 04:35:37 +03:00
|
|
|
struct sKeyDef
|
2004-08-15 14:53:48 +04:00
|
|
|
{
|
2005-11-21 04:35:37 +03:00
|
|
|
String *definition;
|
|
|
|
int key;
|
2004-08-15 14:53:48 +04:00
|
|
|
};
|
|
|
|
|
2006-01-24 21:47:08 +03:00
|
|
|
struct lang_err
|
|
|
|
{
|
|
|
|
lang_err() : last(0.0f)
|
|
|
|
{
|
|
|
|
};
|
|
|
|
float last;
|
|
|
|
};
|
|
|
|
|
2005-11-21 04:35:37 +03:00
|
|
|
class defentry
|
2004-08-15 14:53:48 +04:00
|
|
|
{
|
2005-11-21 04:35:37 +03:00
|
|
|
public:
|
|
|
|
defentry() : definition(NULL)
|
|
|
|
{
|
|
|
|
};
|
2005-11-21 13:04:43 +03:00
|
|
|
defentry(const defentry &src)
|
|
|
|
{
|
|
|
|
definition = src.definition;
|
|
|
|
}
|
2005-11-21 04:35:37 +03:00
|
|
|
~defentry()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
String *definition;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct keytbl_val
|
|
|
|
{
|
|
|
|
keytbl_val() : index(-1)
|
|
|
|
{
|
|
|
|
};
|
|
|
|
int index;
|
2004-08-15 14:53:48 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class CLangMngr
|
|
|
|
{
|
2004-07-27 23:54:21 +04:00
|
|
|
class CLang
|
|
|
|
{
|
|
|
|
public:
|
2004-08-19 20:37:32 +04:00
|
|
|
// Construct an empty CLang object
|
2004-07-27 23:54:21 +04:00
|
|
|
CLang();
|
2004-08-19 20:37:32 +04:00
|
|
|
// Construct a CLang object initialized with a language name
|
2004-07-27 23:54:21 +04:00
|
|
|
CLang(const char *lang);
|
2004-08-19 20:37:32 +04:00
|
|
|
// Destructor
|
2004-07-27 23:54:21 +04:00
|
|
|
~CLang();
|
|
|
|
|
2004-08-19 20:37:32 +04:00
|
|
|
// Get the definition
|
2005-11-21 04:35:37 +03:00
|
|
|
const char *GetDef(int key, int &status);
|
2004-08-19 20:37:32 +04:00
|
|
|
// Add definitions to this language
|
2005-11-21 04:35:37 +03:00
|
|
|
void MergeDefinitions(CQueue <sKeyDef> & vec);
|
2004-08-19 20:37:32 +04:00
|
|
|
// Reset this language
|
2004-07-27 23:54:21 +04:00
|
|
|
void Clear();
|
|
|
|
|
2004-08-19 20:37:32 +04:00
|
|
|
// compare this language to a language name
|
2004-07-27 23:54:21 +04:00
|
|
|
friend bool operator == (const CLang &left, const char *right)
|
|
|
|
{
|
2005-09-17 03:48:51 +04:00
|
|
|
return strcmp(left.m_LanguageName, right) == 0 ? true : false;
|
2004-07-27 23:54:21 +04:00
|
|
|
}
|
2005-09-10 04:38:42 +04:00
|
|
|
|
2004-08-19 20:37:32 +04:00
|
|
|
// Get language name
|
2004-07-27 23:54:21 +04:00
|
|
|
const char *GetName() { return m_LanguageName; }
|
2004-08-19 20:37:32 +04:00
|
|
|
void SetMngr(CLangMngr *l) { m_LMan = l; }
|
|
|
|
// Get number of entries
|
2006-02-06 14:13:27 +03:00
|
|
|
int Entries();
|
2004-08-22 13:28:09 +04:00
|
|
|
protected:
|
2005-11-21 04:35:37 +03:00
|
|
|
typedef THash<int, defentry> LookUpVec;
|
|
|
|
typedef LookUpVec::iterator LookUpVecIter;
|
2004-07-27 23:54:21 +04:00
|
|
|
|
|
|
|
char m_LanguageName[3];
|
|
|
|
|
2004-08-19 20:37:32 +04:00
|
|
|
// our lookup table
|
2004-07-27 23:54:21 +04:00
|
|
|
LookUpVec m_LookUpTable;
|
2006-02-06 14:13:27 +03:00
|
|
|
int m_entries;
|
2004-08-19 20:37:32 +04:00
|
|
|
CLangMngr *m_LMan;
|
2004-08-15 19:26:46 +04:00
|
|
|
public:
|
2005-11-21 04:35:37 +03:00
|
|
|
void AddEntry(int key, const char *definition);
|
2004-07-27 23:54:21 +04:00
|
|
|
};
|
2006-08-28 15:08:18 +04:00
|
|
|
public:
|
2004-08-19 20:37:32 +04:00
|
|
|
// Merge definitions into a language
|
2005-11-21 04:35:37 +03:00
|
|
|
void MergeDefinitions(const char *lang, CQueue <sKeyDef> &tmpVec);
|
2006-08-28 15:08:18 +04:00
|
|
|
|
|
|
|
private:
|
2004-08-19 20:37:32 +04:00
|
|
|
// strip lowercase; make lower if needed
|
2005-09-10 04:38:42 +04:00
|
|
|
static size_t strip(char *str, char *newstr, bool makelower = false);
|
2004-07-27 23:54:21 +04:00
|
|
|
|
2004-08-15 14:53:48 +04:00
|
|
|
typedef CVector<CLang*> LangVec;
|
|
|
|
typedef CVector<CLang*>::iterator LangVecIter;
|
2004-07-27 23:54:21 +04:00
|
|
|
|
|
|
|
LangVec m_Languages;
|
2004-08-19 20:37:32 +04:00
|
|
|
|
2004-08-15 14:53:48 +04:00
|
|
|
CVector<md5Pair *> FileList;
|
2005-11-21 04:35:37 +03:00
|
|
|
CVector<String *> KeyList;
|
|
|
|
THash<String, keytbl_val> KeyTable;
|
2004-07-27 23:54:21 +04:00
|
|
|
|
2004-08-19 20:37:32 +04:00
|
|
|
// Get a lang object (construct if needed)
|
2004-08-15 14:53:48 +04:00
|
|
|
CLang * GetLang(const char *name);
|
2004-07-27 23:54:21 +04:00
|
|
|
|
2004-08-22 01:08:30 +04:00
|
|
|
CLang * GetLangR(const char *name);
|
|
|
|
|
2004-08-19 20:37:32 +04:00
|
|
|
// Current global client-id for functions like client_print with first parameter 0
|
2004-07-28 22:31:30 +04:00
|
|
|
int m_CurGlobId;
|
2004-07-27 23:54:21 +04:00
|
|
|
public:
|
2004-08-19 20:37:32 +04:00
|
|
|
// Merge a definitions file
|
2004-07-27 23:54:21 +04:00
|
|
|
int MergeDefinitionFile(const char *file);
|
2005-11-20 06:47:47 +03:00
|
|
|
// Get a definition from a lang name and a key
|
|
|
|
const char *GetDef(const char *langName, const char *key, int &status);
|
2004-08-19 20:37:32 +04:00
|
|
|
// Format a string for an AMX plugin
|
2004-07-28 22:31:30 +04:00
|
|
|
char *FormatAmxString(AMX *amx, cell *params, int parm, int &len);
|
2005-11-21 04:35:37 +03:00
|
|
|
void InvalidateCache();
|
2004-08-19 20:37:32 +04:00
|
|
|
// Get index
|
2004-08-15 14:53:48 +04:00
|
|
|
int GetKeyEntry(String &key);
|
|
|
|
int GetKeyEntry(const char *key);
|
2004-08-19 20:37:32 +04:00
|
|
|
// Get key from index
|
2004-08-15 14:53:48 +04:00
|
|
|
const char *GetKey(int key);
|
2004-08-19 20:37:32 +04:00
|
|
|
// Add key
|
2004-08-15 14:53:48 +04:00
|
|
|
int AddKeyEntry(String &key);
|
2006-08-28 15:08:18 +04:00
|
|
|
int AddKeyEntry(const char *key);
|
2004-07-28 22:31:30 +04:00
|
|
|
|
2004-08-19 20:37:32 +04:00
|
|
|
// Get the number of languages
|
2004-07-28 22:31:30 +04:00
|
|
|
int GetLangsNum();
|
2004-08-19 20:37:32 +04:00
|
|
|
// Get the name of a language
|
2004-07-28 22:31:30 +04:00
|
|
|
const char *GetLangName(int langId);
|
2004-08-19 20:37:32 +04:00
|
|
|
// Check if a language exists
|
2004-07-28 22:31:30 +04:00
|
|
|
bool LangExists(const char *langName);
|
|
|
|
|
2004-08-19 20:37:32 +04:00
|
|
|
// When a language id in a format string in FormatAmxString is LANG_PLAYER, the glob id decides which language to take.
|
2004-07-28 22:31:30 +04:00
|
|
|
void SetDefLang(int id);
|
2004-08-19 20:37:32 +04:00
|
|
|
|
2005-11-21 13:04:43 +03:00
|
|
|
inline int GetDefLang() const { return m_CurGlobId; }
|
|
|
|
|
2004-08-19 20:37:32 +04:00
|
|
|
// Reset
|
2004-07-28 22:31:30 +04:00
|
|
|
void Clear();
|
2004-08-15 14:53:48 +04:00
|
|
|
|
|
|
|
CLangMngr();
|
|
|
|
~CLangMngr();
|
2004-07-27 23:54:21 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //_INCLUDE_CLANG_H
|