언젠가 네윈나EE와 관련해 빔독 포럼에서 갑갑함을 느꼈던 문제인데 네버윈터나이츠 EE와 이 게임을 둘러싼 모드 개발 환경은 기본적으로 ANSI 기반입니다. 문제는 윈도우 10 기준으로 텍스트 편집의 기본인 메모장같은 경우 기본이 UTF-8입니다. 아무 생각없이 작업하다보면 글자가 깨진다는 이야기죠.
물론 메모장에서 하나하나 save as에서 ANSI로 수정해 줄 도 있습니다. 그러나, 수백은 커녕 파일이 수십만 되도 멘탈에 금이 가기 시작하는 짓거리입니다.
다만 여기서 하나의 문제는 쉽게 갈 수 있는 -Encoding 949 같은 옵션은 powershell 버전이 6.2를 넘어가야 되는데 전문적인 프로그래머가 아니라면 윈도우 10에 깔려 있는 powershell 버전은 5.1이라서 써먹질 못합니다.
다행히도 여기서 요령이 있긴 하더군요. chcp로 인코딩 환경을 설정해주고 이어서 UTF8로 읽은 다음 ANSI로 출력해주면 됩니다.
Powershell.exe "chcp 949; Get-Content "읽을파일.txt" -Encoding UTF8 | Set-Content "꼭읽을파일과다른이름.txt" -Encoding OEM"



하여튼 시간이 지나면서 원래 존재하던 알려진 커맨드라인을 활용한 요령들 중 상당수가 사양 변경으로 인해 막혔는데 그래도 최신 환경에서는 해볼 수 있다는 소리기도 합니다. 그래서, 현재 사용 가능한 가장 확률이 높은 방법은 powershell을 이용하는걸 추천하겠습니다.
다만 여기서 하나의 문제는 쉽게 갈 수 있는 -Encoding 949 같은 옵션은 powershell 버전이 6.2를 넘어가야 되는데 전문적인 프로그래머가 아니라면 윈도우 10에 깔려 있는 powershell 버전은 5.1이라서 써먹질 못합니다.
다행히도 여기서 요령이 있긴 하더군요. chcp로 인코딩 환경을 설정해주고 이어서 UTF8로 읽은 다음 ANSI로 출력해주면 됩니다.
Powershell.exe "chcp 949; Get-Content "읽을파일.txt" -Encoding UTF8 | Set-Content "꼭읽을파일과다른이름.txt" -Encoding OEM"

겸사 겸사 번역 문서에 배치 작업을 하는 것이니 여기에 고쳐야 할 문자열도 집어넣어 봅니다. 아래 프로그램이 사용하는 _KR.TXT는 대강 홀수열에 찾을 문자열 다음 짝수열에 바꿀 문자열 형식으로 마지막에 홀수열의 안쓰는 단어로 끝나는 형식. 당연하지만 _KR.TXT도 ANSI 인코딩 상태여야 합니다. 이 파일은 메모장에서 save as 기능을 사용해서 변경했습니다.
실행하게 되면 대략 이런 결과가 나옵니다.

그리고 TLK에디터에 집어 넣기 위해 합쳐진 텍스트 문서의 결과는 아래와 같습니다. 아쉽게도 1046열째에서 문자열 길이 계산에 문제가 생긴 흔적, 찌그러기가 보이는데 이건 어차피 검토작업도 직접 해야되니까 생산성을 고려해서 그냥 무시할까 말까 싶습니다. ( 수정 완료)
#include "iostream"
#include "stdio.h"
#include "stdlib.h"
struct String {
char str_find[4096];
char str_replace[4096];
};
struct String* string1[9999];
int main(int argc, char* argv[])
{
FILE *IN1, *IN2, *OUT1;
char str[4096];
char *pos;
char *trans_defect;
char utf8_to_ansi[512];
char in_name1[255];
char in_name2[255];
char out_name1[255];
char fix_name[255];
char *fix_buffer;
char *next_access = NULL;
int strlen1 = 0;
int strlen2 = 0;
int strlen3 = 0;
int strlen4 = 0;int i;
strcpy_s(in_name1, argv[1]);
strcpy_s(fix_name, in_name1);
fix_buffer = strtok_s(fix_name, ".", &next_access);
strcpy_s(out_name1, ".\\NEW_TEXT_KR\\");
strcat_s(out_name1, sizeof(out_name1), fix_buffer);
strcat_s(out_name1, sizeof(out_name1), ".kr.txt");
strcpy_s(in_name2, fix_buffer);
strcat_s(in_name2, sizeof(in_name2), ".ansi.txt");
//UTF-8 to ANSI
if (fopen_s(&IN1, in_name1, "r") == 0)
{
fclose(IN1);
strcpy_s(utf8_to_ansi, "Powershell.exe \"chcp 949 > _nwnpapago.tmp; Get-Content ");
strcat_s(utf8_to_ansi, sizeof(utf8_to_ansi), in_name1);
strcat_s(utf8_to_ansi, sizeof(utf8_to_ansi), " -Encoding UTF8 | Set-Content ");
strcat_s(utf8_to_ansi, sizeof(utf8_to_ansi), in_name2);
strcat_s(utf8_to_ansi, sizeof(utf8_to_ansi), " -Encoding OEM\"");
//printf("%s", utf8_to_ansi);
system(utf8_to_ansi);
system("DEL _nwnpapago.tmp");
printf("\n");
fopen_s(&IN1, in_name2, "r");
}
else return 0;
//Exists
if (fopen_s(&OUT1, out_name1, "w") != 0)
{
system("@MKDIR NEW_TEXT_KR");
fopen_s(&OUT1, out_name1, "w");
}
//Spelling
int spelling = 0;
fopen_s(&IN2, "_KR.TXT", "r");
do {
string1[spelling] = (String*)malloc(sizeof(struct String));
fgets(str, 4096, IN2);
if (!feof(IN1))
{
//strcpy_s(string1[spelling]->str_find, str);
strlen3 = strlen((const char*)str);
for (i = 0; i < strlen3; i++)
string1[spelling]->str_find[i] = str[i];
if( string1[spelling]->str_find[i - 1] == 10 )
string1[spelling]->str_find[i - 1] = 0;
fgets(str, 4096, IN2);
if (!feof(IN1))
{
//strcpy_s(string1[spelling]->str_replace, str);
strlen3 = strlen((const char*)str);
for (i = 0; i < strlen3; i++)
string1[spelling]->str_replace[i] = str[i];
if (string1[spelling]->str_replace[i - 1] == 10)
string1[spelling]->str_replace[i - 1] = 0;
spelling++;
}
}
} while (!feof(IN2));
//insign
fgets(str, 4096, IN1);
if (!feof(IN1))
{
fputs("#// ", OUT1);
fputs(in_name1, OUT1);
fputs("\n", OUT1);
}
//body
do {
fgets(str, 4096, IN1);
if (!feof(IN1))
{
for (i = 0; i < spelling - 1; i++)
{
pos = strstr(str, string1[i]->str_find);
//exception
if (i == 0)
{
trans_defect = strstr(str, string1[i]->str_replace);
if (trans_defect) pos = NULL;
}
if (pos)
{
strlen1 = strlen((const char*)string1[i]->str_find);
strlen2 = strlen((const char*)string1[i]->str_replace);
strlen3 = strlen((const char*)str);
//test code
printf("Targeted string = %s\n", string1[i]->str_find);
printf("Right string = %s\n", string1[i]->str_replace);
if (strlen2 == strlen1)
{
memmove(pos, string1[i]->str_replace, strlen2);
}
if (strlen2 > strlen1)
{
memmove(pos + strlen2 - strlen1, pos, strlen3);
memmove(pos, string1[i]->str_replace, strlen2);
}
if (strlen2 < strlen1)
{
memmove(pos, pos + strlen1 - strlen2, strlen3);
memmove(pos, string1[i]->str_replace, strlen2);
}
}
}
fputs(str, OUT1);
strlen4 = strlen((const char*)str);
memset(str, 0, strlen4);
}
} while (!feof(IN1));
fclose(IN1); fclose(IN2); fclose(OUT1);
return 0;
}





덧글