]> Dogcows Code - chaz/tar/commitdiff
Improve command line option handling.
authorSergey Poznyakoff <gray@gnu.org.ua>
Tue, 8 Sep 2009 08:08:49 +0000 (11:08 +0300)
committerSergey Poznyakoff <gray@gnu.org.ua>
Tue, 8 Sep 2009 08:08:49 +0000 (11:08 +0300)
* gnulib.modules: Add argp-version-etc and progname,
use getopt-gnu instead of getopt.
* src/tar.c (HANG_OPTION, USAGE_OPTION)
(VERSION_OPTION): Remove.
(options): Remove corresponding options. Let argp
handle them.
(parse_opt): Likewise.
(_argp_hang): Removed.
(tar_authors): New variable.
(decode_options): Call argp_version_setup.
Do not use ARGP_NO_HELP flag in the call to argp_parse.

gnulib.modules
src/tar.c

index 9ec354fbb7a3826159e7e2db5e62295790323534..d5ebce5e7c51fb3d47e89b70f659a06a0fd52783 100644 (file)
@@ -4,6 +4,7 @@
 alloca
 argmatch
 argp
+argp-version-etc
 backupfile
 canonicalize
 closeout
@@ -19,7 +20,7 @@ ftruncate
 full-write
 getdate
 getline
-getopt
+getopt-gnu
 getpagesize
 gettext
 gettime
@@ -33,6 +34,7 @@ mkdtemp
 modechange
 obstack
 priv-set
+progname
 quote
 quotearg
 rpmatch
index 055746188cd55b029d2026deb4ece99a17d148bb..d4fda6fad53c8df89902e23b95fc2ef339eb21b9 100644 (file)
--- a/src/tar.c
+++ b/src/tar.c
@@ -25,6 +25,7 @@
 #include <argp.h>
 #include <argp-namefrob.h>
 #include <argp-fmtstream.h>
+#include <argp-version-etc.h>
 
 #include <signal.h>
 #if ! defined SIGCHLD && defined SIGCLD
@@ -267,7 +268,6 @@ enum
   EXCLUDE_VCS_OPTION,
   FORCE_LOCAL_OPTION,
   GROUP_OPTION,
-  HANG_OPTION,
   IGNORE_CASE_OPTION,
   IGNORE_COMMAND_ERROR_OPTION,
   IGNORE_FAILED_READ_OPTION,
@@ -327,9 +327,7 @@ enum
   TO_COMMAND_OPTION,
   TRANSFORM_OPTION,
   UNQUOTE_OPTION,
-  USAGE_OPTION,
   UTC_OPTION,
-  VERSION_OPTION,
   VOLNO_FILE_OPTION,
   WARNING_OPTION, 
   WILDCARDS_MATCH_SLASH_OPTION,
@@ -788,14 +786,6 @@ static struct argp_option options[] = {
 
   {"restrict", RESTRICT_OPTION, 0, 0,
    N_("disable use of some potentially harmful options"), -1 },
-
-  {"help",  '?', 0, 0,  N_("give this help list"), -1},
-  {"usage", USAGE_OPTION, 0, 0,  N_("give a short usage message"), -1},
-  {"version", VERSION_OPTION, 0, 0,  N_("print program version"), -1},
-  /* FIXME -V (--label) conflicts with the default short option for
-     --version */
-  {"HANG",       HANG_OPTION,    "SECS", OPTION_ARG_OPTIONAL | OPTION_HIDDEN,
-   N_("hang for SECS seconds (default 3600)"), 0},
 #undef GRID
 
   {0, 0, 0, 0, 0, 0}
@@ -1074,7 +1064,6 @@ report_textual_dates (struct tar_args *args)
 }
 
 \f
-static volatile int _argp_hang;
 
 /* Either NL or NUL, as decided by the --null option.  */
 static char filename_terminator;
@@ -2061,28 +2050,6 @@ parse_opt (int key, char *arg, struct argp_state *state)
 
 #endif /* not DEVICE_PREFIX */
 
-    case '?':
-      tar_help (state);
-      close_stdout ();
-      exit (0);
-
-    case USAGE_OPTION:
-      argp_state_help (state, state->out_stream, ARGP_HELP_USAGE);
-      close_stdout ();
-      exit (0);
-
-    case VERSION_OPTION:
-      version_etc (state->out_stream, "tar", PACKAGE_NAME, VERSION,
-                  "John Gilmore", "Jay Fenlason", (char *) NULL);
-      close_stdout ();
-      exit (0);
-
-    case HANG_OPTION:
-      _argp_hang = atoi (arg ? arg : "3600");
-      while (_argp_hang-- > 0)
-       sleep (1);
-      break;
-
     default:
       return ARGP_ERR_UNKNOWN;
     }
@@ -2123,12 +2090,20 @@ find_argp_option (struct argp_option *o, int letter)
   return NULL;
 }
 
+static const char *tar_authors[] = {
+  "John Gilmore",
+  "Jay Fenlason",
+  NULL
+};
+
 static void
 decode_options (int argc, char **argv)
 {
   int idx;
   struct tar_args args;
 
+  argp_version_setup ("tar", tar_authors);
+  
   /* Set some default option values.  */
   args.textual_date = NULL;
   args.wildcards = default_wildcards;
@@ -2223,8 +2198,7 @@ decode_options (int argc, char **argv)
 
   prepend_default_options (getenv ("TAR_OPTIONS"), &argc, &argv);
 
-  if (argp_parse (&argp, argc, argv, ARGP_IN_ORDER|ARGP_NO_HELP,
-                 &idx, &args))
+  if (argp_parse (&argp, argc, argv, ARGP_IN_ORDER, &idx, &args))
     exit (TAREXIT_FAILURE);
 
 
This page took 0.025197 seconds and 4 git commands to generate.