* regtool.cc (cmd_list): Add new registry display options.

(cmd_list): Add code to implement -p, -k, and -l options.
* regtool.cc (Fail): Add call to LocalFree to free memory allocated by
FormatMessage.
This commit is contained in:
Christopher Faylor 2001-01-10 22:34:02 +00:00
parent 7adad1217b
commit 37770e0009
3 changed files with 107 additions and 69 deletions

View File

@ -1,3 +1,11 @@
Tue Jan 09 10:26:23 2001 Tony Sideris <tonys1110@home.com>
* regtool.cc (cmd_list): Add new registry display options.
(cmd_list): Add code to implement -p, -k, and -l options.
* regtool.cc (Fail): Add call to LocalFree to free memory allocated by
FormatMessage.
Wed Jan 10 09:16:57 2001 Christopher Faylor <cgf@cygnus.com> Wed Jan 10 09:16:57 2001 Christopher Faylor <cgf@cygnus.com>
* regtool.cc (translate): Ensure that 'c' is initialized. * regtool.cc (translate): Ensure that 'c' is initialized.

View File

@ -19,6 +19,12 @@ enum
KT_AUTO, KT_INT, KT_STRING, KT_EXPAND, KT_MULTI KT_AUTO, KT_INT, KT_STRING, KT_EXPAND, KT_MULTI
} key_type = KT_AUTO; } key_type = KT_AUTO;
#define LIST_KEYS 0x01
#define LIST_VALS 0x02
#define LIST_ALL (LIST_KEYS | LIST_VALS)
int listwhat = 0;
int postfix = 0;
int verbose = 0; int verbose = 0;
int quiet = 0; int quiet = 0;
char **argv; char **argv;
@ -29,7 +35,10 @@ char *value;
const char *usage_msg[] = { const char *usage_msg[] = {
"Regtool Copyright (c) 2000 Red Hat Inc", "Regtool Copyright (c) 2000 Red Hat Inc",
" regtool -h - print this message", " regtool -h - print this message",
" regtool [-v] list [key] - list subkeys and values", " regtool [-v|-p|-k|-l] list [key] - list subkeys and values",
" -p=postfix, like ls -p, appends / postfix to key names",
" -k=keys, lists only keys",
" -l=values, lists only values",
" regtool [-v] add [key\\subkey] - add new subkey", " regtool [-v] add [key\\subkey] - add new subkey",
" regtool [-v] remove [key] - remove key", " regtool [-v] remove [key] - remove key",
" regtool [-v|-q] check [key] - exit 0 if key exists, 1 if not", " regtool [-v|-q] check [key] - exit 0 if key exists, 1 if not",
@ -67,6 +76,7 @@ Fail (DWORD rv)
| FORMAT_MESSAGE_FROM_SYSTEM, | FORMAT_MESSAGE_FROM_SYSTEM,
0, rv, 0, (CHAR *) & buf, 0, 0); 0, rv, 0, (CHAR *) & buf, 0, 0);
fprintf (stderr, "Error: %s\n", buf); fprintf (stderr, "Error: %s\n", buf);
LocalFree (buf);
} }
exit (1); exit (1);
} }
@ -248,17 +258,24 @@ cmd_list ()
value_name = (char *) malloc (maxvalnamelen + 1); value_name = (char *) malloc (maxvalnamelen + 1);
value_data = (unsigned char *) malloc (maxvaluelen + 1); value_data = (unsigned char *) malloc (maxvaluelen + 1);
if (!listwhat)
listwhat = LIST_ALL;
if (listwhat & LIST_KEYS)
for (i = 0; i < num_subkeys; i++) for (i = 0; i < num_subkeys; i++)
{ {
m = maxsubkeylen + 1; m = maxsubkeylen + 1;
n = maxclasslen + 1; n = maxclasslen + 1;
RegEnumKeyEx (key, i, subkey_name, &m, 0, class_name, &n, 0); RegEnumKeyEx (key, i, subkey_name, &m, 0, class_name, &n, 0);
printf ("%s%s", subkey_name, (postfix || verbose) ? "\\" : "");
if (verbose) if (verbose)
printf ("%s\\ (%s)\n", subkey_name, class_name); printf (" (%s)", class_name);
else
printf ("%s\n", subkey_name); puts ("");
} }
if (listwhat & LIST_VALS)
for (i = 0; i < num_values; i++) for (i = 0; i < num_values; i++)
{ {
m = maxvalnamelen + 1; m = maxvalnamelen + 1;
@ -496,7 +513,7 @@ main (int argc, char **_argv)
{ {
while (1) while (1)
{ {
int g = getopt (argc, _argv, "hvqisem"); int g = getopt (argc, _argv, "hvqisempkl");
if (g == -1) if (g == -1)
break; break;
switch (g) switch (g)
@ -507,6 +524,15 @@ main (int argc, char **_argv)
case 'q': case 'q':
quiet++; quiet++;
break; break;
case 'p':
postfix++;
break;
case 'k':
listwhat |= LIST_KEYS;
break;
case 'l':
listwhat |= LIST_VALS;
break;
case 'i': case 'i':
key_type = KT_INT; key_type = KT_INT;

View File

@ -613,23 +613,27 @@ reported. The valid bits to set are as follows:
<sect2 id="regtool"><title>regtool</title> <sect2 id="regtool"><title>regtool</title>
<screen> <screen>
regtool -h - print this message Regtool Copyright (c) 2000 Red Hat Inc
regtool [-v] list [key] - list subkeys and values regtool -h - print this message
regtool [-v] add [key\subkey] - add new subkey regtool [-v|-p|-k|-l] list [key] - list subkeys and values
regtool [-v] remove [key] - remove key -p=postfix, like ls -p, appends / postfix to key names
regtool [-v|-q] check [key] - exit 0 if key exists, 1 if not -k=keys, lists only keys
regtool [-i|-s|-e|-m] set [key\value] [data ...] - set value -l=values, lists only values
regtool [-v] add [key\subkey] - add new subkey
regtool [-v] remove [key] - remove key
regtool [-v|-q] check [key] - exit 0 if key exists, 1 if not
regtool [-i|-s|-e|-m] set [key\value] [data ...] - set value
-i=integer -s=string -e=expand-string -m=multi-string -i=integer -s=string -e=expand-string -m=multi-string
regtool [-v] unset [key\value] - removes value from key regtool [-v] unset [key\value] - removes value from key
regtool [-q] get [key\value] - prints value to stdout regtool [-q] get [key\value] - prints value to stdout
-q=quiet, no error msg, just return nonzero exit if key/value missing -q=quiet, no error msg, just return nonzero exit if key/value missing
keys are like \prefix\key\key\key\value, where prefix is any of: keys are like \prefix\key\key\key\value, where prefix is any of:
root HKCR HKEY_CLASSES_ROOT root HKCR HKEY_CLASSES_ROOT
config HKCC HKEY_CURRENT_CONFIG config HKCC HKEY_CURRENT_CONFIG
user HKCU HKEY_CURRENT_USER user HKCU HKEY_CURRENT_USER
machine HKLM HKEY_LOCAL_MACHINE machine HKLM HKEY_LOCAL_MACHINE
users HKU HKEY_USERS users HKU HKEY_USERS
example: \user\software\Microsoft\Clock\iFormat example: \user\software\Microsoft\Clock\iFormat
</screen> </screen>
<para>The <command>regtool</command> program allows shell scripts <para>The <command>regtool</command> program allows shell scripts