2006-02-16 23:23:37 +00:00
|
|
|
/*
|
|
|
|
* CHCP.C - chcp internal command.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* History:
|
|
|
|
*
|
2007-05-05 11:32:25 +00:00
|
|
|
* 23-Dec-1998 (Eric Kohl)
|
2006-02-16 23:23:37 +00:00
|
|
|
* Started.
|
|
|
|
*
|
|
|
|
* 02-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
|
|
|
* Remove all hardcode string to En.rc
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <precomp.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef INCLUDE_CMD_CHCP
|
|
|
|
|
2008-08-25 23:22:03 +00:00
|
|
|
INT CommandChcp (LPTSTR param)
|
2006-02-16 23:23:37 +00:00
|
|
|
{
|
|
|
|
LPTSTR *arg;
|
2007-10-19 23:21:45 +00:00
|
|
|
INT args;
|
2006-02-16 23:23:37 +00:00
|
|
|
UINT uNewCodePage;
|
|
|
|
|
|
|
|
/* print help */
|
|
|
|
if (!_tcsncmp (param, _T("/?"), 2))
|
|
|
|
{
|
|
|
|
ConOutResPaging(TRUE,STRING_CHCP_HELP);
|
|
|
|
return 0;
|
|
|
|
}
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
nErrorLevel = 0;
|
|
|
|
|
|
|
|
/* get parameters */
|
|
|
|
arg = split (param, &args, FALSE);
|
|
|
|
|
|
|
|
if (args == 0)
|
|
|
|
{
|
|
|
|
/* display active code page number */
|
2008-07-26 22:49:49 +00:00
|
|
|
ConErrResPrintf(STRING_CHCP_ERROR1, InputCodePage);
|
2007-08-01 22:41:35 +00:00
|
|
|
freep (arg);
|
2006-02-16 23:23:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args >= 2)
|
|
|
|
{
|
|
|
|
/* too many parameters */
|
2008-07-26 22:49:49 +00:00
|
|
|
ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT, param);
|
2006-02-16 23:23:37 +00:00
|
|
|
nErrorLevel = 1;
|
2007-08-01 22:41:35 +00:00
|
|
|
freep (arg);
|
2006-02-16 23:23:37 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
uNewCodePage = (UINT)_ttoi(arg[0]);
|
|
|
|
|
|
|
|
if (uNewCodePage == 0)
|
|
|
|
{
|
2008-07-26 22:49:49 +00:00
|
|
|
ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT, arg[0]);
|
2006-02-16 23:23:37 +00:00
|
|
|
freep (arg);
|
|
|
|
nErrorLevel = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SetConsoleCP(uNewCodePage))
|
|
|
|
{
|
|
|
|
ConErrResPuts(STRING_CHCP_ERROR4);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
SetConsoleOutputCP (uNewCodePage);
|
|
|
|
InitLocale ();
|
|
|
|
InputCodePage= GetConsoleCP();
|
|
|
|
}
|
|
|
|
|
|
|
|
freep (arg);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* INCLUDE_CMD_CHCP */
|