fix a memory leak
[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 freep (arg);
45 return 0;
46 }
47
48 if (args >= 2)
49 {
50 /* too many parameters */
51 LoadString(CMD_ModuleHandle, STRING_ERROR_INVALID_PARAM_FORMAT, szMsg, RC_STRING_MAX_SIZE);
52 ConErrPrintf(szMsg, param);
53 nErrorLevel = 1;
54 freep (arg);
55 return 1;
56 }
57
58 uNewCodePage = (UINT)_ttoi(arg[0]);
59
60 if (uNewCodePage == 0)
61 {
62 LoadString(CMD_ModuleHandle, STRING_ERROR_INVALID_PARAM_FORMAT, szMsg, RC_STRING_MAX_SIZE);
63 ConErrPrintf(szMsg, arg[0]);
64 freep (arg);
65 nErrorLevel = 1;
66 return 1;
67 }
68
69 if (!SetConsoleCP(uNewCodePage))
70 {
71 ConErrResPuts(STRING_CHCP_ERROR4);
72 }
73 else
74 {
75
76 SetConsoleOutputCP (uNewCodePage);
77 InitLocale ();
78 InputCodePage= GetConsoleCP();
79 }
80
81 freep (arg);
82
83 return 0;
84 }
85
86 #endif /* INCLUDE_CMD_CHCP */