Synced back with upstream.
See https://sourceforge.net/p/staden/code/HEAD/tree/io_lib/trunk/.

Relevant SVN commit messages follow. Sorry they're folded into one
here, but for now SVN is the master for the CRAM implementation.

------------------------------------------------------------------------
r3357 | jkbonfield | 2013-05-30 10:13:55 +0100 (Thu, 30 May 2013) | 5
lines
Changed paths:
   M /io_lib/trunk/io_lib/cram_codecs.c
   M /io_lib/trunk/io_lib/cram_decode.c
   M /io_lib/trunk/io_lib/cram_stats.c

Changed to using BETA encoding for alphabets with more than 200
symbols. These are typically slower using HUFFMAN and on the large
alphabets it's typically just as efficient to use BETA encoding (plus
the overhead of writing the HUFFMAN table is significant).

------------------------------------------------------------------------
r3356 | jkbonfield | 2013-05-29 17:10:42 +0100 (Wed, 29 May 2013) | 2
lines
Changed paths:
   M /io_lib/trunk/io_lib/cram_encode.c
   M /io_lib/trunk/progs/scramble.c

Improved support for sequence "*" and added a test for it.

------------------------------------------------------------------------
r3354 | jkbonfield | 2013-05-29 15:20:13 +0100 (Wed, 29 May 2013) | 3
lines
Changed paths:
   M /io_lib/trunk/io_lib/cram_decode.c
   M /io_lib/trunk/io_lib/cram_io.c
   M /io_lib/trunk/io_lib/cram_io.h
   M /io_lib/trunk/io_lib/scram.c

Removed a few memory leaks and adding more rigorous freeing upon
receiving errors.

------------------------------------------------------------------------
r3352 | jkbonfield | 2013-05-29 15:17:58 +0100 (Wed, 29 May 2013) | 2
lines
Changed paths:
   M /io_lib/trunk/io_lib/sam_header.c

Fix memory overflow during adding PG lines.

------------------------------------------------------------------------
r3351 | jkbonfield | 2013-05-29 15:17:35 +0100 (Wed, 29 May 2013) | 2
lines
Changed paths:
   M /io_lib/trunk/progs/scram_merge.c

Extra tidying up on exit to free more memory.

------------------------------------------------------------------------
r3346 | jkbonfield | 2013-05-24 15:03:33 +0100 (Fri, 24 May 2013) | 9
lines
Changed paths:
   M /io_lib/trunk/io_lib/cram_io.c
   M /io_lib/trunk/io_lib/sam_header.c
   M /io_lib/trunk/io_lib/scram.c
   M /io_lib/trunk/progs/scramble.c

Improved support for file type detection. Now that BAM/SAM uses stdio
we use getc/ungetc to query the first character, allowing file type
detection on stdin.

This means we can pipe in cram without needing -I cram in scramble.

Also added a "rs" and "ws" modes for explicit reading and writing of
SAM, in addition to the previous "r","w" ones.

------------------------------------------------------------------------
r3345 | jkbonfield | 2013-05-24 15:01:47 +0100 (Fri, 24 May 2013) | 3
lines
Changed paths:
   M /io_lib/trunk/io_lib/bam.c
   M /io_lib/trunk/io_lib/bam.h

Switched BAM/SAM code to using fread/fwrite instead of read/write.
This is to permit a unified I/O layer for CRAM too.