7bede0c7c75aaf89897b7ce9d7282e0d957b0cbc
1 /* $Id: regcmds.c,v 1.1 2002/11/24 19:13:40 robd Exp $
7 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
9 * Original Work Copyright 2002 Andriy Palamarchuk
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
39 ////////////////////////////////////////////////////////////////////////////////
46 " regedit /E filename [regpath]\n"
47 " regedit /D regpath\n"
49 "filename - registry file name\n"
50 "regpath - name of the registry key\n"
52 "When is called without any switches adds contents of the specified\n"
53 "registry file to the registry\n"
56 " /E - exports contents of the specified registry key to the specified\n"
57 " file. Exports the whole registry if no key is specified.\n"
58 " /D - deletes specified registry key\n"
59 " /S - silent execution, can be used with any other switch.\n"
60 " The only existing mode, exists for compatibility with Windows regedit.\n"
61 " /V - advanced mode, can be used with any other switch.\n"
62 " Ignored, exists for compatibility with Windows regedit.\n"
63 " /L - location of system.dat file. Can be used with any other switch.\n"
64 " Ignored. Exists for compatibility with Windows regedit.\n"
65 " /R - location of user.dat file. Can be used with any other switch.\n"
66 " Ignored. Exists for compatibility with Windows regedit.\n"
67 " /? - print this help. Any other switches are ignored.\n"
68 " /C - create registry from. Not implemented.\n"
70 "The switches are case-insensitive, can be prefixed either by '-' or '/'.\n"
71 "This program is command-line compatible with Microsoft Windows\n"
72 "regedit. The difference with Windows regedit - this application has\n"
73 "command-line interface only.\n";
76 ACTION_UNDEF
, ACTION_ADD
, ACTION_EXPORT
, ACTION_DELETE
80 * Process unknown switch.
83 * chu - the switch character in upper-case.
84 * s - the command line string where s points to the switch character.
86 void error_unknown_switch(char chu
, char *s
)
89 printf("Undefined switch /%c!\n", chu
);
91 printf("Alphabetic character is expected after '%c' "
92 "in switch specification\n", *(s
- 1));
97 BOOL
PerformRegAction(REGEDIT_ACTION action
, LPSTR s
)
99 TCHAR filename
[MAX_PATH
];
100 TCHAR reg_key_name
[KEY_MAX_LEN
];
104 get_file_name(&s
, filename
, MAX_PATH
);
106 printf("No file name is specified\n%s", usage
);
110 while (filename
[0]) {
111 if (!import_registry_file(filename
)) {
113 printf("Can't open file \"%s\"\n", filename
);
117 get_file_name(&s
, filename
, MAX_PATH
);
121 get_file_name(&s
, reg_key_name
, KEY_MAX_LEN
);
122 if (!reg_key_name
[0]) {
123 printf("No registry key is specified for removal\n%s", usage
);
127 delete_registry_key(reg_key_name
);
131 get_file_name(&s
, filename
, MAX_PATH
);
133 printf("No file name is specified\n%s", usage
);
138 get_file_name(&s
, reg_key_name
, KEY_MAX_LEN
);
139 export_registry_key(filename
, reg_key_name
);
141 export_registry_key(filename
, NULL
);
145 printf("Unhandled action!\n");
151 BOOL
ProcessCmdLine(LPSTR lpCmdLine
)
153 REGEDIT_ACTION action
= ACTION_UNDEF
;
154 LPSTR s
= lpCmdLine
; /* command line pointer */
155 CHAR ch
= *s
; /* current character */
157 while (ch
&& ((ch
== '-') || (ch
== '/'))) {
165 if (!ch2
|| isspace(ch2
)) {
166 if (chu
== 'S' || chu
== 'V') {
167 /* ignore these switches */
171 action
= ACTION_DELETE
;
174 action
= ACTION_EXPORT
;
182 error_unknown_switch(chu
, s
);
195 while (*s
&& !isspace(*s
)) {
200 error_unknown_switch(chu
, s
);
205 /* this is a file name, starting from '/' */
210 /* skip spaces to the next parameter */
212 while (ch
&& isspace(ch
)) {
217 if (action
== ACTION_UNDEF
) {
220 return PerformRegAction(action
, s
);