Index: base/applications/cmdutils/chcp/CMakeLists.txt =================================================================== --- base/applications/cmdutils/chcp/CMakeLists.txt (revision 0) +++ base/applications/cmdutils/chcp/CMakeLists.txt (working copy) @@ -0,0 +1,6 @@ + +add_executable(chcp chcp.c chcp.rc) +set_module_type(chcp win32cui UNICODE) +set_target_properties(chcp PROPERTIES SUFFIX ".com") +add_importlibs(chcp user32 msvcrt kernel32) +add_cd_file(TARGET chcp DESTINATION reactos/system32 FOR all) Index: base/applications/cmdutils/chcp/chcp.c =================================================================== --- base/applications/cmdutils/chcp/chcp.c (revision 0) +++ base/applications/cmdutils/chcp/chcp.c (working copy) @@ -0,0 +1,77 @@ +/* + * PROJECT: ReactOS Change CodePage Utility + * LICENSE: GPL - See COPYING in the top level directory + * FILE: base/applications/cmdutils/chcp/chcp.c + * PURPOSE: Shows or edits the active code page number + * COPYRIGHT: Eric Kohl + * Lee Schroeder (spaceseel at gmail dot com) + * + */ +#include +#include +#include +#include +#include +#include +#include + +#include "resource.h" + +#define MAX_BUFFER_SIZE 5024 + +VOID PrintResourceString(INT resID, ...) +{ + WCHAR tmpBuffer[MAX_BUFFER_SIZE]; + va_list arg_ptr; + + va_start(arg_ptr, resID); + LoadStringW(GetModuleHandle(NULL), resID, tmpBuffer, MAX_BUFFER_SIZE); + vfwprintf(stdout, tmpBuffer, arg_ptr); + va_end(arg_ptr); +} + +int wmain(int argc, WCHAR *argv[]) +{ + UINT uNewCodePage; + + /* If more than one parameter is provided, then show the user the usage and exit */ + if (argc > 2) + { + PrintResourceString(IDS_ERROR_TOOMANY_ARGUMENTS); + return 0; + } + + /* If there is no parameter, then show the current code page */ + if (argc == 1) + { + UINT currentCP = GetConsoleCP(); + PrintResourceString(IDS_CURRENT_CODEPAGE, currentCP); + return 0; + } + + /* Check to see if the user wants to see the help */ + if ((wcscmp(argv[1], L"-?") == 0) || + (wcscmp(argv[1], L"/?") == 0)) + { + PrintResourceString(IDS_USAGE); + return 0; + } + + /* If there is one argument, then try to convert the code page to the new one */ + uNewCodePage = (UINT)_wtoi(argv[1]); + if (uNewCodePage == 0) + { + PrintResourceString(IDS_ERROR_CODEPAGE, argv[1]); + return 0; + } + + if (!SetConsoleCP(uNewCodePage)) + { + PrintResourceString(IDS_ERROR_CODEPAGE, argv[1]); + return 0; + } + + SetConsoleOutputCP(uNewCodePage); + + return 0; +} Index: base/applications/cmdutils/chcp/chcp.rc =================================================================== --- base/applications/cmdutils/chcp/chcp.rc (revision 0) +++ base/applications/cmdutils/chcp/chcp.rc (working copy) @@ -0,0 +1,16 @@ +#include + +#include "resource.h" + +LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL + +#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Change CodePage Utility" +#define REACTOS_STR_INTERNAL_NAME "chcp" +#define REACTOS_STR_ORIGINAL_FILENAME "chcp.com" +#include + +/* UTF-8 */ +#pragma code_page(65001) +#ifdef LANGUAGE_EN_US + #include "lang/en-US.rc" +#endif Index: base/applications/cmdutils/chcp/lang/en-US.rc =================================================================== --- base/applications/cmdutils/chcp/lang/en-US.rc (revision 0) +++ base/applications/cmdutils/chcp/lang/en-US.rc (working copy) @@ -0,0 +1,15 @@ +LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT + +STRINGTABLE +BEGIN + IDS_USAGE "Shows or edits the active code page number.\n\n\ +CHCP [/?][nnn]\n\ +\n\ + /? Shows this help.\n\ + nnn Changes the code page number to this value.\n\ +\n\ +To show the current active code page number, type CHCP without parameters.\n" + IDS_CURRENT_CODEPAGE "Active Code Page: %d\n" + IDS_ERROR_CODEPAGE "ERROR: Invalid Code Page: %s\n" + IDS_ERROR_TOOMANY_ARGUMENTS "ERROR: Only one argument is supported.\nType CHCP /? for more information.\n" +END Index: base/applications/cmdutils/chcp/resource.h =================================================================== --- base/applications/cmdutils/chcp/resource.h (revision 0) +++ base/applications/cmdutils/chcp/resource.h (working copy) @@ -0,0 +1,9 @@ +#ifndef RESOURCE_H +#define RESOURCE_H + +#define IDS_USAGE 0 +#define IDS_CURRENT_CODEPAGE 1 +#define IDS_ERROR_CODEPAGE 2 +#define IDS_ERROR_TOOMANY_ARGUMENTS 3 + +#endif /* RESOURCE_H */ Index: base/applications/cmdutils/chcp/chcp.c =================================================================== --- base/applications/cmdutils/chcp/chcp.c (revision 0) +++ base/applications/cmdutils/chcp/chcp.c (working copy) @@ -0,0 +1,77 @@ +/* + * PROJECT: ReactOS Change CodePage Utility + * LICENSE: GPL - See COPYING in the top level directory + * FILE: base/applications/cmdutils/chcp/chcp.c + * PURPOSE: Shows or edits the active code page number + * COPYRIGHT: Eric Kohl + * Lee Schroeder (spaceseel at gmail dot com) + * + */ +#include +#include +#include +#include +#include +#include +#include + +#include "resource.h" + +#define MAX_BUFFER_SIZE 5024 + +VOID PrintResourceString(INT resID, ...) +{ + WCHAR tmpBuffer[MAX_BUFFER_SIZE]; + va_list arg_ptr; + + va_start(arg_ptr, resID); + LoadStringW(GetModuleHandle(NULL), resID, tmpBuffer, MAX_BUFFER_SIZE); + vfwprintf(stdout, tmpBuffer, arg_ptr); + va_end(arg_ptr); +} + +int wmain(int argc, WCHAR *argv[]) +{ + UINT uNewCodePage; + + /* If more than one parameter is provided, then show the user the usage and exit */ + if (argc > 2) + { + PrintResourceString(IDS_ERROR_TOOMANY_ARGUMENTS); + return 0; + } + + /* If there is no parameter, then show the current code page */ + if (argc == 1) + { + UINT currentCP = GetConsoleCP(); + PrintResourceString(IDS_CURRENT_CODEPAGE, currentCP); + return 0; + } + + /* Check to see if the user wants to see the help */ + if ((wcscmp(argv[1], L"-?") == 0) || + (wcscmp(argv[1], L"/?") == 0)) + { + PrintResourceString(IDS_USAGE); + return 0; + } + + /* If there is one argument, then try to convert the code page to the new one */ + uNewCodePage = (UINT)_wtoi(argv[1]); + if (uNewCodePage == 0) + { + PrintResourceString(IDS_ERROR_CODEPAGE, argv[1]); + return 0; + } + + if (!SetConsoleCP(uNewCodePage)) + { + PrintResourceString(IDS_ERROR_CODEPAGE, argv[1]); + return 0; + } + + SetConsoleOutputCP(uNewCodePage); + + return 0; +} Index: base/applications/cmdutils/chcp/chcp.rc =================================================================== --- base/applications/cmdutils/chcp/chcp.rc (revision 0) +++ base/applications/cmdutils/chcp/chcp.rc (working copy) @@ -0,0 +1,16 @@ +#include + +#include "resource.h" + +LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL + +#define REACTOS_STR_FILE_DESCRIPTION "ReactOS Change CodePage Utility" +#define REACTOS_STR_INTERNAL_NAME "chcp" +#define REACTOS_STR_ORIGINAL_FILENAME "chcp.com" +#include + +/* UTF-8 */ +#pragma code_page(65001) +#ifdef LANGUAGE_EN_US + #include "lang/en-US.rc" +#endif Index: base/applications/cmdutils/chcp/CMakeLists.txt =================================================================== --- base/applications/cmdutils/chcp/CMakeLists.txt (revision 0) +++ base/applications/cmdutils/chcp/CMakeLists.txt (working copy) @@ -0,0 +1,6 @@ + +add_executable(chcp chcp.c chcp.rc) +set_module_type(chcp win32cui UNICODE) +set_target_properties(chcp PROPERTIES SUFFIX ".com") +add_importlibs(chcp user32 msvcrt kernel32) +add_cd_file(TARGET chcp DESTINATION reactos/system32 FOR all) Index: base/applications/cmdutils/chcp/lang/en-US.rc =================================================================== --- base/applications/cmdutils/chcp/lang/en-US.rc (revision 0) +++ base/applications/cmdutils/chcp/lang/en-US.rc (working copy) @@ -0,0 +1,15 @@ +LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT + +STRINGTABLE +BEGIN + IDS_USAGE "Shows or edits the active code page number.\n\n\ +CHCP [/?][nnn]\n\ +\n\ + /? Shows this help.\n\ + nnn Changes the code page number to this value.\n\ +\n\ +To show the current active code page number, type CHCP without parameters.\n" + IDS_CURRENT_CODEPAGE "Active Code Page: %d\n" + IDS_ERROR_CODEPAGE "ERROR: Invalid Code Page: %s\n" + IDS_ERROR_TOOMANY_ARGUMENTS "ERROR: Only one argument is supported.\nType CHCP /? for more information.\n" +END Index: base/applications/cmdutils/chcp/lang/en-US.rc =================================================================== --- base/applications/cmdutils/chcp/lang/en-US.rc (revision 0) +++ base/applications/cmdutils/chcp/lang/en-US.rc (working copy) @@ -0,0 +1,15 @@ +LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT + +STRINGTABLE +BEGIN + IDS_USAGE "Shows or edits the active code page number.\n\n\ +CHCP [/?][nnn]\n\ +\n\ + /? Shows this help.\n\ + nnn Changes the code page number to this value.\n\ +\n\ +To show the current active code page number, type CHCP without parameters.\n" + IDS_CURRENT_CODEPAGE "Active Code Page: %d\n" + IDS_ERROR_CODEPAGE "ERROR: Invalid Code Page: %s\n" + IDS_ERROR_TOOMANY_ARGUMENTS "ERROR: Only one argument is supported.\nType CHCP /? for more information.\n" +END Index: base/applications/cmdutils/chcp/resource.h =================================================================== --- base/applications/cmdutils/chcp/resource.h (revision 0) +++ base/applications/cmdutils/chcp/resource.h (working copy) @@ -0,0 +1,9 @@ +#ifndef RESOURCE_H +#define RESOURCE_H + +#define IDS_USAGE 0 +#define IDS_CURRENT_CODEPAGE 1 +#define IDS_ERROR_CODEPAGE 2 +#define IDS_ERROR_TOOMANY_ARGUMENTS 3 + +#endif /* RESOURCE_H */ Index: base/applications/cmdutils/CMakeLists.txt =================================================================== --- base/applications/cmdutils/CMakeLists.txt (revision 69433) +++ base/applications/cmdutils/CMakeLists.txt (working copy) @@ -1,3 +1,4 @@ +add_subdirectory(chcp) add_subdirectory(comp) add_subdirectory(cscript) add_subdirectory(dbgprint)