ReactOS  0.4.12-dev-919-gfc3b8d5
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 {
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 
97 {
99  TCHAR reg_key_name[KEY_MAX_LEN];
100 
101  switch (action) {
102  case ACTION_ADD:
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]) {
111  perror("");
112  printf("Can't open file \"%s\"\n", filename);
113  return FALSE;
114  //exit(1);
115  }
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';
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 {
141  }
142  break;
143  default:
144  printf("Unhandled action!\n");
145  return FALSE;
146  }
147  return TRUE;
148 }
149 
151 {
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':
171  break;
172  case 'E':
174  break;
175  case 'V':
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 }
#define isspace(c)
Definition: acclib.h:69
#define TRUE
Definition: types.h:120
BOOL ProcessCmdLine(LPSTR lpCmdLine)
Definition: regcmds.c:150
REGEDIT_ACTION
Definition: regcmds.c:74
char CHAR
Definition: xmlstorage.h:175
#define isalpha(c)
Definition: acclib.h:74
char * LPSTR
Definition: xmlstorage.h:182
const char * filename
Definition: ioapi.h:135
#define KEY_MAX_LEN
Definition: regproc.h:22
BOOL PerformRegAction(REGEDIT_ACTION action, LPSTR s)
Definition: regcmds.c:96
void get_file_name(LPWSTR *command_line, LPWSTR file_name)
Definition: regedit.c:77
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
char TCHAR
Definition: xmlstorage.h:189
int toupper(int c)
Definition: utclib.c:881
#define MAX_PATH
Definition: compat.h:26
GLsizeiptr const GLvoid GLenum usage
Definition: glext.h:5919
GLdouble s
Definition: gl.h:2039
void error_unknown_switch(char chu, char *s)
Definition: regcmds.c:85
REGEDIT_ACTION
Definition: regedit.c:55
const WCHAR * action
Definition: action.c:7783
BOOL export_registry_key(WCHAR *file_name, WCHAR *reg_key_name, DWORD format)
Definition: regproc.c:1310
BOOL import_registry_file(FILE *reg_file)
Definition: regproc.c:1405
void delete_registry_key(WCHAR *reg_key_name)
Definition: regproc.c:1432
#define printf
Definition: config.h:203