summaryrefslogtreecommitdiff
path: root/src/numericsort.c
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2002-05-02 11:11:01 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>2002-05-02 11:11:01 +0000
commita237472c70abda43511b988a519f9672d37dc652 (patch)
tree0ecd052f262d37e47e2d300a0d53faed0f0b55eb /src/numericsort.c
parent540739e6d79a9a3fa77deef3c326993da9b3dc07 (diff)
Update fl_filename_list() to accept a sort function to use, and export
fl_alphasort, fl_casealphasort, fl_casenumericsort, and fl_numericsort. Still need to document this and provide hooks in the file chooser and browsers. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2174 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/numericsort.c')
-rw-r--r--src/numericsort.c47
1 files changed, 38 insertions, 9 deletions
diff --git a/src/numericsort.c b/src/numericsort.c
index cb20aa75c..7220d0c94 100644
--- a/src/numericsort.c
+++ b/src/numericsort.c
@@ -1,5 +1,5 @@
/*
- * "$Id: numericsort.c,v 1.10.2.4.2.2 2002/01/01 15:11:32 easysw Exp $"
+ * "$Id: numericsort.c,v 1.10.2.4.2.3 2002/05/02 11:11:01 easysw Exp $"
*
* Numeric sorting routine for the Fast Light Tool Kit (FLTK).
*
@@ -49,9 +49,15 @@
#endif
#ifdef __cplusplus
-extern "C"
+extern "C" {
#endif
-int numericsort(struct dirent **A, struct dirent **B) {
+
+/*
+ * 'numericsort()' - Compare two directory entries, possibly with
+ * a case-insensitive comparison...
+ */
+
+static int numericsort(struct dirent **A, struct dirent **B, int cs) {
const char* a = (*A)->d_name;
const char* b = (*B)->d_name;
int ret = 0;
@@ -68,11 +74,14 @@ int numericsort(struct dirent **A, struct dirent **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((unsigned)*a)-tolower((unsigned)*b))) break; /* compare case-insensitve */
-#else
- if ((ret = *a-*b)) break; /* compare case-sensitive */
-#endif
+ if (cs) {
+ /* compare case-sensitive */
+ if ((ret = *a-*b)) break;
+ } else {
+ /* compare case-insensitve */
+ if ((ret = tolower((unsigned)*a)-tolower((unsigned)*b))) break;
+ }
+
if (!*a) break;
a++; b++;
}
@@ -82,5 +91,25 @@ int numericsort(struct dirent **A, struct dirent **B) {
}
/*
- * End of "$Id: numericsort.c,v 1.10.2.4.2.2 2002/01/01 15:11:32 easysw Exp $".
+ * 'fl_casenumericsort()' - Compare directory entries with case-sensitivity.
+ */
+
+int fl_casenumericsort(struct dirent **A, struct dirent **B) {
+ return numericsort(A, B, 0);
+}
+
+/*
+ * 'fl_numericsort()' - Compare directory entries with case-sensitivity.
+ */
+
+int fl_numericsort(struct dirent **A, struct dirent **B) {
+ return numericsort(A, B, 1);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+/*
+ * End of "$Id: numericsort.c,v 1.10.2.4.2.3 2002/05/02 11:11:01 easysw Exp $".
*/