From 5cf455d73662078073e2192e0070fbceda7340c2 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 5 Dec 1995 17:53:39 +0000 Subject: (numcompare): Properly handle all cases in which signs differ. From Karl Heuer. --- src/sort.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/sort.c b/src/sort.c index 3fc2f7873..707df9cfb 100644 --- a/src/sort.c +++ b/src/sort.c @@ -779,19 +779,30 @@ numcompare (register const char *a, register const char *b) if (tmpa == '-') { - tmpa = UCHAR (*++a); + do + tmpa = UCHAR (*++a); + while (tmpa == '0'); if (tmpb != '-') { - if ((tmpa == 0 || digits[tmpa]) && digits[tmpb]) + if (tmpa == '.') + do + tmpa = UCHAR (*++a); + while (tmpa == '0'); + if (digits[tmpa]) + return -1; + while (tmpb == '0') + tmpb = UCHAR (*++b); + if (tmpb == '.') + do + tmpb = *++b; + while (tmpb == '0'); + if (digits[tmpb]) return -1; return 0; } - tmpb = UCHAR (*++b); - - while (tmpa == '0') - tmpa = UCHAR (*++a); - while (tmpb == '0') + do tmpb = UCHAR (*++b); + while (tmpb == '0'); while (tmpa == tmpb && digits[tmpa]) tmpa = UCHAR (*++a), tmpb = UCHAR (*++b); @@ -821,8 +832,22 @@ numcompare (register const char *a, register const char *b) } else if (tmpb == '-') { - ++b; - if (digits[UCHAR (tmpa)] && (UCHAR (*b) == 0 || digits[UCHAR (*b)])) + do + tmpb = UCHAR (*++b); + while (tmpb == '0'); + if (tmpb == '.') + do + tmpb = *++b; + while (tmpb == '0'); + if (digits[tmpb]) + return 1; + while (tmpa == '0') + tmpa = UCHAR (*++a); + if (tmpa == '.') + do + tmpa = UCHAR (*++a); + while (tmpa == '0'); + if (digits[tmpa]) return 1; return 0; } -- cgit v1.2.3-70-g09d2