Added CRAM support to htslib and htscmd samview.
This is just a port over from the samtools io_lib subdirectory and has
all the same nasties and duplication of abstract data types.
Merged with attractivechaos/klib:
- add upstream kvsprintf and rework ksprintf
- add upstream printf attribute checks
- use our kputw (has MIN_INT bug fix)
- keep our extra functions (kputc_, kputsn_, kputl)

Added ks_str and ks_len functions for tidier manipulation of
internals.

Added error checking to all functions that allocate memory and could
potentially fail; ie return EOF or negative values as per stdio
equivalents.
Major overhaul of CRAM code (originally imported from Samtools/htlib
branch, and further back from Staden Package io_lib).

All uses of io_lib's HashTable and dstring_t types have been replaced
by khash and kstring.

Renamed io_lib subdir to cram subdir.

Needs exhaustive testing still, but compiles and can encode to and
from CRAM for one small test file.
Merge branch 'develop' of https://github.com/samtools/htslib into develop

Conflicts:
	Makefile
	hts.c
	htslib/Makefile
	sam.c
	samview.c

Added test/test_view.c as a minimal port from the old htscmd view
(samview.c) file.
Further removal of various unusued portions of Staden io_lib.
Switch from modifying CFLAGS to CPPFLAGS so we can do "make CFLAGS=-g".
Bug fix to handle blank headers in SAM files.
Bug fix to stop sam view from converting 'H' into 'Z' types.
Use strtoul instead of strtol for XX:B:I tags so that integers >2.14
billion work.
Better handling of unknown references.
Bug fix to khash-ification of sam_hdr_add_lines
A bit of a hack to set the header and references up properly for
cram. This is a hack right now as it requires accessing internals of
the fp, but it should be fixed in future by properly supporting
methods to manipulate these fields for all data types rather than just
cram (eg see scram.c in io_lib).
Added some synthetic SAM test data and a test perl script to trial
conversion between SAM, BAM and CRAM. A work in progress.
Bug fix to khashification of process_one_read.

(Our CRAM test files now all pass.)
Added tests/test_view
(io_lib r3438/7)

Improved error reporting and detection for MD5 sums. We report where
the md5 error comes from (which reference slice). We also have better
detection of slices that overhang the end of the reference.

Finally it no longer crashes sometimes after getting reference errors,
now exiting cleanly with exit code 1.
(io_lib r3439)

Added test case for sequences with alignments beyond references. These
are handled by scramble by adding individual base features for the
base calls that are beyond the reference.
(io_lib r3460)

Fixed curl timeout. We meant CONNECTTIMEOUT instead of TIMEOUT. This
was causing long downloads to be terminated early.
(io_lib r3461 minus arithmetic coder & last_name experimental parts)

Optimised the compression levels so -1, -3, and above are more
distinct and use their own specific zlib parameters.

Minor speed up.
(io_lib r3467)

Bug fix for reference handling when fetching via MD5/http.

Firstly the fd->refs->lock mutex has been moved to just before
cram_populate_ref instead of just after, given that this code is not
thread safe (it potentially uses open_path_url+curl in a manner which
shares the curl handle between threads).

Secondly certain thread orderings could cause the reference count to
hit zero and then try to reaccess it again, which triggered a
bug. ref->length is now reset to zero as well as ->seq=NULL as both
are checked.