diff --git a/genex/pdf.c b/genex/pdf.c index e8a7b69..0600a39 100644 --- a/genex/pdf.c +++ b/genex/pdf.c @@ -12,6 +12,7 @@ #define _GNU_SOURCE #include #include +#include #include "comp.h" #include "pdf.h" @@ -95,7 +96,6 @@ static void make_title(FILE *file, const struct node *node, int unit) fprintf(file, " show\n"); fprintf(file, "grestore\n"); - fflush(file); } @@ -119,7 +119,35 @@ static void print_comment(FILE *file, const struct line *comment) fprintf(file, " show\n"); } fprintf(file, "grestore\n"); - fflush(file); +} + + +static void cat(FILE *out, const char *name) +{ + FILE *in; + char buf[10000]; /* pick any good size */ + size_t got, wrote; + + in = fopen(name, "r"); + if (!in) { + perror(name); + exit(1); + } + while (1) { + got = fread(buf, 1, sizeof(buf), in); + if (!got) + break; + wrote = fwrite(buf, 1, got, out); + if (wrote != got) { + perror("fwrite"); + exit(1); + } + } + if (ferror(in)) { + perror(name); + exit(1); + } + fclose(in); } @@ -129,7 +157,7 @@ static void convert_comp(const struct node *node, FILE *out) int i, res; for (i = 0; i != node->units; i++) { - make_title(stdout, node, i); + make_title(out, node, i); if (!i && node->comment) print_comment(out, node->comment); if (asprintf(&tmp, "./sym2xps '%s' '%s' %d '%s' '%s'", @@ -146,8 +174,7 @@ static void convert_comp(const struct node *node, FILE *out) fprintf(stderr, "sym2xps returned %d\n", res); exit(1); } - fflush(out); - system("cat tmp.ps"); + cat(out, "tmp.ps"); } }