sync with trunk head (34904)
[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 LPTSTR *arg;
23 INT args;
24 UINT uNewCodePage;
25
26 /* print help */
27 if (!_tcsncmp (param, _T("/?"), 2))
28 {
29 ConOutResPaging(TRUE,STRING_CHCP_HELP);
30 return 0;
31 }
32
33 nErrorLevel = 0;
34
35 /* get parameters */
36 arg = split (param, &args, FALSE);
37
38 if (args == 0)
39 {
40 /* display active code page number */
41 ConErrResPrintf(STRING_CHCP_ERROR1, InputCodePage);
42 freep (arg);
43 return 0;
44 }
45
46 if (args >= 2)
47 {
48 /* too many parameters */
49 ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT, param);
50 nErrorLevel = 1;
51 freep (arg);
52 return 1;
53 }
54
55 uNewCodePage = (UINT)_ttoi(arg[0]);
56
57 if (uNewCodePage == 0)
58 {
59 ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT, arg[0]);
60 freep (arg);
61 nErrorLevel = 1;
62 return 1;
63 }
64
65 if (!SetConsoleCP(uNewCodePage))
66 {
67 ConErrResPuts(STRING_CHCP_ERROR4);
68 }
69 else
70 {
71
72 SetConsoleOutputCP (uNewCodePage);
73 InitLocale ();
74 InputCodePage= GetConsoleCP();
75 }
76
77 freep (arg);
78
79 return 0;
80 }
81
82 #endif /* INCLUDE_CMD_CHCP */