From b1d126c4bb7d216264f1393e47479b8ac6009772 Mon Sep 17 00:00:00 2001 From: Robert James Kaes Date: Thu, 16 Oct 2003 21:19:09 +0000 Subject: [PATCH] (filter_init): Fixed up the comment handling code. Closes bug 822226 [https://sourceforge.net/tracker/index.php?func=detail&aid=822226&group_id=2632&atid=102632] --- src/filter.c | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/src/filter.c b/src/filter.c index 585b344..4d88b2c 100644 --- a/src/filter.c +++ b/src/filter.c @@ -1,4 +1,4 @@ -/* $Id: filter.c,v 1.16 2003-01-27 17:57:39 rjkaes Exp $ +/* $Id: filter.c,v 1.16.2.1 2003-10-16 21:19:09 rjkaes Exp $ * * Copyright (c) 1999 George Talusan (gstalusan@uwaterloo.ca) * Copyright (c) 2002 James E. Flemer (jflemer@acm.jhu.edu) @@ -49,7 +49,7 @@ filter_init(void) FILE *fd; struct filter_list *p; char buf[FILTER_BUFFER_LEN]; - char *s, *t; + char *s; int cflags; if (!fl && !already_init) { @@ -64,7 +64,35 @@ filter_init(void) cflags |= REG_ICASE; while (fgets(buf, FILTER_BUFFER_LEN, fd)) { + /* + * Remove any trailing white space and + * comments. + */ s = buf; + while (*s) { + if (isspace((unsigned char)*s)) break; + if (*s == '#') { + /* + * If the '#' char is preceeded by + * an escape, it's not a comment + * string. + */ + if (s == buf || *(s - 1) != '\\') + break; + } + ++s; + } + *s = '\0'; + + /* skip leading whitespace */ + s = buf; + while (*s && isspace((unsigned char)*s)) + s++; + + /* skip blank lines and comments */ + if (*s == '\0') + continue; + if (!p) /* head of list */ fl = p = safecalloc(1, @@ -78,23 +106,6 @@ filter_init(void) p = p->next; } - /* strip trailing whitespace & comments */ - t = s; - while (*s && *s != '#') { - if (!isspace((unsigned char)*(s++))) - t = s; - } - *t = '\0'; - - /* skip leading whitespace */ - s = buf; - while (*s && isspace((unsigned char)*s)) - s++; - - /* skip blank lines and comments */ - if (*s == '\0') - continue; - p->pat = safestrdup(s); p->cpat = safemalloc(sizeof(regex_t)); if ((err = regcomp(p->cpat, p->pat, cflags)) != 0) {