diff options
author | Jim Meyering <jim@meyering.net> | 1993-04-01 04:02:20 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1993-04-01 04:02:20 +0000 |
commit | d24f7571cc04065e3c7cb1fe39563dd350f00738 (patch) | |
tree | 3c3a2a5860755ed24d63ce0cbe5cc96b4e76e804 | |
parent | 0f8d90bd48f669a9575a0a0750db7ba883f4dfa0 (diff) | |
download | coreutils-d24f7571cc04065e3c7cb1fe39563dd350f00738.tar.xz |
Add --version, --help options.
-rw-r--r-- | src/dd.c | 37 |
1 files changed, 35 insertions, 2 deletions
@@ -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; |