From 93b00446b9b474d561d4f3b25d2215ac7a6ffad4 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 15 Sep 2009 01:13:11 +0200 Subject: filter: reduce indentation in filter_init by 16 characters by using return. Michael --- src/filter.c | 148 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 76 insertions(+), 72 deletions(-) (limited to 'src') diff --git a/src/filter.c b/src/filter.c index 9ec7858..3a955ce 100644 --- a/src/filter.c +++ b/src/filter.c @@ -54,84 +54,88 @@ void filter_init (void) char *s; int cflags; - if (!fl && !already_init) { - fd = fopen (config.filter, "r"); - if (fd) { - p = NULL; - - cflags = REG_NEWLINE | REG_NOSUB; - if (config.filter_extended) - cflags |= REG_EXTENDED; - if (!config.filter_casesensitive) - cflags |= REG_ICASE; - - while (fgets (buf, FILTER_BUFFER_LEN, fd)) { + if (fl || already_init) { + return; + } + + fd = fopen (config.filter, "r"); + if (!fd) { + return; + } + + p = NULL; + + cflags = REG_NEWLINE | REG_NOSUB; + if (config.filter_extended) + cflags |= REG_EXTENDED; + if (!config.filter_casesensitive) + 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 == '#') { /* - * Remove any trailing white space and - * comments. + * If the '#' char is preceeded by + * an escape, it's not a comment + * string. */ - 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 = - (struct filter_list *) - safecalloc (1, - sizeof (struct - filter_list)); - else { /* next entry */ - p->next = - (struct filter_list *) - safecalloc (1, - sizeof (struct - filter_list)); - p = p->next; - } - - p->pat = safestrdup (s); - p->cpat = - (regex_t *) safemalloc (sizeof (regex_t)); - err = regcomp (p->cpat, p->pat, cflags); - if (err != 0) { - fprintf (stderr, - "Bad regex in %s: %s\n", - config.filter, p->pat); - exit (EX_DATAERR); - } - } - if (ferror (fd)) { - perror ("fgets"); - exit (EX_DATAERR); + if (s == buf + || *(s - 1) != '\\') + break; } - fclose (fd); + ++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 = + (struct filter_list *) + safecalloc (1, + sizeof (struct + filter_list)); + else { /* next entry */ + p->next = + (struct filter_list *) + safecalloc (1, + sizeof (struct + filter_list)); + p = p->next; + } - already_init = 1; + p->pat = safestrdup (s); + p->cpat = + (regex_t *) safemalloc (sizeof (regex_t)); + err = regcomp (p->cpat, p->pat, cflags); + if (err != 0) { + fprintf (stderr, + "Bad regex in %s: %s\n", + config.filter, p->pat); + exit (EX_DATAERR); } } + if (ferror (fd)) { + perror ("fgets"); + exit (EX_DATAERR); + } + fclose (fd); + + already_init = 1; } /* unlink the list */ -- cgit v1.2.3