diff options
author | Christopher Faylor <me@cgf.cx> | 2002-06-03 06:57:55 +0400 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2002-06-03 06:57:55 +0400 |
commit | 9bd02410094c041166560235fb3165d0653139a6 (patch) | |
tree | 071ac2fb450efba3f187994135faf9bceeb97026 /winsup | |
parent | 56c0639f5963698dd119f213294a91b144b6c7f5 (diff) |
* 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).
Diffstat (limited to 'winsup')
-rw-r--r-- | winsup/utils/ChangeLog | 24 | ||||
-rw-r--r-- | winsup/utils/regtool.cc | 185 |
2 files changed, 144 insertions, 65 deletions
diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog index e08295a04..a159ea6c1 100644 --- a/winsup/utils/ChangeLog +++ b/winsup/utils/ChangeLog @@ -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> * strace.cc (forkdebug): Make true by default. @@ -55,11 +65,11 @@ 2002-05-23 Joshua Daniel Franklin <joshuadfranklin@yahoo.com> - * setfacl.c (usage): Standardize usage output. Change return type to - static void. - (print_version): New function. - (longopts): Added longopts for all options. - (main): Accommodate changes in usage function and new version option. + * setfacl.c (usage): Standardize usage output. Change return type to + static void. + (print_version): New function. + (longopts): Added longopts for all options. + (main): Accommodate changes in usage function and new version option. 2002-05-23 Joshua Daniel Franklin <joshuadfranklin@yahoo.com> @@ -84,7 +94,7 @@ 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. Support of options from file for capital options. (dowin): New function. Refactured from main. @@ -92,7 +102,7 @@ (get_long_name): New function. (get_long_paths): New function. (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). (get_short_name): Call GetShortPathName only once. (get_short_paths): Fix calculating buffer size. diff --git a/winsup/utils/regtool.cc b/winsup/utils/regtool.cc index 6068f3a3d..b4a3b7d08 100644 --- a/winsup/utils/regtool.cc +++ b/winsup/utils/regtool.cc @@ -1,6 +1,6 @@ /* regtool.cc - Copyright 2000 Red Hat Inc. + Copyright 2000, 2001, 2002 Red Hat Inc. This file is part of Cygwin. @@ -23,6 +23,27 @@ enum #define LIST_VALS 0x02 #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 postfix = 0; int verbose = 0; @@ -32,38 +53,78 @@ char **argv; HKEY key; char *value; -const char *usage_msg[] = { - "Regtool Copyright (c) 2000 Red Hat Inc", - " 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 -}; +static void +usage (FILE *where = stderr) +{ + fprintf (where, "" + "Usage: %s [OPTION] (add | check | get | list | remove | unset) KEY\n" + "\n" + "", 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); +} -void -usage (void) +static void +print_version () { - int i; - for (i = 0; usage_msg[i]; i++) - fprintf (stderr, "%s\n", usage_msg[i]); - exit (1); + 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 @@ -515,48 +576,56 @@ struct int main (int argc, char **_argv) { - while (1) - { - int g = getopt (argc, _argv, "hvqisempkl"); - if (g == -1) - break; - switch (g) + int g; + + prog_name = strrchr (_argv[0], '/'); + if (prog_name == NULL) + prog_name = strrchr (_argv[0], '\\'); + 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': - verbose++; - break; - case 'q': - quiet++; - break; - case 'p': - postfix++; + case 'e': + key_type = KT_EXPAND; break; case 'k': listwhat |= LIST_KEYS; break; + case 'h': + usage (stdout); + case 'i': + key_type = KT_INT; + break; case 'l': listwhat |= LIST_VALS; break; - - case 'i': - key_type = KT_INT; + case 'm': + key_type = KT_MULTI; + break; + case 'p': + postfix++; + break; + case 'q': + quiet++; break; case 's': key_type = KT_STRING; break; - case 'e': - key_type = KT_EXPAND; - break; - case 'm': - key_type = KT_MULTI; + case 'v': + verbose++; break; - - case '?': - case 'h': + case 'V': + print_version (); + exit (0); + default : usage (); } - } - if (_argv[optind] == NULL) + + if ((_argv[optind] == NULL) || (_argv[optind+1] == NULL)) usage (); argv = _argv + optind; |