@@ -20,6 +20,9 @@ static int need_restart = 0;
2020static int need_load = 0 ;
2121static int need_save = 0 ;
2222
23+ #ifdef _WIN32
24+ static int opt_codepage = 1251 ;
25+ #endif
2326static int luaB_menu (lua_State * L )
2427{
2528 const char * menu = luaL_optstring (L , 1 , NULL );
@@ -158,14 +161,14 @@ int main(int argc, const char **argv)
158161 int menu_mode = 0 ;
159162
160163 setlocale (LC_ALL , "" );
161- #ifdef _WIN32
162- SetConsoleOutputCP (1251 );
163- SetConsoleCP (1251 );
164- #endif
165164 for (i = 1 ; i < argc ; i ++ ) {
166165 if (!strncmp (argv [i ], "-l" , 2 )) {
167166 opt_log = 1 ;
168167 reopen_stderr (argv [i ] + 2 );
168+ #ifdef _WIN32
169+ } else if (!strncmp (argv [i ], "-cp" , 3 )) {
170+ opt_codepage = atoi (argv [i ] + 3 );
171+ #endif
169172 } else if (!strncmp (argv [i ], "-d" , 2 )) {
170173 opt_debug = 1 ;
171174 reopen_stderr (argv [i ] + 2 );
@@ -180,7 +183,10 @@ int main(int argc, const char **argv)
180183 game = argv [i ];
181184 }
182185 }
183-
186+ #ifdef _WIN32
187+ SetConsoleOutputCP (opt_codepage );
188+ SetConsoleCP (opt_codepage );
189+ #endif
184190 if (!game ) {
185191 fprintf (stdout , "Usage: %s [-d<file>] [-w<width>] [-i<script>] [-l<log>] <game>\n" , argv [0 ]);
186192 exit (1 );
@@ -201,7 +207,12 @@ int main(int argc, const char **argv)
201207 exit (1 );
202208 }
203209#ifdef _WIN32
204- instead_set_encoding ("CP1251" );
210+ if (opt_codepage == 65001 )
211+ instead_set_encoding ("UTF-8" );
212+ else {
213+ snprintf (cmd , sizeof (cmd ), "CP%d" , opt_codepage );
214+ instead_set_encoding (cmd );
215+ }
205216#endif
206217 if (instead_load (NULL )) {
207218 fprintf (stdout , "Can not load game: %s\n" , instead_err ());
0 commit comments