diff options
author | Jim Meyering <jim@meyering.net> | 1995-12-05 17:53:39 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1995-12-05 17:53:39 +0000 |
commit | 5cf455d73662078073e2192e0070fbceda7340c2 (patch) | |
tree | b8fc23f2ad9f9da1f0e62ce02f16c73cc172554a | |
parent | 8ef322d66fb68167e1f530c849abbfb2164f7002 (diff) | |
download | coreutils-5cf455d73662078073e2192e0070fbceda7340c2.tar.xz |
(numcompare): Properly handle all cases in which signs differ. From Karl Heuer.
-rw-r--r-- | src/sort.c | 43 |
1 files changed, 34 insertions, 9 deletions
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; } |