Format localization source files

This commit is contained in:
smallmodel 2025-01-08 21:25:59 +01:00
parent 7f8bcf8075
commit 6a31381c8e
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512
3 changed files with 408 additions and 443 deletions

View file

@ -63,6 +63,7 @@ const char *Sys_LV_CL_ConvertString( const char *var )
}
typedef char *charstar;
int compare_strings(const void *pe1, const void *pe2)
{
const char *psz1 = (const char *)pe1;
@ -85,8 +86,7 @@ cLocalization::cLocalization()
Com_Printf("-- Localization: I see %d localization files\n", iFileCount);
qsort(ppszFiles, iFileCount, sizeof(char *), compare_strings);
for( i = 0; i < iFileCount; i++ )
{
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);
@ -106,18 +106,15 @@ void cLocalization::LoadFile( const char *name )
Com_Printf("Loading Localization File %s\n", name);
if( !tiki.LoadFile( name, qtrue ) )
{
if (!tiki.LoadFile(name, qtrue)) {
Com_Printf("--- Error: File Not Found\n");
return;
}
while( tiki.TokenAvailable( qtrue ) )
{
while (tiki.TokenAvailable(qtrue)) {
token = tiki.GetToken(qtrue);
if( !Q_stricmp( token, "{" ) )
{
if (!Q_stricmp(token, "{")) {
if (!tiki.TokenAvailable(qtrue)) {
break;
}
@ -128,25 +125,19 @@ void cLocalization::LoadFile( const char *name )
rl = strlen(token);
p = strstr(token, "&&&");
if( p )
{
if (p) {
new_entry.m_r1_rep = p - token;
p2 = p + 3;
p = strstr(p2, "&&&");
if( p )
{
if (p) {
new_entry.m_r2_rep = p - p2;
new_entry.m_r3_rep = strlen(p + 3);
}
else
{
} 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,9 +146,11 @@ 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;
}
@ -167,25 +160,19 @@ void cLocalization::LoadFile( const char *name )
ll = strlen(token);
p = strstr(token, "&&&");
if( p )
{
if (p) {
new_entry.m_l1_rep = p - token;
p2 = p + 3;
p = strstr(p2, "&&&");
if( p )
{
if (p) {
new_entry.m_l2_rep = p - p2;
new_entry.m_l3_rep = strlen(p + 3);
}
else
{
} 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;
@ -202,13 +189,14 @@ void cLocalization::LoadFile( const char *name )
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 ) )
{
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;
}
@ -226,27 +214,28 @@ void cLocalization::LoadFile( const char *name )
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;
}
@ -260,8 +249,7 @@ static void bjb_rebreak( const char *var, char *buf, size_t max )
return;
}
while( 1 )
{
while (1) {
rb = &buf[nl - var];
rb1 = &buf[nl - var];
rb2 = &buf[nl - var];
@ -270,13 +258,14 @@ static void bjb_rebreak( const char *var, char *buf, size_t max )
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 (rb1 < var) {
if (!*rb2 || !isspace(*rb2)) {
return;
}
@ -284,8 +273,7 @@ static void bjb_rebreak( const char *var, char *buf, size_t max )
goto _set_new_line;
}
if( !*rb2 || !isspace( *rb1 ) || !isspace( *rb2 ) )
{
if (!*rb2 || !isspace(*rb1) || !isspace(*rb2)) {
if (rb1 >= var && isspace(*rb1)) {
*rb1 = '\n';
goto _new_line_set;
@ -296,8 +284,7 @@ static void bjb_rebreak( const char *var, char *buf, size_t max )
goto _set_new_line;
}
if( rb - rb1 - 4 <= rb2 - rb )
{
if (rb - rb1 - 4 <= rb2 - rb) {
*rb1 = '\n';
goto _new_line_set;
}
@ -329,8 +316,7 @@ const char *cLocalization::ConvertString( const char *var )
l = strlen(var);
for( o = l; o > 0; o-- )
{
for (o = l; o > 0; o--) {
if (var[o - 1] >= ' ') {
break;
}
@ -340,8 +326,7 @@ const char *cLocalization::ConvertString( const char *var )
m = l - o;
n = 0;
for( pVar = var; o > 0; o-- )
{
for (pVar = var; o > 0; o--) {
if (*pVar >= ' ') {
break;
}
@ -351,25 +336,21 @@ const char *cLocalization::ConvertString( const char *var )
}
char *buf = global_buf[(buf_index++) % MAX_BUFFERS];
for( i = 1; i <= m_entries.NumObjects(); i++ )
{
for (i = 1; i <= m_entries.NumObjects(); i++) {
entry = &m_entries.ObjectAt(i);
if( entry->m_r2_rep < 0 )
{
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 ) )
{
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 )
{
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);
@ -396,8 +377,7 @@ const char *cLocalization::ConvertString( const char *var )
pSrc = &pVar[entry->m_r1_rep];
if( entry->m_r3_rep >= 0 )
{
if (entry->m_r3_rep >= 0) {
pAfter = &entry->m_refName[entry->m_r1_rep + 3];
if (entry->m_r2_rep > 100) {
@ -416,8 +396,7 @@ const char *cLocalization::ConvertString( const char *var )
nAfter = pArg1 - pSrc;
pArg2 = &pArg1[entry->m_r2_rep];
if( entry->m_r3_rep > 0 )
{
if (entry->m_r3_rep > 0) {
if (strlen(pArg2) < entry->m_r3_rep) {
continue;
}
@ -430,19 +409,14 @@ const char *cLocalization::ConvertString( const char *var )
} else {
nBefore = o - (pArg2 - pVar);
}
}
else
{
if( entry->m_r2_rep > 0 )
{
} 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
{
} else {
nAfter = o - entry->m_r1_rep;
}
@ -452,8 +426,7 @@ const char *cLocalization::ConvertString( const char *var )
n1 = 0;
n2 = 0;
if( n > 0 )
{
if (n > 0) {
if (n >= 1024) {
continue;
}
@ -462,8 +435,7 @@ const char *cLocalization::ConvertString( const char *var )
n2 = n;
}
if( entry->m_l1_rep >= 0 )
{
if (entry->m_l1_rep >= 0) {
if (entry->m_l1_rep + n2 >= 1024) {
continue;
}
@ -476,8 +448,7 @@ const char *cLocalization::ConvertString( const char *var )
n1 = entry->m_l1_rep + 3;
}
if( nAfter >= 0 )
{
if (nAfter >= 0) {
if (nAfter + n2 >= 1024) {
continue;
}
@ -489,8 +460,7 @@ const char *cLocalization::ConvertString( const char *var )
n2 += nAfter;
}
if( entry->m_l2_rep >= 0 )
{
if (entry->m_l2_rep >= 0) {
if (entry->m_l2_rep + n2 >= 1024) {
continue;
}
@ -503,8 +473,7 @@ const char *cLocalization::ConvertString( const char *var )
n1 += entry->m_l2_rep + 3;
}
if( nBefore >= 0 )
{
if (nBefore >= 0) {
if (nBefore + n2 >= 1024) {
continue;
}
@ -516,8 +485,7 @@ const char *cLocalization::ConvertString( const char *var )
n2 += nBefore;
}
if( entry->m_l3_rep >= 0 )
{
if (entry->m_l3_rep >= 0) {
if (entry->m_l3_rep + n2 >= 1024) {
continue;
}
@ -529,8 +497,7 @@ const char *cLocalization::ConvertString( const char *var )
n2 += entry->m_l3_rep;
}
if( m <= 0 || m + n2 < 1024 )
{
if (m <= 0 || m + n2 < 1024) {
if (m + n2 < 1024) {
memcpy(&buf[n2], pRef, m);
n2 += m;
@ -548,16 +515,14 @@ const char *cLocalization::ConvertString( const char *var )
i = 0;
while( var[ i ] < 0 || !isspace( var[ i ] ) )
{
while (var[i] < 0 || !isspace(var[i])) {
i++;
if (!var[i]) {
return var;
}
}
if( !missing.ObjectInList( var ) )
{
if (!missing.ObjectInList(var)) {
missing.AddUniqueObject(var);
Com_DPrintf("LOCALIZATION ERROR: '%s' does not have a localization entry\n", var);
}

View file

@ -1,6 +1,6 @@
/*
===========================================================================
Copyright (C) 2015 the OpenMoHAA team
Copyright (C) 2025 the OpenMoHAA team
This file is part of OpenMoHAA source code.
@ -44,7 +44,8 @@ typedef struct {
intptr_t m_l3_rep;
} loc_entry_t;
class cLocalization {
class cLocalization
{
Container<loc_entry_t> m_entries;
Container<str> missing;
@ -58,4 +59,3 @@ private:
void GenerateMissing(const char *file_name);
};
#endif