Quellcode durchsuchen

Improve previous changes.

* acinclude.m4: Fix typos.
* gnulib.modules: Add xvasprintf.
* src/common.h: Include xvasprintf.h.
* src/tar.c (options): Remove docstrings for --gzip, --bzip2,
--compress, --lzop, --lzma and --xz.
(tar_help_filter): Generate these using actual values of
*_PROGRAM constants.
(format_default_settings): Use xasprintf.
(parse_opt): Use *_PROGRAM defines instead of hardcoded
program names.
Sergey Poznyakoff vor 15 Jahren
Ursprung
Commit
84a55f12e5
4 geänderte Dateien mit 60 neuen und 42 gelöschten Zeilen
  1. 2 2
      acinclude.m4
  2. 1 1
      gnulib.modules
  3. 1 0
      src/common.h
  4. 56 39
      src/tar.c

+ 2 - 2
acinclude.m4

@@ -17,10 +17,10 @@ dnl with GNU tar.  If not, see <http://www.gnu.org/licenses/>.
 AC_DEFUN([TAR_COMPR_PROGRAM],[
 AC_DEFUN([TAR_COMPR_PROGRAM],[
  m4_pushdef([tar_compr_define],translit($1,[a-z+-],[A-ZX_])[_PROGRAM])
  m4_pushdef([tar_compr_define],translit($1,[a-z+-],[A-ZX_])[_PROGRAM])
  m4_pushdef([tar_compr_var],[tar_cv_compressor_]translit($1,[+-],[x_]))
  m4_pushdef([tar_compr_var],[tar_cv_compressor_]translit($1,[+-],[x_]))
- AC_ARG_WITH([--with-]$1,
+ AC_ARG_WITH($1,
              AC_HELP_STRING([--with-]$1[=PROG],
              AC_HELP_STRING([--with-]$1[=PROG],
 	                    [use PROG as ]$1[ compressor program]),
 	                    [use PROG as ]$1[ compressor program]),
-             [tar_compr_var=${withvar}],
+             [tar_compr_var=${withval}],
 	     [tar_compr_var=m4_if($2,,$1,$2)])
 	     [tar_compr_var=m4_if($2,,$1,$2)])
  AC_DEFINE_UNQUOTED(tar_compr_define, "$tar_compr_var",
  AC_DEFINE_UNQUOTED(tar_compr_define, "$tar_compr_var",
                     [Define to the program name of ]$1[ compressor program])])
                     [Define to the program name of ]$1[ compressor program])])

+ 1 - 1
gnulib.modules

@@ -5,7 +5,6 @@ alloca
 argmatch
 argmatch
 argp
 argp
 argp-version-etc
 argp-version-etc
-asprintf
 backupfile
 backupfile
 canonicalize
 canonicalize
 closeout
 closeout
@@ -62,3 +61,4 @@ xalloc
 xalloc-die
 xalloc-die
 xgetcwd
 xgetcwd
 xstrtoumax
 xstrtoumax
+xvasprintf

+ 1 - 0
src/common.h

@@ -61,6 +61,7 @@
 #define obstack_chunk_free free
 #define obstack_chunk_free free
 #include <obstack.h>
 #include <obstack.h>
 #include <progname.h>
 #include <progname.h>
+#include <xvasprintf.h>
 
 
 #include <paxlib.h>
 #include <paxlib.h>
 
 

+ 56 - 39
src/tar.c

@@ -614,23 +614,18 @@ static struct argp_option options[] = {
   {"no-auto-compress", NO_AUTO_COMPRESS_OPTION, 0, 0,
   {"no-auto-compress", NO_AUTO_COMPRESS_OPTION, 0, 0,
    N_("do not use archive suffix to determine the compression program"),
    N_("do not use archive suffix to determine the compression program"),
    GRID+1 },
    GRID+1 },
-  {"bzip2", 'j', 0, 0,
-   N_("filter the archive through bzip2"), GRID+1 },
-  {"gzip", 'z', 0, 0,
-   N_("filter the archive through gzip"), GRID+1 },
+  {"use-compress-program", 'I', N_("PROG"), 0,
+   N_("filter through PROG (must accept -d)"), GRID+1 },
+  /* Note: docstrings for the options below are generated by tar_help_filter */
+  {"bzip2", 'j', 0, 0, NULL, GRID+1 },
+  {"gzip", 'z', 0, 0, NULL, GRID+1 },
   {"gunzip", 0, 0, OPTION_ALIAS, NULL, GRID+1 },
   {"gunzip", 0, 0, OPTION_ALIAS, NULL, GRID+1 },
   {"ungzip", 0, 0, OPTION_ALIAS, NULL, GRID+1 },
   {"ungzip", 0, 0, OPTION_ALIAS, NULL, GRID+1 },
-  {"compress", 'Z', 0, 0,
-   N_("filter the archive through compress"), GRID+1 },
+  {"compress", 'Z', 0, 0, NULL, GRID+1 },
   {"uncompress", 0, 0, OPTION_ALIAS, NULL, GRID+1 },
   {"uncompress", 0, 0, OPTION_ALIAS, NULL, GRID+1 },
-  {"lzma", LZMA_OPTION, 0, 0,
-   N_("filter the archive through lzma"), GRID+1 },
-  {"lzop", LZOP_OPTION, 0, 0,
-   N_("filter the archive through lzop"), GRID+8 },
-  {"xz", 'J', 0, 0,
-   N_("filter the archive through xz"), GRID+8 },
-  {"use-compress-program", 'I', N_("PROG"), 0,
-   N_("filter through PROG (must accept -d)"), GRID+1 },
+  {"lzma", LZMA_OPTION, 0, 0, NULL, GRID+1 },
+  {"lzop", LZOP_OPTION, 0, 0, NULL, GRID+1 },
+  {"xz", 'J', 0, 0, NULL, GRID+1 },
 #undef GRID
 #undef GRID
   
   
 #define GRID 100
 #define GRID 100
@@ -903,9 +898,7 @@ add_exclude_array (char const * const * fv)
 static char *
 static char *
 format_default_settings (void)
 format_default_settings (void)
 {
 {
-  char *s;
-  
-  asprintf (&s,
+  return xasprintf (
 	    "--format=%s -f%s -b%d --quoting-style=%s --rmt-command=%s"
 	    "--format=%s -f%s -b%d --quoting-style=%s --rmt-command=%s"
 #ifdef REMOTE_SHELL
 #ifdef REMOTE_SHELL
 	    " --rsh-command=%s"
 	    " --rsh-command=%s"
@@ -919,7 +912,6 @@ format_default_settings (void)
 	    REMOTE_SHELL
 	    REMOTE_SHELL
 #endif
 #endif
 	    );
 	    );
-  return s;
 }
 }
 
 
 
 
@@ -1260,22 +1252,47 @@ tar_help_filter (int key, const char *text, void *input)
   struct obstack stk;
   struct obstack stk;
   char *s;
   char *s;
 
 
-  if (key != ARGP_KEY_HELP_EXTRA)
-    return (char*) text;
+  switch (key)
+    {
+    default:
+      s = (char*) text;
+      break;
+      
+    case 'j':
+      s = xasprintf (_("filter the archive through %s"), BZIP2_PROGRAM);
+      break;
+      
+    case 'z':
+      s = xasprintf (_("filter the archive through %s"), GZIP_PROGRAM);
+      break;
+      
+    case 'Z':
+      s = xasprintf (_("filter the archive through %s"), COMPRESS_PROGRAM);
+      break;
 
 
-  obstack_init (&stk);
-  s = _("Valid arguments for the --quoting-style option are:");
-  obstack_grow (&stk, s, strlen (s));
-  obstack_grow (&stk, "\n\n", 2);
-  tar_list_quoting_styles (&stk, "  ");
-  s = _("\n*This* tar defaults to:\n");
-  obstack_grow (&stk, s, strlen (s));
-  s = format_default_settings ();
-  obstack_grow (&stk, s, strlen (s));
-  obstack_1grow (&stk, '\n');
-  obstack_1grow (&stk, 0);
-  s = xstrdup (obstack_finish (&stk));
-  obstack_free (&stk, NULL);
+    case LZMA_OPTION:
+      s = xasprintf (_("filter the archive through %s"), LZMA_PROGRAM);
+      break;
+      
+    case 'J':
+      s = xasprintf (_("filter the archive through %s"), XZ_PROGRAM);
+      break;
+      
+    case ARGP_KEY_HELP_EXTRA:
+      obstack_init (&stk);
+      s = _("Valid arguments for the --quoting-style option are:");
+      obstack_grow (&stk, s, strlen (s));
+      obstack_grow (&stk, "\n\n", 2);
+      tar_list_quoting_styles (&stk, "  ");
+      s = _("\n*This* tar defaults to:\n");
+      obstack_grow (&stk, s, strlen (s));
+      s = format_default_settings ();
+      obstack_grow (&stk, s, strlen (s));
+      obstack_1grow (&stk, '\n');
+      obstack_1grow (&stk, 0);
+      s = xstrdup (obstack_finish (&stk));
+      obstack_free (&stk, NULL);
+    }
   return s;
   return s;
 }
 }
 
 
@@ -1441,11 +1458,11 @@ parse_opt (int key, char *arg, struct argp_state *state)
       break;
       break;
       
       
     case 'j':
     case 'j':
-      set_use_compress_program_option ("bzip2");
+      set_use_compress_program_option (BZIP2_PROGRAM);
       break;
       break;
       
       
     case 'J':
     case 'J':
-      set_use_compress_program_option ("xz");
+      set_use_compress_program_option (XZ_PROGRAM);
       break;
       break;
       
       
     case 'k':
     case 'k':
@@ -1489,11 +1506,11 @@ parse_opt (int key, char *arg, struct argp_state *state)
       break;
       break;
       
       
     case LZMA_OPTION:
     case LZMA_OPTION:
-      set_use_compress_program_option ("lzma");
+      set_use_compress_program_option (LZMA_PROGRAM);
       break;
       break;
       
       
     case LZOP_OPTION:
     case LZOP_OPTION:
-      set_use_compress_program_option ("lzop");
+      set_use_compress_program_option (LZOP_PROGRAM);
       break;
       break;
       
       
     case 'm':
     case 'm':
@@ -1651,11 +1668,11 @@ parse_opt (int key, char *arg, struct argp_state *state)
       break;
       break;
       
       
     case 'z':
     case 'z':
-      set_use_compress_program_option ("gzip");
+      set_use_compress_program_option (GZIP_PROGRAM);
       break;
       break;
       
       
     case 'Z':
     case 'Z':
-      set_use_compress_program_option ("compress");
+      set_use_compress_program_option (COMPRESS_PROGRAM);
       break;
       break;
       
       
     case ANCHORED_OPTION:
     case ANCHORED_OPTION: