diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-09-04 23:39:46 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-09-04 23:39:46 +0200 |
commit | 8ed2a34facea5b2992055d811aeb25aa9762012c (patch) | |
tree | a42b35cf7edb73bdeffe97339b5b4544803d0389 /src | |
parent | dd654fb29f1b0ca2590ac697ff758d2645474e7e (diff) |
Add -s
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 23 |
1 files changed, 20 insertions, 3 deletions
@@ -10,6 +10,7 @@ #include <stdint.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <unistd.h> #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) |