Merge tag 'upstream/1.6'
authorBdale Garbee <bdale@gag.com>
Tue, 11 Jun 2013 14:48:11 +0000 (08:48 -0600)
committerBdale Garbee <bdale@gag.com>
Tue, 11 Jun 2013 14:48:11 +0000 (08:48 -0600)
Upstream version 1.6

Conflicts:
gzip.1
gzip.c
zdiff.1

1  2 
deflate.c
doc/gzip.texi
gzip.c
gzip.h
zdiff.1

diff --combined deflate.c
index 4a0f3d37b28278a00695d6440c7993d91e6e5845,f0f23940ac9d0c891877105ebc803d508483987d..8e539d2623a6eac5d6bc9d471a3ef6088b7bea65
+++ b/deflate.c
@@@ -1,6 -1,6 +1,6 @@@
  /* deflate.c -- compress data using the deflation algorithm
  
-    Copyright (C) 1999, 2006, 2009-2012 Free Software Foundation, Inc.
+    Copyright (C) 1999, 2006, 2009-2013 Free Software Foundation, Inc.
     Copyright (C) 1992-1993 Jean-loup Gailly
  
     This program is free software; you can redistribute it and/or modify
  #endif
  /* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
  
 +#ifndef RSYNC_WIN
 +#  define RSYNC_WIN 8192
 +#endif
 +/* Size of rsync window, must be < MAX_DIST */
 +
 +#define RSYNC_SUM_MATCH(sum) (((sum) & (RSYNC_WIN - 1)) == 0)
 +/* Whether window sum matches magic value */
 +
  /* ===========================================================================
   * Local data used by the "longest match" routines.
   */
@@@ -220,8 -212,6 +220,8 @@@ local int compr_level
  unsigned good_match;
  /* Use a faster search when the previous match is longer than this */
  
 +local ulg rsync_sum;  /* rolling sum of rsync window */
 +local ulg rsync_chunk_end; /* next rsync sequence point */
  
  /* Values for max_lazy_match, good_match and max_chain_length, depending on
   * the desired pack level (0..9). The values given below have been tuned to
@@@ -324,10 -314,6 +324,10 @@@ void lm_init (pack_level, flags
  #endif
      /* prev will be initialized on the fly */
  
 +    /* rsync params */
 +    rsync_chunk_end = 0xFFFFFFFFUL;
 +    rsync_sum = 0;
 +
      /* Set the default configuration parameters:
       */
      max_lazy_match   = configuration_table[pack_level].max_lazy;
  
      strstart = 0;
      block_start = 0L;
 +    rsync_chunk_end = 0xFFFFFFFFUL;
  #ifdef ASMV
      match_init(); /* initialize the asm code */
  #endif
@@@ -565,8 -550,6 +565,8 @@@ local void fill_window(
          memcpy((char*)window, (char*)window+WSIZE, (unsigned)WSIZE);
          match_start -= WSIZE;
          strstart    -= WSIZE; /* we now have strstart >= MAX_DIST: */
 +      if (rsync_chunk_end != 0xFFFFFFFFUL)
 +          rsync_chunk_end -= WSIZE;
  
          block_start -= (long) WSIZE;
  
      }
  }
  
 +local void rsync_roll(start, num)
 +    unsigned start;
 +    unsigned num;
 +{
 +    unsigned i;
 +
 +    if (start < RSYNC_WIN) {
 +      /* before window fills. */
 +      for (i = start; i < RSYNC_WIN; i++) {
 +          if (i == start + num) return;
 +          rsync_sum += (ulg)window[i];
 +      }
 +      num -= (RSYNC_WIN - start);
 +      start = RSYNC_WIN;
 +    }
 +
 +    /* buffer after window full */
 +    for (i = start; i < start+num; i++) {
 +      /* New character in */
 +      rsync_sum += (ulg)window[i];
 +      /* Old character out */
 +      rsync_sum -= (ulg)window[i - RSYNC_WIN];
 +      if (rsync_chunk_end == 0xFFFFFFFFUL && RSYNC_SUM_MATCH(rsync_sum))
 +          rsync_chunk_end = i;
 +    }
 +}
 +
 +/* ===========================================================================
 + * Set rsync_chunk_end if window sum matches magic value.
 + */
 +#define RSYNC_ROLL(s, n) \
 +   do { if (rsync) rsync_roll((s), (n)); } while(0)
 +
  /* ===========================================================================
   * Flush the current block, with given end-of-file flag.
   * IN assertion: strstart is set to the end of the current match.
@@@ -676,8 -626,7 +676,8 @@@ local off_t deflate_fast(
  
              lookahead -= match_length;
  
 -            /* Insert new strings in the hash table only if the match length
 +          RSYNC_ROLL(strstart, match_length);
 +          /* Insert new strings in the hash table only if the match length
               * is not too large. This saves time but degrades compression.
               */
              if (match_length <= max_insert_length) {
              /* No match, output a literal byte */
              Tracevv((stderr,"%c",window[strstart]));
              flush = ct_tally (0, window[strstart]);
 +          RSYNC_ROLL(strstart, 1);
              lookahead--;
              strstart++;
          }
 +        if (rsync && strstart > rsync_chunk_end) {
 +            ush  attr = 0;          /* ascii/binary flag */
 +
 +            flush = 1;
 +            /* Reset huffman tree */
 +            ct_init(&attr, &method);
 +            rsync_chunk_end = 0xFFFFFFFFUL;
 +        }
          if (flush) FLUSH_BLOCK(0), block_start = strstart;
  
          /* Make sure that we always have enough lookahead, except
@@@ -790,7 -730,6 +790,7 @@@ off_t deflate(
               */
              lookahead -= prev_length-1;
              prev_length -= 2;
 +          RSYNC_ROLL(strstart, prev_length+1);
              do {
                  strstart++;
                  INSERT_STRING(strstart, hash_head);
              match_available = 0;
              match_length = MIN_MATCH-1;
              strstart++;
 -            if (flush) FLUSH_BLOCK(0), block_start = strstart;
  
 +          if (rsync && strstart > rsync_chunk_end) {
 +              ush  attr = 0;          /* ascii/binary flag */
 +
 +              /* Reset huffman tree */
 +              ct_init(&attr, &method);
 +              rsync_chunk_end = 0xFFFFFFFFUL;
 +              flush = 1;
 +          }
 +            if (flush) FLUSH_BLOCK(0), block_start = strstart;
          } else if (match_available) {
              /* If there was no match at the previous position, output a
               * single literal. If there was a match but the current match
               * is longer, truncate the previous match to a single literal.
               */
              Tracevv((stderr,"%c",window[strstart-1]));
 -            if (ct_tally (0, window[strstart-1])) {
 -                FLUSH_BLOCK(0), block_start = strstart;
 -            }
 +          flush = ct_tally (0, window[strstart-1]);
 +          if (rsync && strstart > rsync_chunk_end) {
 +              ush  attr = 0;          /* ascii/binary flag */
 +
 +              /* Reset huffman tree */
 +              ct_init(&attr, &method);
 +              rsync_chunk_end = 0xFFFFFFFFUL;
 +
 +              flush = 1;
 +          }
 +            if (flush) FLUSH_BLOCK(0), block_start = strstart;
 +          RSYNC_ROLL(strstart, 1);
              strstart++;
              lookahead--;
          } else {
              /* There is no previous match to compare with, wait for
               * the next step to decide.
               */
 +          if (rsync && strstart > rsync_chunk_end) {
 +              ush  attr = 0;          /* ascii/binary flag */
 +
 +              /* Reset huffman tree */
 +              ct_init(&attr, &method);
 +              rsync_chunk_end = 0xFFFFFFFFUL;
 +
 +              FLUSH_BLOCK(0), block_start = strstart;
 +          }
              match_available = 1;
 +          RSYNC_ROLL(strstart, 1);
              strstart++;
              lookahead--;
          }
diff --combined doc/gzip.texi
index ffe20b4acfcf811d6edff48382e6bce5e3f7700c,3de3063c17b8f612321977646f16ff491beb9e53..7ff37adf6cd1adf698f54bfc260fc4c7124a8bad
@@@ -11,7 -11,7 +11,7 @@@ This manual is for GNU Gzi
  (version @value{VERSION}, @value{UPDATED}),
  and documents commands for compressing and decompressing data.
  
- Copyright @copyright{} 1998-1999, 2001-2002, 2006-2007, 2009-2012 Free Software
+ Copyright @copyright{} 1998-1999, 2001-2002, 2006-2007, 2009-2013 Free Software
  Foundation, Inc.
  
  Copyright @copyright{} 1992, 1993 Jean-loup Gailly
@@@ -171,10 -171,10 +171,10 @@@ ownership and time stamps of files whe
  
  The @command{gzip} file format is specified in P. Deutsch, @sc{gzip} file
  format specification version 4.3,
- @uref{ftp://ftp.isi.edu/in-notes/rfc1952.txt, Internet @abbr{RFC} 1952} (May
+ @uref{http://www.ietf.org/rfc/rfc1952.txt, Internet @abbr{RFC} 1952} (May
  1996).  The @command{zip} deflation format is specified in P. Deutsch,
  @sc{deflate} Compressed Data Format Specification version 1.3,
- @uref{ftp://ftp.isi.edu/in-notes/rfc1951.txt, Internet @abbr{RFC} 1951} (May
+ @uref{http://www.ietf.org/rfc/rfc1951.txt, Internet @abbr{RFC} 1951} (May
  1996).
  
  @node Sample
@@@ -195,6 -195,7 +195,7 @@@ Mandatory arguments to long options ar
    -d, --decompress  decompress
    -f, --force       force overwrite of output file and compress links
    -h, --help        give this help
+   -k, --keep        keep (don't delete) input files
    -l, --list        list compressed file contents
    -L, --license     display software license
    -n, --no-name     do not save or restore the original name and time stamp
    -V, --version     display version number
    -1, --fast        compress faster
    -9, --best        compress better
 +    --rsyncable   Make rsync-friendly archive
  
  With no FILE, or when FILE is -, read standard input.
  
@@@ -277,6 -277,10 +278,10 @@@ whether an existing file should be over
  @itemx -h
  Print an informative help message describing the options then quit.
  
+ @item --keep
+ @itemx -k
+ Keep (don't delete) input files during compression or decompression.
  @item --list
  @itemx -l
  For each compressed file, list the following fields:
@@@ -354,30 -358,6 +359,30 @@@ specified on the command line are direc
  into the directory and compress all the files it finds there (or
  decompress them in the case of @command{gunzip}).
  
 +@item --rsyncable
 +While compressing, synchronize the output occasionally based on the
 +input.  This can reduce the compression slightly in some cases, but
 +means that the @code{rsync} program can take advantage of similarities
 +in the uncompressed input when syncronizing two files compressed with
 +this flag.  @code{gunzip} cannot tell the difference between a
 +compressed file created with this option, and one created without it.
 +
 +@item --rsyncable
 +While compressing, synchronize the output occasionally based on
 +the input.  This increases size by less than 1 percent most
 +cases, but means that the @command{rsync} program can much more efficiently
 +synchronize files compressed with this flag.  @command{gunzip}
 +cannot tell the difference between a compressed file created
 +with this option, and one created without it.
 +
 +@item --rsyncable
 +While compressing, synchronize the output occasionally based on the
 +input.  This can reduce the compression slightly in some cases, but
 +means that the @code{rsync} program can take advantage of similarities
 +in the uncompressed input when syncronizing two files compressed with
 +this flag.  @code{gunzip} cannot tell the difference between a
 +compressed file created with this option, and one created without it.
 +
  @item --suffix @var{suf}
  @itemx -S @var{suf}
  Use suffix @var{suf} instead of @samp{.gz}.  Any suffix can be
diff --combined gzip.c
index 5fc6ded293c785ed584812e0b7eae73bcb0ecc9c,93cc7384ff3959664807e7dad470fe01f4c4f99c..cceb42000d48e80536f3c352a103c6cea63aa644
--- 1/gzip.c
--- 2/gzip.c
+++ b/gzip.c
@@@ -1,6 -1,6 +1,6 @@@
  /* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
  
-    Copyright (C) 1999, 2001-2002, 2006-2007, 2009-2012 Free Software
+    Copyright (C) 1999, 2001-2002, 2006-2007, 2009-2013 Free Software
     Foundation, Inc.
     Copyright (C) 1992-1993 Jean-loup Gailly
  
@@@ -74,6 -74,7 +74,7 @@@ static char const *const license_msg[] 
  #include "ignore-value.h"
  #include "stat-time.h"
  #include "version.h"
+ #include "yesno.h"
  
                  /* configuration */
  
@@@ -166,6 -167,7 +167,7 @@@ static int ascii = 0;        /* conver
         int to_stdout = 0;    /* output to stdout (-c) */
  static int decompress = 0;   /* decompress (-d) */
  static int force = 0;        /* don't ask questions, compress links (-f) */
+ static int keep = 0;         /* keep (don't delete) input files */
  static int no_name = -1;     /* don't save or restore the original file name */
  static int no_time = -1;     /* don't save or restore the original file time */
  static int recursive = 0;    /* recurse through directories (-r) */
@@@ -213,7 -215,6 +215,7 @@@ int  ofd;                  /* output fi
  unsigned insize;           /* valid bytes in inbuf */
  unsigned inptr;            /* index of next byte to be processed in inbuf */
  unsigned outcnt;           /* bytes in output buffer */
 +int rsync = 0;             /* make ryncable chunks */
  
  static int handled_sig[] =
    {
  #ifdef SIGHUP
      , SIGHUP
  #endif
- #ifdef SIGPIPE
+ #if SIGPIPE
      , SIGPIPE
  #endif
  #ifdef SIGTERM
@@@ -256,6 -257,7 +258,7 @@@ static const struct option longopts[] 
      {"force",      0, 0, 'f'}, /* force overwrite of output file */
      {"help",       0, 0, 'h'}, /* give help */
   /* {"pkzip",      0, 0, 'k'},    force output in pkzip format */
+     {"keep",       0, 0, 'k'}, /* keep (don't delete) input files */
      {"list",       0, 0, 'l'}, /* list .gz file contents */
      {"license",    0, 0, 'L'}, /* display software license */
      {"no-name",    0, 0, 'n'}, /* don't save or restore original name & time */
      {"best",       0, 0, '9'}, /* compress better */
      {"lzw",        0, 0, 'Z'}, /* make output compatible with old compress */
      {"bits",       1, 0, 'b'}, /* max number of bits per code (implies -Z) */
 -
 +    {"rsyncable",  0, 0, 'R'}, /* make rsync-friendly archive */
      { 0, 0, 0, 0 }
  };
  
@@@ -334,6 -336,7 +337,7 @@@ local void help(
   "  -f, --force       force overwrite of output file and compress links",
   "  -h, --help        give this help",
  /*  -k, --pkzip       force output in pkzip format */
+  "  -k, --keep        keep (don't delete) input files",
   "  -l, --list        list compressed file contents",
   "  -L, --license     display software license",
  #ifdef UNDOCUMENTED
   "  -Z, --lzw         produce output compatible with old compress",
   "  -b, --bits=BITS   max number of bits per code (implies -Z)",
  #endif
 + "  --rsyncable       Make rsync-friendly archive",
   "",
   "With no FILE, or when FILE is -, read standard input.",
   "",
@@@ -438,7 -440,7 +442,7 @@@ int main (int argc, char **argv
      z_suffix = Z_SUFFIX;
      z_len = strlen(z_suffix);
  
-     while ((optc = getopt_long (argc, argv, "ab:cdfhH?lLmMnNqrS:tvVZ123456789",
+     while ((optc = getopt_long (argc, argv, "ab:cdfhH?klLmMnNqrS:tvVZ123456789",
                                  longopts, (int *)0)) != -1) {
          switch (optc) {
          case 'a':
              force++; break;
          case 'h': case 'H':
              help(); do_exit(OK); break;
+         case 'k':
+             keep = 1; break;
          case 'l':
              list = decompress = to_stdout = 1; break;
          case 'L':
  #else
              recursive = 1;
  #endif
 -            break;
 -        case 'S':
 +          break;
 +        case 'R':
 +          rsync = 1; break;
 +
 +      case 'S':
  #ifdef NO_MULTIPLE_DOTS
              if (*optarg == '.') optarg++;
  #endif
      ALLOC(ush, tab_prefix1, 1L<<(BITS-1));
  #endif
  
 +#ifdef SIGPIPE
      exiting_signal = quiet ? SIGPIPE : 0;
 +#else
 +    exiting_signal = 0;
 +#endif
      install_signal_handlers ();
  
      /* And get to work */
@@@ -859,25 -856,29 +865,29 @@@ local void treat_file(iname
  
      if (!to_stdout)
        {
-         sigset_t oldset;
-         int unlink_errno;
  
          copy_stat (&istat);
          if (close (ofd) != 0)
            write_error ();
  
-         sigprocmask (SIG_BLOCK, &caught_signals, &oldset);
-         remove_ofname_fd = -1;
-         unlink_errno = xunlink (ifname) == 0 ? 0 : errno;
-         sigprocmask (SIG_SETMASK, &oldset, NULL);
-         if (unlink_errno)
+         if (!keep)
            {
-             WARN ((stderr, "%s: ", program_name));
-             if (!quiet)
+             sigset_t oldset;
+             int unlink_errno;
+             sigprocmask (SIG_BLOCK, &caught_signals, &oldset);
+             remove_ofname_fd = -1;
+             unlink_errno = xunlink (ifname) == 0 ? 0 : errno;
+             sigprocmask (SIG_SETMASK, &oldset, NULL);
+             if (unlink_errno)
                {
-                 errno = unlink_errno;
-                 perror (ifname);
+                 WARN ((stderr, "%s: ", program_name));
+                 if (!quiet)
+                   {
+                     errno = unlink_errno;
+                     perror (ifname);
+                   }
                }
            }
        }
diff --combined gzip.h
index 711ff662a674ee1d292e0566265de7576d3dde5d,648073eee4b3106513c4102dddfd8de02e99ca1a..70ccaa93200f16646a263990f0e5d75868fa0b53
--- 1/gzip.h
--- 2/gzip.h
+++ b/gzip.h
@@@ -1,6 -1,6 +1,6 @@@
  /* gzip.h -- common declarations for all gzip modules
  
-    Copyright (C) 1997-1999, 2001, 2006-2007, 2009-2012 Free Software
+    Copyright (C) 1997-1999, 2001, 2006-2007, 2009-2013 Free Software
     Foundation, Inc.
  
     Copyright (C) 1992-1993 Jean-loup Gailly.
@@@ -140,7 -140,6 +140,7 @@@ EXTERN(uch, window);         /* Slidin
  extern unsigned insize; /* valid bytes in inbuf */
  extern unsigned inptr;  /* index of next byte to be processed in inbuf */
  extern unsigned outcnt; /* bytes in output buffer */
 +extern int rsync;  /* deflate into rsyncable chunks */
  
  extern off_t bytes_in;   /* number of input bytes */
  extern off_t bytes_out;  /* number of output bytes */
@@@ -322,6 -321,3 +322,3 @@@ extern void fprint_off    (FILE *, off_
  
          /* in inflate.c */
  extern int inflate (void);
-         /* in yesno.c */
- extern int yesno (void);
diff --combined zdiff.1
index 3b0ace58e1b7ef13812e574f61c0aeef05afa237,0c826c3ffeaee9fb6dc42c3072c02a62119c6465..d1b12358d11cb56b26aa56b68b4d2b0debc17706
+++ b/zdiff.1
@@@ -10,7 -10,6 +10,7 @@@ zcmp, zdiff \- compare compressed file
  [ diff_options ] file1
  [ file2 ]
  .SH DESCRIPTION
 +.P
  .I  Zcmp
  and
  .I zdiff
@@@ -24,14 -23,15 +24,15 @@@ All options specified are passed direct
  .I cmp
  or
  .IR diff "."
- If only one file is specified, then it is compared to a file with the same name
- without the
- .I ".gz"
- extension. If two files are specified, then they are uncompressed if necessary
and fed to
+ If only
+ .I file1
+ is specified, it is compared to the uncompressed contents of
+ .IR file1 ".gz."
If two files are specified, their contents (uncompressed if necessary) are fed to
  .I cmp
  or
  .IR diff "."
+ The input files are not modified.
  The exit status from
  .I cmp
  or
@@@ -44,4 -44,5 +45,5 @@@ Messages from th
  .I cmp
  or
  .I diff
- programs refer to temporary filenames instead of those specified.
+ programs may refer to file names such as "\-" instead of to the file
+ names specified.