- if (fn_list) { // the input is SAM
- tamFile fp;
- bam1_t *b;
- int ret;
- bam_plbuf_t *buf = bam_plbuf_init(pileup_func, d);
- bam_plbuf_set_mask(buf, d->mask);
- d->h = sam_header_read2(fn_list);
- if (fn_pos) d->hash = load_pos(fn_pos, d->h);
- fp = sam_open(argv[optind]);
- b = (bam1_t*)calloc(1, sizeof(bam1_t));
- while ((ret = sam_read1(fp, d->h, b)) >= 0)
- bam_plbuf_push(b, buf);
- bam_plbuf_push(0, buf);
- bam_plbuf_destroy(buf);
- bam_destroy1(b);
- sam_close(fp);
- } else { // the input is BAM
- bamFile fp;
- fp = (strcmp(argv[optind], "-") == 0)? bam_dopen(fileno(stdin), "r") : bam_open(argv[optind], "r");
- d->h = bam_header_read(fp);
- if (d->h == 0) {
+ {
+ samfile_t *fp;
+ fp = fn_list? samopen(argv[optind], "r", fn_list) : samopen(argv[optind], "rb", 0);
+ if (fp->header == 0) {