summaryrefslogtreecommitdiff
path: root/src/numericsort.c
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>1998-12-02 15:47:30 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>1998-12-02 15:47:30 +0000
commit92402e682a1dc89c8915f1a4f5698d1c3ab82eb8 (patch)
tree8c05965a36c0802d98572b4fa189bcc033e598e8 /src/numericsort.c
parent849e11623e44a62599d62ba9425f7e96146f555d (diff)
Fix for numericsort(), and drawing of some box types.
git-svn-id: file:///fltk/svn/fltk/trunk@107 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/numericsort.c')
-rw-r--r--src/numericsort.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/src/numericsort.c b/src/numericsort.c
index 3369f863d..00992097f 100644
--- a/src/numericsort.c
+++ b/src/numericsort.c
@@ -1,5 +1,5 @@
/*
- * "$Id: numericsort.c,v 1.7 1998/11/09 16:25:59 mike Exp $"
+ * "$Id: numericsort.c,v 1.8 1998/12/02 15:47:30 mike Exp $"
*
* Numeric sorting routine for the Fast Light Tool Kit (FLTK).
*
@@ -56,26 +56,33 @@ 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 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++;
+ int diff,magdiff;
+ while (*a == '0') a++;
+ while (*b == '0') b++;
+ 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 (magdiff) {ret = magdiff; break;} /* compare # of significant digits*/
+ if (diff) {ret = diff; break;} /* compare first non-zero digit */
+ } else {
+#if 1
+ if ((ret = tolower(*a)-tolower(*b))) break; /* compare case-insensitve */
+#else
+ if ((ret = *a-*b)) break; /* compare case-sensitive */
+#endif
+ if (!*a) break;
+ a++; b++;
}
}
+ if (!ret) return 0;
+ else return (ret < 0) ? -1 : 1;
}
/*
- * End of "$Id: numericsort.c,v 1.7 1998/11/09 16:25:59 mike Exp $".
+ * End of "$Id: numericsort.c,v 1.8 1998/12/02 15:47:30 mike Exp $".
*/