* regtool.cc (prog_name): New global variable.

(longopts): Ditto.
(opts): Ditto.
(usage): Standardize usage output.  Rearrange/add descriptions.
(print_version): New function.
(main): Accomodate longopts and new --help, --version options.  Add check for
(_argv[optind+1] == NULL).
This commit is contained in:
Christopher Faylor 2002-06-03 02:57:55 +00:00
parent 56c0639f59
commit 9bd0241009
2 changed files with 146 additions and 67 deletions

View File

@ -1,3 +1,13 @@
2002-06-02 Joshua Daniel Franklin <joshuadfranklin@yahoo.com>
* regtool.cc (prog_name): New global variable.
(longopts): Ditto.
(opts): Ditto.
(usage): Standardize usage output. Rearrange/add descriptions.
(print_version): New function.
(main): Accomodate longopts and new --help, --version options. Add
check for (_argv[optind+1] == NULL).
2002-06-02 Christopher Faylor <cgf@redhat.com> 2002-06-02 Christopher Faylor <cgf@redhat.com>
* strace.cc (forkdebug): Make true by default. * strace.cc (forkdebug): Make true by default.
@ -55,11 +65,11 @@
2002-05-23 Joshua Daniel Franklin <joshuadfranklin@yahoo.com> 2002-05-23 Joshua Daniel Franklin <joshuadfranklin@yahoo.com>
* setfacl.c (usage): Standardize usage output. Change return type to * setfacl.c (usage): Standardize usage output. Change return type to
static void. static void.
(print_version): New function. (print_version): New function.
(longopts): Added longopts for all options. (longopts): Added longopts for all options.
(main): Accommodate changes in usage function and new version option. (main): Accommodate changes in usage function and new version option.
2002-05-23 Joshua Daniel Franklin <joshuadfranklin@yahoo.com> 2002-05-23 Joshua Daniel Franklin <joshuadfranklin@yahoo.com>
@ -84,7 +94,7 @@
2002-05-20 Joerg Schaible <joerg.schaible@gmx.de> 2002-05-20 Joerg Schaible <joerg.schaible@gmx.de>
* cygpath.cc (main): Add option l to support conversion to * cygpath.cc (main): Add option l to support conversion to
Windows long file names. Refactured code for capital options. Windows long file names. Refactured code for capital options.
Support of options from file for capital options. Support of options from file for capital options.
(dowin): New function. Refactured from main. (dowin): New function. Refactured from main.
@ -92,7 +102,7 @@
(get_long_name): New function. (get_long_name): New function.
(get_long_paths): New function. (get_long_paths): New function.
(get_long_path_name_w32impl): New function. Reimplementation (get_long_path_name_w32impl): New function. Reimplementation
of Windows API function GetLongPathName (only 98/Me/2000/XP or of Windows API function GetLongPathName (only 98/Me/2000/XP or
higher). higher).
(get_short_name): Call GetShortPathName only once. (get_short_name): Call GetShortPathName only once.
(get_short_paths): Fix calculating buffer size. (get_short_paths): Fix calculating buffer size.

View File

@ -1,6 +1,6 @@
/* regtool.cc /* regtool.cc
Copyright 2000 Red Hat Inc. Copyright 2000, 2001, 2002 Red Hat Inc.
This file is part of Cygwin. This file is part of Cygwin.
@ -23,6 +23,27 @@ enum
#define LIST_VALS 0x02 #define LIST_VALS 0x02
#define LIST_ALL (LIST_KEYS | LIST_VALS) #define LIST_ALL (LIST_KEYS | LIST_VALS)
static const char version[] = "$Revision$";
static char *prog_name;
static struct option longopts[] =
{
{"expand-string", no_argument, NULL, 'e' },
{"help", no_argument, NULL, 'h' },
{"integer", no_argument, NULL, 'i' },
{"keys", no_argument, NULL, 'k'},
{"list", no_argument, NULL, 'l'},
{"multi-string", no_argument, NULL, 'm'},
{"postfix", no_argument, NULL, 'p'},
{"quiet", no_argument, NULL, 'q'},
{"string", no_argument, NULL, 's'},
{"verbose", no_argument, NULL, 'v'},
{"version", no_argument, NULL, 'V'},
{NULL, 0, NULL, 0}
};
static char opts[] = "ehiklmpqsvV";
int listwhat = 0; int listwhat = 0;
int postfix = 0; int postfix = 0;
int verbose = 0; int verbose = 0;
@ -32,38 +53,78 @@ char **argv;
HKEY key; HKEY key;
char *value; char *value;
const char *usage_msg[] = { static void
"Regtool Copyright (c) 2000 Red Hat Inc", usage (FILE *where = stderr)
" regtool -h - print this message",
" 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] 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",
" regtool [-v] unset [key\\value] - removes value from key",
" regtool [-q] get [key\\value] - prints value to stdout",
" -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:",
" root HKCR HKEY_CLASSES_ROOT",
" config HKCC HKEY_CURRENT_CONFIG",
" user HKCU HKEY_CURRENT_USER",
" machine HKLM HKEY_LOCAL_MACHINE",
" users HKU HKEY_USERS",
" example: \\user\\software\\Microsoft\\Clock\\iFormat",
0
};
void
usage (void)
{ {
int i; fprintf (where, ""
for (i = 0; usage_msg[i]; i++) "Usage: %s [OPTION] (add | check | get | list | remove | unset) KEY\n"
fprintf (stderr, "%s\n", usage_msg[i]); "\n"
exit (1); "", prog_name);
if (where == stdout)
fprintf (where, ""
"Actions:\n"
" add KEY\\SUBKEY add new SUBKEY\n"
" check KEY exit 0 if KEY exists, 1 if not\n"
" get KEY\\VALUE prints VALUE to stdout\n"
" list KEY list SUBKEYs and VALUEs\n"
" remove KEY remove KEY\n"
" set KEY\\VALUE [data ...] set VALUE\n"
" unset KEY\\VALUE removes VALUE from KEY\n"
"\n");
fprintf (where, ""
"Options for 'list' Action:\n"
" -k, --keys print only KEYs\n"
" -l, --list print only VALUEs\n"
" -p, --postfix like ls -p, appends '\\' postfix to KEY names\n"
"\n"
"Options for 'set' Action:\n"
" -e, --expand-string set type to REG_EXPAND_SZ\n"
" -i, --integer set type to REG_DWORD\n"
" -m, --multi-string set type to REG_MULTI_SZ\n"
" -s, --string set type to REG_SZ\n"
"\n"
"Other Options:\n"
" -h, --help output usage information and exit\n"
" -q, --quiet no error output, just nonzero return if KEY/VALUE missing\n"
" -v, --verbose verbose output, including VALUE contents when applicable\n"
" -V, --version output version information and exit\n"
"\n");
if (where == stdout)
fprintf (where, ""
"KEY is in the format \\prefix\\KEY\\KEY\\VALUE, where prefix is any of:\n"
" \\root HKCR HKEY_CLASSES_ROOT\n"
" \\config HKCC HKEY_CURRENT_CONFIG\n"
" \\user HKCU HKEY_CURRENT_USER\n"
" \\machine HKLM HKEY_LOCAL_MACHINE\n"
" \\users HKU HKEY_USERS\n"
"");
fprintf (where, ""
"Example: %s get '\\user\\software\\Microsoft\\Clock\\iFormat'\n", prog_name);
if (where == stderr)
fprintf (where, "Try '%s --help' for more information.", prog_name);
exit (where == stderr ? 1 : 0);
}
static void
print_version ()
{
const char *v = strchr (version, ':');
int len;
if (!v)
{
v = "?";
len = 1;
}
else
{
v += 2;
len = strchr (v, ' ') - v;
}
printf ("\
%s (cygwin) %.*s\n\
Registry Tool\n\
Copyright 2000, 2001, 2002 Red Hat, Inc.\n\
Compiled on %s", prog_name, len, v, __DATE__);
} }
void void
@ -515,48 +576,56 @@ struct
int int
main (int argc, char **_argv) main (int argc, char **_argv)
{ {
while (1) int g;
{
int g = getopt (argc, _argv, "hvqisempkl"); prog_name = strrchr (_argv[0], '/');
if (g == -1) if (prog_name == NULL)
break; prog_name = strrchr (_argv[0], '\\');
switch (g) if (prog_name == NULL)
prog_name = _argv[0];
else
prog_name++;
while ((g = getopt_long (argc, _argv, opts, longopts, NULL)) != EOF)
switch (g)
{ {
case 'v': case 'e':
verbose++; key_type = KT_EXPAND;
break;
case 'q':
quiet++;
break;
case 'p':
postfix++;
break; break;
case 'k': case 'k':
listwhat |= LIST_KEYS; listwhat |= LIST_KEYS;
break; break;
case 'l': case 'h':
listwhat |= LIST_VALS; usage (stdout);
break;
case 'i': case 'i':
key_type = KT_INT; key_type = KT_INT;
break; break;
case 's': case 'l':
key_type = KT_STRING; listwhat |= LIST_VALS;
break;
case 'e':
key_type = KT_EXPAND;
break; break;
case 'm': case 'm':
key_type = KT_MULTI; key_type = KT_MULTI;
break; break;
case 'p':
case '?': postfix++;
case 'h': break;
case 'q':
quiet++;
break;
case 's':
key_type = KT_STRING;
break;
case 'v':
verbose++;
break;
case 'V':
print_version ();
exit (0);
default :
usage (); usage ();
} }
}
if (_argv[optind] == NULL) if ((_argv[optind] == NULL) || (_argv[optind+1] == NULL))
usage (); usage ();
argv = _argv + optind; argv = _argv + optind;