]> sourceware.org Git - newlib-cygwin.git/commitdiff
* kill.cc (prog_name) New global variable.
authorChristopher Faylor <me@cgf.cx>
Mon, 13 May 2002 23:42:32 +0000 (23:42 +0000)
committerChristopher Faylor <me@cgf.cx>
Mon, 13 May 2002 23:42:32 +0000 (23:42 +0000)
(usage) Standardize usage output.  Add descriptions.
(print_version) New function.
(longopts) Accomodate new version option.
(opts) Ditto.
(main) Ditto.

winsup/utils/ChangeLog
winsup/utils/kill.cc

index 7f34b68de5700b4a1a046997cdfda2e12549c589..42f5f0cd3fcdb7b1de88c93c7f67345ea6a52e38 100644 (file)
@@ -1,3 +1,12 @@
+2002-05-13  Joshua Daniel Franklin <joshuadfranklin@yahoo.com>
+
+       * kill.cc (prog_name) New global variable.
+       (usage) Standardize usage output.  Add descriptions.
+       (print_version) New function.
+       (longopts) Accomodate new version option.
+       (opts) Ditto.
+       (main) Ditto.
+
 2002-05-13  Christopher Faylor  <cgf@redhat.com>
 
        * kill.cc (listsig): Display numeric id when given symbolic input.
index 80758283e515bbe7c272494b792f29019dfb8bc4..f59d1e8fda933eea8790295ccadee310bd0f44fb 100644 (file)
@@ -1,6 +1,6 @@
 /* kill.cc
 
-   Copyright 1996, 1997, 1998, 1999, 2000, 2001 Red Hat, Inc.
+   Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
 
 This file is part of Cygwin.
 
@@ -18,27 +18,60 @@ details. */
 #include <sys/cygwin.h>
 #include <getopt.h>
 
+static const char version[] = "$Revision$";
+static char *prog_name;
+
 static struct option longopts[] =
 {
   {"help", no_argument, NULL, 'h' },
   {"list", optional_argument, NULL, 'l'},
   {"force", no_argument, NULL, 'f'},
   {"signal", required_argument, NULL, 's'},
+  {"version", no_argument, NULL, 'v'},
   {NULL, 0, NULL, 0}
 };
 
-static char opts[] = "hl::fs:";
+static char opts[] = "hl::fs:v";
 
 extern "C" const char *strsigno (int);
 
 static void
 usage (FILE *where = stderr)
 {
-  fputs ("usage: kill [-signal] [-s signal] pid1 [pid2 ...]\n"
-        "       kill -l [signal]\n", where);
+  fprintf (where , ""
+       "Usage: %s [-f] [-signal] [-s signal] pid1 [pid2 ...]\n"
+       "       %s -l [signal]\n"
+       " -f, --force     force, using win32 interface if necessary\n"
+       " -l, --list      print a list of signal names\n"
+       " -s, --signal    send signal (use %s --list for a list)\n"
+       " -h, --help      output usage information and exit\n"
+       " -v, --version   output version information and exit\n"
+       "", prog_name, prog_name, 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\
+Process Signaller\n\
+Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.\n\
+Compiled on %s", prog_name, len, v, __DATE__);
+}
+
 static int
 getsig (const char *in_sig)
 {
@@ -65,7 +98,7 @@ test_for_unknown_sig (int sig, const char *sigstr)
 {
   if (sig < 0 || sig > NSIG)
     {
-      fprintf (stderr, "kill: unknown signal: %s\n", sigstr);
+      fprintf (stderr, "%s: unknown signal: %s\n", prog_name, sigstr);
       usage ();
       exit (1);
     }
@@ -111,6 +144,14 @@ main (int argc, char **argv)
   char *gotsig = NULL;
   int ret = 0;
 
+  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++;
+
   if (argc == 1)
     usage ();
 
@@ -147,6 +188,9 @@ main (int argc, char **argv)
        case 'h':
          usage (stdout);
          break;
+       case 'v':
+         print_version ();
+         break;
        case '?':
          if (gotsig)
            usage ();
@@ -170,7 +214,7 @@ main (int argc, char **argv)
       int pid = strtol (*argv, &p, 10);
       if (*p != '\0')
        {
-         fprintf (stderr, "kill: illegal pid: %s\n", *argv);
+         fprintf (stderr, "%s: illegal pid: %s\n", prog_name, *argv);
          ret = 1;
        }
       else if (kill (pid, sig) == 0)
@@ -183,7 +227,7 @@ main (int argc, char **argv)
       else
        {
          char buf[1000];
-         sprintf (buf, "kill %d", pid);
+         sprintf (buf, "%s %d", prog_name, pid);
          perror (buf);
          ret = 1;
        }
This page took 0.0363 seconds and 5 git commands to generate.