filter: Remove redundant code

Skipping leading whitespace and removing trailing whitespace and
comments were swapped to avoid skipping the leading whitespace twice.
This commit is contained in:
Janosch Hoffmann 2019-05-05 16:46:16 +02:00
parent 10d36d48a4
commit fffe45cae1

View File

@ -52,7 +52,7 @@ void filter_init (void)
FILE *fd; FILE *fd;
struct filter_list *p; struct filter_list *p;
char buf[FILTER_BUFFER_LEN]; char buf[FILTER_BUFFER_LEN];
char *s; char *s, *start;
int cflags; int cflags;
if (fl || already_init) { if (fl || already_init) {
@ -73,14 +73,16 @@ void filter_init (void)
cflags |= REG_ICASE; cflags |= REG_ICASE;
while (fgets (buf, FILTER_BUFFER_LEN, fd)) { while (fgets (buf, FILTER_BUFFER_LEN, fd)) {
/* skip leading whitespace */
s = buf;
while (*s && isspace ((unsigned char) *s))
s++;
start = s;
/* /*
* Remove any trailing white space and * Remove any trailing white space and
* comments. * comments.
*/ */
s = buf;
/* skip leading whitespace */
while (*s && isspace ((unsigned char) *s))
++s;
while (*s) { while (*s) {
if (isspace ((unsigned char) *s)) if (isspace ((unsigned char) *s))
break; break;
@ -96,11 +98,7 @@ void filter_init (void)
++s; ++s;
} }
*s = '\0'; *s = '\0';
s = start;
/* skip leading whitespace */
s = buf;
while (*s && isspace ((unsigned char) *s))
s++;
/* skip blank lines and comments */ /* skip blank lines and comments */
if (*s == '\0') if (*s == '\0')