mirror of
https://github.com/fltk/fltk.git
synced 2026-05-27 19:10:24 +08:00
Rewrite filename_isdir.cxx for the driver model.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11555 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
@@ -106,6 +106,10 @@ public:
|
|||||||
virtual int filename_relative(char *to, int tolen, const char *from, const char *base);
|
virtual int filename_relative(char *to, int tolen, const char *from, const char *base);
|
||||||
// the default implementation of filename_absolute() is in src/filename_absolute.cxx and may be enough
|
// the default implementation of filename_absolute() is in src/filename_absolute.cxx and may be enough
|
||||||
virtual int filename_absolute(char *to, int tolen, const char *from);
|
virtual int filename_absolute(char *to, int tolen, const char *from);
|
||||||
|
// the default implementation of filename_isdir() is in src/filename_isdir.cxx and may be enough
|
||||||
|
virtual int filename_isdir(const char* n);
|
||||||
|
// the default implementation of filename_isdir_quick() is in src/filename_isdir.cxx and may be enough
|
||||||
|
virtual int filename_isdir_quick(const char* n);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FL_SYSTEM_DRIVER_H
|
#endif // FL_SYSTEM_DRIVER_H
|
||||||
|
|||||||
@@ -100,17 +100,6 @@ FL_EXPORT int fl_open_uri(const char *uri, char *msg = (char *)0,
|
|||||||
|
|
||||||
FL_EXPORT void fl_decode_uri(char *uri);
|
FL_EXPORT void fl_decode_uri(char *uri);
|
||||||
|
|
||||||
# ifndef FL_DOXYGEN
|
|
||||||
/*
|
|
||||||
* _fl_filename_isdir_quick() is a private function that checks for a
|
|
||||||
* trailing slash and assumes that the passed name is a directory if
|
|
||||||
* it finds one. This function is used by Fl_File_Browser and
|
|
||||||
* Fl_File_Chooser to avoid extra stat() calls, but is not supported
|
|
||||||
* outside of FLTK...
|
|
||||||
*/
|
|
||||||
int _fl_filename_isdir_quick(const char *name);
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# endif /* __cplusplus */
|
# endif /* __cplusplus */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -37,6 +37,8 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include <FL/Fl_File_Browser.H>
|
#include <FL/Fl_File_Browser.H>
|
||||||
|
#include <FL/Fl.H>
|
||||||
|
#include <FL/Fl_System_Driver.H>
|
||||||
#include <FL/fl_draw.H>
|
#include <FL/fl_draw.H>
|
||||||
#include <FL/filename.H>
|
#include <FL/filename.H>
|
||||||
#include <FL/Fl_Image.H> // icon
|
#include <FL/Fl_Image.H> // icon
|
||||||
@@ -700,7 +702,7 @@ Fl_File_Browser::load(const char *directory,// I - Directory to load
|
|||||||
|
|
||||||
icon = Fl_File_Icon::find(filename);
|
icon = Fl_File_Icon::find(filename);
|
||||||
if ((icon && icon->type() == Fl_File_Icon::DIRECTORY) ||
|
if ((icon && icon->type() == Fl_File_Icon::DIRECTORY) ||
|
||||||
_fl_filename_isdir_quick(filename)) {
|
Fl::system_driver()->filename_isdir_quick(filename)) {
|
||||||
num_dirs ++;
|
num_dirs ++;
|
||||||
insert(num_dirs, files[i]->d_name, icon);
|
insert(num_dirs, files[i]->d_name, icon);
|
||||||
} else if (filetype_ == FILES &&
|
} else if (filetype_ == FILES &&
|
||||||
|
|||||||
@@ -344,7 +344,8 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include <FL/Fl_File_Chooser.H>
|
#include <FL/Fl_File_Chooser.H>
|
||||||
#include <FL/Fl_System_Driver.H> // for struct stat
|
#include <FL/Fl_System_Driver.H>
|
||||||
|
#include <FL/Fl.H>
|
||||||
#include <FL/filename.H>
|
#include <FL/filename.H>
|
||||||
#include <FL/fl_ask.H>
|
#include <FL/fl_ask.H>
|
||||||
#include <FL/x.H>
|
#include <FL/x.H>
|
||||||
@@ -724,9 +725,9 @@ Fl_File_Chooser::fileListCB()
|
|||||||
if (Fl::event_clicks()) {
|
if (Fl::event_clicks()) {
|
||||||
#if (defined(WIN32) && ! defined(__CYGWIN__)) || defined(__EMX__)
|
#if (defined(WIN32) && ! defined(__CYGWIN__)) || defined(__EMX__)
|
||||||
if ((strlen(pathname) == 2 && pathname[1] == ':') ||
|
if ((strlen(pathname) == 2 && pathname[1] == ':') ||
|
||||||
_fl_filename_isdir_quick(pathname))
|
Fl::system_driver()->filename_isdir_quick(pathname))
|
||||||
#else
|
#else
|
||||||
if (_fl_filename_isdir_quick(pathname))
|
if (Fl::system_driver()->filename_isdir_quick(pathname))
|
||||||
#endif /* WIN32 || __EMX__ */
|
#endif /* WIN32 || __EMX__ */
|
||||||
{
|
{
|
||||||
// Change directories...
|
// Change directories...
|
||||||
@@ -790,7 +791,7 @@ Fl_File_Chooser::fileListCB()
|
|||||||
if (callback_) (*callback_)(this, data_);
|
if (callback_) (*callback_)(this, data_);
|
||||||
|
|
||||||
// Activate the OK button as needed...
|
// Activate the OK button as needed...
|
||||||
if (!_fl_filename_isdir_quick(pathname) || (type_ & DIRECTORY))
|
if (!Fl::system_driver()->filename_isdir_quick(pathname) || (type_ & DIRECTORY))
|
||||||
okButton->activate();
|
okButton->activate();
|
||||||
else
|
else
|
||||||
okButton->deactivate();
|
okButton->deactivate();
|
||||||
@@ -857,15 +858,15 @@ Fl_File_Chooser::fileNameCB()
|
|||||||
// Enter pressed - select or change directory...
|
// Enter pressed - select or change directory...
|
||||||
#if (defined(WIN32) && ! defined(__CYGWIN__)) || defined(__EMX__)
|
#if (defined(WIN32) && ! defined(__CYGWIN__)) || defined(__EMX__)
|
||||||
if ((isalpha(pathname[0] & 255) && pathname[1] == ':' && !pathname[2]) ||
|
if ((isalpha(pathname[0] & 255) && pathname[1] == ':' && !pathname[2]) ||
|
||||||
(_fl_filename_isdir_quick(pathname) &&
|
(Fl::system_driver()->filename_isdir_quick(pathname) &&
|
||||||
compare_dirnames(pathname, directory_))) {
|
compare_dirnames(pathname, directory_))) {
|
||||||
#else
|
#else
|
||||||
if (_fl_filename_isdir_quick(pathname) &&
|
if (Fl::system_driver()->filename_isdir_quick(pathname) &&
|
||||||
compare_dirnames(pathname, directory_)) {
|
compare_dirnames(pathname, directory_)) {
|
||||||
#endif /* WIN32 || __EMX__ */
|
#endif /* WIN32 || __EMX__ */
|
||||||
directory(pathname);
|
directory(pathname);
|
||||||
} else if ((type_ & CREATE) || access(pathname, 0) == 0) {
|
} else if ((type_ & CREATE) || access(pathname, 0) == 0) {
|
||||||
if (!_fl_filename_isdir_quick(pathname) || (type_ & DIRECTORY)) {
|
if (!Fl::system_driver()->filename_isdir_quick(pathname) || (type_ & DIRECTORY)) {
|
||||||
// Update the preview box...
|
// Update the preview box...
|
||||||
update_preview();
|
update_preview();
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,8 @@ public:
|
|||||||
virtual int filename_expand(char *to,int tolen, const char *from);
|
virtual int filename_expand(char *to,int tolen, const char *from);
|
||||||
virtual int filename_relative(char *to, int tolen, const char *from, const char *base);
|
virtual int filename_relative(char *to, int tolen, const char *from, const char *base);
|
||||||
virtual int filename_absolute(char *to, int tolen, const char *from);
|
virtual int filename_absolute(char *to, int tolen, const char *from);
|
||||||
|
virtual int filename_isdir(const char* n);
|
||||||
|
virtual int filename_isdir_quick(const char* n);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FL_WINAPI_SYSTEM_DRIVER_H
|
#endif // FL_WINAPI_SYSTEM_DRIVER_H
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "Fl_WinAPI_System_Driver.H"
|
#include "Fl_WinAPI_System_Driver.H"
|
||||||
#include <FL/Fl.H>
|
#include <FL/Fl.H>
|
||||||
#include <FL/fl_utf8.h>
|
#include <FL/fl_utf8.h>
|
||||||
|
#include <FL/filename.H>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
@@ -614,6 +615,39 @@ int Fl_WinAPI_System_Driver::filename_absolute(char *to, int tolen, const char *
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Fl_WinAPI_System_Driver::filename_isdir(const char* n)
|
||||||
|
{
|
||||||
|
struct stat s;
|
||||||
|
char fn[FL_PATH_MAX];
|
||||||
|
int length;
|
||||||
|
length = (int) strlen(n);
|
||||||
|
// This workaround brought to you by the fine folks at Microsoft!
|
||||||
|
// (read lots of sarcasm in that...)
|
||||||
|
if (length < (int)(sizeof(fn) - 1)) {
|
||||||
|
if (length < 4 && isalpha(n[0]) && n[1] == ':' &&
|
||||||
|
(isdirsep(n[2]) || !n[2])) {
|
||||||
|
// Always use D:/ for drive letters
|
||||||
|
fn[0] = n[0];
|
||||||
|
strcpy(fn + 1, ":/");
|
||||||
|
n = fn;
|
||||||
|
} else if (length > 0 && isdirsep(n[length - 1])) {
|
||||||
|
// Strip trailing slash from name...
|
||||||
|
length --;
|
||||||
|
memcpy(fn, n, length);
|
||||||
|
fn[length] = '\0';
|
||||||
|
n = fn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return !stat(n, &s) && (s.st_mode & S_IFMT) == S_IFDIR;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Fl_WinAPI_System_Driver::filename_isdir_quick(const char* n)
|
||||||
|
{
|
||||||
|
// Do a quick optimization for filenames with a trailing slash...
|
||||||
|
if (*n && isdirsep(n[strlen(n) - 1])) return 1;
|
||||||
|
return filename_isdir(n);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// End of "$Id$".
|
// End of "$Id$".
|
||||||
//
|
//
|
||||||
|
|||||||
+18
-38
@@ -19,22 +19,21 @@
|
|||||||
// Used by fl_file_chooser
|
// Used by fl_file_chooser
|
||||||
|
|
||||||
#include "flstring.h"
|
#include "flstring.h"
|
||||||
#include <sys/types.h>
|
#include <FL/Fl_System_Driver.H>
|
||||||
#include <FL/Fl_System_Driver.H> // for struct stat
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <FL/filename.H>
|
#include <FL/filename.H>
|
||||||
#include <FL/fl_utf8.h>
|
#include <FL/Fl.H>
|
||||||
|
|
||||||
#if defined(WIN32) || defined(__EMX__) && !defined(__CYGWIN__)
|
/*
|
||||||
static inline int isdirsep(char c) {return c=='/' || c=='\\';}
|
* filename_isdir_quick() is a private function that checks for a
|
||||||
#else
|
* trailing slash and assumes that the passed name is a directory if
|
||||||
#define isdirsep(c) ((c)=='/')
|
* it finds one. This function is used by Fl_File_Browser and
|
||||||
#endif
|
* Fl_File_Chooser to avoid extra stat() calls, but is not supported
|
||||||
|
* outside of FLTK...
|
||||||
int _fl_filename_isdir_quick(const char* n) {
|
*/
|
||||||
|
int Fl_System_Driver::filename_isdir_quick(const char* n) {
|
||||||
// Do a quick optimization for filenames with a trailing slash...
|
// Do a quick optimization for filenames with a trailing slash...
|
||||||
if (*n && isdirsep(n[strlen(n) - 1])) return 1;
|
if (*n && n[strlen(n) - 1] == '/') return 1;
|
||||||
return fl_filename_isdir(n);
|
return filename_isdir(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,43 +48,24 @@ int _fl_filename_isdir_quick(const char* n) {
|
|||||||
\return non zero if file exists and is a directory, zero otherwise
|
\return non zero if file exists and is a directory, zero otherwise
|
||||||
*/
|
*/
|
||||||
int fl_filename_isdir(const char* n) {
|
int fl_filename_isdir(const char* n) {
|
||||||
|
return Fl::system_driver()->filename_isdir(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Fl_System_Driver::filename_isdir(const char* n) {
|
||||||
struct stat s;
|
struct stat s;
|
||||||
char fn[FL_PATH_MAX];
|
char fn[FL_PATH_MAX];
|
||||||
int length;
|
int length;
|
||||||
|
|
||||||
length = (int) strlen(n);
|
length = (int) strlen(n);
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
// This workaround brought to you by the fine folks at Microsoft!
|
|
||||||
// (read lots of sarcasm in that...)
|
|
||||||
if (length < (int)(sizeof(fn) - 1)) {
|
|
||||||
if (length < 4 && isalpha(n[0]) && n[1] == ':' &&
|
|
||||||
(isdirsep(n[2]) || !n[2])) {
|
|
||||||
// Always use D:/ for drive letters
|
|
||||||
fn[0] = n[0];
|
|
||||||
strcpy(fn + 1, ":/");
|
|
||||||
n = fn;
|
|
||||||
} else if (length > 0 && isdirsep(n[length - 1])) {
|
|
||||||
// Strip trailing slash from name...
|
|
||||||
length --;
|
|
||||||
memcpy(fn, n, length);
|
|
||||||
fn[length] = '\0';
|
|
||||||
n = fn;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
// Matt: Just in case, we strip the slash for other operating
|
// Matt: Just in case, we strip the slash for other operating
|
||||||
// systems as well, avoid bugs by sloppy implementations
|
// systems as well, avoid bugs by sloppy implementations
|
||||||
// of "stat".
|
// of "stat".
|
||||||
if (length > 1 && isdirsep(n[length - 1])) {
|
if (length > 1 && n[length - 1] == '/') {
|
||||||
length --;
|
length --;
|
||||||
memcpy(fn, n, length);
|
memcpy(fn, n, length);
|
||||||
fn[length] = '\0';
|
fn[length] = '\0';
|
||||||
n = fn;
|
n = fn;
|
||||||
}
|
}
|
||||||
#endif
|
return !stat(n, &s) && (s.st_mode & S_IFMT) == S_IFDIR;
|
||||||
|
|
||||||
return !fl_stat(n, &s) && (s.st_mode & S_IFMT) == S_IFDIR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user