[MMEBUDDY]
[reactos.git] / rostests / tests / regdump / regdump.c
1 /* $Id$
2 *
3 * ReactOS regedit
4 *
5 * regdump.c
6 *
7 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24 #include <windows.h>
25 #include <tchar.h>
26 #include <stdio.h>
27 #include "regdump.h"
28
29
30 #ifdef UNICODE
31 //#define dprintf _tprintf
32 #define dprintf printf
33 #else
34 #define dprintf printf
35 #endif
36
37 void RegKeyPrint(int which);
38
39
40
41 const char* default_cmd_line1 = "/E HKLM_EXPORT.TXT HKEY_LOCAL_MACHINE";
42 const char* default_cmd_line2 = "TEST_IMPORT.TXT";
43 const char* default_cmd_line3 = "/P HKEY_LOCAL_MACHINE\\SYSTEM";
44 const char* default_cmd_line4 = "/P HKEY_LOCAL_MACHINE\\SOFTWARE";
45 const char* default_cmd_line5 = "/P HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes";
46 const char* default_cmd_line6 = "/E HKCR_EXPORT.TXT HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes";
47 const char* default_cmd_line7 = "/D HKEY_LOCAL_MACHINE\\SYSTEM";
48 const char* default_cmd_line8 = "/D HKEY_LOCAL_MACHINE\\SOFTWARE";
49 const char* default_cmd_line9 = "/D HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes";
50
51 /* Show usage */
52 void usage(const char* appName)
53 {
54 fprintf(stderr, "%s: Dump registry key to console\n", appName);
55 fprintf(stderr, "%s HKCR | HKCU | HKLM | HKU | HKCC | HKRR\n", appName);
56 }
57
58 void show_menu(void)
59 {
60 _tprintf(_T("\nchoose test :\n"));
61 _tprintf(_T(" 0 = Exit\n"));
62 printf(" 1 = %s\n", default_cmd_line1);
63 printf(" 2 = %s\n", default_cmd_line2);
64 printf(" 3 = %s\n", default_cmd_line3);
65 printf(" 4 = %s\n", default_cmd_line4);
66 printf(" 5 = %s\n", default_cmd_line5);
67 printf(" 6 = %s\n", default_cmd_line6);
68 printf(" 7 = %s\n", default_cmd_line7);
69 printf(" 8 = %s\n", default_cmd_line8);
70 printf(" 9 = %s\n", default_cmd_line9);
71 /*
72 _tprintf(_T(" 1 = %s\n"), default_cmd_line1);
73 _tprintf(_T(" 2 = %s\n"), default_cmd_line2);
74 _tprintf(_T(" 3 = %s\n"), default_cmd_line3);
75 _tprintf(_T(" 4 = %s\n"), default_cmd_line4);
76 _tprintf(_T(" 5 = %s\n"), default_cmd_line5);
77 _tprintf(_T(" 6 = %s\n"), default_cmd_line6);
78 _tprintf(_T(" 7 = %s\n"), default_cmd_line7);
79 _tprintf(_T(" 8 = %s\n"), default_cmd_line8);
80 _tprintf(_T(" 9 = %s\n"), default_cmd_line9);
81 */
82 // _tprintf(_T(" A = HKEY_CLASSES_ROOT\n"));
83 // _tprintf(_T(" B = HKEY_CURRENT_USER\n"));
84 // _tprintf(_T(" C = HKEY_LOCAL_MACHINE\n"));
85 // _tprintf(_T(" D = HKEY_USERS\n"));
86 // _tprintf(_T(" E = HKEY_CURRENT_CONFIG\n"));
87 // _tprintf(_T(" F = REGISTRY ROOT\n"));
88 }
89
90 int regdump(int argc, char* argv[])
91 {
92 char Buffer[500];
93
94 if (argc > 1) {
95 // if (0 == _tcsstr(argv[1], _T("HKLM"))) {
96 if (strstr(argv[1], "help")) {
97 usage(argv[0]);
98 } else if (strstr(argv[1], "HKCR")) {
99 RegKeyPrint('1');
100 } else if (strstr(argv[1], "HKCU")) {
101 RegKeyPrint('2');
102 } else if (strstr(argv[1], "HKLM")) {
103 RegKeyPrint('3');
104 } else if (strstr(argv[1], "HKU")) {
105 RegKeyPrint('4');
106 } else if (strstr(argv[1], "HKCC")) {
107 RegKeyPrint('5');
108 } else if (strstr(argv[1], "HKRR")) {
109 RegKeyPrint('6');
110 } else {
111 dprintf("started with argc = %d, argv[1] = %s (unknown?)\n", argc, argv[1]);
112 }
113 return 0;
114 }
115 show_menu();
116 while (1) {
117 GetInput(Buffer, sizeof(Buffer));
118 switch (toupper(Buffer[0])) {
119 case '0':
120 return(0);
121 case '1':
122 strcpy(Buffer, default_cmd_line1);
123 goto doit;
124 case '2':
125 strcpy(Buffer, default_cmd_line2);
126 goto doit;
127 case '3':
128 strcpy(Buffer, default_cmd_line3);
129 goto doit;
130 case '4':
131 strcpy(Buffer, default_cmd_line4);
132 goto doit;
133 case '5':
134 strcpy(Buffer, default_cmd_line5);
135 goto doit;
136 case '6':
137 strcpy(Buffer, default_cmd_line6);
138 goto doit;
139 case '7':
140 strcpy(Buffer, default_cmd_line7);
141 goto doit;
142 case '8':
143 strcpy(Buffer, default_cmd_line8);
144 goto doit;
145 case '9':
146 strcpy(Buffer, default_cmd_line9);
147 goto doit;
148 case 'A':
149 case 'B':
150 case 'C':
151 case 'D':
152 case 'E':
153 case 'F':
154 RegKeyPrint(toupper(Buffer[0]) - 'A' + 1);
155 break;
156 default: doit:
157 if (!ProcessCmdLine(Buffer)) {
158 dprintf("invalid input.\n");
159 show_menu();
160 } else {
161 dprintf("done.\n");
162 }
163 break;
164 }
165 }
166 return 0;
167 }