sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit af1fb0c9c299166ef398d27e0f47361418d4033c
parent c55948ba91c7daab7a269ba8c70c7432d93a1b87
Author: sin <sin@2f30.org>
Date:   Mon, 11 Nov 2013 11:26:29 +0000

Inverse condition to avoid nesting in test(1)

Diffstat:
Mtest.c | 48++++++++++++++++++++++++------------------------
1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/test.c b/test.c @@ -113,32 +113,32 @@ binary(const char *arg1, const char *op, const char *arg2) }; for (i = 0; i < LEN(optexts); i++) { - if (strcmp(op, optexts[i]) == 0) { - oper = i; + if (strcmp(op, optexts[i]) != 0) + continue; + oper = i; + switch (oper) { + case STREQ: + return strcmp(arg1, arg2) == 0; + case STRNE: + return strcmp(arg1, arg2) != 0; + default: + narg1 = estrtol(arg1, 0); + narg2 = estrtol(arg2, 0); switch (oper) { - case STREQ: - return strcmp(arg1, arg2) == 0; - case STRNE: - return strcmp(arg1, arg2) != 0; + case EQ: + return narg1 == narg2; + case GE: + return narg1 >= narg2; + case GT: + return narg1 > narg2; + case LE: + return narg1 <= narg2; + case LT: + return narg1 < narg2; + case NE: + return narg1 != narg2; default: - narg1 = estrtol(arg1, 0); - narg2 = estrtol(arg2, 0); - switch (oper) { - case EQ: - return narg1 == narg2; - case GE: - return narg1 >= narg2; - case GT: - return narg1 > narg2; - case LE: - return narg1 <= narg2; - case LT: - return narg1 < narg2; - case NE: - return narg1 != narg2; - default: - usage(); - } + usage(); } } }