From 77ac11913647af2f8db36a01c3db3d3711c75e84 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 2 Aug 2016 09:07:00 -0300 Subject: [PATCH] sch2fig/: new option -C file to "cat" a file (also works with git) This provides quick access to the git-file mechanism. --- sch2fig/file.c | 7 +++++++ sch2fig/file.h | 2 +- sch2fig/main.c | 19 ++++++++++++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/sch2fig/file.c b/sch2fig/file.c index b1585ad..de76a58 100644 --- a/sch2fig/file.c +++ b/sch2fig/file.c @@ -21,6 +21,13 @@ #include "file.h" +bool file_cat(void *user, const char *line) +{ + printf("%s", line); + return 1; +} + + static void read_from_file(FILE *file, bool (*parse)(void *user, const char *line), void *user) { diff --git a/sch2fig/file.h b/sch2fig/file.h index fabc2e4..a6cc170 100644 --- a/sch2fig/file.h +++ b/sch2fig/file.h @@ -15,7 +15,7 @@ #include - +bool file_cat(void *user, const char *line); void file_read(const char *name, bool (*parse)(void *user, const char *line), void *user); diff --git a/sch2fig/main.c b/sch2fig/main.c index 6ffee2a..5920a9b 100644 --- a/sch2fig/main.c +++ b/sch2fig/main.c @@ -22,6 +22,7 @@ #include "cro.h" #include "diff.h" #include "gfx.h" +#include "file.h" #include "lib.h" #include "sch.h" #include "main.h" @@ -41,7 +42,8 @@ static struct gfx_ops const *ops_list[] = { void usage(const char *name) { fprintf(stderr, -"usage: %s [-r] [-v ...] [file.lib ...] file.sch -- driver_spec\n\n" +"usage: %s [-r] [-v ...] [file.lib ...] file.sch -- driver_spec\n" +" %s [-v ...] -C file\n\n" " FIG driver spec:\n" " fig [-t template.fig] [var=value ...]\n" " Cairo PNG driver spec:\n" @@ -50,7 +52,7 @@ void usage(const char *name) " pdf [-o output.pdf] [-s scale]\n" " Diff driver spec:\n" " diff [-o output.pdf] [-s scale] [file.lib ...] file.sch\n" - , name); + , name, name); exit(1); } @@ -60,6 +62,7 @@ int main(int argc, char *const *argv) struct lib lib; struct sch_ctx sch_ctx; bool recurse = 0; + const char *cat = NULL; char c; int arg, dashdash; int gfx_argc; @@ -70,7 +73,7 @@ int main(int argc, char *const *argv) if (!strcmp(argv[dashdash], "--")) break; - while ((c = getopt(dashdash, argv, "rv")) != EOF) + while ((c = getopt(dashdash, argv, "rvC:")) != EOF) switch (c) { case 'r': recurse = 1; @@ -78,10 +81,20 @@ int main(int argc, char *const *argv) case 'v': verbose++; break; + case 'C': + cat = optarg; + break; default: usage(*argv); } + if (cat) { + if (argc != optind) + usage(*argv); + file_read(cat, file_cat, NULL); + return 0; + } + if (dashdash - optind < 1) usage(*argv);