Imported bzip2 modified to build a decompression only dll for use by the ramdisk...
[reactos.git] / rosapps / cmd / chcp.c
1 /*
2 * CHCP.C - chcp internal command.
3 *
4 *
5 * History:
6 *
7 * 23-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
8 * Started.
9 *
10 */
11
12 #include "config.h"
13
14 #ifdef INCLUDE_CMD_CHCP
15
16 #include <windows.h>
17 #include <tchar.h>
18 #include <stdlib.h>
19 #include <string.h>
20
21 #include "cmd.h"
22
23
24 INT CommandChcp (LPTSTR cmd, LPTSTR param)
25 {
26 LPTSTR *arg;
27 INT args;
28 UINT uOldCodePage;
29 UINT uNewCodePage;
30
31 /* print help */
32 if (!_tcsncmp (param, _T("/?"), 2))
33 {
34 ConOutPuts (_T("Displays or sets the active code page number.\n\n"
35 "CHCP [nnn]\n\n"
36 " nnn Specifies the active code page number.\n\n"
37 "Type CHCP without a parameter to display the active code page number."));
38 return 0;
39 }
40
41 if (args == 0)
42 {
43 /* display active code page number */
44 ConOutPrintf ("Active code page: %u\n", GetConsoleCP ());
45 return 0;
46 }
47
48 if (args >= 2)
49 {
50 /* too many parameters */
51 ConErrPrintf ("Invalid parameter format - %s\n", param);
52 return 1;
53 }
54
55 /* get parameters */
56 arg = split (param, &args);
57
58 /* save old code page */
59 uOldCodePage = GetConsoleCP ();
60
61 uNewCodePage = (UINT)_ttoi (arg[0]);
62
63 if (uNewCodePage == 0)
64 {
65 ConErrPrintf ("Parameter format incorrect - %s\n", arg[0]);
66 freep (arg);
67 return 1;
68 }
69
70 if (!SetConsoleCP (uNewCodePage))
71 {
72 ConErrPrintf ("Invalid code page\n");
73 }
74 else
75 {
76 SetConsoleOutputCP (uNewCodePage);
77 InitLocale ();
78 }
79
80 freep (arg);
81
82 return 0;
83 }
84
85 #endif /* INCLUDE_CMD_CHCP */