1999-03-20 20:28:42 +00:00
|
|
|
/*
|
|
|
|
* CHCP.C - chcp internal command.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* History:
|
|
|
|
*
|
|
|
|
* 23-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
|
|
|
|
* Started.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#ifdef INCLUDE_CMD_CHCP
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <tchar.h>
|
|
|
|
#include <stdlib.h>
|
1999-03-21 21:32:45 +00:00
|
|
|
#include <string.h>
|
1999-03-20 20:28:42 +00:00
|
|
|
|
|
|
|
#include "cmd.h"
|
|
|
|
|
|
|
|
|
1999-10-03 22:20:33 +00:00
|
|
|
INT CommandChcp (LPTSTR cmd, LPTSTR param)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
|
|
|
LPTSTR *arg;
|
|
|
|
INT args;
|
1999-10-03 22:20:33 +00:00
|
|
|
UINT uOldCodePage;
|
|
|
|
UINT uNewCodePage;
|
1999-03-20 20:28:42 +00:00
|
|
|
|
|
|
|
/* print help */
|
|
|
|
if (!_tcsncmp (param, _T("/?"), 2))
|
|
|
|
{
|
|
|
|
ConOutPuts (_T("Displays or sets the active code page number.\n\n"
|
1999-09-12 18:23:31 +00:00
|
|
|
"CHCP [nnn]\n\n"
|
|
|
|
" nnn Specifies the active code page number.\n\n"
|
|
|
|
"Type CHCP without a parameter to display the active code page number."));
|
1999-10-03 22:20:33 +00:00
|
|
|
return 0;
|
1999-03-20 20:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (args == 0)
|
|
|
|
{
|
|
|
|
/* display active code page number */
|
|
|
|
ConOutPrintf ("Active code page: %u\n", GetConsoleCP ());
|
1999-10-03 22:20:33 +00:00
|
|
|
return 0;
|
1999-03-20 20:28:42 +00:00
|
|
|
}
|
1999-10-03 22:20:33 +00:00
|
|
|
|
|
|
|
if (args >= 2)
|
1999-03-20 20:28:42 +00:00
|
|
|
{
|
|
|
|
/* too many parameters */
|
|
|
|
ConErrPrintf ("Invalid parameter format - %s\n", param);
|
1999-10-03 22:20:33 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get parameters */
|
|
|
|
arg = split (param, &args);
|
|
|
|
|
|
|
|
/* save old code page */
|
|
|
|
uOldCodePage = GetConsoleCP ();
|
|
|
|
|
|
|
|
uNewCodePage = (UINT)_ttoi (arg[0]);
|
|
|
|
|
|
|
|
if (uNewCodePage == 0)
|
|
|
|
{
|
|
|
|
ConErrPrintf ("Parameter format incorrect - %s\n", arg[0]);
|
|
|
|
freep (arg);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SetConsoleCP (uNewCodePage))
|
|
|
|
{
|
|
|
|
ConErrPrintf ("Invalid code page\n");
|
1999-03-20 20:28:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-10-03 22:20:33 +00:00
|
|
|
SetConsoleOutputCP (uNewCodePage);
|
|
|
|
InitLocale ();
|
1999-03-20 20:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
freep (arg);
|
|
|
|
|
1999-10-03 22:20:33 +00:00
|
|
|
return 0;
|
1999-03-20 20:28:42 +00:00
|
|
|
}
|
|
|
|
|
2002-07-15 11:26:07 +00:00
|
|
|
#endif /* INCLUDE_CMD_CHCP */
|