From a237472c70abda43511b988a519f9672d37dc652 Mon Sep 17 00:00:00 2001
From: Michael R Sweet
Date: Thu, 2 May 2002 11:11:01 +0000
Subject: 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
---
FL/filename.H | 17 +++++++++++++---
documentation/migration.html | 4 ++++
src/filename_list.cxx | 40 +++++++++++++++++++++++--------------
src/numericsort.c | 47 +++++++++++++++++++++++++++++++++++---------
src/scandir.c | 10 +++-------
src/scandir_win32.c | 14 +++++--------
6 files changed, 89 insertions(+), 43 deletions(-)
diff --git a/FL/filename.H b/FL/filename.H
index fdcdd73d0..419f59a19 100644
--- a/FL/filename.H
+++ b/FL/filename.H
@@ -1,5 +1,5 @@
//
-// "$Id: filename.H,v 1.11.2.4.2.5 2002/03/25 21:08:41 easysw Exp $"
+// "$Id: filename.H,v 1.11.2.4.2.6 2002/05/02 11:11:00 easysw Exp $"
//
// Filename header file for the Fast Light Tool Kit (FLTK).
//
@@ -69,10 +69,21 @@ struct dirent {char d_name[1];};
# endif
-FL_EXPORT int fl_filename_list(const char *d, struct dirent ***list);
+extern "C" {
+ FL_EXPORT int fl_alphasort(dirent **, dirent **);
+ FL_EXPORT int fl_casealphasort(dirent **, dirent **);
+ FL_EXPORT int fl_casenumericsort(dirent **, dirent **);
+ FL_EXPORT int fl_numericsort(dirent **, dirent **);
+
+ typedef int (Fl_File_Sort_F)(dirent **, dirent **);
+}
+
+FL_EXPORT int fl_filename_list(const char *d, struct dirent ***list,
+ Fl_File_Sort_F *sort = fl_numericsort);
+
#endif
//
-// End of "$Id: filename.H,v 1.11.2.4.2.5 2002/03/25 21:08:41 easysw Exp $".
+// End of "$Id: filename.H,v 1.11.2.4.2.6 2002/05/02 11:11:00 easysw Exp $".
//
diff --git a/documentation/migration.html b/documentation/migration.html
index e95fc54fd..68a03357f 100644
--- a/documentation/migration.html
+++ b/documentation/migration.html
@@ -88,6 +88,10 @@ the old and new function names:
inactive() |
fl_inactive() |
+
+ | numericsort() |
+ fl_numericsort() |
+
Image Support
diff --git a/src/filename_list.cxx b/src/filename_list.cxx
index 8856594b7..c64ba9564 100644
--- a/src/filename_list.cxx
+++ b/src/filename_list.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: filename_list.cxx,v 1.10.2.11.2.2 2002/03/25 21:08:42 easysw Exp $"
+// "$Id: filename_list.cxx,v 1.10.2.11.2.3 2002/05/02 11:11:01 easysw Exp $"
//
// Filename list routines for the Fast Light Tool Kit (FLTK).
//
@@ -27,40 +27,50 @@
#include
#include
+#include "flstring.h"
+
extern "C" {
- int numericsort(dirent **, dirent **);
-#if HAVE_SCANDIR
-#else
- int alphasort(dirent **, dirent **);
- int scandir (const char *dir, dirent ***namelist,
- int (*select)(dirent *),
- int (*compar)(dirent **, dirent **));
+#ifndef HAVE_SCANDIR
+ int fl_scandir (const char *dir, dirent ***namelist,
+ int (*select)(dirent *),
+ int (*compar)(dirent **, dirent **));
+# define scandir fl_scandir
#endif
}
-int fl_filename_list(const char *d, dirent ***list) {
+int fl_alphasort(struct dirent **a, struct dirent **b) {
+ return strcmp((*a)->d_name, (*b)->d_name);
+}
+
+int fl_casealphasort(struct dirent **a, struct dirent **b) {
+ return strcasecmp((*a)->d_name, (*b)->d_name);
+}
+
+
+int fl_filename_list(const char *d, dirent ***list,
+ Fl_File_Sort_F *sort) {
#if defined(__hpux)
// HP-UX defines the comparison function like this:
- return scandir(d, list, 0, (int(*)(const dirent **, const dirent **))numericsort);
+ return scandir(d, list, 0, (int(*)(const dirent **, const dirent **))sort);
#elif defined(__osf__)
// OSF, DU 4.0x
- return scandir(d, list, 0, (int(*)(dirent **, dirent **))numericsort);
+ return scandir(d, list, 0, (int(*)(dirent **, dirent **))sort);
#elif defined(_AIX)
// AIX is almost standard...
- return scandir(d, list, 0, (int(*)(void*, void*))numericsort);
+ return scandir(d, list, 0, (int(*)(void*, void*))sort);
#elif HAVE_SCANDIR && !defined(__sgi)
// The vast majority of Unix systems want the sort function to have this
// prototype, most likely so that it can be passed to qsort without any
// changes:
- return scandir(d, list, 0, (int(*)(const void*,const void*))numericsort);
+ return scandir(d, list, 0, (int(*)(const void*,const void*))sort);
#else
// This version is when we define our own scandir (WIN32 and perhaps
// some Unix systems) and apparently on Irix:
- return scandir(d, list, 0, numericsort);
+ return scandir(d, list, 0, sort);
#endif
}
//
-// End of "$Id: filename_list.cxx,v 1.10.2.11.2.2 2002/03/25 21:08:42 easysw Exp $".
+// End of "$Id: filename_list.cxx,v 1.10.2.11.2.3 2002/05/02 11:11:01 easysw Exp $".
//
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 $".
*/
diff --git a/src/scandir.c b/src/scandir.c
index 5eabafa41..1e52da9d2 100644
--- a/src/scandir.c
+++ b/src/scandir.c
@@ -49,9 +49,9 @@ USA. */
#endif
int
-scandir (const char *dir, struct dirent ***namelist,
- int (*select)(struct dirent *),
- int (*compar)(struct dirent **, struct dirent **))
+fl_scandir(const char *dir, struct dirent ***namelist,
+ int (*select)(struct dirent *),
+ int (*compar)(struct dirent **, struct dirent **))
{
DIR *dp = opendir (dir);
struct dirent **v = NULL;
@@ -120,9 +120,5 @@ scandir (const char *dir, struct dirent ***namelist,
return i;
}
-int alphasort (struct dirent **a, struct dirent **b) {
- return strcmp ((*a)->d_name, (*b)->d_name);
-}
-
#endif
#endif
diff --git a/src/scandir_win32.c b/src/scandir_win32.c
index acfe24b35..33598f8d6 100644
--- a/src/scandir_win32.c
+++ b/src/scandir_win32.c
@@ -1,5 +1,5 @@
/*
- * "$Id: scandir_win32.c,v 1.11.2.4.2.3 2002/04/29 19:40:51 easysw Exp $"
+ * "$Id: scandir_win32.c,v 1.11.2.4.2.4 2002/05/02 11:11:01 easysw Exp $"
*
* WIN32 scandir function for the Fast Light Tool Kit (FLTK).
*
@@ -32,9 +32,9 @@
struct dirent { char d_name[1]; };
-int scandir(const char *dirname, struct dirent ***namelist,
- int (*select)(struct dirent *),
- int (*compar)(struct dirent **, struct dirent **)) {
+int fl_scandir(const char *dirname, struct dirent ***namelist,
+ int (*select)(struct dirent *),
+ int (*compar)(struct dirent **, struct dirent **)) {
int len;
char *findIn, *d;
WIN32_FIND_DATA find;
@@ -101,12 +101,8 @@ int scandir(const char *dirname, struct dirent ***namelist,
return nDir;
}
-int alphasort (struct dirent **a, struct dirent **b) {
- return strcmp ((*a)->d_name, (*b)->d_name);
-}
-
#endif
/*
- * End of "$Id: scandir_win32.c,v 1.11.2.4.2.3 2002/04/29 19:40:51 easysw Exp $".
+ * End of "$Id: scandir_win32.c,v 1.11.2.4.2.4 2002/05/02 11:11:01 easysw Exp $".
*/
--
cgit v1.2.3