latest cleaned files for today (i cant read more :o )

This commit is contained in:
Borja Ferrer 2005-09-10 03:39:23 +00:00
parent 16ad8739e7
commit 52b1d67ca2
5 changed files with 598 additions and 465 deletions

View File

@ -35,8 +35,10 @@
// *****************************************************
// class CmdMngr
// *****************************************************
CmdMngr::CmdMngr() {
memset(sortedlists,0,sizeof(sortedlists));
CmdMngr::CmdMngr()
{
memset(sortedlists, 0, sizeof(sortedlists));
srvcmdlist = 0;
clcmdlist = 0;
prefixHead = 0;
@ -49,13 +51,12 @@ CmdMngr::CmdMngr() {
}
CmdMngr::Command::Command( CPluginMngr::CPlugin* pplugin,const char* pcmd,
const char* pinfo , int pflags , int pfunc,
bool pviewable, CmdMngr* pparent ) : commandline(pcmd) , info(pinfo) {
CmdMngr::Command::Command(CPluginMngr::CPlugin* pplugin, const char* pcmd, const char* pinfo, int pflags,
int pfunc, bool pviewable, CmdMngr* pparent) : commandline(pcmd), info(pinfo)
{
char szCmd[64], szArg[64];
*szCmd = 0; *szArg=0;
sscanf(pcmd,"%s %s",szCmd,szArg);
*szCmd = 0; *szArg = 0;
sscanf(pcmd, "%s %s", szCmd, szArg);
command.assign(szCmd);
argument.assign(szArg);
plugin = pplugin;
@ -73,180 +74,190 @@ CmdMngr::Command::~Command()
++uniqueid;
}
CmdMngr::Command* CmdMngr::registerCommand( CPluginMngr::CPlugin* plugin , int func , char* cmd , char* info , int level , bool listable )
CmdMngr::Command* CmdMngr::registerCommand(CPluginMngr::CPlugin* plugin, int func, char* cmd, char* info, int level, bool listable)
{
Command* b = new Command( plugin , cmd , info , level , func , listable, this );
if ( b == 0 ) return 0;
setCmdLink( &sortedlists[0] , b );
return b;
Command* b = new Command(plugin, cmd, info, level, func, listable, this);
if (b == 0) return 0;
setCmdLink(&sortedlists[0], b);
return b;
}
CmdMngr::Command* CmdMngr::getCmd( long int id ,int type, int access )
CmdMngr::Command* CmdMngr::getCmd(long int id, int type, int access)
{
//if ( id >= 1024 || id < 0 ) return (Command*)id;
if ( id < 0 ){
for (CmdMngr::iterator a = begin( type ); a ; ++a){
if ( (*a).id == id )
//if (id >= 1024 || id < 0) return (Command*)id;
if (id < 0)
{
for (CmdMngr::iterator a = begin(type); a ; ++a)
{
if ((*a).id == id)
return &(*a);
}
return 0;
}
if ( (id < buf_cmdid) || (access != buf_cmdaccess) || (type != buf_cmdtype) )
if ((id < buf_cmdid) || (access != buf_cmdaccess) || (type != buf_cmdtype))
{
buf_cmdptr = begin( type );
buf_cmdptr = begin(type);
buf_cmdaccess = access;
buf_cmdtype = type;
buf_cmdid = id;
}
else
{
} else {
int a = id;
id -= buf_cmdid;
buf_cmdid = a;
}
while ( buf_cmdptr )
while (buf_cmdptr)
{
if ( (*buf_cmdptr).gotAccess( access ) &&
(*buf_cmdptr).getPlugin()->isExecutable( (*buf_cmdptr).getFunction() )
&& (*buf_cmdptr).isViewable() )
if ((*buf_cmdptr).gotAccess(access) && (*buf_cmdptr).getPlugin()->isExecutable((*buf_cmdptr).getFunction())
&& (*buf_cmdptr).isViewable())
{
if ( id-- == 0 )
if (id-- == 0)
return &(*buf_cmdptr);
}
++buf_cmdptr;
}
return 0;
}
int CmdMngr::getCmdNum( int type, int access )
int CmdMngr::getCmdNum(int type, int access)
{
if ( (access == buf_access) && (type == buf_type) )
return buf_num; // once calculated don't have to be done again
if ((access == buf_access) && (type == buf_type))
return buf_num; // once calculated don't have to be done again
buf_access = access;
buf_type = type;
buf_num = 0;
CmdMngr::iterator a = begin( type );
CmdMngr::iterator a = begin(type);
while ( a )
while (a)
{
if ( (*a).gotAccess( access ) &&
(*a).getPlugin()->isExecutable( (*a).getFunction() )
&& (*a).isViewable() )
++buf_num;
if ((*a).gotAccess(access) && (*a).getPlugin()->isExecutable((*a).getFunction()) && (*a).isViewable())
++buf_num;
++a;
}
return buf_num;
}
void CmdMngr::setCmdLink( CmdLink** a , Command* c, bool sorted )
void CmdMngr::setCmdLink(CmdLink** a, Command* c, bool sorted)
{
CmdLink* np = new CmdLink( c );
CmdLink* np = new CmdLink(c);
if ( np == 0 ) return;
if (np == 0) return;
if ( sorted )
if (sorted)
{
while( *a )
while (*a)
{
int i = strcmp(c->getCommand(),(*a)->cmd->getCommand() );
int i = strcmp(c->getCommand(),(*a)->cmd->getCommand());
if ( (i<0) || (i==0) && ( strcmp( c->getArgument() , (*a)->cmd->getArgument() ) < 0 ) )
if ((i < 0) || (i == 0) && (strcmp(c->getArgument(), (*a)->cmd->getArgument()) < 0))
break;
a = &(*a)->next;
}
np->next = *a;
*a = np;
}
else
{
while ( *a ) a = &(*a)->next;
} else {
while (*a) a = &(*a)->next;
*a = np;
}
}
void CmdMngr::clearCmdLink( CmdLink** phead, bool pclear )
void CmdMngr::clearCmdLink(CmdLink** phead, bool pclear)
{
while( *phead ){
while (*phead)
{
CmdLink* pp = (*phead)->next;
if ( pclear ) delete (*phead)->cmd;
if (pclear) delete (*phead)->cmd;
delete *phead;
*phead = pp;
}
}
void CmdMngr::Command::setCmdType( int a )
void CmdMngr::Command::setCmdType(int a)
{
switch(a){
case CMD_ConsoleCommand: cmdtype |= 3; break;
case CMD_ClientCommand: cmdtype |= 1; break;
case CMD_ServerCommand: cmdtype |= 2; break;
switch(a)
{
case CMD_ConsoleCommand: cmdtype |= 3; break;
case CMD_ClientCommand: cmdtype |= 1; break;
case CMD_ServerCommand: cmdtype |= 2; break;
}
if ( cmdtype & 1 ) { // ClientCommand
parent->setCmdLink( &parent->sortedlists[1] , this );
if ( !parent->registerCmdPrefix( this ) )
parent->setCmdLink( &parent->clcmdlist , this , false );
if (cmdtype & 1) // ClientCommand
{
parent->setCmdLink(&parent->sortedlists[1], this);
if (!parent->registerCmdPrefix(this))
parent->setCmdLink(&parent->clcmdlist, this, false);
}
if ( cmdtype & 2 ) { // ServerCommand
parent->setCmdLink( &parent->sortedlists[2] , this );
parent->setCmdLink( &parent->srvcmdlist , this , false );
if (cmdtype & 2) // ServerCommand
{
parent->setCmdLink(&parent->sortedlists[2], this);
parent->setCmdLink(&parent->srvcmdlist, this, false);
}
}
const char* CmdMngr::Command::getCmdType() const {
switch( cmdtype ){
case 1: return"client";
case 2: return "server";
case 3: return "console";
const char* CmdMngr::Command::getCmdType() const
{
switch(cmdtype)
{
case 1: return "client";
case 2: return "server";
case 3: return "console";
}
return "unknown";
}
bool CmdMngr::registerCmdPrefix( Command* cc )
bool CmdMngr::registerCmdPrefix(Command* cc)
{
CmdPrefix** b = findPrefix( cc->getCommand() );
if (*b){
setCmdLink( &(*b)->list , cc , false );
CmdPrefix** b = findPrefix(cc->getCommand());
if (*b)
{
setCmdLink(&(*b)->list, cc, false);
cc->prefix = (*b)->name.size();
return true;
}
return false;
}
void CmdMngr::registerPrefix( const char* nn )
void CmdMngr::registerPrefix(const char* nn)
{
if ( *nn == 0 ) return;
CmdPrefix** b = findPrefix( nn );
if (*nn == 0) return;
CmdPrefix** b = findPrefix(nn);
if (*b) return;
*b = new CmdPrefix( nn , this );
*b = new CmdPrefix(nn, this);
}
CmdMngr::CmdPrefix** CmdMngr::findPrefix( const char* nn ){
CmdMngr::CmdPrefix** CmdMngr::findPrefix(const char* nn)
{
CmdPrefix** aa = &prefixHead;
while(*aa){
if ( !strncmp( (*aa)->name.c_str(), nn, (*aa)->name.size() ) )
while (*aa)
{
if (!strncmp((*aa)->name.c_str(), nn, (*aa)->name.size()))
break;
aa=&(*aa)->next;
aa = &(*aa)->next;
}
return aa;
}
void CmdMngr::clearPrefix(){
while(prefixHead){
void CmdMngr::clearPrefix()
{
while (prefixHead)
{
CmdPrefix* a = prefixHead->next;
delete prefixHead;
prefixHead = a;
@ -264,7 +275,8 @@ void CmdMngr::clear()
clearBufforedInfo();
}
void CmdMngr::clearBufforedInfo() {
void CmdMngr::clearBufforedInfo()
{
buf_type = -1;
buf_access = 0;
buf_id = -1;
@ -274,4 +286,3 @@ void CmdMngr::clearBufforedInfo() {
}
int CmdMngr::Command::uniqueid = 0;

View File

@ -36,7 +36,7 @@
// class ClEvent
// *****************************************************
EventsMngr::ClEvent::ClEvent(CPluginMngr::CPlugin* plugin, int func, int flags)
EventsMngr::ClEvent::ClEvent(CPluginMngr::CPlugin* plugin, int func, int flags)
{
m_Plugin = plugin;
m_Func = func;
@ -45,13 +45,14 @@ EventsMngr::ClEvent::ClEvent(CPluginMngr::CPlugin* plugin, int func, int flags)
m_FlagAlive = true;
m_FlagDead = true;
m_FlagWorld = (flags & 1) ? true : false; // flag a
m_FlagPlayer = (flags & 2) ? true : false; // flag b
m_FlagOnce = (flags & 4) ? true : false; // flag c
m_FlagWorld = (flags & 1) ? true : false; // flag a
m_FlagPlayer = (flags & 2) ? true : false; // flag b
m_FlagOnce = (flags & 4) ? true : false; // flag c
if (flags & 24)
{
m_FlagAlive = (flags & 16) ? true : false; // flag e
m_FlagDead = (flags & 8) ? true : false; // flag d
m_FlagAlive = (flags & 16) ? true : false; // flag e
m_FlagDead = (flags & 8) ? true : false; // flag d
}
m_Stamp = 0.0f;
@ -64,12 +65,14 @@ EventsMngr::ClEvent::~ClEvent()
{
cond_t *tmp1 = m_Conditions;
cond_t *tmp2 = NULL;
while (tmp1)
{
tmp2 = tmp1->next;
delete tmp1;
tmp1 = tmp2;
}
m_Conditions = NULL;
}
@ -82,14 +85,17 @@ void EventsMngr::NextParam()
MsgDataEntry *tmp = NULL;
int tmpSize = 0;
if (m_ParseVault)
{
// copy to tmp
tmp = new MsgDataEntry[m_ParseVaultSize];
if (!tmp)
{
return; // :TODO: Error report !!
}
memcpy(tmp, m_ParseVault, m_ParseVaultSize * sizeof(MsgDataEntry));
tmpSize = m_ParseVaultSize;
delete [] m_ParseVault;
@ -102,6 +108,7 @@ void EventsMngr::NextParam()
m_ParseVaultSize = INITIAL_PARSEVAULT_SIZE;
m_ParseVault = new MsgDataEntry[m_ParseVaultSize];
if (tmp)
{
memcpy(m_ParseVault, tmp, tmpSize * sizeof(MsgDataEntry));
@ -178,10 +185,11 @@ void EventsMngr::ClEvent::registerFilter(char *filter)
if (m_Conditions)
{
cond_t *tmp = m_Conditions;
while (tmp->next)
tmp = tmp->next;
tmp->next = tmpCond;
}
else
m_Conditions = tmpCond;
@ -194,6 +202,7 @@ EventsMngr::ClEvent* EventsMngr::registerEvent(CPluginMngr::CPlugin* plugin, int
return NULL;
ClEvent *event = new ClEvent(plugin, func, flags);
if (!event)
return NULL;
@ -216,12 +225,11 @@ void EventsMngr::parserInit(int msg_type, float* timer, CPlayer* pPlayer, int in
if (!m_Events[msg_type].size())
return;
for(ClEventVecIter iter = m_Events[msg_type].begin(); iter; ++iter)
for (ClEventVecIter iter = m_Events[msg_type].begin(); iter; ++iter)
{
if ((*iter).m_Done)
continue;
if (!(*iter).m_Plugin->isExecutable((*iter).m_Func))
{
(*iter).m_Done = true;
@ -230,7 +238,7 @@ void EventsMngr::parserInit(int msg_type, float* timer, CPlayer* pPlayer, int in
if (pPlayer)
{
if (!(*iter).m_FlagPlayer || (pPlayer->IsAlive() ? !(*iter).m_FlagAlive : !(*iter).m_FlagDead ) )
if (!(*iter).m_FlagPlayer || (pPlayer->IsAlive() ? !(*iter).m_FlagAlive : !(*iter).m_FlagDead))
{
(*iter).m_Done = true;
continue;
@ -247,6 +255,7 @@ void EventsMngr::parserInit(int msg_type, float* timer, CPlayer* pPlayer, int in
(*iter).m_Done = true;
continue;
}
m_ParseNotDone = true;
}
@ -257,6 +266,7 @@ void EventsMngr::parserInit(int msg_type, float* timer, CPlayer* pPlayer, int in
m_ParseVault[0].type = MSG_INTEGER;
m_ParseVault[0].iValue = index;
}
m_ParseFun = &m_Events[msg_type];
}
@ -266,7 +276,6 @@ void EventsMngr::parseValue(int iValue)
if (!m_ParseNotDone || !m_ParseFun)
return;
// grow if needed
++m_ParsePos;
NextParam();
@ -284,6 +293,7 @@ void EventsMngr::parseValue(int iValue)
// loop through conditions
bool execute = false;
bool anyConditions = false;
for (ClEvent::cond_t *condIter = (*iter).m_Conditions; condIter; condIter = condIter->next)
{
if (condIter->paramId == m_ParsePos)
@ -291,11 +301,11 @@ void EventsMngr::parseValue(int iValue)
anyConditions = true;
switch(condIter->type)
{
case '=': if (condIter->iValue == iValue) execute=true; break;
case '!': if (condIter->iValue != iValue) execute=true; break;
case '&': if (iValue & condIter->iValue) execute=true; break;
case '<': if (iValue < condIter->iValue) execute=true; break;
case '>': if (iValue > condIter->iValue) execute=true; break;
case '=': if (condIter->iValue == iValue) execute = true; break;
case '!': if (condIter->iValue != iValue) execute = true; break;
case '&': if (iValue & condIter->iValue) execute = true; break;
case '<': if (iValue < condIter->iValue) execute = true; break;
case '>': if (iValue > condIter->iValue) execute = true; break;
}
if (execute)
break;
@ -312,7 +322,6 @@ void EventsMngr::parseValue(float fValue)
if (!m_ParseNotDone || !m_ParseFun)
return;
// grow if needed
++m_ParsePos;
NextParam();
@ -330,6 +339,7 @@ void EventsMngr::parseValue(float fValue)
// loop through conditions
bool execute = false;
bool anyConditions = false;
for (ClEvent::cond_t *condIter = (*iter).m_Conditions; condIter; condIter = condIter->next)
{
if (condIter->paramId == m_ParsePos)
@ -337,10 +347,10 @@ void EventsMngr::parseValue(float fValue)
anyConditions = true;
switch(condIter->type)
{
case '=': if (condIter->fValue == fValue) execute=true; break;
case '!': if (condIter->fValue != fValue) execute=true; break;
case '<': if (fValue < condIter->fValue) execute=true; break;
case '>': if (fValue > condIter->fValue) execute=true; break;
case '=': if (condIter->fValue == fValue) execute = true; break;
case '!': if (condIter->fValue != fValue) execute = true; break;
case '<': if (fValue < condIter->fValue) execute = true; break;
case '>': if (fValue > condIter->fValue) execute = true; break;
}
if (execute)
break;
@ -374,6 +384,7 @@ void EventsMngr::parseValue(const char *sz)
// loop through conditions
bool execute = false;
bool anyConditions = false;
for (ClEvent::cond_t *condIter = (*iter).m_Conditions; condIter; condIter = condIter->next)
{
if (condIter->paramId == m_ParsePos)
@ -381,9 +392,9 @@ void EventsMngr::parseValue(const char *sz)
anyConditions = true;
switch(condIter->type)
{
case '=': if (!strcmp(sz, condIter->sValue.c_str())) execute=true; break;
case '!': if (strcmp(sz, condIter->sValue.c_str())) execute=true; break;
case '&': if (strstr(sz, condIter->sValue.c_str())) execute=true; break;
case '=': if (!strcmp(sz, condIter->sValue.c_str())) execute = true; break;
case '!': if (strcmp(sz, condIter->sValue.c_str())) execute = true; break;
case '&': if (strstr(sz, condIter->sValue.c_str())) execute = true; break;
}
if (execute)
break;
@ -403,11 +414,12 @@ void EventsMngr::executeEvents()
for (ClEventVecIter iter = m_ParseFun->begin(); iter; ++iter)
{
if ( (*iter).m_Done )
if ((*iter).m_Done)
{
(*iter).m_Done = false;
continue;
}
(*iter).m_Stamp = (float)*m_Timer;
executeForwards((*iter).m_Func, m_ParseVault ? m_ParseVault[0].iValue : 0);
}
@ -423,53 +435,53 @@ int EventsMngr::getArgNum() const
const char* EventsMngr::getArgString(int a) const
{
if ( a < 0 || a > m_ParsePos )
if (a < 0 || a > m_ParsePos)
return "";
static char var[32];
switch(m_ParseVault[a].type)
{
case MSG_INTEGER:
sprintf( var, "%d", m_ParseVault[a].iValue );
return var;
case MSG_STRING:
return m_ParseVault[a].sValue;
default:
sprintf( var, "%g", m_ParseVault[a].fValue );
return var;
case MSG_INTEGER:
sprintf(var, "%d", m_ParseVault[a].iValue);
return var;
case MSG_STRING:
return m_ParseVault[a].sValue;
default:
sprintf(var, "%g", m_ParseVault[a].fValue);
return var;
}
}
int EventsMngr::getArgInteger(int a) const
{
if ( a < 0 || a > m_ParsePos )
if (a < 0 || a > m_ParsePos)
return 0;
switch(m_ParseVault[a].type)
{
case MSG_INTEGER:
return m_ParseVault[a].iValue;
case MSG_STRING:
return atoi(m_ParseVault[a].sValue);
default:
return (int)m_ParseVault[a].fValue;
case MSG_INTEGER:
return m_ParseVault[a].iValue;
case MSG_STRING:
return atoi(m_ParseVault[a].sValue);
default:
return (int)m_ParseVault[a].fValue;
}
}
float EventsMngr::getArgFloat(int a) const
{
if ( a < 0 || a > m_ParsePos )
if (a < 0 || a > m_ParsePos)
return 0.0f;
switch(m_ParseVault[a].type)
{
case MSG_INTEGER:
return static_cast<float>(m_ParseVault[a].iValue);
case MSG_STRING:
return static_cast<float>(atof(m_ParseVault[a].sValue));
default:
return m_ParseVault[a].fValue;
case MSG_INTEGER:
return static_cast<float>(m_ParseVault[a].iValue);
case MSG_STRING:
return static_cast<float>(atof(m_ParseVault[a].sValue));
default:
return m_ParseVault[a].fValue;
}
}
@ -479,6 +491,7 @@ void EventsMngr::clearEvents(void)
{
m_Events[i].clear();
}
// delete parsevault
if (m_ParseVault)
{
@ -497,25 +510,26 @@ int EventsMngr::getEventId(const char* msg)
CS_EventsIds id;
} table[] =
{
{ "CS_DeathMsg" , CS_DeathMsg },
// { "CS_RoundEnd" , CS_RoundEnd },
// { "CS_RoundStart" , CS_RoundStart },
// { "CS_Restart" , CS_Restart },
{ "" , CS_Null }
{"CS_DeathMsg", CS_DeathMsg},
// {"CS_RoundEnd", CS_RoundEnd},
// {"CS_RoundStart", CS_RoundStart},
// {"CS_Restart", CS_Restart},
{"", CS_Null}
};
// if msg is a number, return it
int pos = atoi(msg);
if (pos != 0)
return pos;
// try to find in table first
for (pos = 0; table[ pos ].id != CS_Null; ++pos )
if ( !strcmp( table[ pos ].name , msg ) )
return table[ pos ].id;
for (pos = 0; table[pos].id != CS_Null; ++pos)
if (!strcmp(table[pos].name, msg))
return table[pos].id;
// find the id of the message
return pos = GET_USER_MSG_ID(PLID, msg , 0 );
return pos = GET_USER_MSG_ID(PLID, msg, 0);
}
int EventsMngr::getCurrentMsgType()

View File

@ -36,91 +36,91 @@
// *****************************************************
// class File
// *****************************************************
File::File( const char* n, const char* m )
File::File(const char* n, const char* m)
{
fp = fopen( n , m );
fp = fopen(n, m);
}
File::~File( )
File::~File()
{
if ( fp )
fclose( fp );
if (fp)
fclose(fp);
}
File::operator bool ( ) const
File::operator bool () const
{
return fp && !feof(fp);
return fp && !feof(fp);
}
File& operator<<( File& f, const String& n )
File& operator<<(File& f, const String& n)
{
if ( f ) fputs( n.c_str() , f.fp ) ;
return f;
if (f) fputs(n.c_str(), f.fp);
return f;
}
File& operator<<( File& f, const char* n )
File& operator<<(File& f, const char* n)
{
if ( f ) fputs( n , f.fp ) ;
return f;
if (f) fputs(n, f.fp);
return f;
}
File& operator<<( File& f, int n )
File& operator<<(File& f, int n)
{
if ( f ) fprintf( f.fp , "%d" , n ) ;
return f;
if (f) fprintf(f.fp, "%d", n);
return f;
}
File& operator<<( File& f, const char& c )
File& operator<<(File& f, const char& c)
{
if ( f ) fputc( c , f.fp ) ;
return f;
if (f) fputc(c, f.fp);
return f;
}
File& operator>>( File& f, String& n )
File& operator>>(File& f, String& n)
{
if ( !f ) return f;
char temp[1024];
fscanf( f.fp , "%s", temp );
n.assign(temp);
return f;
if (!f) return f;
char temp[1024];
fscanf(f.fp, "%s", temp);
n.assign(temp);
return f;
}
File& operator>>( File& f, char* n )
File& operator>>(File& f, char* n)
{
if ( f ) fscanf( f.fp , "%s", n );
return f;
if (f) fscanf(f.fp, "%s", n);
return f;
}
int File::getline( char* buf, int sz )
int File::getline(char* buf, int sz)
{
int a = sz;
char *origBuf = buf;
if ( *this )
{
int c;
while ( sz-- && (c = getc( (*this).fp)) && c != EOF && c != '\n' )
*buf++ = c;
*buf = 0;
}
// trim 0x0a and 0x0d characters at the end
while (buf != origBuf)
{
if (*buf == 0x0a || *buf == 0x0d)
int a = sz;
char *origBuf = buf;
if (*this)
{
int c;
while (sz-- && (c = getc((*this).fp)) && c != EOF && c != '\n')
*buf++ = c;
*buf = 0;
--buf;
}
}
return a - sz;
// trim 0x0a and 0x0d characters at the end
while (buf != origBuf)
{
if (*buf == 0x0a || *buf == 0x0d)
*buf = 0;
--buf;
}
return a - sz;
}
File& File::skipWs( )
File& File::skipWs()
{
if ( !*this ) return *this;
int c;
while( isspace( c = getc( fp ) ) ){};
ungetc( c , fp );
return *this;
if (!*this) return *this;
int c;
while (isspace(c = getc(fp))) {};
ungetc(c, fp);
return *this;
}

View File

@ -157,7 +157,7 @@ size_t CLangMngr::strip(char *str, char *newstr, bool makelower)
int flag = 0;
size_t strln = strlen(str);
for (i=strln-1; i>=0; i--)
for (i = strln - 1; i >= 0; i--)
{
if (str[i] == '\n' || str[i] == ' ' || str[i] == '\t')
{
@ -184,6 +184,7 @@ size_t CLangMngr::strip(char *str, char *newstr, bool makelower)
}
newstr[pos] = 0;
return ptr - str + 1;
}
@ -300,11 +301,12 @@ CLangMngr::CLang::~CLang()
void CLangMngr::CLang::Clear()
{
for (unsigned int i=0; i<m_LookUpTable.size(); i++)
for (unsigned int i = 0; i < m_LookUpTable.size(); i++)
{
if (m_LookUpTable[i])
delete m_LookUpTable[i];
}
m_LookUpTable.clear();
}
@ -312,7 +314,7 @@ CLangMngr::CLang::LangEntry * CLangMngr::CLang::GetEntry(int pkey)
{
unsigned int i;
for (i=0; i<m_LookUpTable.size(); i++)
for (i = 0; i < m_LookUpTable.size(); i++)
{
if (m_LookUpTable[i]->GetKey() == pkey)
{
@ -332,11 +334,13 @@ void CLangMngr::CLang::MergeDefinitions(CQueue<sKeyDef*> &vec)
{
const char *def = 0;
int key = -1;
while (!vec.empty())
{
key = vec.front()->key;
def = vec.front()->def->c_str();
LangEntry *entry = GetEntry(key);
if (entry->GetDefHash() != MakeHash(def))
{
if (entry->GetCache())
@ -348,6 +352,7 @@ void CLangMngr::CLang::MergeDefinitions(CQueue<sKeyDef*> &vec)
//AMXXLOG_Log("[AMXX] Language key %s[%s] defined twice", m_LMan->GetKey(key), m_LanguageName);
}
}
delete vec.front();
vec.pop();
}
@ -357,20 +362,22 @@ const char * CLangMngr::CLang::GetDef(const char *key)
{
static char nfind[1024] = "ML_NOTFOUND(KEY)";
int ikey = m_LMan->GetKeyEntry(key);
if (ikey == -1)
{
sprintf(nfind, "ML_NOTFOUND: %s", key);
return nfind;
}
for (unsigned int i = 0; i<m_LookUpTable.size(); i++)
for (unsigned int i = 0; i < m_LookUpTable.size(); i++)
{
if (m_LookUpTable[i]->GetKey() == ikey)
return m_LookUpTable[i]->GetDef();
}
return NULL;
}
struct OffsetPair
{
uint32_t defOffset;
@ -381,7 +388,8 @@ struct OffsetPair
bool CLangMngr::CLang::SaveDefinitions(FILE *fp, uint32_t &curOffset)
{
unsigned short defLen = 0;
for (unsigned int i = 0; i<m_LookUpTable.size(); i++)
for (unsigned int i = 0; i < m_LookUpTable.size(); i++)
{
defLen = m_LookUpTable[i]->GetDefLength();
fwrite((void *)&defLen, sizeof(unsigned short), 1, fp);
@ -403,7 +411,7 @@ bool CLangMngr::CLang::Save(FILE *fp, int &defOffset, uint32_t &curOffset)
fwrite((void*)&size, sizeof(uint32_t), 1, fp);
curOffset += sizeof(uint32_t);
for (unsigned int i = 0; i<m_LookUpTable.size(); i++)
for (unsigned int i = 0; i < m_LookUpTable.size(); i++)
{
keynum = m_LookUpTable[i]->GetKey();
defhash = m_LookUpTable[i]->GetDefHash();
@ -423,7 +431,6 @@ bool CLangMngr::CLang::Save(FILE *fp, int &defOffset, uint32_t &curOffset)
// assumes fp is set to the right position
bool CLangMngr::CLang::Load(FILE *fp)
{
return true;
}
@ -461,9 +468,10 @@ int CLangMngr::GetKeyEntry(const char *key)
return -1;
}
for (i = 0; i<KeyList.size(); i++)
for (i = 0; i < KeyList.size(); i++)
{
cmpKey = KeyList[i]->hash;
if (hKey == cmpKey)
{
return i;
@ -490,7 +498,7 @@ int CLangMngr::GetKeyEntry(String &key)
uint32_t hKey = MakeHash(key.c_str(), true);
unsigned int i = 0;
for (i = 0; i<KeyList.size(); i++)
for (i = 0; i < KeyList.size(); i++)
{
if (hKey == KeyList[i]->hash)
{
@ -521,6 +529,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
{
// number of parameters ( for NEXT_PARAM macro )
int paramCount = *params / sizeof(cell);
// the output buffer
static char outbuf[4096];
char *outptr = outbuf;
@ -531,13 +540,14 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
if (*src == '%')
{
++src;
if (*src=='L')
if (*src == 'L')
{
cell langName = params[parm]; // "en" case (langName contains the address to the string)
NEXT_PARAM();
cell *pAmxLangName = get_amxaddr(amx, params[parm++]); // other cases
const char *cpLangName=NULL;
// Handle player ids (1-32) and server language
if (*pAmxLangName == LANG_PLAYER) // LANG_PLAYER
{
if ((int)CVAR_GET_FLOAT("amx_client_languages") == 0)
@ -546,9 +556,11 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
} else {
cpLangName = ENTITY_KEYVALUE(GET_PLAYER_POINTER_I(m_CurGlobId)->pEdict, "lang");
}
} else if (*pAmxLangName == LANG_SERVER) { // LANG_SERVER
} else if (*pAmxLangName == LANG_SERVER) // LANG_SERVER
{
cpLangName = g_vault.get("server_language");
} else if (*pAmxLangName >= 1 && *pAmxLangName <= 32) { // Direct Client Id
} else if (*pAmxLangName >= 1 && *pAmxLangName <= 32) // Direct Client Id
{
if ((int)CVAR_GET_FLOAT("amx_client_languages") == 0)
{
cpLangName = g_vault.get("server_language");
@ -559,12 +571,15 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
int tmplen = 0;
cpLangName = get_amxstring(amx, langName, 2, tmplen);
}
if (!cpLangName || strlen(cpLangName) < 1)
cpLangName = "en";
int tmplen = 0;
NEXT_PARAM();
char *key = get_amxstring(amx, params[parm++], 1, tmplen);
const char *def = GetDef(cpLangName, key);
if (def == NULL)
{
if (*pAmxLangName != LANG_SERVER)
@ -583,6 +598,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
def = buf;
}
}
while (*def)
{
if (*def == '%')
@ -592,9 +608,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
{
*outptr++ = '%';
++def;
}
else
{
} else {
static char format[32];
format[0] = '%';
char *ptr = format+1;
@ -604,88 +618,89 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
ZEROTERM(format);
*ptr = 0;
switch ( *(ptr-1) )
switch (*(ptr - 1))
{
case 's':
case 's':
{
static char tmpString[4096];
char *tmpPtr = tmpString;
NEXT_PARAM();
cell *tmpCell = get_amxaddr(amx, params[parm++]);
while (tmpPtr-tmpString < sizeof(tmpString) && *tmpCell)
*tmpPtr++ = static_cast<char>(*tmpCell++);
*tmpPtr++ = static_cast<char>(*tmpCell++);
*tmpPtr = 0;
_snprintf(outptr, sizeof(outbuf)-(outptr-outbuf)-1, format, tmpString);
ZEROTERM(outbuf);
break;
}
case 'g':
case 'f':
case 'g':
case 'f':
{
NEXT_PARAM();
_snprintf(outptr, sizeof(outbuf)-(outptr-outbuf)-1, format, *(REAL*)get_amxaddr(amx, params[parm++]));
ZEROTERM(outbuf);
break;
}
case 'i':
case 'd':
case 'c':
case 'i':
case 'd':
case 'c':
{
NEXT_PARAM();
_snprintf(outptr, sizeof(outbuf)-(outptr-outbuf)-1, format, (int)*get_amxaddr(amx, params[parm++]));
ZEROTERM(outbuf);
break;
}
default:
default:
{
CHECK_OUTPTR(strlen(format)+1);
strcpy(outptr, format);
strcpy(outptr, format);
break;
}
}
outptr += strlen(outptr);
}
}
else if (*def == '^')
{
++def;
switch (*def)
{
case 'n':
CHECK_OUTPTR(1);
*outptr++ = '\n';
break;
case 't':
CHECK_OUTPTR(1);
*outptr++ = '\t';
break;
case '^':
CHECK_OUTPTR(1);
*outptr++ = '^';
break;
default:
CHECK_OUTPTR(2);
*outptr++ = '^';
*outptr++ = *def;
break;
case 'n':
CHECK_OUTPTR(1);
*outptr++ = '\n';
break;
case 't':
CHECK_OUTPTR(1);
*outptr++ = '\t';
break;
case '^':
CHECK_OUTPTR(1);
*outptr++ = '^';
break;
default:
CHECK_OUTPTR(2);
*outptr++ = '^';
*outptr++ = *def;
break;
}
++def;
}
else
{
} else {
CHECK_OUTPTR(1);
*outptr++ = *def++;
}
}
}
else
{
} else {
static char tmpString[4096];
char *tmpPtr = tmpString;
int tmpLen = 0;
static char format[32] = {'%'};
char *ptr = format+1;
if (*src != '%')
{
while (*src != 0 && ptr-format<sizeof(format) && !isalpha(*ptr++ = static_cast<char>(*src++)))
@ -693,9 +708,10 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
*ptr = 0;
ZEROTERM(format);
--src;
switch ( *(ptr-1) )
switch (*(ptr - 1))
{
case 's':
case 's':
{
NEXT_PARAM();
cell *tmpCell = get_amxaddr(amx, params[parm++]);
@ -706,45 +722,46 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
ZEROTERM(outbuf);
break;
}
case 'g':
case 'f':
case 'g':
case 'f':
{
NEXT_PARAM();
_snprintf(outptr, sizeof(outbuf)-(outptr-outbuf)-1, format, *(REAL*)get_amxaddr(amx, params[parm++]));
break;
}
case 'i':
case 'd':
case 'c':
case 'i':
case 'd':
case 'c':
{
NEXT_PARAM();
_snprintf(outptr, sizeof(outbuf)-(outptr-outbuf)-1, format, (int)*get_amxaddr(amx, params[parm++]));
break;
}
default:
default:
{
CHECK_OUTPTR(strlen(format)+1);
strcpy(outptr, format);
break;
}
}
outptr += strlen(outptr);
} else {
CHECK_OUTPTR(1);
*outptr++ = '%';
}
}
}
else
{
} else {
CHECK_OUTPTR(1);
*outptr++ = static_cast<char>(*src);
}
++src;
}
len = outptr - outbuf;
CHECK_OUTPTR(1);
*outptr++ = 0;
return outbuf;
}
@ -754,6 +771,7 @@ const char *CLangMngr::Format(const char *fmt, ...)
va_start(ap, fmt);
const char *retVal = FormatString(fmt, ap);
va_end(ap);
return retVal;
}
@ -782,12 +800,13 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
if (*src == '%')
{
++src;
if (*src=='L')
if (*src == 'L')
{
NEXT_PARAM();
const char *pAmxLangName = va_arg(ap, const char*);
const char *cpLangName=NULL;
// Handle player ids (1-32) and server language
if (pAmxLangName == (const char *)LANG_PLAYER) // LANG_PLAYER
{
if ((int)CVAR_GET_FLOAT("amx_client_languages"))
@ -796,9 +815,11 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
} else {
cpLangName = ENTITY_KEYVALUE(GET_PLAYER_POINTER_I(m_CurGlobId)->pEdict, "lang");
}
} else if (pAmxLangName == (const char *)LANG_SERVER) { // LANG_SERVER
} else if (pAmxLangName == (const char *)LANG_SERVER) // LANG_SERVER
{
cpLangName = g_vault.get("server_language");
} else if (pAmxLangName >= (const char *)1 && pAmxLangName <= (const char *)32) { // Direct Client Id
} else if (pAmxLangName >= (const char *)1 && pAmxLangName <= (const char *)32) // Direct Client Id
{
if ((int)CVAR_GET_FLOAT("amx_client_languages"))
{
cpLangName = g_vault.get("server_language");
@ -809,11 +830,14 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
int tmplen = 0;
cpLangName = pAmxLangName;
}
if (!cpLangName || strlen(cpLangName) < 1)
cpLangName = "en";
int tmplen = 0;
const char *key = va_arg(ap, const char *);
const char *def = GetDef(cpLangName, key);
if (def == NULL)
{
if (pAmxLangName != LANG_SERVER)
@ -832,6 +856,7 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
def = buf;
}
}
while (*def)
{
if (*def == '%')
@ -847,8 +872,72 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
*ptr = 0;
vsprintf(outptr, format, ap);
// vsprintf doesnt alter the ap, increment here
switch (*(ptr-1))
switch (*(ptr - 1))
{
case 'f':
va_arg(ap, double);
break;
case 's':
va_arg(ap, char *);
break;
case 'c':
case 'd':
case 'i':
default: // default: assume int-like parameter
va_arg(ap, int);
break;
}
outptr += strlen(outptr);
}
else if (*def == '^')
{
++def;
switch (*def)
{
case 'n':
CHECK_OUTPTR(1);
*outptr++ = '\n';
break;
case 't':
CHECK_OUTPTR(1);
*outptr++ = '\t';
break;
case '^':
CHECK_OUTPTR(1);
*outptr++ = '^';
break;
default:
CHECK_OUTPTR(2);
*outptr++ = '^';
*outptr++ = *def;
break;
}
++def;
} else {
CHECK_OUTPTR(1);
*outptr++ = *def++;
}
}
} else {
static char format[32] = {'%'};
char *ptr = format+1;
if (*src != '%')
{
while (*src != 0 && ptr-format < sizeof(format) && !isalpha(*ptr++ = *src++))
/*nothing*/;
*ptr = 0;
ZEROTERM(format);
--src;
vsprintf(outptr, format, ap);
// vsprintf doesnt alter the ap, increment here
switch (*(ptr - 1))
{
case 'f':
va_arg(ap, double);
break;
@ -861,85 +950,24 @@ char *CLangMngr::FormatString(const char *fmt, va_list &ap)
default: // default: assume int-like parameter
va_arg(ap, int);
break;
}
outptr += strlen(outptr);
}
else if (*def == '^')
{
++def;
switch (*def)
{
case 'n':
CHECK_OUTPTR(1);
*outptr++ = '\n';
break;
case 't':
CHECK_OUTPTR(1);
*outptr++ = '\t';
break;
case '^':
CHECK_OUTPTR(1);
*outptr++ = '^';
break;
default:
CHECK_OUTPTR(2);
*outptr++ = '^';
*outptr++ = *def;
break;
}
++def;
}
else
{
CHECK_OUTPTR(1);
*outptr++ = *def++;
}
}
}
else
{
static char format[32] = {'%'};
char *ptr = format+1;
if (*src != '%')
{
while (*src != 0 && ptr-format<sizeof(format) && !isalpha(*ptr++ = *src++))
/*nothing*/;
*ptr = 0;
ZEROTERM(format);
--src;
vsprintf(outptr, format, ap);
// vsprintf doesnt alter the ap, increment here
switch (*(ptr-1))
{
case 'f':
va_arg(ap, double);
break;
case 's':
va_arg(ap, char *);
break;
case 'c':
case 'd':
case 'i':
default: // default: assume int-like parameter
va_arg(ap, int);
break;
}
outptr += strlen(outptr);
} else {
CHECK_OUTPTR(1);
*outptr++ = '%';
}
}
}
else
{
} else {
CHECK_OUTPTR(1);
*outptr++ = *src;
}
++src;
}
CHECK_OUTPTR(1);
*outptr++ = 0;
return outbuf;
}
void CLangMngr::MergeDefinitions(const char *lang, CQueue<sKeyDef*> &tmpVec)
@ -957,9 +985,9 @@ int CLangMngr::MergeDefinitionFile(const char *file)
if (!fp)
{
CVector<md5Pair *>::iterator iter;
for (iter=FileList.begin(); iter!=FileList.end(); ++iter)
for (iter = FileList.begin(); iter != FileList.end(); ++iter)
{
if ( (*iter)->file.compare(file) == 0 )
if ((*iter)->file.compare(file) == 0)
{
char buf[33] = {0};
(*iter)->val.assign(buf);
@ -969,19 +997,20 @@ int CLangMngr::MergeDefinitionFile(const char *file)
AMXXLOG_Log("[AMXX] Failed to open dictionary file: %s", file);
return 0;
}
MD5 md5;
md5.update(fp); // closes for us
md5.update(fp); // closes for us
md5.finalize();
char md5buffer[33];
md5.hex_digest(md5buffer);
bool foundFlag = false;
CVector<md5Pair *>::iterator iter;
for (iter=FileList.begin(); iter!=FileList.end(); ++iter)
for (iter = FileList.begin(); iter != FileList.end(); ++iter)
{
if ( (*iter)->file.compare(file) == 0 )
if ((*iter)->file.compare(file) == 0)
{
if ( (*iter)->val.compare(md5buffer) == 0 )
if ((*iter)->val.compare(md5buffer) == 0)
{
return -1;
} else {
@ -1022,6 +1051,7 @@ int CLangMngr::MergeDefinitionFile(const char *file)
buf.trim();
if (buf[0] == 0)
continue;
if (buf[0] == '[' && buf.size() >= 3)
{
if (multiline)
@ -1031,10 +1061,12 @@ int CLangMngr::MergeDefinitionFile(const char *file)
delete tmpEntry;
tmpEntry = 0;
}
if (!Defq.empty())
{
MergeDefinitions(language, Defq);
}
language[0] = buf[1];
language[1] = buf[2];
language[2] = 0;
@ -1042,6 +1074,7 @@ int CLangMngr::MergeDefinitionFile(const char *file)
if (!multiline)
{
pos = buf.find('=');
if (pos > String::npos)
{
tmpEntry = new sKeyDef;
@ -1062,6 +1095,7 @@ int CLangMngr::MergeDefinitionFile(const char *file)
tmpEntry = 0;
} else {
pos = buf.find(':');
if (pos > String::npos)
{
tmpEntry = new sKeyDef;
@ -1105,9 +1139,9 @@ int CLangMngr::MergeDefinitionFile(const char *file)
CLangMngr::CLang * CLangMngr::GetLang(const char *name)
{
LangVecIter iter;
for (iter=m_Languages.begin(); iter!=m_Languages.end(); ++iter)
for (iter = m_Languages.begin(); iter != m_Languages.end(); ++iter)
{
if ( strcmp((*iter)->GetName(), name)==0 )
if (strcmp((*iter)->GetName(), name) == 0)
return (*iter);
}
@ -1122,9 +1156,9 @@ CLangMngr::CLang * CLangMngr::GetLang(const char *name)
CLangMngr::CLang * CLangMngr::GetLangR(const char *name)
{
LangVecIter iter;
for (iter=m_Languages.begin(); iter!=m_Languages.end(); ++iter)
for (iter = m_Languages.begin(); iter != m_Languages.end(); ++iter)
{
if ( strcmp((*iter)->GetName(), name)==0 )
if (strcmp((*iter)->GetName(), name) == 0)
return (*iter);
}
@ -1166,7 +1200,7 @@ bool CLangMngr::Save(const char *filename)
curOffset += sizeof(uint32_t);
uint32_t langOffset = curOffset + ktbSize + ltbSize;
for (unsigned int i = 0; i<m_Languages.size(); i++)
for (unsigned int i = 0; i < m_Languages.size(); i++)
{
langName = m_Languages[i]->GetName();
fwrite(langName, sizeof(char), 2, fp);
@ -1179,7 +1213,7 @@ bool CLangMngr::Save(const char *filename)
//Note - langOffset now points to the start of key lookup table
uint32_t keyHash = 0;
uint32_t keyOffset = langOffset;
for (unsigned int i = 0; i<KeyList.size(); i++)
for (unsigned int i = 0; i < KeyList.size(); i++)
{
keyHash = KeyList[i]->hash;
fwrite((void*)&keyHash, sizeof(uint32_t), 1, fp);
@ -1192,7 +1226,7 @@ bool CLangMngr::Save(const char *filename)
//Note - now keyOffset points toward the start of the def table
int defOffset = keyOffset;
for (unsigned int i = 0; i<m_Languages.size(); i++)
for (unsigned int i = 0; i < m_Languages.size(); i++)
{
m_Languages[i]->Save(fp, defOffset, curOffset);
}
@ -1200,7 +1234,7 @@ bool CLangMngr::Save(const char *filename)
//Now, defOffset points toward the END of the file
//curoffset should point toward the key table, so...
unsigned char keyLen = 0;
for (unsigned int i = 0; i<KeyList.size(); i++)
for (unsigned int i = 0; i < KeyList.size(); i++)
{
keyLen = KeyList[i]->key.size();
fwrite((void*)&keyLen, sizeof(unsigned char), 1, fp);
@ -1211,7 +1245,7 @@ bool CLangMngr::Save(const char *filename)
//Finally, write the def table
// It's assumed no orders changed...
for (unsigned int i = 0; i<m_Languages.size(); i++)
for (unsigned int i = 0; i < m_Languages.size(); i++)
{
m_Languages[i]->SaveDefinitions(fp, curOffset);
}
@ -1236,7 +1270,7 @@ bool CLangMngr::SaveCache(const char *filename)
fwrite((void *)&dictCount, sizeof(short), 1, fp);
for (i=FileList.begin(); i!=FileList.end(); i++)
for (i = FileList.begin(); i != FileList.end(); i++)
{
len = (*i)->file.size();
fwrite((void *)&len, sizeof(char), 1, fp);
@ -1264,8 +1298,7 @@ bool CLangMngr::LoadCache(const char *filename)
fread((void*)&dictCount, sizeof(short), 1, fp);
md5Pair *p = 0;
for (int i=1; i<=dictCount; i++)
for (int i = 1; i <= dictCount; i++)
{
fread((void*)&len, sizeof(char), 1, fp);
fread(buf, sizeof(char), len, fp);
@ -1311,7 +1344,8 @@ bool CLangMngr::Load(const char *filename)
uint32_t *LangOffsets = new uint32_t[langCount];
char langname[3];
for (unsigned int i=0; i<langCount; i++)
for (unsigned int i = 0; i < langCount; i++)
{
fread(langname, sizeof(char), 2, fp);
langname[2] = 0;
@ -1324,7 +1358,8 @@ bool CLangMngr::Load(const char *filename)
keyEntry *e = 0;
unsigned char keylen;
uint32_t keyoffset, save;
for (unsigned i=0; i<keycount; i++)
for (unsigned i = 0; i < keycount; i++)
{
e = new keyEntry;
fread((void*)&(e->hash), sizeof(uint32_t), 1, fp);
@ -1347,10 +1382,12 @@ bool CLangMngr::Load(const char *filename)
uint32_t defhash;
uint32_t defoffset;
unsigned short deflen;
for (unsigned int i=0; i<langCount; i++)
for (unsigned int i = 0; i < langCount; i++)
{
fread((void*)&numentries, sizeof(uint32_t), 1, fp);
for (unsigned int j=0; j<numentries; j++)
for (unsigned int j = 0; j < numentries; j++)
{
fread((void *)&keynum, sizeof(uint32_t), 1, fp);
fread((void *)&defhash, sizeof(uint32_t), 1, fp);
@ -1383,19 +1420,20 @@ CLangMngr::~CLangMngr()
void CLangMngr::Clear()
{
unsigned int i = 0;
for (i=0; i<m_Languages.size(); i++)
for (i = 0; i < m_Languages.size(); i++)
{
if (m_Languages[i])
delete m_Languages[i];
}
for (i=0; i<FileList.size(); i++)
for (i = 0; i < FileList.size(); i++)
{
if (FileList[i])
delete FileList[i];
}
for (i=0; i<KeyList.size(); i++)
for (i = 0; i < KeyList.size(); i++)
{
if (KeyList[i])
delete KeyList[i];
@ -1415,7 +1453,8 @@ const char *CLangMngr::GetLangName(int langId)
{
int i = 0;
LangVecIter iter;
for (iter=m_Languages.begin(); iter!=m_Languages.end(); ++iter)
for (iter = m_Languages.begin(); iter != m_Languages.end(); ++iter)
{
if (i == langId)
{
@ -1423,13 +1462,15 @@ const char *CLangMngr::GetLangName(int langId)
}
i++;
}
return "";
}
bool CLangMngr::LangExists(const char *langName)
{
char buf[3] = { 0 };
char buf[3] = {0};
int i = 0;
while (buf[i] = tolower(*langName++))
{
if (++i == 2)
@ -1437,11 +1478,13 @@ bool CLangMngr::LangExists(const char *langName)
}
LangVecIter iter;
for (iter=m_Languages.begin(); iter!=m_Languages.end(); ++iter)
for (iter = m_Languages.begin(); iter != m_Languages.end(); ++iter)
{
if ( strcmp((*iter)->GetName(), buf)==0 )
if (strcmp((*iter)->GetName(), buf) == 0)
return true;
}
return false;
}

View File

@ -35,135 +35,177 @@
// *****************************************************
// class LogEventsMngr
// *****************************************************
LogEventsMngr::LogEventsMngr() {
logCurrent = logCounter = 0;
logcmplist = 0;
arelogevents = false;
memset( logevents, 0, sizeof(logevents) );
LogEventsMngr::LogEventsMngr()
{
logCurrent = logCounter = 0;
logcmplist = 0;
arelogevents = false;
memset(logevents, 0, sizeof(logevents));
}
LogEventsMngr::~LogEventsMngr() {
LogEventsMngr::~LogEventsMngr()
{
clearLogEvents();
}
int LogEventsMngr::CLogCmp::compareCondition(const char* string){
if ( logid == parent->logCounter )
return result;
logid = parent->logCounter;
if ( in ) return result = strstr( string , text.c_str() ) ? 0 : 1;
return result = strcmp(string,text.c_str());
int LogEventsMngr::CLogCmp::compareCondition(const char* string)
{
if (logid == parent->logCounter)
return result;
logid = parent->logCounter;
if (in) return result = strstr(string, text.c_str()) ? 0 : 1;
return result = strcmp(string,text.c_str());
}
LogEventsMngr::CLogCmp* LogEventsMngr::registerCondition(char* filter){
LogEventsMngr::CLogCmp* LogEventsMngr::registerCondition(char* filter)
{
char* temp = filter;
// expand "1=message"
while ( isdigit(*filter) )
while (isdigit(*filter))
++filter;
bool in = (*filter=='&');
bool in = (*filter=='&');
*filter++ = 0;
int pos = atoi(temp);
if ( pos < 0 || pos >= MAX_LOGARGS) pos = 0;
if (pos < 0 || pos >= MAX_LOGARGS) pos = 0;
CLogCmp* c = logcmplist;
while( c ) {
if ( (c->pos==pos) && (c->in==in) && !strcmp(c->text.c_str(), filter))
while (c)
{
if ((c->pos == pos) && (c->in == in) && !strcmp(c->text.c_str(), filter))
return c;
c = c->next;
}
return logcmplist = new CLogCmp( filter , in , pos , logcmplist,this );
return logcmplist = new CLogCmp(filter, in, pos, logcmplist, this);
}
void LogEventsMngr::CLogEvent::registerFilter( char* filter ){
CLogCmp *cmp = parent->registerCondition( filter );
if ( cmp == 0 ) return;
for(LogCond* c = filters; c ; c = c->next){
if ( c->argnum == cmp->pos ){
c->list = new LogCondEle( cmp , c->list );
void LogEventsMngr::CLogEvent::registerFilter(char* filter)
{
CLogCmp *cmp = parent->registerCondition(filter);
if (cmp == 0) return;
for (LogCond* c = filters; c; c = c->next)
{
if (c->argnum == cmp->pos)
{
c->list = new LogCondEle(cmp, c->list);
return;
}
}
LogCondEle* aa = new LogCondEle( cmp , 0 );
if ( aa == 0 ) return;
filters = new LogCond( cmp->pos , aa , filters );
LogCondEle* aa = new LogCondEle(cmp, 0);
if (aa == 0) return;
filters = new LogCond(cmp->pos, aa, filters);
}
void LogEventsMngr::setLogString( char* frmt, va_list& vaptr ) {
void LogEventsMngr::setLogString(char* frmt, va_list& vaptr)
{
++logCounter;
int len = vsnprintf (logString, 255 , frmt, vaptr );
if ( len == - 1) {
int len = vsnprintf(logString, 255, frmt, vaptr);
if (len == - 1)
{
len = 255;
logString[len] = 0;
}
if ( len ) logString[--len] = 0;
if (len) logString[--len] = 0;
logArgc = 0;
}
void LogEventsMngr::setLogString( char* frmt, ... ) {
void LogEventsMngr::setLogString(char* frmt, ...)
{
++logCounter;
va_list logArgPtr;
va_start ( logArgPtr , frmt );
int len = vsnprintf(logString, 255 , frmt, logArgPtr );
if ( len == - 1) {
va_start(logArgPtr, frmt);
int len = vsnprintf(logString, 255, frmt, logArgPtr);
if (len == - 1)
{
len = 255;
logString[len] = 0;
}
va_end ( logArgPtr );
if ( len ) logString[--len] = 0;
va_end(logArgPtr);
if (len) logString[--len] = 0;
logArgc = 0;
}
void LogEventsMngr::parseLogString( ) {
register const char* b = logString;
register int a;
while( *b && logArgc < MAX_LOGARGS ){
a = 0;
if ( *b == '"' ) {
++b;
while ( *b && *b != '"' && a < 127 )
logArgs[logArgc][a++] = *b++;
logArgs[logArgc++][a] = 0;
if ( *b) b+=2; // thanks to double terminator
}
else if ( *b == '(' ) {
++b;
while ( *b && *b != ')' && a < 127 )
logArgs[logArgc][a++] = *b++;
logArgs[logArgc++][a] = 0;
if ( *b) b+=2;
}
else {
while ( *b && *b != '(' && *b != '"' && a < 127 )
logArgs[logArgc][a++] = *b++;
if ( *b ) --a;
logArgs[logArgc++][a] = 0;
}
}
void LogEventsMngr::parseLogString()
{
register const char* b = logString;
register int a;
while (*b && logArgc < MAX_LOGARGS)
{
a = 0;
if (*b == '"')
{
++b;
while (*b && *b != '"' && a < 127)
logArgs[logArgc][a++] = *b++;
logArgs[logArgc++][a] = 0;
if (*b) b+=2; // thanks to double terminator
}
else if (*b == '(')
{
++b;
while (*b && *b != ')' && a < 127)
logArgs[logArgc][a++] = *b++;
logArgs[logArgc++][a] = 0;
if (*b) b+=2;
} else {
while (*b && *b != '(' && *b != '"' && a < 127)
logArgs[logArgc][a++] = *b++;
if (*b) --a;
logArgs[logArgc++][a] = 0;
}
}
}
LogEventsMngr::CLogEvent* LogEventsMngr::registerLogEvent( CPluginMngr::CPlugin* plugin, int func, int pos )
LogEventsMngr::CLogEvent* LogEventsMngr::registerLogEvent(CPluginMngr::CPlugin* plugin, int func, int pos)
{
if ( pos < 1 || pos > MAX_LOGARGS)
return 0;
arelogevents = true;
CLogEvent** d = &logevents[pos];
while(*d) d = &(*d)->next;
return *d = new CLogEvent( plugin , func, this );
if (pos < 1 || pos > MAX_LOGARGS)
return 0;
arelogevents = true;
CLogEvent** d = &logevents[pos];
while (*d) d = &(*d)->next;
return *d = new CLogEvent(plugin, func, this);
}
void LogEventsMngr::executeLogEvents()
{
bool valid;
for(CLogEvent* a = logevents[ logArgc ]; a ; a = a->next)
for (CLogEvent* a = logevents[logArgc]; a; a = a->next)
{
valid = true;
for( CLogEvent::LogCond* b = a->filters; b ; b = b->next)
for (CLogEvent::LogCond* b = a->filters; b; b = b->next)
{
valid = false;
for( CLogEvent::LogCondEle* c = b->list; c ; c = c->next) {
if ( c->cmp->compareCondition( logArgs[b->argnum] ) == 0 ){
for (CLogEvent::LogCondEle* c = b->list; c; c = c->next)
{
if (c->cmp->compareCondition(logArgs[b->argnum]) == 0)
{
valid = true;
break;
}
}
if (!valid)
break;
}
@ -175,64 +217,87 @@ void LogEventsMngr::executeLogEvents()
}
}
void LogEventsMngr::clearLogEvents(){
logCurrent = logCounter = 0;
arelogevents = false;
for(int i = 0; i < MAX_LOGARGS + 1; ++i){
CLogEvent **a = &logevents[i];
while(*a){
CLogEvent* bb = (*a)->next;
delete *a;
*a = bb;
}
}
clearConditions();
void LogEventsMngr::clearLogEvents()
{
logCurrent = logCounter = 0;
arelogevents = false;
for (int i = 0; i < MAX_LOGARGS + 1; ++i)
{
CLogEvent **a = &logevents[i];
while (*a)
{
CLogEvent* bb = (*a)->next;
delete *a;
*a = bb;
}
}
clearConditions();
}
void LogEventsMngr::clearConditions() {
while (logcmplist){
CLogCmp* a = logcmplist->next;
delete logcmplist;
logcmplist = a;
}
void LogEventsMngr::clearConditions()
{
while (logcmplist)
{
CLogCmp* a = logcmplist->next;
delete logcmplist;
logcmplist = a;
}
}
LogEventsMngr::CLogEvent::LogCond::~LogCond() {
while( list ) {
LogEventsMngr::CLogEvent::LogCond::~LogCond()
{
while (list)
{
LogCondEle* cc = list->next;
delete list;
list = cc;
}
}
LogEventsMngr::CLogEvent::~CLogEvent() {
while( filters ) {
LogEventsMngr::CLogEvent::~CLogEvent()
{
while (filters)
{
LogCond* cc = filters->next;
delete filters;
filters = cc;
}
}
LogEventsMngr::CLogEvent *LogEventsMngr::getValidLogEvent( CLogEvent * a )
LogEventsMngr::CLogEvent *LogEventsMngr::getValidLogEvent(CLogEvent * a)
{
bool valid;
while(a){
while (a)
{
valid = true;
for( CLogEvent::LogCond* b = a->filters; b ; b = b->next){
for (CLogEvent::LogCond* b = a->filters; b; b = b->next)
{
valid = false;
for( CLogEvent::LogCondEle* c = b->list; c ; c = c->next) {
if ( c->cmp->compareCondition( logArgs[b->argnum] ) == 0 ){
for (CLogEvent::LogCondEle* c = b->list; c; c = c->next)
{
if (c->cmp->compareCondition(logArgs[b->argnum]) == 0)
{
valid = true;
break;
}
}
if (!valid) break;
}
if (!valid){
if (!valid)
{
a = a->next;
continue;
}
return a;
}
return 0;
}