- idx = ti_index_load(argv[optind]);
- if (idx == 0) {
- bgzf_close(fp);
- fprintf(stderr, "[main] fail to load the index.\n");
- return 1;
- }
+ if ( ti_lazy_index_load(t) )
+ {
+ fprintf(stderr,"[tabix] failed to load the index file.\n");
+ return 1;
+ }
+
+ ti_iter_t iter;
+ const char *s;
+ int len;
+ if ( print_header )
+ {
+ // If requested, print the header lines here
+ iter = ti_query(t, 0, 0, 0);
+ while ((s = ti_read(t, iter, &len)) != 0) {
+ if ( *s != '#' ) break;
+ fputs(s, stdout); fputc('\n', stdout);
+ }
+ ti_iter_destroy(iter);
+ }