X-Git-Url: https://git.toastfreeware.priv.at/gregoa/bti.git/blobdiff_plain/cb0d563370248c29cdc857c409d47387d068d7f6..9c4bfd8cd15f0cfcf774313ac84513f6ba6f366d:/config.c diff --git a/config.c b/config.c index 9326c71..2b510b9 100644 --- a/config.c +++ b/config.c @@ -327,6 +327,7 @@ void bti_parse_configfile(struct session *session) char *line = NULL; char *key = NULL; char *value = NULL; + char *hashmarker; size_t len = 0; ssize_t n; char *c; @@ -344,14 +345,30 @@ void bti_parse_configfile(struct session *session) if (line[n - 1] == '\n') line[n - 1] = '\0'; - /* '#' is comment markers, like bash style - but it is a valid character in some fields, so - only treat it as a comment marker if it occurs - at the beginning of the line, or after whitespace */ - char *hashmarker = strchrnul(line, '#'); - if (line == hashmarker) line[0] = '\0'; - if (*(--hashmarker) == ' ' || *hashmarker == '\t') - *hashmarker = '\0'; + /* + * '#' is comment markers, like bash style but it is a valid + * character in some fields, so only treat it as a comment + * marker if it occurs at the beginning of the line, or after + * whitespace + */ + hashmarker = strchr(line, '#'); + if (line == hashmarker) + line[0] = '\0'; + else { + while (hashmarker != NULL) { + --hashmarker; + if (isblank(hashmarker[0])) { + hashmarker[0] = '\0'; + break; + } else { + /* + * false positive; '#' occured + * within a string + */ + hashmarker = strchr(hashmarker+2, '#'); + } + } + } c = line; while (isspace(*c)) c++;