[MPlayer-dev-eng] [PATCH] path seperator makeover

Joey Parrish joey at nicewarrior.org
Thu Aug 12 02:04:35 CEST 2004


Hello,

I'm releasing new cygwin packages soon, so time for another round of
hopefully useful patches.  :)

Attached is a patch to alter the way paths are handled in MPlayer.  This
patch allows both unix-style paths and a variety of windows-style paths
in playlist code.  The current way is to have playlist code look for
PATH_SEP which is defined to either / or \.  And mplayer.c's mp_basename
macro only looked for /, as well.

The problem is that cygwin systems can handle unix or windows paths at
once.  So why choose one or the other at compile time?

mp_basename now finds either / or \.
Playlist basename code now does this:
 sees /path/to/file as a full path
 sees c:\windows as a full path
 sees \windows as a near-full path (and prepends playlist drive letter)
 sees file.avi as a relative path (and prepends path to playlist)

This should not change anything under linux.
Please test, comment, or say "commit".

--Joey

-- 
Me: "Isn't Kennedy as real as Colonel Sanders?"
Chad: "... Which Kennedy?"
-------------- next part --------------
change some path stuff for windows:
 basename should look for \ and / both
 playlist parsing was being crazy before...
  now it sees c:\windows as a full path,
  \windows as a "near-full" path (and prepends drive letter),
  and file.avi as a relative path (and prepends path to playlist).

diff -Nur main.sofar/mplayer.c main.dev/mplayer.c
--- main.sofar/mplayer.c	2004-08-10 03:07:21.000000000 +0000
+++ main.dev/mplayer.c	2004-08-11 03:03:28.829166400 +0000
@@ -619,7 +619,8 @@
   return eof;
 }
 
-#define mp_basename(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
+#define mp_basename2(s) (strrchr(s,'/')==NULL?(char*)s:(strrchr(s,'/')+1))
+#define mp_basename(s) (strrchr(s,'\\')==NULL?(mp_basename2(s)):(strrchr(s,'\\')+1))
 
 int playtree_add_playlist(play_tree_t* entry)
 {
diff -Nur main.sofar/playtreeparser.c main.dev/playtreeparser.c
--- main.sofar/playtreeparser.c	2004-06-26 13:07:04.000000000 +0000
+++ main.dev/playtreeparser.c	2004-08-11 03:16:37.022532800 +0000
@@ -20,12 +20,6 @@
 #include "mp_msg.h"
 
 
-#if defined(__CYGWIN__) || defined(__OS2__)
-#define PATH_SEP '\\'
-#else
-#define PATH_SEP '/'
-#endif
-
 extern play_tree_t*
 asx_parser_build_tree(char* buffer, int ref);
 
@@ -630,8 +624,16 @@
 
   for(i = 0 ; pt->files[i] != NULL ; i++) {
     fl = strlen(pt->files[i]);
-    if(fl <= 0 || pt->files[i][0] == PATH_SEP || strstr(pt->files[i],"://"))
+    // if we find url:// or X:\ at the beginning, don't mangle it.
+    if(fl <= 0 || strstr(pt->files[i],"://") || strstr(pt->files[i],":\\") == pt->files[i] + 1)
       continue;
+    // if the path begins with \ then prepend drive letter to it.
+    if (pt->files[i][0] == '\\') {
+      pt->files[i] = (char*)realloc(pt->files[i],2+fl+1);
+      memmove(pt->files[i] + 2,pt->files[i],fl+1);
+      memcpy(pt->files[i],bp,2);
+      return;
+    }
     pt->files[i] = (char*)realloc(pt->files[i],bl+fl+1);
     memmove(pt->files[i] + bl,pt->files[i],fl+1);
     memcpy(pt->files[i],bp,bl);
@@ -648,7 +650,8 @@
     file = strdup(filename);
     if (file)
     {
-      ls = strrchr(file,PATH_SEP);
+      ls = strrchr(file,'/');
+      if(!ls) ls = strrchr(file,'\\');
       if(ls) {
         ls[1] = '\0';
         play_tree_add_basepath(pt,file);


More information about the MPlayer-dev-eng mailing list