[hackers] [sbase] sort: work with signed integers as well || Jakob Kramer

From: <git_AT_suckless.org>
Date: Tue, 06 May 2014 17:21:43 +0200

commit 0723c8d32eabcb326381235e4aed265ee93af7b4
Author: Jakob Kramer <jakob.kramer_AT_gmx.de>
Date: Tue May 6 13:35:06 2014 +0200

    sort: work with signed integers as well

diff --git a/sort.c b/sort.c
index 0f19b44..1d5f325 100644
--- a/sort.c
+++ b/sort.c
_AT_@ -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 {
_AT_@ -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);
 
_AT_@ -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
");
+ 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
", 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 != '
Received on Tue May 06 2014 - 17:21:43 CEST

This archive was generated by hypermail 2.3.0 : Tue May 06 2014 - 17:24:08 CEST