]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Add --version, --help options.
authorJim Meyering <jim@meyering.net>
Thu, 1 Apr 1993 04:02:20 +0000 (04:02 +0000)
committerJim Meyering <jim@meyering.net>
Thu, 1 Apr 1993 04:02:20 +0000 (04:02 +0000)
src/dd.c

index 4d78b8e40b5d22bf80fad1ade715bd223747ee1e..c8a433740a6f98371e3eff8ed1d3f15c268176ba 100644 (file)
--- a/src/dd.c
+++ b/src/dd.c
@@ -56,7 +56,7 @@
 #include <stdio.h>
 #include <ctype.h>
 
-#ifndef isascii
+#if !defined (isascii) || defined (STDC_HEADERS)
 #define isascii(c) 1
 #endif
 
@@ -66,7 +66,9 @@
 
 #include <sys/types.h>
 #include <signal.h>
+#include <getopt.h>
 #include "system.h"
+#include "version.h"
 
 #define equal(p, q) (strcmp ((p),(q)) == 0)
 #define max(a, b) ((a) > (b) ? (a) : (b))
@@ -305,6 +307,16 @@ static unsigned char const ebcdic_to_ascii[] =
   070, 071, 0372, 0373, 0374, 0375, 0376, 0377
 };
 
+static int flag_help;
+static int flag_version;
+
+static struct option const long_options[] =
+{
+  {"help", no_argument, &flag_help, 1},
+  {"version", no_argument, &flag_version, 1},
+  {0, 0, 0, 0}
+};
+
 void
 main (argc, argv)
      int argc;
@@ -323,6 +335,13 @@ main (argc, argv)
 
   /* Decode arguments. */
   scanargs (argc, argv);
+
+  if (flag_version)
+    fprintf (stderr, "%s", version_string);
+
+  if (flag_help)
+    usage ("", NULL, NULL);
+
   apply_translations ();
 
   if (input_file != NULL)
@@ -774,8 +793,22 @@ scanargs (argc, argv)
      char **argv;
 {
   int i, n;
+  int c;
+
+  while ((c = getopt_long (argc, argv, "", long_options, (int *) 0)) != EOF)
+    {
+      switch (c)
+       {
+       case 0:
+         break;
+
+       default:
+         usage ("", NULL, NULL);
+
+       }
+    }
 
-  for (i = 1; i < argc; i++)
+  for (i = optind; i < argc; i++)
     {
       char *name, *val;