FLTK logo

[Library] r4525 - in branches/branch-1.1: . documentation src

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[Library] r4525 - in branches/branch-1.1: . documentation src fltk-dev Aug 17, 2005  
 
Author: matt
Date: 2005-08-17 17:56:22 -0400 (Wed, 17 Aug 2005)
New Revision: 4525

Modified:
   branches/branch-1.1/CHANGES
   branches/branch-1.1/documentation/functions.html
   branches/branch-1.1/src/Fl_File_Browser.cxx
   branches/branch-1.1/src/filename_list.cxx
Log:
This change is controversial. It changes the behavior of fl_filename_list
slightly by adding a forward slash after every directory name on every
supported OS. Included in this patch is a change in the code that 
lists mounted volumes on OS X Mac.

Apple users, please check. Open FLUID, open the file dialog and
clear the current path. You shoudl see a list of mounted volumes.


Modified: branches/branch-1.1/CHANGES
===================================================================
--- branches/branch-1.1/CHANGES	2005-08-17 18:09:20 UTC (rev 4524)
+++ branches/branch-1.1/CHANGES	2005-08-17 21:56:22 UTC (rev 4525)
@@ -3,6 +3,8 @@
 	- Documentation fixes (STR #571, STR #648, STR #692, STR
 	  #730, STR #744, STR #745, STR #931, STR #942, STR #960,
 	  STR #969)
+	- fl_filename_list now always appends a forward slash to
+	  directory names (STR #874)
 	- Multiline Input will update right if a space character is
 	  inserted in word wrap mode (STR #981)
 	- FLUID group labels redraw correctly (STR #959)

Modified: branches/branch-1.1/documentation/functions.html
===================================================================
--- branches/branch-1.1/documentation/functions.html	2005-08-17 18:09:20 UTC (rev 4524)
+++ branches/branch-1.1/documentation/functions.html	2005-08-17 21:56:22 UTC (rev 4525)
@@ -718,6 +718,8 @@
 <tt>errno</tt> has the reason; <tt>errno</tt> does not work
 under WIN32.
 
+<P>The name of directory always ends in a forward slash '/'.
+
 <P>The <tt>sort</tt> argument specifies a sort function to be used
 when on the array of filenames. The following standard sort functions
 are provided with FLTK:

Modified: branches/branch-1.1/src/Fl_File_Browser.cxx
===================================================================
--- branches/branch-1.1/src/Fl_File_Browser.cxx	2005-08-17 18:09:20 UTC (rev 4524)
+++ branches/branch-1.1/src/Fl_File_Browser.cxx	2005-08-17 21:56:22 UTC (rev 4525)
@@ -67,6 +67,7 @@
 // CodeWarrior (__MWERKS__) gets its include paths confused, so we
 // temporarily disable this...
 #if defined(__APPLE__) && !defined(__MWERKS__)
+#  include <Carbon/Carbon.h>
 #  include <sys/param.h>
 #  include <sys/ucred.h>
 #  include <sys/mount.h>
@@ -495,30 +496,20 @@
 	num_files ++;
       }
 #elif defined(__APPLE__) && !defined(__MWERKS__)
-    // MacOS X and Darwin use getfsstat() system call...
-    int			numfs;	// Number of file systems
-    struct statfs	*fs;	// Buffer for file system info
-
-
-    numfs = getfsstat(NULL, 0, MNT_NOWAIT);
-    if (numfs > 0) {
-      // We have file systems, get them...
-      fs = new struct statfs[numfs];
-      getfsstat(fs, sizeof(struct statfs) * numfs, MNT_NOWAIT);
-
-      // Add filesystems to the list...
-      for (i = 0; i < numfs; i ++) {
-        if (fs[i].f_mntonname[1]) {
-          snprintf(filename, sizeof(filename), "%s/", fs[i].f_mntonname);
-          add(filename, icon);
-        } else {
-          add("/", icon);
-        }
-        num_files ++;
+    // All mounted volumes are in a directory called '/Volumes/'
+    // This seems to be the case on international installations, too.
+    add("/", icon);
+    dirent **dir;
+    int n = fl_filename_list("/Volumes/", &dir, 0);
+    if (n>=0) {
+      int i;
+      for (i=0; i<n; i++) {
+        if (dir[i]->d_name[0]=='.') continue;
+        sprintf(filename, "/Volumes/%s", dir[i]->d_name);
+        add(filename, icon);
+        free(dir[i]);
       }
-
-      // Free the memory used for the file system info array...
-      delete[] fs;
+      free(dir);
     }
 #else
     //
@@ -596,18 +587,7 @@
 	if ((icon && icon->type() == Fl_File_Icon::DIRECTORY) ||
 	     fl_filename_isdir(filename)) {
           num_dirs ++;
-
-#if defined(WIN32) && !defined(__CYGWIN__)
-	  // WIN32 already has the trailing slash... :)
           insert(num_dirs, files[i]->d_name, icon);
-#else
-	  // Add a trailing slash to directory names...
-	  char name[1024]; // Temporary directory name
-
-	  snprintf(name, sizeof(name), "%s/", files[i]->d_name);
-
-          insert(num_dirs, name, icon);
-#endif // WIN32 && !__CYGWIN__
 	} else if (filetype_ == FILES &&
 	           fl_filename_match(files[i]->d_name, pattern_)) {
           add(files[i]->d_name, icon);

Modified: branches/branch-1.1/src/filename_list.cxx
===================================================================
--- branches/branch-1.1/src/filename_list.cxx	2005-08-17 18:09:20 UTC (rev 4524)
+++ branches/branch-1.1/src/filename_list.cxx	2005-08-17 21:56:22 UTC (rev 4525)
@@ -29,6 +29,7 @@
 
 #include <FL/filename.H>
 #include "flstring.h"
+#include <stdlib.h>
 
 
 extern "C" {
@@ -52,26 +53,52 @@
 int fl_filename_list(const char *d, dirent ***list,
                      Fl_File_Sort_F *sort) {
 #ifndef HAVE_SCANDIR
-  return scandir(d, list, 0, sort);
+  int n = scandir(d, list, 0, sort);
 #elif defined(__hpux) || defined(__CYGWIN__)
   // HP-UX, Cygwin define the comparison function like this:
-  return scandir(d, list, 0, (int(*)(const dirent **, const dirent **))sort);
+  int n = 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 **))sort);
+  int n = scandir(d, list, 0, (int(*)(dirent **, dirent **))sort);
 #elif defined(_AIX)
   // AIX is almost standard...
-  return scandir(d, list, 0, (int(*)(void*, void*))sort);
+  int n = scandir(d, list, 0, (int(*)(void*, void*))sort);
 #elif !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*))sort);
+  int n = 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, sort);
+  int n = scandir(d, list, 0, sort);
 #endif
+
+#if defined(WIN32) && !defined(__CYGWIN__)
+  // we did this already during fl_scandir/win32
+#else
+  // append a '/' to all filenames that are directories
+  int i, dirlen = strlen(d);
+  char *fullname = (char*)malloc(dirlen+FL_PATH_MAX+2);
+  memcpy(fullname, d, dirlen+1);
+  char *name = fullname + dirlen;
+  if (name!=fullname && name[-1]!='/') *name++ = '/';
+  for (i=0; i<n; i++) {
+    dirent *de = (*list)[i];
+    int len = strlen(de->d_name);
+    if (de->d_name[len-1]=='/' || len>FL_PATH_MAX) continue;
+    memcpy(name, de->d_name, len+1);
+    if (fl_filename_isdir(fullname)) {
+      if (len<FL_PATH_MAX) {
+        char *dst = de->d_name + len;
+        *dst++ = '/';
+        *dst = 0;
+      }
+    }
+  }
+  free(fullname);
+#endif
+  return n;
 }
 
 //

Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.