[hackers] [sbase] Simplify code in cut(1) || sin

From: <git_AT_suckless.org>
Date: Fri, 11 Oct 2013 12:06:19 +0200

commit 486d22fc48abf753bdc90e4c73a9a998b42ebe3d
Author: sin <sin_AT_2f30.org>
Date: Thu Oct 10 23:03:15 2013 +0100

    Simplify code in cut(1)
    
    Thanks Roberto and Rob for your input on this.

diff --git a/cut.c b/cut.c
index 40dc250..7e30361 100644
--- a/cut.c
+++ b/cut.c
_AT_@ -60,16 +60,8 @@ parselist(char *str)
         if(!(r = malloc(n * sizeof(Range))))
                 eprintf("malloc:");
         for(s = str; n; n--, s++) {
- if (*s == '-')
- r->min = 1;
- else
- r->min = strtoul(s, &s, 10);
- if (*s == '-') {
- s++;
- r->max = strtoul(s, &s, 10);
- } else {
- r->max = r->min;
- }
+ r->min = (*s == '-') ? 1 : strtoul(s, &s, 10);
+ r->max = (*s == '-') ? strtoul(s + 1, &s, 10) : r->min;
                 r->next = NULL;
                 if(!r->min || (r->max && r->max < r->min) || (*s && *s != ','))
                         eprintf("cut: bad list value
");
Received on Fri Oct 11 2013 - 12:06:19 CEST

This archive was generated by hypermail 2.3.0 : Fri Oct 11 2013 - 12:12:21 CEST