Browse Source

*** empty log message ***

David Rose 25 years ago
parent
commit
5b79971243

+ 3 - 0
dtool/Config.Irix.pp

@@ -84,6 +84,9 @@
 // Do we have <utime.h>?
 #define HAVE_UTIME_H 1
 
+// Do we have <dirent.h>?
+#define HAVE_DIRENT_H 1
+
 // Do we have <sys/soundcard.h> (and presumably a Linux-style audio
 // interface)?
 #define HAVE_SYS_SOUNDCARD_H

+ 3 - 0
dtool/Config.Linux.pp

@@ -84,6 +84,9 @@
 // Do we have <utime.h>?
 #define HAVE_UTIME_H 1
 
+// Do we have <dirent.h>?
+#define HAVE_DIRENT_H 1
+
 // Do we have <sys/soundcard.h> (and presumably a Linux-style audio
 // interface)?
 #define HAVE_SYS_SOUNDCARD_H 1

+ 3 - 0
dtool/Config.Win32.pp

@@ -84,6 +84,9 @@
 // Do we have <utime.h>?
 #define HAVE_UTIME_H
 
+// Do we have <dirent.h>?
+#define HAVE_DIRENT_H
+
 // Do we have <sys/soundcard.h> (and presumably a Linux-style audio
 // interface)?
 #define HAVE_SYS_SOUNDCARD_H

+ 3 - 0
dtool/LocalSetup.pp

@@ -142,6 +142,9 @@ $[cdefine HAVE_UNISTD_H]
 /* Define if you have the <utime.h> header file.  */
 $[cdefine HAVE_UTIME_H]
 
+/* Define if you have the <dirent.h> header file.  */
+$[cdefine HAVE_DIRENT_H]
+
 /* Do we have <sys/soundcard.h> (and presumably a Linux-style audio
    interface)? */
 $[cdefine HAVE_SYS_SOUNDCARD_H]

+ 53 - 0
dtool/src/dtoolutil/filename.cxx

@@ -18,6 +18,7 @@
 
 #include <stdio.h>  // For rename()
 #include <sys/stat.h>
+#include <algorithm>
 
 #ifdef HAVE_UTIME_H
 #include <utime.h>
@@ -27,6 +28,10 @@
 #include <fcntl.h>
 #endif
 
+#ifdef HAVE_DIRENT_H
+#include <dirent.h>
+#endif
+
 
 #if defined(WIN32)
 /* begin Win32-specific code */
@@ -932,6 +937,54 @@ find_on_searchpath(const DSearchPath &searchpath) {
   return -1;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: Filename::scan_directory
+//       Access: Public
+//  Description: Attempts to open the named filename as if it were a
+//               directory and looks for the non-hidden files within
+//               the directory.  Fills the given vector up with the
+//               sorted list of filenames that are local to this
+//               directory.
+//
+//               It is the user's responsibility to ensure that the
+//               contents vector is empty before making this call;
+//               otherwise, the new files will be appended to it.
+//
+//               Returns true on success, false if the directory could
+//               not be read for some reason.
+////////////////////////////////////////////////////////////////////
+bool Filename::
+scan_directory(vector_string &contents) const {
+#if defined(HAVE_DIRENT_H)
+  size_t orig_size = contents.size();
+
+  DIR *root = opendir(_filename.c_str());
+  if (root == (DIR *)NULL) {
+    return false;
+  }
+
+  struct dirent *d;
+  d = readdir(root);
+  while (d != (struct dirent *)NULL) {
+    if (d->d_name[0] != '.') {
+      contents.push_back(d->d_name);
+    }
+    d = readdir(root);
+  }
+  closedir(root);
+
+  sort(contents.begin() + orig_size, contents.end());
+  return true;
+
+#elif defined(WIN32_VC)
+  return false;
+
+#else
+  // Don't know how to scan directories!
+  return false;
+#endif  
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: Filename::open_read
 //       Access: Public

+ 4 - 0
dtool/src/dtoolutil/filename.h

@@ -17,6 +17,8 @@
 
 #include <dtoolbase.h>
 
+#include "vector_string.h"
+
 #include <assert.h>
 
 class DSearchPath;
@@ -135,6 +137,8 @@ PUBLISHED:
   bool make_relative_to(Filename directory, bool allow_backups = true);
   int find_on_searchpath(const DSearchPath &searchpath);
 
+  bool scan_directory(vector_string &contents) const;
+
   bool open_read(ifstream &stream) const;
   bool open_write(ofstream &stream) const;
   bool open_append(ofstream &stream) const;