sbase

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

commit 0723c8d32eabcb326381235e4aed265ee93af7b4
parent 9694305e05c1de0d0f0c903d6fbd6d9c52c78aa5
Author: Jakob Kramer <jakob.kramer@gmx.de>
Date:   Tue,  6 May 2014 13:35:06 +0200

sort: work with signed integers as well

Diffstat:
Msort.c | 31++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/sort.c b/sort.c @@ -9,10 +9,10 @@ #include "util.h" struct keydef { - unsigned start_column; - unsigned end_column; - unsigned start_char; - unsigned end_char; + int start_column; + int end_column; + int start_char; + int end_char; }; struct kdlist { @@ -146,7 +146,7 @@ linecmp(const char **a, const char **b) else if(!(node == head) && !node->next) res = strcmp(s1, s2); else if(nflag) - res = strtoul(s1, 0, 10) - strtoul(s2, 0, 10); + res = strtol(s1, 0, 10) - strtol(s2, 0, 10); else res = strcmp(s1, s2); @@ -167,17 +167,22 @@ parse_keydef(struct keydef *kd, char *s) kd->end_column = 0; kd->end_char = 0; - kd->start_column = strtoul(rest, &rest, 10); - if(!kd->start_column) - enprintf(2, "starting column cannot be 0\n"); + kd->start_column = strtol(rest, &rest, 10); + if(kd->start_column < 1) + return -1; if(*rest == '.') - kd->start_char = strtoul(rest+1, &rest, 10); + kd->start_char = strtol(rest+1, &rest, 10); + if(kd->start_char < 1) + return -1; if(*rest == ',') { - kd->end_column = strtoul(rest+1, &rest, 10); + kd->end_column = strtol(rest+1, &rest, 10); if(kd->end_column && kd->end_column < kd->start_column) - enprintf(2, ",%u is too small\n", kd->end_column); - if(*rest == '.') - kd->end_char = strtoul(rest+1, &rest, 10); + return -1; + if(*rest == '.') { + kd->end_char = strtol(rest+1, &rest, 10); + if(kd->end_char < 1) + return -1; + } } if(*rest != '\0') return -1;