asn1: Allow comments and leading ws in opt files

This commit is contained in:
Nicolas Williams
2022-03-17 17:11:35 -05:00
parent f072249d26
commit db0ba731ca
2 changed files with 13 additions and 0 deletions

View File

@@ -330,6 +330,11 @@ to form the names of the files generated.
.It Fl Fl option-file=FILE
Take additional command-line options from
.Ar FILE .
The options file must have one command-line option per-line, but
leading whitespace is ignored, and lines that start with a hash
symbol
.Sq ( # )
are comments and are ignored.
.It Fl Fl original-order
Attempt to preserve the original order of type definition in the
ASN.1 module.

View File

@@ -409,8 +409,16 @@ main(int argc, char **argv)
sz = 2;
while (fgets(buf, sizeof(buf), opt) != NULL) {
size_t buflen, ws;
buf[strcspn(buf, "\n\r")] = '\0';
buflen = strlen(buf);
if ((ws = strspn(buf, " \t")))
memmove(buf, buf + ws, buflen -= ws);
if (buf[0] == '\0' || buf[0] == '#')
continue;
if (len + 1 >= sz) {
arg = realloc(arg, (sz + (sz>>1) + 2) * sizeof(arg[0]));
if (arg == NULL) {