diff options
| author | Michael R Sweet <michael.r.sweet@gmail.com> | 1998-11-09 16:25:59 +0000 |
|---|---|---|
| committer | Michael R Sweet <michael.r.sweet@gmail.com> | 1998-11-09 16:25:59 +0000 |
| commit | bb21ad727029ca68db0c7bfe43d54b793e6182a7 (patch) | |
| tree | b0686a842a01a50fe29fafdfc6b8ec86ade82f57 /src | |
| parent | 8a5883e03baa12869f33055e96365614e6b8346a (diff) | |
Fixed sort function - was returning numbers other than 1, -1, and 0, and
didn't correctly sort numbers.
git-svn-id: file:///fltk/svn/fltk/trunk@81 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
| -rw-r--r-- | src/numericsort.c | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/src/numericsort.c b/src/numericsort.c index c854e79e1..3369f863d 100644 --- a/src/numericsort.c +++ b/src/numericsort.c @@ -1,5 +1,5 @@ /* - * "$Id: numericsort.c,v 1.6 1998/10/21 14:21:10 mike Exp $" + * "$Id: numericsort.c,v 1.7 1998/11/09 16:25:59 mike Exp $" * * Numeric sorting routine for the Fast Light Tool Kit (FLTK). * @@ -56,30 +56,26 @@ extern "C" int numericsort(struct dirent **A, struct dirent **B) { const char* a = (*A)->d_name; const char* b = (*B)->d_name; - int ret = 0; + for (;;) { if (isdigit(*a) && isdigit(*b)) { - int zdiff,diff,magdiff; - zdiff = 0; - while (*a == '0') {a++; zdiff++;} - while (*b == '0') {b++; zdiff--;} - while (isdigit(*a) && *a == *b) {a++; b++;} - diff = (isdigit(*a) && isdigit(*b)) ? *a - *b : 0; - magdiff = 0; - while (isdigit(*a)) {magdiff++; a++;} - while (isdigit(*b)) {magdiff--; b++;} - if (ret); - else if (magdiff) ret = magdiff; - else if (diff) ret = diff; - else if (zdiff) ret = zdiff; - } else if (*a == *b) { - if (!*a) return ret; - a++; b++; - } else - return (*a-*b); + int anum = 0, bnum = 0; + + while (isdigit(*a)) anum = anum * 10 + *a++ - '0'; + while (isdigit(*b)) bnum = bnum * 10 + *b++ - '0'; + + if (anum < bnum) return (-1); + else if (anum > bnum) return (1); + } else if (tolower(*a) < tolower(*b)) return (-1); + else if (tolower(*a) > tolower(*b)) return (1); + else { + if (*a == '\0') return (0); + a++; + b++; + } } } /* - * End of "$Id: numericsort.c,v 1.6 1998/10/21 14:21:10 mike Exp $". + * End of "$Id: numericsort.c,v 1.7 1998/11/09 16:25:59 mike Exp $". */ |
