2 * CHCP.C - chcp internal command.
7 * 23-Dec-1998 (Eric Kohl)
10 * 02-Apr-2005 (Magnus Olsen <magnus@greatlord.com>)
11 * Remove all hardcoded strings in En.rc
16 #ifdef INCLUDE_CMD_CHCP
18 INT
CommandChcp(LPTSTR param
)
25 if (!_tcsncmp(param
, _T("/?"), 2))
27 ConOutResPaging(TRUE
,STRING_CHCP_HELP
);
34 arg
= split(param
, &args
, FALSE
, FALSE
);
38 /* Display the active code page number */
39 ConOutResPrintf(STRING_CHCP_ERROR1
, OutputCodePage
);
46 /* Too many parameters */
47 ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT
, param
);
53 uNewCodePage
= (UINT
)_ttoi(arg
[0]);
55 if (uNewCodePage
== 0)
57 ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT
, arg
[0]);
65 // TODO: In case of failure of SetConsoleCP or SetConsoleOutputCP,
66 // restore the old code page!
69 * Try changing the console input codepage. If it works then also change
70 * the console output codepage, and refresh our local codepage cache.
72 if (!SetConsoleCP(uNewCodePage
))
74 ConErrResPuts(STRING_CHCP_ERROR4
);
78 SetConsoleOutputCP(uNewCodePage
);
80 /* Update our local codepage cache */
81 InputCodePage
= GetConsoleCP();
82 OutputCodePage
= GetConsoleOutputCP();
86 /* Display the active code page number */
87 ConOutResPrintf(STRING_CHCP_ERROR1
, OutputCodePage
);
93 #endif /* INCLUDE_CMD_CHCP */