Add optional bsdcat tool.

bsdcat works like zcat, bzcat, xzcat and similar tools, but auto-detects
source data format, which can also vary between multiple input files.
Use getopt() instead of getopt_long() in bsdcat for compatibility reasons.
Change bsdcat behavior to process as many files as possible.

Change is to match "cat" behavior of printing any errors (e.g. "unable to
open file") and continue to the next file instead of exiting on first error
encountered.
Minor cleanup of a redundant check in bsdcat cli parsing.
Refactor archive_read_extract

The initialisation of the archive_write_disk object and the call to
archive_write_disk_set_standard_lookup are only needed in the
archive_read_extract function, not in archive_read_extract2 or other related
functions. Therefore this initialisation is merged into archive_read_extract.

The static function get_extract is renamed to __archive_read_get_extract so that
is can be made non-static. The struct extract is renamed to archive_read_extract
so that it can be placed in a header file without risk of namespace clashes.
Both these declarations are then moved to the archive_read_private.h header.
This preparation is necessary so that the contents of archive_read_extract.c can
be split between two source files.

Signed-off-by: Paul Barker <paul@paulbarker.me.uk>
Split archive_read_extract2 from archive_read_extract

The function archive_read_extract requires a call to
archive_write_disk_set_standard_lookup but the functions archive_read_extract2
and archive_read_extract_set_progress_callback do not. Therefore, the latter
pair of functions, the internal function __archive_read_get_extract and the
static function copy_data are moved out of archive_read_extract.c into the new
file archive_read_extract2.c.

This ensures that when statically linking, the standard user and group lookup
functions will not be linked into a program unless they are really needed.

Signed-off-by: Paul Barker <paul@paulbarker.me.uk>
Merge pull request #71 from betafive/pbarker/extract

Split archive_read_extract.c into two source files
Prevent unnecessary linking against deflate code

In _archive_write_disk_free, the call to deflateEnd was compiled if HAVE_ZLIB_H
was defined. However, all other calls to deflate functions were only compiled
if __APPLE__, UF_COMPRESSED and HAVE_SYS_XATTR_H were also defined. So if one of
these macros was not defined but HAVE_ZLIB_H was defined, the call the
deflateEnd would be unnecessary as deflateInit could never have been called.

In statically linked applications which don't use deflate functions elsewhere
this was causing unnecessary linking of the deflate code from zlib, adding at
least 20k of object code to the final executable size.

This patch fixes the above issue by surrounding the call to deflateEnd with the
same conditional compilation checks as surround the call to deflateInit.

Signed-off-by: Paul Barker <paul@paulbarker.me.uk>
Fix intermittent segfault when reading zip files

When looking up the compression name for a zip file the index variable was being
incremented too soon. Thus element zero ("uncompressed") was never checked and
reads could be made past the end of the array. This was causing intermittent
segfaults in the call to sprintf in zip_read_local_file_header.

Signed-off-by: Paul Barker <paul@paulbarker.me.uk>
Use snprintf to print to zip->format_name

zip->format_name is a fixed size character array so ensure that the number of
characters written to the array is appropriately limited.

Signed-off-by: Paul Barker <paul@paulbarker.me.uk>
Minor style correction in bsdcat.
Merge pull request #70 from mk-fg/add_bsdcat_tool

Add optional bsdcat tool
Merge pull request #72 from betafive/pbarker/fix-zip

Fix intermittent segfault when reading zip files
Merge pull request #73 from betafive/pbarker/deflate

Prevent unnecessary linking against deflate code