FULLPIPE: Transcode Cyrillic into UTF-8 for debugging convenience

This commit is contained in:
Eugene Sandulenko 2013-06-26 20:46:14 -04:00
parent ee5dc16eaa
commit d4e572843d
4 changed files with 50 additions and 3 deletions

View File

@ -118,7 +118,7 @@ bool Scene::load(MfcArchive &file) {
_sceneId = file.readUint16LE();
_scstringObj = file.readPascalString();
debug(0, "scene: <%s>", _scstringObj);
debug(0, "scene: <%s>", transCyrillic((byte *)_scstringObj));
int count = file.readUint16LE();
debug(7, "scene.ani: %d", count);

View File

@ -401,7 +401,7 @@ bool CGameVar::load(MfcArchive &file) {
for (int i = 0; i < file.getLevel(); i++)
debugN(6, " ");
debugN(6, "<%s>: ", _stringObj);
debugN(6, "<%s>: ", transCyrillic((byte *)_stringObj));
switch (_varType) {
case 0:

View File

@ -99,7 +99,7 @@ char *MfcArchive::readPascalString(bool twoByte) {
tmp = (char *)calloc(len + 1, 1);
read(tmp, len);
debug(9, "readPascalString: %d <%s>", len, tmp);
debug(9, "readPascalString: %d <%s>", len, transCyrillic((byte *)tmp));
return tmp;
}
@ -360,4 +360,50 @@ char *genFileName(int superId, int sceneId, const char *ext) {
return s;
}
// Translates cp-1251..utf-8
byte *transCyrillic(byte *s) {
static byte tmp[1024];
static int trans[] = { 0xa8, 0xd081, 0xb8, 0xd191, 0xc0, 0xd090,
0xc1, 0xd091, 0xc2, 0xd092, 0xc3, 0xd093, 0xc4, 0xd094,
0xc5, 0xd095, 0xc6, 0xd096, 0xc7, 0xd097, 0xc8, 0xd098,
0xc9, 0xd099, 0xca, 0xd09a, 0xcb, 0xd09b, 0xcc, 0xd09c,
0xcd, 0xd09d, 0xce, 0xd09e, 0xcf, 0xd09f, 0xd0, 0xd0a0,
0xd1, 0xd0a1, 0xd2, 0xd0a2, 0xd3, 0xd0a3, 0xd4, 0xd0a4,
0xd5, 0xd0a5, 0xd6, 0xd0a6, 0xd7, 0xd0a7, 0xd8, 0xd0a8,
0xd9, 0xd0a9, 0xda, 0xd0aa, 0xdb, 0xd0ab, 0xdc, 0xd0ac,
0xdd, 0xd0ad, 0xde, 0xd0ae, 0xdf, 0xd0af, 0xe0, 0xd0b0,
0xe1, 0xd0b1, 0xe2, 0xd0b2, 0xe3, 0xd0b3, 0xe4, 0xd0b4,
0xe5, 0xd0b5, 0xe6, 0xd0b6, 0xe7, 0xd0b7, 0xe8, 0xd0b8,
0xe9, 0xd0b9, 0xea, 0xd0ba, 0xeb, 0xd0bb, 0xec, 0xd0bc,
0xed, 0xd0bd, 0xee, 0xd0be, 0xef, 0xd0bf, 0xf0, 0xd180,
0xf1, 0xd181, 0xf2, 0xd182, 0xf3, 0xd183, 0xf4, 0xd184,
0xf5, 0xd185, 0xf6, 0xd186, 0xf7, 0xd187, 0xf8, 0xd188,
0xf9, 0xd189, 0xfa, 0xd18a, 0xfb, 0xd18b, 0xfc, 0xd18c,
0xfd, 0xd18d, 0xfe, 0xd18e, 0xff, 0xd18f };
int i = 0;
for (byte *p = s; *p; p++) {
if (*p < 128) {
tmp[i++] = *p;
} else {
int j;
for (j = 0; trans[j]; j += 2) {
if (trans[j] == *p) {
tmp[i++] = (trans[j + 1] >> 8) & 0xff;
tmp[i++] = trans[j + 1] & 0xff;
break;
}
}
assert(trans[j]);
}
}
tmp[i] = 0;
return tmp;
}
} // End of namespace Fullpipe

View File

@ -127,6 +127,7 @@ struct CNode {
typedef Common::Array<void *> CPtrList;
char *genFileName(int superId, int sceneId, const char *ext);
byte *transCyrillic(byte *s);
} // End of namespace Fullpipe