1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-26 10:12:49 +02:00

genex/pdf.c: only use pipe, not stdout in parallel

This produced no end of synchronization issues.
This commit is contained in:
Werner Almesberger 2012-04-17 07:51:09 -03:00
parent 5a8606b118
commit a553d5896c

View File

@ -12,6 +12,7 @@
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#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");
}
}