Raise error if give @HD SO:coordinate to 'samtools fixmate'

The (minimal) documentation does tell you 'samtools fixmate' requires query name
sorted reads (in fact grouped by query name is enough), but doesn't actually raise
an error if given coordinate sorted reads (it just silently fails to fix them).

This change raises an explicit error is the @HD line contains SO:coordinate
Catch overflow in n_cigar and give an explicit error.

Due to the use of an unsigned 16bit integer, BAM
files can only hold reads with up to 65535 CIGAR
operators. SAM does not have this limit, but the
samtools implementation (reasonably) also has the
same 16bit limit.

Prior to this fix a very long CIGAR read would
give a confusing 'unmatched CIGAR operation'
warning and then abort with a core dump.
Don't set text-is-cached flag if reading headers encountered EOF

Only set is_first (i.e., some SAM record text has already been read
in) if a column of the following SAM record has actually been pre-read.
This will not be the case if there are no records at all, only headers.

Fixes #113 (hattip @kmsquire).
Merge pull request #20, fixmate aborts on SO:coordinate
Fix buffer overflow
Reenable idxstats and convert to htslib

Reenable idxstats code by using new functions added to htslib.
Convert API for index and idxstats to htslib.

Signed-off-by: Martin O. Pollard <mp15@sanger.ac.uk>
Remove double fclose()

This fixes issue #47 for the legacy non-HTSlib code branch.
Silence -Wstrict-prototypes warnings in main header files

Fixes issue #45 for the legacy non-HTSlib code branch.
mpileup: Long options

[Add long options as per eb2b30907ada8dc77b2d373dcf36ea6b8b9d64d2, but
without removing existing -a/-D/-M/-S/-V/--ff/--rf options or creating
new -1/-2 short options --- @jmarshall]
Create a print_usage() function for usage printing

The source code text is unchanged, modulo whitespace and s/./->/g.
Reformat usage to (mostly) fit in 80 columns

This uses the typical GNU-style spacing (e.g., two leading spaces on
option lines) and removes brackets around <FILE> etc, as the capitals
used distinguishes them without using up characters.
Minor rewording of usage to fit in 80 columns
Deprecate `-S`, `-D`, `-V` in favour of `-t DP,DV,SP`

- Deprecate `-S`, `-D`, `-V` by hiding in short help.
- Options still exist, but warning to stderr is printed when used.
- Updated man for (just) these options.
Fix long option has_arg inconsistencies
some progress for mpileup documentation

- add missing options to the command line summary
- add missing and long options to the man page (#127)
- option `-a` removed as it implemented the default and was hidden anyway (#127)
- change to pileup output description in response to (#134)
- pileup command long since deprecated in favour of mpileup
- still needs work
Use getopt.h's descriptive constants in long options array

Also fix --illumina1.3+ short option equivalent.
Remove mpileup -M option, which has never been implemented

(Fixes #132.)
Removes '(forces -S)' from samtools view -T|t usage
Updates documentation for `samtools view`

Adds all missing options to samtools man page under the
`samtools view` section.

Adds all missing options to `samtools view` usage and updates
notes to better reflect reality.

Closes #155. Although we should definitely split the samtools
man page into sub-pages for each command.
Improves performance of `samtools merge` (slightly)

Moves call to pretty_header so that it is done once at the end rather than
once for each input file. As a result, 'trans_tbl_init' no longer returns
prettified headers. This results in a performance improvement when merging
many files, although performance still becomes very poor when merging on
the order of hundreds of files.