Skip to content

Commit

Permalink
Merge pull request #707 from kyleabeauchamp/puts_kab
Browse files Browse the repository at this point in the history
Fix EOF issue, part 3
  • Loading branch information
AndreasHeger authored Jul 26, 2018
2 parents c3c98a1 + f548884 commit bca66ee
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 10 deletions.
6 changes: 6 additions & 0 deletions bcftools/bcftools.pysam.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ void bcftools_unset_stdout(void)
bcftools_stdout_fileno = STDOUT_FILENO;
}

int bcftools_puts(const char *s)
{
if (fputs(s, bcftools_stdout) == EOF) return EOF;
return putc('\n', bcftools_stdout);
}

void bcftools_set_optind(int val)
{
// setting this in cython via
Expand Down
2 changes: 2 additions & 0 deletions bcftools/bcftools.pysam.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ void bcftools_unset_stderr(void);
*/
void bcftools_unset_stdout(void);

int bcftools_puts(const char *s);

int bcftools_dispatch(int argc, char *argv[]);

void bcftools_set_optind(int);
Expand Down
4 changes: 2 additions & 2 deletions bcftools/tabix.c.pysam.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int main_tabix(int argc, char *argv[])
BGZF *fp;
s.l = s.m = 0; s.s = 0;
fp = bgzf_open(argv[optind], "r");
while (bgzf_getline(fp, '\n', &s) >= 0) fputs(s.s, bcftools_stdout) & fputc('\n', bcftools_stdout);
while (bgzf_getline(fp, '\n', &s) >= 0) bcftools_puts(s.s);
bgzf_close(fp);
free(s.s);
} else if (optind + 2 > argc) { // create index
Expand Down Expand Up @@ -122,7 +122,7 @@ int main_tabix(int argc, char *argv[])
for (i = optind + 1; i < argc; ++i) {
hts_itr_t *itr;
if ((itr = tbx_itr_querys(tbx, argv[i])) == 0) continue;
while (tbx_bgzf_itr_next(fp, tbx, itr, &s) >= 0) fputs(s.s, bcftools_stdout) & fputc('\n', bcftools_stdout);
while (tbx_bgzf_itr_next(fp, tbx, itr, &s) >= 0) bcftools_puts(s.s);
tbx_itr_destroy(itr);
}
free(s.s);
Expand Down
4 changes: 1 addition & 3 deletions devtools/import.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ def _update_pysam_files(cf, destdir):
lines = re.sub("stderr", "{}_stderr".format(basename), lines)
lines = re.sub("stdout", "{}_stdout".format(basename), lines)
lines = re.sub(" printf\(", " fprintf({}_stdout, ".format(basename), lines)
lines = re.sub("([^kf])puts\(([^)]+)\)",
r"\1fputs(\2, {}_stdout) & fputc('\\n', {}_stdout)".format(basename, basename),
lines)
lines = re.sub("([^kf])puts\(", r"\1{}_puts(".format(basename), lines)
lines = re.sub("putchar\(([^)]+)\)",
r"fputc(\1, {}_stdout)".format(basename), lines)

Expand Down
6 changes: 6 additions & 0 deletions import/pysam.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ void @pysam@_unset_stdout(void)
@pysam@_stdout_fileno = STDOUT_FILENO;
}

int @pysam@_puts(const char *s)
{
if (fputs(s, @pysam@_stdout) == EOF) return EOF;
return putc('\n', @pysam@_stdout);
}

void @pysam@_set_optind(int val)
{
// setting this in cython via
Expand Down
2 changes: 2 additions & 0 deletions import/pysam.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ void @pysam@_unset_stderr(void);
*/
void @pysam@_unset_stdout(void);

int @pysam@_puts(const char *s);

int @pysam@_dispatch(int argc, char *argv[]);

void @pysam@_set_optind(int);
Expand Down
2 changes: 1 addition & 1 deletion samtools/bam.c.pysam.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int bam_view1(const bam_header_t *header, const bam1_t *b)
char *s = bam_format1(header, b);
int ret = -1;
if (!s) return -1;
if (fputs(s, samtools_stdout) & fputc('\n', samtools_stdout) != EOF) ret = 0;
if (samtools_puts(s) != EOF) ret = 0;
free(s);
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion samtools/bedcov.c.pysam.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ int main_bedcov(int argc, char *argv[])
kputc('\t', &str);
kputl(cnt[i], &str);
}
fputs(str.s, samtools_stdout) & fputc('\n', samtools_stdout);
samtools_puts(str.s);
bam_mplp_destroy(mplp);
continue;

Expand Down
6 changes: 3 additions & 3 deletions samtools/misc/ace2sam.c.pysam.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ int samtools_ace2sam_main(int argc, char *argv[])
if (dret != '\n') ks_getuntil(ks, '\n', &s, &dret);
ks_getuntil(ks, '\n', &s, &dret); // skip the empty line
if (write_cns) {
if (t[4].l) fputs(t[4].s, samtools_stdout) & fputc('\n', samtools_stdout);
if (t[4].l) samtools_puts(t[4].s);
t[4].l = 0;
}
} else if (strcmp(s.s, "AF") == 0) { // padded read position
int reversed, neg, pos;
if (t[0].l == 0) fatal("come to 'AF' before reading 'CO'");
if (write_cns) {
if (t[4].l) fputs(t[4].s, samtools_stdout) & fputc('\n', samtools_stdout);
if (t[4].l) samtools_puts(t[4].s);
t[4].l = 0;
}
ks_getuntil(ks, 0, &s, &dret); // read name
Expand Down Expand Up @@ -244,7 +244,7 @@ int samtools_ace2sam_main(int argc, char *argv[])
kputs("\t*\t0\t0\t", &t[4]); // empty MRNM, MPOS and TLEN
kputsn(t[3].s, t[3].l, &t[4]); // unpadded SEQ
kputs("\t*", &t[4]); // QUAL
fputs(t[4].s, samtools_stdout) & fputc('\n', samtools_stdout); // print to samtools_stdout
samtools_puts(t[4].s); // print to samtools_stdout
++af_i;
} else if (dret != '\n') ks_getuntil(ks, '\n', &s, &dret);
}
Expand Down
6 changes: 6 additions & 0 deletions samtools/samtools.pysam.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ void samtools_unset_stdout(void)
samtools_stdout_fileno = STDOUT_FILENO;
}

int samtools_puts(const char *s)
{
if (fputs(s, samtools_stdout) == EOF) return EOF;
return putc('\n', samtools_stdout);
}

void samtools_set_optind(int val)
{
// setting this in cython via
Expand Down
2 changes: 2 additions & 0 deletions samtools/samtools.pysam.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ void samtools_unset_stderr(void);
*/
void samtools_unset_stdout(void);

int samtools_puts(const char *s);

int samtools_dispatch(int argc, char *argv[]);

void samtools_set_optind(int);
Expand Down

0 comments on commit bca66ee

Please sign in to comment.