From f8e10b31a758407d9a50f35a6716cf09c96cde67 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 17 Apr 2012 08:17:34 -0300 Subject: [PATCH] genex: generate PDF by default; new option -P to generate Postscript --- genex/genex.c | 16 +++++++++++----- genex/pdf.c | 15 +++++++-------- genex/pdf.h | 2 +- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/genex/genex.c b/genex/genex.c index 9649ace..e23b739 100644 --- a/genex/genex.c +++ b/genex/genex.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "comp.h" #include "libs.h" @@ -22,11 +23,13 @@ static void usage(const char *name) { fprintf(stderr, -"usage: %s [-d] [-L libdir ...] [-l lib ...] hierarchy [descriptions ...]\n\n" +"usage: %s [-d] [-P] [-L libdir ...] [-l lib ...] hierarchy\n" +" %*s [descriptions ...]\n\n" " -d dump the tree instead of generating a PDF\n" " -L libdir search all libraries in the specified directory\n" " -l lib search the specified component library\n" - , name); +" -P generate Postscript instead of PDF (mainly for debugging)\n" + , name, (int) strlen(name), ""); exit(1); } @@ -35,10 +38,10 @@ int main(int argc, char **argv) { FILE *file; int c; - int dump = 0; + int dump = 0, postscript = 0; char **arg; - while ((c = getopt(argc, argv, "dL:l:")) != EOF) + while ((c = getopt(argc, argv, "dL:l:P")) != EOF) switch (c) { case 'd': dump = 1; @@ -49,6 +52,9 @@ int main(int argc, char **argv) case 'l': add_lib(optarg); break; + case 'P': + postscript = 1; + break; default: usage(*argv); } @@ -82,6 +88,6 @@ int main(int argc, char **argv) if (dump) dump_tree(); else - make_pdf(); + make_pdf(!postscript); return 0; } diff --git a/genex/pdf.c b/genex/pdf.c index 17f3ba5..55b7d5c 100644 --- a/genex/pdf.c +++ b/genex/pdf.c @@ -211,7 +211,7 @@ static void convert_tree(const struct node *node, FILE *out) } -void make_pdf(void) +void make_pdf(int pdf) { FILE *out; int res; @@ -220,13 +220,12 @@ void make_pdf(void) format = landscape; else format = portrait; -#if 0 - out = popen( - "gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=- -f -", - "w"); -#else - out = popen("cat", "w"); -#endif + if (pdf) + out = popen( + "gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=- " + "-f -", "w"); + else + out = popen("cat", "w"); if (!out) { perror("gs"); exit(1); diff --git a/genex/pdf.h b/genex/pdf.h index 7ab058e..0a19830 100644 --- a/genex/pdf.h +++ b/genex/pdf.h @@ -12,6 +12,6 @@ #ifndef PDF_H #define PDF_H -void make_pdf(void); +void make_pdf(int pdf); #endif /* !PDF_H */