sort: work with signed integers as well

This commit is contained in:
Jakob Kramer 2014-05-06 13:35:06 +02:00 committed by sin
parent 9694305e05
commit 0723c8d32e

31
sort.c
View File

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