This is the mail archive of the cygwin-patches@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: help/version patches


> > I'm not sure I understand. Hard-code the revision in a const char 
> 
> man co might enlighten you.
> 

I'm afraid I've never used CVS/RCS before. :(
Am I reading this right? If I just put $Revision$ in the code, once
it's checked in/out that'll be replaced with the correct version number?
I see strace.cc has a line:
static const char *version_string = "@(#)strace V1.0, Copyright (C) 2001 Red
Hat
 Inc., " __DATE__ "\n";

That doesn't look autogenerated, but maybe it is.

Anyway here is a patch for cygcheck that I think does the right thing.
Somebody want to take a look?

__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com
--- cygcheck.cc-orig	Sun Feb 24 13:28:27 2002
+++ cygcheck.cc	Mon Feb 25 21:03:02 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,22 @@ 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+11);
+  version[strlen(version)-1]= 0;
 
   while ((i = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
     switch (i)
@@ -1267,17 +1278,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 ();

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]