From e804e02abf598cfb55c0da92f556a7c2f842c501 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 18 Apr 2012 18:44:22 -0300 Subject: [PATCH] genex: add progress reporting, and option -q to turn it off --- genex/genex.c | 12 ++++++++++-- genex/pdf.c | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/genex/genex.c b/genex/genex.c index d4f74ff..c9e4f9e 100644 --- a/genex/genex.c +++ b/genex/genex.c @@ -18,12 +18,16 @@ #include "comp.h" #include "libs.h" #include "pdf.h" +#include "genex.h" + + +int quiet = 0; static void usage(const char *name) { fprintf(stderr, -"usage: %s [-d|-D] [-p] [-P] [-L libdir ...] [-l lib ...] hierarchy\n" +"usage: %s [-d|-D] [-p] [-P] [-q] [-L libdir ...] [-l lib ...] hierarchy\n" " %*s [descriptions ...]\n\n" " -d dump the tree instead of generating a PDF\n" " -D dump all the canonical component names (without aliases)\n" @@ -31,6 +35,7 @@ static void usage(const char *name) " -l lib search the specified component library\n" " -p use portrait orientation; default: landscape\n" " -P generate Postscript instead of PDF (mainly for debugging)\n" +" -q don't show progress\n" , name, (int) strlen(name), ""); exit(1); } @@ -43,7 +48,7 @@ int main(int argc, char **argv) int opt_dump_tree = 0, opt_dump_comp = 0, postscript = 0, portrait = 0; char **arg; - while ((c = getopt(argc, argv, "dDL:l:Pp")) != EOF) + while ((c = getopt(argc, argv, "dDL:l:Ppq")) != EOF) switch (c) { case 'd': opt_dump_tree = 1; @@ -63,6 +68,9 @@ int main(int argc, char **argv) case 'p': portrait = 1; break; + case 'q': + quiet = 1; + break; default: usage(*argv); } diff --git a/genex/pdf.c b/genex/pdf.c index c8ab5b1..ad447cc 100644 --- a/genex/pdf.c +++ b/genex/pdf.c @@ -14,6 +14,7 @@ #include #include +#include "genex.h" #include "comp.h" #include "pdf.h" @@ -51,6 +52,8 @@ static struct format { .comment_line_skip = 14, }, format; +static int total, done = 0; + static int children(const struct node *node) { @@ -180,6 +183,10 @@ static void convert_comp(const struct node *node, FILE *out) int i, res; for (i = 0; i != node->units; i++) { + if (!quiet) { + fprintf(stderr, "\r%u/%u", ++done, total); + fflush(stderr); + } make_title(out, node, i); if (!i && node->comment) print_comment(out, node->comment); @@ -218,6 +225,21 @@ static void convert_tree(const struct node *node, FILE *out) } +static int count_tree(const struct node *node) +{ + int sum = 0; + + while (node) { + if (node->child) + sum += count_tree(node->child); + else + sum += node->units; + node = node->next; + } + return sum; +} + + void make_pdf(int pdf, int use_portrait) { FILE *out; @@ -238,7 +260,10 @@ void make_pdf(int pdf, int use_portrait) exit(1); } fprintf(out, "%%!PS\n%s\n", format.file_setup); + total = count_tree(tree); convert_tree(tree, out); + if (!quiet) + fprintf(stderr, "\rFinishing\n"); res = pclose(out); if (res < 0) { perror("pclose");