1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-04 22:58:26 +02:00

genex: add progress reporting, and option -q to turn it off

This commit is contained in:
Werner Almesberger 2012-04-18 18:44:22 -03:00
parent 7d97a749f4
commit e804e02abf
2 changed files with 35 additions and 2 deletions

View File

@ -18,12 +18,16 @@
#include "comp.h" #include "comp.h"
#include "libs.h" #include "libs.h"
#include "pdf.h" #include "pdf.h"
#include "genex.h"
int quiet = 0;
static void usage(const char *name) static void usage(const char *name)
{ {
fprintf(stderr, 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" " %*s [descriptions ...]\n\n"
" -d dump the tree instead of generating a PDF\n" " -d dump the tree instead of generating a PDF\n"
" -D dump all the canonical component names (without aliases)\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" " -l lib search the specified component library\n"
" -p use portrait orientation; default: landscape\n" " -p use portrait orientation; default: landscape\n"
" -P generate Postscript instead of PDF (mainly for debugging)\n" " -P generate Postscript instead of PDF (mainly for debugging)\n"
" -q don't show progress\n"
, name, (int) strlen(name), ""); , name, (int) strlen(name), "");
exit(1); 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; int opt_dump_tree = 0, opt_dump_comp = 0, postscript = 0, portrait = 0;
char **arg; char **arg;
while ((c = getopt(argc, argv, "dDL:l:Pp")) != EOF) while ((c = getopt(argc, argv, "dDL:l:Ppq")) != EOF)
switch (c) { switch (c) {
case 'd': case 'd':
opt_dump_tree = 1; opt_dump_tree = 1;
@ -63,6 +68,9 @@ int main(int argc, char **argv)
case 'p': case 'p':
portrait = 1; portrait = 1;
break; break;
case 'q':
quiet = 1;
break;
default: default:
usage(*argv); usage(*argv);
} }

View File

@ -14,6 +14,7 @@
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include "genex.h"
#include "comp.h" #include "comp.h"
#include "pdf.h" #include "pdf.h"
@ -51,6 +52,8 @@ static struct format {
.comment_line_skip = 14, .comment_line_skip = 14,
}, format; }, format;
static int total, done = 0;
static int children(const struct node *node) static int children(const struct node *node)
{ {
@ -180,6 +183,10 @@ static void convert_comp(const struct node *node, FILE *out)
int i, res; int i, res;
for (i = 0; i != node->units; i++) { for (i = 0; i != node->units; i++) {
if (!quiet) {
fprintf(stderr, "\r%u/%u", ++done, total);
fflush(stderr);
}
make_title(out, node, i); make_title(out, node, i);
if (!i && node->comment) if (!i && node->comment)
print_comment(out, 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) void make_pdf(int pdf, int use_portrait)
{ {
FILE *out; FILE *out;
@ -238,7 +260,10 @@ void make_pdf(int pdf, int use_portrait)
exit(1); exit(1);
} }
fprintf(out, "%%!PS\n%s\n", format.file_setup); fprintf(out, "%%!PS\n%s\n", format.file_setup);
total = count_tree(tree);
convert_tree(tree, out); convert_tree(tree, out);
if (!quiet)
fprintf(stderr, "\rFinishing\n");
res = pclose(out); res = pclose(out);
if (res < 0) { if (res < 0) {
perror("pclose"); perror("pclose");