[hackers] [sbase] grep: Reverse some if-else logic || Michael Forney

From: <git_AT_suckless.org>
Date: Sat, 14 May 2016 13:58:42 +0200 (CEST)

commit 8636c956d954c589565fca21c820354bc19c4384
Author: Michael Forney <mforney_AT_mforney.org>
AuthorDate: Fri May 13 23:34:50 2016 -0700
Commit: sin <sin_AT_2f30.org>
CommitDate: Sat May 14 12:58:38 2016 +0100

    grep: Reverse some if-else logic
    
    This way, people don't have to do double negatives in their head.

diff --git a/grep.c b/grep.c
index 64ffbe2..ae23967 100644
--- a/grep.c
+++ b/grep.c
_AT_@ -114,23 +114,23 @@ grep(FILE *fp, const char *str)
                 if (len && buf[len - 1] == '\n')
                         buf[len - 1] = '\0';
                 SLIST_FOREACH(pnode, &phead, entry) {
- if (!Fflag) {
- if (regexec(&pnode->preg, buf, 0, NULL, 0) ^ vflag)
- continue;
- } else {
- if (!xflag) {
- if ((iflag ? strcasestr : strstr)(buf, pnode->pattern))
+ if (Fflag) {
+ if (xflag) {
+ if (!(iflag ? strcasecmp : strcmp)(buf, pnode->pattern))
                                                 match = Match;
                                         else
                                                 match = NoMatch;
                                 } else {
- if (!(iflag ? strcasecmp : strcmp)(buf, pnode->pattern))
+ if ((iflag ? strcasestr : strstr)(buf, pnode->pattern))
                                                 match = Match;
                                         else
                                                 match = NoMatch;
                                 }
                                 if (match ^ vflag)
                                         continue;
+ } else {
+ if (regexec(&pnode->preg, buf, 0, NULL, 0) ^ vflag)
+ continue;
                         }
                         switch (mode) {
                         case 'c':
Received on Sat May 14 2016 - 13:58:42 CEST

This archive was generated by hypermail 2.3.0 : Sat May 14 2016 - 14:00:21 CEST