diff --git a/sch2fig/fig.c b/sch2fig/fig.c index b45c9f6..90defc8 100644 --- a/sch2fig/fig.c +++ b/sch2fig/fig.c @@ -406,7 +406,7 @@ void fig_text(int x, int y, const char *s, unsigned size, /* ----- FIG file header --------------------------------------------------- */ -void fig_init(void) +static void fig_header(void) { printf("#FIG 3.2\n"); printf("Landscape\n"); @@ -418,3 +418,24 @@ void fig_init(void) printf("-2\n"); printf("1200 2\n"); } + + +void fig_init(const char *template) +{ + FILE *file; + char buf[1000]; + + if (!template) { + fig_header(); + return; + } + + file = fopen(template, "r"); + if (!file) { + perror(template); + exit(1); + } + while (fgets(buf, sizeof(buf), file)) + printf("%s", buf); + fclose(file); +} diff --git a/sch2fig/fig.h b/sch2fig/fig.h index 646a72b..c90f27f 100644 --- a/sch2fig/fig.h +++ b/sch2fig/fig.h @@ -53,6 +53,6 @@ void fig_text(int x, int y, const char *s, unsigned size, /* inititalization */ -void fig_init(void); +void fig_init(const char *template); #endif /* !FIG_H */ diff --git a/sch2fig/main.c b/sch2fig/main.c index 310eaf4..49c7b2c 100644 --- a/sch2fig/main.c +++ b/sch2fig/main.c @@ -13,6 +13,7 @@ #include #include +#include #include #include "fig.h" @@ -57,20 +58,32 @@ static void read_file(const char *name, void *ctx, static void usage(const char *name) { - fprintf(stderr, "usage: %s [file.lib ...] file.sch\n", name); + fprintf(stderr, + "usage: %s [-t template.fig] [file.lib ...] file.sch\n", name); exit(1); } int main(int argc, char **argv) { + const char *template = NULL; + char c; int arg; - if (argc < 2) + while ((c = getopt(argc, argv, "t:")) != EOF) + switch (c) { + case 't': + template = optarg; + break; + default: + usage(*argv); + } + + if (argc - optind < 1) usage(*argv); - fig_init(); - for (arg = 1; arg != argc; arg++) { + fig_init(template); + for (arg = optind; arg != argc; arg++) { if (arg == argc - 1) { struct sch_ctx ctx;