716b7ef36bfe347ae455131941818c5fb0841f0b
[reactos.git] / reactos / base / shell / cmd / chcp.c
1 /*
2 * CHCP.C - chcp internal command.
3 *
4 *
5 * History:
6 *
7 * 23-Dec-1998 (Eric Kohl)
8 * Started.
9 *
10 * 02-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
11 * Remove all hardcode string to En.rc
12 */
13
14 #include <precomp.h>
15
16
17
18 #ifdef INCLUDE_CMD_CHCP
19
20 INT CommandChcp (LPTSTR cmd, LPTSTR param)
21 {
22 TCHAR szMsg[RC_STRING_MAX_SIZE];
23 LPTSTR *arg;
24 INT args;
25 UINT uNewCodePage;
26
27 /* print help */
28 if (!_tcsncmp (param, _T("/?"), 2))
29 {
30 ConOutResPaging(TRUE,STRING_CHCP_HELP);
31 return 0;
32 }
33
34 nErrorLevel = 0;
35
36 /* get parameters */
37 arg = split (param, &args, FALSE);
38
39 if (args == 0)
40 {
41 /* display active code page number */
42 LoadString(CMD_ModuleHandle, STRING_CHCP_ERROR1, szMsg, RC_STRING_MAX_SIZE);
43 ConErrPrintf(szMsg, InputCodePage);
44 return 0;
45 }
46
47 if (args >= 2)
48 {
49 /* too many parameters */
50 LoadString(CMD_ModuleHandle, STRING_ERROR_INVALID_PARAM_FORMAT, szMsg, RC_STRING_MAX_SIZE);
51 ConErrPrintf(szMsg, param);
52 nErrorLevel = 1;
53 return 1;
54 }
55
56 uNewCodePage = (UINT)_ttoi(arg[0]);
57
58 if (uNewCodePage == 0)
59 {
60 LoadString(CMD_ModuleHandle, STRING_ERROR_INVALID_PARAM_FORMAT, szMsg, RC_STRING_MAX_SIZE);
61 ConErrPrintf(szMsg, arg[0]);
62 freep (arg);
63 nErrorLevel = 1;
64 return 1;
65 }
66
67 if (!SetConsoleCP(uNewCodePage))
68 {
69 ConErrResPuts(STRING_CHCP_ERROR4);
70 }
71 else
72 {
73
74 SetConsoleOutputCP (uNewCodePage);
75 InitLocale ();
76 InputCodePage= GetConsoleCP();
77 }
78
79 freep (arg);
80
81 return 0;
82 }
83
84 #endif /* INCLUDE_CMD_CHCP */