From efc0cf8039cbff5e0f0d52fd7414c7186129b6ac Mon Sep 17 00:00:00 2001 From: lemon Date: Mon, 5 Jun 2023 09:32:17 +0200 Subject: command line switch for debug options --- main.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'main.c') diff --git a/main.c b/main.c index d56cd50..d91188f 100644 --- a/main.c +++ b/main.c @@ -12,10 +12,11 @@ flushstd(void) ioflush(&bstderr); } +/* parse an argument of the form 'opt=abcd' + * e.g. arg="foo=bar123"; opt="foo"; returns "bar123" */ static const char * optval(const char *arg, const char *opt) { - /* arg="foo=bar123"; opt="foo"; returns "bar123" */ uint n1 = strlen(arg), n2 = strlen(opt); if (n1 < n2+1 || memcmp(arg, opt, n2) != 0 || arg[n2] != '=') return NULL; @@ -41,6 +42,14 @@ optparse(const char **file, const char **targ, char **args) else goto Bad; } else if (!strcmp(arg, "pedantic")) { ccopt.pedant = 1; + } else if (*arg == 'd' && arg[1]) { + /* see common.h§struct option */ + while (*++arg) switch (*arg | 32) { + case 'p': ccopt.dbg.p = 1; break; + case 'a': ccopt.dbg.a = 1; break; + case 'r': ccopt.dbg.r = 1; break; + default: warn(NULL, "-d: invalid debug flag %'c", *arg); + } } else Bad: warn(NULL, "invalid option: %'s", arg-1); } } -- cgit v1.2.3