From: Vincent Bernat Date: Sat, 18 Oct 2014 07:03:57 +0000 (+0200) Subject: lldpcli: handle comments in tokenizer X-Git-Tag: 0.7.12~21 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3ea0bccfdd4c1fad302260b87ae240f3e86ee3bd;p=thirdparty%2Flldpd.git lldpcli: handle comments in tokenizer This enables us to also ignore end-of-line comments. Completion is a bit grumpy when done in comments but I doubt anyone would care. --- diff --git a/src/client/lldpcli.c b/src/client/lldpcli.c index ef565c71..8eeac70e 100644 --- a/src/client/lldpcli.c +++ b/src/client/lldpcli.c @@ -494,8 +494,7 @@ main(int argc, char *argv[]) line = strndup(line, len); if (line[len - 1] == '\n') { line[len - 1] = '\0'; - if (line[0] != '#') - parse_and_exec(conn, fmt, line); + parse_and_exec(conn, fmt, line); } free(line); } diff --git a/src/client/tokenizer.c b/src/client/tokenizer.c index e751d729..234091f7 100644 --- a/src/client/tokenizer.c +++ b/src/client/tokenizer.c @@ -44,6 +44,8 @@ tokenize_line(const char *line, int *argc, char ***argv) char input[2*strlen(line) + 3]; /* 3 = 2 for '\n ' and 1 for \0 */ memset(input, 0, 2*strlen(line) + 3); for (int pos = 0; line[pos]; pos++) { + if (line[pos] == '#' && !escaped && !quote) + break; if (!escaped && strchr(escapes, line[pos])) escaped = 1; else if (!escaped && strchr(quotes, line[pos]) && !quote) {