2 * Windows regedit.exe registry editor implementation.
4 * Copyright 2002 Andriy Palamarchuk
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 " regedit /E filename [regpath]\n"
30 " regedit /D regpath\n"
32 "filename - registry file name\n"
33 "regpath - name of the registry key\n"
35 "When is called without any switches adds contents of the specified\n"
36 "registry file to the registry\n"
39 " /E - exports contents of the specified registry key to the specified\n"
40 " file. Exports the whole registry if no key is specified.\n"
41 " /D - deletes specified registry key\n"
42 " /S - silent execution, can be used with any other switch.\n"
43 " The only existing mode, exists for compatibility with Windows regedit.\n"
44 " /V - advanced mode, can be used with any other switch.\n"
45 " Ignored, exists for compatibility with Windows regedit.\n"
46 " /L - location of system.dat file. Can be used with any other switch.\n"
47 " Ignored. Exists for compatibility with Windows regedit.\n"
48 " /R - location of user.dat file. Can be used with any other switch.\n"
49 " Ignored. Exists for compatibility with Windows regedit.\n"
50 " /? - print this help. Any other switches are ignored.\n"
51 " /C - create registry from. Not implemented.\n"
53 "The switches are case-insensitive, can be prefixed either by '-' or '/'.\n"
54 "This program is command-line compatible with Microsoft Windows\n"
55 "regedit. The difference with Windows regedit - this application has\n"
56 "command-line interface only.\n";
59 ACTION_UNDEF
, ACTION_ADD
, ACTION_EXPORT
, ACTION_DELETE
63 * Process unknown switch.
66 * chu - the switch character in upper-case.
67 * s - the command line string where s points to the switch character.
69 void error_unknown_switch(char chu
, char *s
)
73 printf("%s: Undefined switch /%c!\n", getAppName(), chu
);
75 printf("%s: Alphabetic character is expected after '%c' "
76 "in switch specification\n", getAppName(), *(s
- 1));
81 int WINAPI
WinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
,
82 LPSTR lpCmdLine
, int nCmdShow
)
84 REGEDIT_ACTION action
= ACTION_UNDEF
;
85 LPSTR s
= lpCmdLine
; /* command line pointer */
86 CHAR ch
= *s
; /* current character */
88 setAppName("regedit");
89 while (ch
&& ((ch
== '-') || (ch
== '/')))
98 if (!ch2
|| isspace(ch2
))
100 if (chu
== 'S' || chu
== 'V')
102 /* ignore these switches */
107 action
= ACTION_DELETE
;
110 action
= ACTION_EXPORT
;
117 error_unknown_switch(chu
, s
);
131 while (*s
&& !isspace(*s
))
137 error_unknown_switch(chu
, s
);
141 /* this is a file name, starting from '/' */
146 /* skip spaces to the next parameter */
148 while (ch
&& isspace(ch
))
155 if (action
== ACTION_UNDEF
)
164 CHAR filename
[MAX_PATH
];
167 get_file_name(&s
, filename
);
170 printf("%s: No file name is specified\n%s", getAppName(), usage
);
176 reg_file
= fopen(filename
, "r");
179 processRegLines(reg_file
, doSetValue
);
182 printf("%s: Can't open file \"%s\"\n", getAppName(), filename
);
185 get_file_name(&s
, filename
);
191 CHAR reg_key_name
[KEY_MAX_LEN
];
193 get_file_name(&s
, reg_key_name
);
194 if (!reg_key_name
[0])
196 printf("%s: No registry key is specified for removal\n%s",
197 getAppName(), usage
);
200 delete_registry_key(reg_key_name
);
205 CHAR filename
[MAX_PATH
];
208 get_file_name(&s
, filename
);
211 printf("%s: No file name is specified\n%s", getAppName(), usage
);
217 CHAR reg_key_name
[KEY_MAX_LEN
];
219 get_file_name(&s
, reg_key_name
);
220 export_registry_key(filename
, reg_key_name
);
222 export_registry_key(filename
, NULL
);
227 printf("%s: Unhandled action!\n", getAppName());