mirror of
https://github.com/fltk/fltk.git
synced 2026-05-28 20:06:18 +08:00
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
This commit is contained in:
+14
-3
@@ -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).
|
// Filename header file for the Fast Light Tool Kit (FLTK).
|
||||||
//
|
//
|
||||||
@@ -69,10 +69,21 @@ struct dirent {char d_name[1];};
|
|||||||
|
|
||||||
# endif
|
# 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
|
#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 $".
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -88,6 +88,10 @@ the old and new function names:</P>
|
|||||||
<TD>inactive()</TD>
|
<TD>inactive()</TD>
|
||||||
<TD>fl_inactive()</TD>
|
<TD>fl_inactive()</TD>
|
||||||
</TR>
|
</TR>
|
||||||
|
<TR>
|
||||||
|
<TD>numericsort()</TD>
|
||||||
|
<TD>fl_numericsort()</TD>
|
||||||
|
</TR>
|
||||||
</TABLE></CENTER>
|
</TABLE></CENTER>
|
||||||
|
|
||||||
<H2>Image Support</H2>
|
<H2>Image Support</H2>
|
||||||
|
|||||||
+25
-15
@@ -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).
|
// Filename list routines for the Fast Light Tool Kit (FLTK).
|
||||||
//
|
//
|
||||||
@@ -27,40 +27,50 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <FL/filename.H>
|
#include <FL/filename.H>
|
||||||
|
#include "flstring.h"
|
||||||
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
int numericsort(dirent **, dirent **);
|
#ifndef HAVE_SCANDIR
|
||||||
#if HAVE_SCANDIR
|
int fl_scandir (const char *dir, dirent ***namelist,
|
||||||
#else
|
int (*select)(dirent *),
|
||||||
int alphasort(dirent **, dirent **);
|
int (*compar)(dirent **, dirent **));
|
||||||
int scandir (const char *dir, dirent ***namelist,
|
# define scandir fl_scandir
|
||||||
int (*select)(dirent *),
|
|
||||||
int (*compar)(dirent **, dirent **));
|
|
||||||
#endif
|
#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)
|
#if defined(__hpux)
|
||||||
// HP-UX defines the comparison function like this:
|
// 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__)
|
#elif defined(__osf__)
|
||||||
// OSF, DU 4.0x
|
// 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)
|
#elif defined(_AIX)
|
||||||
// AIX is almost standard...
|
// 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)
|
#elif HAVE_SCANDIR && !defined(__sgi)
|
||||||
// The vast majority of Unix systems want the sort function to have this
|
// 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
|
// prototype, most likely so that it can be passed to qsort without any
|
||||||
// changes:
|
// changes:
|
||||||
return scandir(d, list, 0, (int(*)(const void*,const void*))numericsort);
|
return scandir(d, list, 0, (int(*)(const void*,const void*))sort);
|
||||||
#else
|
#else
|
||||||
// This version is when we define our own scandir (WIN32 and perhaps
|
// This version is when we define our own scandir (WIN32 and perhaps
|
||||||
// some Unix systems) and apparently on Irix:
|
// some Unix systems) and apparently on Irix:
|
||||||
return scandir(d, list, 0, numericsort);
|
return scandir(d, list, 0, sort);
|
||||||
#endif
|
#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 $".
|
||||||
//
|
//
|
||||||
|
|||||||
+38
-9
@@ -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).
|
* Numeric sorting routine for the Fast Light Tool Kit (FLTK).
|
||||||
*
|
*
|
||||||
@@ -49,9 +49,15 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C" {
|
||||||
#endif
|
#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* a = (*A)->d_name;
|
||||||
const char* b = (*B)->d_name;
|
const char* b = (*B)->d_name;
|
||||||
int ret = 0;
|
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 (magdiff) {ret = magdiff; break;} /* compare # of significant digits*/
|
||||||
if (diff) {ret = diff; break;} /* compare first non-zero digit */
|
if (diff) {ret = diff; break;} /* compare first non-zero digit */
|
||||||
} else {
|
} else {
|
||||||
#if 1
|
if (cs) {
|
||||||
if ((ret = tolower((unsigned)*a)-tolower((unsigned)*b))) break; /* compare case-insensitve */
|
/* compare case-sensitive */
|
||||||
#else
|
if ((ret = *a-*b)) break;
|
||||||
if ((ret = *a-*b)) break; /* compare case-sensitive */
|
} else {
|
||||||
#endif
|
/* compare case-insensitve */
|
||||||
|
if ((ret = tolower((unsigned)*a)-tolower((unsigned)*b))) break;
|
||||||
|
}
|
||||||
|
|
||||||
if (!*a) break;
|
if (!*a) break;
|
||||||
a++; b++;
|
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 $".
|
||||||
*/
|
*/
|
||||||
|
|||||||
+3
-7
@@ -49,9 +49,9 @@ USA. */
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
int
|
int
|
||||||
scandir (const char *dir, struct dirent ***namelist,
|
fl_scandir(const char *dir, struct dirent ***namelist,
|
||||||
int (*select)(struct dirent *),
|
int (*select)(struct dirent *),
|
||||||
int (*compar)(struct dirent **, struct dirent **))
|
int (*compar)(struct dirent **, struct dirent **))
|
||||||
{
|
{
|
||||||
DIR *dp = opendir (dir);
|
DIR *dp = opendir (dir);
|
||||||
struct dirent **v = NULL;
|
struct dirent **v = NULL;
|
||||||
@@ -120,9 +120,5 @@ scandir (const char *dir, struct dirent ***namelist,
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int alphasort (struct dirent **a, struct dirent **b) {
|
|
||||||
return strcmp ((*a)->d_name, (*b)->d_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+5
-9
@@ -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).
|
* WIN32 scandir function for the Fast Light Tool Kit (FLTK).
|
||||||
*
|
*
|
||||||
@@ -32,9 +32,9 @@
|
|||||||
|
|
||||||
struct dirent { char d_name[1]; };
|
struct dirent { char d_name[1]; };
|
||||||
|
|
||||||
int scandir(const char *dirname, struct dirent ***namelist,
|
int fl_scandir(const char *dirname, struct dirent ***namelist,
|
||||||
int (*select)(struct dirent *),
|
int (*select)(struct dirent *),
|
||||||
int (*compar)(struct dirent **, struct dirent **)) {
|
int (*compar)(struct dirent **, struct dirent **)) {
|
||||||
int len;
|
int len;
|
||||||
char *findIn, *d;
|
char *findIn, *d;
|
||||||
WIN32_FIND_DATA find;
|
WIN32_FIND_DATA find;
|
||||||
@@ -101,12 +101,8 @@ int scandir(const char *dirname, struct dirent ***namelist,
|
|||||||
return nDir;
|
return nDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
int alphasort (struct dirent **a, struct dirent **b) {
|
|
||||||
return strcmp ((*a)->d_name, (*b)->d_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#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 $".
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user