ReactOS
0.4.16-dev-597-gdbf7844
regcmds.c
Go to the documentation of this file.
1
/*
2
* ReactOS regedit
3
*
4
* regcmds.c
5
*
6
* Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
7
*
8
* Original Work Copyright 2002 Andriy Palamarchuk
9
*
10
* This library is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Lesser General Public
12
* License as published by the Free Software Foundation; either
13
* version 2.1 of the License, or (at your option) any later version.
14
*
15
* This library is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
* Lesser General Public License for more details.
19
*
20
* You should have received a copy of the GNU Lesser General Public
21
* License along with this library; if not, write to the Free Software
22
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
*/
24
25
#define WIN32_LEAN_AND_MEAN
// Exclude rarely-used stuff from Windows headers
26
#include <windows.h>
27
#include <tchar.h>
28
#include <stdio.h>
29
30
#ifdef WIN32_REGDBG
31
#else
32
#include <ctype.h>
33
#endif
34
35
#include "
regproc.h
"
36
37
39
// Global Variables:
40
//
41
42
static
char
*
usage
=
43
"Usage:\n"
44
" regedit filename\n"
45
" regedit /E filename [regpath]\n"
46
" regedit /D regpath\n"
47
"\n"
48
"filename - registry file name\n"
49
"regpath - name of the registry key\n"
50
"\n"
51
"When is called without any switches adds contents of the specified\n"
52
"registry file to the registry\n"
53
"\n"
54
"Switches:\n"
55
" /E - exports contents of the specified registry key to the specified\n"
56
" file. Exports the whole registry if no key is specified.\n"
57
" /D - deletes specified registry key\n"
58
" /S - silent execution, can be used with any other switch.\n"
59
" The only existing mode, exists for compatibility with Windows regedit.\n"
60
" /V - advanced mode, can be used with any other switch.\n"
61
" Ignored, exists for compatibility with Windows regedit.\n"
62
" /L - location of system.dat file. Can be used with any other switch.\n"
63
" Ignored. Exists for compatibility with Windows regedit.\n"
64
" /R - location of user.dat file. Can be used with any other switch.\n"
65
" Ignored. Exists for compatibility with Windows regedit.\n"
66
" /? - print this help. Any other switches are ignored.\n"
67
" /C - create registry from. Not implemented.\n"
68
"\n"
69
"The switches are case-insensitive, can be prefixed either by '-' or '/'.\n"
70
"This program is command-line compatible with Microsoft Windows\n"
71
"regedit. The difference with Windows regedit - this application has\n"
72
"command-line interface only.\n"
;
73
74
typedef
enum
{
75
ACTION_UNDEF
,
ACTION_ADD
,
ACTION_EXPORT
,
ACTION_DELETE
,
ACTION_VIEW
76
}
REGEDIT_ACTION
;
77
85
void
error_unknown_switch
(
char
chu,
char
*
s
)
86
{
87
if
(
isalpha
(chu)) {
88
printf
(
"Undefined switch /%c!\n"
, chu);
89
}
else
{
90
printf
(
"Alphabetic character is expected after '%c' "
91
"in switch specification\n"
, *(
s
- 1));
92
}
93
//exit(1);
94
}
95
96
BOOL
PerformRegAction
(
REGEDIT_ACTION
action
,
LPSTR
s
)
97
{
98
TCHAR
filename
[
MAX_PATH
];
99
TCHAR
reg_key_name[
KEY_MAX_LEN
];
100
101
switch
(
action
) {
102
case
ACTION_ADD
:
103
get_file_name
(&
s
,
filename
,
MAX_PATH
);
104
if
(!
filename
[0]) {
105
printf
(
"No file name is specified\n%s"
,
usage
);
106
return
FALSE
;
107
//exit(1);
108
}
109
while
(
filename
[0]) {
110
if
(!
import_registry_file
(
filename
)) {
111
perror
(
""
);
112
printf
(
"Can't open file \"%s\"\n"
,
filename
);
113
return
FALSE
;
114
//exit(1);
115
}
116
get_file_name
(&
s
,
filename
,
MAX_PATH
);
117
}
118
break
;
119
case
ACTION_DELETE
:
120
get_file_name
(&
s
, reg_key_name,
KEY_MAX_LEN
);
121
if
(!reg_key_name[0]) {
122
printf
(
"No registry key is specified for removal\n%s"
,
usage
);
123
return
FALSE
;
124
//exit(1);
125
}
126
delete_registry_key
(reg_key_name);
127
break
;
128
case
ACTION_EXPORT
:
129
filename
[0] =
'\0'
;
130
get_file_name
(&
s
,
filename
,
MAX_PATH
);
131
if
(!
filename
[0]) {
132
printf
(
"No file name is specified\n%s"
,
usage
);
133
return
FALSE
;
134
//exit(1);
135
}
136
if
(
s
[0]) {
137
get_file_name
(&
s
, reg_key_name,
KEY_MAX_LEN
);
138
export_registry_key
(
filename
, reg_key_name);
139
}
else
{
140
export_registry_key
(
filename
,
NULL
);
141
}
142
break
;
143
default
:
144
printf
(
"Unhandled action!\n"
);
145
return
FALSE
;
146
}
147
return
TRUE
;
148
}
149
150
BOOL
ProcessCmdLine
(
LPSTR
lpCmdLine)
151
{
152
REGEDIT_ACTION
action
=
ACTION_UNDEF
;
153
LPSTR
s
= lpCmdLine;
/* command line pointer */
154
CHAR
ch = *
s
;
/* current character */
155
156
while
(ch && ((ch ==
'-'
) || (ch ==
'/'
))) {
157
char
chu;
158
char
ch2;
159
160
s
++;
161
ch = *
s
;
162
ch2 = *(
s
+1);
163
chu =
toupper
(ch);
164
if
(!ch2 ||
isspace
(ch2)) {
165
if
(chu ==
'S'
|| chu ==
'V'
) {
166
/* ignore these switches */
167
}
else
{
168
switch
(chu) {
169
case
'D'
:
170
action
=
ACTION_DELETE
;
171
break
;
172
case
'E'
:
173
action
=
ACTION_EXPORT
;
174
break
;
175
case
'V'
:
176
action
=
ACTION_VIEW
;
177
break
;
178
case
'?'
:
179
printf
(
usage
);
180
return
FALSE
;
181
//exit(0);
182
break
;
183
default
:
184
error_unknown_switch
(chu,
s
);
185
return
FALSE
;
186
break
;
187
}
188
}
189
s
++;
190
}
else
{
191
if
(ch2 ==
':'
) {
192
switch
(chu) {
193
case
'L'
:
194
/* fall through */
195
case
'R'
:
196
s
+= 2;
197
while
(*
s
&& !
isspace
(*
s
)) {
198
s
++;
199
}
200
break
;
201
default
:
202
error_unknown_switch
(chu,
s
);
203
return
FALSE
;
204
break
;
205
}
206
}
else
{
207
/* this is a file name, starting from '/' */
208
s
--;
209
break
;
210
}
211
}
212
/* skip spaces to the next parameter */
213
ch = *
s
;
214
while
(ch &&
isspace
(ch)) {
215
s
++;
216
ch = *
s
;
217
}
218
}
219
if
(
action
==
ACTION_UNDEF
) {
220
action
=
ACTION_ADD
;
221
}
222
return
PerformRegAction
(
action
,
s
);
223
}
isspace
#define isspace(c)
Definition:
acclib.h:69
isalpha
#define isalpha(c)
Definition:
acclib.h:74
toupper
int toupper(int c)
Definition:
utclib.c:881
KEY_MAX_LEN
#define KEY_MAX_LEN
Definition:
main.h:29
import_registry_file
BOOL import_registry_file(FILE *reg_file)
Definition:
regproc.c:1041
export_registry_key
BOOL export_registry_key(WCHAR *file_name, WCHAR *path, DWORD format)
Definition:
regproc.c:1566
delete_registry_key
void delete_registry_key(WCHAR *reg_key_name)
Definition:
regproc.c:1089
REGEDIT_ACTION
REGEDIT_ACTION
Definition:
regedit.c:107
NULL
#define NULL
Definition:
types.h:112
TRUE
#define TRUE
Definition:
types.h:120
FALSE
#define FALSE
Definition:
types.h:117
MAX_PATH
#define MAX_PATH
Definition:
compat.h:34
action
const WCHAR * action
Definition:
action.c:7509
BOOL
unsigned int BOOL
Definition:
ntddk_ex.h:94
printf
#define printf
Definition:
freeldr.h:97
s
GLdouble s
Definition:
gl.h:2039
usage
GLsizeiptr const GLvoid GLenum usage
Definition:
glext.h:5919
perror
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
filename
const char * filename
Definition:
ioapi.h:137
ProcessCmdLine
BOOL ProcessCmdLine(LPSTR lpCmdLine)
Definition:
regcmds.c:150
PerformRegAction
BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s)
Definition:
regcmds.c:96
error_unknown_switch
void error_unknown_switch(char chu, char *s)
Definition:
regcmds.c:85
REGEDIT_ACTION
REGEDIT_ACTION
Definition:
regcmds.c:74
ACTION_ADD
@ ACTION_ADD
Definition:
regcmds.c:75
ACTION_EXPORT
@ ACTION_EXPORT
Definition:
regcmds.c:75
ACTION_DELETE
@ ACTION_DELETE
Definition:
regcmds.c:75
ACTION_VIEW
@ ACTION_VIEW
Definition:
regcmds.c:75
ACTION_UNDEF
@ ACTION_UNDEF
Definition:
regcmds.c:75
regproc.h
get_file_name
#define get_file_name
Definition:
regproc.h:51
TCHAR
char TCHAR
Definition:
xmlstorage.h:189
LPSTR
char * LPSTR
Definition:
xmlstorage.h:182
CHAR
char CHAR
Definition:
xmlstorage.h:175
modules
rostests
tests
regdump
regcmds.c
Generated on Fri Jan 24 2025 06:08:58 for ReactOS by
1.9.6