From 8ed2a34facea5b2992055d811aeb25aa9762012c Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Wed, 4 Sep 2024 23:39:46 +0200 Subject: Add -s --- src/main.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index d90bb96..56f8ef7 100644 --- a/src/main.c +++ b/src/main.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "lexer.h" @@ -72,13 +73,15 @@ main(int argc, char **argv) interactive = isatty(STDIN_FILENO); int opt; + const char *sflag = NULL; static struct option longopts[] = { {"bool-style", required_argument, 0, 'b'}, + {"string", required_argument, 0, 's'}, {"table-style", required_argument, 0, 't'}, {0}, }; - while ((opt = getopt_long(argc, argv, "b:t:", longopts, NULL)) != -1) { + while ((opt = getopt_long(argc, argv, "b:s:t:", longopts, NULL)) != -1) { switch (opt) { case 'b': if (streq(optarg, "alpha")) @@ -92,6 +95,9 @@ main(int argc, char **argv) goto usage; } break; + case 's': + sflag = optarg; + break; case 't': if (streq(optarg, "ascii")) tflag = TS_ASCII; @@ -106,8 +112,10 @@ main(int argc, char **argv) break; default: usage: - fprintf(stderr, "Usage: %s [-b alpha|binary|symbols] [-t ascii|latex|utf8] [file ...]\n", - argv[0]); + fprintf(stderr, + "Usage: %s [-b alpha|binary|symbols] [-t ascii|latex|utf8] [file ...]\n" + " %s [-b alpha|binary|symbols] [-t ascii|latex|utf8] -s string\n", + argv[0], argv[0]); exit(EXIT_FAILURE); } } @@ -120,7 +128,16 @@ usage: argc -= optind; argv += optind; + if (sflag != NULL && argc != 0) + goto usage; + if (argc == 0) { + if (sflag != NULL && + (yyin = fmemopen((char *)sflag, strlen(sflag), "r")) == NULL) + { + err(1, "fmemopen"); + } + current_file = "-"; for (;;) { if (yyparse() == 0) -- cgit v1.2.3