This is the mail archive of the
cygwin-patches@cygwin.com
mailing list for the Cygwin project.
RE: help/version patches
- From: Joshua Daniel Franklin <joshuadfranklin at yahoo dot com>
- To: Robert Collins <robert dot collins at itdomain dot com dot au>
- Cc: cygwin-patches at cygwin dot com
- Date: Tue, 26 Feb 2002 20:59:45 -0800 (PST)
- Subject: RE: help/version patches
--- Robert Collins <robert.collins@itdomain.com.au> wrote:
>
>
> > -----Original Message-----
> > From: Joshua Daniel Franklin [mailto:joshuadfranklin@yahoo.com]
>
> +const char *revision="$Revision: 1.22 $";
>
> This is suspect: The revision string can look like $Revision:$ in some
> circumstances - see man co again - which is why I had "$Revision: $ " - note
> the space after the second $ sign.
Hmm. Sounds like if -kk is used, it could be replaced with just "$Revision$",
which gives the +11 part problems. Another if...
> Likewise, the
> + /* Get version number out of the autogenerated revision string */
> + (void *) version = malloc(sizeof(revision));
> + strcpy(version, revision+11);
> + version[strlen(version)-1]= 0;
>
> Could be more robustly done as
> + version = (char *) malloc(sizeof(revision));
> + strcpy(version, revision+11);
> + {
> + char *temp=version + strlen (version);
> + while (isspace(--temp) && temp >= version);
> + temp[1]='\0';
> + }
>
> Which will munch an arbitrary amount of whitespace.
Well, except that that loop does away with the whole point--eating the
trailing '$'. Here's another go. I tested it with "$Revision$",
"$Revision:$", "$Revision: $ ", "$Revision: 1.22 $ ", and "$Revision: 1.2 2 $ "
(in the unlikely event of a version number with spaces) and it does the right
thing on each.
__________________________________________________
Do You Yahoo!?
Yahoo! Greetings - Send FREE e-cards for every occasion!
http://greetings.yahoo.com
--- cygcheck.cc-orig Sun Feb 24 13:28:27 2002
+++ cygcheck.cc Tue Feb 26 22:55:33 2002
@@ -1,6 +1,6 @@
/* cygcheck.cc
- Copyright 1998, 1999, 2000, 2001 Red Hat, Inc.
+ Copyright 1998-2002 Red Hat, Inc.
This file is part of Cygwin.
@@ -33,6 +33,8 @@ typedef __int64 longlong;
void dump_setup (int, char **, bool);
+const char *revision="$Revision: 1.22 $ ";
+
const char *known_env_vars[] = {
"c_include_path",
"compiler_path",
@@ -1216,17 +1218,19 @@ check_keys ()
}
void
-usage ()
+usage (FILE *stream, int status)
{
- fprintf (stderr, "Usage: cygcheck [OPTIONS] [program ...]\n");
- fprintf (stderr, " -c, --check-setup = check packages installed via setup.exe\n");
- fprintf (stderr, " -s, --sysinfo = system information (not with -k)\n");
- fprintf (stderr, " -v, --verbose = verbose output (indented) (for -s or programs)\n");
- fprintf (stderr, " -r, --registry = registry search (requires -s)\n");
- fprintf (stderr, " -k, --keycheck = perform a keyboard check session (not with -s)\n");
- fprintf (stderr, " -h, --help = give help about the info (not with -c)\n");
- fprintf (stderr, "You must at least give either -s or -k or a program name\n");
- exit (1);
+ fprintf (stream, "\
+Usage: cygcheck [OPTIONS] [program ...]\n\
+ -c, --check-setup check packages installed via setup.exe\n\
+ -s, --sysinfo system information (not with -k)\n\
+ -v, --verbose verbose output (indented) (for -s or programs)\n\
+ -r, --registry registry search (requires -s)\n\
+ -k, --keycheck perform a keyboard check session (not with -s)\n\
+ -h, --help give help about the info (not with -c)\n\
+ -z, --version output version information and exit\n\
+You must at least give either -s or -k or a program name\n");
+ exit (status);
}
struct option longopts[] = {
@@ -1236,15 +1240,32 @@ struct option longopts[] = {
{"verbose", no_argument, NULL, 'v'},
{"keycheck", no_argument, NULL, 'k'},
{"help", no_argument, NULL, 'h'},
+ {"version", no_argument, 0, 'z'},
{0, no_argument, NULL, 0}
};
-char opts[] = "srvkhc";
+char opts[] = "chkrsvz";
int
main (int argc, char **argv)
{
int i;
+ char *version;
+
+ /* Get version number out of the autogenerated revision string */
+ (void *) version = malloc(sizeof(revision));
+ strcpy(version, revision+9);
+ if (version[0] != ':')
+ *version=0;
+ else
+ {
+ version = version+2;
+ char *temp=version + strlen (version);
+ while (isspace((int)*--temp) || *temp=='$' && temp >= version)
+ temp[1]='\0';
+ }
+
+ version[strlen(version)-1]= 0;
while ((i = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
switch (i)
@@ -1267,17 +1288,27 @@ main (int argc, char **argv)
case 'h':
givehelp = 1;
break;
+ case 'z':
+ printf ("cygcheck (cygwin) %s\n", version);
+ printf ("System Checker\n");
+ printf ("Copyright 1998-2002 Red Hat, Inc.\n");
+ fputs ("Compiled "__DATE__"\n", stdout);
+ exit (0);
default:
- usage ();
+ usage (stderr, 1);
/*NOTREACHED*/}
argc -= optind;
argv += optind;
- if (argc == 0 && !sysinfo && !keycheck && !check_setup)
- usage ();
+ if (argc == 0 && !sysinfo && !keycheck && !check_setup) {
+ if (givehelp)
+ usage (stdout, 0);
+ else
+ usage (stderr, 1);
+ }
if ((check_setup || sysinfo) && keycheck)
- usage ();
+ usage (stderr, 1);
if (keycheck)
return check_keys ();