From 6cc8fac7fd9b47e179629a61acef0e8758763803 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Wed, 27 Aug 2003 17:35:54 +0300 Subject: [PATCH] Support # comments also at the end of setting lines --HG-- branch : HEAD --- src/lib-settings/settings.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/lib-settings/settings.c b/src/lib-settings/settings.c index ded6bc358a..a09ee5d7f7 100644 --- a/src/lib-settings/settings.c +++ b/src/lib-settings/settings.c @@ -66,7 +66,7 @@ int settings_read(const char *path, const char *section, { struct istream *input; const char *errormsg, *next_section; - char *line, *key, *name; + char *line, *key, *name, *p, quote; size_t len; int fd, linenum, skip, sections, root_section; @@ -101,6 +101,22 @@ int settings_read(const char *path, const char *section, if (*line == '#' || *line == '\0') continue; + /* strip away comments. pretty kludgy way really.. */ + for (p = line; *p != '\0'; p++) { + if (*p == '\'' || *p == '"') { + quote = *p; + for (p++; *p != quote && *p != '\0'; p++) { + if (*p == '\\' && p[1] != '\0') + p++; + } + if (*p == '\0') + break; + } else if (*p == '#') { + *p = '\0'; + break; + } + } + /* remove whitespace from end of line */ len = strlen(line); while (IS_WHITE(line[len-1])) -- 2.47.3