Removed 'optimization' for fl_filename_isdir which would break the original purpose of the fuction (testing the *existence* of a directory). But I did not want to lose the performance in the directory chooser where I *know* that a directory exists, just not if it is a file or directory, so I added the function fl_filename_isdir_quick() to do just that. Please verify that the new version works as expected, especially with regard to the directory chooser.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@5630 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
9e79fd13d2
commit
e4586d1572
@ -40,6 +40,7 @@ FL_EXPORT int fl_filename_absolute(char *to, int tolen, const char *from);
|
||||
FL_EXPORT int fl_filename_relative(char *to, int tolen, const char *from);
|
||||
FL_EXPORT int fl_filename_match(const char *name, const char *pattern);
|
||||
FL_EXPORT int fl_filename_isdir(const char *name);
|
||||
FL_EXPORT int fl_filename_isdir_quick(const char *name);
|
||||
|
||||
# ifdef __cplusplus
|
||||
/*
|
||||
|
@ -58,11 +58,11 @@ A</A>.
|
||||
<LI><A HREF="drawing.html#fl_draw_image"><TT>fl_draw_image</TT></A></LI>
|
||||
<LI><A HREF="drawing.html#fl_draw_image"><TT>fl_draw_image_mono</TT></A></LI>
|
||||
<LI><A HREF="drawing.html#fl_draw_pixmap"><TT>fl_draw_pixmap</TT></A></LI>
|
||||
<LI><A HREF="common.html#fl_draw_symbol"><TT>fl_draw_symbol</TT></A></LI>
|
||||
</UL>
|
||||
</TD>
|
||||
<TD width=33%>
|
||||
<UL>
|
||||
<LI><A HREF="common.html#fl_draw_symbol"><TT>fl_draw_symbol</TT></A></LI>
|
||||
<LI><A HREF="drawing.html#fl_begin_complex_polygon"><TT>fl_end_complex_polygon</TT></A></LI>
|
||||
<LI><A HREF="drawing.html#fl_begin_line"><TT>fl_end_line</TT></A></LI>
|
||||
<LI><A HREF="drawing.html#fl_begin_loop"><TT>fl_end_loop</TT></A></LI>
|
||||
@ -76,6 +76,7 @@ A</A>.
|
||||
<LI><A HREF="#fl_filename_expand"><TT>fl_filename_expand</TT></A></LI>
|
||||
<LI><A HREF="#fl_filename_ext"><TT>fl_filename_ext</TT></A></LI>
|
||||
<LI><A HREF="#fl_filename_isdir"><TT>fl_filename_isdir</TT></A></LI>
|
||||
<LI><A HREF="#fl_filename_isdir_quick"><TT>fl_filename_isdir_quick</TT></A></LI>
|
||||
<LI><A HREF="#fl_filename_list"><TT>fl_filename_list</TT></A></LI>
|
||||
<LI><A HREF="#fl_filename_match"><TT>fl_filename_match</TT></A></LI>
|
||||
<LI><A HREF="#fl_filename_name"><TT>fl_filename_name</TT></A></LI>
|
||||
@ -104,11 +105,11 @@ A</A>.
|
||||
<LI><A HREF="drawing.html#fl_measure_pixmap"><TT>fl_measure_pixmap</TT></A></LI>
|
||||
<LI><A HREF="#fl_message"><TT>fl_message</TT></A></LI>
|
||||
<LI><A HREF="#fl_message_font"><TT>fl_message_font</TT></A></LI>
|
||||
<LI><A HREF="#fl_message_icon"><TT>fl_message_icon</TT></A></LI>
|
||||
</UL>
|
||||
</TD>
|
||||
<TD width=30%>
|
||||
<UL>
|
||||
<LI><A HREF="#fl_message_icon"><TT>fl_message_icon</TT></A></LI>
|
||||
<LI><A HREF="drawing.html#fl_scale"><TT>fl_mult_matrix</TT></A></LI>
|
||||
<LI><A HREF="drawing.html#fl_not_clipped"><TT>fl_not_clipped</TT></A></LI>
|
||||
<LI><A HREF="#fl_numericsort"><TT>fl_numericsort</TT></A></LI>
|
||||
@ -309,6 +310,7 @@ A</A>.
|
||||
<LI><A HREF="#fl_filename_expand"><TT>fl_filename_expand</TT></A></LI>
|
||||
<LI><A HREF="#fl_filename_ext"><TT>fl_filename_ext</TT></A></LI>
|
||||
<LI><A HREF="#fl_filename_isdir"><TT>fl_filename_isdir</TT></A></LI>
|
||||
<LI><A HREF="#fl_filename_isdir_quick"><TT>fl_filename_isdir_quick</TT></A></LI>
|
||||
<LI><A HREF="#fl_filename_list"><TT>fl_filename_list</TT></A></LI>
|
||||
<LI><A HREF="#fl_filename_match"><TT>fl_filename_match</TT></A></LI>
|
||||
<LI><A HREF="#fl_filename_name"><TT>fl_filename_name</TT></A></LI>
|
||||
@ -934,6 +936,34 @@ int fl_filename_isdir(const char *f);
|
||||
<P>Returns non-zero if the file exists and is a directory.
|
||||
|
||||
|
||||
<!-- NEED 4in -->
|
||||
<H2><A NAME="fl_filename_isdir_quick">fl_filename_isdir_quick</A></H2>
|
||||
|
||||
<HR>
|
||||
|
||||
<H3>Include Files</H3>
|
||||
|
||||
<UL><PRE>
|
||||
#include <FL/filename.H>
|
||||
</PRE></UL>
|
||||
|
||||
<H3>Prototype</H3>
|
||||
|
||||
<UL><PRE>
|
||||
int fl_filename_isdir_quick(const char *f);
|
||||
</PRE></UL>
|
||||
|
||||
<H3>Description</H3>
|
||||
|
||||
<P>Returns non-zero if the file is a directory. If the
|
||||
filename ends in a directory seperator (usually the
|
||||
slash '/'), the existence of the directory will not
|
||||
be verified and '1' is returned. This is much faster
|
||||
than <tt>fl_filename_isdir</tt> if the file is known
|
||||
to exist, because its filename was obtained via
|
||||
<tt>fl_filename_list</tt> or similar.
|
||||
|
||||
|
||||
<!-- NEED 4in -->
|
||||
<H2><A NAME="fl_filename_list">fl_filename_list</A></H2>
|
||||
|
||||
|
@ -600,7 +600,7 @@ Fl_File_Browser::load(const char *directory,// I - Directory to load
|
||||
|
||||
icon = Fl_File_Icon::find(filename);
|
||||
if ((icon && icon->type() == Fl_File_Icon::DIRECTORY) ||
|
||||
fl_filename_isdir(filename)) {
|
||||
fl_filename_isdir_quick(filename)) {
|
||||
num_dirs ++;
|
||||
insert(num_dirs, files[i]->d_name, icon);
|
||||
} else if (filetype_ == FILES &&
|
||||
|
@ -412,9 +412,9 @@ Fl_File_Chooser::fileListCB()
|
||||
if (Fl::event_clicks()) {
|
||||
#if (defined(WIN32) && ! defined(__CYGWIN__)) || defined(__EMX__)
|
||||
if ((strlen(pathname) == 2 && pathname[1] == ':') ||
|
||||
fl_filename_isdir(pathname))
|
||||
fl_filename_isdir_quick(pathname))
|
||||
#else
|
||||
if (fl_filename_isdir(pathname))
|
||||
if (fl_filename_isdir_quick(pathname))
|
||||
#endif /* WIN32 || __EMX__ */
|
||||
{
|
||||
// Change directories...
|
||||
@ -477,7 +477,7 @@ Fl_File_Chooser::fileListCB()
|
||||
if (callback_) (*callback_)(this, data_);
|
||||
|
||||
// Activate the OK button as needed...
|
||||
if (!fl_filename_isdir(pathname) || (type_ & DIRECTORY))
|
||||
if (!fl_filename_isdir_quick(pathname) || (type_ & DIRECTORY))
|
||||
okButton->activate();
|
||||
else
|
||||
okButton->deactivate();
|
||||
@ -544,15 +544,15 @@ Fl_File_Chooser::fileNameCB()
|
||||
// Enter pressed - select or change directory...
|
||||
#if (defined(WIN32) && ! defined(__CYGWIN__)) || defined(__EMX__)
|
||||
if ((isalpha(pathname[0] & 255) && pathname[1] == ':' && !pathname[2]) ||
|
||||
fl_filename_isdir(pathname) &&
|
||||
fl_filename_isdir_quick(pathname) &&
|
||||
compare_dirnames(pathname, directory_)) {
|
||||
#else
|
||||
if (fl_filename_isdir(pathname) &&
|
||||
if (fl_filename_isdir_quick(pathname) &&
|
||||
compare_dirnames(pathname, directory_)) {
|
||||
#endif /* WIN32 || __EMX__ */
|
||||
directory(pathname);
|
||||
} else if ((type_ & CREATE) || access(pathname, 0) == 0) {
|
||||
if (!fl_filename_isdir(pathname) || (type_ & DIRECTORY)) {
|
||||
if (!fl_filename_isdir_quick(pathname) || (type_ & DIRECTORY)) {
|
||||
// Update the preview box...
|
||||
update_preview();
|
||||
|
||||
|
@ -40,18 +40,22 @@ static inline int isdirsep(char c) {return c=='/' || c=='\\';}
|
||||
#define isdirsep(c) ((c)=='/')
|
||||
#endif
|
||||
|
||||
int fl_filename_isdir(const char* n) {
|
||||
struct stat s;
|
||||
|
||||
int fl_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 fl_filename_isdir(n);
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
int fl_filename_isdir(const char* n) {
|
||||
struct stat s;
|
||||
char fn[1024];
|
||||
int length;
|
||||
|
||||
length = strlen(n);
|
||||
|
||||
#ifdef WIN32
|
||||
// This workaround brought to you by the fine folks at Microsoft!
|
||||
// (read lots of sarcasm in that...)
|
||||
length = strlen(n);
|
||||
if (length < (int)(sizeof(fn) - 1)) {
|
||||
if (length < 4 && isalpha(n[0]) && n[1] == ':' &&
|
||||
(isdirsep(n[2]) || !n[2])) {
|
||||
@ -67,6 +71,16 @@ int fl_filename_isdir(const char* n) {
|
||||
n = fn;
|
||||
}
|
||||
}
|
||||
#else
|
||||
// Matt: Actually, we found out that a trailling slash may also throw off
|
||||
// some Unix implementations of stat, so cutting slashes is a must on every
|
||||
// platform (thanks for that test, Greg)
|
||||
if (length > 0 && isdirsep(n[length - 1])) {
|
||||
length --;
|
||||
memcpy(fn, n, length);
|
||||
fn[length] = '\0';
|
||||
n = fn;
|
||||
}
|
||||
#endif
|
||||
|
||||
return !stat(n, &s) && (s.st_mode&0170000)==0040000;
|
||||
|
Loading…
Reference in New Issue
Block a user