Fixed bugs

This commit is contained in:
Pavol Marko 2004-08-19 18:35:18 +00:00
parent 3af9ae8927
commit 16c406fe1a
2 changed files with 112 additions and 156 deletions

View File

@ -617,30 +617,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
curState = S_PercentSign;
else if (curState == S_PercentSign)
{
switch (*src)
{
case 's':
{
cell *tmpArg = get_amxaddr(amx, params[parm++]);;
while (*tmpArg)
*outptr++ = *tmpArg++;
break;
}
case 'f':
case 'g':
{
char format[16];
format[0] = '%';
char *ptr = format+1;
while (!isalpha(*ptr++ = *src++))
/*nothing*/;
--src;
*ptr = 0;
sprintf(outptr, format, *(REAL*)get_amxaddr(amx, params[parm++]));
outptr += strlen(outptr);
break;
}
case 'L':
if (*src=='L')
{
cell langName = params[parm]; // "en" case (langName contains the address to the string)
cell *pAmxLangName = get_amxaddr(amx, params[parm++]); // other cases
@ -659,7 +636,7 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
}
if (!cpLangName || strlen(cpLangName) < 1)
cpLangName = "en";
int len;
int len = 0;
char *key = get_amxstring(amx, params[parm++], 1, len);
const char *def = GetDef(cpLangName, key);
if (def == NULL)
@ -681,38 +658,47 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
}
while (*def)
{
switch (*def)
if (*def == '%')
{
case INSERT_NUMBER:
{
sprintf(outptr, "%d", *get_amxaddr(amx, params[parm++]));
outptr += strlen(outptr);
break;
}
case INSERT_STRING:
{
cell *tmpArg = get_amxaddr(amx, params[parm++]);;
while (*tmpArg)
*outptr++ = *tmpArg++;
break;
}
case INSERT_FLOAT:
{
sprintf(outptr, "%f", *(REAL*)get_amxaddr(amx, params[parm++]));
outptr += strlen(outptr);
break;
}
case INSERT_NEWLINE:
*outptr++ = '\n';
break;
default:
*outptr++ = *def;
}
++def;
}
char format[16];
format[0] = '%';
char *ptr = format+1;
while (!isalpha(*ptr++ = *def++))
/*nothing*/;
*ptr = 0;
switch ( *(ptr-1) )
{
case 's':
{
char tmpString[256];
char *tmpPtr = tmpString;
cell *tmpCell = get_amxaddr(amx, params[parm++]);
while (*tmpCell)
*tmpPtr++ = *tmpCell++;
*tmpPtr = 0;
sprintf(outptr, format, tmpString);
break;
}
default:
case 'g':
case 'f':
{
sprintf(outptr, format, *(REAL*)get_amxaddr(amx, params[parm++]));
break;
}
case 'i':
case 'd':
{
sprintf(outptr, format, (int)*get_amxaddr(amx, params[parm++]));
break;
}
}
outptr += strlen(outptr);
}
*outptr++ = *def++;
}
}
else
{
char tmpString[256];
char *tmpPtr = tmpString;
@ -735,25 +721,20 @@ char * CLangMngr::FormatAmxString(AMX *amx, cell *params, int parm, int &len)
sprintf(outptr, format, tmpString);
break;
}
case 'g':
case 'f':
{
sprintf(outptr, format, *(REAL*)get_amxaddr(amx, params[parm++]));
break;
}
case 'd':
{
sprintf(outptr, format, (int)*get_amxaddr(amx, params[parm++]));
break;
}
case 'i':
case 'd':
{
sprintf(outptr, format, (int)*get_amxaddr(amx, params[parm++]));
break;
}
}
outptr += strlen(outptr);
break;
}
}
curState = S_Normal;
}
@ -781,7 +762,7 @@ 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 )
{
@ -801,7 +782,7 @@ int CLangMngr::MergeDefinitionFile(const char *file)
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 )
{
@ -880,30 +861,6 @@ int CLangMngr::MergeDefinitionFile(const char *file)
tmpEntry->def = new String;
tmpEntry->def->assign(def.c_str());
tmpEntry->def->trim();
int pos = tmpEntry->def->find('%');
char r = 0, c = 0;
while (pos!=String::npos)
{
c = tmpEntry->def->at(pos+1);
if (c == 'd' || c == 'i')
{
r = INSERT_NUMBER;
} else if (c == 'f') {
r = INSERT_FLOAT;
} else if (c == 's') {
r = INSERT_STRING;
} else if (c == 'n') {
r = '\n';
} else {
r = 0;
}
if (r)
{
tmpEntry->def->at(pos+1, r);
tmpEntry->def->erase(pos, 1);
}
pos = tmpEntry->def->find('%', pos+1);
}
Defq.push(tmpEntry);
tmpEntry = 0;
} else {
@ -949,7 +906,7 @@ 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 )
return (*iter);
@ -1246,7 +1203,7 @@ 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)
{
@ -1268,11 +1225,10 @@ 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(), langName)==0 )
if ( strcmp((*iter)->GetName(), buf)==0 )
return true;
iter++;
}
return false;
}

View File

@ -286,7 +286,7 @@ static cell AMX_NATIVE_CALL set_hudmessage(AMX *amx, cell *params) /* 11 param
static cell AMX_NATIVE_CALL show_hudmessage(AMX *amx, cell *params) /* 2 param */
{
int len;
int len=0;
g_langMngr.SetDefLang(params[1]);
char* message = NULL;
if (params[1] == 0)
@ -2638,7 +2638,7 @@ static cell register_dictionary(AMX *amx, cell *params)
// lang_exists(const name[]);
static cell lang_exists(AMX *amx, cell *params)
{
int len;
int len = 0;
return g_langMngr.LangExists(get_amxstring(amx, params[1], 1, len)) ? 1 : 0;
}