filter: reduce indentation in filter_init by 16 characters by using return.

Michael
This commit is contained in:
Michael Adam 2009-09-15 01:13:11 +02:00
parent 9594b8889e
commit 93b00446b9

View File

@ -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;
if (fl || already_init) {
return;
}
cflags = REG_NEWLINE | REG_NOSUB;
if (config.filter_extended)
cflags |= REG_EXTENDED;
if (!config.filter_casesensitive)
cflags |= REG_ICASE;
fd = fopen (config.filter, "r");
if (!fd) {
return;
}
while (fgets (buf, FILTER_BUFFER_LEN, 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)) {
/*
* 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 (s == buf
|| *(s - 1) != '\\')
break;
}
if (ferror (fd)) {
perror ("fgets");
exit (EX_DATAERR);
}
fclose (fd);
++s;
}
*s = '\0';
already_init = 1;
/* 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);
}
fclose (fd);
already_init = 1;
}
/* unlink the list */