aboutsummaryrefslogtreecommitdiff
path: root/playlist
diff options
context:
space:
mode:
Diffstat (limited to 'playlist')
-rw-r--r--playlist/playlist.c63
1 files changed, 59 insertions, 4 deletions
diff --git a/playlist/playlist.c b/playlist/playlist.c
index fce68a8..4576267 100644
--- a/playlist/playlist.c
+++ b/playlist/playlist.c
@@ -37,17 +37,60 @@
#include <regex.h>
#include <time.h>
#include <sys/time.h>
+#include <dirent.h>
#include "m_pd.h"
#include "m_imp.h"
#include "g_canvas.h"
-
+#include <sys/types.h>
#ifdef _WIN32
#include <io.h>
+#include <pthread.h>
+#include <direct.h>
+
+int scandir(const char *dir, struct dirent ***namelist,
+ int (*select)(const struct dirent *),
+ int (*compar)(const struct dirent **, const struct dirent **)) {
+ DIR *d;
+ struct dirent *entry;
+ register int i=0;
+ size_t entrysize;
+
+ if ((d=opendir(dir)) == NULL)
+ return(-1);
+
+ *namelist=NULL;
+ while ((entry=readdir(d)) != NULL)
+ {
+ if (select == NULL || (select != NULL && (*select)(entry)))
+ {
+ *namelist=(struct dirent **)realloc((void *)(*namelist),
+ (size_t)((i+1)*sizeof(struct dirent *)));
+ if (*namelist == NULL) return(-1);
+ entrysize=sizeof(struct dirent)-sizeof(entry->d_name)+strlen(entry->d_name)+1;
+ (*namelist)[i]=(struct dirent *)malloc(entrysize);
+ if ((*namelist)[i] == NULL) return(-1);
+ memcpy((*namelist)[i], entry, entrysize);
+ i++;
+ }
+ }
+ if (closedir(d)) return(-1);
+ if (i == 0) return(-1);
+ if (compar != NULL)
+ qsort((void *)(*namelist), (size_t)i, sizeof(struct dirent *), compar);
+
+ return(i);
+}
+
+int alphasort(const struct dirent **a, const struct dirent **b) {
+ return(strcmp((*a)->d_name, (*b)->d_name));
+ }
+
+int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), int (*)(const struct dirent **, const struct dirent **));
+int alphasort(const struct dirent **, const struct dirent **);
+
#else
#include <unistd.h>
-#include <sys/types.h>
-#include <dirent.h>
#endif
t_widgetbehavior playlist_widgetbehavior;
@@ -844,7 +887,19 @@ static t_playlist *playlist_new(t_symbol *s, int argc, t_atom *argv )
// get current directory full path
x->x_curdir = ( char * ) getbytes( MAX_DIR_LENGTH );
- if ( ( tmpcurdir = getenv( "PWD" ) ) == NULL )
+
+#ifdef _WIN32
+ char path[_MAX_DIR];
+
+ _getcwd (path, _MAX_DIR);
+ post ("Current directory is: %s", path);
+ tmpcurdir = path;
+
+#else
+ tmpcurdir = getenv( "PWD" );
+#endif
+
+ if ( tmpcurdir == NULL )
{
post( "playlist : could not get current directory ( where the hell are you ??? )" );
return NULL;