diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2020-04-26 20:57:20 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2020-04-26 20:57:20 +0300 |
commit | 563d555bc14424066973a4dbc92123d308344a49 (patch) | |
tree | e6cccc0b77953b97e075f6fed22937bdf8339035 /src/cmdline.opt | |
parent | 31a028f8992e6b48eb72ea8028b6248a67291bde (diff) | |
download | wydawca-563d555bc14424066973a4dbc92123d308344a49.tar.gz wydawca-563d555bc14424066973a4dbc92123d308344a49.tar.bz2 |
Support both new and legacy usage of -d
Diffstat (limited to 'src/cmdline.opt')
-rw-r--r-- | src/cmdline.opt | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/cmdline.opt b/src/cmdline.opt index a23335d..e66564f 100644 --- a/src/cmdline.opt +++ b/src/cmdline.opt @@ -174,10 +174,39 @@ END GROUP(Debugging) -OPTION(debug,d,[<LEVEL>], +OPTION(debug,d,[<[LEVEL]>], [<set debugging level>]) BEGIN - wy_debug_level = atoi(optarg); + if (!optarg) { + wy_debug_level++; + } else { + char *p; + unsigned long n = strtoul(optarg, &p, 10); + if (*p != 0) { + /* Try to detect legacy usage */ + if (p == optarg && *p == 'd') { + n = 1; + while (*p && *p == 'd') { + n++; + p++; + } + if (*p) { + wy_log(LOG_CRIT, _("--debug: not a valid number: %s"), + optarg); + exit(EX_USAGE); + } + } else { + wy_log(LOG_CRIT, _("--debug: not a valid number: %s"), optarg); + exit(EX_USAGE); + } + } + if (n < INT_MAX) + wy_debug_level = n; + else { + wy_log(LOG_CRIT, _("--debug: number out of range: %s"), optarg); + exit(EX_USAGE); + } + } END OPTION(dump-grammar-trace,,, |