commit 486d22fc48abf753bdc90e4c73a9a998b42ebe3d
parent f559b71488a314c974e07ca1662adabddff0805d
Author: sin <sin@2f30.org>
Date: Thu, 10 Oct 2013 23:03:15 +0100
Simplify code in cut(1)
Thanks Roberto and Rob for your input on this.
Diffstat:
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git a/cut.c b/cut.c
@@ -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\n");