mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-04-28 13:47:58 +03:00
Format localization source files
This commit is contained in:
parent
7f8bcf8075
commit
6a31381c8e
3 changed files with 408 additions and 443 deletions
|
@ -6,8 +6,8 @@ extern "C" {
|
|||
|
||||
void Sys_InitLocalization();
|
||||
void Sys_ShutLocalization();
|
||||
const char* Sys_LV_ConvertString(const char* var);
|
||||
const char* Sys_LV_CL_ConvertString(const char* var);
|
||||
const char *Sys_LV_ConvertString(const char *var);
|
||||
const char *Sys_LV_CL_ConvertString(const char *var);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
cLocalization *g_localization;
|
||||
static char global_buf[MAX_BUFFERS][MAX_LOCALIZATION_LENGTH];
|
||||
static char szTemp[ 100 ];
|
||||
static char szTemp[100];
|
||||
static size_t buf_index = 0;
|
||||
|
||||
void Sys_InitLocalization()
|
||||
|
@ -44,7 +44,7 @@ void Sys_ShutLocalization()
|
|||
g_localization = NULL;
|
||||
}
|
||||
|
||||
const char *Sys_LV_ConvertString( const char *var )
|
||||
const char *Sys_LV_ConvertString(const char *var)
|
||||
{
|
||||
//
|
||||
// Since 2.0, don't localize messages from fgame.
|
||||
|
@ -53,21 +53,22 @@ const char *Sys_LV_ConvertString( const char *var )
|
|||
return var;
|
||||
}
|
||||
|
||||
const char *Sys_LV_CL_ConvertString( const char *var )
|
||||
const char *Sys_LV_CL_ConvertString(const char *var)
|
||||
{
|
||||
if (!g_localization) {
|
||||
return var;
|
||||
}
|
||||
|
||||
return g_localization->ConvertString( var );
|
||||
return g_localization->ConvertString(var);
|
||||
}
|
||||
|
||||
typedef char *charstar;
|
||||
int compare_strings( const void *pe1, const void *pe2 )
|
||||
|
||||
int compare_strings(const void *pe1, const void *pe2)
|
||||
{
|
||||
const char *psz1 = ( const char * )pe1;
|
||||
const char *psz2 = ( const char * )pe2;
|
||||
return Q_stricmp( psz1, psz2 );
|
||||
const char *psz1 = (const char *)pe1;
|
||||
const char *psz2 = (const char *)pe2;
|
||||
return Q_stricmp(psz1, psz2);
|
||||
}
|
||||
|
||||
cLocalization::cLocalization()
|
||||
|
@ -75,27 +76,26 @@ cLocalization::cLocalization()
|
|||
int i;
|
||||
int iFileCount;
|
||||
char **ppszFiles;
|
||||
char szFilename[ MAX_QPATH ];
|
||||
char szFilename[MAX_QPATH];
|
||||
size_t iBasePos;
|
||||
|
||||
ppszFiles = FS_ListFilteredFiles( "global", "txt", "localization*.txt", qfalse, &iFileCount, qtrue );
|
||||
Q_strncpyz( szFilename, "global/", sizeof( szFilename ) );
|
||||
memset( szFilename + 8, 0, sizeof( szFilename ) - 8 );
|
||||
iBasePos = strlen( szFilename );
|
||||
ppszFiles = FS_ListFilteredFiles("global", "txt", "localization*.txt", qfalse, &iFileCount, qtrue);
|
||||
Q_strncpyz(szFilename, "global/", sizeof(szFilename));
|
||||
memset(szFilename + 8, 0, sizeof(szFilename) - 8);
|
||||
iBasePos = strlen(szFilename);
|
||||
|
||||
Com_Printf( "-- Localization: I see %d localization files\n", iFileCount );
|
||||
qsort( ppszFiles, iFileCount, sizeof( char * ), compare_strings );
|
||||
for( i = 0; i < iFileCount; i++ )
|
||||
{
|
||||
Q_strncpyz( szFilename + iBasePos, ppszFiles[ i ], sizeof( szFilename ) - iBasePos );
|
||||
Com_Printf( "--- Localization: reading file %s\n", szFilename );
|
||||
LoadFile( szFilename );
|
||||
Com_Printf("-- Localization: I see %d localization files\n", iFileCount);
|
||||
qsort(ppszFiles, iFileCount, sizeof(char *), compare_strings);
|
||||
for (i = 0; i < iFileCount; i++) {
|
||||
Q_strncpyz(szFilename + iBasePos, ppszFiles[i], sizeof(szFilename) - iBasePos);
|
||||
Com_Printf("--- Localization: reading file %s\n", szFilename);
|
||||
LoadFile(szFilename);
|
||||
}
|
||||
|
||||
FS_FreeFileList( ppszFiles );
|
||||
FS_FreeFileList(ppszFiles);
|
||||
}
|
||||
|
||||
void cLocalization::LoadFile( const char *name )
|
||||
void cLocalization::LoadFile(const char *name)
|
||||
{
|
||||
TikiScript tiki;
|
||||
const char *token;
|
||||
|
@ -104,49 +104,40 @@ void cLocalization::LoadFile( const char *name )
|
|||
size_t rl;
|
||||
size_t ll;
|
||||
|
||||
Com_Printf( "Loading Localization File %s\n", name );
|
||||
Com_Printf("Loading Localization File %s\n", name);
|
||||
|
||||
if( !tiki.LoadFile( name, qtrue ) )
|
||||
{
|
||||
Com_Printf( "--- Error: File Not Found\n" );
|
||||
if (!tiki.LoadFile(name, qtrue)) {
|
||||
Com_Printf("--- Error: File Not Found\n");
|
||||
return;
|
||||
}
|
||||
|
||||
while( tiki.TokenAvailable( qtrue ) )
|
||||
{
|
||||
token = tiki.GetToken( qtrue );
|
||||
while (tiki.TokenAvailable(qtrue)) {
|
||||
token = tiki.GetToken(qtrue);
|
||||
|
||||
if( !Q_stricmp( token, "{" ) )
|
||||
{
|
||||
if( !tiki.TokenAvailable( qtrue ) ) {
|
||||
if (!Q_stricmp(token, "{")) {
|
||||
if (!tiki.TokenAvailable(qtrue)) {
|
||||
break;
|
||||
}
|
||||
|
||||
token = tiki.GetToken( qtrue );
|
||||
token = tiki.GetToken(qtrue);
|
||||
new_entry.m_refName = token;
|
||||
|
||||
rl = strlen( token );
|
||||
p = strstr( token, "&&&" );
|
||||
rl = strlen(token);
|
||||
p = strstr(token, "&&&");
|
||||
|
||||
if( p )
|
||||
{
|
||||
if (p) {
|
||||
new_entry.m_r1_rep = p - token;
|
||||
p2 = p + 3;
|
||||
p = strstr( p2, "&&&" );
|
||||
p = strstr(p2, "&&&");
|
||||
|
||||
if( p )
|
||||
{
|
||||
if (p) {
|
||||
new_entry.m_r2_rep = p - p2;
|
||||
new_entry.m_r3_rep = strlen( p + 3 );
|
||||
}
|
||||
else
|
||||
{
|
||||
new_entry.m_r2_rep = strlen( p2 );
|
||||
new_entry.m_r3_rep = strlen(p + 3);
|
||||
} else {
|
||||
new_entry.m_r2_rep = strlen(p2);
|
||||
new_entry.m_r3_rep = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
new_entry.m_r1_rep = rl;
|
||||
new_entry.m_r2_rep = -1;
|
||||
new_entry.m_r3_rep = -1;
|
||||
|
@ -155,37 +146,33 @@ void cLocalization::LoadFile( const char *name )
|
|||
new_entry.m_l3_rep = -1;
|
||||
}
|
||||
|
||||
if( !tiki.TokenAvailable( qtrue ) )
|
||||
{
|
||||
Com_Printf( "--- Error: EOF Found without LocName. Last RefName was %s. (Misspelling/Unused)\n", new_entry.m_refName.c_str() );
|
||||
if (!tiki.TokenAvailable(qtrue)) {
|
||||
Com_Printf(
|
||||
"--- Error: EOF Found without LocName. Last RefName was %s. (Misspelling/Unused)\n",
|
||||
new_entry.m_refName.c_str()
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
token = tiki.GetToken( qtrue );
|
||||
token = tiki.GetToken(qtrue);
|
||||
new_entry.m_locName = token;
|
||||
|
||||
ll = strlen( token );
|
||||
p = strstr( token, "&&&" );
|
||||
ll = strlen(token);
|
||||
p = strstr(token, "&&&");
|
||||
|
||||
if( p )
|
||||
{
|
||||
if (p) {
|
||||
new_entry.m_l1_rep = p - token;
|
||||
p2 = p + 3;
|
||||
p = strstr( p2, "&&&" );
|
||||
p = strstr(p2, "&&&");
|
||||
|
||||
if( p )
|
||||
{
|
||||
if (p) {
|
||||
new_entry.m_l2_rep = p - p2;
|
||||
new_entry.m_l3_rep = strlen( p + 3 );
|
||||
}
|
||||
else
|
||||
{
|
||||
new_entry.m_l2_rep = strlen( p2 );
|
||||
new_entry.m_l3_rep = strlen(p + 3);
|
||||
} else {
|
||||
new_entry.m_l2_rep = strlen(p2);
|
||||
new_entry.m_l3_rep = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
new_entry.m_r1_rep = rl;
|
||||
new_entry.m_r2_rep = -1;
|
||||
new_entry.m_r3_rep = -1;
|
||||
|
@ -194,125 +181,125 @@ void cLocalization::LoadFile( const char *name )
|
|||
new_entry.m_l3_rep = -1;
|
||||
}
|
||||
|
||||
m_entries.AddObject( new_entry );
|
||||
m_entries.AddObject(new_entry);
|
||||
|
||||
if( !tiki.TokenAvailable( qtrue ) ) {
|
||||
if (!tiki.TokenAvailable(qtrue)) {
|
||||
break;
|
||||
}
|
||||
|
||||
token = tiki.GetToken( qtrue );
|
||||
token = tiki.GetToken(qtrue);
|
||||
|
||||
if( Q_stricmp( token, "}" ) )
|
||||
{
|
||||
Com_Printf( "--- Error: Invalid Entry... RefName: %s\t\tLocName: %s Attempting to Recover.\n", new_entry.m_refName.c_str(), new_entry.m_locName.c_str() );
|
||||
do
|
||||
{
|
||||
if( !tiki.TokenAvailable( qtrue ) )
|
||||
{
|
||||
Com_Printf( "--- Error: EOF Found. Unable to Recover from Error. \n" );
|
||||
if (Q_stricmp(token, "}")) {
|
||||
Com_Printf(
|
||||
"--- Error: Invalid Entry... RefName: %s\t\tLocName: %s Attempting to Recover.\n",
|
||||
new_entry.m_refName.c_str(),
|
||||
new_entry.m_locName.c_str()
|
||||
);
|
||||
do {
|
||||
if (!tiki.TokenAvailable(qtrue)) {
|
||||
Com_Printf("--- Error: EOF Found. Unable to Recover from Error. \n");
|
||||
break;
|
||||
}
|
||||
|
||||
token = tiki.GetToken( qtrue );
|
||||
} while( Q_stricmp( token, "}" ) );
|
||||
token = tiki.GetToken(qtrue);
|
||||
} while (Q_stricmp(token, "}"));
|
||||
|
||||
Com_Printf( "--- Warning: Recovered From Error, Data May have been lost.\n" );
|
||||
Com_Printf("--- Warning: Recovered From Error, Data May have been lost.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Com_Printf( "Loaded %d localization entries\n", m_entries.NumObjects() );
|
||||
Com_Printf("Loaded %d localization entries\n", m_entries.NumObjects());
|
||||
}
|
||||
|
||||
static int bjb_strnscmp( const char *a, const char *b, size_t n )
|
||||
static int bjb_strnscmp(const char *a, const char *b, size_t n)
|
||||
{
|
||||
while( 1 )
|
||||
{
|
||||
while( isspace( (unsigned char)*a ) )
|
||||
while (1) {
|
||||
while (isspace((unsigned char)*a)) {
|
||||
a++;
|
||||
while( isspace( (unsigned char)*b ) )
|
||||
}
|
||||
while (isspace((unsigned char)*b)) {
|
||||
b++;
|
||||
while( *a && *a == *b )
|
||||
}
|
||||
while (*a && *a == *b) {
|
||||
a++, b++;
|
||||
if( isspace( (unsigned char)*a ) )
|
||||
{
|
||||
if( isalnum( (unsigned char)a[ -1 ] ) && isalnum( (unsigned char)*b ) )
|
||||
}
|
||||
if (isspace((unsigned char)*a)) {
|
||||
if (isalnum((unsigned char)a[-1]) && isalnum((unsigned char)*b)) {
|
||||
break;
|
||||
}
|
||||
else if( isspace( (unsigned char)*b ) )
|
||||
{
|
||||
if( isalnum( (unsigned char)b[ -1 ] ) && isalnum( (unsigned char)*a ) )
|
||||
} else if (isspace((unsigned char)*b)) {
|
||||
if (isalnum((unsigned char)b[-1]) && isalnum((unsigned char)*a)) {
|
||||
break;
|
||||
}
|
||||
else
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return *a - *b;
|
||||
}
|
||||
|
||||
static void bjb_rebreak( const char *var, char *buf, size_t max )
|
||||
static void bjb_rebreak(const char *var, char *buf, size_t max)
|
||||
{
|
||||
const char *nl;
|
||||
char *rb, *rb1, *rb2;
|
||||
|
||||
nl = strchr( var, '\n' );
|
||||
if( !nl || nl >= &var[ max ] ) {
|
||||
nl = strchr(var, '\n');
|
||||
if (!nl || nl >= &var[max]) {
|
||||
return;
|
||||
}
|
||||
|
||||
while( 1 )
|
||||
{
|
||||
rb = &buf[ nl - var ];
|
||||
rb1 = &buf[ nl - var ];
|
||||
rb2 = &buf[ nl - var ];
|
||||
while (1) {
|
||||
rb = &buf[nl - var];
|
||||
rb1 = &buf[nl - var];
|
||||
rb2 = &buf[nl - var];
|
||||
|
||||
if( strlen( buf ) < nl - var ) {
|
||||
if (strlen(buf) < nl - var) {
|
||||
return;
|
||||
}
|
||||
|
||||
while( rb1 > var && !isspace( *rb1 ) )
|
||||
while (rb1 > var && !isspace(*rb1)) {
|
||||
rb1--;
|
||||
while( *rb2 && rb2 < &var[ max ] && !isspace( *rb2 ) )
|
||||
}
|
||||
while (*rb2 && rb2 < &var[max] && !isspace(*rb2)) {
|
||||
rb2++;
|
||||
}
|
||||
|
||||
if( rb1 < var )
|
||||
{
|
||||
if( !*rb2 || !isspace( *rb2 ) ) {
|
||||
if (rb1 < var) {
|
||||
if (!*rb2 || !isspace(*rb2)) {
|
||||
return;
|
||||
}
|
||||
|
||||
goto _set_new_line;
|
||||
}
|
||||
|
||||
if( !*rb2 || !isspace( *rb1 ) || !isspace( *rb2 ) )
|
||||
{
|
||||
if( rb1 >= var && isspace( *rb1 ) ) {
|
||||
if (!*rb2 || !isspace(*rb1) || !isspace(*rb2)) {
|
||||
if (rb1 >= var && isspace(*rb1)) {
|
||||
*rb1 = '\n';
|
||||
goto _new_line_set;
|
||||
} else if( !*rb2 || !isspace( *rb2 ) ) {
|
||||
} else if (!*rb2 || !isspace(*rb2)) {
|
||||
return;
|
||||
}
|
||||
|
||||
goto _set_new_line;
|
||||
}
|
||||
|
||||
if( rb - rb1 - 4 <= rb2 - rb )
|
||||
{
|
||||
if (rb - rb1 - 4 <= rb2 - rb) {
|
||||
*rb1 = '\n';
|
||||
goto _new_line_set;
|
||||
}
|
||||
|
||||
_set_new_line:
|
||||
_set_new_line:
|
||||
*rb2 = '\n';
|
||||
_new_line_set:
|
||||
nl = strchr( nl + 1, '\n' );
|
||||
if( !nl || nl >= &var[ max ] ) {
|
||||
_new_line_set:
|
||||
nl = strchr(nl + 1, '\n');
|
||||
if (!nl || nl >= &var[max]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char *cLocalization::ConvertString( const char *var )
|
||||
const char *cLocalization::ConvertString(const char *var)
|
||||
{
|
||||
size_t l;
|
||||
intptr_t i, m, n, o;
|
||||
|
@ -327,22 +314,20 @@ const char *cLocalization::ConvertString( const char *var )
|
|||
loc_entry_t *entry;
|
||||
str s1, s2;
|
||||
|
||||
l = strlen( var );
|
||||
l = strlen(var);
|
||||
|
||||
for( o = l; o > 0; o-- )
|
||||
{
|
||||
if( var[ o - 1 ] >= ' ' ) {
|
||||
for (o = l; o > 0; o--) {
|
||||
if (var[o - 1] >= ' ') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pRef = &var[ o ];
|
||||
pRef = &var[o];
|
||||
m = l - o;
|
||||
n = 0;
|
||||
|
||||
for( pVar = var; o > 0; o-- )
|
||||
{
|
||||
if( *pVar >= ' ' ) {
|
||||
for (pVar = var; o > 0; o--) {
|
||||
if (*pVar >= ' ') {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -350,31 +335,27 @@ const char *cLocalization::ConvertString( const char *var )
|
|||
n++;
|
||||
}
|
||||
|
||||
char* buf = global_buf[(buf_index++) % MAX_BUFFERS];
|
||||
for( i = 1; i <= m_entries.NumObjects(); i++ )
|
||||
{
|
||||
entry = &m_entries.ObjectAt( i );
|
||||
char *buf = global_buf[(buf_index++) % MAX_BUFFERS];
|
||||
for (i = 1; i <= m_entries.NumObjects(); i++) {
|
||||
entry = &m_entries.ObjectAt(i);
|
||||
|
||||
if( entry->m_r2_rep < 0 )
|
||||
{
|
||||
if( entry->m_r1_rep != o || bjb_strnscmp( pVar, entry->m_refName.c_str(), o ) ) {
|
||||
if (entry->m_r2_rep < 0) {
|
||||
if (entry->m_r1_rep != o || bjb_strnscmp(pVar, entry->m_refName.c_str(), o)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( !( m + n ) )
|
||||
{
|
||||
strncpy( buf, entry->m_locName, MAX_LOCALIZATION_LENGTH );
|
||||
bjb_rebreak( var, buf, MAX_LOCALIZATION_LENGTH );
|
||||
if (!(m + n)) {
|
||||
strncpy(buf, entry->m_locName, MAX_LOCALIZATION_LENGTH);
|
||||
bjb_rebreak(var, buf, MAX_LOCALIZATION_LENGTH);
|
||||
return buf;
|
||||
}
|
||||
|
||||
if( entry->m_l1_rep + m + n < MAX_LOCALIZATION_LENGTH )
|
||||
{
|
||||
memcpy( buf, var, n );
|
||||
memcpy( &buf[ n ], entry->m_locName.c_str(), entry->m_l1_rep );
|
||||
memcpy( &buf[ entry->m_l1_rep + n ], pRef, m );
|
||||
buf[ entry->m_l1_rep + m + n ] = 0;
|
||||
bjb_rebreak( var, buf, entry->m_l1_rep );
|
||||
if (entry->m_l1_rep + m + n < MAX_LOCALIZATION_LENGTH) {
|
||||
memcpy(buf, var, n);
|
||||
memcpy(&buf[n], entry->m_locName.c_str(), entry->m_l1_rep);
|
||||
memcpy(&buf[entry->m_l1_rep + n], pRef, m);
|
||||
buf[entry->m_l1_rep + m + n] = 0;
|
||||
bjb_rebreak(var, buf, entry->m_l1_rep);
|
||||
return buf;
|
||||
} else {
|
||||
return var;
|
||||
|
@ -382,67 +363,60 @@ const char *cLocalization::ConvertString( const char *var )
|
|||
}
|
||||
|
||||
nArg1 = entry->m_r1_rep + entry->m_r2_rep;
|
||||
if( entry->m_r3_rep >= 0 ) {
|
||||
if (entry->m_r3_rep >= 0) {
|
||||
nArg1 += entry->m_r3_rep;
|
||||
}
|
||||
|
||||
if( nArg1 > o ) {
|
||||
if (nArg1 > o) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( bjb_strnscmp( pVar, entry->m_refName.c_str(), entry->m_r1_rep ) ) {
|
||||
if (bjb_strnscmp(pVar, entry->m_refName.c_str(), entry->m_r1_rep)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pSrc = &pVar[ entry->m_r1_rep ];
|
||||
pSrc = &pVar[entry->m_r1_rep];
|
||||
|
||||
if( entry->m_r3_rep >= 0 )
|
||||
{
|
||||
pAfter = &entry->m_refName[ entry->m_r1_rep + 3 ];
|
||||
if (entry->m_r3_rep >= 0) {
|
||||
pAfter = &entry->m_refName[entry->m_r1_rep + 3];
|
||||
|
||||
if( entry->m_r2_rep > 100 ) {
|
||||
if (entry->m_r2_rep > 100) {
|
||||
continue;
|
||||
}
|
||||
|
||||
strncpy( szTemp, pAfter, entry->m_r2_rep );
|
||||
szTemp[ entry->m_r2_rep ] = 0;
|
||||
strncpy(szTemp, pAfter, entry->m_r2_rep);
|
||||
szTemp[entry->m_r2_rep] = 0;
|
||||
|
||||
pArg1 = strstr( pSrc, szTemp );
|
||||
pArg1 = strstr(pSrc, szTemp);
|
||||
|
||||
if( !pArg1 ) {
|
||||
if (!pArg1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nAfter = pArg1 - pSrc;
|
||||
pArg2 = &pArg1[ entry->m_r2_rep ];
|
||||
pArg2 = &pArg1[entry->m_r2_rep];
|
||||
|
||||
if( entry->m_r3_rep > 0 )
|
||||
{
|
||||
if( strlen( pArg2 ) < entry->m_r3_rep ) {
|
||||
if (entry->m_r3_rep > 0) {
|
||||
if (strlen(pArg2) < entry->m_r3_rep) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( bjb_strnscmp( &pVar[ o - entry->m_r3_rep ], &pAfter[ entry->m_r2_rep + 3 ], entry->m_r3_rep ) ) {
|
||||
if (bjb_strnscmp(&pVar[o - entry->m_r3_rep], &pAfter[entry->m_r2_rep + 3], entry->m_r3_rep)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nBefore = &pVar[ o - entry->m_r3_rep ] - pArg2;
|
||||
nBefore = &pVar[o - entry->m_r3_rep] - pArg2;
|
||||
} else {
|
||||
nBefore = o - ( pArg2 - pVar );
|
||||
nBefore = o - (pArg2 - pVar);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( entry->m_r2_rep > 0 )
|
||||
{
|
||||
if( bjb_strnscmp( &pVar[ o - entry->m_r2_rep ], &entry->m_refName[ entry->m_r1_rep + 3 ], entry->m_r2_rep ) ) {
|
||||
} else {
|
||||
if (entry->m_r2_rep > 0) {
|
||||
if (bjb_strnscmp(&pVar[o - entry->m_r2_rep], &entry->m_refName[entry->m_r1_rep + 3], entry->m_r2_rep)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nAfter = &pVar[ o - entry->m_r2_rep ] - pSrc;
|
||||
}
|
||||
else
|
||||
{
|
||||
nAfter = &pVar[o - entry->m_r2_rep] - pSrc;
|
||||
} else {
|
||||
nAfter = o - entry->m_r1_rep;
|
||||
}
|
||||
|
||||
|
@ -452,114 +426,105 @@ const char *cLocalization::ConvertString( const char *var )
|
|||
|
||||
n1 = 0;
|
||||
n2 = 0;
|
||||
if( n > 0 )
|
||||
{
|
||||
if( n >= 1024 ) {
|
||||
if (n > 0) {
|
||||
if (n >= 1024) {
|
||||
continue;
|
||||
}
|
||||
|
||||
memcpy( buf, var, n );
|
||||
memcpy(buf, var, n);
|
||||
n2 = n;
|
||||
}
|
||||
|
||||
if( entry->m_l1_rep >= 0 )
|
||||
{
|
||||
if( entry->m_l1_rep + n2 >= 1024 ) {
|
||||
if (entry->m_l1_rep >= 0) {
|
||||
if (entry->m_l1_rep + n2 >= 1024) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( entry->m_l1_rep > 0 ) {
|
||||
memcpy( &buf[ n2 ], &entry->m_locName[ 0 ], entry->m_l1_rep );
|
||||
if (entry->m_l1_rep > 0) {
|
||||
memcpy(&buf[n2], &entry->m_locName[0], entry->m_l1_rep);
|
||||
}
|
||||
|
||||
n2 += entry->m_l1_rep;
|
||||
n1 = entry->m_l1_rep + 3;
|
||||
}
|
||||
|
||||
if( nAfter >= 0 )
|
||||
{
|
||||
if( nAfter + n2 >= 1024 ) {
|
||||
if (nAfter >= 0) {
|
||||
if (nAfter + n2 >= 1024) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( nAfter > 0 ) {
|
||||
memcpy( &buf[ n2 ], pSrc, nAfter );
|
||||
if (nAfter > 0) {
|
||||
memcpy(&buf[n2], pSrc, nAfter);
|
||||
}
|
||||
|
||||
n2 += nAfter;
|
||||
}
|
||||
|
||||
if( entry->m_l2_rep >= 0 )
|
||||
{
|
||||
if( entry->m_l2_rep + n2 >= 1024 ) {
|
||||
if (entry->m_l2_rep >= 0) {
|
||||
if (entry->m_l2_rep + n2 >= 1024) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( entry->m_l2_rep > 0 ) {
|
||||
memcpy( &buf[ n2 ], &entry->m_locName[ n1 ], entry->m_l2_rep );
|
||||
if (entry->m_l2_rep > 0) {
|
||||
memcpy(&buf[n2], &entry->m_locName[n1], entry->m_l2_rep);
|
||||
}
|
||||
|
||||
n2 += entry->m_l2_rep;
|
||||
n1 += entry->m_l2_rep + 3;
|
||||
}
|
||||
|
||||
if( nBefore >= 0 )
|
||||
{
|
||||
if( nBefore + n2 >= 1024 ) {
|
||||
if (nBefore >= 0) {
|
||||
if (nBefore + n2 >= 1024) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( nBefore > 0 ) {
|
||||
memcpy( &buf[ n2 ], pArg2, nBefore );
|
||||
if (nBefore > 0) {
|
||||
memcpy(&buf[n2], pArg2, nBefore);
|
||||
}
|
||||
|
||||
n2 += nBefore;
|
||||
}
|
||||
|
||||
if( entry->m_l3_rep >= 0 )
|
||||
{
|
||||
if( entry->m_l3_rep + n2 >= 1024 ) {
|
||||
if (entry->m_l3_rep >= 0) {
|
||||
if (entry->m_l3_rep + n2 >= 1024) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( entry->m_l3_rep > 0 ) {
|
||||
memcpy( &buf[ n2 ], &entry->m_locName[ n1 ], entry->m_l3_rep );
|
||||
if (entry->m_l3_rep > 0) {
|
||||
memcpy(&buf[n2], &entry->m_locName[n1], entry->m_l3_rep);
|
||||
}
|
||||
|
||||
n2 += entry->m_l3_rep;
|
||||
}
|
||||
|
||||
if( m <= 0 || m + n2 < 1024 )
|
||||
{
|
||||
if( m + n2 < 1024 ) {
|
||||
memcpy( &buf[ n2 ], pRef, m );
|
||||
if (m <= 0 || m + n2 < 1024) {
|
||||
if (m + n2 < 1024) {
|
||||
memcpy(&buf[n2], pRef, m);
|
||||
n2 += m;
|
||||
}
|
||||
|
||||
buf[ n2 ] = 0;
|
||||
bjb_rebreak( var, buf, n2 );
|
||||
buf[n2] = 0;
|
||||
bjb_rebreak(var, buf, n2);
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
if( !developer->integer || !var[ 0 ] || !var[ 1 ] ) {
|
||||
if (!developer->integer || !var[0] || !var[1]) {
|
||||
return var;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
|
||||
while( var[ i ] < 0 || !isspace( var[ i ] ) )
|
||||
{
|
||||
while (var[i] < 0 || !isspace(var[i])) {
|
||||
i++;
|
||||
if( !var[ i ] ) {
|
||||
if (!var[i]) {
|
||||
return var;
|
||||
}
|
||||
}
|
||||
|
||||
if( !missing.ObjectInList( var ) )
|
||||
{
|
||||
missing.AddUniqueObject( var );
|
||||
Com_DPrintf( "LOCALIZATION ERROR: '%s' does not have a localization entry\n", var );
|
||||
if (!missing.ObjectInList(var)) {
|
||||
missing.AddUniqueObject(var);
|
||||
Com_DPrintf("LOCALIZATION ERROR: '%s' does not have a localization entry\n", var);
|
||||
}
|
||||
|
||||
return var;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
===========================================================================
|
||||
Copyright (C) 2015 the OpenMoHAA team
|
||||
Copyright (C) 2025 the OpenMoHAA team
|
||||
|
||||
This file is part of OpenMoHAA source code.
|
||||
|
||||
|
@ -30,8 +30,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
#include "../qcommon/localization.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "str.h"
|
||||
#include "container.h"
|
||||
# include "str.h"
|
||||
# include "container.h"
|
||||
|
||||
typedef struct {
|
||||
str m_refName;
|
||||
|
@ -44,18 +44,18 @@ typedef struct {
|
|||
intptr_t m_l3_rep;
|
||||
} loc_entry_t;
|
||||
|
||||
class cLocalization {
|
||||
Container< loc_entry_t > m_entries;
|
||||
Container< str > missing;
|
||||
class cLocalization
|
||||
{
|
||||
Container<loc_entry_t> m_entries;
|
||||
Container<str> missing;
|
||||
|
||||
public:
|
||||
cLocalization();
|
||||
|
||||
const char *ConvertString( const char *var );
|
||||
const char *ConvertString(const char *var);
|
||||
|
||||
private:
|
||||
void LoadFile( const char *name );
|
||||
void GenerateMissing( const char *file_name );
|
||||
void LoadFile(const char *name);
|
||||
void GenerateMissing(const char *file_name);
|
||||
};
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue