separated and improved SAM printing code

This is for the PE mode. The routines may also be useful for bwa-sw, but
probably I won't change the old code.