long-option kill patch

Joshua Daniel Franklin joshuadfranklin@yahoo.com
Tue May 7 19:28:00 GMT 2002


And I'm sorry for the delay in keeping this help/version ball rolling.
No, I haven't been temporarily dead, just my 'net connection's been
flaky. Here's another small one. I'm keeping the patches to kill
small and managable as discussed.

This patch changes the option-handling in kill to use a switch instead
of if/else if/else clauses. It also adds basic long-option handling.

2001-05-07 Joshua Daniel Franklin <joshuadfranklin@yahoo.com>
	* kill.cc (main): Handle options in a switch. Add long-option
	for --force.
-------------- next part --------------
--- kill.cc-orig	Mon Mar 11 19:48:34 2002
+++ kill.cc	Mon Mar 11 19:55:19 2002
@@ -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.
 
@@ -61,26 +61,50 @@ main (int argc, char **argv)
   int force = 0;
   int gotsig = 0;
   int ret = 0;
+  int opt = 0;
+  char *longopt;
 
   if (argc == 1)
     usage ();
 
   while (*++argv && **argv == '-')
-    if (strcmp (*argv + 1, "f") == 0)
-      force = 1;
-    else if (gotsig)
-      break;
-    else if (strcmp(*argv + 1, "0") != 0)
-      {
-	sig = getsig (*argv + 1);
-	gotsig = 1;
-      }
-    else
-      {
-	argv++;
-	sig = 0;
-	goto sig0;
-      }
+    {
+      opt = *(*argv + 1);
+      if (!gotsig)
+        switch (opt)
+          {
+          case 'f':
+            force = 1;
+            break;
+
+          case '0':
+            argv++;
+            sig = 0;
+            goto sig0;
+            return ret;
+
+          /* Handle long options */
+          case '-':
+            longopt = *argv + 2;
+            if (strcmp (longopt, "force") == 0)
+              force = 1;
+            else
+              {
+                fprintf (stderr, "kill: unknown long option: --%s\n\n",
+                         longopt);
+                usage ();
+              }
+            *argv += strlen (longopt);
+            break;
+          /* End of long options */
+
+          default:
+            sig = getsig (*argv + 1);
+            gotsig = 1;
+          }
+      else
+        break;
+    }
 
   if (sig <= 0 || sig > NSIG)
     {


More information about the Cygwin-patches mailing list