2004-07-27 19:54:21 +00:00
|
|
|
/* AMX Mod X
|
|
|
|
*
|
|
|
|
* by the AMX Mod X Development Team
|
|
|
|
* originally developed by OLO
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program 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; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the author gives permission to
|
|
|
|
* link the code of this program with the Half-Life Game Engine ("HL
|
|
|
|
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
|
|
|
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
|
|
|
* respects for all of the code used other than the HL Engine and MODs
|
|
|
|
* from Valve. If you modify this file, you may extend this exception
|
|
|
|
* to your version of the file, but you are not obligated to do so. If
|
|
|
|
* you do not wish to do so, delete this exception statement from your
|
|
|
|
* version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE_CLANG_H
|
|
|
|
#define _INCLUDE_CLANG_H
|
|
|
|
|
2004-08-13 16:21:15 +00:00
|
|
|
#define LANG_SERVER 0
|
|
|
|
#define LANG_PLAYER -1
|
2004-07-28 18:31:30 +00:00
|
|
|
|
2004-08-15 10:53:48 +00:00
|
|
|
struct md5Pair
|
2004-07-27 19:54:21 +00:00
|
|
|
{
|
2004-08-15 10:53:48 +00:00
|
|
|
String file;
|
|
|
|
String val;
|
|
|
|
};
|
2004-07-27 19:54:21 +00:00
|
|
|
|
2004-08-15 10:53:48 +00:00
|
|
|
struct keyEntry
|
|
|
|
{
|
|
|
|
String key;
|
|
|
|
uint32_t hash;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sKeyDef
|
|
|
|
{
|
|
|
|
sKeyDef() { key = -1; def = 0; }
|
|
|
|
~sKeyDef() { if (def) delete def; }
|
|
|
|
int key;
|
|
|
|
String *def;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CLangMngr
|
|
|
|
{
|
2004-07-27 19:54:21 +00:00
|
|
|
class CLang
|
|
|
|
{
|
|
|
|
public:
|
2004-08-19 16:37:32 +00:00
|
|
|
// Construct an empty CLang object
|
2004-07-27 19:54:21 +00:00
|
|
|
CLang();
|
2004-08-19 16:37:32 +00:00
|
|
|
// Construct a CLang object initialized with a language name
|
2004-07-27 19:54:21 +00:00
|
|
|
CLang(const char *lang);
|
2004-08-19 16:37:32 +00:00
|
|
|
// Destructor
|
2004-07-27 19:54:21 +00:00
|
|
|
~CLang();
|
|
|
|
|
2004-08-19 16:37:32 +00:00
|
|
|
// Get the definition
|
2004-07-27 19:54:21 +00:00
|
|
|
const char *GetDef(const char *key);
|
2004-08-19 16:37:32 +00:00
|
|
|
// Add definitions to this language
|
2004-08-15 10:53:48 +00:00
|
|
|
void MergeDefinitions(CQueue <sKeyDef*> & vec);
|
2004-08-19 16:37:32 +00:00
|
|
|
// Reset this language
|
2004-07-27 19:54:21 +00:00
|
|
|
void Clear();
|
|
|
|
|
2004-08-19 16:37:32 +00:00
|
|
|
// compare this language to a language name
|
2004-07-27 19:54:21 +00:00
|
|
|
friend bool operator == (const CLang &left, const char *right)
|
|
|
|
{
|
|
|
|
return strcmp(left.m_LanguageName, right)==0 ? true : false;
|
|
|
|
}
|
2004-08-19 16:37:32 +00:00
|
|
|
// Get language name
|
2004-07-27 19:54:21 +00:00
|
|
|
const char *GetName() { return m_LanguageName; }
|
2004-08-19 16:37:32 +00:00
|
|
|
// Save to file
|
2004-08-15 15:26:46 +00:00
|
|
|
bool Save(FILE *fp, int &defOffset, uint32_t &curOffset);
|
|
|
|
bool SaveDefinitions(FILE *fp, uint32_t &curOffset);
|
2004-08-19 16:37:32 +00:00
|
|
|
// Load
|
2004-07-27 19:54:21 +00:00
|
|
|
bool Load(FILE *fp);
|
2004-08-19 16:37:32 +00:00
|
|
|
void SetMngr(CLangMngr *l) { m_LMan = l; }
|
|
|
|
// Get number of entries
|
2004-08-15 15:26:46 +00:00
|
|
|
int Entries() { return m_LookUpTable.size(); }
|
2004-08-19 16:37:32 +00:00
|
|
|
protected:
|
|
|
|
// Make a hash from a string; convert to lowercase first if needed
|
2004-07-28 18:31:30 +00:00
|
|
|
static uint32_t MakeHash(const char *src, bool makeLower = false);
|
2004-07-27 19:54:21 +00:00
|
|
|
|
2004-08-19 16:37:32 +00:00
|
|
|
// An entry in the language
|
2004-07-27 19:54:21 +00:00
|
|
|
class LangEntry
|
|
|
|
{
|
2004-08-19 16:37:32 +00:00
|
|
|
// the definition hash
|
2004-07-27 19:54:21 +00:00
|
|
|
uint32_t m_DefHash;
|
2004-08-19 16:37:32 +00:00
|
|
|
// index into the lookup table?
|
2004-08-15 10:53:48 +00:00
|
|
|
int key;
|
2004-08-19 16:37:32 +00:00
|
|
|
// the definition
|
2004-08-15 10:53:48 +00:00
|
|
|
String m_pDef;
|
2004-07-27 19:54:21 +00:00
|
|
|
public:
|
2004-08-19 16:37:32 +00:00
|
|
|
// Set
|
2004-08-15 10:53:48 +00:00
|
|
|
void SetKey(int key);
|
|
|
|
void SetDef(const char *pDef);
|
2004-08-19 16:37:32 +00:00
|
|
|
// Get
|
2004-07-27 19:54:21 +00:00
|
|
|
uint32_t GetDefHash();
|
2004-08-15 10:53:48 +00:00
|
|
|
int GetKey();
|
2004-07-27 19:54:21 +00:00
|
|
|
const char *GetDef();
|
2004-08-15 15:26:46 +00:00
|
|
|
int GetDefLength();
|
2004-07-27 19:54:21 +00:00
|
|
|
|
2004-08-19 16:37:32 +00:00
|
|
|
// Constructors / destructors
|
2004-07-27 19:54:21 +00:00
|
|
|
LangEntry();
|
2004-08-15 10:53:48 +00:00
|
|
|
LangEntry(int key);
|
|
|
|
LangEntry(int key, const char *pDef);
|
2004-07-27 19:54:21 +00:00
|
|
|
LangEntry(const LangEntry &other);
|
2004-08-15 15:26:46 +00:00
|
|
|
LangEntry(int pKey, uint32_t defHash, const char *pDef);
|
2004-07-27 19:54:21 +00:00
|
|
|
|
2004-08-19 16:37:32 +00:00
|
|
|
// Reset
|
2004-07-27 19:54:21 +00:00
|
|
|
void Clear();
|
|
|
|
};
|
|
|
|
|
2004-08-19 16:37:32 +00:00
|
|
|
// Get (construct if needed) an entry
|
2004-08-15 10:53:48 +00:00
|
|
|
LangEntry * GetEntry(int key);
|
2004-08-19 16:37:32 +00:00
|
|
|
|
2004-08-15 10:53:48 +00:00
|
|
|
typedef CVector<LangEntry*> LookUpVec;
|
2004-07-27 19:54:21 +00:00
|
|
|
typedef LookUpVec::iterator LookUpVecIter;
|
|
|
|
|
|
|
|
char m_LanguageName[3];
|
|
|
|
|
2004-08-19 16:37:32 +00:00
|
|
|
// our lookup table
|
2004-07-27 19:54:21 +00:00
|
|
|
LookUpVec m_LookUpTable;
|
2004-08-19 16:37:32 +00:00
|
|
|
CLangMngr *m_LMan;
|
2004-08-15 15:26:46 +00:00
|
|
|
public:
|
2004-08-19 16:37:32 +00:00
|
|
|
LangEntry *AddEntry(int pKey, uint32_t defHash, const char *def);
|
2004-07-27 19:54:21 +00:00
|
|
|
};
|
|
|
|
|
2004-08-19 16:37:32 +00:00
|
|
|
// Merge definitions into a language
|
2004-08-15 10:53:48 +00:00
|
|
|
void MergeDefinitions(const char *lang, CQueue <sKeyDef*> &tmpVec);
|
2004-08-19 16:37:32 +00:00
|
|
|
// strip lowercase; make lower if needed
|
2004-07-27 19:54:21 +00:00
|
|
|
static size_t strip(char *str, char *newstr, bool makelower=false);
|
|
|
|
|
2004-08-15 10:53:48 +00:00
|
|
|
typedef CVector<CLang*> LangVec;
|
|
|
|
typedef CVector<CLang*>::iterator LangVecIter;
|
2004-07-27 19:54:21 +00:00
|
|
|
|
|
|
|
LangVec m_Languages;
|
2004-08-19 16:37:32 +00:00
|
|
|
|
2004-08-15 10:53:48 +00:00
|
|
|
CVector<md5Pair *> FileList;
|
|
|
|
CVector<keyEntry*> KeyList;
|
2004-07-27 19:54:21 +00:00
|
|
|
|
2004-08-19 16:37:32 +00:00
|
|
|
// Get a lang object (construct if needed)
|
2004-08-15 10:53:48 +00:00
|
|
|
CLang * GetLang(const char *name);
|
2004-07-27 19:54:21 +00:00
|
|
|
|
2004-08-19 16:37:32 +00:00
|
|
|
// Current global client-id for functions like client_print with first parameter 0
|
2004-07-28 18:31:30 +00:00
|
|
|
int m_CurGlobId;
|
2004-07-27 19:54:21 +00:00
|
|
|
public:
|
2004-08-19 16:37:32 +00:00
|
|
|
// Merge a definitions file
|
2004-07-27 19:54:21 +00:00
|
|
|
int MergeDefinitionFile(const char *file);
|
2004-08-19 16:37:32 +00:00
|
|
|
// Get a definition from a lang name and a kyer
|
2004-07-27 19:54:21 +00:00
|
|
|
const char *GetDef(const char *langName, const char *key);
|
2004-08-19 16:37:32 +00:00
|
|
|
// Format a string
|
2004-07-28 18:31:30 +00:00
|
|
|
const char *Format(const char *src, ...);
|
2004-08-19 16:37:32 +00:00
|
|
|
// Format a string for an AMX plugin
|
2004-07-28 18:31:30 +00:00
|
|
|
char *FormatAmxString(AMX *amx, cell *params, int parm, int &len);
|
2004-08-19 16:37:32 +00:00
|
|
|
// Save
|
2004-07-27 19:54:21 +00:00
|
|
|
bool Save(const char *filename);
|
2004-08-19 16:37:32 +00:00
|
|
|
// Load
|
2004-07-27 19:54:21 +00:00
|
|
|
bool Load(const char *filename);
|
2004-08-19 16:37:32 +00:00
|
|
|
// Cache
|
2004-08-15 10:53:48 +00:00
|
|
|
bool LoadCache(const char *filename);
|
|
|
|
bool SaveCache(const char *filename);
|
2004-08-19 16:37:32 +00:00
|
|
|
// Get index
|
2004-08-15 10:53:48 +00:00
|
|
|
int GetKeyEntry(String &key);
|
|
|
|
int GetKeyEntry(const char *key);
|
|
|
|
int GetKeyHash(int key);
|
2004-08-19 16:37:32 +00:00
|
|
|
// Get key from index
|
2004-08-15 10:53:48 +00:00
|
|
|
const char *GetKey(int key);
|
2004-08-19 16:37:32 +00:00
|
|
|
// Add key
|
2004-08-15 10:53:48 +00:00
|
|
|
int AddKeyEntry(String &key);
|
2004-08-19 16:37:32 +00:00
|
|
|
// Make a hash from a string; convert to lowercase first if needed
|
2004-08-15 10:53:48 +00:00
|
|
|
uint32_t MakeHash(const char *src, bool makeLower);
|
2004-07-28 18:31:30 +00:00
|
|
|
|
2004-08-19 16:37:32 +00:00
|
|
|
// Get the number of languages
|
2004-07-28 18:31:30 +00:00
|
|
|
int GetLangsNum();
|
2004-08-19 16:37:32 +00:00
|
|
|
// Get the name of a language
|
2004-07-28 18:31:30 +00:00
|
|
|
const char *GetLangName(int langId);
|
2004-08-19 16:37:32 +00:00
|
|
|
// Check if a language exists
|
2004-07-28 18:31:30 +00:00
|
|
|
bool LangExists(const char *langName);
|
|
|
|
|
2004-08-19 16:37:32 +00: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 18:31:30 +00:00
|
|
|
void SetDefLang(int id);
|
2004-08-19 16:37:32 +00:00
|
|
|
|
|
|
|
// Reset
|
2004-07-28 18:31:30 +00:00
|
|
|
void Clear();
|
2004-08-15 10:53:48 +00:00
|
|
|
|
|
|
|
CLangMngr();
|
|
|
|
~CLangMngr();
|
2004-07-27 19:54:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //_INCLUDE_CLANG_H
|