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:
parent
540739e6d7
commit
a237472c70
@ -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 $".
|
||||
//
|
||||
|
@ -88,6 +88,10 @@ the old and new function names:</P>
|
||||
<TD>inactive()</TD>
|
||||
<TD>fl_inactive()</TD>
|
||||
</TR>
|
||||
<TR>
|
||||
<TD>numericsort()</TD>
|
||||
<TD>fl_numericsort()</TD>
|
||||
</TR>
|
||||
</TABLE></CENTER>
|
||||
|
||||
<H2>Image Support</H2>
|
||||
|
@ -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 <config.h>
|
||||
#include <FL/filename.H>
|
||||
#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 $".
|
||||
//
|
||||
|
@ -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 $".
|
||||
*/
|
||||
|
@ -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
|
||||
|
@ -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 $".
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user